CMPlatform/src/Win/ProgramPath.cpp

70 lines
1.5 KiB
C++
Raw Normal View History

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
{
2022-03-31 18:14:43 +08:00
bool GetOSLibararyPath(OSString &result)
{
wchar_t dllfn[MAX_PATH];
UINT size;
size=::GetSystemDirectoryW(dllfn,MAX_PATH);
if(size==0)
return(false);
result.SetString(dllfn,size);
return(true);
}
bool GetLocalAppdataPath(OSString &result)
2019-08-23 10:54:57 +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