コード例 #1
0
        ////////////////

        public static void SaveAsJson <T>(Mod mod, string fileNameNoExt, JsonSerializerSettings jsonSettings, T data) where T : class
        {
            DataFileHelpers.PrepareDir(mod);

            string relDir = DataFileHelpers.GetRelativeDirectoryPath(mod);

            try {
                var jsonFile = new JsonConfig <T>(fileNameNoExt + ".json", relDir, data, jsonSettings);
                jsonFile.SaveFile();
            } catch (IOException e) {
                LogHelpers.Warn("Failed to save json file " + fileNameNoExt + " at " + relDir + " - " + e.ToString());
                throw new IOException("Failed to save json file " + fileNameNoExt + " at " + relDir, e);
            }
        }
コード例 #2
0
        public static T LoadBinary <T>(Mod mod, string fileNameHasExt, bool isCloud, JsonSerializerSettings jsonSettings) where T : class
        {
            DataFileHelpers.PrepareDir(mod);

            string fullPath = DataFileHelpers.GetFullPath(mod, fileNameHasExt);

            try {
                return(FileHelpers.LoadBinaryFile <T>(fullPath, isCloud, jsonSettings));
            } catch (IOException e) {
                string fullDir = DataFileHelpers.GetFullDirectoryPath(mod);
                LogHelpers.Warn("Failed to load binary file " + fileNameHasExt + " at " + fullDir + " - " + e.ToString());
                throw new IOException("Failed to load binary file " + fileNameHasExt + " at " + fullDir, e);
            }
        }
コード例 #3
0
        public static void SaveAsBinary <T>(Mod mod, string fileNameHasExt, bool isCloud, JsonSerializerSettings jsonSettings, T data) where T : class
        {
            DataFileHelpers.PrepareDir(mod);

            string fullPath = DataFileHelpers.GetFullPath(mod, fileNameHasExt);

            try {
                FileHelpers.SaveBinaryFile <T>(data, fullPath, isCloud, false, jsonSettings);
            } catch (IOException e) {
                string fullDir = DataFileHelpers.GetFullDirectoryPath(mod);
                LogHelpers.Warn("Failed to save binary file " + fileNameHasExt + " at " + fullDir + " - " + e.ToString());
                throw new IOException("Failed to save binary file " + fileNameHasExt + " at " + fullDir, e);
            }
        }
コード例 #4
0
        ////////////////

        public static T LoadJson <T>(Mod mod, string fileNameNoExt, JsonSerializerSettings jsonSettings, out bool success) where T : class
        {
            DataFileHelpers.PrepareDir(mod);

            string relDir = DataFileHelpers.GetRelativeDirectoryPath(mod);

            success = false;

            try {
                var jsonFile = new JsonConfig <T>(fileNameNoExt + ".json", relDir, jsonSettings);
                success = jsonFile.LoadFile();

                return(jsonFile.Data);
            } catch (IOException e) {
                string fullDir = DataFileHelpers.GetFullDirectoryPath(mod);
                LogHelpers.Warn("Failed to load json file " + fileNameNoExt + " at " + fullDir + " - " + e.ToString());
                throw new IOException("Failed to load json file " + fileNameNoExt + " at " + fullDir, e);
            } catch (Exception e) {
                throw new HamstarException("From " + fileNameNoExt + " (" + typeof(T).Name + ")", e);
            }
        }