Windows: look for config files in $LOCALAPPDATA

This commit is contained in:
李通洲
2023-01-02 11:49:41 +08:00
parent 8533dc234b
commit 822496808d
6 changed files with 39 additions and 2 deletions
+1
View File
@@ -3,6 +3,7 @@
Features:
* `--logo-padding-top` option (@CarterLi, #372)
* Raw image file as logo support (@CarterLi)
* Look for config files in $LOCALAPPDATA (Windows) (@CarterLi)
Logos:
* Raspbian (@IamNoRobot, #373)
+18 -1
View File
@@ -12,6 +12,8 @@
#ifdef _WIN32
#include <wincon.h>
#include <locale.h>
#include <shlobj.h>
#include "util/windows/unicode.h"
#else
#include <signal.h>
#endif
@@ -20,7 +22,22 @@ static void initConfigDirs(FFstate* state)
{
ffListInit(&state->configDirs, sizeof(FFstrbuf));
#if !(defined(_WIN32) || defined(__APPLE__) || defined(__ANDROID__))
#ifdef _WIN32
{
PWSTR pPath;
if(SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_LocalAppData, 0, NULL, &pPath)))
{
FFstrbuf* buffer = (FFstrbuf*) ffListAdd(&state->configDirs);
ffStrbufInit(buffer);
ffStrbufSetWS(buffer, pPath);
ffStrbufReplaceAllC(buffer, '\\', '/');
ffStrbufEnsureEndsWithC(buffer, '/');
}
CoTaskMemFree(pPath);
}
#elif !(defined(__APPLE__) || defined(__ANDROID__))
const char* xdgConfigHome = getenv("XDG_CONFIG_HOME");
if(ffStrSet(xdgConfigHome))
+6
View File
@@ -328,6 +328,12 @@ uint32_t ffStrbufPreviousIndexC(const FFstrbuf* strbuf, uint32_t start, char c)
return strbuf->length;
}
void ffStrbufReplaceAllC(FFstrbuf* strbuf, char find, char replace)
{
for (char *current_pos = strchr(strbuf->chars, find); current_pos; current_pos = strchr(current_pos + 1, find))
*current_pos = replace;
}
void ffStrbufSubstrBefore(FFstrbuf* strbuf, uint32_t index)
{
if(strbuf->length <= index)
+2
View File
@@ -69,6 +69,8 @@ FF_C_NODISCARD uint32_t ffStrbufNextIndexS(const FFstrbuf* strbuf, uint32_t star
FF_C_NODISCARD uint32_t ffStrbufPreviousIndexC(const FFstrbuf* strbuf, uint32_t start, char c);
void ffStrbufReplaceAllC(FFstrbuf* strbuf, char find, char replace);
void ffStrbufSubstrBefore(FFstrbuf* strbuf, uint32_t index);
void ffStrbufSubstrBeforeFirstC(FFstrbuf* strbuf, char c);
void ffStrbufSubstrBeforeLastC(FFstrbuf* strbuf, char c);
+6 -1
View File
@@ -11,7 +11,12 @@ struct passwd* ffGetPasswd()
DWORD len = sizeof(res.pw_name);
GetUserNameA(res.pw_name, &len);
SHGetFolderPathA(NULL, CSIDL_PROFILE, NULL, 0, res.pw_dir);
PWSTR pPath;
if(SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_Profile, KF_FLAG_DEFAULT, NULL, &pPath)))
WideCharToMultiByte(CP_UTF8, 0, pPath, -1, res.pw_dir, sizeof(res.pw_dir), NULL, NULL); //res has been NULL inited
CoTaskMemFree(pPath);
for (char *current_pos = strchr(res.pw_dir, '\\'); current_pos; current_pos = strchr(current_pos + 1, '\\'))
*current_pos = '/';
return &res;
}
+6
View File
@@ -208,6 +208,12 @@ int main(void)
VERIFY(ffStrbufContainC(&strbuf, '1'));
VERIFY(!ffStrbufContainC(&strbuf, '-'));
//replaceAllC
ffStrbufReplaceAllC(&strbuf, '1', '-');
VERIFY(ffStrbufEqualS(&strbuf, "-234567890-234567890-234567890-"));
ffStrbufReplaceAllC(&strbuf, '1', '-');
VERIFY(ffStrbufEqualS(&strbuf, "-234567890-234567890-234567890-"));
ffStrbufDestroy(&strbuf);
//Success