コード例 #1
0
        public List <string> GetRegionsForModIDs(ModsData modsData, List <int> modIds)
        {
            List <string> regions = new List <string>();

            foreach (var modItem in modsData.Mods)
            {
                if (modIds.Contains(modItem.Id))
                {
                    if (!modItem.Region.Equals("ALL") || !modItem.GameRegions.Contains("All Regions") || !modItem.GameRegions.Contains("-") || !modItem.GameRegions.Contains("n/a") || !modItem.GameRegions.Contains(""))
                    {
                        if (!regions.Any(x => modItem.GameRegions.Any(y => y == x)))
                        {
                            if (!modItem.GameRegions.Contains("All Regions"))
                            {
                                if (!modItem.GameRegions.Contains("n/a"))
                                {
                                    regions.AddRange(modItem.GameRegions);
                                }
                            }
                        }
                    }
                }
            }

            return(regions.Distinct().ToList());
        }
コード例 #2
0
        /// <summary>
        /// Determines whether a installed package file is out of date by checking current package files in the database.
        /// </summary>
        /// <param name="modsData"></param>
        /// <param name="categoriesData"></param>
        /// <param name="packageFile"></param>
        /// <returns></returns>
        public bool IsPackageFileOldVersion(ModsData modsData, CategoriesData categoriesData, PackageFile packageFile)
        {
            foreach (var modItem in modsData.Mods)
            {
                if (modItem.GetCategoryType(categoriesData) == CategoryType.Homebrew)
                {
                    if (packageFile.Id.Equals(modItem.Id))
                    {
                        try
                        {
                            Version oldVersion = Version.Parse(packageFile.Version);
                            Version newVersion = Version.Parse(modItem.Version);

                            if (oldVersion.CompareTo(newVersion) < 0)
                            {
                                return(true);
                            }
                        }
                        catch
                        {
                            return(false);
                        }
                    }
                }
            }

            return(false);
        }
コード例 #3
0
    public static void UpdateSaveData(ModsData modsData)
    {
        if (modsData.version < 1.1f)
        {
            foreach (ModInfo mod in modsData.modInfos)
            {
                if (File.Exists(mod.modPath))
                {
                    mod.date = File.GetCreationTime(mod.modPath);
                }
            }
        }


        if (modsData.version < 1.4f)
        {
            string path = Serializer.GetMMDataFolder();

            try {
                (path + "SharpCompress.dll").DeleteIfPathExists();
                (path + "ObjectListView.dll").DeleteIfPathExists();
                (path + "SevenZipSharp.dll").DeleteIfPathExists();
            } catch (Exception ex) {
            }
        }

        modsData.version = MainForm.programVersion;
    }
コード例 #4
0
    public static async Task SaveLoadoutAuto(string path, bool rescan = true)
    {
        Task scanTask = Task.Factory.StartNew(() => {
            if (rescan)
            {
                foreach (var mod in modsData.modInfos)
                {
                    mod.CheckIfInstalled();
                }
            }
        });

        await scanTask;

        //save here
        string saveFolder = Path.GetDirectoryName(path);

        Directory.CreateDirectory(saveFolder);


        ModsData saveData = new ModsData();

        saveData.modInfos = modsData.modInfos;
        Serializer.SaveObj(saveData, path);
    }
コード例 #5
0
        /// <summary>
        ///     Retrieve the mods data from the loaded database
        /// </summary>
        /// <param name="modsData">Name of the mod</param>
        /// <param name="modId">Name of the mod</param>
        /// <returns>Mod information</returns>
        internal static ModsData.ModItem GetModById(ModsData modsData, long modId)
        {
            foreach (ModsData.ModItem mod in modsData.Mods)
            {
                if (mod.Id == modId)
                {
                    return(mod);
                }
            }

            throw new Exception($"Unable to match with modId : {modId}");
        }
コード例 #6
0
        public List <string> GetModTypesForModIDs(ModsData modsData, List <int> modIds)
        {
            List <string> modTypes = new List <string>();

            foreach (var modItem in modsData.Mods)
            {
                if (modIds.Contains(modItem.Id))
                {
                    modTypes.AddRange(modItem.ModTypes);
                }
            }

            return(modTypes.Distinct().ToList());
        }
コード例 #7
0
    void LoadData()
    {
        modsData = Serializer.LoadObj(Serializer.GetDataFilePath()) as ModsData;
        if (!modsData)
        {
            modsData = new ModsData();
        }
        else
        {
            SaveUpdater.UpdateSaveData(modsData);
        }

        //modsData.modInfos = new List<ModInfo>();

        textBoxGameDir.Text   = modsData.gameDir;
        textBoxModFolder.Text = modsData.modDir;

        checkBoxIgnoreTopFiles.Checked = !modsData.useTopLevelFiles;
    }
コード例 #8
0
    public static void SaveLoadout()
    {
        Task scanTask = Task.Factory.StartNew(() => {
            foreach (var mod in modsData.modInfos)
            {
                mod.CheckIfInstalled();
            }
        });

        SaveFileDialog fileDialog = new SaveFileDialog()
        {
            InitialDirectory = string.IsNullOrEmpty(modsData.lastSaveDialoguePath) ? Serializer.GetMMDataFolder() : modsData.lastSaveDialoguePath,
            Title            = "Input Mod Loadout Save Location",
            ValidateNames    = true, AddExtension = true, FileName = "ModLoadout", Filter = selectDialogFilter
        };

        var result = fileDialog.ShowDialog();

        if (result != DialogResult.OK)
        {
            return;
        }

        scanTask.Wait();

        //save here
        string savePath   = fileDialog.FileName;
        string saveFolder = Path.GetDirectoryName(savePath);

        modsData.lastSaveDialoguePath = saveFolder;
        Directory.CreateDirectory(saveFolder);

        ModsData saveData = new ModsData();

        saveData.modInfos = modsData.modInfos;
        Serializer.SaveObj(saveData, savePath);
    }
コード例 #9
0
ファイル: MainForm.cs プロジェクト: gatekeeper1122/ModioX
 /// <summary>
 ///     Retrieves the games and mods data into the application
 /// </summary>
 private static void LoadData()
 {
     GamesData = Utilities.GetGamesData();
     ModsData  = Utilities.GetModsData();
 }
コード例 #10
0
    public static async void LoadLoadout()
    {
        Task saveBakTask = SaveLoadoutAuto(Serializer.GetMMDataFolder() + "LastLoadoutStateBackup.mlf", false);


        OpenFileDialog fileDialog = new OpenFileDialog()
        {
            InitialDirectory = string.IsNullOrEmpty(modsData.lastSaveDialoguePath) ? Serializer.GetMMDataFolder() : modsData.lastSaveDialoguePath,
            AddExtension     = true, Filter = selectDialogFilter, ValidateNames = true, Multiselect = false, CheckFileExists = true
        };

        var result = fileDialog.ShowDialog();

        if (result != DialogResult.OK)
        {
            return;
        }

        await saveBakTask;

        try {
            ModsData loadoutData = Serializer.LoadObj(fileDialog.FileName) as ModsData;


            List <string> issues = new List <string>();

            foreach (var loadMod in loadoutData.modInfos)
            {
                //Console.WriteLine("");
                //foreach(var file in loadMod.archiveFiles) {
                //    Console.WriteLine($"{file.installed}: {file.path}");
                //}

                //Console.WriteLine($"{mod.modName}: {mod.intalledText}");

                if (!loadMod.archiveExists)
                {
                    issues.Add($"Couldnt Find: {loadMod.shortPath}");
                    continue;
                }

                ModInfo matchingMod = modsData.modInfos.Find(realMod => realMod.modName == loadMod.modName);

                if (!matchingMod)
                {
                    issues.Add($"Archive Not Loaded: {loadMod.modPath}");
                    continue;
                }


                RestoreModState(loadMod);
                foreach (var file in loadMod.archiveFiles)
                {
                    //not sure if neccessary but just clear the temporary belonging nodes just in case
                    file.belongingNode = null;

                    //update the installed status of the real mod archive files to match the status of the loadout files
                    ArchiveFile matchFile = matchingMod.archiveFiles.First(x => x.path == file.path);
                    if (matchFile)
                    {
                        matchFile.installed    = file.installed;
                        matchFile.installedCRC = file.installedCRC;
                    }
                }
            }

            IEnumerable <ModInfo> newlyAddedMods = modsData.modInfos.Where(mod => !loadoutData.modInfos.Find(loadmod => loadmod.modName == mod.modName));

            if (newlyAddedMods.Count() > 0)
            {
                InputBoxForm watDoBox = InputBoxForm.OKBOX("New Files Were Added!", "", "Uninstall New Mods");
                watDoBox.TitleLabel.ForeColor = Color.LightYellow;
                watDoBox.buttonClose.Visible  = false;

                watDoBox.richTextBox1.AppendText("\nSince this loadout was created, new mod archives have been added.\nWhat would you like to do about this?");
                watDoBox.richTextBox1.CenterText();

                watDoBox.buttonCancel.Width += 50;
                watDoBox.buttonCancel.Left  -= 50;

                watDoBox.buttonNoAll.Text    = "Leave As Is";
                watDoBox.buttonNoAll.Visible = true;
                watDoBox.buttonNoAll.Width  += 45;
                watDoBox.buttonNoAll.Left    = watDoBox.buttonCancel.Left - watDoBox.buttonNoAll.Width - 10;

                watDoBox.checkBoxGeneric1.Text    = "Update Loadout With Changes";
                watDoBox.checkBoxGeneric1.Visible = true;
                watDoBox.checkBoxGeneric1.Checked = true;
                watDoBox.checkBoxGeneric1.Top     = watDoBox.buttonNoAll.Top + 5;
                watDoBox.checkBoxGeneric1.Left    = 10;


                result = watDoBox.ShowDialog();
                if (result == DialogResult.No)
                {
                    //uninstall
                    foreach (var mod in newlyAddedMods)
                    {
                        foreach (var file in mod.archiveFiles)
                        {
                            file.belongingNode = new TreeNode()
                            {
                                Checked = true
                            }
                        }
                        ;
                        ArchiveManager.UninstallSelected(mod, false, true);
                        foreach (var file in mod.archiveFiles)
                        {
                            file.belongingNode = null;
                        }
                    }
                }
                else
                {
                    //leave be
                }

                if (watDoBox.checkBoxGeneric1.Checked)
                {
                    await SaveLoadoutAuto(fileDialog.FileName, false);
                }
            }

            ArchiveManager.DeleteEmptyDirs(Serializer.GetGameModFolder());

            InputBoxForm infoBox;

            if (issues.Count > 0)
            {
                infoBox = InputBoxForm.OKBOX("Completed With Warnings", "");
                infoBox.TitleLabel.ForeColor = Color.Orange;
                infoBox.richTextBox1.AppendText("The loadout was restored but there were some issues.\n\n");

                infoBox.Height += 100;
                infoBox.richTextBox1.Height += 95;

                foreach (string issue in issues)
                {
                    infoBox.richTextBox1.AppendText(issue, Color.LightYellow, true);
                }

                infoBox.checkBoxGeneric1.Text    = "Update Loadout With These Removed";
                infoBox.checkBoxGeneric1.Visible = true;
                infoBox.checkBoxGeneric1.Top     = infoBox.buttonNoAll.Top + 5;
                infoBox.checkBoxGeneric1.Left    = 10;
            }
            else
            {
                infoBox = InputBoxForm.OKBOX("Success", "");
                infoBox.TitleLabel.ForeColor = Color.PaleGreen;
                infoBox.richTextBox1.AppendText("\nMod loadout state succesfully restored.", Color.LawnGreen, true);
            }

            infoBox.richTextBox1.CenterText();
            infoBox.ShowDialog();

            if (infoBox.checkBoxGeneric1.Checked)
            {
                await SaveLoadoutAuto(fileDialog.FileName, false);
            }


            MainForm.RefreshListView();
            MainForm.RefreshTreeView();
        } catch (Exception ex) {
            InputBoxForm successBox = InputBoxForm.OKBOX("Failure", "");
            successBox.richTextBox1.AppendText("An error occured while trying to restore your mod loadout.", Color.Salmon, true);
            successBox.richTextBox1.AppendText("Heres the error:\n\n");
            successBox.richTextBox1.CenterText();

            successBox.richTextBox1.AppendText(ex.ToString());
        }
    }