From b8d5799d01d38e4a5483e4f375e0a63db954be65 Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Sun, 3 Nov 2024 08:57:50 +0000 Subject: [PATCH] Change to JackTools::GetUID() on Windows that fixes metadata creating a new BDB on every API call. JackTools::GetUID() would return the PID of the calling process. (I think this was a stub because there is no Windows equivalent). The linux version appears to return a linux UID. This patch does something similar on Windows so as to create/open the same DB on Windows. --- common/JackTools.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/common/JackTools.cpp b/common/JackTools.cpp index 94e7034d1..ca731b52f 100644 --- a/common/JackTools.cpp +++ b/common/JackTools.cpp @@ -69,8 +69,19 @@ namespace Jack { int JackTools::GetUID() { #ifdef WIN32 - return _getpid(); - //#error "No getuid function available" + HANDLE tokenHandle = nullptr; + if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &tokenHandle)) { + return 0; + } + + TOKEN_STATISTICS tokenStats; + DWORD returnLength; + if (!GetTokenInformation(tokenHandle, TokenStatistics, &tokenStats, sizeof(tokenStats), &returnLength)) { + CloseHandle(tokenHandle); + return 0; + } + + return(tokenStats.AuthenticationId.LowPart); #else return geteuid(); #endif