Exemplo n.º 1
0
        public void WriteToFile(string FileName, bool Overwrite = true)
        {
            IFileSystemImageResult Res = ISO.CreateResultImage();
            IStream ImgStream          = (IStream)Res.ImageStream;

            if (ImgStream != null)
            {
                STATSTG Stat;
                ImgStream.Stat(out Stat, 0x1);

                if (File.Exists(FileName))
                {
                    if (Overwrite)
                    {
                        File.Delete(FileName);
                    }
                    else
                    {
                        throw new Exception("File already exists: " + FileName);
                    }
                }

                IStream OutStream;
                SHCreateStreamOnFile(FileName, 0x1001, out OutStream);

                ImgStream.CopyTo(OutStream, Stat.cbSize, IntPtr.Zero, IntPtr.Zero);
                OutStream.Commit(0);
            }
        }
Exemplo n.º 2
0
        internal void CreateISOFile(COMTypes.IStream imagestream)
        {
            if (Cancel)
            {
                return;
            }
            COMTypes.IStream newStream;
            newStream = CreateCOMStreamFromFile(OutputFileName);

            COMTypes.STATSTG stat;
#if DEBUG
            var tm = new Stopwatch();
            tm.Start();
#endif
            imagestream.Stat(out stat, 0x0);

            var inBytes  = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ulong)));
            var outBytes = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ulong)));

            try
            {
                imagestream.CopyTo(newStream, stat.cbSize, inBytes, outBytes);
                newStream.Commit(0);
            }
            catch (Exception r)
            {
                Debug.WriteLine(r.ToString());
                throw;
            }
            finally
            {
                if (newStream != null)
                {
                    Marshal.FinalReleaseComObject(newStream);
                }
                newStream = null;
                Marshal.FreeHGlobal(inBytes);
                Marshal.FreeHGlobal(outBytes);
#if DEBUG
                tm.Stop();
                Debug.WriteLine(string.Format("Time spent in CreateISOFile: {0} ms",
                                              tm.Elapsed.TotalMilliseconds.ToString("#,#")));
#endif
            }
        }