public async Task Run(string subCommand, Dictionary <string, string> options, ConsoleProgress progress, CancellationToken ct) { if (this is CliHelp) { await Run(subCommand, null, null, options, progress, ct); return; } if (options.ContainsKey("h") || options.ContainsKey("?") || options.ContainsKey("-help")) { Console.WriteLine(GetHelp()); return; } var source = options.GetValueOrDefault("s", null); if (source != null) { var cachePath = PatchProcess.GetCachePath(source); var configPath = options.GetValueOrDefault("c", Path.Combine(cachePath, "config.csv")); await Run(subCommand, source, configPath, options, progress, ct); } else { List <string> candidates = await ExeWrapper.findCandidates("", ct, progress); // remove the candidates which are extracted versions of an image int removeId = -1; do { for (int i = candidates.Count - 1; i >= 0; i--) { removeId = candidates.FindIndex((s) => PatchProcess.GetCachePath(s) == candidates[i] && s != candidates[i]); if (removeId != -1) { candidates.RemoveAt(i); break; } } } while (removeId != -1); if (candidates.Count == 1) { var fortuneStreetPath = candidates.Single(); progress?.Report("Found suitable candidate in current directory: " + fortuneStreetPath); var cachePath = PatchProcess.GetCachePath(fortuneStreetPath); var configPath = options.GetValueOrDefault("c", Path.Combine(cachePath, "config.csv")); await Run(subCommand, fortuneStreetPath, configPath, options, progress, ct); } else { progress?.Report("Following candidates found:"); foreach (var candidate in candidates) { progress?.Report(candidate); } progress?.Report("Please specify the source Fortune Street game disc image or directory with -s <path>"); } } }
public override async Task Run(string subCommand, string fortuneStreetPath, string configPath, Dictionary <string, string> options, ConsoleProgress progress, CancellationToken ct) { if (File.Exists(configPath) && !options.ContainsKey("f")) { throw new ArgumentException("The source " + fortuneStreetPath + " is already open. Use the switch -f to close and reopen it losing pending changes."); } var mapDescriptors = await PatchProcess.Open(fortuneStreetPath, progress, ct); Configuration.Save(configPath, mapDescriptors, progress, ct); progress?.Report("Opened " + fortuneStreetPath); }
private async Task Save(string fortuneStreetPath, string destination, string config, Optional <bool> wiimmfi, ConsoleProgress progress, CancellationToken ct) { progress.Report("Saving at " + Path.GetFullPath(destination)); var mapDescriptors = await PatchProcess.Open(fortuneStreetPath, progress, ct); await Task.Delay(500, ct); Configuration.Load(config, mapDescriptors, progress, ct); await PatchProcess.Save(fortuneStreetPath, destination, mapDescriptors, wiimmfi.OrElse(true), progress, ct); await Task.Delay(500, ct); }
public Task Close(string fortuneStreetPath, string configPath, ConsoleProgress progress, CancellationToken ct) { if (File.Exists(configPath)) { File.Delete(configPath); PatchProcess.CleanCache(fortuneStreetPath); progress?.Report("All cleaned up"); } else { throw new ArgumentException(fortuneStreetPath + " was not open"); } return(Task.CompletedTask); }
private async Task Export(string fortuneStreetPath, string destination, List <string> ids, bool all, List <string> internalNames, bool overwrite, ConsoleProgress progress, CancellationToken ct) { var mapDescriptors = await PatchProcess.Open(fortuneStreetPath, progress, ct); await Task.Delay(500, ct); var mapDescriptorsToExport = new List <MapDescriptor>(); for (int i = 0; i < mapDescriptors.Count; i++) { bool export = false; if (all) { export = true; } if (internalNames.Contains(mapDescriptors[i].InternalName)) { export = true; } if (ids.Contains(i.ToString())) { export = true; } if (export) { mapDescriptorsToExport.Add(mapDescriptors[i]); } } if (mapDescriptorsToExport.Count > 1 && !Directory.Exists(destination) && !string.IsNullOrEmpty(Path.GetExtension(destination))) { throw new ArgumentException("Multiple map descriptors are to be exported, however the given destination is a filename. Use a directory instead."); } foreach (var mapDescriptor in mapDescriptorsToExport) { try { PatchProcess.ExportMd(destination, PatchProcess.GetCachePath(fortuneStreetPath), mapDescriptor, overwrite, progress, ct); } catch (FileAlreadyExistException) { progress.Report("Use the switch -f to overwrite already existing files."); throw; } } await Task.Delay(500, ct); }
private async Task Json(string fortuneStreetPath, string configPath, string destination, ConsoleProgress progress, CancellationToken ct) { var mapDescriptors = await PatchProcess.Open(fortuneStreetPath, progress, ct); await Task.Delay(500, ct); var options = new JsonSerializerOptions { WriteIndented = true }; // Configuration.Load(configPath, mapDescriptors, progress, ct); progress?.Report(JsonSerializer.Serialize(mapDescriptors, options)); if (!string.IsNullOrEmpty(destination)) { File.WriteAllBytes(destination, JsonSerializer.SerializeToUtf8Bytes(mapDescriptors, options)); } }