更新GetLocalAppdataPath函数,使其风格和其它函数一致

This commit is contained in:
2020-10-09 18:23:30 +08:00
parent be71d3b818
commit 5dca9ae3a5
4 changed files with 17 additions and 8 deletions

View File

@@ -17,9 +17,10 @@ namespace hgl
strcpy(files_dir,HGL_MAX_PATH,fn); strcpy(files_dir,HGL_MAX_PATH,fn);
} }
void GetLocalAppdataPath(char fn[HGL_MAX_PATH]) bool GetLocalAppdataPath(OSString &result)
{ {
strcpy(fn,HGL_MAX_PATH,files_dir); result=files_dir;
return(true);
} }
/** /**

View File

@@ -5,13 +5,14 @@ namespace hgl
{ {
namespace filesystem namespace filesystem
{ {
void GetLocalAppdataPath(char fn[HGL_MAX_PATH]) bool GetLocalAppdataPath(OSString &result)
{ {
NSFileManager *dfm=[NSFileManager defaultManager]; NSFileManager *dfm=[NSFileManager defaultManager];
const char *str=[[[dfm homeDirectoryForCurrentUser] path] cStringUsingEncoding:NSUTF8StringEncoding]; const char *str=[[[dfm homeDirectoryForCurrentUser] path] cStringUsingEncoding:NSUTF8StringEncoding];
hgl::strcpy(fn,HGL_MAX_PATH,str,strlen(str)); result=str;
return(true);
} }
/** /**

View File

@@ -7,7 +7,7 @@ namespace hgl
{ {
namespace filesystem namespace filesystem
{ {
void GetLocalAppdataPath(os_char fn[HGL_MAX_PATH]) bool GetLocalAppdataPath(OSString &result)
{ {
struct passwd pwd; struct passwd pwd;
struct passwd *result; struct passwd *result;
@@ -21,9 +21,10 @@ namespace hgl
getpwuid_r(getuid(),&pwd,buf,bufsize,&result); getpwuid_r(getuid(),&pwd,buf,bufsize,&result);
strcpy(fn,HGL_MAX_PATH,pwd.pw_dir); result=pwd.pw_dir;
free(buf); free(buf);
return(true);
} }
/** /**

View File

@@ -6,9 +6,15 @@ namespace hgl
{ {
namespace filesystem namespace filesystem
{ {
void GetLocalAppdataPath(os_char fn[HGL_MAX_PATH]) bool GetLocalAppdataPath(OSString &result)
{ {
SHGetFolderPathW(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, fn); os_char fn[HGL_MAX_PATH];
if(SHGetFolderPathW(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, fn)!=S_OK)
return(false);
result=fn;
return(true);
} }
/** /**