Beispiel #1
0
        private static void writeInstalledModToJson(ModFile[] files)
        {
            var modexport = new InstalledModsFormat();

            modexport.InstalledMods = files;                                                //drops file into installedmodsformat
            File.WriteAllText(Utilities.ModCache,
                              JsonConvert.SerializeObject(modexport, Formatting.Indented)); //serialize and write to file
        }
Beispiel #2
0
        /// <summary>
        ///     Gets the currently installed mods from the JSON files
        /// </summary>
        /// <returns>String array with the installed mods</returns>
        public static ModFile[] GetInstalledMods()
        {
            if (!File.Exists(Utilities.ModCache))
            {
                return(Array.Empty <ModFile>());
            }
            Console.WriteLine("Reading from " + Utilities.ModCache);
            InstalledModsFormat input = null;

            try
            {
                input = JsonConvert.DeserializeObject <InstalledModsFormat>(File.ReadAllText(Utilities.ModCache));
            }
            catch
            {
                //this here tries to convert the json file into a new file. If it doesn't work, it just deletes and starts over.
                try
                {
                    var depInput =
                        JsonConvert.DeserializeObject <DeprecatedInstalledModsFormat>(
                            File.ReadAllText(Directory.GetCurrentDirectory() + "/installedmods.json"));
                    File.Delete(Utilities.ModCache);
                    Console.WriteLine("Mods cache is in a deprecated format, converting!");
                    foreach (var t in depInput.InstalledMods)
                    {
                        AddInstalledMod(t);
                    }
                }
                catch
                {
                    var err = MessageBox.Show("Mod cache (installed_mods.json) IS INVALID!\nThis is most likely because Deli Counter was used for installing mods, before Mod Installer!\n(if you had any installed mods with Deli Counter from before, it could cause serious issues!)\n\nThese programs are not compatible, delete?", "Mod Cache INVALID!", MessageBoxButtons.YesNo, MessageBoxIcon.Error);

                    if (err == DialogResult.Yes)
                    {
                        File.Delete(Utilities.ModCache);
                    }
                }
            }


            return(input == null?Array.Empty <ModFile>() : input.InstalledMods);
        }