diff --git a/src/common/utility.h b/src/common/utility.h index ed042c2caa..0be37ceee1 100644 --- a/src/common/utility.h +++ b/src/common/utility.h @@ -69,9 +69,9 @@ namespace Utility { * @brief Creates or overwrite the Desktop.ini file to use new folder IconResource shown as a favorite link * * @param folder absolute file path to folder - * @param overwrite boolean to create or overwrite ini file + * @param localizedResourceName new folder name to be used as display name (migration) */ - OCSYNC_EXPORT void setupDesktopIni(const QString &folder, bool overwrite = false); + OCSYNC_EXPORT void setupDesktopIni(const QString &folder, const QString localizedResourceName = {}); /** * @brief Removes the Desktop.ini file which contains the folder IconResource shown as a favorite link * diff --git a/src/common/utility_mac.mm b/src/common/utility_mac.mm index 768f35c63a..e66f69a65d 100644 --- a/src/common/utility_mac.mm +++ b/src/common/utility_mac.mm @@ -61,6 +61,12 @@ void Utility::migrateFavLink(const QString &folder) Q_UNUSED(folder) } +void Utility::setupDesktopIni(const QString &folder, const QString localizedResourceName) +{ + Q_UNUSED(folder) + Q_UNUSED(localizedResourceName) +} + QString Utility::syncFolderDisplayName(const QString &folder, const QString &displayName) { Q_UNUSED(folder) diff --git a/src/common/utility_unix.cpp b/src/common/utility_unix.cpp index 05ea04723d..fc7d56058b 100644 --- a/src/common/utility_unix.cpp +++ b/src/common/utility_unix.cpp @@ -70,6 +70,12 @@ void Utility::migrateFavLink(const QString &folder) Q_UNUSED(folder) } +void Utility::setupDesktopIni(const QString &folder, const QString localizedResourceName) +{ + Q_UNUSED(folder) + Q_UNUSED(localizedResourceName) +} + QString Utility::syncFolderDisplayName(const QString &folder, const QString &displayName) { Q_UNUSED(folder) diff --git a/src/common/utility_win.cpp b/src/common/utility_win.cpp index 7c0fe43562..adb1509810 100644 --- a/src/common/utility_win.cpp +++ b/src/common/utility_win.cpp @@ -118,11 +118,12 @@ QString Utility::systemPathToLinks() return pathToLinks; } -void Utility::setupDesktopIni(const QString &folder, bool overwrite) +void Utility::setupDesktopIni(const QString &folder, const QString localizedResourceName) { // First create a Desktop.ini so that the folder and favorite link show our application's icon. QFile desktopIni(folder + QLatin1String("/Desktop.ini")); - if (!overwrite && desktopIni.exists()) { + const auto migration = !localizedResourceName.isEmpty(); + if (!migration && desktopIni.exists()) { qCWarning(lcUtility) << desktopIni.fileName() << "already exists, not overwriting it to set the folder icon."; return; } @@ -138,6 +139,10 @@ void Utility::setupDesktopIni(const QString &folder, bool overwrite) #endif desktopIni.write(","); desktopIni.write(iconIndex); + if (migration) { + desktopIni.write("\r\nLocalizedResourceName="); + desktopIni.write(localizedResourceName.toUtf8()); + } desktopIni.write("\r\n"); desktopIni.close(); @@ -190,16 +195,11 @@ QString Utility::syncFolderDisplayName(const QString ¤tDisplayName, const void Utility::migrateFavLink(const QString &folder) { - //overwrite Desktop.ini, update icon - setupDesktopIni(folder, true); - const QDir folderDir(QDir::fromNativeSeparators(folder)); const auto oldDirName = folderDir.dirName(); - const auto nextcloud = QStringLiteral("Nextcloud"); - if (!oldDirName.startsWith(nextcloud)) { - qCWarning(lcUtility) << "Link name does not need to change for" << folder; - return; - } + const auto folderDisplayName = syncFolderDisplayName(oldDirName, QStringLiteral(APPLICATION_NAME)); + // overwrite Desktop.ini, update icon, update folder display name + setupDesktopIni(folder, folderDisplayName); const auto pathToLinks = systemPathToLinks(); if (pathToLinks.isEmpty()) { @@ -209,7 +209,7 @@ void Utility::migrateFavLink(const QString &folder) const QDir dirPathToLinks(pathToLinks); const auto oldLnkFilename = dirPathToLinks.filePath(oldDirName + QLatin1String(".lnk")); - const auto newLnkFilename = dirPathToLinks.filePath(syncFolderDisplayName(oldDirName, QStringLiteral(APPLICATION_NAME)) + QLatin1String(".lnk")); + const auto newLnkFilename = dirPathToLinks.filePath(folderDisplayName + QLatin1String(".lnk")); if (QFile::exists(newLnkFilename)) { qCWarning(lcUtility) << "New lnk file already exists" << newLnkFilename; @@ -248,7 +248,8 @@ void Utility::removeFavLink(const QString &folder) const QDir links(QString::fromWCharArray(path)); CoTaskMemFree(path); - const auto linkName = QDir(links).absoluteFilePath(folderDir.dirName() + QLatin1String(".lnk")); + const auto folderDisplayName = syncFolderDisplayName(folderDir.dirName(), QStringLiteral(APPLICATION_NAME)); + const auto linkName = QDir(links).absoluteFilePath(folderDisplayName + QLatin1String(".lnk")); qCDebug(lcUtility) << "Removing favorite link from" << folder << "to" << linkName; if (!QFile::remove(linkName)) {