Windows: Make sure that the folder and Desktop.ini have the right attributes (#6018)
authorJocelyn Turcotte <jturcotte@woboq.com>
Mon, 11 Sep 2017 13:32:42 +0000 (15:32 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Thu, 5 Oct 2017 20:01:04 +0000 (22:01 +0200)
When created from scratch, the owncloud icon won't be picked-up by
explorer unless the right attributes are set on both the sync root and the
Desktop.ini file.

Issue #2446

src/common/utility_win.cpp

index f7fef1019313e737c367c1eb1f17e0376f32d52b..5374b098649035c584152eca4da71a50e102787e 100644 (file)
@@ -43,6 +43,12 @@ static void setupFavLink_private(const QString &folder)
         desktopIni.write(QDir::toNativeSeparators(qApp->applicationFilePath()).toUtf8());
         desktopIni.write(",0\r\n");
         desktopIni.close();
+
+        // Set the folder as system and Desktop.ini as hidden+system for explorer to pick it.
+        // https://msdn.microsoft.com/en-us/library/windows/desktop/cc144102
+        DWORD folderAttrs = GetFileAttributesW((wchar_t *)folder.utf16());
+        SetFileAttributesW((wchar_t *)folder.utf16(), folderAttrs | FILE_ATTRIBUTE_SYSTEM);
+        SetFileAttributesW((wchar_t *)desktopIni.fileName().utf16(), FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
     }
 
     // Windows Explorer: Place under "Favorites" (Links)