private void ExportMap(Map map, string destinationFolderPath, bool overrideExisting) { LogTextBox.WriteLine(string.Format(Text.ExportingMap, map.Name)); string destinationLevelPath = Path.Combine(destinationFolderPath, Program.LevelFolderName); string destinationScriptPath = Path.Combine(destinationFolderPath, Program.ScriptFolderName); Directory.CreateDirectory(destinationLevelPath); foreach (var level in map.Levels) { string levelSource = Path.Combine(Program.installedLevelsPath, level); string levelDestination = Path.Combine(destinationLevelPath, level); File.Copy(levelSource, levelDestination, overrideExisting); } Directory.CreateDirectory(destinationScriptPath); foreach (var script in map.Scripts) { string scriptSource = Path.Combine(Program.installedScriptsPath, script); string scriptDestination = Path.Combine(destinationScriptPath, script); File.Copy(scriptSource, scriptDestination, overrideExisting); } var loadableMap = new LoadableMap(map, destinationFolderPath); Program.availableMaps.Add(loadableMap); loadableMap.SaveMapInfo(); LogTextBox.AppendLastLine(Text.Exported); if (map.IsWIP) { LogTextBox.WriteLine(Text.MapStillWipWarning); } ignoreNextSelectionChangedEvent = true; }
public void UninstallMap(Map map) { LogTextBox.WriteLine(string.Format(Text.UninstallingMap, map.Name)); foreach (var level in map.Levels) { var levelPath = Path.Combine(Program.installedLevelsPath, level); File.Delete(levelPath); } foreach (var script in map.Scripts) { var scriptPath = Path.Combine(Program.installedScriptsPath, script); File.Delete(scriptPath); } Program.installedMaps.Remove(map); Program.SaveInstalledMaps(); InstalledMapsList.SetMaps(Program.installedMaps); InstalledMapsList.Clear(); InstalledMapsList.Draw(); LogTextBox.AppendLastLine(Text.Uninstalled); if (Program.backupsWindow.RestoreInstalledMapFiles(map)) { LogTextBox.WriteLine(Text.BackedUpFilesRestored); } ignoreNextSelectionChangedEvent = true; }
public void InstallMap(LoadableMap map, bool overwrite) { if (FindInstalledMap(map.Name) != null) { LogTextBox.WriteLine(string.Format("ERROR: Map {0} is already installed!", map.Name)); return; } LogTextBox.WriteLine(string.Format("Installing map {0}...", map.Name)); string levelSourcePath = Path.Combine(map.MapPath, Program.LevelFolderName); string scriptSourcePath = Path.Combine(map.MapPath, Program.ScriptFolderName); foreach (var level in map.Levels) { string sourcePath = Path.Combine(levelSourcePath, level); string destinationPath = Path.Combine(Program.installedLevelsPath, level); File.Copy(sourcePath, destinationPath, overwrite); } foreach (var script in map.Scripts) { string sourcePath = Path.Combine(scriptSourcePath, script); string destinationPath = Path.Combine(Program.installedScriptsPath, script); File.Copy(sourcePath, destinationPath, overwrite); } var installedMap = new Map( map.Name, map.Author, map.Version, map.ShortDescription, map.LongDescription, new string[map.Levels.Length], new string[map.Scripts.Length], map.StartupLevel, map.IsWIP, map.Issues); if (installedMap.Levels.Length == 1) { installedMap.StartupLevel = Program.RemoveLevelExtension(map.Levels[0]); } map.Levels.CopyTo(installedMap.Levels, 0); map.Scripts.CopyTo(installedMap.Scripts, 0); Program.installedMaps.Add(installedMap); InstalledMapsList.SetMaps(Program.installedMaps); Program.SaveInstalledMaps(); Menu.Draw(); LogTextBox.AppendLastLine(" installed!"); ignoreNextSelectionChangedEvent = true; }
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); } }
private void EditLevels(Map map) { RefreshLevelList(map); levelList.NavigateToDefault(); bool quitPrompt = false; while (!quitPrompt) { GUI.Selection selection = levelList.PromptSelection(); switch (selection.Command) { case Properties.Command.Confirm: switch (selection.RowIndex) { case 0: // Add New Level if (levelNameInput.PromptText()) { LogTextBox.ClearContent(); string levelName = levelNameInput.Text; // Check if level already exists string levelDestination = Path.Combine(Program.installedLevelsPath, levelName + Program.LevelFileExtension); string scriptDestination = Path.Combine(Program.installedScriptsPath, levelName + Program.ScriptFileExtension); if (File.Exists(levelDestination) || File.Exists((scriptDestination))) { LogTextBox.WriteLine(string.Format(Text.LevelOrScriptAlreadyExists, levelName + Program.LevelFileExtension, levelName + Program.ScriptFileExtension)); } else { File.Copy(Program.emptyLevelTemplatePath, levelDestination); File.Copy(Program.emptyScriptTemplatePath, scriptDestination); map.AddLevel(levelName); Program.SaveInstalledMaps(); RefreshLevelList(map); LogTextBox.WriteLine(string.Format(Text.AddedLevel, levelName)); } } break; case 1: // Assign Existing Levels LogTextBox.Clear(); AssignExistingLevels(map); assignedLevelsList.Clear(); LogTextBox.Draw(); break; case 2: // Separator break; default: // Level LogTextBox.ClearContent(); string selectedLevelName = selection.Text; string currentLevelName = selectedLevelName + Program.LevelFileExtension; string currentScriptName = selectedLevelName + Program.ScriptFileExtension; string levelSource = Path.Combine(Program.installedLevelsPath, currentLevelName); string scriptSource = Path.Combine(Program.installedScriptsPath, currentScriptName); switch (SelectionPrompt.PromptSelection(levelCommands, true)) { case 0: // Rename levelRenameInput.Top = levelList.Top + selection.RowIndex; bool renamed = levelRenameInput.PromptText(new GUI.TextInput.PromptOptions(false, true, false, selectedLevelName)); if (renamed) { string newLevelName = levelRenameInput.Text; string levelDestination = Path.Combine(Program.installedLevelsPath, newLevelName + Program.LevelFileExtension); string scriptDestination = Path.Combine(Program.installedScriptsPath, newLevelName + Program.ScriptFileExtension); if (File.Exists(levelDestination) || File.Exists((scriptDestination))) { LogTextBox.WriteLine(string.Format(Text.LevelOrScriptAlreadyExists, newLevelName + Program.LevelFileExtension, newLevelName + Program.ScriptFileExtension)); } else { try { map.RenameLevel(selectedLevelName, newLevelName); File.Move(levelSource, levelDestination); File.Move(scriptSource, scriptDestination); Program.SaveInstalledMaps(); RefreshLevelList(map); } catch (Exception e) { LogTextBox.WriteLine(string.Format(Text.ErrorWithMessage, e.Message)); if (File.Exists(levelDestination)) { LogTextBox.WriteLine(string.Format(Text.RevertLevelRename, currentLevelName)); File.Move(levelDestination, levelSource); LogTextBox.AppendLastLine(Text.Renamed); } if (File.Exists(scriptDestination)) { LogTextBox.WriteLine(string.Format(Text.RevertScriptRename, currentScriptName)); File.Move(scriptDestination, scriptSource); LogTextBox.AppendLastLine(Text.Renamed); } } } } break; case 1: // Delete LogTextBox.WriteLine(string.Format(Text.ConfirmDelete, currentLevelName, currentScriptName)); LogTextBox.WriteLine(Text.AreYouSureYouWantToContinue); LogTextBox.WriteLine(Text.UnassignInsteadOfDelteInstructions); int confirmation = SelectionPrompt.PromptSelection(confirmDeleteCommands, new GUI.SelectionPrompt.Options() { AllowCancel = true, Index = 1 }); if (confirmation == 0) // Confirmed deletion { try { LogTextBox.ClearContent(); map.RemoveLevel(selectedLevelName); Program.SaveInstalledMaps(); LogTextBox.WriteLine(string.Format(Text.Deleting, currentLevelName)); File.Delete(levelSource); LogTextBox.AppendLastLine(Text.Deleted); LogTextBox.WriteLine(string.Format(Text.Deleting, currentScriptName)); File.Delete(scriptSource); LogTextBox.AppendLastLine(Text.Deleted); } catch (Exception e) { LogTextBox.WriteLine(string.Format(Text.ErrorWithMessage, e.Message)); } RefreshLevelList(map); } break; } break; } levelList.SelectCurrentItem(); break; case Properties.Command.Cancel: quitPrompt = true; break; } } }