Example #1
0
        private void btnCusBrowse_Click(object sender, EventArgs e)
        {
            if (rbnCustomFile.Checked)
            {
                OpenFileDialog cusFile = new OpenFileDialog();
                cusFile.Filter = "PACK File (*.pack *.sarc *.ssarc *.rarc *.sgenvb *.sbfarc *.sblarc *.sbactorpack)|*.pack; *.sarc; *.ssarc; *.rarc; *.sgenvb; *.sbfarc; *.sblarc; *.sbactorpack|All Files|*.*";
                if (Properties.Settings.Default.RootFolder != "")
                {
                    cusFile.InitialDirectory = Properties.Settings.Default.RootFolder;
                }
                if (cusFile.ShowDialog() == DialogResult.Cancel)
                {
                    goto toss;
                }
                tbxCustom.Text = cusFile.FileName;

                dgvCusTable.Rows.Clear();
                dgvCusTable.Refresh();
verify:
                byte[] fileCheck = System.IO.File.ReadAllBytes(tbxCustom.Text);
                if (fileCheck[0] == 'Y' && fileCheck[1] == 'a' && fileCheck[2] == 'z' && fileCheck[3] == '0') // if Yaz0 encoded, ask if they want to decode it
                {
                    DialogResult diagResult = MessageBox.Show("This file is encoded!" + "\n\n" + "Do you want to decode?\nIt will create a seperate file automatically", "Yaz0 Encoded file...", MessageBoxButtons.YesNo);
                    if (diagResult == DialogResult.No)
                    {
                        tbxCustom.Text = "";
                        goto toss;
                    }
                    string outFile = Path.GetDirectoryName(cusFile.FileName) + "\\" + Path.GetFileNameWithoutExtension(cusFile.FileName) + "Decoded" + Path.GetExtension(cusFile.FileName);
                    if (!Yaz0.Decode(cusFile.FileName, outFile))
                    {
                        MessageBox.Show("Decode error:" + "\n\n" + Yaz0.lerror);
                        tbxCustom.Text = "";
                        goto toss;
                    }
                    tbxCustom.Text = outFile;
                    goto verify;
                }
                if (("" + ((char)fileCheck[0]) + ((char)fileCheck[1]) + ((char)fileCheck[2]) + ((char)fileCheck[3])) != "SARC")
                {
                    MessageBox.Show("Not a SARC archive! Missing SARC header at 0x00" + "\n" + "( Your file header is: " + ((char)fileCheck[0]) + ((char)fileCheck[1]) + ((char)fileCheck[2]) + ((char)fileCheck[3]) + " )");
                    tbxCustom.Text = "";
                    goto toss;
                }

                int      nodeCount    = PACK.GetFileNodeCount(tbxCustom.Text);
                string[] nodeTypes    = PACK.GetFileNodeType(tbxCustom.Text);
                uint[]   nodeSizes    = PACK.GetFileNodeSizes(tbxCustom.Text);
                string[] nodePaths    = PACK.GetFileNodePaths(tbxCustom.Text);
                uint[]   nodePaddings = PACK.GetFileNodePaddings(tbxCustom.Text);

                for (int i = 0; i < nodeCount; i++)
                {
                    dgvCusTable.Rows.Add();
                    dgvCusTable.Rows[i].Cells[0].Value = i + 1;
                    dgvCusTable.Rows[i].Cells[1].Value = nodeTypes[i];
                    dgvCusTable.Rows[i].Cells[2].Value = nodeSizes[i];
                    dgvCusTable.Rows[i].Cells[3].Value = nodeSizes[i].ToString("X");
                    dgvCusTable.Rows[i].Cells[4].Value = nodePaths[i];
                    dgvCusTable.Rows[i].Cells[5].Value = nodePaddings[i];
                }

toss:
                cusFile.Dispose();
                GC.Collect();
            }
            else if (rbnCustomFolder.Checked)
            {
                FolderBrowserDialog cusFolder = new FolderBrowserDialog();
                if (Properties.Settings.Default.RootFolder != "")
                {
                    cusFolder.SelectedPath = Properties.Settings.Default.RootFolder;
                }
                cusFolder.Description = "Select Custom Folder";
                if (cusFolder.ShowDialog() == DialogResult.Cancel)
                {
                    goto toss;
                }
                tbxCustom.Text = cusFolder.SelectedPath;

                dgvCusTable.Rows.Clear();
                dgvCusTable.Refresh();
                string[] cusFolderFiles = System.IO.Directory.GetFiles(cusFolder.SelectedPath == "" ? System.Environment.CurrentDirectory : cusFolder.SelectedPath, "*.*", System.IO.SearchOption.AllDirectories);
                int      nodeCount      = cusFolderFiles.Length;
                if (nodeCount > 1000)
                {
                    MessageBox.Show("Too many files (1000+)!\n\nI doubt you ment to select this folder...\n" + tbxCustom.Text + "\n\nTry again");
                    tbxCustom.Text = "";
                    goto toss;
                }
                uint[]   nodeSizes = PACK.GetFolderFileSizes(cusFolder.SelectedPath);
                string[] nodeTypes = PACK.GetFolderFileTypes(cusFolder.SelectedPath);
                string[] nodePaths = PACK.GetFolderFilePaths(cusFolder.SelectedPath);

                for (int i = 0; i < nodeCount; i++)
                {
                    dgvCusTable.Rows.Add();
                    dgvCusTable.Rows[i].Cells[0].Value = i + 1;
                    dgvCusTable.Rows[i].Cells[1].Value = nodeTypes[i];
                    dgvCusTable.Rows[i].Cells[2].Value = nodeSizes[i];
                    dgvCusTable.Rows[i].Cells[3].Value = nodeSizes[i].ToString("X");
                    dgvCusTable.Rows[i].Cells[4].Value = nodePaths[i];
                }

toss:
                cusFolder.Dispose();
                GC.Collect();
            }
        }