Platform (Windows): add exePath

This commit is contained in:
李通洲
2023-08-24 13:47:20 +08:00
parent 28c01599d5
commit 5e9166847d
3 changed files with 15 additions and 0 deletions
+1
View File
@@ -8,6 +8,7 @@ void ffPlatformInit(FFPlatform* platform)
ffStrbufInit(&platform->cacheDir);
ffListInit(&platform->configDirs, sizeof(FFstrbuf));
ffListInit(&platform->dataDirs, sizeof(FFstrbuf));
ffStrbufInit(&platform->exePath);
ffStrbufInit(&platform->userName);
ffStrbufInit(&platform->hostName);
+1
View File
@@ -11,6 +11,7 @@ typedef struct FFPlatform {
FFstrbuf cacheDir; // Trailing slash included
FFlist configDirs; // List of FFstrbuf, trailing slash included
FFlist dataDirs; // List of FFstrbuf, trailing slash included
FFstrbuf exePath; // The real path of current exe
FFstrbuf userName;
FFstrbuf hostName;
+13
View File
@@ -6,6 +6,18 @@
#include <Windows.h>
#include <shlobj.h>
static void getExePath(FFPlatform* platform)
{
wchar_t exePathW[MAX_PATH];
DWORD exePathWLen = GetModuleFileNameW(NULL, exePathW, MAX_PATH);
if (exePathWLen == 0 && exePathWLen >= MAX_PATH) return;
ffStrbufSetNWS(&platform->exePath, exePathWLen, exePathW);
if (ffStrbufStartsWithS(&platform->exePath, "\\\\?\\"))
ffStrbufSubstrAfter(&platform->exePath, 3);
ffStrbufReplaceAllC(&platform->exePath, '\\', '/');
}
static void getHomeDir(FFPlatform* platform)
{
PWSTR pPath;
@@ -213,6 +225,7 @@ static void getSystemArchitecture(FFPlatform* platform)
void ffPlatformInitImpl(FFPlatform* platform)
{
getExePath(platform);
getHomeDir(platform);
getCacheDir(platform);
getConfigDirs(platform);