//////////////// public static void SaveAsJson <T>(Mod mod, string file_name_no_ext, T data) where T : class { DataFileHelpers.PrepareDir(mod); string rel_dir = DataFileHelpers.GetRelativeDirectoryPath(mod); try { var json_file = new JsonConfig <T>(file_name_no_ext + ".json", rel_dir, data); json_file.SaveFile(); } catch (IOException e) { throw new IOException("Failed to save json file " + file_name_no_ext + " at " + rel_dir, e); } }
//////////////// public static T LoadJson <T>(Mod mod, string file_name_no_ext, out bool success) where T : class { DataFileHelpers.PrepareDir(mod); string rel_dir = DataFileHelpers.GetRelativeDirectoryPath(mod); success = false; try { var json_file = new JsonConfig <T>(file_name_no_ext + ".json", rel_dir); success = json_file.LoadFile(); return(json_file.Data); } catch (IOException e) { string full_dir = DataFileHelpers.GetFullDirectoryPath(mod); throw new IOException("Failed to load json file " + file_name_no_ext + " at " + full_dir, e); } }
public static string GetFullDirectoryPath(Mod mod) { return(Main.SavePath + Path.DirectorySeparatorChar + DataFileHelpers.GetRelativeDirectoryPath(mod)); }