From 251f1d0047971f54f4167a9db326fea763a61462 Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Fri, 11 Aug 2017 17:19:02 +0200 Subject: [PATCH] Windows: Use the application icon for the sidebar By setting the icon in Desktop.ini of the root folder, this adds the icon both when browsing the folder directly and to the sidebar shortcut. To avoid overwriting any user setting that could exist in Desktop.ini, only do this if the file doesn't exist. Editing .ini files on Windows isn't trivial and isn't worth it given that this file won't exist most of the time. Fixes #2446 --- src/libsync/utility_win.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libsync/utility_win.cpp b/src/libsync/utility_win.cpp index f46cde4d5..3762808b7 100644 --- a/src/libsync/utility_win.cpp +++ b/src/libsync/utility_win.cpp @@ -28,8 +28,20 @@ namespace OCC { static void setupFavLink_private(const QString &folder) { - // Windows Explorer: Place under "Favorites" (Links) + // First create a Desktop.ini so that the folder and favorite link show our application's icon. + QFile desktopIni(folder + QLatin1String("/Desktop.ini")); + if (desktopIni.exists()) { + qCWarning(lcUtility) << desktopIni.fileName() << "already exists, not overwriting it to set the folder icon."; + } else { + qCInfo(lcUtility) << "Creating" << desktopIni.fileName() << "to set a folder icon in Explorer."; + desktopIni.open(QFile::WriteOnly); + desktopIni.write("[.ShellClassInfo]\r\nIconResource="); + desktopIni.write(QDir::toNativeSeparators(qApp->applicationFilePath()).toUtf8()); + desktopIni.write(",0\r\n"); + desktopIni.close(); + } + // Windows Explorer: Place under "Favorites" (Links) QString linkName; QDir folderDir(QDir::fromNativeSeparators(folder)); @@ -41,7 +53,7 @@ static void setupFavLink_private(const QString &folder) linkName = QDir(links).filePath(folderDir.dirName() + QLatin1String(".lnk")); CoTaskMemFree(path); } - qCDebug(lcUtility) << " creating link from " << linkName << " to " << folder; + qCInfo(lcUtility) << "Creating favorite link from" << folder << "to" << linkName; if (!QFile::link(folder, linkName)) qCWarning(lcUtility) << "linking" << folder << "to" << linkName << "failed!"; }