Merge pull request #8585 from nextcloud/bugfix/syncfolderdisplay

feat: set LocalizedResourceName for sync folders.
This commit is contained in:
Camila Ayres 2025-08-18 14:15:44 +02:00 committed by GitHub
commit 6cbccf5fc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 14 deletions

View File

@ -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
*

View File

@ -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)

View File

@ -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)

View File

@ -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 &currentDisplayName, 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)) {