Skip to content

Commit db0ee25

Browse files
authored
Merge pull request #10132 from nextcloud/backport/9872/stable-3.17
[stable-3.17] fix(common): preserve Windows Explorer custom folder icons during migration.
2 parents 46f5846 + 0d89ee4 commit db0ee25

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/common/utility_win.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,23 @@ void Utility::setupDesktopIni(const QString &folder, const QString localizedReso
123123
// First create a Desktop.ini so that the folder and favorite link show our application's icon.
124124
QFile desktopIni(folder + QLatin1String("/Desktop.ini"));
125125
const auto migration = !localizedResourceName.isEmpty();
126-
if (!migration && desktopIni.exists()) {
127-
qCWarning(lcUtility) << desktopIni.fileName() << "already exists, not overwriting it to set the folder icon.";
128-
return;
126+
if (desktopIni.exists()) {
127+
if (!migration) {
128+
qCWarning(lcUtility) << desktopIni.fileName() << "already exists, not overwriting it to set the folder icon.";
129+
return;
130+
}
131+
if (!desktopIni.open(QFile::ReadOnly)) {
132+
qCWarning(lcUtility) << "Cannot read" << desktopIni.fileName() << "to check encoding; skipping icon migration.";
133+
return;
134+
}
135+
const auto desktopIniContent = desktopIni.read(2);
136+
desktopIni.close();
137+
if (desktopIniContent.startsWith("\xFF\xFE") || desktopIniContent.startsWith("\xFE\xFF")) {
138+
qCWarning(lcUtility) << desktopIni.fileName() << "is UTF-16 encoded (Windows Explorer custom icon), preserving it.";
139+
return;
140+
}
141+
// If the file is not UTF-16 encoded, we assume it is not a custom icon: overwritte it with the new icon and set the localized resource name
129142
}
130-
131143
qCDebug(lcUtility) << "Creating" << desktopIni.fileName() << "to set a folder icon in Explorer.";
132144
desktopIni.open(QFile::WriteOnly);
133145
desktopIni.write("[.ShellClassInfo]\r\nIconResource=");

0 commit comments

Comments
 (0)