diff --git a/uppsrc/Core/JSON.cpp b/uppsrc/Core/JSON.cpp index be682203d..32b5797a5 100644 --- a/uppsrc/Core/JSON.cpp +++ b/uppsrc/Core/JSON.cpp @@ -304,4 +304,9 @@ template<> void Jsonize(JsonIO& io, Time& var) var.year, var.month, var.day, var.hour, var.minute, var.second)); } +String sJsonFile(const char *file) +{ + return file ? String(file) : ConfigFile(GetExeTitle() + ".json"); +} + END_UPP_NAMESPACE diff --git a/uppsrc/Core/JSON.h b/uppsrc/Core/JSON.h index 11c34f5ce..4ee2d6b95 100644 --- a/uppsrc/Core/JSON.h +++ b/uppsrc/Core/JSON.h @@ -174,6 +174,20 @@ bool LoadFromJson(T& var, const char *json) return true; } +String sJsonFile(const char *file); + +template +bool StoreAsJsonFile(const T& var, const char *file, bool pretty = false) +{ + return SaveFile(sJsonFile(file), StoreAsJson(var, pretty));; +} + +template +bool LoadFromJsonFile(T& var, const char *file = NULL) +{ + return LoadFromJson(var, LoadFile(sJsonFile(file))); +} + template<> void Jsonize(JsonIO& io, int& var); template<> void Jsonize(JsonIO& io, int64& var); template<> void Jsonize(JsonIO& io, double& var);