From d17c45e59291a9154bcf16261b66f707139f9bb8 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Wed, 25 Nov 2015 20:50:48 +0100 Subject: [PATCH] Some code clean-up + removed a debug output. --- src/OSSupport_Win32.cpp | 22 ++++++++++++---------- src/Utils_Win32.cpp | 5 +++-- src/Utils_Win32.h | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/OSSupport_Win32.cpp b/src/OSSupport_Win32.cpp index dde3443..cbcd692 100644 --- a/src/OSSupport_Win32.cpp +++ b/src/OSSupport_Win32.cpp @@ -728,9 +728,9 @@ static QString get_file_path_drive_list(void) return list; } -static QString &get_file_path_translate(QString &path) +static void get_file_path_translate(QString &path) { - static const DWORD BUFSIZE = 4096; + static const DWORD BUFSIZE = 2048; wchar_t buffer[BUFSIZE], drive[3]; const QString driveList = get_file_path_drive_list(); @@ -748,8 +748,6 @@ static QString &get_file_path_translate(QString &path) } } } - - return path; } static QString get_file_path_fallback(const HANDLE &hFile) @@ -759,20 +757,25 @@ static QString get_file_path_fallback(const HANDLE &hFile) const HANDLE hFileMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 1, NULL); if (hFileMap) { - void* pMem = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 1); + void *const pMem = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 1); if (pMem) { - static const DWORD BUFSIZE = 4096; - wchar_t buffer[BUFSIZE]; - if (GetMappedFileNameW(GetCurrentProcess(), pMem, buffer, BUFSIZE)) + static const size_t BUFFSIZE = 2048; + wchar_t buffer[BUFFSIZE]; + if (GetMappedFileNameW(GetCurrentProcess(), pMem, buffer, BUFFSIZE) > 0) { - filePath = get_file_path_translate(MUTILS_QSTR(buffer)); + filePath = MUTILS_QSTR(buffer); } UnmapViewOfFile(pMem); } CloseHandle(hFileMap); } + if (!filePath.isEmpty()) + { + get_file_path_translate(filePath); + } + return filePath; } @@ -783,7 +786,6 @@ QString MUtils::OS::get_file_path(const int &fd) const GetPathNameByHandleFun getPathNameByHandleFun = MUtils::Win32Utils::resolve(QLatin1String("kernel32"), QLatin1String("GetFinalPathNameByHandleW")); if (!getPathNameByHandleFun) { - qWarning("MUtils::OS::get_file_path() --> fallback!"); return get_file_path_fallback((HANDLE)_get_osfhandle(fd)); } diff --git a/src/Utils_Win32.cpp b/src/Utils_Win32.cpp index 0be05b3..7568b1d 100644 --- a/src/Utils_Win32.cpp +++ b/src/Utils_Win32.cpp @@ -61,7 +61,7 @@ typedef QPair, FunctionMap> LibraryItem; static QReadWriteLock g_resolve_lock; static QHash g_resolve_libs; -uintptr_t MUtils::Win32Utils::resolve_helper(const QString &libraryName, const QString &functionName) +const uintptr_t &MUtils::Win32Utils::resolve_helper(const QString &libraryName, const QString &functionName) { const QString libraryNameFolded = libraryName.toCaseFolded().trimmed(); const QString functionIdTrimmed = functionName.trimmed(); @@ -97,7 +97,8 @@ uintptr_t MUtils::Win32Utils::resolve_helper(const QString &libraryName, const Q LibraryItem &lib = g_resolve_libs[libraryNameFolded]; if (lib.first.isNull() || (!lib.first->isLoaded())) { - return NULL; /*library unavailable*/ + static const uintptr_t null = NULL; + return null; /*library unavailable*/ } //Lookup the function diff --git a/src/Utils_Win32.h b/src/Utils_Win32.h index 51e82ea..d6e0bfe 100644 --- a/src/Utils_Win32.h +++ b/src/Utils_Win32.h @@ -30,7 +30,7 @@ namespace MUtils namespace Win32Utils { uintptr_t qicon_to_hicon(const QIcon &icon, const int w, const int h); - uintptr_t resolve_helper(const QString &libraryName, const QString &functionName); + const uintptr_t &resolve_helper(const QString &libraryName, const QString &functionName); template T resolve(const QString &libraryName, const QString &functionName) -- 2.11.0