Exemple #1
0
        /// <summary>
        /// Saves a custom mod data JSON file.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="mod"></param>
        /// <param name="fileNameNoExt"></param>
        /// <param name="jsonSettings"></param>
        /// <param name="overrides">Replaces any existing files.</param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static bool SaveAsJson <T>(
            Mod mod,
            string fileNameNoExt,
            JsonSerializerSettings jsonSettings,
            bool overrides, T data)
            where T : class
        {
            string relDir = ModCustomDataFileLibraries.GetRelativeDirectoryPath(mod);

            if (data == null)
            {
                LogLibraries.Warn("Failed to save json file " + fileNameNoExt + " at " + relDir + " - Data is null.");
                return(false);
            }

            try {
                ModCustomDataFileLibraries.PrepareDir(mod);

                string fullPath = ModCustomDataFileLibraries.GetFullPath(mod, fileNameNoExt + ".json");
                string dataJson = JsonConvert.SerializeObject(data, jsonSettings);

                return(FileLibraries.SaveTextFile(dataJson, fullPath, false, !overrides));
            } catch (IOException e) {
                LogLibraries.Warn("Failed to save json file " + fileNameNoExt + " at " + relDir + " - " + e.ToString());
                throw new IOException("Failed to save json file " + fileNameNoExt + " at " + relDir, e);
            }
        }
Exemple #2
0
 /// <summary>
 /// Gets the full system directory of a mod's custom data folder.
 /// </summary>
 /// <param name="mod"></param>
 /// <returns></returns>
 public static string GetFullDirectoryPath(Mod mod)
 {
     return(Main.SavePath + Path.DirectorySeparatorChar + ModCustomDataFileLibraries.GetRelativeDirectoryPath(mod));
 }