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();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include "json.hpp"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
static std::fstream stream;
|
||||
|
||||
extern bool OpenFile(fs::path path);
|
||||
extern nlohmann::json GetData();
|
||||
/// Note we have a specific function for json for pretty printing purpose
|
||||
bool SaveJsonFile(fs::path path, nlohmann::json j);
|
||||
// bool SaveFile(fs::path path, void *dataToSave); // Leaving it commented out until later
|
||||
inline void CloseFileStream() { stream.close(); }
|
||||
Reference in New Issue
Block a user