| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  |  | // Copyright (c) 2016-2018 Easy2D - Nomango
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
					
						
							|  |  |  |  | // of this software and associated documentation files (the "Software"), to deal
 | 
					
						
							|  |  |  |  | // in the Software without restriction, including without limitation the rights
 | 
					
						
							|  |  |  |  | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
					
						
							|  |  |  |  | // copies of the Software, and to permit persons to whom the Software is
 | 
					
						
							|  |  |  |  | // furnished to do so, subject to the following conditions:
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // The above copyright notice and this permission notice shall be included in
 | 
					
						
							|  |  |  |  | // all copies or substantial portions of the Software.
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					
						
							|  |  |  |  | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
					
						
							|  |  |  |  | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
					
						
							|  |  |  |  | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
					
						
							|  |  |  |  | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
					
						
							|  |  |  |  | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
					
						
							|  |  |  |  | // THE SOFTWARE.
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 13:33:39 +08:00
										 |  |  |  | #include "..\e2dtool.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-05 13:17:07 +08:00
										 |  |  |  | #include "..\e2dmodule.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-02 14:03:04 +08:00
										 |  |  |  | #include <shlobj.h>
 | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 14:57:28 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | namespace | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-10-28 23:24:01 +08:00
										 |  |  |  | 	bool CreateFolder(const std::wstring & dir_path) | 
					
						
							| 
									
										
										
										
											2018-10-16 14:57:28 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-10-28 23:24:01 +08:00
										 |  |  |  | 		if (dir_path.empty() || dir_path.size() >= MAX_PATH) | 
					
						
							| 
									
										
										
										
											2018-10-16 14:57:28 +08:00
										 |  |  |  | 			return false; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		wchar_t tmp_dir_path[MAX_PATH] = { 0 }; | 
					
						
							| 
									
										
										
										
											2018-10-28 23:24:01 +08:00
										 |  |  |  | 		size_t length = dir_path.length(); | 
					
						
							| 
									
										
										
										
											2018-10-16 14:57:28 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-28 23:24:01 +08:00
										 |  |  |  | 		for (size_t i = 0; i < length; ++i) | 
					
						
							| 
									
										
										
										
											2018-10-16 14:57:28 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-10-28 23:24:01 +08:00
										 |  |  |  | 			tmp_dir_path[i] = dir_path.at(i); | 
					
						
							| 
									
										
										
										
											2018-10-16 14:57:28 +08:00
										 |  |  |  | 			if (tmp_dir_path[i] == L'\\' || tmp_dir_path[i] == L'/' || i == (length - 1)) | 
					
						
							|  |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				if (::_waccess(tmp_dir_path, 0) != 0) | 
					
						
							|  |  |  |  | 				{ | 
					
						
							|  |  |  |  | 					if (::_wmkdir(tmp_dir_path) != 0) | 
					
						
							|  |  |  |  | 					{ | 
					
						
							|  |  |  |  | 						return false; | 
					
						
							|  |  |  |  | 					} | 
					
						
							|  |  |  |  | 				} | 
					
						
							|  |  |  |  | 			} | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		return true; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-28 23:24:01 +08:00
										 |  |  |  | const std::wstring& easy2d::Path::GetDataPath() | 
					
						
							| 
									
										
										
										
											2018-07-04 17:00:21 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-28 23:24:01 +08:00
										 |  |  |  | 	static std::wstring data_path; | 
					
						
							|  |  |  |  | 	if (data_path.empty()) | 
					
						
							| 
									
										
										
										
											2018-07-04 17:00:21 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵı<DDB5><C4B1><EFBFBD>·<EFBFBD><C2B7>
 | 
					
						
							| 
									
										
										
										
											2018-10-28 23:24:01 +08:00
										 |  |  |  | 		std::wstring local_app_data_path = Path::GetLocalAppDataPath(); | 
					
						
							|  |  |  |  | 		std::wstring title = Game::GetInstance()->GetTitle(); | 
					
						
							|  |  |  |  | 		std::wstring folder_name = std::to_wstring(std::hash<std::wstring>{}(title)); | 
					
						
							| 
									
										
										
										
											2018-08-19 15:11:20 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-28 23:24:01 +08:00
										 |  |  |  | 		if (!local_app_data_path.empty()) | 
					
						
							| 
									
										
										
										
											2018-07-04 17:00:21 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-10-28 23:24:01 +08:00
										 |  |  |  | 			data_path.append(local_app_data_path) | 
					
						
							|  |  |  |  | 				.append(L"\\Easy2DGameData\\") | 
					
						
							|  |  |  |  | 				.append(folder_name) | 
					
						
							|  |  |  |  | 				.append(L"\\"); | 
					
						
							| 
									
										
										
										
											2018-07-04 17:00:21 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 			File file(data_path); | 
					
						
							| 
									
										
										
										
											2018-10-16 14:57:28 +08:00
										 |  |  |  | 			if (!file.Exists() && !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-10-28 23:24:01 +08:00
										 |  |  |  | 		data_path.append(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-10-28 23:24:01 +08:00
										 |  |  |  | const std::wstring& easy2d::Path::GetTemporaryPath() | 
					
						
							| 
									
										
										
										
											2018-04-26 21:47:56 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-28 23:24:01 +08:00
										 |  |  |  | 	static std::wstring temp_path; | 
					
						
							|  |  |  |  | 	if (temp_path.empty()) | 
					
						
							| 
									
										
										
										
											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-10-28 23:24:01 +08:00
										 |  |  |  | 		std::wstring title = Game::GetInstance()->GetTitle(); | 
					
						
							|  |  |  |  | 		std::wstring folder_name = std::to_wstring(std::hash<std::wstring>{}(title)); | 
					
						
							| 
									
										
										
										
											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-10-28 23:24:01 +08:00
										 |  |  |  | 			temp_path.append(path) | 
					
						
							|  |  |  |  | 				.append(L"\\Easy2DGameTemp\\") | 
					
						
							|  |  |  |  | 				.append(folder_name) | 
					
						
							|  |  |  |  | 				.append(L"\\"); | 
					
						
							| 
									
										
										
										
											2018-07-04 17:00:21 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 			File file(temp_path); | 
					
						
							| 
									
										
										
										
											2018-10-16 14:57:28 +08:00
										 |  |  |  | 			if (!file.Exists() && !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-10-28 23:24:01 +08:00
										 |  |  |  | const std::wstring& easy2d::Path::GetLocalAppDataPath() | 
					
						
							| 
									
										
										
										
											2018-07-04 12:49:05 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-28 23:24:01 +08:00
										 |  |  |  | 	static std::wstring local_app_data_path; | 
					
						
							|  |  |  |  | 	if (local_app_data_path.empty()) | 
					
						
							| 
									
										
										
										
											2018-07-04 12:49:05 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><>ȡ AppData/Local <20>ļ<EFBFBD><C4BC>е<EFBFBD>·<EFBFBD><C2B7>
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:57:40 +08:00
										 |  |  |  | 		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-10-28 23:24:01 +08:00
										 |  |  |  | const std::wstring& easy2d::Path::GetExeFilePath() | 
					
						
							| 
									
										
										
										
											2018-05-24 15:47:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-28 23:24:01 +08:00
										 |  |  |  | 	static std::wstring exe_file_path; | 
					
						
							|  |  |  |  | 	if (exe_file_path.empty()) | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2018-05-24 14:33:16 +08:00
										 |  |  |  | } |