private void AddonInfoWindow_Loaded(object sender, RoutedEventArgs e)
 {
     try {
         // Set basic addon info.
         nameValue.Text = addonData.Name;
         fileValue.Text = addonData.File;
         string releaseDate = addonData.releaseDate.Year == 1 ? "before the dawn of man." : addonData.releaseDate.ToLocalTime().ToString("MM/dd/yyyy");
         versionValue.Text             = $"{addonData.FileVersion} released {releaseDate}";
         tagsValue.Text                = addonData.tagsFlat;
         descriptionValue.Text         = addonData.Description;
         descriptionValue.TextWrapping = TextWrapping.Wrap;
         // Determine if addon is currently installed, and update action button appropriately.
         installedAddons i = installedAddonData.FirstOrDefault(x => x.addonName == addonData.Name && x.addonRepo == addonData.whichRepo);
         if (i != null)
         {
             // Addon was found.  Change Action Button to Uninstall, and check version and determine if update is available.
             actionButton.Content = "Uninstall"; actionButton.Background = Brushes.LightSalmon;
             Version curVersion       = new Version(); Version.TryParse(addonData.FileVersion.Replace("v", ""), out curVersion);
             Version installedVersion = new Version(); Version.TryParse(i.addonVersion.Replace("v", ""), out installedVersion);
             if (curVersion.CompareTo(installedVersion) > 0)
             {
                 updateButton.Visibility = Visibility.Visible;
             }
         }
         displayRepoAuthor();
     } catch (Exception ex) {
         Common.showError("Addon Info Window Error", ex);
     }
 } // end AddonInfoWindow_loaded
Пример #2
0
        } // end deleteInstalledAddon

        internal bool updateInstalledAddonList(int action)
        {
            try {
                if (action == 0)   // Add
                {
                    installedAddonData.Add(new installedAddons {
                        addonAuthorRepo = addonData.authorRepo, addonFilename = addonData.File, addonName = addonData.Name, addonRepo = addonData.whichRepo, addonVersion = addonData.FileVersion, installDate = DateTime.Now
                    });
                }
                else if (action == 1)                                                                                                                // Remove
                {
                    installedAddons q = installedAddonData.FirstOrDefault(x => x.addonName == addonData.Name && x.addonRepo == addonData.whichRepo); // Check only the name and repo - ignore the version in case we've come in with a new version and it doesn't match the installed version.
                    if (q != null)
                    {
                        installedAddonData.Remove(q);
                    }
                }
                return(true);
            } catch (Exception ex) {
                Common.showError("Update Installed Addon List Error", ex);
                return(false);
            }
        } // end updateInstalledAddonList
        } // 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