Magic_Game/core/Tool/Path.cpp

81 lines
1.8 KiB
C++
Raw Normal View History

2018-09-05 13:33:39 +08:00
#include "..\e2dtool.h"
2018-09-05 13:17:07 +08:00
#include "..\e2dmodule.h"
#include <shlobj.h>
2018-01-30 16:45:38 +08:00
2018-09-04 22:42:34 +08:00
const e2d::String& e2d::Path::GetDataPath()
2018-07-04 17:00:21 +08:00
{
2018-09-04 22:42:34 +08:00
static String data_path;
if (data_path.IsEmpty())
2018-07-04 17:00:21 +08:00
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵı<DDB5><C4B1><EFBFBD>·<EFBFBD><C2B7>
2018-09-04 22:42:34 +08:00
String local_app_data_path = Path::GetLocalAppDataPath();
String title = Window::GetInstance()->GetTitle();
String folder_name = String::Parse(title.GetHash());
2018-08-19 15:11:20 +08:00
2018-09-04 22:42:34 +08:00
if (!local_app_data_path.IsEmpty())
2018-07-04 17:00:21 +08:00
{
2018-09-04 22:42:34 +08:00
data_path = local_app_data_path + L"\\Easy2DGameData\\" << folder_name << L"\\";
2018-07-04 17:00:21 +08:00
2018-09-04 22:42:34 +08:00
File file(data_path);
if (!file.Exists() && !File::CreateFolder(data_path))
2018-07-04 17:00:21 +08:00
{
2018-09-04 22:42:34 +08:00
data_path = L"";
2018-07-04 17:00:21 +08:00
}
}
2018-09-04 22:42:34 +08:00
data_path << L"Data.ini";
2018-07-04 17:00:21 +08:00
}
2018-09-04 22:42:34 +08:00
return data_path;
2018-07-04 17:00:21 +08:00
}
2018-09-04 22:42:34 +08:00
const e2d::String& e2d::Path::GetTemporaryPath()
2018-04-26 21:47:56 +08:00
{
2018-09-04 22:42:34 +08:00
static String temp_path;
if (temp_path.IsEmpty())
2018-07-04 17:00:21 +08:00
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
wchar_t path[_MAX_PATH];
2018-09-04 22:42:34 +08:00
String title = Window::GetInstance()->GetTitle();
String folder_name = String::Parse(title.GetHash());
2018-07-04 17:00:21 +08:00
2018-08-19 15:11:20 +08:00
if (0 != ::GetTempPath(_MAX_PATH, path))
2018-07-04 17:00:21 +08:00
{
2018-09-04 22:42:34 +08:00
temp_path << path << L"\\Easy2DGameTemp\\" << folder_name << L"\\";
2018-07-04 17:00:21 +08:00
2018-09-04 22:42:34 +08:00
File file(temp_path);
if (!file.Exists() && !File::CreateFolder(temp_path))
2018-07-04 17:00:21 +08:00
{
2018-09-04 22:42:34 +08:00
temp_path = L"";
2018-07-04 17:00:21 +08:00
}
}
}
2018-09-04 22:42:34 +08:00
return temp_path;
2018-07-04 12:49:05 +08:00
}
2018-09-04 22:42:34 +08:00
const e2d::String& e2d::Path::GetLocalAppDataPath()
2018-07-04 12:49:05 +08:00
{
2018-09-04 22:42:34 +08:00
static String local_app_data_path;
if (local_app_data_path.IsEmpty())
2018-07-04 12:49:05 +08:00
{
// <20><>ȡ AppData/Local <20>ļ<EFBFBD><C4BC>е<EFBFBD>·<EFBFBD><C2B7>
wchar_t path[MAX_PATH] = { 0 };
2018-09-04 22:42:34 +08:00
::SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path);
local_app_data_path = path;
2018-07-04 12:49:05 +08:00
}
2018-09-04 22:42:34 +08:00
return local_app_data_path;
2018-04-26 21:47:56 +08:00
}
2018-09-04 22:42:34 +08:00
const e2d::String& e2d::Path::GetExeFilePath()
2018-05-24 15:47:38 +08:00
{
2018-09-04 22:42:34 +08:00
static String exe_file_path;
if (exe_file_path.IsEmpty())
2018-05-24 15:47:38 +08:00
{
2018-09-04 22:42:34 +08:00
TCHAR path[_MAX_PATH] = { 0 };
if (::GetModuleFileName(nullptr, path, _MAX_PATH) != 0)
2018-05-24 15:47:38 +08:00
{
2018-09-04 22:42:34 +08:00
exe_file_path = path;
2018-05-24 15:47:38 +08:00
}
}
2018-09-04 22:42:34 +08:00
return exe_file_path;
}