Merge pull request #3994 from nextcloud/bugfix/reset-syncfolder-icon

Cleanup system bindings from Windows when removing a local sync folder
This commit is contained in:
Matthieu Gallien 2021-11-23 10:58:06 +01:00 committed by GitHub
commit c89d2abf5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 0 deletions

View File

@ -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

View File

@ -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();

View File

@ -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.

View File

@ -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()

View File

@ -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);

View File

@ -761,6 +761,7 @@ void AccountSettings::slotRemoveCurrentFolder()
messageBox->addButton(tr("Cancel"), QMessageBox::NoRole);
connect(messageBox, &QMessageBox::finished, this, [messageBox, yesButton, folder, row, this]{
if (messageBox->clickedButton() == yesButton) {
Utility::removeFavLink(folder->path());
FolderMan::instance()->removeFolder(folder);
_model->removeRow(row);