Ejemplo n.º 1
0
        private void btnCreateWad_Click(object sender, EventArgs e)
        {
            Point mousePos = MousePosition;

            if (mousePos.X < (this.Location.X + btnCreateWad.Location.X + Math.Ceiling(separatorBtn) + 3))
            {
                //SEND WAD
                if (pbProgress.Value == 100)
                {
                    if (!string.IsNullOrEmpty(tbSourceWad.Text))
                    {
                        if (!File.Exists(Application.StartupPath + Path.DirectorySeparatorChar + "CustomizeMiiInstaller.dll"))
                            errorBox("CustomizeMiiInstaller.dll wasn't found!");
                        else
                        {
                            if (cbSecurityChecksOff.Checked == true || securityChecks() == true)
                            {
                                CustomizeMii_Transmit cmt = new CustomizeMii_Transmit();

                                if (cmt.ShowDialog() == DialogResult.OK)
                                {
                                    try
                                    {
                                        WadCreationInfo wadInfo = new WadCreationInfo();

                                        if (!int.TryParse(tbStartupIos.Text, out wadInfo.startupIos)) { errorBox("Please enter a valid startup IOS! (0 - 255)"); return; }
                                        wadInfo.titles = new string[] { tbJapanese.Text, tbEnglish.Text, tbGerman.Text, tbFrench.Text, tbSpanish.Text, tbItalian.Text, tbDutch.Text, tbKorean.Text };
                                        wadInfo.allLangTitle = tbAllLanguages.Text;
                                        wadInfo.nandLoader = (WadCreationInfo.NandLoader)cmbNandLoader.SelectedIndex;
                                        wadInfo.sendToWii = true;
                                        wadInfo.transmitProtocol = (cmt.Protocol == 1) ? Protocol.HAXX : Protocol.JODI;
                                        wadInfo.transmitIp = cmt.IPAddress;
                                        wadInfo.transmitIos = int.Parse(cmt.IOS);
                                        wadInfo.titleId = tbTitleID.Text;
                                        wadInfo.sound = tbSound.Text;
                                        wadInfo.dol = tbDol.Text;
                                        wadInfo.lz77 = cbLz77.Checked;

                                        BackgroundWorker bwCreateWad = new BackgroundWorker();
                                        bwCreateWad.DoWork += new DoWorkEventHandler(bwCreateWad_DoWork);
                                        bwCreateWad.ProgressChanged += new ProgressChangedEventHandler(bwCreateWad_ProgressChanged);
                                        bwCreateWad.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bwCreateWad_RunWorkerCompleted);
                                        bwCreateWad.WorkerReportsProgress = true;
                                        bwCreateWad.RunWorkerAsync(wadInfo);
                                    }
                                    catch (Exception ex) { errorBox(ex.Message); }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                //CREATE WAD
                if (pbProgress.Value == 100)
                {
                    if (!string.IsNullOrEmpty(tbSourceWad.Text))
                    {
                        if (cbSecurityChecksOff.Checked == true || securityChecks() == true)
                        {
                            SaveFileDialog sfd = new SaveFileDialog();
                            sfd.Filter = "Wii Channels|*.wad";

                            string fileName;

                            if (!string.IsNullOrEmpty(tbAllLanguages.Text))
                                fileName = tbAllLanguages.Text + " - " + tbTitleID.Text.ToUpper() + ".wad";
                            else
                                fileName = tbEnglish.Text + " - " + tbTitleID.Text.ToUpper() + ".wad";

                            foreach (char invalidChar in Path.GetInvalidFileNameChars())
                                fileName = fileName.Replace(invalidChar.ToString(), string.Empty);

                            sfd.FileName = fileName;

                            if (sfd.ShowDialog() == DialogResult.OK)
                            {
                                try
                                {
                                    WadCreationInfo wadInfo = new WadCreationInfo();

                                    if (!int.TryParse(tbStartupIos.Text, out wadInfo.startupIos)) { errorBox("Please enter a valid startup IOS! (0 - 255)"); return; }
                                    wadInfo.titles = new string[] { tbJapanese.Text, tbEnglish.Text, tbGerman.Text, tbFrench.Text, tbSpanish.Text, tbItalian.Text, tbDutch.Text, tbKorean.Text };
                                    wadInfo.allLangTitle = tbAllLanguages.Text;
                                    wadInfo.titleId = tbTitleID.Text;
                                    wadInfo.sound = tbSound.Text;
                                    wadInfo.dol = tbDol.Text;
                                    wadInfo.lz77 = cbLz77.Checked;

                                    wadInfo.outFile = sfd.FileName;
                                    wadInfo.nandLoader = (WadCreationInfo.NandLoader)cmbNandLoader.SelectedIndex;

                                    BackgroundWorker bwCreateWad = new BackgroundWorker();
                                    bwCreateWad.DoWork += new DoWorkEventHandler(bwCreateWad_DoWork);
                                    bwCreateWad.ProgressChanged += new ProgressChangedEventHandler(bwCreateWad_ProgressChanged);
                                    bwCreateWad.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bwCreateWad_RunWorkerCompleted);
                                    bwCreateWad.WorkerReportsProgress = true;
                                    bwCreateWad.RunWorkerAsync(wadInfo);

                                    return;
                                }
                                catch (Exception ex)
                                {
                                    errorBox(ex.Message);
                                }
                            }
                        }
                    }
                }

                currentProgress.progressValue = 100;
                currentProgress.progressState = " ";
                this.Invoke(ProgressUpdate);
            }
        }
Ejemplo n.º 2
0
        void bwCreateWad_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bwCreateWad   = sender as BackgroundWorker;
            Stopwatch        creationTimer = new Stopwatch();

            creationTimer.Start();

            try
            {
                WadCreationInfo wadInfo = (WadCreationInfo)e.Argument;


                disableControls();

                //Check Startup IOS
                if (wadInfo.startupIos < 0 || wadInfo.startupIos > 255)
                {
                    throw new Exception("Startup IOS must be between 0 and 255!");
                }

                wadInfo.success      = false;
                wadInfo.sendWadReady = false;
                wadCreationInfo      = wadInfo;

                //Make TPLs transparent
                makeBannerTplsTransparent();
                makeIconTplsTransparent();

                //Pack icon.bin
                bwCreateWad.ReportProgress(0, "Packing icon.bin...");
                if (string.IsNullOrEmpty(replacedIcon))
                {
                    iconBin.AddHeaderImd5();
                    iconBin.Lz77Compress = wadInfo.lz77;

                    for (int i = 0; i < sourceWad.BannerApp.NumOfNodes; i++)
                    {
                        if (sourceWad.BannerApp.StringTable[i].ToLower() == "icon.bin")
                        {
                            sourceWad.BannerApp.ReplaceFile(i, iconBin.ToByteArray()); break;
                        }
                    }
                }
                else
                {
                    newIconBin.AddHeaderImd5();
                    newIconBin.Lz77Compress = wadInfo.lz77;

                    for (int i = 0; i < sourceWad.BannerApp.NumOfNodes; i++)
                    {
                        if (sourceWad.BannerApp.StringTable[i].ToLower() == "icon.bin")
                        {
                            sourceWad.BannerApp.ReplaceFile(i, newIconBin.ToByteArray()); break;
                        }
                    }
                }

                //Pack banner.bin
                bwCreateWad.ReportProgress(20, "Packing banner.bin...");
                if (string.IsNullOrEmpty(replacedBanner))
                {
                    bannerBin.AddHeaderImd5();
                    bannerBin.Lz77Compress = wadInfo.lz77;

                    for (int i = 0; i < sourceWad.BannerApp.NumOfNodes; i++)
                    {
                        if (sourceWad.BannerApp.StringTable[i].ToLower() == "banner.bin")
                        {
                            sourceWad.BannerApp.ReplaceFile(i, bannerBin.ToByteArray()); break;
                        }
                    }
                }
                else
                {
                    newBannerBin.AddHeaderImd5();
                    bannerBin.Lz77Compress = wadInfo.lz77;

                    for (int i = 0; i < sourceWad.BannerApp.NumOfNodes; i++)
                    {
                        if (sourceWad.BannerApp.StringTable[i].ToLower() == "banner.bin")
                        {
                            sourceWad.BannerApp.ReplaceFile(i, newBannerBin.ToByteArray()); break;
                        }
                    }
                }

                //Pack sound.bin
                bwCreateWad.ReportProgress(40, "Packing sound.bin...");
                if (!string.IsNullOrEmpty(replacedSound) || !string.IsNullOrEmpty(wadInfo.sound))
                {
                    for (int i = 0; i < sourceWad.BannerApp.NumOfNodes; i++)
                    {
                        if (sourceWad.BannerApp.StringTable[i].ToLower() == "sound.bin")
                        {
                            sourceWad.BannerApp.ReplaceFile(i, newSoundBin); break;
                        }
                    }
                }

                //Insert new dol
                if (!string.IsNullOrEmpty(wadInfo.dol))
                {
                    bwCreateWad.ReportProgress(50, "Inserting DOL...");
                    sourceWad.RemoveAllContents();

                    if (wadInfo.nandLoader == WadCreationInfo.NandLoader.comex)
                    {
                        sourceWad.AddContent(Properties.Resources.comex, 1, 1, ContentType.Normal);

                        if (wadInfo.dol.StartsWith("Simple Forwarder:"))
                        {
                            sourceWad.AddContent(createForwarderSimple(), 2, 2, ContentType.Normal);
                        }
                        else if (wadInfo.dol.StartsWith("Complex Forwarder"))
                        {
                            bwCreateWad.ReportProgress(55, "Compiling Forwarder...");
                            sourceWad.AddContent(createForwarderComplex(), 2, 2, ContentType.Normal);
                        }
                        else
                        {
                            sourceWad.AddContent(newDol, 2, 2, ContentType.Normal);
                        }

                        sourceWad.BootIndex = 1;
                    }
                    else
                    {
                        sourceWad.AddContent(Properties.Resources.Waninkoko, 2, 2, ContentType.Normal);

                        if (wadInfo.dol.StartsWith("Simple Forwarder:"))
                        {
                            sourceWad.AddContent(createForwarderSimple(), 1, 1, ContentType.Normal);
                        }
                        else if (wadInfo.dol.StartsWith("Complex Forwarder"))
                        {
                            bwCreateWad.ReportProgress(55, "Compiling Forwarder...");
                            sourceWad.AddContent(createForwarderComplex(), 1, 1, ContentType.Normal);
                        }
                        else
                        {
                            sourceWad.AddContent(newDol, 1, 1, ContentType.Normal);
                        }

                        sourceWad.BootIndex = 2;
                    }
                }

                //Change channel information
                for (int i = 0; i < wadInfo.titles.Length; i++)
                {
                    if (string.IsNullOrEmpty(wadInfo.titles[i]))
                    {
                        wadInfo.titles[i] = wadInfo.allLangTitle;
                    }
                }

                bwCreateWad.ReportProgress(75, "Updating Channel Information...");
                sourceWad.ChangeStartupIOS(wadInfo.startupIos);
                sourceWad.ChangeChannelTitles(wadInfo.titles);
                if (!string.IsNullOrEmpty(wadInfo.titleId))
                {
                    sourceWad.ChangeTitleID(LowerTitleID.Channel, wadInfo.titleId);
                }

                sourceWad.FakeSign = true;
                sourceWad.ChangeTitleKey("GottaGetSomeBeer");

                //Pack WAD
                bwCreateWad.ReportProgress(80, "Packing WAD...");
                if (!wadInfo.sendToWii)
                {
                    sourceWad.Save(wadInfo.outFile);
                }
                else
                {
                    wadInfo.wadFile = sourceWad.ToByteArray();
                }

                bwCreateWad.ReportProgress(100, " ");
                creationTimer.Stop();

                if (!wadInfo.sendToWii)
                {
                    FileInfo fi       = new FileInfo(wadInfo.outFile);
                    double   fileSize = Math.Round(fi.Length * 0.0009765625 * 0.0009765625, 2);

                    infoBox(string.Format("Successfully created custom channel!\nTime elapsed: {0} ms\nFilesize: {1} MB\nApprox. Blocks: {2}", creationTimer.ElapsedMilliseconds, fileSize, sourceWad.NandBlocks));
                }
                else
                {
                    wadInfo.sendWadReady = true;
                }

                wadCreationInfo         = wadInfo;
                wadCreationInfo.success = true;
            }
            catch (Exception ex)
            {
                wadCreationInfo.sendWadReady = false;
                creationTimer.Stop();

                enableControls();
                errorBox(ex.Message);
            }
        }
        void bwCreateWad_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bwCreateWad = sender as BackgroundWorker;
            Stopwatch creationTimer = new Stopwatch();
            creationTimer.Start();

            try
            {
                WadCreationInfo wadInfo = (WadCreationInfo)e.Argument;

                disableControls();

                //Check Startup IOS
                if (wadInfo.startupIos < 0 || wadInfo.startupIos > 255)
                    throw new Exception("Startup IOS must be between 0 and 255!");

                wadInfo.success = false;
                wadInfo.sendWadReady = false;
                wadCreationInfo = wadInfo;

                //Make TPLs transparent
                makeBannerTplsTransparent();
                makeIconTplsTransparent();

                //Pack icon.bin
                bwCreateWad.ReportProgress(0, "Packing icon.bin...");
                if (string.IsNullOrEmpty(replacedIcon))
                {
                    iconBin.AddHeaderImd5();
                    iconBin.Lz77Compress = wadInfo.lz77;

                    for (int i = 0; i < sourceWad.BannerApp.NumOfNodes; i++)
                        if (sourceWad.BannerApp.StringTable[i].ToLower() == "icon.bin")
                        { sourceWad.BannerApp.ReplaceFile(i, iconBin.ToByteArray()); break; }
                }
                else
                {
                    newIconBin.AddHeaderImd5();
                    newIconBin.Lz77Compress = wadInfo.lz77;

                    for (int i = 0; i < sourceWad.BannerApp.NumOfNodes; i++)
                        if (sourceWad.BannerApp.StringTable[i].ToLower() == "icon.bin")
                        { sourceWad.BannerApp.ReplaceFile(i, newIconBin.ToByteArray()); break; }
                }

                //Pack banner.bin
                bwCreateWad.ReportProgress(20, "Packing banner.bin...");
                if (string.IsNullOrEmpty(replacedBanner))
                {
                    bannerBin.AddHeaderImd5();
                    bannerBin.Lz77Compress = wadInfo.lz77;

                    for (int i = 0; i < sourceWad.BannerApp.NumOfNodes; i++)
                        if (sourceWad.BannerApp.StringTable[i].ToLower() == "banner.bin")
                        { sourceWad.BannerApp.ReplaceFile(i, bannerBin.ToByteArray()); break; }
                }
                else
                {
                    newBannerBin.AddHeaderImd5();
                    bannerBin.Lz77Compress = wadInfo.lz77;

                    for (int i = 0; i < sourceWad.BannerApp.NumOfNodes; i++)
                        if (sourceWad.BannerApp.StringTable[i].ToLower() == "banner.bin")
                        { sourceWad.BannerApp.ReplaceFile(i, newBannerBin.ToByteArray()); break; }
                }

                //Pack sound.bin
                bwCreateWad.ReportProgress(40, "Packing sound.bin...");
                if (!string.IsNullOrEmpty(replacedSound) || !string.IsNullOrEmpty(wadInfo.sound))
                {
                    for (int i = 0; i < sourceWad.BannerApp.NumOfNodes; i++)
                        if (sourceWad.BannerApp.StringTable[i].ToLower() == "sound.bin")
                        { sourceWad.BannerApp.ReplaceFile(i, newSoundBin); break; }
                }

                //Insert new dol
                if (!string.IsNullOrEmpty(wadInfo.dol))
                {
                    bwCreateWad.ReportProgress(50, "Inserting DOL...");
                    sourceWad.RemoveAllContents();

                    if (wadInfo.nandLoader == WadCreationInfo.NandLoader.comex)
                    {
                        sourceWad.AddContent(Properties.Resources.comex, 1, 1, ContentType.Normal);

                        if (wadInfo.dol.StartsWith("Simple Forwarder:"))
                            sourceWad.AddContent(createForwarderSimple(), 2, 2, ContentType.Normal);
                        else if (wadInfo.dol.StartsWith("Complex Forwarder"))
                        {
                            bwCreateWad.ReportProgress(55, "Compiling Forwarder...");
                            sourceWad.AddContent(createForwarderComplex(), 2, 2, ContentType.Normal);
                        }
                        else
                            sourceWad.AddContent(newDol, 2, 2, ContentType.Normal);

                        sourceWad.BootIndex = 1;
                    }
                    else
                    {
                        sourceWad.AddContent(Properties.Resources.Waninkoko, 2, 2, ContentType.Normal);

                        if (wadInfo.dol.StartsWith("Simple Forwarder:"))
                            sourceWad.AddContent(createForwarderSimple(), 1, 1, ContentType.Normal);
                        else if (wadInfo.dol.StartsWith("Complex Forwarder"))
                        {
                            bwCreateWad.ReportProgress(55, "Compiling Forwarder...");
                            sourceWad.AddContent(createForwarderComplex(), 1, 1, ContentType.Normal);
                        }
                        else
                            sourceWad.AddContent(newDol, 1, 1, ContentType.Normal);

                        sourceWad.BootIndex = 2;
                    }
                }

                //Change channel information
                for (int i = 0; i < wadInfo.titles.Length; i++)
                    if (string.IsNullOrEmpty(wadInfo.titles[i]))
                        wadInfo.titles[i] = wadInfo.allLangTitle;

                bwCreateWad.ReportProgress(75, "Updating Channel Information...");
                sourceWad.ChangeStartupIOS(wadInfo.startupIos);
                sourceWad.ChangeChannelTitles(wadInfo.titles);
                if (!string.IsNullOrEmpty(wadInfo.titleId))
                    sourceWad.ChangeTitleID(LowerTitleID.Channel, wadInfo.titleId);

                sourceWad.FakeSign = true;
                sourceWad.ChangeTitleKey("GottaGetSomeBeer");

                //Pack WAD
                bwCreateWad.ReportProgress(80, "Packing WAD...");
                if (!wadInfo.sendToWii) sourceWad.Save(wadInfo.outFile);
                else wadInfo.wadFile = sourceWad.ToByteArray();

                bwCreateWad.ReportProgress(100, " ");
                creationTimer.Stop();

                if (!wadInfo.sendToWii)
                {
                    FileInfo fi = new FileInfo(wadInfo.outFile);
                    double fileSize = Math.Round(fi.Length * 0.0009765625 * 0.0009765625, 2);

                    infoBox(string.Format("Successfully created custom channel!\nTime elapsed: {0} ms\nFilesize: {1} MB\nApprox. Blocks: {2}", creationTimer.ElapsedMilliseconds, fileSize, sourceWad.NandBlocks));
                }
                else wadInfo.sendWadReady = true;

                wadCreationInfo = wadInfo;
                wadCreationInfo.success = true;
            }
            catch (Exception ex)
            {
                wadCreationInfo.sendWadReady = false;
                creationTimer.Stop();

                enableControls();
                errorBox(ex.Message);
            }
        }