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

github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralex-z <blackslayer4@gmail.com>2021-11-19 17:03:09 +0300
committerMatthieu Gallien (Rebase PR Action) <matthieu_gallien@yahoo.fr>2021-11-23 11:32:55 +0300
commitb3914f627d598abd920b65feb88e0488458d2b85 (patch)
treed9902598a4c71bcaffeb8976c925cea0bab21f5d /src/common
parent998236dcc5ce5f12d7a340e88f2950c5bd18fbe9 (diff)
Cleanup system bindings from Windows when removing a local sync folder
Signed-off-by: alex-z <blackslayer4@gmail.com>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/utility.cpp5
-rw-r--r--src/common/utility.h1
-rw-r--r--src/common/utility_mac.cpp5
-rw-r--r--src/common/utility_unix.cpp5
-rw-r--r--src/common/utility_win.cpp34
5 files changed, 50 insertions, 0 deletions
diff --git a/src/common/utility.cpp b/src/common/utility.cpp
index bd9394b8c..3adb9a4de 100644
--- a/src/common/utility.cpp
+++ b/src/common/utility.cpp
@@ -109,6 +109,11 @@ void Utility::setupFavLink(const QString &folder)
setupFavLink_private(folder);
}
+void Utility::removeFavLink(const QString &folder)
+{
+ removeFavLink_private(folder);
+}
+
QString Utility::octetsToString(qint64 octets)
{
#define THE_FACTOR 1024
diff --git a/src/common/utility.h b/src/common/utility.h
index 9522d188e..349791644 100644
--- a/src/common/utility.h
+++ b/src/common/utility.h
@@ -55,6 +55,7 @@ namespace Utility {
OCSYNC_EXPORT void usleep(int usec);
OCSYNC_EXPORT QString formatFingerprint(const QByteArray &, bool colonSeparated = true);
OCSYNC_EXPORT void setupFavLink(const QString &folder);
+ OCSYNC_EXPORT void removeFavLink(const QString &folder);
OCSYNC_EXPORT bool writeRandomFile(const QString &fname, int size = -1);
OCSYNC_EXPORT QString octetsToString(qint64 octets);
OCSYNC_EXPORT QByteArray userAgentString();
diff --git a/src/common/utility_mac.cpp b/src/common/utility_mac.cpp
index c093d8805..f11cf0b8f 100644
--- a/src/common/utility_mac.cpp
+++ b/src/common/utility_mac.cpp
@@ -41,6 +41,11 @@ static void setupFavLink_private(const QString &folder)
CFRelease(urlRef);
}
+static void removeFavLink_private(const QString &folder)
+{
+ Q_UNUSED(folder)
+}
+
bool hasLaunchOnStartup_private(const QString &)
{
// this is quite some duplicate code with setLaunchOnStartup, at some point we should fix this FIXME.
diff --git a/src/common/utility_unix.cpp b/src/common/utility_unix.cpp
index 087254e60..d99475738 100644
--- a/src/common/utility_unix.cpp
+++ b/src/common/utility_unix.cpp
@@ -37,6 +37,11 @@ static void setupFavLink_private(const QString &folder)
}
}
+static void removeFavLink_private(const QString &folder)
+{
+ Q_UNUSED(folder)
+}
+
// returns the autostart directory the linux way
// and respects the XDG_CONFIG_HOME env variable
QString getUserAutostartDir_private()
diff --git a/src/common/utility_win.cpp b/src/common/utility_win.cpp
index c6f9c0066..2c14ccb1f 100644
--- a/src/common/utility_win.cpp
+++ b/src/common/utility_win.cpp
@@ -74,6 +74,40 @@ static void setupFavLink_private(const QString &folder)
qCWarning(lcUtility) << "linking" << folder << "to" << linkName << "failed!";
}
+static void removeFavLink_private(const QString &folder)
+{
+ const QDir folderDir(folder);
+
+ // #1 Remove the Desktop.ini to reset the folder icon
+ if (!QFile::remove(folderDir.absoluteFilePath(QLatin1String("Desktop.ini")))) {
+ qCWarning(lcUtility) << "Remove Desktop.ini from" << folder
+ << " has failed. Make sure it exists and is not locked by another process.";
+ }
+
+ // #2 Remove the system file attribute
+ const auto folderAttrs = GetFileAttributesW(folder.toStdWString().c_str());
+ if (!SetFileAttributesW(folder.toStdWString().c_str(), folderAttrs & ~FILE_ATTRIBUTE_SYSTEM)) {
+ qCWarning(lcUtility) << "Remove system file attribute failed for:" << folder;
+ }
+
+ // #3 Remove the link to this folder
+ PWSTR path;
+ if (!SHGetKnownFolderPath(FOLDERID_Links, 0, nullptr, &path) == S_OK) {
+ qCWarning(lcUtility) << "SHGetKnownFolderPath for " << folder << "has failed.";
+ return;
+ }
+
+ const QDir links(QString::fromWCharArray(path));
+ CoTaskMemFree(path);
+
+ const auto linkName = QDir(links).absoluteFilePath(folderDir.dirName() + QLatin1String(".lnk"));
+
+ qCInfo(lcUtility) << "Removing favorite link from" << folder << "to" << linkName;
+ if (!QFile::remove(linkName)) {
+ qCWarning(lcUtility) << "Removing a favorite link from" << folder << "to" << linkName << "failed.";
+ }
+}
+
bool hasSystemLaunchOnStartup_private(const QString &appName)
{
QString runPath = QLatin1String(systemRunPathC);