Added fileCommon, added freebie font, start listening to SDL Keyboard text input
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#include "fileCommon.h"
|
||||
#include "json.hpp"
|
||||
|
||||
|
||||
bool OpenFile(fs::path path) {
|
||||
path = fs::absolute(path);
|
||||
|
||||
if (!fs::exists(path)) {
|
||||
printf("File Read error! Could not find file at: \n");
|
||||
printf("%s\n", path.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
stream.open(absolute(path));
|
||||
if (!stream) {
|
||||
printf("Error opening stream \n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
nlohmann::json GetData() {
|
||||
if (!stream) {
|
||||
printf("Open the file first! \n");
|
||||
return nlohmann::json();
|
||||
}
|
||||
|
||||
return nlohmann::json::parse(stream);
|
||||
}
|
||||
|
||||
bool SaveJsonFile(fs::path path, nlohmann::json j) {
|
||||
|
||||
if (stream) {
|
||||
printf("Stream open for reading! Please close stream before saving \n");
|
||||
return false;
|
||||
}
|
||||
|
||||
stream.open(absolute(path), std::fstream::in | std::fstream::out | std::fstream::app);
|
||||
stream << std::setw(4) << j << std::endl;
|
||||
|
||||
stream.close();
|
||||
}
|
||||
Reference in New Issue
Block a user