Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Config/Include/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ 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);

for (auto x : m_nodes)
x->load_setting(config_str);

CloseFile(config_file);
config_file.close();
}

void holder_t::load(std::string& config)
Expand All @@ -45,19 +45,18 @@ 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;

for (auto x : m_nodes)
x->save_setting(config_str);

WriteToFile(config_str, config_file);
CloseFile(config_file);
config_file.close();
}

c_settings settings;
21 changes: 9 additions & 12 deletions Config/Include/fileIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -25,17 +23,18 @@ std::vector<std::filesystem::path> 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)
Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions Config/Include/fileIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#include <fstream>
#include <filesystem>

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<std::filesystem::path> GetFileList(std::string path);
extern void CreateFolder(std::string path);
extern bool DoesPathExist(std::string path);