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 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); } }
public void ReinstallMap(Map installedMap, LoadableMap toInstall) { UninstallMap(installedMap); InstallMap(toInstall, false); }