Skip to content

Commit

Permalink
Platform (Windows): use %USERNAME% if available
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Feb 5, 2024
1 parent 79e2007 commit 51b0c43
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/util/platform/FFPlatform_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ static void getHomeDir(FFPlatform* platform)
ffStrbufSetWS(&platform->homeDir, pPath);
ffStrbufReplaceAllC(&platform->homeDir, '\\', '/');
ffStrbufEnsureEndsWithC(&platform->homeDir, '/');
CoTaskMemFree(pPath);
}
else
{
ffStrbufSetS(&platform->homeDir, getenv("USERPROFILE"));
ffStrbufReplaceAllC(&platform->homeDir, '\\', '/');
ffStrbufEnsureEndsWithC(&platform->homeDir, '/');
}
CoTaskMemFree(pPath);
}

static void getCacheDir(FFPlatform* platform)
Expand All @@ -52,13 +58,13 @@ static void getCacheDir(FFPlatform* platform)
ffStrbufSetWS(&platform->cacheDir, pPath);
ffStrbufReplaceAllC(&platform->cacheDir, '\\', '/');
ffStrbufEnsureEndsWithC(&platform->cacheDir, '/');
CoTaskMemFree(pPath);
}
else
{
ffStrbufAppend(&platform->cacheDir, &platform->homeDir);
ffStrbufAppendS(&platform->cacheDir, "AppData/Local/");
}
CoTaskMemFree(pPath);
}

static void platformPathAddKnownFolder(FFlist* dirs, REFKNOWNFOLDERID folderId)
Expand All @@ -71,8 +77,8 @@ static void platformPathAddKnownFolder(FFlist* dirs, REFKNOWNFOLDERID folderId)
ffStrbufEnsureEndsWithC(&buffer, '/');
if (!ffListContains(dirs, &buffer, (void*) ffStrbufEqual))
ffStrbufInitMove((FFstrbuf*) ffListAdd(dirs), &buffer);
CoTaskMemFree(pPath);
}
CoTaskMemFree(pPath);
}

static void platformPathAddEnvSuffix(FFlist* dirs, const char* env, const char* suffix)
Expand Down Expand Up @@ -130,10 +136,16 @@ static void getDataDirs(FFPlatform* platform)

static void getUserName(FFPlatform* platform)
{
wchar_t buffer[128];
DWORD len = sizeof(buffer) / sizeof(*buffer);
if(GetUserNameW(buffer, &len))
ffStrbufSetWS(&platform->userName, buffer);
const char* userName = getenv("USERNAME");
if (ffStrSet(userName))
ffStrbufSetS(&platform->userName, userName);
else
{
wchar_t buffer[128];
DWORD len = sizeof(buffer) / sizeof(*buffer);
if(GetUserNameW(buffer, &len))
ffStrbufSetWS(&platform->userName, buffer);
}
}

static void getHostName(FFPlatform* platform)
Expand Down

0 comments on commit 51b0c43

Please sign in to comment.