Skip to content

Can load and save configuration files#1

Open
JoeyAnthony wants to merge 15 commits into
mainfrom
feature/game-configuration
Open

Can load and save configuration files#1
JoeyAnthony wants to merge 15 commits into
mainfrom
feature/game-configuration

Conversation

@JoeyAnthony

Copy link
Copy Markdown
Collaborator

No documentation, focussing on speed atm

@@ -0,0 +1,37 @@
#include "configuration.h"

#include <filesystem>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort these include statements so that all the internal includes and external includes are next to each other.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 0202cc1

namespace game_bridge {
void InitializeConfiguration()
{
if (!fs::exists(SRGB_CONFIGURATION_PATH))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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";

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split into a log when no config is found and a log when you have generated an empty one.

@JoeyAnthony JoeyAnthony Jul 6, 2023

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in name here, that's my bad but it should be fixed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 0202cc1

bool WriteTextToFile(const std::string& path, const std::string& buffer)
{
std::ofstream myfile(path);
if (myfile.is_open())

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this crash if the path is invalid?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this crash if the path is invalid?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here #1 (comment)


std::vector<GameConfiguration> LoadConfiguration()
{
std::string read_data = ReadTextFile(SRGB_CONFIGURATION_PATH);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about: return json::parse(ReadTextFile(SRGB_CONFIGURATION_PAHT));

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it 0202cc1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants