Example #1
0
        private void btnBuild_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog cusFolder = new FolderBrowserDialog();
            OpenFileDialog      oriFile   = new OpenFileDialog();
            SaveFileDialog      sFile     = new SaveFileDialog();

            //Verify files and directories
            if (tbxOriFile.Text == "")
            {
                MessageBox.Show("Original file path missing!");
                goto toss;
            }
            if (tbxCustom.Text == "")
            {
                MessageBox.Show("Custom folder path missing!");
                goto toss;
            }
            if (FileOrDirectoryExists(tbxOriFile.Text))
            {
                oriFile.FileName = tbxOriFile.Text;
            }
            else
            {
                MessageBox.Show("Original File has an invalid path:\n\n" + tbxOriFile.Text);
                goto toss;
            }
            if (FileOrDirectoryExists(tbxCustom.Text))
            {
                cusFolder.SelectedPath = tbxCustom.Text;
            }
            else
            {
                MessageBox.Show("Custom Folder has an invalid path:\n\n" + tbxCustom.Text);
                goto toss;
            }

            int oriNodeCount = PACK.GetFileNodeCount(oriFile.FileName);

            string[] cusFolderFiles = System.IO.Directory.GetFiles(cusFolder.SelectedPath == "" ? System.Environment.CurrentDirectory : cusFolder.SelectedPath, "*.*", System.IO.SearchOption.AllDirectories);
            if (oriNodeCount != cusFolderFiles.Length)
            {
                MessageBox.Show("Number of nodes do not match!\n\n" + "Original file nodes: " + oriNodeCount + "\nCustom Folder nodes: " + cusFolderFiles.Length);
                goto toss;
            }
            int numFiles = Directory.GetFiles(cusFolder.SelectedPath, "*", SearchOption.AllDirectories).Length;

            //Save file path
            sFile.Filter             = "PACK|*.pack|SARC|*.sarc|SSARC|*.ssarc|RARC|*.rarc|SGENVB|*.sgenvb|SBFARC|*.sbfarc|SBLARC|*.sblarc|SBACTORPACK|*sbactorpack|All Files|*.*";
            sFile.InitialDirectory   = cusFolder.SelectedPath.Remove(cusFolder.SelectedPath.LastIndexOf("\\")); //Previous folder, as selected is to build outside of it.
            sFile.FileName           = System.IO.Path.GetFileName(cusFolder.SelectedPath);
            lblProcessStatus.Visible = true;
            if (sFile.ShowDialog() == DialogResult.Cancel)
            {
                goto toss;
            }

            if (!PACK.CompareAndBuild(oriFile.FileName, cusFolder.SelectedPath, sFile.FileName, true))
            {
                MessageBox.Show("Failed to build!" + "\n\n" + PACK.lerror);
            }
            else
            {
                MessageBox.Show("Done!\n\n" + sFile.FileName);
            }

toss:
            cusFolder.Dispose();
            oriFile.Dispose();
            sFile.Dispose();
            GC.Collect();
            lblProcessStatus.Visible = false;
        }