session shown name parsing, pending refactor
This commit is contained in:
parent
517f117575
commit
e42dbaa194
2 changed files with 31 additions and 14 deletions
|
|
@ -128,11 +128,14 @@ Session::Session(Endpoint* ep, IAudioSessionControl2* sessionControl, size_t idx
|
|||
this->sessionControl->GetDisplayName(&sessionDisplayName);
|
||||
if (!wcscmp(sessionDisplayName, L"")) {
|
||||
std::wstring exePath;
|
||||
if (getExePath(pid, &exePath))
|
||||
fetchName(exePath, pid);
|
||||
else this->sessionName = std::wstring(LSTRING_UNNAMED_SESSION);
|
||||
if (getExePath(pid, &exePath)) {
|
||||
if (fetchName(exePath, pid)) goto nameFound;
|
||||
}
|
||||
if (fetchNameViaWindowName(pid, &this->sessionName)) goto nameFound;
|
||||
} else
|
||||
this->sessionName = std::wstring(sessionDisplayName);
|
||||
|
||||
nameFound:
|
||||
CoTaskMemFree(sessionDisplayName);
|
||||
}
|
||||
}
|
||||
|
|
@ -207,7 +210,7 @@ bool Session::getExePath(DWORD pid, std::wstring *exePath) {
|
|||
|
||||
HANDLE processList = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, pid);
|
||||
if (processList == INVALID_HANDLE_VALUE) {
|
||||
log_wdebugcpp(L"aye no procname.");
|
||||
log_wdebugcpp(L"aye no procname. -> " + std::to_wstring(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -351,7 +354,7 @@ bool Session::fetchNameViaMSIX(std::wstring exePath, DWORD pid, std::wstring *se
|
|||
}
|
||||
|
||||
|
||||
bool Session::fetchNameViaWindowName(std::wstring exePath, DWORD pid, std::wstring *sessionName) {
|
||||
bool Session::fetchNameViaWindowName(DWORD pid, std::wstring *sessionName) {
|
||||
//lParam is documented as in, so... Beware of future explosions, ig?
|
||||
std::pair<HWND, DWORD> params = { 0, pid };
|
||||
|
||||
|
|
@ -359,7 +362,11 @@ bool Session::fetchNameViaWindowName(std::wstring exePath, DWORD pid, std::wstri
|
|||
auto pParams = (std::pair<HWND, DWORD>*)(lParam);
|
||||
|
||||
DWORD processId;
|
||||
if (GetWindowThreadProcessId(hwnd, &processId) && processId == pParams->second) {
|
||||
//&& GetWindow(hwnd, GW_OWNER) == 0
|
||||
if (IsWindowVisible(hwnd) && GetWindowThreadProcessId(hwnd, &processId) && processId == pParams->second) {
|
||||
int length = GetWindowTextLength(hwnd);
|
||||
if (!length) return TRUE;
|
||||
|
||||
// Stop enumerating
|
||||
SetLastError(-1);
|
||||
pParams->first = hwnd;
|
||||
|
|
@ -371,6 +378,7 @@ bool Session::fetchNameViaWindowName(std::wstring exePath, DWORD pid, std::wstri
|
|||
} , (LPARAM)¶ms);
|
||||
|
||||
if(!result && GetLastError() == -1 && params.first) {
|
||||
//todo: double-dipping length... Not a fan
|
||||
int length = GetWindowTextLength(params.first);
|
||||
wchar_t* buffer = new wchar_t[length + 1];
|
||||
GetWindowTextW(params.first, buffer, length + 1);
|
||||
|
|
@ -381,13 +389,22 @@ bool Session::fetchNameViaWindowName(std::wstring exePath, DWORD pid, std::wstri
|
|||
return false;
|
||||
}
|
||||
|
||||
void Session::fetchName(std::wstring exePath, DWORD pid) {
|
||||
bool Session::fetchName(std::wstring exePath, DWORD pid) {
|
||||
/*
|
||||
* if(fetchNameViaWindowName(exePath, pid, &this->sessionName))
|
||||
* return;
|
||||
* else if(fetchNameViaMSIX(exePath, pid, &this->sessionName))
|
||||
* return;
|
||||
* else if(!fetchNameViaFD(exePath, pid, &this->sessionName))
|
||||
* this->sessionName = exePath;
|
||||
*/
|
||||
|
||||
if(fetchNameViaFD(exePath, pid, &this->sessionName))
|
||||
return;
|
||||
else if(fetchNameViaMSIX(exePath, pid, &this->sessionName))
|
||||
return;
|
||||
else if(!fetchNameViaWindowName(exePath, pid, &this->sessionName))
|
||||
this->sessionName = exePath;
|
||||
return true;
|
||||
return fetchNameViaMSIX(exePath, pid, &this->sessionName);
|
||||
//else if(!fetchNameViaWindowName(exePath, pid, &this->sessionName))
|
||||
/// this->sessionName = exePath;
|
||||
|
||||
}
|
||||
|
||||
//todo: conflicting names. change callback name
|
||||
|
|
|
|||
|
|
@ -49,10 +49,10 @@ class Session {
|
|||
|
||||
private:
|
||||
bool getExePath(DWORD pid, /*out*/ std::wstring *exePath);
|
||||
void fetchName(std::wstring exePath, DWORD pid);
|
||||
bool fetchName(std::wstring exePath, DWORD pid);
|
||||
bool fetchNameViaFD(std::wstring exePath, DWORD pid, /*out*/ std::wstring *sessionName);
|
||||
bool fetchNameViaMSIX(std::wstring exePath, DWORD pid, /*out*/ std::wstring *sessionName);
|
||||
bool fetchNameViaWindowName(std::wstring exePath, DWORD pid, /*out*/ std::wstring *sessionName);
|
||||
bool fetchNameViaWindowName(DWORD pid, /*out*/ std::wstring *sessionName);
|
||||
/* std::wstring fetchProcessName(DWORD pid); */
|
||||
std::wstring sessionName;
|
||||
SessionState sessionState;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue