public void InstalledMapSelectionChanged(object sender, GUI.SelectionChangedEventArgs args) { if (ignoreNextSelectionChangedEvent) { ignoreNextSelectionChangedEvent = false; } else { var selectedMap = Program.installedMaps[args.SelectedItemIndex]; LogTextBox.WriteShortMapInfo(selectedMap); } }
private bool VerifyNothingOverwritten(LoadableMap map) { // Check which files already exist var existingLevels = new List <string>(); foreach (var level in map.Levels) { string correspondingLevel = Path.Combine(Program.installedLevelsPath, level); if (File.Exists(correspondingLevel)) { existingLevels.Add(level); } } var existingScripts = new List <string>(); foreach (var script in map.Scripts) { string correspondingScript = Path.Combine(Program.installedScriptsPath, script); if (File.Exists(correspondingScript)) { existingScripts.Add(script); } } if (existingLevels.Count > 0 || existingScripts.Count > 0) { LogTextBox.ClearContent(); LogTextBox.WriteLine("Map is not marked as installed, but one or more files already exist. Overwrite?"); LogTextBox.WriteLine(string.Format("Levels: {0}", string.Join(',', existingLevels.ToArray()))); LogTextBox.WriteLine(string.Format("Scripts: {0}", string.Join(',', existingLevels.ToArray()))); string[] selections; GUI.SelectionPrompt.Options options; if (map.IsValid) { selections = new string[] { Text.Overwrite, Text.BackupAndInstall }; options = new GUI.SelectionPrompt.Options() { AllowCancel = true, Index = 2, }; } else { selections = new string[] { Text.Overwrite, Text.BackupAndInstall, Text.ShowIssues }; options = new GUI.SelectionPrompt.Options() { AllowCancel = true, Index = 3, }; } int response = SelectionPrompt.PromptSelection(selections, options); LogTextBox.ClearContent(); switch (response) { case 0: InstallMap(map, true); break; case 1: // TODO: Verify in case backups would be overwritten. LogTextBox.WriteLine(Text.BackingUpFiles); Program.backupsWindow.BackUpInstalledMapFiles(map); LogTextBox.AppendLastLine(" " + Text.BackupFinished); InstallMap(map, true); break; default: LogTextBox.WriteShortMapInfo(map); break; } return(false); } else { return(true); } }
public override void Selected(GUI.Selection selection) { selection.SelectedItem.Highlight(); if (selection.ColumnIndex == 0) // Installed Maps -> Uninstall { var selectedMap = Program.installedMaps[selection.RowIndex]; LogTextBox.ClearContent(); string[] selections; var options = new GUI.SelectionPrompt.Options() { AllowCancel = true, }; if (selectedMap.IsValid) { selections = new string[] { Text.Uninstall }; } else { selections = new string[] { Text.Uninstall, Text.ShowIssues }; options.Index = 1; } int response = SelectionPrompt.PromptSelection(selections, options); switch (response) { case 0: if (selectedMap.IsWIP) { LogTextBox.WriteLine(Text.CantUninstallWIP); ignoreNextSelectionChangedEvent = true; } else { var currentRow = Menu.CurrentRow; UninstallMap(selectedMap); bool keepIgnoringSelectionChanged = ignoreNextSelectionChangedEvent; if (InstalledMapsList.CanNavigate) { InstalledMapsList.Select(currentRow); } else { Menu.NavigateToDefault(); } ignoreNextSelectionChangedEvent = keepIgnoringSelectionChanged; } break; case 1: selectedMap.ShowIssues(); DrawAll(); break; } } else if (selection.ColumnIndex == 1) // Available Maps -> Install/Reinstall/Overwrite { var selectedLoadableMap = Program.availableMaps[selection.RowIndex]; var alreadyInstalledMap = FindInstalledMap(selectedLoadableMap.Name); if (alreadyInstalledMap != null) // If the map is already installed { LogTextBox.ClearContent(); LogTextBox.WriteLine(string.Format(Text.PromptReinstall, alreadyInstalledMap.Name)); string[] selections; var options = new GUI.SelectionPrompt.Options() { AllowCancel = true, }; if (selectedLoadableMap.IsValid) { selections = new string[] { Text.Reinstall }; } else { selections = new string[] { Text.Reinstall, Text.ShowIssues }; options.Index = 1; } int response = SelectionPrompt.PromptSelection(selections, options); switch (response) { case 0: ReinstallMap(alreadyInstalledMap, selectedLoadableMap); break; case 1: selectedLoadableMap.ShowIssues(); DrawAll(); break; default: LogTextBox.WriteShortMapInfo(selectedLoadableMap); break; } } else if (VerifyNothingOverwritten(selectedLoadableMap)) { LogTextBox.ClearContent(); string[] selections; var options = new GUI.SelectionPrompt.Options() { AllowCancel = true, }; if (selectedLoadableMap.IsValid) { selections = new string[] { Text.Install }; } else { selections = new string[] { Text.Install, Text.ShowIssues }; options.Index = 1; } int response = SelectionPrompt.PromptSelection(selections, options); switch (response) { case 0: InstallMap(selectedLoadableMap, false); break; case 1: selectedLoadableMap.ShowIssues(); DrawAll(); break; default: LogTextBox.WriteShortMapInfo(selectedLoadableMap); break; } } } selection.List.Select(selection.RowIndex); }