Example #1
0
        private void btnExtractPack_Click(object sender, EventArgs e) //Extract Pack button
        {
            OpenFileDialog oFile = new OpenFileDialog();

            oFile.Filter = "PACK File (*.pack *.sarc *.ssarc *.rarc *.sgenvb *.sbfarc *.sblarc *.sbactorpack)|*.pack; *.sarc; *.ssarc; *.rarc; *.sgenvb; *.sbfarc; *.sblarc; *.sbactorpack|All Files|*.*";
            if (tbxFolderRoot.Text != "")
            {
                oFile.InitialDirectory = tbxFolderRoot.Text;
            }
            if (oFile.ShowDialog() == DialogResult.Cancel)
            {
                goto toss;
            }

            String oFolderName = Path.GetFileNameWithoutExtension(oFile.FileName);
            String oFolderPath = Path.GetDirectoryName(oFile.FileName) + "\\" + oFolderName;

            // if the output folder exists, prompt user if they want to extract anyway
            if (Directory.Exists(oFolderPath))
            {
                if (MessageBox.Show(oFolderName + " already exists!" + "\n\n" + "Proceed anyway?", "Overwrite?", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    goto xml;
                }
            }

            //SARC
            lblProcessStatus.Visible = true;
            bool boolAutoDecode  = false;
            bool boolReplaceFile = false;

            if (cbxAutoDecode.Checked) //Auto Yaz0 decoding
            {
                boolAutoDecode = true;
                if (cbxReplaceDecodedFile.Checked) //Replace File
                {
                    boolReplaceFile = true;
                }
            }
            else //Default, without any checkboxes
            {
                if (PACK.IsYaz0File(oFile.FileName))
                {
                    if (MessageBox.Show("This file is Yaz0 encoded!" + "\n\n" + "Want to decode it and attempt to extract?", "Decode and Extact?", MessageBoxButtons.YesNo) != DialogResult.No)
                    {
                        boolAutoDecode = true; //Auto decode just this once since we prompted
                    }
                    else
                    {
                        goto toss; //User clicked no
                    }
                }
            }
            if (!PACK.Extract(oFile.FileName, oFolderPath, boolAutoDecode, boolReplaceFile)) //Extraction
            {
                MessageBox.Show("Extraction error:" + "\n\n" + PACK.lerror);
                goto toss;
            }
            else
            {
                System.Diagnostics.Process.Start(oFolderPath);
            }

            //XML
xml:
            if (cbxWriteXml.Checked)
            {
                if (File.Exists(oFolderPath + ".xml"))
                {
                    if (MessageBox.Show(oFolderName + ".xml already exists!" + "\n\n" + "Proceed anyway?", "Overwrite?", MessageBoxButtons.YesNo) == DialogResult.No)
                    {
                        goto toss;
                    }
                }
                if (!XMLWriter.SaveXml(oFile.FileName, (oFolderPath + ".xml")))
                {
                    MessageBox.Show("XML file failed to write by unknown reasons");
                }
            }

toss:
            oFile.Dispose();
            GC.Collect();
            lblProcessStatus.Visible = false;
        }