| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | #include "..\etools.h"
 | 
					
						
							|  |  |  |  | #include <algorithm>
 | 
					
						
							|  |  |  |  | #include <commdlg.h>
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #define DEFINE_KNOWN_FOLDER(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
 | 
					
						
							|  |  |  |  | 	EXTERN_C const GUID DECLSPEC_SELECTANY name \ | 
					
						
							|  |  |  |  | 	= { l, w1, w2,{ b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | DEFINE_KNOWN_FOLDER(FOLDERID_LocalAppData, 0xF1B32785, 0x6FBA, 0x4FCF, 0x9D, 0x55, 0x7B, 0x8E, 0x7F, 0x15, 0x70, 0x91); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-11 23:56:40 +08:00
										 |  |  |  | e2d::String e2d::Path::getLocalAppDataPath() | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-01 09:38:25 +08:00
										 |  |  |  | 	typedef HRESULT(WINAPI* pFunSHGetKnownFolderPath)(const GUID& rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | 	// <20><>ȡ AppData\Local <20>ļ<EFBFBD><C4BC>е<EFBFBD>·<EFBFBD><C2B7>
 | 
					
						
							|  |  |  |  | 	PWSTR pszPath = NULL; | 
					
						
							|  |  |  |  | 	HMODULE hModule = LoadLibrary(L"shell32.dll"); | 
					
						
							|  |  |  |  | 	pFunSHGetKnownFolderPath SHGetKnownFolderPath = (pFunSHGetKnownFolderPath)GetProcAddress(hModule, "SHGetKnownFolderPath"); | 
					
						
							|  |  |  |  | 	HRESULT hr = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &pszPath); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (SUCCEEDED(hr)) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | 		String path = pszPath; | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | 		CoTaskMemFree(pszPath); | 
					
						
							|  |  |  |  | 		return path; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return L""; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-11 23:56:40 +08:00
										 |  |  |  | e2d::String e2d::Path::getTempPath() | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	// <20><>ȡ<EFBFBD><C8A1>ʱ<EFBFBD>ļ<EFBFBD>Ŀ¼
 | 
					
						
							| 
									
										
										
										
											2017-12-11 18:17:24 +08:00
										 |  |  |  | 	wchar_t path[_MAX_PATH]; | 
					
						
							| 
									
										
										
										
											2018-03-11 23:56:40 +08:00
										 |  |  |  | 	if (0 == ::GetTempPath(_MAX_PATH, path)) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		return L""; | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ļ<EFBFBD>Ŀ¼
 | 
					
						
							| 
									
										
										
										
											2018-03-11 23:56:40 +08:00
										 |  |  |  | 	e2d::String tempFilePath; | 
					
						
							|  |  |  |  | 	tempFilePath << path << L"Easy2DGameTemp"; | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
 | 
					
						
							|  |  |  |  | 	if (!Path::createFolder(tempFilePath)) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		return path; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20><>ȡ AppName
 | 
					
						
							|  |  |  |  | 	String sAppName = Game::getAppName(); | 
					
						
							|  |  |  |  | 	if (!sAppName.isEmpty()) | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-03-11 23:56:40 +08:00
										 |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
 | 
					
						
							|  |  |  |  | 		if (!Path::createFolder(tempFilePath + L"\\" + sAppName)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			return std::move(tempFilePath); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		tempFilePath << L"\\" << sAppName; | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-11 23:56:40 +08:00
										 |  |  |  | 	tempFilePath << L"\\"; | 
					
						
							|  |  |  |  | 	return std::move(tempFilePath); | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-11 23:56:40 +08:00
										 |  |  |  | e2d::String e2d::Path::getDefaultSavePath() | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-03-11 23:56:40 +08:00
										 |  |  |  | 	// <20><>ȡ AppData ·<><C2B7>
 | 
					
						
							|  |  |  |  | 	String path = Path::getLocalAppDataPath(); | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-11 23:56:40 +08:00
										 |  |  |  | 	if (path.isEmpty()) | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-03-11 23:56:40 +08:00
										 |  |  |  | 		WARN_IF(true, "Cannot get local AppData path!"); | 
					
						
							|  |  |  |  | 		return std::move(path); | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-11 23:56:40 +08:00
										 |  |  |  | 	 | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
 | 
					
						
							|  |  |  |  | 	if (!Path::createFolder(path + L"\\Easy2DGameData")) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		return std::move(path); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	path << L"\\Easy2DGameData"; | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-11 23:56:40 +08:00
										 |  |  |  | 	// <20><>ȡ AppName
 | 
					
						
							|  |  |  |  | 	String sAppName = Game::getAppName(); | 
					
						
							|  |  |  |  | 	if (!sAppName.isEmpty()) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
 | 
					
						
							|  |  |  |  | 		if (!Path::createFolder(path + L"\\" + sAppName)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			return std::move(path); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		path << L"\\" << sAppName; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	path << L"\\"; | 
					
						
							|  |  |  |  | 	 | 
					
						
							|  |  |  |  | 	return std::move(path); | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-11 23:56:40 +08:00
										 |  |  |  | e2d::String e2d::Path::getFileExtension(const String & filePath) | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | 	String fileExtension; | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | 	// <20>ҵ<EFBFBD><D2B5>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> '.' <20><>λ<EFBFBD><CEBB>
 | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	int pos = filePath.findLastOf(L'.'); | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | 	// <20>ж<EFBFBD> pos <20>Ƿ<EFBFBD><C7B7>Ǹ<EFBFBD><C7B8><EFBFBD>Чλ<D0A7><CEBB>
 | 
					
						
							| 
									
										
										
										
											2017-12-11 18:17:24 +08:00
										 |  |  |  | 	if (pos != -1) | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><>ȡ<EFBFBD><C8A1>չ<EFBFBD><D5B9>
 | 
					
						
							| 
									
										
										
										
											2018-02-27 16:32:17 +08:00
										 |  |  |  | 		fileExtension = filePath.subtract(pos); | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | 		// ת<><D7AA>ΪСд<D0A1><D0B4>ĸ
 | 
					
						
							| 
									
										
										
										
											2018-02-27 16:32:17 +08:00
										 |  |  |  | 		fileExtension = fileExtension.toLower(); | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	return fileExtension; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-11 23:56:40 +08:00
										 |  |  |  | e2d::String e2d::Path::getSaveFilePath(const String & title, const String & defExt) | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ի<EFBFBD><D4BB><EFBFBD>
 | 
					
						
							|  |  |  |  | 	OPENFILENAME ofn = { 0 }; | 
					
						
							| 
									
										
										
										
											2018-02-28 19:17:15 +08:00
										 |  |  |  | 	wchar_t strFilename[MAX_PATH] = { 0 };				// <20><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | 	ofn.lStructSize = sizeof(OPENFILENAME);				// <20>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>С
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | 	ofn.hwndOwner = Window::getHWnd();					// <20><><EFBFBD>ھ<EFBFBD><DABE><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2017-12-11 18:17:24 +08:00
										 |  |  |  | 	ofn.lpstrFilter = L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>\0*.*\0\0";				// <20><><EFBFBD>ù<EFBFBD><C3B9><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | 	ofn.nFilterIndex = 1;								// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 	ofn.lpstrFile = strFilename;						// <20><><EFBFBD>շ<EFBFBD><D5B7>ص<EFBFBD><D8B5>ļ<EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
 | 
					
						
							|  |  |  |  | 	ofn.nMaxFile = sizeof(strFilename);					// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 	ofn.lpstrInitialDir = NULL;							// <20><>ʼĿ¼ΪĬ<CEAA><C4AC>
 | 
					
						
							| 
									
										
										
										
											2017-12-11 18:17:24 +08:00
										 |  |  |  | 	ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; | 
					
						
							|  |  |  |  | 	ofn.lpstrTitle = title;								// <20><><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 	ofn.lpstrDefExt = defExt;							// Ĭ<><C4AC><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD>չ<EFBFBD><D5B9>
 | 
					
						
							| 
									
										
										
										
											2017-10-19 12:48:58 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (GetSaveFileName(&ofn)) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		return strFilename; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return L""; | 
					
						
							| 
									
										
										
										
											2018-03-11 23:56:40 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | bool e2d::Path::createFolder(const String & strDirPath) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (strDirPath.isEmpty()) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		WARN_IF(true, "Path::createFolder Failed: Invalid directory path!"); | 
					
						
							|  |  |  |  | 		return false; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (-1 == ::_waccess(strDirPath, 0)) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		if (0 != ::_wmkdir(strDirPath)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			return false; | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return true; | 
					
						
							|  |  |  |  | } |