Exemple #1
0
        /*
         *  ----------
         *  Essentials
         *  ----------
         */

        public List <QueueItem> GetQueue()
        {
            // Get all mods with valid Github URLs.
            List <ModConfig> allMods = ModUtilities.GetAllMods();

            allMods = GetConfigsWithValidGithubUrl(allMods);

            // Get mappings from all mods.
            List <QueueItem> mappings = FromModList(allMods);

            // Get mappings already stored on disk.
            List <QueueItem> fileMappings = new List <QueueItem>();

            try   { fileMappings = JsonConvert.DeserializeObject <List <QueueItem> >(File.ReadAllText(SavePath)); }
            catch { }

            // Assign each mapping's proper last checked date.
            for (int x = 0; x < mappings.Count; x++)
            {
                foreach (var fileMapping in fileMappings)
                {
                    if (mappings[x].ModId == fileMapping.ModId)
                    {
                        var updateMapping = mappings[x];
                        updateMapping.LastChecked = fileMapping.LastChecked;
                        mappings[x] = updateMapping;
                        break;
                    }
                }
            }

            // Sort mappings.
            return(SortQueue(mappings));
        }
        /// <summary>
        /// Retrieves a list of all mod configurations for each game and adds the ones with GameBananaUpdater.json
        /// to the list.
        /// </summary>
        /// <param name="gbModEntries"></param>
        /// <returns></returns>
        public List <GBModEntry> GetEntriesFromExistingMods(List <GBModEntry> gbModEntries)
        {
            // Get all of the individual mods, and then if a manual config file exists, try parsing
            // it and adding a new GBModEntry.
            List <ModConfig> allExistingMods = ModUtilities.GetAllMods();

            foreach (ModConfig existingMod in allExistingMods)
            {
                string potentialFileLocation = $"{existingMod.GetModDirectory()}\\{ModManualEntryFileName}";
                if (File.Exists(potentialFileLocation))
                {
                    try
                    {
                        var simpleModEntry = JsonConvert.DeserializeObject <GBSimpleModEntry>(File.ReadAllText(potentialFileLocation));
                        simpleModEntry.ModConfig = existingMod;
                        gbModEntries.Add(GBModEntry.FromSimpleModEntry(simpleModEntry));
                    }
                    catch (Exception ex)
                    {
                        // Write correct template.
                        string templateFileName = potentialFileLocation.Replace(".json", "Example.json");
                        string json             = JsonConvert.SerializeObject(new GBSimpleModEntry("Example", 123456, null), Formatting.Indented);
                        json += $"\r\n\r\n/*You did something wrong in your GameBanana.json, so here's a template to help you.\r\nHere's a tip about what you did wrong {ex.Message}*/";

                        File.WriteAllText(templateFileName, json);
                    }
                }
            }

            return(gbModEntries);
        }