Esempio n. 1
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>");
                }
            }
        }
Esempio n. 2
0
        private async Task exportMdAsync(MapDescriptor mapDescriptor)
        {
            if (mapDescriptor == null)
            {
                return;
            }
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter          = "Map Descriptor file and accompanying files|*.md";
            saveFileDialog1.Title           = "Where shall the map files be exported?";
            saveFileDialog1.FileName        = mapDescriptor.InternalName + ".md";
            saveFileDialog1.OverwritePrompt = false;

            if (saveFileDialog1.ShowDialog(this) == DialogResult.OK && !string.IsNullOrWhiteSpace(saveFileDialog1.FileName))
            {
                using (var cancelTokenSource = new CancellationTokenSource())
                    using (var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(exitTokenSource.Token, cancelTokenSource.Token))
                    {
                        CancellationToken ct          = linkedTokenSource.Token;
                        ProgressBar       progressBar = new ProgressBar(verboseToolStripMenuItem.Checked);
                        progressBar.callback = (b) => { try { cancelTokenSource?.Cancel(); } catch (ObjectDisposedException) { } };
                        progressBar.Show(this);
                        var progress = new Progress <ProgressInfo>(progressInfo =>
                        {
                            progressBar.update(progressInfo);
                            Debug.WriteLine(progressInfo.line);
                        });

                        bool overwrite = false;

tryExportMd:
                        try
                        {
                            var input = setInputISOLocation.Text;

                            input = PatchProcess.DoPathCorrections(input, false);
                            input = PatchProcess.GetCachePath(input);
                            PatchProcess.ExportMd(saveFileDialog1.FileName, input, mapDescriptor, overwrite, progress, ct);
                        }
                        catch (FileAlreadyExistException e1)
                        {
                            DialogResult dialogResult = MessageBox.Show(e1.Message.Replace("\n", Environment.NewLine) + Environment.NewLine + "Do you want to overwrite these files?", "Files already exist", MessageBoxButtons.OKCancel);
                            if (dialogResult == DialogResult.OK)
                            {
                                overwrite = true;
                                goto tryExportMd;
                            }
                        }
                        catch (Exception e)
                        {
                            progressBar.appendText(e.Message);
                            progressBar.appendText(Environment.NewLine + Environment.NewLine + e.ToString());
                            progressBar.EnableButton();
                            Debug.WriteLine(e.ToString());
                        }
                    }
            }
        }
        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);
        }
Esempio n. 4
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);
        }