test: fixed unnamed sessions

This commit is contained in:
Hane 2024-06-06 20:08:36 +02:00
commit 73251b4f3b
5 changed files with 92 additions and 31 deletions

View file

@ -475,7 +475,7 @@ void Endpoint::setFlow() {
if(FAILED(this->endpoint->QueryInterface(__uuidof(IMMEndpoint), (void**)&flowGetter)))
{ log_debugcpp("no flow..."); }
EDataFlow MSflow;
HRESULT vafllar = flowGetter->GetDataFlow(&MSflow);
flowGetter->GetDataFlow(&MSflow);
this->flow = (MSflow == EDataFlow::eRender ? Flows::FLOW_PLAYBACK : Flows::FLOW_CAPTURE);
log_debugcpp("Endpoint flow: " + std::to_string(flow));
flowGetter->Release();

View file

@ -196,10 +196,13 @@ std::wstring Session::fetchProcessName(DWORD pid) {
/*
* https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-tlhelp32-createtoolhelp32snapshot
* https://stackoverflow.com/questions/11843368/how-to-get-process-description
* https://notes.indezine.com/2018/05/microsoft-locale-ids.html#:~:text=Wait%2C%201033%20is%20the%20decimal,ID%20for%20English%20%E2%80%93%20United%20States.
* https://stackoverflow.com/questions/64321036/c-win32-getting-app-name-using-pid-and-executable-path
*/
/* Executable path retrieval */
std::wstring exePath = L"";
std::wstring msixName;
HANDLE processList = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, pid);
if (processList == INVALID_HANDLE_VALUE) {
@ -224,55 +227,111 @@ std::wstring Session::fetchProcessName(DWORD pid) {
}
CloseHandle(processList);
/* File description retrieval */
/* File description retrieval: size and available lang-codepages */
struct LANGANDCODEPAGE {
WORD wLanguage;
WORD wCodePage;
} *translationArray;
DWORD filler;
DWORD fileVersionInfoSize = GetFileVersionInfoSizeW(exePath.c_str(), &filler);
DWORD fileVersionInfoSize = GetFileVersionInfoSizeExW
(FILE_VER_GET_LOCALISED | FILE_VER_GET_NEUTRAL, exePath.c_str(), &filler);
if (!fileVersionInfoSize) return exePath;
void* fileVersionInfo = malloc(fileVersionInfoSize);
if(!GetFileVersionInfoW(exePath.c_str(),0,fileVersionInfoSize, fileVersionInfo))
if(!GetFileVersionInfoExW(FILE_VER_GET_LOCALISED | FILE_VER_GET_NEUTRAL,
exePath.c_str(),0,fileVersionInfoSize, fileVersionInfo))
return exePath;
UINT translationArrayLen = 0;
if (!VerQueryValueW(fileVersionInfo, L"\\VarFileInfo\\Translation", (LPVOID*)&translationArray, &translationArrayLen))
return exePath;
bool match = false;
for (UINT i = 0; i < (translationArrayLen / sizeof(LANGANDCODEPAGE)); i++) {
wchar_t fileDescriptionKey[256];
//File descriptor parsing
//TODO: https://learn.microsoft.com/en-us/windows/win32/api/winnls/nf-winnls-getuserpreferreduilanguages
/* It is possible to retrieve user languages and try to use one of those before falling back to whatever
* is available. Also possible to hardcode en-US or any other lang-codepage combo. When an actual translation
* sysem is put in place, I'll come finish this up.
*/
uint64_t availableLangs = (translationArrayLen / sizeof(LANGANDCODEPAGE));
if (!availableLangs) return exePath;
int8_t syslangIdx = -1;
wchar_t metadataStringKey[256];
wchar_t* metadataString = NULL;
//std::wstring name;
for (UINT i = 0; i < availableLangs; i++) {
LANGID defaultUILanguage = GetUserDefaultUILanguage();
if (defaultUILanguage != translationArray[i].wLanguage)
continue;
match = true;
wchar_t* fileDescription = NULL;
UINT fileDescriptionSize = 0;
swprintf(fileDescriptionKey, L"\\StringFileInfo\\%04x%04x\\FileDescription",
translationArray[i].wLanguage, translationArray[i].wCodePage);
if (VerQueryValueW(fileVersionInfo, fileDescriptionKey, (LPVOID*)&fileDescription, &fileDescriptionSize)) {
exePath = std::wstring(fileDescription);
}
syslangIdx = i;
break;
}
if (!match && 1 <= (translationArrayLen / sizeof(LANGANDCODEPAGE))) {
wchar_t fileDescriptionKey[256];
UINT metadataStringSize = 0;
swprintf(metadataStringKey, L"\\StringFileInfo\\%04x%04x\\FileDescription",
translationArray[(syslangIdx < 0 ? 0 : syslangIdx)].wLanguage,
translationArray[(syslangIdx < 0 ? 0 : syslangIdx)].wCodePage);
if (VerQueryValueW(fileVersionInfo, metadataStringKey, (LPVOID*)&metadataString, &metadataStringSize)
&& metadataString[0] != '\0') {
return std::wstring(metadataString);
}
swprintf(metadataStringKey, L"\\StringFileInfo\\%04x%04x\\ProductName",
translationArray[(syslangIdx < 0 ? 0 : syslangIdx)].wLanguage,
translationArray[(syslangIdx < 0 ? 0 : syslangIdx)].wCodePage);
if (VerQueryValueW(fileVersionInfo, metadataStringKey, (LPVOID*)&metadataString, &metadataStringSize)
&& metadataString[0] != '\0') {
return std::wstring(metadataString);
}
wchar_t* fileDescription = NULL;
UINT fileDescriptionSize = 0;
swprintf(fileDescriptionKey, L"\\StringFileInfo\\%04x%04x\\FileDescription",
translationArray[0].wLanguage, translationArray[0].wCodePage);
if (VerQueryValueW(fileVersionInfo, fileDescriptionKey, (LPVOID*)&fileDescription, &fileDescriptionSize)) {
exePath = std::wstring(fileDescription);
}
}
//MSIX?
HANDLE process = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
if(!process) return exePath;
free(fileVersionInfo);
return exePath;
//constant missing in mingw64. TB removed when I upgrade to a mingw64 ver that has it
#define APPLICATION_USER_MODEL_ID_MAX_LENGTH 130
uint32_t length = APPLICATION_USER_MODEL_ID_MAX_LENGTH;
PWSTR userModelId = (PWSTR)malloc(length * sizeof(wchar_t));
if(GetApplicationUserModelId(process, &length, userModelId) != ERROR_SUCCESS) {
CloseHandle(process);
return exePath;
}
CloseHandle(process);
static constexpr wchar_t* prefix = L"shell:appsfolder\\";
uint32_t prefixLen = wcslen(prefix);
uint32_t userModelIdLen = wcslen(userModelId);
wchar_t* fullName;
fullName = (prefixLen + userModelIdLen < length)
? (wchar_t*)malloc(length * sizeof(wchar_t))
: (wchar_t*)malloc((length * 2) * sizeof(wchar_t));
for (int32_t i = prefixLen - 1; i >= 0; i--) {
fullName[i] = prefix[i];
}
for (uint32_t i = 0; i < userModelIdLen + 1; i++) {
fullName[prefixLen + i] = userModelId[i];
}
IShellItem* si;
HRESULT hr = SHCreateItemFromParsingName(fullName,
nullptr,
IID_IShellItem,
(void**)&si
);
free(fullName);
LPWSTR humanName = nullptr;
si->GetDisplayName(SIGDN_NORMALDISPLAY, &humanName);
if(humanName && humanName[0] != '\0') {
msixName = std::wstring(humanName);
CoTaskMemFree(humanName);
}
if(si) si->Release();
if (msixName.length() > 0)
return msixName;
else return exePath;
//free(fileVersionInfo);
}
//todo: conflicting names. change callback name

View file

@ -7,6 +7,8 @@
#include <Windows.h>
#include <shellapi.h>
#include <Shobjidl.h>
#include <appmodel.h>
#include <processthreadsapi.h>
#include <mmdeviceapi.h>
#include <combaseapi.h>

View file

@ -263,7 +263,7 @@ void MainWindow::compose() {
log_to_file("dpr: %f \n", dpr);
for (auto *epw : ews) {
if (!epw) continue;
epw->calculateSize(windowWidth * dpr,screenHeight * screen->devicePixelRatio());
epw->calculateSize(windowWidth, screenHeight);
log_debugcpp("epw loop");
log_debugcpp("epw roles: " + print_as_binary((epw->getEndpointHandler()->getRoles())));
//std::bitset<sizeof(uint8_t)> content =

View file

@ -86,7 +86,7 @@ namespace StylingHelper {
#endif
}
static inline qreal calculateDpi(const QScreen screen) {
static inline qreal calculateDpi() {
return QFontMetrics(QApplication::font()).fontDpi();
}