Example #1
0
        private void SaveFile(string destination)
        {
            try
            {
                int[]  sizes      = new int[3];
                byte[] u8         = Wii.U8.PackU8(TempPath, out sizes[0], out sizes[1], out sizes[2]);
                bool   reallydoit = true;

                if (cbLz77.Checked == true && cbLz77.Enabled == true)
                {
                    u8 = Wii.Lz77.Compress(u8);
                }

                if (rbIMD5.Checked == true)
                {
                    u8 = Wii.U8.AddHeaderIMD5(u8);
                }
                else if (rbIMET.Checked == true)
                {
                    ChannelNameBox.ChannelNameDialog cnd = new ChannelNameBox.ChannelNameDialog();
                    cnd.Titles        = TempChannelTitles;
                    cnd.FormCaption   = "Enter Channel Titles";
                    cnd.btnCancelText = "Cancel";

                    if (cnd.ShowDialog() == DialogResult.OK)
                    {
                        string[] titles = cnd.Titles;
                        u8 = Wii.U8.AddHeaderIMET(u8, titles, sizes);
                    }
                    else
                    {
                        reallydoit = false;
                    }
                }

                if (reallydoit == true)
                {
                    Wii.Tools.SaveFileFromByteArray(u8, destination);
                    InfoBox(string.Format("Successfully packed U8 archive to:\n{0}", destination));
                }
            }
            catch (Exception ex) { ErrorBox(ex.Message); }
        }
Example #2
0
        private void btnUnPack_Click(object sender, EventArgs e)
        {
            if (rbPack.Checked == true)
            {
                if (Directory.Exists(tbFolder.Text))
                {
                    bool overwrite = true;

                    if (File.Exists(tbFile.Text))
                    {
                        if (MessageBox.Show("The file already exists, do you want to overwrite?", "Overwrite?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            overwrite = false;
                        }
                    }

                    if (overwrite == true)
                    {
                        bool compress = cbCompress.Checked;
                        int  header   = 0; //No Header

                        if (cmbHeader.SelectedIndex == 1)
                        {
                            header = 2;                               //IMET
                        }
                        else if (cmbHeader.SelectedIndex == 0)
                        {
                            header = 1;                                    //IMD5
                        }
                        try
                        {
                            int[] sizes      = new int[3];
                            bool  reallydoit = true;

                            byte[] u8 = Wii.U8.PackU8(tbFolder.Text, out sizes[0], out sizes[1], out sizes[2]);
                            if (compress == true)
                            {
                                u8 = Wii.Lz77.Compress(u8);
                            }

                            if (header == 1)
                            {
                                u8 = Wii.U8.AddHeaderIMD5(u8);
                            }
                            else if (header == 2)
                            {
                                ChannelNameBox.ChannelNameDialog cnd = new ChannelNameBox.ChannelNameDialog();
                                cnd.btnCancelText = "Cancel";
                                cnd.FormCaption   = "Enter Channel Titles";

                                if (cnd.ShowDialog() == DialogResult.OK)
                                {
                                    string[] titles = cnd.Titles;
                                    u8 = Wii.U8.AddHeaderIMET(u8, titles, sizes);
                                }
                                else
                                {
                                    reallydoit = false;
                                }
                            }

                            if (reallydoit == true)
                            {
                                Wii.Tools.SaveFileFromByteArray(u8, tbFile.Text);
                                if (header == 2 && (sizes[0] == 0 || sizes[1] == 0 || sizes[2] == 0))
                                {
                                    MessageBox.Show("Successfully packed U8 file\nHowever, note that this is no valid 00000000.app!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                else
                                {
                                    MessageBox.Show("Successfully packed U8 file", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                            }
                        }
                        catch (Exception ex) { ErrorBox(ex.Message); }
                    }
                }
                else
                {
                    ErrorBox("The directory doesn't exist");
                }
            }
            else
            {
                string u8file   = tbFolder.Text;
                string u8folder = tbFile.Text; //I know this is confusing :P

                if (File.Exists(u8file))
                {
                    if (!Directory.Exists(u8folder) || Directory.GetFiles(u8folder).Length < 1)
                    {
                        if (!Directory.Exists(u8folder))
                        {
                            Directory.CreateDirectory(u8folder);
                        }

                        try
                        {
                            Wii.U8.UnpackU8(u8file, u8folder);
                            MessageBox.Show("Successfully unpacked U8", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        catch (Exception ex) { ErrorBox(ex.Message); }
                    }
                    else
                    {
                        ErrorBox("The directory already exists or is not empty.\nPlease choose an empty folder");
                    }
                }
                else
                {
                    ErrorBox("The U8 file doesn't exist");
                }
            }
        }