From 6338b04140e5efe64bc079f951059ed9b960c3e9 Mon Sep 17 00:00:00 2001 From: lossStick214 <80992179+lossStick214@users.noreply.github.com> Date: Wed, 11 Dec 2024 07:06:09 +0300 Subject: [PATCH 1/3] Fixed write & read functions --- Config/Include/config.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Config/Include/config.cpp b/Config/Include/config.cpp index b9f3fed..619578e 100644 --- a/Config/Include/config.cpp +++ b/Config/Include/config.cpp @@ -12,8 +12,8 @@ void holder_t::load(const char* path, const char* file) std::filesystem::path fileObj(file); std::filesystem::path config_path = pathObj / fileObj; - auto config_file = OpenFile(config_path.string()); - if (!config_file) + auto config_file = OpenFileI(config_path.string()); + if (!config_file || !config_file.is_open()) return; std::string config_str = ReadFile(config_file); @@ -21,7 +21,7 @@ void holder_t::load(const char* path, const char* file) for (auto x : m_nodes) x->load_setting(config_str); - CloseFile(config_file); + config_file.close(); } void holder_t::load(std::string& config) @@ -45,11 +45,10 @@ void holder_t::save(const char* path, const char* file) CreateFolder(pathObj.string()); //Save File - auto files = OpenFile(config_path, std::ios::app | std::ios::in); + auto files = OpenFileO(config_path); WriteToFile("", files); - CloseFile(files); - std::ofstream config_file = OpenFile(config_path); + std::ofstream config_file = OpenFileO(config_path); std::string config_str; @@ -57,7 +56,7 @@ void holder_t::save(const char* path, const char* file) x->save_setting(config_str); WriteToFile(config_str, config_file); - CloseFile(config_file); + config_file.close(); } c_settings settings; From 36ed7612082ee54ee9cda857def62cc03fddb0cf Mon Sep 17 00:00:00 2001 From: lossStick214 <80992179+lossStick214@users.noreply.github.com> Date: Wed, 11 Dec 2024 07:06:41 +0300 Subject: [PATCH 2/3] Fixed write & read functions --- Config/Include/fileIO.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Config/Include/fileIO.cpp b/Config/Include/fileIO.cpp index e8cf093..e742a64 100644 --- a/Config/Include/fileIO.cpp +++ b/Config/Include/fileIO.cpp @@ -3,10 +3,8 @@ bool DoesPathExist(std::string path) { - if (std::filesystem::exists(path)) - return true; - else - return false; + return std::filesystem::exists(path); + } void CreateFolder(std::string path) @@ -25,17 +23,18 @@ std::vector GetFileList(std::string path) return ret; } -std::ofstream OpenFile(std::string name, std::ios_base::openmode mode) +std::ofstream OpenFileO(std::string name) { std::ofstream file; - file.open(name, mode); + file.open(name, std::fstream::out); return file; } -void CloseFile(std::ofstream& file) +std::ifstream OpenFileI(std::string name) { - if (file) - file.close(); + std::ifstream file; + file.open(name, std::fstream::in); + return file; } bool WriteToFile(std::string buffer, std::ofstream& file) @@ -46,13 +45,11 @@ bool WriteToFile(std::string buffer, std::ofstream& file) return true; } -std::string ReadFile(std::ofstream& file) +std::string ReadFile(std::ifstream& file) { if (!file.is_open()) return ""; - file.seekp(0, std::ios_base::beg); - std::stringstream bffr; bffr << file.rdbuf(); return bffr.str(); From 3241592c18b8cef1147d62678a63badc32b4a7a9 Mon Sep 17 00:00:00 2001 From: lossStick214 <80992179+lossStick214@users.noreply.github.com> Date: Wed, 11 Dec 2024 07:07:04 +0300 Subject: [PATCH 3/3] Fix externs for new functions --- Config/Include/fileIO.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Config/Include/fileIO.h b/Config/Include/fileIO.h index 6078480..ccbd19f 100644 --- a/Config/Include/fileIO.h +++ b/Config/Include/fileIO.h @@ -2,10 +2,10 @@ #include #include -extern std::string ReadFile(std::ofstream& file); +extern std::string ReadFile(std::ifstream& file); extern bool WriteToFile(std::string buffer, std::ofstream& file); -extern void CloseFile(std::ofstream& file); -extern std::ofstream OpenFile(std::string name, std::ios_base::openmode mode = std::fstream::in | std::fstream::out); +extern std::ofstream OpenFileO(std::string name); +extern std::ifstream OpenFileI(std::string name); extern std::vector GetFileList(std::string path); extern void CreateFolder(std::string path); extern bool DoesPathExist(std::string path);