} // end returnFilteredList private void mouseClickInfoAction(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) { addonInfo addonInfoWin = new addonInfo { addonData = selectedAddon, installedAddonData = listOfInstalledAddons, rootDir = tosAMProgramSettings.tosRootDir, webConnector = webConnector, Owner = this }; addonInfoWin.ShowDialog(); // The popup window can update the installed Addon list, so we need to update our List<> and cache file, and then re-process the display. listOfInstalledAddons = addonInfoWin.installedAddonData; saveInstalledAddonDataToFile(); // Writes JSON file. addonInfoWin = null; // WPF should clean up all resources, so this is probably pointless. } } } catch (Exception ex) { Common.showError("Mouse Click Info Action Error", ex); } finally { displayActiveGrid(); } } // end mouseClickInfoAction
} // 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
} // 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
} // end FilterGroupCheckChanged #endregion #region "WrapPanel Setup and Control" private void displayActiveGrid() { try { ItemsControl ic = null; // Determine which tab is currently active, so we don't update the background tab(s). if (repoTabs == null) { return; } // At program load (before anything shows up) this will not be set, so do not attempt to process just yet. string selectedTab = ""; switch (repoTabs.SelectedIndex) { case 1: ic = jToSIC; selectedTab = "jToS"; break; default: ic = iToSIC; selectedTab = "iToS"; break; } if (ic == null) { return; } // Wait, what? List <addonDataFromRepo> filteredAddonList = returnFilteredList(selectedTab); // Return filtered and sorted list. List <addonDisplayData> addonDisplayList = new List <addonDisplayData>(); foreach (addonDataFromRepo a in filteredAddonList) { if (filterGroupWhatsNew.IsChecked == true && a.releaseDate < tosAMProgramSettings.previousUpdateDateStampUTC) { continue; } // Only displaying addons that have been updated/added since the last cache update. installedAddons ia = listOfInstalledAddons.FirstOrDefault(x => x.addonName == a.Name && x.addonRepo == a.whichRepo); // Check if this addon is installed. if (ia == null && (filterGroupInstalled.IsChecked == true || filterGroupUpdatable.IsChecked == true)) { continue; } // Only displaying installed or updatable addons. addonDisplayData q = new addonDisplayData() { name = a.Name, description = a.Description, installStatusColor = Brushes.White, whichRepo = a.whichRepo, allowInstall = Visibility.Visible, allowDelete = Visibility.Hidden }; string releaseDate = "during the big bang."; // Try to display the release date with the 'available version' tag. if (a.releaseDate != DateTimeOffset.MinValue) { releaseDate = $"on {a.releaseDate.ToLocalTime().ToString("MM/dd/yyyy")}"; } q.availableVersion = $"{a.FileVersion} released {releaseDate}"; if (ia != null) // Addon is installed. { q.allowInstall = Visibility.Hidden; q.allowDelete = Visibility.Visible; q.installedVersion = $"Installed: {ia.addonVersion} on {ia.installDate.ToShortDateString()}"; Version curVersion = new Version(); Version.TryParse(a.FileVersion.Replace("v", ""), out curVersion); // See if it's the version matches. Version installedVersion = new Version(); Version.TryParse(ia.addonVersion.Replace("v", ""), out installedVersion); int verComp = curVersion.CompareTo(installedVersion); if (verComp == 0 && filterGroupUpdatable.IsChecked == true) // Only displaying updatable addons. { continue; } else if (verComp > 0) // Addon is updatable. { q.installStatusColor = Brushes.Yellow; q.allowInstall = Visibility.Visible; } else { q.installStatusColor = Brushes.LightGreen; } } string[] aR = a.authorRepo.Split('/'); q.author = $"by {aR[0]}"; q.authorRepoUri = new Hyperlink(new Run(a.authorRepo)) { NavigateUri = new Uri($"https://github.com/{a.authorRepo}") }; q.authorRepoUri.RequestNavigate += new RequestNavigateEventHandler(delegate(object sender, RequestNavigateEventArgs e) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(e.Uri.AbsoluteUri)); e.Handled = true; }); // No matter what, if this addon was in the broken list, color the background red. Still allow the user to download, I guess. brokenAddons broken = listOfBrokenAddons.FirstOrDefault(x => x.File == a.File && x.Version == a.FileVersion.Replace("v", "") && x.Author == aR[0]); if (broken != null) { q.installStatusColor = Brushes.Salmon; } addonDisplayList.Add(q); } ic.ItemsSource = addonDisplayList; } catch (Exception ex) { Common.showError("displayActiveGrid Error", ex); } } // end displayActiveGrid