Ejemplo n.º 1
0
        private void SaveSettingsButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (ModsFolderTextBox.Text != "" && GameFolderTextBox.Text != "")
                {
                    Config = new ManagerConfig {
                        GameFolder = GameFolderTextBox.Text, ModsFolder = ModsFolderTextBox.Text
                    };
                    JsonReader.WriteToJson(Config, Path.Combine(programPath, "config.json"));
                    //Reiniciar IMOWA e o Loader Installer
                    if (ModDataHandler == null)
                    {
                        ModDataHandler = new ModDataHandler(Config.GameFolder, Config.ModsFolder, Config.ModsFolder);

                        new ModEnableElement(panel1, ModDataHandler.ManifestDoLoader, ModDataHandler.DIMOWALoaderInstaller.IsLoaderInstalled);
                        allEnabledMods = ModDataHandler.ModEnabledList.ModList.ToList();
                        for (int i = 0; i < ModDataHandler.ManifestsDosMods.Length; i++)
                        {
                            var ele = new ModEnableElement(panel1, ModDataHandler.ManifestsDosMods[i], allEnabledMods.IndexOf(ModDataHandler.ManifestsDosMods[i].FileName) > -1);
                            if (i == 0)
                            {
                                ele.ChangeRow(75);
                            }
                            else
                            {
                                ele.ChangeRow(ModEnableElement.ModEnableElements[i].GetRow() + 25);
                            }

                            if (!ModDataHandler.DIMOWALoaderInstaller.IsLoaderInstalled)
                            {
                                ele.LockElement(Color.Gray);
                            }
                        }
                    }
                }
                else if (ModsFolderTextBox.Text != "" && GameFolderTextBox.Text == "")
                {
                    ConsoleWindowHelper.Warning("The Game Folder path is missing");
                    MessageBox.Show("The Game Folder path is missing");
                }
                else if (ModsFolderTextBox.Text == "" && GameFolderTextBox.Text != "")
                {
                    ConsoleWindowHelper.Warning("The Mod Folder path is missing");
                    MessageBox.Show("The Mod Folder path is missing");
                }
                else
                {
                    ConsoleWindowHelper.Warning("Both paths are missing");
                    MessageBox.Show("Both paths are missing");
                }
            }
            catch (Exception ex)
            {
                ConsoleWindowHelper.FatalException("A Fatal Exception occured while saving the settings: " + ex.Message + " check the Console Windows for more information.");
                ConsoleWindowHelper.Exception(string.Format("{0}: {1} {2}\nInner Exception Message: {3}", ex.Source, ex.Message, ex.StackTrace, ex.InnerException));
            }
        }
Ejemplo n.º 2
0
        private void SaveModsButton_Click(object sender, EventArgs e)
        {
            try
            {
                for (int i = 0; i < ModEnableElement.ModEnableElements.Count; i++)
                {
                    if (ModEnableElement.ModEnableElements[i].json.FileName != ModDataHandler.dimowaModLoaderFile)
                    {
                        if (ModEnableElement.ModEnableElements[i].IsEnabled && allEnabledMods.IndexOf(ModEnableElement.ModEnableElements[i].json.FileName) < 0)
                        {
                            allEnabledMods.Add(ModEnableElement.ModEnableElements[i].json.FileName);
                        }
                        else if (!ModEnableElement.ModEnableElements[i].IsEnabled && allEnabledMods.IndexOf(ModEnableElement.ModEnableElements[i].json.FileName) > -1)
                        {
                            allEnabledMods.Remove(ModEnableElement.ModEnableElements[i].json.FileName);
                        }
                    }
                }

                ModFolderAndList modList = new ModFolderAndList()
                {
                    ModList   = allEnabledMods.ToArray(),
                    ModFolder = Config.ModsFolder
                };
                ClassSerializer.WriteToFile(Path.Combine(DirectorySearchTools.GetDirectoryInDirectory("Managed", Config.GameFolder), ModDataHandler.loaderModOWFile), modList);
                if (ModEnableElement.ModEnableElements[0].IsEnabled) //Primeiro elemento é sempre do loader
                {                                                    //DIMOWALoaderInstaller.Install()/.Unistall() consomem bastante ram e cpu quanto chamados com o .Save() e continuam consumindo ele em seguida, parece ser algo relacionado com o tamanho do DLL (como se ele estivesse carregando todo ele para salvar mas não largando esse objeto)
                    ;
                    if (ModDataHandler.DIMOWALoaderInstaller.Install())
                    {
                        string[] filesToCopy = { ModDataHandler.ManifestDoLoader.FileName };
                        foreach (string s in filesToCopy)
                        {
                            string fullPath = Path.Combine(DirectorySearchTools.GetDirectoryInDirectory("Managed", Config.GameFolder), s);
                            if (!File.Exists(fullPath))
                            {
                                File.Copy(DirectorySearchTools.GetFilePathInDirectory(ModDataHandler.ManifestDoLoader.FileName, Config.ModsFolder, Config.GameFolder), fullPath);
                            }
                        }
                        ModDataHandler.DIMOWALoaderInstaller.SaveModifications();
                        ModDataHandler.DIMOWALoaderInstaller.ResetLoaderInstaller();

                        ConsoleWindowHelper.Log("DIMOWAModLoader has been successfully installed");
                        foreach (var element in ModEnableElement.ModEnableElements)
                        {
                            element.UnlockElement();
                        }
                    }
                }
                else
                {
                    if (ModDataHandler.DIMOWALoaderInstaller.Uninstall())
                    {
                        ModDataHandler.DIMOWALoaderInstaller.SaveModifications();
                        ModDataHandler.DIMOWALoaderInstaller.ResetLoaderInstaller();

                        string[] filesToDelete = { ModDataHandler.ManifestDoLoader.FileName, ModDataHandler.loaderModOWFile };
                        foreach (string s in filesToDelete)
                        {
                            string fullPath = Path.Combine(DirectorySearchTools.GetDirectoryInDirectory("Managed", Config.GameFolder), s);
                            if (File.Exists(fullPath))
                            {
                                File.Delete(fullPath);
                            }
                        }

                        ConsoleWindowHelper.Log("DIMOWAModLoader has been successfully uninstalled");
                        for (int i = 1; i < ModEnableElement.ModEnableElements.Count; i++)
                        {
                            ModEnableElement.ModEnableElements[i].LockElement(Color.Gray);
                        }
                    }
                }

                ConsoleWindowHelper.Log("All the changes have been performed and saved");
            }
            catch (Exception ex)
            {
                ConsoleWindowHelper.FatalException("A Fatal Exception occured while saving: " + ex.Message + " check the Console Windows for more information.");
                ConsoleWindowHelper.Exception(string.Format("{0}: {1} {2}\nInner Exception Message: {3}", ex.Source, ex.Message, ex.StackTrace, ex.InnerException));
            }
        }
Ejemplo n.º 3
0
        public Form1()
        {
            programPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            InitializeComponent();
            ConsoleWindowHelper Console = new ConsoleWindowHelper(ConsoleWindow);

            try
            {
                tabControl1.Appearance = TabAppearance.Normal;
                MainMenu();
                SettingsMenu();

                string[] possibleConfig = Directory.GetFiles(Form1.programPath, "*config.json");
                if (possibleConfig.Length <= 0)
                {
                    tabControl1.SelectedTab = tabPage2;
                }
                else
                {
                    try
                    {
                        Config = JsonReader.ReadFromJson <ManagerConfig>(possibleConfig[0]);
                    }
                    catch (Exception ex)
                    {
                        ConsoleWindowHelper.Exception(ex.Message + " - " + ex.StackTrace);
                        throw new IOException("Something went wrong while reading the config.json file, try deleting it and running the program again");
                    }

                    ModsFolderTextBox.Text = Config.ModsFolder;
                    GameFolderTextBox.Text = Config.GameFolder;

                    ModDataHandler = new ModDataHandler(Config.GameFolder, Config.ModsFolder, Config.ModsFolder);
                    new ModEnableElement(panel1, ModDataHandler.ManifestDoLoader, ModDataHandler.DIMOWALoaderInstaller.IsLoaderInstalled);

                    allEnabledMods = ModDataHandler.ModEnabledList.ModList.ToList();
                    for (int i = 0; i < ModDataHandler.ManifestsDosMods.Length; i++)
                    {
                        var e = new ModEnableElement(panel1, ModDataHandler.ManifestsDosMods[i], allEnabledMods.IndexOf(ModDataHandler.ManifestsDosMods[i].FileName) > -1);
                        if (i == 0)
                        {
                            e.ChangeRow(75);
                        }
                        else
                        {
                            e.ChangeRow(ModEnableElement.ModEnableElements[i].GetRow() + 25);
                        }

                        if (!ModDataHandler.DIMOWALoaderInstaller.IsLoaderInstalled)
                        {
                            e.LockElement(Color.Gray);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ConsoleWindowHelper.FatalException("A Fatal Exception occured while starting the program: " + ex.Message + " check the Console Windows for more information.");
                ConsoleWindowHelper.Exception(string.Format("{0}: {1} {2}\nInner Exception Message: {3}", ex.Source, ex.Message, ex.StackTrace, ex.InnerException));
            }
        }