private void button_mod_Click(object sender, EventArgs e) { var warning = false; SetMessage("...", Color.Black); _progressBarManipulator.Reset(3 + _activeMods.Count); _progressBarManipulator.Increment(); _moddingService.Restore(); _progressBarManipulator.Increment(); foreach (var mod in _activeMods) { var modDir = new DirectoryInfo(Paths.ModPath + "\\" + Paths.ModDirectoryName + "\\" + mod.ModDirectoryName); warning = _moddingService.LetsMod(mod, modDir, new DirectoryInfo(Paths.ExePath), _activeMods) || warning; _progressBarManipulator.Increment(); } _moddingService.SaveActiveMods(_language, _activeMods); _progressBarManipulator.Increment(); if (warning) { SetMessage("Warning", Color.Orange); } else { SetMessage("Modding was successful", Color.Green); } _progressBarManipulator.Finish(); }
private void button_mod_Click(object sender, EventArgs e) { // set user interface into the modding state (disable buttons etc) setUIToModdingState(true); // Modding in second task to avoid UI freeze var activeMods = new List <Mod>(); //get file count of all active mods var fileCount = 0; foreach (ListViewItem modItem in activeModsListView.Items) { var mod = modItem.Tag as Mod; activeMods.Add(mod); fileCount += mod.FileCount; } Task.Factory.StartNew(() => { SetMessage(Resources.PleaseWait, Color.Black); //reset progress bar to new file count _progressBarManipulator.Reset(fileCount + 3); _progressBarManipulator.Increment(); _moddingService.Restore(); _progressBarManipulator.Increment(); var warning = false; var error = false; foreach (var mod in activeMods) { var returnValue = _moddingService.LetsMod(mod, mod.ModDirectoryInfo, new DirectoryInfo(Paths.ExePath), activeMods, _progressBarManipulator); warning = warning || returnValue == ModdingService.WARNING_CODE; error = error || returnValue == ModdingService.ERROR_CODE; //cancel when error occured if (error) { break; } } _moddingService.SaveActiveMods(_language, activeMods); _progressBarManipulator.Finish(); if (error) { SetMessage(Resources.Error, Color.Red); Helpers.ShowMessage(Resources.ModdingService_ErrorMessage, Resources.Error); } else if (warning) { SetMessage(Resources.Warning, Color.Orange); Helpers.ShowMessage(Resources.ModdingService_WarningMessage, Resources.Warning); } else { SetMessage(Resources.ModdingSuccessful, Color.Green); } // set user interface into normal state (enable buttons etc) setUIToModdingState(false); }); }