Skip to content

Commit 0d89ee4

Browse files
camilasanbackportbot[bot]
authored andcommitted
fix(common): preserve Windows Explorer custom folder icons during migration.
Check the encoding of the Desktop.ini file to determine if it should be overwritten or preserved: - Windows Explorer writes Desktop.ini in UTF-16LE (custom icon), - While the client always writes UTF-8 (default icon). Fixes the regression introduced by d60c760. Signed-off-by: Camila Ayres <hello@camilasan.com>
1 parent 46f5846 commit 0d89ee4

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)