/// <summary> /// 提取为流格式 /// </summary> /// <param name="source">压缩源</param> /// <param name="path">关键字</param> /// <returns></returns> private Stream ExtractToStream(SevenZipArchive source, string path) { ArchiveEntry entry = source[path]; MemoryStream stream = new MemoryStream(); entry.Extract(stream); stream.Seek(0, SeekOrigin.Begin); return(stream); }
public static StreamReader ExtractToStreamReader(this ArchiveEntry archiveEntry) { var stream = new MemoryStream(); stream.Position = 0; archiveEntry.Extract(stream); var result = new StreamReader(stream); result.BaseStream.Position = 0; return(result); }
/// <summary> /// 提取为图片源格式 /// </summary> /// <param name="source">压缩源</param> /// <param name="path">关键字</param> /// <returns></returns> private ImageSource ExtractToImageSource(SevenZipArchive source, string path) { ArchiveEntry entry = source[path]; MemoryStream stream = new MemoryStream(); entry.Extract(stream); stream.Seek(0, SeekOrigin.Begin); ImageSourceConverter isc = new ImageSourceConverter(); return((ImageSource)isc.ConvertFrom(stream)); }
/// <summary> /// 提取视频格式 /// </summary> /// <param name="source"></param> /// <param name="path"></param> /// <returns></returns> private Uri ExtractToVideoSoruce(SevenZipArchive source, string path) { ArchiveEntry entry = source[path]; string cachestring = Directory.GetCurrentDirectory() + "\\Cache"; entry.Extract(cachestring); string name = System.IO.Path.Combine(cachestring, path); string parserName = System.IO.Path.Combine(cachestring, "cache_" + GetSystemDateString() + Path.GetExtension(path)); (new FileInfo(name)).MoveTo(parserName); return(new Uri(parserName)); }
private string ExtractToVideoSoruce(SevenZipArchive source, string path, string extension, string moveName) { ArchiveEntry entry = source[path]; string cachePath = Directory.GetCurrentDirectory() + "\\Cache"; if (!Directory.Exists(cachePath)) { Directory.CreateDirectory(cachePath); } string cachestring = cachePath; entry.Extract(cachestring); string name = System.IO.Path.Combine(cachestring, path); string parserName = System.IO.Path.Combine(cachestring, moveName + extension); (new FileInfo(name)).MoveTo(parserName); return("\\Cache\\" + moveName + extension); }
public static void PreviewTexture(IWin32Window owner, ArchiveEntry entry) { if (entry == null) { throw new ArgumentException("Parameter 'entry' can't be null.", nameof(entry)); } string fileName = entry.FileName; var extension = Path.GetExtension(entry.LowerPath); switch (extension) { case ".dds": case ".bmp": case ".png": case ".jpg": if ((entry as BA2TextureEntry)?.IsFormatSupported() == false) { MessageBox.Show(owner, "Unsupported DDS texture."); return; } if (!Settings.Default.BuiltInPreviewing.Contains(extension)) { goto default; } if (entry is BA2GNFEntry) { if (Settings.Default.ReplaceGNFExt) { fileName = Path.GetFileNameWithoutExtension(fileName) + ".gnf"; } goto default; } try { DDSViewer.Show(owner, entry.FileName, entry.GetDataStream()); } catch (Exception ex) { Debug.WriteLine(ex); goto default; } break; case ".txt": case ".bat": case ".xml": case ".lst": case ".psc": case ".json": if (!Settings.Default.BuiltInPreviewing.Contains(extension)) { // Don't launch .bat files, just to be safe if (extension == ".bat") { MessageBox.Show(owner, "Can only preview batch scripts with built-in text viewer, you can enable it in Options.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } goto default; } new TextViewer(entry).Show(owner); break; default: string dest = Program.CreateTempDirectory(); string file = Path.Combine(dest, fileName); entry.Extract(dest, false, fileName); try { Process.Start(new ProcessStartInfo(file)); } catch (Win32Exception ex) { if (ex.NativeErrorCode == (int)SystemErrorCodes.ERROR_NO_ASSOCIATION) { ShellExecute.OpenWith(file); } else if (ex.NativeErrorCode != (int)SystemErrorCodes.ERROR_CANCELLED) { MessageBox.Show(owner, ex.Message, "Preview Error"); } } break; } }