Windows: Use the application icon for the sidebar
authorJocelyn Turcotte <jturcotte@woboq.com>
Fri, 11 Aug 2017 15:19:02 +0000 (17:19 +0200)
committerJocelyn Turcotte <jturcotte@woboq.com>
Tue, 15 Aug 2017 11:37:33 +0000 (13:37 +0200)
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

index f46cde4d548127c61ac3469addf19290546b916d..3762808b7b22f29842ef38a7dac5a1be764b55c4 100644 (file)
@@ -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!";
 }