Exemple #1
0
        public void update(ProgressInfo progressInfo)
        {
            if (IsDisposed)
            {
                return;
            }
            if (progressInfo.progress > 0)
            {
                SetProgressBarValue(progressInfo.progress);
            }
            string lastLine = "";

            if (textBox.Lines.Length >= 2)
            {
                lastLine = textBox.Lines[textBox.Lines.Length - 2];
            }
            if (progressInfo.line != null)
            {
                if (lastLine.ToLower() != progressInfo.line.ToLower())
                {
                    if (verbose && progressInfo.verbose || !progressInfo.verbose)
                    {
                        textBox.AppendText(progressInfo.line + Environment.NewLine);
                    }
                }
            }
            Update();
        }
Exemple #2
0
 public static IProgress <ProgressInfo> makeSubProgress(IProgress <ProgressInfo> progress, int minProgress, int maxProgress)
 {
     return(new Progress <ProgressInfo>(progressInfo =>
     {
         progressInfo.progress = ProgressInfo.lerp(minProgress, maxProgress, progressInfo.progress);
         progress?.Report(progressInfo);
     }));
 }
 private static void parsePercentageValue(string line, IProgress<ProgressInfo> progress)
 {
     var pi = new ProgressInfo();
     pi.progress = -1;
     pi.line = line;
     pi.verbose = true;
     Match match = Regex.Match(line, @"(\d\d\d?)%");
     if (match.Success && match.Groups.Count == 2)
     {
         var percentage = match.Groups[1].Value;
         pi.progress = int.Parse(percentage);
     }
     progress?.Report(pi);
 }
 private static async Task <bool> canRunAsync(string[] requiredRunnables, CancellationToken cancelToken, IProgress <ProgressInfo> progress)
 {
     try
     {
         foreach (var requiredRunnable in requiredRunnables)
         {
             var psi = ExeWrapper.preparePsi(requiredRunnable, "");
             await ExeWrapper.execute(psi, cancelToken, ProgressInfo.makeNoProgress(progress));
         }
     }
     catch (Exception e)
     {
         progress?.Report(new ProgressInfo(e.Message, true));
         return(false);
     }
     return(true);
 }
        public static async Task <List <MapDescriptor> > Open(string input, IProgress <ProgressInfo> progress, CancellationToken ct, string cachePath = null)
        {
            progress?.Report(0);

            if (string.IsNullOrWhiteSpace(input) || input.ToLower() == "none")
            {
                throw new ArgumentNullException("Can't load wbfs or iso file as the input file name is not set.");
            }

            input = DoPathCorrections(input, false);
            var cacheFileSet = new DataFileSet(GetCachePath(input, cachePath));

            if (IsImageFileExtension(input))
            {
                progress?.Report("Extract iso/wbfs...");
                await ExeWrapper.extractFullIsoAsync(input, cacheFileSet.rootDir, ct, ProgressInfo.makeSubProgress(progress, 0, 90)).ConfigureAwait(false);
            }

            progress?.Report("Detect the sections in main.dol file...");
            List <AddressSection> sections = await ExeWrapper.readSections(cacheFileSet.main_dol, ct, ProgressInfo.makeSubProgress(progress, 90, 95)).ConfigureAwait(false);

            progress?.Report("Read data from main.dol file...");

            List <MapDescriptor> mapDescriptors;

            using (var stream = File.OpenRead(cacheFileSet.main_dol))
            {
                EndianBinaryReader binReader = new EndianBinaryReader(EndianBitConverter.Big, stream);
                var mainDol = new MainDol(binReader, sections, progress);
                mapDescriptors = mainDol.readMainDol(binReader, progress);

                progress?.Report(97);
                progress?.Report("Read localization files...");
                LoadUIMessages(mapDescriptors, cacheFileSet, ProgressInfo.makeSubProgress(progress, 20, 60), ct);
            }

            progress?.Report(100);
            progress?.Report("Loaded successfully.");
            CleanTemp();
            CleanRiivolution();

            return(mapDescriptors);
        }
        private static async Task <bool> downloadAndExtractZip(string name, string downloadUrl, string[] requiredFiles, CancellationToken cancelToken, IProgress <ProgressInfo> progress)
        {
            string zipFileName = name + ".zip";
            string zipFilePath = Path.Combine(Directory.GetCurrentDirectory(), zipFileName);
            string extractPath = Directory.GetCurrentDirectory();
            var    progressSub = ProgressInfo.makeSubProgress(progress, 0, 50);

            using (var client = new WebClient())
            {
                progressSub?.Report("Downloading " + name + "...");
                client.DownloadProgressChanged += (s, e) =>
                {
                    progressSub?.Report(e.ProgressPercentage);
                };
                await client.DownloadFileTaskAsync(downloadUrl, zipFilePath).ConfigureAwait(continueOnCapturedContext);
            }
            progressSub = ProgressInfo.makeSubProgress(progress, 50, 100);
            using (ZipArchive archive = ZipFile.OpenRead(zipFilePath))
            {
                int i = 0;
                progressSub?.Report("Extracting " + name + " ...");
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    foreach (string requiredFile in requiredFiles)
                    {
                        if (entry.FullName.EndsWith(requiredFile, StringComparison.OrdinalIgnoreCase))
                        {
                            string destinationPath = Path.GetFullPath(Path.Combine(extractPath, entry.Name));
                            if (destinationPath.StartsWith(extractPath, StringComparison.Ordinal))
                            {
                                entry.ExtractToFile(destinationPath, true);
                                progressSub?.Report(100 * i / requiredFiles.Length);
                                i++;
                            }
                        }
                    }
                }
            }
            File.Delete(zipFilePath);
            return(true);
        }
Exemple #7
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);
        }
        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());
                    }
                }
        }
        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());
                    }
                }
        }
Exemple #10
0
        private static async Task <bool> InjectMapIcons(List <MapDescriptor> mapDescriptors, DataFileSet cacheFileSet, DataFileSet tmpFileSet, DataFileSet riivFileSet, IProgress <ProgressInfo> progress, CancellationToken ct)
        {
            // first check if we need to inject any map icons in the first place. We do not need to if only vanilla map icons are used.
            bool allMapIconsVanilla = true;

            foreach (var mapDescriptor in mapDescriptors)
            {
                var mapIcon = mapDescriptor.MapIcon;
                if (string.IsNullOrEmpty(mapIcon))
                {
                    continue;
                }
                if (!VanillaDatabase.getVanillaTpl(mapIcon).Any())
                {
                    allMapIconsVanilla = false;
                    break;
                }
            }
            if (allMapIconsVanilla)
            {
                return(true);
            }

            progress.Report("Extract game_sequence files...");

            // setup the directories for the game sequence files

            /** maps the path of the various variants of the game_sequenceXXXXXXXX.arc files to their respective extraction path in the tmp directory */
            var gameSequenceExtractPaths = new Dictionary <string, string>();
            /** maps the path of the various variants of the game_sequenceXXXXXXXX.arc files to their respective temporary path for the converted xmlyt base path */
            var gameSequenceToXmlytBasePaths = new Dictionary <string, string>();
            /** maps the path of the various variants of the game_sequenceXXXXXXXX.arc files to their target path where they will be packed again */
            var gameSequencePackPaths = new Dictionary <string, string>();

            foreach (var entry in cacheFileSet.game_sequence_arc)
            {
                var locale           = entry.Key;
                var gameSequencePath = entry.Value;

                var extractPath = Path.Combine(tmpFileSet.rootDir, Path.GetFileNameWithoutExtension(gameSequencePath));
                Directory.CreateDirectory(Path.GetDirectoryName(extractPath));
                gameSequenceExtractPaths.Add(gameSequencePath, extractPath);

                var xmlytPath = Path.Combine(tmpFileSet.rootDir, Path.GetFileNameWithoutExtension(gameSequencePath) + ".");
                Directory.CreateDirectory(Path.GetDirectoryName(xmlytPath));
                gameSequenceToXmlytBasePaths.Add(gameSequencePath, xmlytPath);

                var packPath = riivFileSet.game_sequence_arc[locale];
                Directory.CreateDirectory(Path.GetDirectoryName(packPath));
                gameSequencePackPaths.Add(gameSequencePath, packPath);
            }
            foreach (var entry in cacheFileSet.game_sequence_wifi_arc)
            {
                var locale           = entry.Key;
                var gameSequencePath = entry.Value;

                var extractPath = Path.Combine(tmpFileSet.rootDir, Path.GetFileNameWithoutExtension(gameSequencePath));
                Directory.CreateDirectory(Path.GetDirectoryName(extractPath));
                gameSequenceExtractPaths.Add(gameSequencePath, extractPath);

                var xmlytPath = Path.Combine(tmpFileSet.rootDir, Path.GetFileNameWithoutExtension(gameSequencePath) + ".");
                Directory.CreateDirectory(Path.GetDirectoryName(xmlytPath));
                gameSequenceToXmlytBasePaths.Add(gameSequencePath, xmlytPath);

                var packPath = riivFileSet.game_sequence_wifi_arc[locale];
                Directory.CreateDirectory(Path.GetDirectoryName(packPath));
                gameSequencePackPaths.Add(gameSequencePath, packPath);
            }

            using (CancellationTokenSource source = new CancellationTokenSource())
            {
                // start fake progress
                var fakeProgressTask = ProgressInfo.makeFakeProgress(ProgressInfo.makeSubProgress(progress, 2, 33), source.Token);

                // extract the arc files
                List <Task <string> > extractArcFileTasks = new List <Task <string> >();
                foreach (var entry in gameSequenceExtractPaths)
                {
                    string gameSequencePath        = entry.Key;
                    string gameSequenceExtractPath = entry.Value;
                    extractArcFileTasks.Add(ExeWrapper.extractArcFile(gameSequencePath, gameSequenceExtractPath, ct, ProgressInfo.makeNoProgress(progress)));
                }
                await Task.WhenAll(extractArcFileTasks).ConfigureAwait(false);

                source.Cancel();
                await fakeProgressTask.ConfigureAwait(false);
            }
            progress.Report("Convert map icons and inject them...");
            using (CancellationTokenSource source = new CancellationTokenSource())
            {
                // start fake progress
                var fakeProgressTask = ProgressInfo.makeFakeProgress(ProgressInfo.makeSubProgress(progress, 33, 66), source.Token);

                // convert the png files to tpl and copy them to the correct location
                Dictionary <string, string> mapIconToTplName = new Dictionary <string, string>();
                List <Task> convertPngFileTasks = new List <Task>();
                foreach (var mapDescriptor in mapDescriptors)
                {
                    var mapIcon = mapDescriptor.MapIcon;
                    if (string.IsNullOrEmpty(mapIcon))
                    {
                        continue;
                    }

                    if (VanillaDatabase.getVanillaTpl(mapIcon).Any())
                    {
                        // its a vanilla map icon -> dont convert and inject it
                        VanillaDatabase.getVanillaTpl(mapIcon).IfPresent(value => mapIconToTplName[mapIcon] = value);
                    }
                    else
                    {
                        var mapIconPng = Path.Combine(tmpFileSet.param_folder, mapIcon + ".png");
                        var mapIconTpl = Path.ChangeExtension(mapIconPng, ".tpl");
                        var tplName    = Ui_menu_19_00a.constructMapIconTplName(mapIcon);
                        if (!mapIconToTplName.ContainsKey(mapIcon))
                        {
                            mapIconToTplName.Add(mapIcon, tplName);
                        }
                        if (File.Exists(mapIconPng))
                        {
                            Task task1 = ExeWrapper.convertPngToTpl(mapIconPng, mapIconTpl, ct, ProgressInfo.makeNoProgress(progress));
                            Task task2 = task1.ContinueWith(async(t1) =>
                            {
                                await t1.ConfigureAwait(false);
                                foreach (var entry in gameSequenceExtractPaths)
                                {
                                    string gameSequencePath        = entry.Key;
                                    string gameSequenceExtractPath = entry.Value;
                                    var mapIconTplCopy             = Path.Combine(gameSequenceExtractPath, "arc", "timg", tplName);
                                    File.Copy(mapIconTpl, mapIconTplCopy, true);
                                }
                            });
                            convertPngFileTasks.Add(task2);
                        }
                    }
                }
                // convert the brlyt files to xmlyt, inject the map icons and convert it back
                List <Task> injectMapIconsInBrlytTasks = new List <Task>();
                foreach (var entry in gameSequenceExtractPaths)
                {
                    string gameSequencePath        = entry.Key;
                    string gameSequenceExtractPath = entry.Value;
                    var    brlytFile = Path.Combine(gameSequenceExtractPath, "arc", "blyt", "ui_menu_19_00a.brlyt");
                    string xmlytFile = gameSequenceToXmlytBasePaths[gameSequencePath] + Path.GetFileNameWithoutExtension(brlytFile) + ".xmlyt";
                    Task   task1     = ExeWrapper.convertBryltToXmlyt(brlytFile, xmlytFile, ct, ProgressInfo.makeNoProgress(progress));
                    Task   task2     = task1.ContinueWith(async(t1) => { await t1.ConfigureAwait(false); Ui_menu_19_00a.injectMapIconsLayout(xmlytFile, mapIconToTplName); });
                    Task   task3     = task2.ContinueWith(async(t2) => { await t2.ConfigureAwait(false); await ExeWrapper.convertXmlytToBrylt(xmlytFile, brlytFile, ct, ProgressInfo.makeNoProgress(progress)); });
                    Task   task4     = task3.ContinueWith(async(t3) =>
                    {
                        await t3;
                        // strange phenomenon: when converting the xmlyt files back to brlyt using benzin, sometimes the first byte is not correctly written. This fixes it as the first byte must be an 'R'.
                        await Task.Delay(500);
                        using (var stream = File.OpenWrite(brlytFile))
                        {
                            stream.Seek(0, SeekOrigin.Begin);
                            stream.WriteByte((byte)'R');
                        }
                        // wait till the handle has been disposed properly
                        await Task.Delay(500);
                    });
                    injectMapIconsInBrlytTasks.Add(task4);
                }
                // convert the brlan files to xmlan, inject the map icons and convert it back
                List <Task> injectMapIconsInBrlanTasks = new List <Task>();
                foreach (var entry in gameSequenceExtractPaths)
                {
                    string gameSequencePath        = entry.Key;
                    string gameSequenceExtractPath = entry.Value;
                    foreach (var brlanFile in Directory.GetFiles(Path.Combine(gameSequenceExtractPath, "arc", "anim"), "ui_menu_19_00a_Tag_*.brlan"))
                    {
                        string xmlanFile = gameSequenceToXmlytBasePaths[gameSequencePath] + Path.GetFileNameWithoutExtension(brlanFile) + ".xmlan";
                        Task   task1     = ExeWrapper.convertBryltToXmlyt(brlanFile, xmlanFile, ct, ProgressInfo.makeNoProgress(progress));
                        Task   task2     = task1.ContinueWith(async(t1) => { await t1.ConfigureAwait(false); Ui_menu_19_00a.injectMapIconsAnimation(xmlanFile, mapIconToTplName); });
                        Task   task3     = task2.ContinueWith(async(t2) => { await t2.ConfigureAwait(false); await ExeWrapper.convertXmlytToBrylt(xmlanFile, brlanFile, ct, ProgressInfo.makeNoProgress(progress)); });
                        Task   task4     = task3.ContinueWith(async(t3) =>
                        {
                            await t3;
                            // strange phenomenon: when converting the xmlyt files back to brlyt using benzin, sometimes the first byte is not correctly written. This fixes it as the first byte must be an 'R'.
                            await Task.Delay(500);
                            using (var stream = File.OpenWrite(brlanFile))
                            {
                                stream.Seek(0, SeekOrigin.Begin);
                                stream.WriteByte((byte)'R');
                            }
                            // wait till the handle has been disposed properly
                            await Task.Delay(500);
                        });
                        injectMapIconsInBrlanTasks.Add(task4);
                    }
                }
                await Task.WhenAll(injectMapIconsInBrlytTasks).ConfigureAwait(false);

                await Task.WhenAll(injectMapIconsInBrlanTasks).ConfigureAwait(false);

                await Task.WhenAll(convertPngFileTasks).ConfigureAwait(false);

                source.Cancel();
                await fakeProgressTask.ConfigureAwait(false);
            }
            await Task.Delay(1000);

            progress.Report("Pack game_sequence files...");
            using (CancellationTokenSource source = new CancellationTokenSource())
            {
                // start fake progress
                var fakeProgressTask = ProgressInfo.makeFakeProgress(ProgressInfo.makeSubProgress(progress, 66, 100), source.Token);

                // pack the arc files
                List <Task <string> > packArcFileTasks = new List <Task <string> >();
                foreach (var entry in gameSequenceExtractPaths)
                {
                    string gameSequencePath        = entry.Key;
                    string gameSequenceExtractPath = entry.Value;
                    string gameSequencePackPath    = gameSequencePackPaths[gameSequencePath];
                    packArcFileTasks.Add(ExeWrapper.packDfolderToArc(gameSequenceExtractPath, gameSequencePackPath, ct, ProgressInfo.makeNoProgress(progress)));
                }
                await Task.WhenAll(packArcFileTasks).ConfigureAwait(false);

                source.Cancel();
                await fakeProgressTask.ConfigureAwait(false);
            }
            await Task.Delay(1000);

            progress.Report(100);

            return(true);
        }
Exemple #11
0
        private static async Task PatchMainDolAsync(List <MapDescriptor> mapDescriptors, DataFileSet cacheFileSet, DataFileSet riivFileSet, IProgress <ProgressInfo> progress, CancellationToken ct)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(riivFileSet.main_dol));
            File.Copy(cacheFileSet.main_dol, riivFileSet.main_dol, true);

            // expand dol if not already expanded
            // ehmm.. actually lets not do this -> range 0x80001800 till 0x80003000 is already used by gecko codes
            //if (mainDol.toFileAddress(0x80001800) == -1)
            //{
            //    await ExeWrapper.createNewTextSection(riivFileSet.main_dol, 0x80001800, 0x1800, ct, progress);
            //    mainDol.setSections(await ExeWrapper.readSections(riivFileSet.main_dol, ct, progress));
            //}

            progress?.Report("Detect the sections in main.dol file...");
            List <AddressSection> sections = await ExeWrapper.readSections(riivFileSet.main_dol, ct, ProgressInfo.makeNoProgress(progress)).ConfigureAwait(false);

            MainDol mainDol;

            using (var stream = File.OpenRead(riivFileSet.main_dol))
            {
                EndianBinaryReader binReader = new EndianBinaryReader(EndianBitConverter.Big, stream);
                mainDol = new MainDol(binReader, sections, progress);
            }

            using (Stream baseStream = File.Open(riivFileSet.main_dol, FileMode.Open))
            {
                try
                {
                    EndianBinaryWriter stream = new EndianBinaryWriter(EndianBitConverter.Big, baseStream);
                    mainDol.writeMainDol(stream, mapDescriptors, progress);
                }
                finally
                {
                    progress.Report("Before Patch:");
                    progress.Report("Amount of free space available in main.dol: " + mainDol.freeSpaceManager.calculateTotalFreeSpace() + " bytes");
                    progress.Report("Amount of free space in the largest block in main.dol: " + mainDol.freeSpaceManager.calculateLargestFreeSpaceBlockSize() + " bytes");
                    progress.Report("After Patch:");
                    progress.Report("Amount of free space available in main.dol: " + mainDol.freeSpaceManager.calculateTotalRemainingFreeSpace() + " bytes");
                    progress.Report("Amount of free space in the largest block in main.dol: " + mainDol.freeSpaceManager.calculateLargestRemainingFreeSpaceBlockSize() + " bytes");
                    int bytesWritten = mainDol.freeSpaceManager.calculateTotalFreeSpace() - mainDol.freeSpaceManager.calculateTotalRemainingFreeSpace();
                    progress.Report("Total free space used: " + bytesWritten + " bytes");
                }
            }
        }
Exemple #12
0
        public static async Task <bool> Save(string inputFile, string outputFile, List <MapDescriptor> mapDescriptors, bool patchWiimmfi, IProgress <ProgressInfo> progress, CancellationToken ct, string cachePath = null, string riivPath = null, string tmpPath = null)
        {
            var packIso = IsImageFileExtension(outputFile);

            outputFile = DoPathCorrections(outputFile, true);
            inputFile  = DoPathCorrections(inputFile, false);
            cachePath  = Path.GetFullPath(GetCachePath(inputFile, cachePath));
            if (IsImageFileExtension(cachePath))
            {
                throw new ArgumentException("cachePath must be a valid extracted fortune street game disc directory");
            }
            var cacheFileSet = new DataFileSet(cachePath);
            var riivFileSet  = new DataFileSet(GetDefaultRiivPath(riivPath));
            var tmpFileSet   = new DataFileSet(GetDefaultTmpPath(tmpPath));

            progress?.Report(new ProgressInfo(0, "Writing localization files..."));
            WriteLocalizationFiles(mapDescriptors, cacheFileSet, riivFileSet, patchWiimmfi && packIso);

            progress?.Report(new ProgressInfo(5, "Writing main.dol..."));
            await PatchMainDolAsync(mapDescriptors, cacheFileSet, riivFileSet, ProgressInfo.makeSubProgress(progress, 0, 6), ct);

            // lets get to the map icons
            await InjectMapIcons(mapDescriptors, cacheFileSet, tmpFileSet, riivFileSet, ProgressInfo.makeSubProgress(progress, 7, 40), ct).ConfigureAwait(false);

            await Task.Delay(500);

            var packIsoInputPath = cacheFileSet.rootDir;

            using (CancellationTokenSource source = new CancellationTokenSource())
            {
                // start fake progress
                progress.Report(new ProgressInfo(45, "Copying the modified files..."));
                var fakeProgressTask = ProgressInfo.makeFakeProgress(ProgressInfo.makeSubProgress(progress, 45, packIso ? 60 : 99), source.Token);

                if (packIso)
                {
                    if (ShouldKeepCache(inputFile))
                    {
                        packIsoInputPath = Path.Combine(tmpFileSet.rootDir, Path.GetFileNameWithoutExtension("pack_" + outputFile));
                        DirectoryCopy(cacheFileSet.rootDir, packIsoInputPath, true, true, ProgressInfo.makeNoProgress(progress), ct);
                        DirectoryCopy(riivFileSet.rootDir, packIsoInputPath, true, true, ProgressInfo.makeNoProgress(progress), ct);
                    }
                    else
                    {
                        DirectoryCopy(riivFileSet.rootDir, packIsoInputPath, true, true, ProgressInfo.makeNoProgress(progress), ct);
                    }
                }
                else
                {
                    if (cacheFileSet.rootDir != outputFile)
                    {
                        DirectoryCopy(cacheFileSet.rootDir, outputFile, true, true, ProgressInfo.makeNoProgress(progress), ct);
                    }
                    DirectoryCopy(riivFileSet.rootDir, outputFile, true, true, ProgressInfo.makeNoProgress(progress), ct);
                }
                source.Cancel();
                await fakeProgressTask.ConfigureAwait(false);
            }

            await Task.Delay(500);

            if (packIso)
            {
                progress.Report(new ProgressInfo(60, "Packing ISO/WBFS file..."));
                await ExeWrapper.packFullIso(packIsoInputPath, outputFile, patchWiimmfi, ct, ProgressInfo.makeSubProgress(progress, 60, 100)).ConfigureAwait(true);

                if (patchWiimmfi)
                {
                    await Task.Delay(500);

                    progress.Report("Applying Wiimmfi...");
                    await ExeWrapper.applyWiimmfi(outputFile, ct, ProgressInfo.makeNoProgress(progress)).ConfigureAwait(false);
                }
            }
            else if (patchWiimmfi)
            {
                progress.Report("Warning: Wiimmfi is not applied as it can only be patched when packing into an iso/wbfs image.");
            }

            await Task.Delay(500);

            progress.Report(new ProgressInfo(100, "Done."));

            return(true);
        }
Exemple #13
0
        public static MapDescriptor ImportMd(string mapDescriptorImportFile, IProgress <ProgressInfo> progress, CancellationToken ct, string riivPath = null, string tmpPath = null)
        {
            var riivFileSet = new DataFileSet(GetDefaultRiivPath(riivPath));
            var tmpFileSet  = new DataFileSet(GetDefaultTmpPath(tmpPath));

            MapDescriptor mapDescriptorImport = new MapDescriptor();

            progress.Report(new ProgressInfo(0, "Parse Map Descriptor File..."));

            var dir = Path.GetDirectoryName(mapDescriptorImportFile);

            var internalName = Path.GetFileNameWithoutExtension(mapDescriptorImportFile);

            if (internalName.ToLower() == "readme")
            {
                internalName = Path.GetFileName(dir);
            }

            mapDescriptorImport.readMapDescriptorFromFile(mapDescriptorImportFile, internalName);
            progress.Report(new ProgressInfo(20, "Imported " + mapDescriptorImportFile));

            var usedSquareTypes = mapDescriptorImport.readFrbFileInfo(dir, ProgressInfo.makeSubProgress(progress, 20, 60), ct);

            if (mapDescriptorImport.VentureCardActiveCount == 0)
            {
                progress.Report("The map " + internalName + " does not have a venture card table specified. A default venture card table will be used.");
                mapDescriptorImport.VentureCard = VanillaDatabase.getDefaultVentureCardTable(mapDescriptorImport.RuleSet, usedSquareTypes);
            }
            else if (mapDescriptorImport.VentureCardActiveCount < 64)
            {
                progress.Report("Warning: The map " + internalName + " has a venture card count smaller than 64. The behavior is undefined and glitchy.");
            }
            else if (mapDescriptorImport.VentureCardActiveCount > 64)
            {
                progress.Report("Warning: The map " + internalName + " has a venture card count larger than 64. Only the first 64 venture cards will be used.");
            }
            int problematicVentureCard = VanillaDatabase.hasProblemWithVentureCardMissingNeededSquareType(mapDescriptorImport.VentureCard, usedSquareTypes);

            if (problematicVentureCard != -1)
            {
                progress.Report("The map " + internalName + " uses venture card " + problematicVentureCard + ". This venture card needs certain square types which have not been placed on the map.");
                mapDescriptorImport.VentureCard = VanillaDatabase.getDefaultVentureCardTable(mapDescriptorImport.RuleSet, usedSquareTypes);
            }

            progress.Report(new ProgressInfo(60, "Copy frb file(s) to tmp..."));

            var frbFileName = mapDescriptorImport.FrbFile1;
            var importFile  = Path.Combine(dir, frbFileName + ".frb");
            var destFile    = Path.Combine(riivFileSet.param_folder, frbFileName + ".frb");

            Directory.CreateDirectory(riivFileSet.param_folder);
            File.Copy(importFile, destFile, true);

            progress.Report("Imported " + importFile);

            frbFileName = mapDescriptorImport.FrbFile2;
            if (frbFileName != null)
            {
                importFile = Path.Combine(dir, frbFileName + ".frb");
                destFile   = Path.Combine(riivFileSet.param_folder, frbFileName + ".frb");
                File.Copy(importFile, destFile, true);
                progress.Report("Imported " + importFile);
            }
            frbFileName = mapDescriptorImport.FrbFile3;
            if (frbFileName != null)
            {
                importFile = Path.Combine(dir, frbFileName + ".frb");
                destFile   = Path.Combine(riivFileSet.param_folder, frbFileName + ".frb");
                File.Copy(importFile, destFile, true);
                progress.Report("Imported " + importFile);
            }
            frbFileName = mapDescriptorImport.FrbFile4;
            if (frbFileName != null)
            {
                importFile = Path.Combine(dir, frbFileName + ".frb");
                destFile   = Path.Combine(riivFileSet.param_folder, frbFileName + ".frb");
                File.Copy(importFile, destFile, true);
                progress.Report("Imported " + importFile);
            }
            var mapIcon = mapDescriptorImport.MapIcon;

            // only import the png if it is not a vanilla map icon
            if (mapIcon != null && !VanillaDatabase.getVanillaTpl(mapIcon).Any())
            {
                importFile = Path.Combine(dir, mapIcon + ".png");
                destFile   = Path.Combine(tmpFileSet.param_folder, mapIcon + ".png");
                Directory.CreateDirectory(tmpFileSet.param_folder);
                if (File.Exists(destFile))
                {
                    File.Delete(destFile);
                }
                // we have a map icon for the tutorial map ready, we can use it
                if (mapIcon == "p_bg_901")
                {
                    WriteResourceToFile("CustomStreetMapManager.Images.p_bg_901.png", destFile);
                }
                else
                {
                    File.Copy(importFile, destFile);
                    progress.Report("Imported " + importFile);
                }
            }
            mapDescriptorImport.Dirty = true;
            progress.Report(new ProgressInfo(100, "Done."));
            return(mapDescriptorImport);
        }
 private static async Task<string> callWszst(string arguments, CancellationToken cancelToken, IProgress<ProgressInfo> progress)
 {
     var psi = preparePsi("wszst", arguments);
     return await execute(psi, cancelToken, ProgressInfo.makeSubProgress(progress, 10, 100));
 }