2020-09-03 15:57:08 +08:00
|
|
|
|
#include<hgl/type/String.h>
|
2019-08-23 10:54:57 +08:00
|
|
|
|
#include<windows.h>
|
|
|
|
|
#include<shlobj.h>
|
|
|
|
|
|
|
|
|
|
namespace hgl
|
|
|
|
|
{
|
|
|
|
|
namespace filesystem
|
|
|
|
|
{
|
2020-10-09 18:23:30 +08:00
|
|
|
|
bool GetLocalAppdataPath(OSString &result)
|
2019-08-23 10:54:57 +08:00
|
|
|
|
{
|
2020-10-09 18:23:30 +08:00
|
|
|
|
os_char fn[HGL_MAX_PATH];
|
|
|
|
|
|
|
|
|
|
if(SHGetFolderPathW(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, fn)!=S_OK)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
result=fn;
|
|
|
|
|
return(true);
|
2019-08-23 10:54:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 取得当前程序完整路径名称
|
|
|
|
|
*/
|
|
|
|
|
bool GetCurrentProgram(OSString &result)
|
|
|
|
|
{
|
|
|
|
|
os_char *path=new os_char[HGL_MAX_PATH];
|
|
|
|
|
|
|
|
|
|
GetModuleFileNameW(nullptr,path,HGL_MAX_PATH);
|
|
|
|
|
|
|
|
|
|
result = path;
|
|
|
|
|
delete[] path;
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 取得当前程序所在路径
|
|
|
|
|
*/
|
|
|
|
|
bool GetCurrentProgramPath(OSString &result)
|
|
|
|
|
{
|
|
|
|
|
os_char *path=new os_char[HGL_MAX_PATH];
|
|
|
|
|
|
|
|
|
|
int len=GetModuleFileNameW(nullptr,path,HGL_MAX_PATH);
|
|
|
|
|
|
|
|
|
|
os_char *right=hgl::strrchr(path,len,HGL_DIRECTORY_SEPARATOR);
|
|
|
|
|
|
|
|
|
|
if(right)
|
|
|
|
|
*right=0;
|
|
|
|
|
|
|
|
|
|
result = path;
|
|
|
|
|
delete[] path;
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
}//namespace filesystem
|
|
|
|
|
}//namespace hgl
|