private static void ExtractFile(string tempDir, IAppxFile appxFile) { var fileName = appxFile.GetName(); var dest = Path.Combine(tempDir, fileName); Directory.CreateDirectory(Path.GetDirectoryName(dest)); var fileStream = appxFile.GetStream(); System.Runtime.InteropServices.ComTypes.STATSTG stats; fileStream.Stat(out stats, 0); using (var wrappedStream = new StreamWrapper(File.OpenWrite(dest))) { var read = Marshal.AllocHGlobal(sizeof(long)); var written = Marshal.AllocHGlobal(sizeof(long)); fileStream.CopyTo(wrappedStream, stats.cbSize, read, written); Debug.Assert(Marshal.ReadInt64(read) == Marshal.ReadInt64(written)); Marshal.FreeHGlobal(read); Marshal.FreeHGlobal(written); } }
private static void ExtractFile(string tempDir, IAppxFile appxFile) { var fileName = appxFile.GetName(); var dest = Path.Combine(tempDir, fileName); Directory.CreateDirectory(Path.GetDirectoryName(dest)); var fileStream = appxFile.GetStream(); System.Runtime.InteropServices.ComTypes.STATSTG stats; fileStream.Stat(out stats, 0); using (var wrappedStream = new StreamWrapper(File.OpenWrite(dest))) { var read = Marshal.AllocHGlobal(sizeof(long)); var written = Marshal.AllocHGlobal(sizeof(long)); fileStream.CopyTo(wrappedStream, stats.cbSize, read, written); Debug.Assert(Marshal.ReadInt64(read) == Marshal.ReadInt64(written)); Marshal.FreeHGlobal(read); Marshal.FreeHGlobal(written); } }