public TexturePreview(TexTrend handler) { //verify texture integrity if (handler.Images == null) { MessageBox.Show(@"Invalid texture; no images were defined whilst parsing."); Close(); return; } //assign global TextureHandler = handler; //designer stuff InitializeComponent(); }
private void TextureOpen() { try { if (lstMain.SelectedItems.Count > 0) { //grab file name var fileName = lstMain.SelectedItems[0].SubItems[2].Text; var fileId = Convert.ToInt32(lstMain.SelectedItems[0].SubItems[1].Text); //grab raw file bytes var buffer = ExtractFile(fileId); //verify extracted bytes if (buffer != null) { //texture handler var handler = new TexTrend(buffer, fileName); //display texture previewer var frm = new TexturePreview(handler); if (!frm.IsDisposed) { frm.ShowDialog(); } } else { MessageBox.Show(@"Extracted bytes were null; texture previewer cannot be opened."); } } } catch (Exception ex) { MessageBox.Show($"Error whilst loading in-memory texture:\n\n{ex}"); } }
private void PreviewFile() { switch (Path.GetExtension(_listviewFileSelected).ToLower()) { //executables case ".exe": case ".dll": case ".bat": case ".com": case ".cmd": case ".sh": case ".so": var ask = MessageBox.Show( @"Are you sure? You're about to open an executable file which will run code on your PC; this may have unforeseen adverse effects.", @"Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (ask == DialogResult.Yes) { if (!string.IsNullOrEmpty(_listviewFileSelected)) { var dir = Path.GetDirectoryName(Path.GetFullPath(_listviewFileSelected)); var p = new Process { StartInfo = { FileName = _listviewFileSelected, CreateNoWindow = false, WorkingDirectory = !string.IsNullOrEmpty(dir) ? dir : @"" } }; p.Start(); } } break; //code files case ".txt": case ".csv": case ".sub": case ".bms": case ".sf": case ".scp": case ".cfg": case ".ini": case ".inf": case ".vdf": case ".gip": case ".gix": case ".giz": case ".gin": case ".ats": new CodePreview(_listviewFileSelected).ShowDialog(); break; //archive files case ".dat": new DatExtractor(_listviewFileSelected).ShowDialog(); break; case ".hdr": MessageBox.Show(@"Please open the *.DAT instead of the *.HDR"); break; case ".pac": case ".pak": case ".fpk": new PakExtractor(_listviewFileSelected).ShowDialog(); break; //image files case ".tex": case ".dds": case ".png": case ".bmp": case ".raw": case ".tga": case ".jpg": case ".jpeg": case ".gif": case ".giff": case ".tif": case ".tiff": //new texture handler var texHandler = new TexTrend(_listviewFileSelected); //run preview window new TexturePreview(texHandler).ShowDialog(); break; //anything else is unsupported default: MessageBox.Show( $@"*{Path.GetExtension(_listviewFileSelected)?.ToLower()} files are not currently supported"); break; } }
private void PreviewFile() { //more validation if (lstMain.SelectedItems.Count > 0) { //parse out file extension from list view var fileName = lstMain.SelectedItems[0].SubItems[2].Text; var fileId = Convert.ToInt32(lstMain.SelectedItems[0].SubItems[1].Text); var ext = Path.GetExtension(fileName).ToLower(); //grab needed data from archive via extraction var buffer = ExtractFile(fileId); //validation if (buffer != null) { switch (ext) { //executables case ".exe": case ".dll": case ".bat": case ".com": case ".cmd": case ".sh": case ".so": MessageBox.Show( $"You cannot run executable files of type '*{ext}' from within an archive, as this could lead to arbitrary code execution.", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); break; //code files case ".txt": case ".csv": case ".sub": case ".bms": case ".sf": case ".scp": case ".cfg": case ".ini": case ".inf": case ".vdf": case ".gip": case ".gix": case ".giz": case ".gin": case ".ats": new CodePreview(buffer, fileName).ShowDialog(); break; //archive files case ".dat": MessageBox.Show(@"You cannot open *.DAT files from within a *.DAT file"); break; case ".hdr": MessageBox.Show(@"You cannot open *.HDR files from within a *.DAT file"); break; case ".pac": case ".pak": case ".fpk": new PakExtractor(buffer, fileName).ShowDialog(); break; //image files case ".tex": case ".dds": case ".png": case ".bmp": case ".raw": case ".tga": case ".jpg": case ".jpeg": case ".gif": case ".giff": case ".tif": case ".tiff": //new texture handler var texHandler = new TexTrend(buffer, fileName); //run preview window new TexturePreview(texHandler).ShowDialog(); break; //anything else is unsupported default: MessageBox.Show( $@"*{ext} files are not currently supported"); break; } } else { MessageBox.Show(@"Null extracted data; could not open file."); } } }