Commit 67d0902c authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Sébastien Blin

profiles: try to open the base64 path first for vcards

Change-Id: I632b4dd891813327fbdaec1d90e3c42e99af9a39
parent ad56bb86
......@@ -232,7 +232,7 @@ setProfile(const std::string& accountId,
file.setFileName(filePath);
}
if (!file.open(QIODevice::WriteOnly)) {
qWarning().noquote() << "Can't open file: " << filePath;
qWarning().noquote() << "Can't open file for writing: " << filePath;
return;
}
QTextStream(&file) << QString::fromStdString(vcard);
......@@ -299,26 +299,28 @@ buildContactFromProfile(const std::string & accountId,
profileInfo.uri = peer_uri;
profileInfo.type = type;
auto accountLocalPath = getPath() + QString::fromStdString(accountId) + "/";
QString filePath;
filePath = accountLocalPath + "profiles/" + QString::fromStdString(peer_uri) + ".vcf";
QFile file(filePath);
bool deleteOld = false;
QString b64filePath;
b64filePath = accountLocalPath + "profiles/" + QString(QByteArray::fromStdString(peer_uri).toBase64()) + ".vcf";
QFile file(b64filePath);
if (!file.open(QIODevice::ReadOnly)) {
qWarning().noquote() << "Can't open file: " << filePath << ". Trying Base64 file path.";
filePath = accountLocalPath + "profiles/" + QString(QByteArray::fromStdString(peer_uri).toBase64()) + ".vcf";
// try non-base64 path
QString filePath = accountLocalPath + "profiles/" + QString::fromStdString(peer_uri) + ".vcf";
file.setFileName(filePath);
if (!file.open(QIODevice::ReadOnly)) {
qWarning().noquote() << "Can't open file (base64 file path): " << filePath;
qWarning().noquote() << "Can't open file: " << filePath;
return { profileInfo, "", true, false };
}
// rename it
qWarning().noquote() << "Renaming profile: " << filePath;
file.rename(b64filePath);
// reopen it
if (!file.open(QIODevice::ReadOnly)) {
qWarning().noquote() << "Can't open file: " << b64filePath;
return { profileInfo, "", true, false };
}
} else {
deleteOld = true;
}
QTextStream in(&file);
QByteArray vcard = in.readAll().toUtf8();
if (deleteOld) {
file.remove();
}
const auto vCard = lrc::vCard::utils::toHashMap(vcard);
const auto alias = vCard[vCard::Property::FORMATTED_NAME];
const auto photo = (vCard.find(vCard::Property::PHOTO_PNG) == vCard.end()) ?
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment