コード例 #1
0
        public static T LoadBinary <T>(Mod mod, string file_name_has_ext, out bool success) where T : class
        {
            T file = DataFileHelpers.LoadBinary <T>(mod, file_name_has_ext, false);

            success = file != null;

            return(file);
        }
コード例 #2
0
        ////////////////

        private static void PrepareDir(Mod mod)
        {
            string full_dir = DataFileHelpers.GetFullDirectoryPath(mod);

            try {
                Directory.CreateDirectory(Main.SavePath);
                Directory.CreateDirectory(Main.SavePath + Path.DirectorySeparatorChar + DataFileHelpers.BaseFolder);
                Directory.CreateDirectory(full_dir);
            } catch (IOException e) {
                throw new IOException("Failed to prepare directory: " + full_dir, e);
            }
        }
コード例 #3
0
        public static void SaveAsBinary <T>(Mod mod, string file_name_has_ext, bool is_cloud, T data) where T : class
        {
            DataFileHelpers.PrepareDir(mod);

            string full_path = DataFileHelpers.GetFullPath(mod, file_name_has_ext);

            try {
                FileHelpers.SaveBinaryFile <T>(data, full_path, is_cloud, false);
            } catch (IOException e) {
                string full_dir = DataFileHelpers.GetFullDirectoryPath(mod);
                throw new IOException("Failed to save binary file " + file_name_has_ext + " at " + full_dir, e);
            }
        }
コード例 #4
0
        ////////////////

        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);
            }
        }
コード例 #5
0
        public static T LoadBinary <T>(Mod mod, string file_name_has_ext, bool is_cloud) where T : class
        {
            DataFileHelpers.PrepareDir(mod);

            string full_path = DataFileHelpers.GetFullPath(mod, file_name_has_ext);

            try {
                return(FileHelpers.LoadBinaryFile <T>(full_path, is_cloud));
            } catch (IOException e) {
                string full_dir = DataFileHelpers.GetFullDirectoryPath(mod);
                throw new IOException("Failed to load binary file " + file_name_has_ext + " at " + full_dir, e);
            }
        }
コード例 #6
0
        ////////////////

        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);
            }
        }
コード例 #7
0
 public static string GetFullPath(Mod mod, string file_name_has_ext)
 {
     return(DataFileHelpers.GetFullDirectoryPath(mod) + Path.DirectorySeparatorChar + file_name_has_ext);
 }
コード例 #8
0
 public static string GetFullDirectoryPath(Mod mod)
 {
     return(Main.SavePath + Path.DirectorySeparatorChar + DataFileHelpers.GetRelativeDirectoryPath(mod));
 }
コード例 #9
0
 public static void SaveAsBinary <T>(Mod mod, string file_name_has_ext, T data) where T : class
 {
     DataFileHelpers.SaveAsBinary <T>(mod, file_name_has_ext, false, data);
 }