} // end ActionButton_Click private async void UpdateButton_Click(object sender, RoutedEventArgs e) { try { actionButton.IsEnabled = false; closeButton.IsEnabled = false; updateButton.IsEnabled = false; AddonManagement am = new AddonManagement() { addonData = addonData, installedAddonData = installedAddonData, rootDir = rootDir }; // Going to just use the same functionality as the install button (for now) Progress <taskProgressMsg> progressMessages = new Progress <taskProgressMsg>(updateForTaskProgress); bool downloadResultBool = await Task.Run(() => am.downloadAndSaveAddon(progressMessages, webConnector)); if (!downloadResultBool) { MessageBox.Show("Apparently, there was an error while attempting to download the addon.. :<"); return; } statusBar1TextBlock.Text = "Updating installed addon list..."; bool updateListResultBoolStage1 = am.updateInstalledAddonList(1); // Remove old record. bool updateListResultBoolStage2 = am.updateInstalledAddonList(0); if (!updateListResultBoolStage1 || !updateListResultBoolStage2) { MessageBox.Show("Apparently, there was an error while attempting to update the installed addon list.. :<"); return; } actionButton.Content = "Uninstall"; actionButton.Background = Brushes.LightSalmon; statusBar1TextBlock.Text = "Updatge Complete"; updateButton.Visibility = Visibility.Hidden; } catch (Exception ex) { Common.showError("Update Button Error", ex); } finally { actionButton.IsEnabled = true; closeButton.IsEnabled = true; updateButton.IsEnabled = true; } } // end Updatebutton_Click
} // end mouseClickInstallAction private void mouseClickUninstallAction(object sender, MouseButtonEventArgs e) { try { if (e.ChangedButton == MouseButton.Left) { if (Common.checkForToSDirectory(tosAMProgramSettings.tosRootDir) == false) { MessageBox.Show("Please set a valid ToS Program directory."); return; } if (Common.checkForToSProcess()) { MessageBox.Show("Cannot uninstall addons while ToS is running.", "ToS Running", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } Image i = (Image)sender; addonDisplayData addon = (addonDisplayData)i.DataContext; addonDataFromRepo selectedAddon = listOfAllAddons.FirstOrDefault(x => x.whichRepo == addon.whichRepo && x.Name == addon.name); if (selectedAddon != null) { MessageBoxResult mbr = MessageBox.Show("Delete Addon?", "Uninstall", MessageBoxButton.YesNo); if (mbr == MessageBoxResult.Yes) { MessageBoxResult mb = MessageBox.Show($"Remove associated addon directory?{Environment.NewLine}Addon-specific settings are stored here, so if you plan on reinstalling, select 'No'", "Addon directory", MessageBoxButton.YesNo); AddonManagement am = new AddonManagement() { addonData = selectedAddon, installedAddonData = listOfInstalledAddons, rootDir = tosAMProgramSettings.tosRootDir, addonInstallerOverrides = listOfAddonOverrides }; bool deleteAddonResultBool = am.deleteInstalledAddon(mb == MessageBoxResult.Yes ? true : false); if (!deleteAddonResultBool) { MessageBox.Show("Apparently, there was an error while attempting to delete the addon.. :<"); return; } bool updateListResultBool = am.updateInstalledAddonList(1); if (!updateListResultBool) { MessageBox.Show("Apparently, there was an error while attempting to update the installed addon list.. :<"); return; } listOfInstalledAddons = am.installedAddonData; saveInstalledAddonDataToFile(); statusBar1TextBlock.Text = "Uninstall Complete"; } } } } catch (Exception ex) { Common.showError("Mouse Click Install Action Error", ex); } finally { displayActiveGrid(); } } // end mouseClickUninstallAction
private void FindExistingAddons_Click(object sender, RoutedEventArgs e) { try { if (Common.checkForToSDirectory(tosAMProgramSettings.tosRootDir) == false) { MessageBox.Show("Please set a valid ToS Program directory."); return; } MessageBoxResult mb = MessageBox.Show("This will attempt to find addons that were previously installed manually or through another manager and update the installed addon list. Proceed?", "Find Existing Addons", MessageBoxButton.YesNo, MessageBoxImage.Information); if (mb == MessageBoxResult.Yes) { string[] fileList = System.IO.Directory.GetFiles($"{tosAMProgramSettings.tosRootDir}/data/", "_*.ipf"); AddonManagement am = new AddonManagement(); int z = 0; foreach (string q in fileList) { System.IO.FileInfo fI = new System.IO.FileInfo(q); string[] fileNameSplit = fI.Name.Split('-'); // 0 will be root of the filename, with _ at the start. 1 will be the unicode char. 2 will be version + ".ipf" string fN = fileNameSplit[0].Replace("_", ""); string fV = fileNameSplit[2].Replace(".ipf", ""); if (listOfInstalledAddons.FirstOrDefault(x => x.addonFilename == fN && x.addonVersion == fV) == null) // Addon is not installed from this manager. { addonDataFromRepo foundAddon = listOfAllAddons.FirstOrDefault(i => i.File == fN && i.Unicode == fileNameSplit[1] && i.FileVersion == fV); if (foundAddon != null) { am.installedAddonData = listOfInstalledAddons; am.addonData = foundAddon; am.updateInstalledAddonList(0); listOfInstalledAddons = am.installedAddonData; } } z++; } if (z > 0) { saveInstalledAddonDataToFile(); displayActiveGrid(); MessageBox.Show($"Found {z} existing addons and added them to the list of installed addons", "Found Addons", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("We did not find any additional addons", "No Addons Discovered", MessageBoxButton.OK, MessageBoxImage.Information); } } } catch (Exception ex) { Common.showError("Allow Automatic Update Check Changed Error", ex); } }
} // end AddonInfoWindow_loaded private async void ActionButton_Click(object sender, RoutedEventArgs e) { try { actionButton.IsEnabled = false; closeButton.IsEnabled = false; updateButton.IsEnabled = false; AddonManagement am = new AddonManagement() { addonData = addonData, installedAddonData = installedAddonData, rootDir = rootDir, addonInstallerOverrides = addonInstallerOverrides }; // Which action to perform? if (actionButton.Content.ToString() == "Install") { Progress <taskProgressMsg> progressMessages = new Progress <taskProgressMsg>(updateForTaskProgress); // Will contain the progress messages from each function. bool downloadResultBool = await am.downloadAndSaveAddon(progressMessages, webConnector); if (!downloadResultBool) { MessageBox.Show("Apparently, there was an error while attempting to download the addon.. :<"); return; } statusBar1TextBlock.Text = "Updating installed addon list..."; bool updateListResultBool = am.updateInstalledAddonList(0); if (!updateListResultBool) { MessageBox.Show("Apparently, there was an error while attempting to update the installed addon list.. :<"); return; } actionButton.Content = "Uninstall"; actionButton.Background = Brushes.LightSalmon; statusBar1TextBlock.Text = "Install Complete"; } else if (actionButton.Content.ToString() == "Uninstall") { if (Common.checkForToSProcess()) { MessageBox.Show("Cannot uninstall addons while ToS is running.", "ToS Running", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } MessageBoxResult mb = MessageBox.Show($"Remove associated addon directory?{Environment.NewLine}Addon-specific settings are stored here, so if you plan on reinstalling, select 'No'", "Addon directory", MessageBoxButton.YesNoCancel); if (mb == MessageBoxResult.Cancel) { return; } bool deleteAddonResultBool = am.deleteInstalledAddon(mb == MessageBoxResult.Yes ? true : false); if (!deleteAddonResultBool) { MessageBox.Show("Apparently, there was an error while attempting to delete the addon.. :<"); return; } bool updateListResultBool = am.updateInstalledAddonList(1); if (!updateListResultBool) { MessageBox.Show("Apparently, there was an error while attempting to update the installed addon list.. :<"); return; } actionButton.Content = "Install"; actionButton.Background = Brushes.LightGreen; statusBar1TextBlock.Text = "Uninstall Complete"; } } catch (Exception ex) { Common.showError("Action Button Error", ex); } finally { actionButton.IsEnabled = true; closeButton.IsEnabled = true; updateButton.IsEnabled = true; } } // end ActionButton_Click
} // end mouseClickInfoAction private async void mouseClickInstallAction(object sender, MouseButtonEventArgs e) { try { if (e.ChangedButton == MouseButton.Left) { if (Common.checkForToSDirectory(tosAMProgramSettings.tosRootDir) == false) { MessageBox.Show("Please set a valid ToS Program directory."); return; } Image i = (Image)sender; addonDisplayData addon = (addonDisplayData)i.DataContext; addonDataFromRepo selectedAddon = listOfAllAddons.FirstOrDefault(x => x.whichRepo == addon.whichRepo && x.Name == addon.name); if (selectedAddon != null) { AddonManagement am = new AddonManagement() { addonData = selectedAddon, installedAddonData = listOfInstalledAddons, rootDir = tosAMProgramSettings.tosRootDir, addonInstallerOverrides = listOfAddonOverrides }; installedAddons iA = listOfInstalledAddons.FirstOrDefault(x => x.addonRepo == addon.whichRepo && x.addonName == addon.name); bool allowContinue = false; if (iA != null) // Allow Update from here as well. { if (MessageBox.Show("Update Addon?", "Update", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { allowContinue = true; bool updateListResultBool = am.updateInstalledAddonList(1); // Remove the addon from the installed list. if (!updateListResultBool) { MessageBox.Show("Apparently, there was an error while attempting to update the installed addon list.. :<"); return; } } } else { if (MessageBox.Show("Install Addon?", "Install", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { allowContinue = true; } } if (allowContinue) { Progress <taskProgressMsg> progressMessages = new Progress <taskProgressMsg>(updateForTaskProgress); bool downloadResultBool = await am.downloadAndSaveAddon(progressMessages, webConnector); if (!downloadResultBool) { MessageBox.Show("Apparently, there was an error while attempting to download the addon.. :<"); return; } statusBar1TextBlock.Text = "Updating installed addon list..."; bool updateListResultBool = am.updateInstalledAddonList(0); if (!updateListResultBool) { MessageBox.Show("Apparently, there was an error while attempting to update the installed addon list.. :<"); return; } listOfInstalledAddons = am.installedAddonData; saveInstalledAddonDataToFile(); statusBar1TextBlock.Text = "Install Complete"; } } } } catch (Exception ex) { Common.showError("Mouse Click Install Action Error", ex); } finally { displayActiveGrid(); } } // end mouseClickInstallAction