private void openButton_Click(object sender, EventArgs e) { openButton.Enabled = false; // Popup Open File dialog openFileDialog.Title = "Open Archive File"; openFileDialog.Filter = "Union File (*.uni)|*.uni|" + "CWAB Animation Package (*.cwab)|*.cwab|" + "MAAB Animation Package (*.maab)|*.maab|" + "Pak File (*.pak)|*.pak|" + "CPack File (*.cpk)|*.cpk|" + "LNK4 File (*.lnk4)|*.lnk4|" + "Sega AFS (*.afs)|*.afs|" + "All Files|*.*"; openFileDialog.Multiselect = false; DialogResult FileResult = openFileDialog.ShowDialog(); // OK button was pressed. if (FileResult == DialogResult.OK) { string fileName = openFileDialog.FileName; try { string fileNameBase; { // Get file name base int fileNameStart = fileName.LastIndexOf('\\') + 1; int fileNameEnd = fileName.LastIndexOf('.'); if (fileNameEnd == -1) { fileNameEnd = fileName.Length; } fileNameBase = fileName.Substring(fileNameStart, fileNameEnd - fileNameStart); } archiveFile = new FileStream(fileName, FileMode.Open, FileAccess.Read); if (archiveFile != null && archiveFile.CanRead) { // Determin file type uint identifier = StreamUtility.ReadUIntFromStream(archiveFile, 0); string fileType = StreamUtility.GetFileExtension(identifier); // Initiate parser based on file type switch (fileType) { case "uni": // Union 2 Archive archive = new Uni2Container(archiveFile); break; case "cwab": // CWAB Animation Package archive = new CwabContainer(archiveFile); break; case "maab": // MAAB Animation Package archive = new MaabContainer(archiveFile); break; case "pak": // Time Leap Pak Archive archive = new PakContainer(archiveFile); break; case "axcs": // AXCS Archive container archive = new AxcsContainer(archiveFile); break; case "cpk": // CRI Archive container archive = new CriPack_Container(archiveFile); break; case "lnk4": // LNK4 Archive container archive = new Lnk4Container(archiveFile); break; case "afs": // AFS Archive container archive = new AfsContainer(archiveFile); break; default: throw new FileLoadException("Unknown file type", fileName); } archive.ParseFileTable(); // Get file list foreach (FileItem file in archive.FileTable) { fileList.Items.Add(file, true); } // Update screen prompts archiveType.Text = archive.ContainerType; numFiles.Text = Convert.ToString(archive.FileTable.Count); SetButtonsAfterOpenFile(); } else { if (archiveFile == null || !archiveFile.CanRead) { MessageBox.Show(fileName + ": File is not readable!?", "Error", MessageBoxButtons.OK); } if (archiveFile != null) { archiveFile.Close(); } ResetButtonStates(); } } catch (Exception exp) { MessageBox.Show("An error occurred while attempting to load the file. The error is: " + System.Environment.NewLine + exp.ToString() + System.Environment.NewLine); ResetButtonStates(); } } // Cancel button was pressed. else { ResetButtonStates(); return; } }