2013-10-02 21:06:33 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2013-10-02 21:06:33 +04:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
2017-04-27 11:34:07 +03:00
|
|
|
#define _WIN32_WINNT 0x0600
|
|
|
|
#define WINVER 0x0600
|
2013-10-02 21:06:33 +04:00
|
|
|
#include <shlobj.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <windows.h>
|
2017-04-27 11:34:07 +03:00
|
|
|
#include <winerror.h>
|
|
|
|
#include <shlguid.h>
|
|
|
|
#include <string>
|
|
|
|
#include <QLibrary>
|
2013-10-02 21:06:33 +04:00
|
|
|
|
|
|
|
static const char runPathC[] = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
|
|
|
|
2017-05-09 15:24:11 +03:00
|
|
|
namespace OCC {
|
2017-05-17 11:55:42 +03:00
|
|
|
|
2013-10-02 21:06:33 +04:00
|
|
|
static void setupFavLink_private(const QString &folder)
|
|
|
|
{
|
2017-08-11 18:19:02 +03:00
|
|
|
// First create a Desktop.ini so that the folder and favorite link show our application's icon.
|
|
|
|
QFile desktopIni(folder + QLatin1String("/Desktop.ini"));
|
|
|
|
if (desktopIni.exists()) {
|
|
|
|
qCWarning(lcUtility) << desktopIni.fileName() << "already exists, not overwriting it to set the folder icon.";
|
|
|
|
} else {
|
|
|
|
qCInfo(lcUtility) << "Creating" << desktopIni.fileName() << "to set a folder icon in Explorer.";
|
|
|
|
desktopIni.open(QFile::WriteOnly);
|
|
|
|
desktopIni.write("[.ShellClassInfo]\r\nIconResource=");
|
|
|
|
desktopIni.write(QDir::toNativeSeparators(qApp->applicationFilePath()).toUtf8());
|
|
|
|
desktopIni.write(",0\r\n");
|
|
|
|
desktopIni.close();
|
|
|
|
}
|
2017-05-17 11:55:42 +03:00
|
|
|
|
2017-08-11 18:19:02 +03:00
|
|
|
// Windows Explorer: Place under "Favorites" (Links)
|
2017-04-27 11:34:07 +03:00
|
|
|
QString linkName;
|
2013-10-02 21:06:33 +04:00
|
|
|
QDir folderDir(QDir::fromNativeSeparators(folder));
|
2017-05-17 11:55:42 +03:00
|
|
|
|
2017-04-27 11:34:07 +03:00
|
|
|
/* Use new WINAPI functions */
|
|
|
|
PWSTR path;
|
2017-05-17 11:55:42 +03:00
|
|
|
|
2017-04-27 11:34:07 +03:00
|
|
|
if (SHGetKnownFolderPath(FOLDERID_Links, 0, NULL, &path) == S_OK) {
|
|
|
|
QString links = QDir::fromNativeSeparators(QString::fromWCharArray(path));
|
|
|
|
linkName = QDir(links).filePath(folderDir.dirName() + QLatin1String(".lnk"));
|
|
|
|
CoTaskMemFree(path);
|
|
|
|
}
|
2017-08-11 18:19:02 +03:00
|
|
|
qCInfo(lcUtility) << "Creating favorite link from" << folder << "to" << linkName;
|
2013-10-02 21:06:33 +04:00
|
|
|
if (!QFile::link(folder, linkName))
|
2017-03-30 14:46:20 +03:00
|
|
|
qCWarning(lcUtility) << "linking" << folder << "to" << linkName << "failed!";
|
2013-10-02 21:06:33 +04:00
|
|
|
}
|
|
|
|
|
2017-04-27 11:34:07 +03:00
|
|
|
|
2013-10-02 21:06:33 +04:00
|
|
|
bool hasLaunchOnStartup_private(const QString &appName)
|
|
|
|
{
|
|
|
|
QString runPath = QLatin1String(runPathC);
|
|
|
|
QSettings settings(runPath, QSettings::NativeFormat);
|
|
|
|
return settings.contains(appName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setLaunchOnStartup_private(const QString &appName, const QString &guiName, bool enable)
|
|
|
|
{
|
|
|
|
Q_UNUSED(guiName);
|
|
|
|
QString runPath = QLatin1String(runPathC);
|
|
|
|
QSettings settings(runPath, QSettings::NativeFormat);
|
|
|
|
if (enable) {
|
|
|
|
settings.setValue(appName, QCoreApplication::applicationFilePath().replace('/', '\\'));
|
|
|
|
} else {
|
|
|
|
settings.remove(appName);
|
|
|
|
}
|
|
|
|
}
|
2014-10-24 23:52:41 +04:00
|
|
|
|
|
|
|
static inline bool hasDarkSystray_private()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2017-05-09 15:24:11 +03:00
|
|
|
|
|
|
|
} // namespace OCC
|