Skip to content

Commit 5e91668

Browse files
committed
Platform (Windows): add exePath
1 parent 28c0159 commit 5e91668

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/util/platform/FFPlatform.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ void ffPlatformInit(FFPlatform* platform)
88
ffStrbufInit(&platform->cacheDir);
99
ffListInit(&platform->configDirs, sizeof(FFstrbuf));
1010
ffListInit(&platform->dataDirs, sizeof(FFstrbuf));
11+
ffStrbufInit(&platform->exePath);
1112

1213
ffStrbufInit(&platform->userName);
1314
ffStrbufInit(&platform->hostName);

src/util/platform/FFPlatform.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ typedef struct FFPlatform {
1111
FFstrbuf cacheDir; // Trailing slash included
1212
FFlist configDirs; // List of FFstrbuf, trailing slash included
1313
FFlist dataDirs; // List of FFstrbuf, trailing slash included
14+
FFstrbuf exePath; // The real path of current exe
1415

1516
FFstrbuf userName;
1617
FFstrbuf hostName;

src/util/platform/FFPlatform_windows.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
#include <Windows.h>
77
#include <shlobj.h>
88

9+
static void getExePath(FFPlatform* platform)
10+
{
11+
wchar_t exePathW[MAX_PATH];
12+
DWORD exePathWLen = GetModuleFileNameW(NULL, exePathW, MAX_PATH);
13+
if (exePathWLen == 0 && exePathWLen >= MAX_PATH) return;
14+
15+
ffStrbufSetNWS(&platform->exePath, exePathWLen, exePathW);
16+
if (ffStrbufStartsWithS(&platform->exePath, "\\\\?\\"))
17+
ffStrbufSubstrAfter(&platform->exePath, 3);
18+
ffStrbufReplaceAllC(&platform->exePath, '\\', '/');
19+
}
20+
921
static void getHomeDir(FFPlatform* platform)
1022
{
1123
PWSTR pPath;
@@ -213,6 +225,7 @@ static void getSystemArchitecture(FFPlatform* platform)
213225

214226
void ffPlatformInitImpl(FFPlatform* platform)
215227
{
228+
getExePath(platform);
216229
getHomeDir(platform);
217230
getCacheDir(platform);
218231
getConfigDirs(platform);

0 commit comments

Comments
 (0)