//Opens the Preview window private void OnItemMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { var clickedItem = TryGetClickedItem(treeViewModFiles, e); if (clickedItem == null) { return; } PackedFile packedFile = modList[listViewMods.SelectedIndex].PackFile.Files.Find(f => f.Name.Contains(clickedItem.Header.ToString())); if (packedFile == null) { return; } if (packedFile.Name.EndsWith(".png") || packedFile.Name.EndsWith(".dds")) { new ImagePreview(packedFile).Show(); } else if (TextPreview.SUPPORTED_FORMATS.Contains(Path.GetExtension(packedFile.Name))) { new TextPreview(packedFile).Show(); } TreeViewItem TryGetClickedItem(TreeView treeView, System.Windows.Input.MouseButtonEventArgs _e) { var hit = _e.OriginalSource as DependencyObject; while (hit != null && !(hit is TreeViewItem)) { hit = VisualTreeHelper.GetParent(hit); } return(hit as TreeViewItem); } }
/* * Notify single pack file having been loaded. */ private void OnPackedFileLoaded(PackedFile packed) { if (this.PackedFileLoaded != null) { this.PackedFileLoaded(packed); } }
public ImagePreview(PackedFile packedFile) { InitializeComponent(); if (packedFile.Name.EndsWith(".dds")) { var image = DDS.LoadImage(packedFile.Data); Image1.Source = Convert(image); } else if (packedFile.Name.EndsWith(".png")) { Image1.Source = Convert(packedFile.Data); } Title = "Preview: " + packedFile.FullPath; }
public TextPreview(PackedFile packedFile) { InitializeComponent(); if (packedFile.Name.EndsWith(".xml") || packedFile.Name.EndsWith(".environment") || packedFile.Name.EndsWith(".wsmodel") || packedFile.Name.EndsWith(".material") || packedFile.Name.EndsWith(".variantmeshdefinition")) { TextBox1.SyntaxHighlighting = ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance.GetDefinitionByExtension(".xml"); TextBox1.ShowLineNumbers = true; } else if (packedFile.Name.EndsWith(".lua")) { TextBox1.SyntaxHighlighting = ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance.GetDefinitionByExtension(".c"); TextBox1.ShowLineNumbers = true; } TextBox1.Text = Encoding.Default.GetString(packedFile.Data); Title = "Preview: " + packedFile.FullPath; }
/* * Decode pack file at the given path. */ public PackFile Open(string packFullPath) { PackFile file; long sizes = 0; using (var reader = new BinaryReader(new FileStream(packFullPath, FileMode.Open), Encoding.ASCII)) { PFHeader header = ReadHeader(reader); file = new PackFile(packFullPath, header); OnHeaderLoaded(header); long offset = file.Header.DataStart; for (int i = 0; i < file.Header.FileCount; i++) { uint size = reader.ReadUInt32(); sizes += size; if (file.Header.HasAdditionalInfo) { header.AdditionalInfo = reader.ReadInt64(); } if (file.Header.PackIdentifier == "PFH5") { reader.ReadByte(); } string packedFileName = IOFunctions.ReadZeroTerminatedAscii(reader); // this is easier because we can use the Path methods // under both Windows and Unix packedFileName = packedFileName.Replace('\\', Path.DirectorySeparatorChar); PackedFile packed = new PackedFile(file.Filepath, packedFileName, offset, size); file.Add(packed); offset += size; this.OnPackedFileLoaded(packed); } } this.OnFinishedLoading(file); file.IsModified = false; return(file); }