setupFavLink_private(folder);
}
+void Utility::removeFavLink(const QString &folder)
+{
+ removeFavLink_private(folder);
+}
+
QString Utility::octetsToString(qint64 octets)
{
#define THE_FACTOR 1024
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();
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.
}
}
+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()
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);
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);