static Archive OpenArchive(string file) { Archive archive = null; string extension = Path.GetExtension(file); switch (extension.ToLower()) { case ".bsa": case ".dat": archive = new SharpBSABA2.BSAUtil.BSA(file, _arguments.Encoding); break; case ".ba2": archive = new SharpBSABA2.BA2Util.BA2(file, _arguments.Encoding); break; default: throw new Exception($"Unrecognized archive file type ({extension})."); } archive.MatchLastWriteTime = _arguments.MatchTimeChanged; archive.Files.Sort((a, b) => string.CompareOrdinal(a.LowerPath, b.LowerPath)); return(archive); }
static Archive OpenArchive(string file, bool ati) { Archive archive = null; try { string extension = Path.GetExtension(file); switch (extension.ToLower()) { case ".bsa": case ".dat": archive = new SharpBSABA2.BSAUtil.BSA(file); break; case ".ba2": archive = new SharpBSABA2.BA2Util.BA2(file) { UseATIFourCC = ati }; break; default: throw new Exception($"Unrecognized archive file type ({extension})."); } archive.Files.Sort((a, b) => string.CompareOrdinal(a.LowerPath, b.LowerPath)); return(archive); } catch (Exception ex) { Console.WriteLine("An error occured:"); Console.WriteLine(ex.Message); return(null); } }
/// <summary> /// Opens the given archive, adding it to the TreeView and making it browsable. /// </summary> /// <param name="path">The archive file path.</param> /// <param name="addToRecentFiles">True if archive should be added to recent files list.</param> public void OpenArchive(string path, bool addToRecentFiles = false) { // Check if archive is already opened foreach (ArchiveNode node in tvFolders.Nodes) { if (node.Archive.FullPath.ToLower() == path.ToLower()) { MessageBox.Show(this, "This archive is already opened."); return; } } Archive archive = null; try { string extension = Path.GetExtension(path); // ToDo: Read file header to find archive type, not just extension switch (extension.ToLower()) { case ".bsa": case ".dat": if (SharpBSABA2.BSAUtil.BSA.IsSupportedVersion(path) == false) { if (MessageBox.Show(this, "This BSA archive has an unknown version number.\n" + "Attempt to open anyway?", "Warning", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } } archive = new SharpBSABA2.BSAUtil.BSA(path); break; case ".ba2": archive = new SharpBSABA2.BA2Util.BA2(path) { UseATIFourCC = Settings.Default.UseATIFourCC }; break; default: throw new Exception($"Unrecognized archive file type ({extension})."); } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } var newNode = new ArchiveNode( Path.GetFileNameWithoutExtension(path) + this.DetectGame(path), archive); var newMenuItem = new MenuItem("Close"); newMenuItem.Tag = newNode; newMenuItem.Click += delegate(object sender, EventArgs e) { this.CloseArchive(newNode); if (tvFolders.Nodes.Count == 0) { this.ClearList(); } else { this.DoSearch(); } }; var cm = new ContextMenu(new MenuItem[] { newMenuItem }); newNode.ContextMenu = cm; newNode.Files = archive.Files.ToArray(); newNode.Nodes.Add("empty"); tvFolders.Nodes.Add(newNode); if (newNode.IsExpanded) { newNode.Collapse(); } btnExtract.Enabled = true; btnExtractAll.Enabled = true; btnPreview.Enabled = true; if (addToRecentFiles) { this.AddToRecentFiles(path); } tvFolders.SelectedNode = newNode; }