Magic_Game/core/Tool/Path.cpp

80 lines
1.7 KiB
C++
Raw Normal View History

2018-04-21 21:24:46 +08:00
#include "..\e2dtool.h"
#include <shlobj.h>
2018-01-30 16:45:38 +08:00
e2d::String e2d::Path::getDataPath()
2018-07-04 17:00:21 +08:00
{
static String dataPath;
if (dataPath.isEmpty())
2018-07-04 17:00:21 +08:00
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵı<DDB5><C4B1><EFBFBD>·<EFBFBD><C2B7>
String localAppDataPath = Path::getLocalAppDataPath();
2018-08-28 00:06:10 +08:00
String title = Window::getInstance()->getTitle();
2018-08-19 15:11:20 +08:00
String folderName = String::parse(title.hash());
if (!localAppDataPath.isEmpty())
2018-07-04 17:00:21 +08:00
{
2018-08-19 15:11:20 +08:00
dataPath = localAppDataPath + L"\\Easy2DGameData\\" << folderName << L"\\";
2018-07-04 17:00:21 +08:00
File file(dataPath);
if (!file.exists() && !File::createFolder(dataPath))
2018-07-04 17:00:21 +08:00
{
dataPath = L"";
2018-07-04 17:00:21 +08:00
}
}
dataPath << L"Data.ini";
2018-07-04 17:00:21 +08:00
}
return dataPath;
2018-07-04 17:00:21 +08:00
}
e2d::String e2d::Path::getTempPath()
2018-04-26 21:47:56 +08:00
{
static String tempPath;
if (tempPath.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-08-28 00:06:10 +08:00
String title = Window::getInstance()->getTitle();
2018-08-19 15:11:20 +08:00
String folderName = String::parse(title.hash());
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-08-19 15:11:20 +08:00
tempPath << path << L"\\Easy2DGameTemp\\" << folderName << L"\\";
2018-07-04 17:00:21 +08:00
File file(tempPath);
if (!file.exists() && !File::createFolder(tempPath))
2018-07-04 17:00:21 +08:00
{
tempPath = L"";
2018-07-04 17:00:21 +08:00
}
}
}
return tempPath;
2018-07-04 12:49:05 +08:00
}
e2d::String e2d::Path::getLocalAppDataPath()
2018-07-04 12:49:05 +08:00
{
static String localAppDataPath;
if (localAppDataPath.isEmpty())
2018-07-04 12:49:05 +08:00
{
// <20><>ȡ AppData/Local <20>ļ<EFBFBD><C4BC>е<EFBFBD>·<EFBFBD><C2B7>
WCHAR strPath[MAX_PATH] = { 0 };
::SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, strPath);
localAppDataPath = strPath;
2018-07-04 12:49:05 +08:00
}
return localAppDataPath;
2018-04-26 21:47:56 +08:00
}
e2d::String e2d::Path::getCurrentFilePath()
2018-05-24 15:47:38 +08:00
{
static String currFilePath;
if (currFilePath.isEmpty())
2018-05-24 15:47:38 +08:00
{
TCHAR szPath[_MAX_PATH] = { 0 };
if (::GetModuleFileName(nullptr, szPath, _MAX_PATH) != 0)
2018-05-24 15:47:38 +08:00
{
currFilePath = szPath;
2018-05-24 15:47:38 +08:00
}
}
return currFilePath;
}