mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-08 22:20:17 +01:00
Windows: uses SHGetKnownFolderPath instead of the unreliable getenv
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include <tlhelp32.h>
|
||||
#include <ntstatus.h>
|
||||
#include <winternl.h>
|
||||
#include <shlobj.h>
|
||||
|
||||
bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version);
|
||||
|
||||
@@ -189,17 +190,29 @@ static bool detectDefaultTerminal(FFTerminalResult* result)
|
||||
{
|
||||
ffStrbufSetS(&result->processName, "WindowsTerminal.exe");
|
||||
ffStrbufSetS(&result->prettyName, "WindowsTerminal");
|
||||
ffStrbufSetF(&result->exe, "%s\\WindowsApps\\%s\\WindowsTerminal.exe", getenv("ProgramFiles"), path.chars);
|
||||
if(ffPathExists(result->exe.chars, FF_PATHTYPE_FILE))
|
||||
|
||||
PWSTR programFiles = NULL;
|
||||
if (SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_ProgramFiles, KF_FLAG_DEFAULT, NULL, &programFiles)))
|
||||
{
|
||||
result->exeName = result->exe.chars + ffStrbufLastIndexC(&result->exe, '\\') + 1;
|
||||
ffStrbufSet(&result->exePath, &result->exe);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffStrbufDestroy(&result->exe);
|
||||
ffStrbufInitMove(&result->exe, &path);
|
||||
result->exeName = "";
|
||||
ffStrbufSetWS(&result->exe, programFiles);
|
||||
CoTaskMemFree(programFiles);
|
||||
programFiles = NULL;
|
||||
|
||||
ffStrbufAppendS(&result->exe, "\\WindowsApps\\");
|
||||
ffStrbufAppend(&result->exe, &path);
|
||||
ffStrbufAppendS(&result->exe, "\\WindowsTerminal.exe");
|
||||
|
||||
if(ffPathExists(result->exe.chars, FF_PATHTYPE_FILE))
|
||||
{
|
||||
result->exeName = result->exe.chars + ffStrbufLastIndexC(&result->exe, '\\') + 1;
|
||||
ffStrbufSet(&result->exePath, &result->exe);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffStrbufDestroy(&result->exe);
|
||||
ffStrbufInitMove(&result->exe, &path);
|
||||
result->exeName = "";
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -214,11 +227,11 @@ conhost:;
|
||||
{
|
||||
// For Windows Terminal, it reports the PID of OpenConsole
|
||||
if(ffProcessGetInfoWindows((uint32_t) conhostPid, NULL, &result->processName, &result->exe, &result->exeName, &result->exePath, NULL))
|
||||
{
|
||||
{
|
||||
ffStrbufSet(&result->prettyName, &result->processName);
|
||||
if(ffStrbufEndsWithIgnCaseS(&result->prettyName, ".exe"))
|
||||
ffStrbufSubstrBefore(&result->prettyName, result->prettyName.length - 4);
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user