Can load and save configuration files#1
Conversation
| @@ -0,0 +1,37 @@ | |||
| #include "configuration.h" | |||
|
|
|||
| #include <filesystem> | |||
There was a problem hiding this comment.
Sort these include statements so that all the internal includes and external includes are next to each other.
| namespace game_bridge { | ||
| void InitializeConfiguration() | ||
| { | ||
| if (!fs::exists(SRGB_CONFIGURATION_PATH)) |
There was a problem hiding this comment.
What are you doing here? Checking if a config is present and if it isn't, adding an empty one there? Please add a comment explaining this.
There was a problem hiding this comment.
I added comments and documentation 0202cc1
| std::string data = json_vec.dump(1); // Dump with indentation of 1 for pretty print! | ||
| WriteTextToFile(SRGB_CONFIGURATION_PATH, data); | ||
|
|
||
| std::cout << "No configuration file found, created one!" << "\n"; |
There was a problem hiding this comment.
Split into a log when no config is found and a log when you have generated an empty one.
There was a problem hiding this comment.
I put the log in the initialize function, I'd like to have the save and load function to have no logging for now to keep logging more clean. So we should log what we doe when we call these functions. 0202cc1
| std::string unique_hash; | ||
| std::string title; | ||
| std::string path_to_exe; | ||
| std::string selected3_d_method; |
There was a problem hiding this comment.
Typo in name here, that's my bad but it should be fixed.
| bool WriteTextToFile(const std::string& path, const std::string& buffer) | ||
| { | ||
| std::ofstream myfile(path); | ||
| if (myfile.is_open()) |
There was a problem hiding this comment.
Can this crash if the path is invalid?
There was a problem hiding this comment.
Not sure, haven't put in any exception handling because I'm just rushing a prototype here. I'd rather not include that now either to make something quickly work and add it later. I will add some todos
| std::stringstream stream; | ||
| std::string line; | ||
| std::ifstream myfile(path); | ||
| if (myfile.is_open()) |
There was a problem hiding this comment.
Can this crash if the path is invalid?
|
|
||
| std::vector<GameConfiguration> LoadConfiguration() | ||
| { | ||
| std::string read_data = ReadTextFile(SRGB_CONFIGURATION_PATH); |
There was a problem hiding this comment.
How about: return json::parse(ReadTextFile(SRGB_CONFIGURATION_PAHT));
Doesn't seem to work with the hooks we want. This method is also not recommended by Microsoft
No documentation, focussing on speed atm