| 
									
										
										
										
											2019-04-11 14:40:54 +08:00
										 |  |  |  | // Copyright (c) 2016-2018 Kiwano - Nomango
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | // 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:
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | // The above copyright notice and this permission notice shall be included in
 | 
					
						
							|  |  |  |  | // all copies or substantial portions of the Software.
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | // 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.
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2019-11-13 14:33:15 +08:00
										 |  |  |  | #include <kiwano/core/Resource.h>
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-11 14:40:54 +08:00
										 |  |  |  | namespace kiwano | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |  * @brief 文件系统,为其他模块提供文件搜索规则等 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |  */ | 
					
						
							|  |  |  |  | class KGE_API FileSystem : public Singleton<FileSystem> | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     friend Singleton<FileSystem>; | 
					
						
							| 
									
										
										
										
											2019-10-11 21:12:29 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  | public: | 
					
						
							|  |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |      * @brief 添加文件搜索路径 | 
					
						
							|  |  |  |  |      * @param path 文件搜索路径 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |      */ | 
					
						
							|  |  |  |  |     void AddSearchPath(String const& path); | 
					
						
							| 
									
										
										
										
											2019-10-11 21:12:29 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |      * @brief 设置文件搜索路径 | 
					
						
							|  |  |  |  |      * @param paths 搜索路径数组 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |      */ | 
					
						
							|  |  |  |  |     void SetSearchPaths(Vector<String> const& paths); | 
					
						
							| 
									
										
										
										
											2019-10-11 21:12:29 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |      * @brief 在搜索列表中查找文件并获取完整路径 | 
					
						
							|  |  |  |  |      * @param file 文件路径 | 
					
						
							|  |  |  |  |      * @return 完整的文件路径 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |      */ | 
					
						
							|  |  |  |  |     String GetFullPathForFile(String const& file) const; | 
					
						
							| 
									
										
										
										
											2019-10-11 21:12:29 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |      * @brief 添加文件路径查找字典规则 | 
					
						
							|  |  |  |  |      * @param key 文件关键词 | 
					
						
							|  |  |  |  |      * @param file_path 文件路径 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |      */ | 
					
						
							|  |  |  |  |     void AddFileLookupRule(String const& key, String const& file_path); | 
					
						
							| 
									
										
										
										
											2019-10-11 21:12:29 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |      * @brief 设置文件路径查找字典 | 
					
						
							|  |  |  |  |      * @param dict 文件路径查找字典 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |      */ | 
					
						
							|  |  |  |  |     void SetFileLookupDictionary(UnorderedMap<String, String> const& dict); | 
					
						
							| 
									
										
										
										
											2019-10-11 21:12:29 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |      * @brief 文件是否存在 | 
					
						
							|  |  |  |  |      * @param file_path 文件路径 | 
					
						
							|  |  |  |  |      * @return 若文件存在,返回 true | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |      */ | 
					
						
							|  |  |  |  |     bool IsFileExists(String const& file_path) const; | 
					
						
							| 
									
										
										
										
											2019-10-11 21:12:29 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |      * @brief 判断路径是否是绝对路径 | 
					
						
							|  |  |  |  |      * @param path 文件路径 | 
					
						
							|  |  |  |  |      * @return 若是绝对路径,返回 true | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |      */ | 
					
						
							|  |  |  |  |     bool IsAbsolutePath(String const& path) const; | 
					
						
							| 
									
										
										
										
											2019-10-11 21:12:29 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |      * @brief 删除文件 | 
					
						
							|  |  |  |  |      * @param file_path 文件路径 | 
					
						
							|  |  |  |  |      * @return 删除是否成功 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |      */ | 
					
						
							|  |  |  |  |     bool RemoveFile(String const& file_path) const; | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |      * @brief 释放二进制资源到临时文件目录 | 
					
						
							|  |  |  |  |      * @param res 资源 | 
					
						
							|  |  |  |  |      * @param dest_file_name 目标文件名 | 
					
						
							|  |  |  |  |      * @return 操作是否成功 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |      */ | 
					
						
							|  |  |  |  |     bool ExtractResourceToFile(Resource const& res, String const& dest_file_name) const; | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  | private: | 
					
						
							|  |  |  |  |     FileSystem(); | 
					
						
							| 
									
										
										
										
											2019-10-11 21:12:29 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |     ~FileSystem(); | 
					
						
							| 
									
										
										
										
											2019-07-29 14:48:17 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  | private: | 
					
						
							|  |  |  |  |     Vector<String>                       search_paths_; | 
					
						
							|  |  |  |  |     UnorderedMap<String, String>         file_lookup_dict_; | 
					
						
							|  |  |  |  |     mutable UnorderedMap<String, String> file_lookup_cache_; | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | }  // namespace kiwano
 |