Some code clean-up + removed a debug output.

This commit is contained in:
LoRd_MuldeR 2015-11-25 20:50:48 +01:00
parent 670d4dc36c
commit d17c45e592
3 changed files with 16 additions and 13 deletions

View File

@ -728,9 +728,9 @@ static QString get_file_path_drive_list(void)
return list; 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]; wchar_t buffer[BUFSIZE], drive[3];
const QString driveList = get_file_path_drive_list(); 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) 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); const HANDLE hFileMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 1, NULL);
if (hFileMap) 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) if (pMem)
{ {
static const DWORD BUFSIZE = 4096; static const size_t BUFFSIZE = 2048;
wchar_t buffer[BUFSIZE]; wchar_t buffer[BUFFSIZE];
if (GetMappedFileNameW(GetCurrentProcess(), pMem, buffer, BUFSIZE)) if (GetMappedFileNameW(GetCurrentProcess(), pMem, buffer, BUFFSIZE) > 0)
{ {
filePath = get_file_path_translate(MUTILS_QSTR(buffer)); filePath = MUTILS_QSTR(buffer);
} }
UnmapViewOfFile(pMem); UnmapViewOfFile(pMem);
} }
CloseHandle(hFileMap); CloseHandle(hFileMap);
} }
if (!filePath.isEmpty())
{
get_file_path_translate(filePath);
}
return filePath; return filePath;
} }
@ -783,7 +786,6 @@ QString MUtils::OS::get_file_path(const int &fd)
const GetPathNameByHandleFun getPathNameByHandleFun = MUtils::Win32Utils::resolve<GetPathNameByHandleFun>(QLatin1String("kernel32"), QLatin1String("GetFinalPathNameByHandleW")); const GetPathNameByHandleFun getPathNameByHandleFun = MUtils::Win32Utils::resolve<GetPathNameByHandleFun>(QLatin1String("kernel32"), QLatin1String("GetFinalPathNameByHandleW"));
if (!getPathNameByHandleFun) if (!getPathNameByHandleFun)
{ {
qWarning("MUtils::OS::get_file_path() --> fallback!");
return get_file_path_fallback((HANDLE)_get_osfhandle(fd)); return get_file_path_fallback((HANDLE)_get_osfhandle(fd));
} }

View File

@ -61,7 +61,7 @@ typedef QPair<QSharedPointer<QLibrary>, FunctionMap> LibraryItem;
static QReadWriteLock g_resolve_lock; static QReadWriteLock g_resolve_lock;
static QHash<QString, LibraryItem> g_resolve_libs; static QHash<QString, LibraryItem> 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 libraryNameFolded = libraryName.toCaseFolded().trimmed();
const QString functionIdTrimmed = functionName.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]; LibraryItem &lib = g_resolve_libs[libraryNameFolded];
if (lib.first.isNull() || (!lib.first->isLoaded())) if (lib.first.isNull() || (!lib.first->isLoaded()))
{ {
return NULL; /*library unavailable*/ static const uintptr_t null = NULL;
return null; /*library unavailable*/
} }
//Lookup the function //Lookup the function

View File

@ -30,7 +30,7 @@ namespace MUtils
namespace Win32Utils namespace Win32Utils
{ {
uintptr_t qicon_to_hicon(const QIcon &icon, const int w, const int h); 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<class T> template<class T>
T resolve(const QString &libraryName, const QString &functionName) T resolve(const QString &libraryName, const QString &functionName)