예제 #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>");
                }
            }
        }
예제 #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());
                        }
                    }
            }
        }
예제 #3
0
        private void SaveFileDialog(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter          = "ISO/WBFS Image|*.wbfs;*.iso;*.ciso|Directory (do not pack ISO/WBFS)|*";
            saveFileDialog1.Title           = "Where shall the output be saved?";
            saveFileDialog1.OverwritePrompt = false;
            saveFileDialog1.FileName        = Path.GetFileName(setInputISOLocation.Text);

            if (saveFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                var outputFile = saveFileDialog1.FileName;
                if (saveFileDialog1.FilterIndex == 2)
                {
                    // remove the extension
                    outputFile = Path.Combine(Directory.GetParent(outputFile).FullName, Path.GetFileNameWithoutExtension(outputFile));
                }
                if (PatchProcess.IsImageFileExtension(outputFile))
                {
                    bool overwrite = File.Exists(outputFile);
                    if (overwrite)
                    {
                        DialogResult dialogResult = MessageBox.Show("An iso/wbfs already exists at " + Environment.NewLine + outputFile + Environment.NewLine + Environment.NewLine + "Do you want to overwrite this wbfs/iso? Make sure you have a backup.", "Files already exist", MessageBoxButtons.YesNo);
                        if (dialogResult == DialogResult.Yes)
                        {
                            setOutputPathLabel.Text = outputFile;
                        }
                    }
                    else
                    {
                        setOutputPathLabel.Text = outputFile;
                    }
                }
                else
                {
                    bool overwrite;
                    outputFile = PatchProcess.DoPathCorrections(outputFile, true, out overwrite);
                    if (overwrite)
                    {
                        DialogResult dialogResult = MessageBox.Show("An extracted iso/wbfs directory already exists at " + Environment.NewLine + outputFile + Environment.NewLine + Environment.NewLine + "Do you want to patch this location? Make sure you have a backup.", "Files already exist", MessageBoxButtons.YesNo);
                        if (dialogResult == DialogResult.Yes)
                        {
                            setOutputPathLabel.Text = outputFile;
                        }
                    }
                    else
                    {
                        setOutputPathLabel.Text = outputFile;
                    }
                }
            }
            else
            {
                setOutputPathLabel.Text = "None";
            }
        }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
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);
        }
 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);
 }
예제 #8
0
        private void OpenFileDialog(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "ISO/WBFS Image or main.dol of extracted image|*.iso;*.wbfs;*.ciso;main.dol";
            openFileDialog1.Title  = "Which ISO image or WBFS image or extracted image folder should we use for patching?";

            if (openFileDialog1.ShowDialog(this) == DialogResult.OK && !string.IsNullOrWhiteSpace(openFileDialog1.FileName))
            {
                var input = openFileDialog1.FileName;

                input = PatchProcess.DoPathCorrections(input, false);

                setInputISOLocation.Text = input;
                reloadWbfsIsoFile();
            }
        }
예제 #9
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);
        }
예제 #10
0
        private void importMd(MapDescriptor mapDescriptor)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "Map Descriptor File (.md)|*.md";
            openFileDialog1.Title  = "Which Map to import?";

            if (openFileDialog1.ShowDialog(this) == DialogResult.OK && !string.IsNullOrWhiteSpace(openFileDialog1.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);
                        });

                        try
                        {
                            var importedMapDescriptor = PatchProcess.ImportMd(openFileDialog1.FileName, progress, ct);
                            if (mapDescriptor != null)
                            {
                                mapDescriptor.setFromImport(importedMapDescriptor);
                            }
                            else
                            {
                                BindingSource bs = dataGridView1.DataSource as BindingSource;
                                bs.Add(importedMapDescriptor);
                            }
                        }
                        catch (Exception e)
                        {
                            progressBar.appendText(e.Message);
                            progressBar.appendText(Environment.NewLine + Environment.NewLine + e.ToString());
                            progressBar.EnableButton();
                            Debug.WriteLine(e.ToString());
                        }
                    }
            }
        }
예제 #11
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));
            }
        }
예제 #12
0
        public static void Load(string fileName, List <MapDescriptor> mapDescriptors, IProgress <ProgressInfo> progress, CancellationToken ct)
        {
            var dir = Directory.GetParent(fileName).FullName;

            string[] lines = File.ReadAllLines(fileName);
            var      p     = 0;
            // how many ids are there?
            var maxId = 0;

            foreach (var line in lines)
            {
                string[] columns = line.Split(new[] { ',' }, 6);
                var      i       = int.Parse(columns[0].Trim());
                if (i > maxId)
                {
                    maxId = i;
                }
            }
            var tempMapDescriptors = new List <MapDescriptor>();

            // add as many new map descriptors
            for (int i = 0; i < maxId + 1; i++)
            {
                var md = new MapDescriptor();
                tempMapDescriptors.Add(md);
                if (i < mapDescriptors.Count)
                {
                    md.set(mapDescriptors[i]);
                }
            }
            foreach (var line in lines)
            {
                string[] columns               = line.Split(new[] { ',' }, 6);
                var      i                     = int.Parse(columns[0].Trim());
                var      mapSet                = sbyte.Parse(columns[1].Trim());
                var      zone                  = sbyte.Parse(columns[2].Trim());
                var      order                 = sbyte.Parse(columns[3].Trim());
                var      isPracticeBoard       = bool.Parse(columns[4].Trim());
                var      mapDescriptorFilePath = columns[5].Trim();

                tempMapDescriptors[i].MapSet          = mapSet;
                tempMapDescriptors[i].Zone            = zone;
                tempMapDescriptors[i].Order           = order;
                tempMapDescriptors[i].IsPracticeBoard = isPracticeBoard;

                if (!string.IsNullOrEmpty(mapDescriptorFilePath))
                {
                    mapDescriptorFilePath = Path.Combine(dir, mapDescriptorFilePath);
                    var importMd = PatchProcess.ImportMd(mapDescriptorFilePath, ProgressInfo.makeNoProgress(progress), ct);
                    tempMapDescriptors[i].setFromImport(importMd);
                }
                progress?.Report(100 * p / lines.Count());
                p++;
            }

            while (mapDescriptors.Count > tempMapDescriptors.Count)
            {
                mapDescriptors.RemoveAt(mapDescriptors.Count - 1);
            }
            for (int i = mapDescriptors.Count; i < tempMapDescriptors.Count; i++)
            {
                var md = new MapDescriptor();
                // only add new maps, if there is a map descriptor file path available
                if (!string.IsNullOrEmpty(tempMapDescriptors[i].MapDescriptorFilePath))
                {
                    mapDescriptors.Add(md);
                }
                else
                {
                    progress?.Report("Warning: Could not load the configuration after map " + i + " because the md files are not set.");
                    break;
                }
            }

            for (int i = 0; i < mapDescriptors.Count; i++)
            {
                if (!tempMapDescriptors[i].Equals(mapDescriptors[i]))
                {
                    tempMapDescriptors[i].Dirty = true;
                }
                mapDescriptors[i].setFromImport(tempMapDescriptors[i]);
                mapDescriptors[i].MapSet          = tempMapDescriptors[i].MapSet;
                mapDescriptors[i].Zone            = tempMapDescriptors[i].Zone;
                mapDescriptors[i].Order           = tempMapDescriptors[i].Order;
                mapDescriptors[i].IsPracticeBoard = tempMapDescriptors[i].IsPracticeBoard;
            }
            progress?.Report(100);
            progress?.Report("Loaded configuration from " + fileName);
        }
예제 #13
0
        private async void reloadWbfsIsoFile()
        {
            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);
                    });

                    var inputWbfsIso = setInputISOLocation.Text;
                    try
                    {
                        await ExeChecker.makeSureWitInstalled(ct, ProgressInfo.makeSubProgress(progress, 0, 1)).ConfigureAwait(true);

                        var mapDescriptors = await PatchProcess.Open(inputWbfsIso, progress, ct);

                        Go.Enabled = true;
                        clearListButton.Enabled         = true;
                        buttonAddMap.Enabled            = true;
                        setOutputLocationButton.Enabled = true;
                        buttonSaveConfiguration.Enabled = false;
                        buttonLoadConfiguration.Enabled = true;
                        BindingSource bs = new BindingSource();
                        bs.DataSource            = mapDescriptors;
                        dataGridView1.DataSource = bs;
                        DataGridView1_CellEndEdit(null, null);

                        for (int i = 0; i < this.dataGridView1.Columns.Count; i++)
                        {
                            DataGridViewColumn column = dataGridView1.Columns[i];
                            if (column.Name == "VentureCardActiveCount")
                            {
                                dataGridView1.Columns.RemoveAt(i);
                                if (!dataGridView1.Columns.Contains(VentureCards))
                                {
                                    dataGridView1.Columns.Insert(i, VentureCards);
                                }
                                break;
                            }
                        }

                        for (int i = 0; i < this.dataGridView1.Columns.Count; i++)
                        {
                            DataGridViewColumn column = this.dataGridView1.Columns[i];
                            // set autosizing
                            column.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader;
                            //store autosized widths
                            int colw = column.Width;
                            //remove autosizing
                            column.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
                            //set width to calculated by autosize
                            if (colw > 75 && column.Name.StartsWith("SwitchRotation"))
                            {
                                colw = 75;
                            }
                            if (colw > 100 && column.Name != "Name_EN")
                            {
                                colw = 100;
                            }
                            column.Width = colw;

                            column.Resizable = DataGridViewTriState.True;
                            if (column.Name == "ExportMd" || column.Name == "ImportMd")
                            {
                                column.Frozen    = true;
                                column.Resizable = DataGridViewTriState.False;
                            }
                            else if (column.ReadOnly)
                            {
                                column.DefaultCellStyle = readOnlyColumnStyle;
                            }
                            else
                            {
                                column.DefaultCellStyle = editColumnStyle;
                                column.Frozen           = true;
                                column.Width           += 25;
                            }
                            if (column.Name == "Name_EN")
                            {
                                column.Frozen = true;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        setInputISOLocation.Text = "None";
                        Go.Enabled = false;
                        clearListButton.Enabled         = false;
                        buttonAddMap.Enabled            = false;
                        buttonRemoveMap.Enabled         = false;
                        setOutputLocationButton.Enabled = false;
                        buttonSaveConfiguration.Enabled = false;
                        buttonLoadConfiguration.Enabled = false;
                        progressBar.appendText(e.Message);
                        progressBar.appendText(Environment.NewLine + Environment.NewLine + e.ToString());
                        progressBar.EnableButton();
                        Debug.WriteLine(e.ToString());
                    }
                }
        }
예제 #14
0
        private async void Go_Click(object sender, EventArgs e)
        {
            var outputFile = setOutputPathLabel.Text;
            var inputFile  = setInputISOLocation.Text;

            if (String.IsNullOrWhiteSpace(outputFile) || outputFile.ToLower() == "none")
            {
                DialogResult dialogResult = MessageBox.Show("Do you want to patch the existing location?" + Environment.NewLine + inputFile + Environment.NewLine + Environment.NewLine + "Make sure you have a backup.", "Files already exist", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    outputFile = inputFile;
                }
                else
                {
                    return;
                }
            }

            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);
                    });

                    try
                    {
                        await ExeChecker.makeSureWszstInstalled(ct, ProgressInfo.makeSubProgress(progress, 0, 1)).ConfigureAwait(true);

                        await ExeChecker.makeSureBenzinInstalled(ct, ProgressInfo.makeSubProgress(progress, 1, 2)).ConfigureAwait(true);

                        await PatchProcess.Save(inputFile, outputFile, GetMapDescriptors(), this.patchWiimmfi.Checked, progress, ct);


                        // TODO, better cleanup
                        Invoke((MethodInvoker) delegate
                        {
                            progressBar.ShowCheckbox("Cleanup temporary files.", false);
                            progressBar.callback = (c) =>
                            {
                                if (c)
                                {
                                    PatchProcess.CleanCache(inputFile);
                                    PatchProcess.CleanRiivolution();
                                }
                                PatchProcess.CleanTemp();
                            };
                        });
                    }
                    catch (Exception e2)
                    {
                        Invoke((MethodInvoker) delegate
                        {
                            progressBar.appendText(e2.Message);
                            progressBar.appendText(Environment.NewLine + Environment.NewLine + e2.ToString());
                            progressBar.EnableButton();
                        });

                        Debug.WriteLine(e2.ToString());
                    }
                }
        }