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);
 }
예제 #2
0
        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);
        }
예제 #3
0
        public override async Task Run(string subCommand, string fortuneStreetPath, string configPath, Dictionary <string, string> options, ConsoleProgress progress, CancellationToken ct)
        {
            string destination = options.GetValueOrDefault("d", PatchProcess.GetCachePath(fortuneStreetPath));

            if (Path.GetFullPath(destination) == Path.GetFullPath(fortuneStreetPath) && !options.ContainsKey("f"))
            {
                throw new ArgumentException("This operation would overwrite the existing game disc directory at " + destination + ". Provide the switch -f to overwrite.");
            }
            var patchWiimmfi = GetBoolParameter(options, "w");

            await Save(fortuneStreetPath, destination, configPath, patchWiimmfi, progress, ct);
        }
예제 #4
0
        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));
            }
        }
 public override async Task Run(string subCommand, string fortuneStreetPath, string configPath, Dictionary <string, string> options, ConsoleProgress progress, CancellationToken ct)
 {
     await Close(fortuneStreetPath, configPath, progress, ct);
 }
예제 #6
0
        public override Task Run(string subCommand, string fortuneStreetPath, string configPath, Dictionary <string, string> options, ConsoleProgress progress, CancellationToken ct)
        {
            bool printGenericHelp = true;

            foreach (var command in Cli.GetCommandList())
            {
                if (subCommand == command.Name)
                {
                    printGenericHelp = false;
                    Console.WriteLine(command.GetHelp());
                }
            }
            if (printGenericHelp)
            {
                Console.WriteLine(GetHelp());
            }
            return(Task.CompletedTask);
        }
예제 #7
0
        public override async Task Run(string subCommand, string fortuneStreetPath, string configPath, Dictionary <string, string> options, ConsoleProgress progress, CancellationToken ct)
        {
            var destination = options.GetValueOrDefault("d", null);

            await Json(fortuneStreetPath, configPath, destination, progress, ct);
        }
예제 #8
0
        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);
        }
예제 #9
0
        static async Task Main(string[] args)
        {
            // args = new string[] { "open" };
            using var cancellationTokenSource = new CancellationTokenSource();
            var ct = cancellationTokenSource.Token;

            Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) =>
            {
                // prevent terminating the application instantly if user requests it -> only once user requests twice
                if (!cancellationTokenSource.IsCancellationRequested)
                {
                    Console.WriteLine("Aborting process...");
                    e.Cancel = true;
                    cancellationTokenSource.Cancel();
                }
                else
                {
                    Console.WriteLine("Killing process without cleanup...");
                }
            };
            if (args.Length == 0)
            {
                PrintHelp();
                return;
            }
            string subCommand = null;
            var    options    = new Dictionary <string, string>();

            for (int i = 1; i < args.Length; i++)
            {
                if (args[i].StartsWith("-"))
                {
                    var option = args[i].Substring(1);
                    if (HasParameter(option))
                    {
                        i++;
                        options.Add(option, args[i]);
                    }
                    else
                    {
                        options.Add(option, "");
                    }
                }
                else if (string.IsNullOrEmpty(subCommand))
                {
                    subCommand = args[i];
                }
            }
            var quiet    = options.ContainsKey("q");
            var verbose  = options.ContainsKey("v");
            var commands = GetCommandList();

            using ConsoleProgress progress = new ConsoleProgress(verbose, quiet);
            try
            {
                bool commandGiven = false;
                foreach (var command in commands)
                {
                    if (args[0].ToLower() == command.Name)
                    {
                        commandGiven = true;
                        await command.Run(subCommand, options, progress, ct);
                    }
                }
                if (!commandGiven)
                {
                    PrintHelp();
                }
            }
            catch (Exception e)
            {
                Environment.ExitCode = e.HResult;
                Console.WriteLine(e.Message);
                if (verbose)
                {
                    throw;
                }
            }
            finally
            {
                // cleanup?
            }
        }
예제 #10
0
        public override async Task Run(string subCommand, string fortuneStreetPath, string configPath, Dictionary <string, string> options, ConsoleProgress progress, CancellationToken ct)
        {
            var destination      = options.GetValueOrDefault("d", Directory.GetCurrentDirectory());
            var idList           = options.GetValueOrDefault("i", null);
            var all              = options.ContainsKey("a");
            var internalNameList = options.GetValueOrDefault("n", null);
            var overwrite        = options.ContainsKey("f");

            if (string.IsNullOrEmpty(idList) && string.IsNullOrEmpty(internalNameList) && !all)
            {
                throw new ArgumentException("No map descriptor to export");
            }
            List <string> ids = new List <string>();

            if (!string.IsNullOrEmpty(idList))
            {
                ids = new List <string>(idList.Split(','));
            }
            List <string> internalNames = new List <string>();

            if (!string.IsNullOrEmpty(internalNameList))
            {
                internalNames = new List <string>(internalNameList.Split(','));
            }
            await Export(fortuneStreetPath, destination, ids, all, internalNames, overwrite, progress, ct);
        }
        public override Task Run(string inputMdFile, string fortuneStreetPath, string configPath, Dictionary <string, string> options, ConsoleProgress progress, CancellationToken ct)
        {
            var mapId         = GetIntParameter(options, "i");
            var mapSet        = GetSbyteParameter(options, "m");
            var zone          = GetSbyteParameter(options, "z");
            var order         = GetSbyteParameter(options, "o");
            var practiceBoard = GetBoolParameter(options, "p");

            Configuration.Import(configPath, inputMdFile, mapId, mapSet, zone, order, practiceBoard, progress, ct);
            return(Task.CompletedTask);
        }
예제 #12
0
        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);
        }
예제 #13
0
        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>");
                }
            }
        }
예제 #14
0
 public abstract Task Run(string subCommand, string fortuneStreetPath, string configPath, Dictionary <string, string> options, ConsoleProgress progress, CancellationToken ct);