Platform: retrieve full user name

This commit is contained in:
李通洲
2025-04-09 14:58:36 +08:00
committed by 李通洲
parent fc31fe4aa4
commit 3c291f1af9
6 changed files with 17 additions and 1 deletions
+3
View File
@@ -63,6 +63,7 @@ void ffPrintTitle(FFTitleOptions* options)
FF_FORMAT_ARG(userNameColored, "user-name-colored"),
FF_FORMAT_ARG(atColored, "at-symbol-colored"),
FF_FORMAT_ARG(hostNameColored, "host-name-colored"),
FF_FORMAT_ARG(instance.state.platform.fullUserName, "full-user-name"),
}));
}
}
@@ -170,6 +171,7 @@ void ffGenerateTitleJsonResult(FF_MAYBE_UNUSED FFTitleOptions* options, yyjson_m
{
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_strbuf(doc, obj, "userName", &instance.state.platform.userName);
yyjson_mut_obj_add_strbuf(doc, obj, "fullUserName", &instance.state.platform.fullUserName);
yyjson_mut_obj_add_strbuf(doc, obj, "hostName", &instance.state.platform.hostName);
yyjson_mut_obj_add_strbuf(doc, obj, "homeDir", &instance.state.platform.homeDir);
yyjson_mut_obj_add_strbuf(doc, obj, "exePath", &instance.state.platform.exePath);
@@ -193,6 +195,7 @@ static FFModuleBaseInfo ffModuleInfo = {
{"User name (colored)", "user-name-colored"},
{"@ symbol (colored)", "at-symbol-colored"},
{"Host name (colored)", "host-name-colored"},
{"Full user name", "full-user-name"},
}))
};
+1
View File
@@ -12,6 +12,7 @@ void ffPlatformInit(FFPlatform* platform)
ffStrbufInit(&platform->exePath);
ffStrbufInit(&platform->userName);
ffStrbufInit(&platform->fullUserName);
ffStrbufInit(&platform->hostName);
ffStrbufInit(&platform->userShell);
+1
View File
@@ -22,6 +22,7 @@ typedef struct FFPlatform
FFstrbuf exePath; // The real path of current exe
FFstrbuf userName;
FFstrbuf fullUserName;
FFstrbuf hostName;
FFstrbuf userShell;
+2
View File
@@ -181,6 +181,8 @@ static void getUserName(FFPlatform* platform, const struct passwd* pwd)
user = pwd->pw_name;
ffStrbufAppendS(&platform->userName, user);
if (pwd) ffStrbufAppendS(&platform->fullUserName, pwd->pw_gecos);
}
static void getHostName(FFPlatform* platform, const struct utsname* uts)
+9 -1
View File
@@ -9,6 +9,9 @@
#include <Windows.h>
#include <shlobj.h>
#define SECURITY_WIN32 1 // For secext.h
#include <secext.h>
static void getExePath(FFPlatform* platform)
{
wchar_t exePathW[MAX_PATH];
@@ -138,11 +141,16 @@ static void getUserName(FFPlatform* platform)
ffStrbufSetS(&platform->userName, userName);
else
{
wchar_t buffer[128];
wchar_t buffer[256];
DWORD len = ARRAY_SIZE(buffer);
if(GetUserNameW(buffer, &len))
ffStrbufSetWS(&platform->userName, buffer);
}
wchar_t buffer[256];
DWORD len = ARRAY_SIZE(buffer);
if (GetUserNameExW(NameDisplay, buffer, &len))
ffStrbufSetWS(&platform->fullUserName, buffer);
}
static void getHostName(FFPlatform* platform)