[Pkg-owncloud-commits] [owncloud-client] 09/498: Use dynamic library loading for detecting the correct path for links
Sandro Knauß
hefee-guest at moszumanska.debian.org
Tue Aug 11 14:48:28 UTC 2015
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit 4e56b0d266c486c2efc1d6c37ac97f51cd8360c1
Author: Luca Lorenzetto <luca.lorenzetto at infocamere.it>
Date: Wed Mar 4 17:28:43 2015 +0100
Use dynamic library loading for detecting the correct path for links
---
src/libsync/utility_win.cpp | 51 +++++++++++++++++++++++++++++++++++++++++----
1 file changed, 47 insertions(+), 4 deletions(-)
diff --git a/src/libsync/utility_win.cpp b/src/libsync/utility_win.cpp
index f450967..b7fed27 100644
--- a/src/libsync/utility_win.cpp
+++ b/src/libsync/utility_win.cpp
@@ -14,19 +14,62 @@
#include <shlobj.h>
#include <winbase.h>
#include <windows.h>
+#include <shlguid.h>
+#include <string>
+#include <QLibrary>
static const char runPathC[] = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
+typedef HRESULT (WINAPI *SHGetKnownFolderPathFun)(
+ const GUID &rfid,
+ DWORD dwFlags,
+ HANDLE hToken,
+ PWSTR *ppszPath
+);
+typedef HRESULT (WINAPI *SHGetFolderPathFun)(
+ HWND hwndOwner,
+ int nFolder,
+ HANDLE hToken,
+ DWORD dwFlags,
+ LPWSTR pszPath
+);
+
static void setupFavLink_private(const QString &folder)
{
// Windows Explorer: Place under "Favorites" (Links)
- wchar_t path[MAX_PATH];
- SHGetSpecialFolderPath(0, path, CSIDL_PROFILE, FALSE);
- QString profile = QDir::fromNativeSeparators(QString::fromWCharArray(path));
+
+ SHGetKnownFolderPathFun SHGetKnownFolderPathPtr = NULL;
+ SHGetFolderPathFun SHGetFolderPathPtr = NULL;
+ QString linkName;
QDir folderDir(QDir::fromNativeSeparators(folder));
- QString linkName = profile+QLatin1String("/Links/") + folderDir.dirName() + QLatin1String(".lnk");
+ if((!SHGetKnownFolderPathPtr) && (!SHGetFolderPathPtr))
+ {
+ QLibrary kernel32Lib("shell32.dll");
+ if(kernel32Lib.load())
+ {
+ SHGetKnownFolderPathPtr = (SHGetKnownFolderPathFun) kernel32Lib.resolve("SHGetKnownFolderPath");
+ SHGetFolderPathPtr = (SHGetFolderPathFun) kernel32Lib.resolve("SHGetFolderPathW");
+ }
+ }
+
+ if(SHGetKnownFolderPathPtr) {
+ /* Use new WINAPI functions */
+ wchar_t *path = NULL;
+ if(SHGetKnownFolderPathPtr(FOLDERID_Links, 0, NULL, &path) == S_OK) {
+ QString Links= QDir::fromNativeSeparators(QString::fromWCharArray(path));
+ linkName = Links + folderDir.dirName() + QLatin1String(".lnk");
+ }
+ } else {
+ /* Use legacy functions */
+ wchar_t path[MAX_PATH];
+ SHGetSpecialFolderPath(0, path, CSIDL_PROFILE, FALSE);
+ QString profile = QDir::fromNativeSeparators(QString::fromWCharArray(path));
+ linkName = profile+QLatin1String("/Links/") + folderDir.dirName() + QLatin1String(".lnk");
+ }
+ qDebug() << Q_FUNC_INFO << " creating link from " << linkName << " to " << folder;
if (!QFile::link(folder, linkName))
qDebug() << Q_FUNC_INFO << "linking" << folder << "to" << linkName << "failed!";
+
}
bool hasLaunchOnStartup_private(const QString &appName)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list