From 407de7999c736f3e89f6ccb7e28324ee5bd6d4fe Mon Sep 17 00:00:00 2001 From: ninemine <1371605831@qq.com> Date: Sat, 26 Jul 2025 23:23:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Convention/[Runtime]/Config.hpp | 10 +++++++- Convention/[Runtime]/File.hpp | 36 +++++++++++++++++++-------- Convention/[Runtime]/GlobalConfig.hpp | 26 ++++++++++--------- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/Convention/[Runtime]/Config.hpp b/Convention/[Runtime]/Config.hpp index fb9beea..5c12bca 100644 --- a/Convention/[Runtime]/Config.hpp +++ b/Convention/[Runtime]/Config.hpp @@ -1394,7 +1394,9 @@ struct StringIndicator static str ToString(const T& value) { if_exists(T::ToString) + { return value.ToString(); + } if constexpr (std::is_constructible_v) return value; else if constexpr (std::is_same_v) @@ -1800,6 +1802,11 @@ namespace Convention public: constexpr static size_t size = 0; constexpr static size_t _MySize = 0; + template + constexpr static size_t ElementOffset() + { + return 0; + } }; } @@ -1871,6 +1878,7 @@ namespace Convention using _SharedPtr = SharedPtr; using _UniquePtr = UniquePtr>; using _Mybase = std::conditional_t; + using _MyAlloc = Allocator; private: /** * @brief 获取内存管理器 @@ -1885,7 +1893,7 @@ namespace Convention { T* ptr = GetStaticMyAllocator().allocate(1); GetStaticMyAllocator().construct(ptr, std::forward(args)...); - return ptr + return ptr; } static void _DestoryMyPtr(_In_ T* ptr) { diff --git a/Convention/[Runtime]/File.hpp b/Convention/[Runtime]/File.hpp index 6a5758f..7e51616 100644 --- a/Convention/[Runtime]/File.hpp +++ b/Convention/[Runtime]/File.hpp @@ -10,13 +10,25 @@ namespace Convention { private: std::filesystem::path FullPath; - mutable std::fstream OriginControlStream; - mutable bool StreamOpen = false; + //mutable std::fstream OriginControlStream; + //mutable bool StreamOpen = false; public: - explicit ToolFile(const std::filesystem::path& path) : FullPath(path) {} - explicit ToolFile(const std::string& path) : FullPath(path) {} - explicit ToolFile(const char* path) : FullPath(path) {} + ToolFile(const std::filesystem::path& path) : FullPath(path) {} + ToolFile(const std::string& path) : FullPath(path) {} + ToolFile(const char* path) : FullPath(path) {} + ToolFile(const ToolFile& other) : FullPath(other.FullPath) {} + ToolFile(ToolFile&& other) : FullPath(std::move(other.FullPath)) {} + ToolFile& operator=(const ToolFile& other) + { + this->FullPath = other.FullPath; + return *this; + } + ToolFile& operator=(ToolFile&& other) + { + this->FullPath = std::move(other.FullPath); + return *this; + } // Convert to string operator std::string() const { return FullPath.string(); } @@ -85,20 +97,21 @@ namespace Convention return *this; } - ToolFile& Open(std::ios::openmode mode = std::ios::in | std::ios::out) + /*ToolFile& Open(std::ios::openmode mode = std::ios::in | std::ios::out) { Close(); OriginControlStream.open(FullPath, mode); StreamOpen = OriginControlStream.is_open(); return *this; - } + }*/ ToolFile& Close() { - if (StreamOpen) { + /*if (StreamOpen) + { OriginControlStream.close(); StreamOpen = false; - } + }*/ return *this; } @@ -154,7 +167,8 @@ namespace Convention ToolFile& MustExistsPath() { auto parent = FullPath.parent_path(); - if (!parent.empty() && !std::filesystem::exists(parent)) { + if (!parent.empty() && !std::filesystem::exists(parent)) + { std::filesystem::create_directories(parent); } return *this; @@ -320,4 +334,4 @@ namespace Convention }; } -#endif // Convention_Runtime_File_hpp \ No newline at end of file +#endif // Convention_Runtime_File_hpp diff --git a/Convention/[Runtime]/GlobalConfig.hpp b/Convention/[Runtime]/GlobalConfig.hpp index f101ec8..1535662 100644 --- a/Convention/[Runtime]/GlobalConfig.hpp +++ b/Convention/[Runtime]/GlobalConfig.hpp @@ -16,14 +16,12 @@ namespace Convention static void InitExtensionEnv() { ConstConfigFile = "config.json"; - ProjectConfig::InitExtensionEnv(); } static void GenerateEmptyConfigJson(ToolFile& file) { nlohmann::json config; config["properties"] = nlohmann::json::object(); - file.Open(std::ios::out | std::ios::trunc); file.SaveAsText(config.dump(4)); file.Close(); } @@ -69,7 +67,8 @@ namespace Convention ToolFile GetFile(const std::string& path, bool isMustExist = false) { auto file = DataDir | path; - if (isMustExist) { + if (isMustExist) + { file.MustExistsPath(); } return file; @@ -78,13 +77,16 @@ namespace Convention bool EraseFile(const std::string& path) { auto file = DataDir | path; - if (file.Exists()) { - try { - file.Open(std::ios::out | std::ios::trunc); - file.Close(); - return true; - } catch (...) {} - } + if (file.Exists()) + { + file.MustExistsPath(); + if (file.IsFile()) + { + file.Remove(); + file.Create(); + } + return true; + } return false; } @@ -209,7 +211,7 @@ namespace Convention MyDefaultLogger = std::move(logger); } - virtual void Log(const std::string& messageType, const std::string& message, std::function logger = nullptr) + virtual void Log(const std::string& messageType, const std::string& message, std::function logger) { configLogging_tspace = std::max(configLogging_tspace, messageType.length()); @@ -305,4 +307,4 @@ namespace Convention std::string ProjectConfig::ProjectConfigFileFocus = "Assets/"; } -#endif // Convention_Runtime_GlobalConfig_hpp \ No newline at end of file +#endif // Convention_Runtime_GlobalConfig_hpp