Exemple #1
0
        public static COMTypes.IStream LoadCOMStream(string file)
        {
            COMTypes.IStream newStream;
            var hres = ISOFormatter.SHCreateStreamOnFile(file, STGM_SHARE_DENY_WRITE, out newStream);

            if (hres != 0 || newStream == null)
            {
                throw new COMException("can't open " + file + " as IStream", unchecked ((int)hres));
            }
            return(newStream);
        }
Exemple #2
0
        public void CreateISO()
        {
            Extraction.WriteResource(Resources.BIOS, Directories.TempPath + "Files\\BIOS.com");
            _repository.BootableImageFile = Directories.TempPath + "Files\\BIOS.com";
            Application.DoEvents();
            OnPropertyChanged("0|Enumerating files...");
            var directory = new DirectoryInfo(_path);
            var files     = directory.GetFiles("*", SearchOption.AllDirectories);

            var filtered = files.Select(f => f)
                           .Where(f => (f.Attributes & FileAttributes.Directory) != FileAttributes.Directory);

            foreach (var file in filtered)
            {
                _repository.AddNewFile(file.FullName);
            }

            IFileSystemImageResult imageResult = null;

            COMTypes.IStream imagestream = null;
            try
            {
                var ifsi = InitRepository();
                Application.DoEvents();
                ifsi.CaptureDirectory = _path;
                imageResult           = ifsi.CreateResultImage();

                if (imageResult == null)
                {
                }

                formatter = new ISOFormatter(_output);


                DiscFormat2Data_Events ev = formatter;
                // if (_ckUseUIReport.Checked)
                ev.Update += FormattingEvent;

                imagestream = formatter.CreateImageStream(imageResult);
                IDiscFormat2Data idf = formatter;

                try
                {
                    idf.Write(imagestream);
                }
                catch (ApplicationException)
                {
                    throw;
                }
                catch (IOException)
                {
                    //WaitForSelection(_output);
                    //if (_backgroundISOWorker.CancellationPending)
                    //    throw;
                    idf.Write(imagestream);
                }
                catch (COMException ex)
                {
                    if (ex.ErrorCode == -2147024864)
                    {
                        //WaitForSelection(_output);
                        //if (_backgroundISOWorker.CancellationPending)
                        //    throw;
                        idf.Write(imagestream);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            catch (COMException ex)
            {
                //Console.Beep();
                //if (ex.ErrorCode == -1062555360)
                //{
                //    _lblUpdate.Text = "On UI Thread: Media size could be too small for the amount of data";
                //}
                //else
                //    _lblUpdate.Text = "On UI Thread: " + ex.Message;
                if (ex.ErrorCode != -2147024864 && File.Exists(_output))
                {
                    File.Delete(_output);
                }
            }
            catch (Exception ex)
            {
                //if (!this.IsDisposed)
                //{
                //    if (_repository.Cancel)
                //        _lblUpdate.Text = "Canceled on UI thread";
                //    else
                //    {
                //        Console.Beep();
                //        _lblUpdate.Text = "Failed on UI thread: " + ex.Message;
                //    }
                //}
                if (!(ex is IOException) && File.Exists(_output))
                {
                    File.Delete(_output);
                }
            }
            finally
            {
                if (imagestream != null)
                {
                    Marshal.FinalReleaseComObject(imagestream);
                    imagestream = null;
                }
                if (_repository.Cancel && !string.IsNullOrEmpty(_output))
                {
                    File.Delete(_output);
                }
                //else if (!_ckWorker.Checked)
                //    _lblFileImage.Text = _output;
                //if (!_ckWorker.Checked)
                //    RestoreUI(formatter);
                FileHandling.DeleteFile(Directories.TempPath + "Files\\BIOS.com");
            }
        }