Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHannah von Reth <hannah.vonreth@owncloud.com>2022-11-08 12:03:37 +0300
committerGitHub <noreply@github.com>2022-11-08 12:03:37 +0300
commit8493878bf4865102420fd97286f05328d8db5074 (patch)
tree9f32d2b149fedbac04d54c044d7db0fe839b3bda
parent53acfd40d7e0cc716caade7c903e23830c9a7aaa (diff)
Update the folder icon on every run (#10245)
Fixes: #10184
-rw-r--r--changelog/unreleased/101846
-rw-r--r--src/gui/folder.cpp30
-rw-r--r--src/gui/folder.h2
-rw-r--r--src/gui/folderman.cpp26
-rw-r--r--src/gui/owncloudgui.cpp1
5 files changed, 40 insertions, 25 deletions
diff --git a/changelog/unreleased/10184 b/changelog/unreleased/10184
new file mode 100644
index 000000000..181a92f02
--- /dev/null
+++ b/changelog/unreleased/10184
@@ -0,0 +1,6 @@
+Change: Windows: Update the folder icon on every start
+
+The ownCloud installation path might have changed, causing the desktop.ini to point at the wrong path.
+We now update the icon location on every application start.
+
+https://github.com/owncloud/client/issues/10184
diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp
index a155c84b1..c304fc551 100644
--- a/src/gui/folder.cpp
+++ b/src/gui/folder.cpp
@@ -113,6 +113,7 @@ Folder::Folder(const FolderDefinition &definition,
// check if the local path exists
if (checkLocalPath()) {
+ prepareFolder(path());
// those errors should not persist over sessions
_journal.wipeErrorBlacklistCategory(SyncJournalErrorBlacklistRecord::Category::LocalSoftError);
_engine.reset(new SyncEngine(_accountState->account(), webDavUrl(), path(), remotePath(), &_journal));
@@ -263,6 +264,35 @@ SyncOptions Folder::loadSyncOptions()
return opt;
}
+void Folder::prepareFolder(const QString &path)
+{
+#ifdef Q_OS_WIN
+ // First create a Desktop.ini so that the folder and favorite link show our application's icon.
+ const QFileInfo desktopIniPath = QStringLiteral("%1/Desktop.ini").arg(path);
+ {
+ QSettings desktopIni(desktopIniPath.absoluteFilePath(), QSettings::IniFormat);
+ qCInfo(lcFolder) << "Creating" << desktopIni.fileName() << "to set a folder icon in Explorer.";
+ desktopIni.beginGroup(QStringLiteral(".ShellClassInfo"));
+ desktopIni.setValue(QStringLiteral("IconResource"), QDir::toNativeSeparators(qApp->applicationFilePath()));
+ desktopIni.sync();
+ }
+
+ const QString longFolderPath = FileSystem::longWinPath(path);
+ const QString longDesktopIniPath = FileSystem::longWinPath(desktopIniPath.absoluteFilePath());
+ // 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
+ const DWORD folderAttrs = GetFileAttributesW(reinterpret_cast<const wchar_t *>(longFolderPath.utf16()));
+ if (!SetFileAttributesW(reinterpret_cast<const wchar_t *>(longFolderPath.utf16()), folderAttrs | FILE_ATTRIBUTE_SYSTEM)) {
+ const auto error = GetLastError();
+ qCWarning(lcFolder) << "SetFileAttributesW failed on" << longFolderPath << Utility::formatWinError(error);
+ }
+ if (!SetFileAttributesW(reinterpret_cast<const wchar_t *>(longDesktopIniPath.utf16()), FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) {
+ const auto error = GetLastError();
+ qCWarning(lcFolder) << "SetFileAttributesW failed on" << longDesktopIniPath << Utility::formatWinError(error);
+ }
+#endif
+}
+
QByteArray Folder::id() const
{
return _definition.id();
diff --git a/src/gui/folder.h b/src/gui/folder.h
index aeaee7fda..8f22d6cc1 100644
--- a/src/gui/folder.h
+++ b/src/gui/folder.h
@@ -163,6 +163,8 @@ public:
};
Q_ENUM(ChangeReason)
+ static void prepareFolder(const QString &path);
+
/** Create a new Folder
*/
Folder(const FolderDefinition &definition, const AccountStatePtr &accountState, std::unique_ptr<Vfs> &&vfs, QObject *parent = nullptr);
diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp
index 704380d2c..42092ef82 100644
--- a/src/gui/folderman.cpp
+++ b/src/gui/folderman.cpp
@@ -1459,31 +1459,7 @@ bool FolderMan::prepareFolder(const QString &folder)
return false;
}
FileSystem::setFolderMinimumPermissions(folder);
-
-#ifdef Q_OS_WIN
- // First create a Desktop.ini so that the folder and favorite link show our application's icon.
- // TODO: as we only write the file once the path to owncloud.exe can be outdated
- QFile desktopIni(folder + QStringLiteral("/Desktop.ini"));
- if (desktopIni.exists()) {
- qCWarning(lcFolderMan) << desktopIni.fileName() << "already exists, not overwriting it to set the folder icon.";
- } else {
- qCInfo(lcFolderMan) << "Creating" << desktopIni.fileName() << "to set a folder icon in Explorer.";
- if (OC_ENSURE(desktopIni.open(QFile::WriteOnly))) {
- desktopIni.write("[.ShellClassInfo]\r\nIconResource=");
- desktopIni.write(QDir::toNativeSeparators(qApp->applicationFilePath()).toUtf8());
- desktopIni.write(",0\r\n");
- desktopIni.close();
- }
-
- const QString longFolderPath = FileSystem::longWinPath(folder);
- const QString longDesktopIniPath = FileSystem::longWinPath(desktopIni.fileName());
- // 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
- const DWORD folderAttrs = GetFileAttributesW(reinterpret_cast<const wchar_t *>(longFolderPath.utf16()));
- SetFileAttributesW(reinterpret_cast<const wchar_t *>(longFolderPath.utf16()), folderAttrs | FILE_ATTRIBUTE_SYSTEM);
- SetFileAttributesW(reinterpret_cast<const wchar_t *>(longDesktopIniPath.utf16()), FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
- }
-#endif
+ Folder::prepareFolder(folder);
}
return true;
}
diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp
index f6a7e47cd..4d41d5d34 100644
--- a/src/gui/owncloudgui.cpp
+++ b/src/gui/owncloudgui.cpp
@@ -77,6 +77,7 @@ void setUpInitialSyncFolder(AccountStatePtr accountStatePtr, bool useVfs)
if (!drives.isEmpty()) {
const QDir localDir(accountStatePtr->account()->defaultSyncRoot());
FileSystem::setFolderMinimumPermissions(localDir.path());
+ Folder::prepareFolder(localDir.path());
Utility::setupFavLink(localDir.path());
for (const auto &d : drives) {
const QString name = GraphApi::Drives::getDriveDisplayName(d);