Exemple #1
0
        /// <summary>
        /// Initialize the form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_Load(object sender, EventArgs e)
        {
            //
            // Determine the current recording devices
            //
            MsftDiscMaster2 discMaster = new MsftDiscMaster2();

            if (!discMaster.IsSupportedEnvironment)
            {
                return;
            }
            foreach (string uniqueRecorderID in discMaster)
            {
                MsftDiscRecorder2 discRecorder2 = new MsftDiscRecorder2();
                discRecorder2.InitializeDiscRecorder(uniqueRecorderID);

                devicesComboBox.Items.Add(discRecorder2);
            }
            if (devicesComboBox.Items.Count > 0)
            {
                devicesComboBox.SelectedIndex = 0;
            }

            //
            // Create the volume label based on the current date
            //
            DateTime now = DateTime.Now;

            textBoxLabel.Text = now.Year + "_" + now.Month + "_" + now.Day;

            labelStatusText.Text       = string.Empty;
            labelFormatStatusText.Text = string.Empty;

            UpdateCapacity();
        }
Exemple #2
0
        /// <summary>
        /// Initialize the form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_Load(object sender, EventArgs e)
        {
            //
            // Determine the current recording devices
            //
            MsftDiscMaster2 discMaster = null;

            try
            {
                discMaster = new MsftDiscMaster2();

                if (!discMaster.IsSupportedEnvironment)
                {
                    return;
                }
                foreach (string uniqueRecorderId in discMaster)
                {
                    var discRecorder2 = new MsftDiscRecorder2();
                    discRecorder2.InitializeDiscRecorder(uniqueRecorderId);

                    devicesComboBox.Items.Add(discRecorder2);
                }
                if (devicesComboBox.Items.Count > 0)
                {
                    devicesComboBox.SelectedIndex = 0;
                }
            }
            catch (COMException ex)
            {
                MessageBox.Show(ex.Message,
                                string.Format("Error:{0} - Please install IMAPI2", ex.ErrorCode),
                                MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            finally
            {
                if (discMaster != null)
                {
                    Marshal.ReleaseComObject(discMaster);
                }
            }


            //
            // Create the volume label based on the current date
            //
            DateTime now = DateTime.Now;

            textBoxLabel.Text = now.Year + "_" + now.Month + "_" + now.Day;

            labelStatusText.Text       = string.Empty;
            labelFormatStatusText.Text = string.Empty;

            //
            // Select no verification, by default
            //
            comboBoxVerification.SelectedIndex = 0;

            UpdateCapacity();
        }
        public List<MsftDiscRecorder2> GetRecordingDevices()
        {
            var result = new List<MsftDiscRecorder2>();

            MsftDiscMaster2 discMaster = null;
            try
            {
                discMaster = new MsftDiscMaster2();

                if (!discMaster.IsSupportedEnvironment)
                    return result;
                foreach (string uniqueRecorderId in discMaster)
                {
                    var discRecorder2 = new MsftDiscRecorder2();
                    discRecorder2.InitializeDiscRecorder(uniqueRecorderId);

                    result.Add(discRecorder2);
                }
            }
            catch (COMException ex)
            {
                MessageBox.Show(ex.Message,
                    string.Format("Error: {0} - Please install IMAPI2", ex.ErrorCode),
                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return result;
            }
            finally
            {
                if (discMaster != null)
                    Marshal.ReleaseComObject(discMaster);
            }

            return result;
        }
Exemple #4
0
        public ImageMaster()
        {
            List<DiscRecorder> recorders = new List<DiscRecorder>();
            _media = PhysicalMedia.Unknown;
            _nodes = new List<IMediaNode>();
            _mediaStates = new ReadOnlyCollection<MediaState>(new List<MediaState> { MediaState.Unknown });

            MsftDiscMaster2 discMaster = null;
            try
            {
                discMaster = new MsftDiscMaster2();

                if (!discMaster.IsSupportedEnvironment)
                    throw new NotSupportedException(
                        "Either the environment does not contain one or more optical devices or the " +
                        "execution context has no permission to access the devices.");

                foreach (string uniqueRecorderId in discMaster)
                {
                    recorders.Add(new DiscRecorder(uniqueRecorderId));
                }
                _recorders = new ReadOnlySelectableCollection<DiscRecorder>(recorders);
            }
            catch (COMException ex)
            {
                throw new NotSupportedException("IMAP2 not found on this system. It will need to be installed (ErrorCode = " + ex.ErrorCode + ").", ex);
            }
            finally
            {
                if (discMaster != null) Marshal.ReleaseComObject(discMaster);
            }
        }
Exemple #5
0
        /// <summary>
        /// Disc burning provider.
        /// </summary>
        public Disc()
        {
            // Create a DiscMaster2 object to connect to CD/DVD drives.
            _discMaster = new MsftDiscMaster2();

            // Set the recorder list.
            SetRecoderList();
        }
        private int DoBurn(string activeDiscRecorder)
        {
            int result = 0;

            var discMaster = new MsftDiscMaster2();
            var discRecorder2 = new MsftDiscRecorder2();

            discRecorder2.InitializeDiscRecorder(activeDiscRecorder);

            var trackAtOnce = new MsftDiscFormat2TrackAtOnce();
            trackAtOnce.ClientName = "";
            trackAtOnce.Recorder = discRecorder2;
            burnData.totalTracks = mediaItems.Count;
            burnData.currentTrackNumber = 0;

            // Prepare the wave file streams
            foreach (MediaFile mediaFile in mediaItems)
            {
                if (cancellationToken.IsCancellationRequested)
                    break;

                // Report back to the UI that we're preparing stream
                burnData.task = BURN_MEDIA_TASK.BURN_MEDIA_TASK_PREPARING;
                burnData.filename = mediaFile.ToString();
                burnData.currentTrackNumber++;

                burnProgress.Report(burnData);
                mediaFile.PrepareStream();
            }

            trackAtOnce.Update += trackAtOnce_Update;

            trackAtOnce.PrepareMedia();

            foreach (MediaFile mediaFile in mediaItems)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    result = -1;
                    break;
                }

                burnData.filename = mediaFile.ToString();
                var stream = mediaFile.GetTrackIStream();
                trackAtOnce.AddAudioTrack(stream);
            }

            trackAtOnce.Update -= trackAtOnce_Update;

            trackAtOnce.ReleaseMedia();

            if (ejectMedia)
                discRecorder2.EjectMedia();

            return result;
        }
Exemple #7
0
        public void BurnCD()
        {
            #region CD WRITING
            MsftDiscMaster2 discMaster = null;
            discMaster = new MsftDiscMaster2();
            String path = "D://hello2.txt";
            Console.WriteLine("Writing to the disc");
            if (!discMaster.IsSupportedEnvironment)
            {
                return;
            }
            foreach (string uniqueRecorderId in discMaster)
            {
                var discRecorder2 = new MsftDiscRecorder2();
                discRecorder2.InitializeDiscRecorder(uniqueRecorderId);
                MsftDiscFormat2Data datawriter = new MsftDiscFormat2Data();
                datawriter.Recorder   = discRecorder2;
                datawriter.ClientName = "IMAPIv2 TEST";
                MsftFileSystemImage FSI = new MsftFileSystemImage();
                try
                {
                    if (!datawriter.MediaHeuristicallyBlank)
                    {
                        FSI.MultisessionInterfaces = datawriter.MultisessionInterfaces;
                        FSI.ImportFileSystem();
                    }
                }
                catch (Exception)
                {
                    FSI.ChooseImageDefaults(discRecorder2);
                    Console.WriteLine("Multisession is not supported on this disk!");
                }
                try
                {
                    FSI.Root.AddTree(path, false);
                    IFileSystemImageResult Result = FSI.CreateResultImage();
                    var stream = Result.ImageStream;
                    Console.WriteLine("\nWriting to disc now!!");
                    datawriter.Write(stream);
                    Console.WriteLine("\nWrite Process completed!");
                }
                catch (Exception)
                {
                    Console.WriteLine("Unable to form image from given path!");
                    Console.WriteLine("\nAborted process!");
                }

                discRecorder2.EjectMedia();
            }
            #endregion
            OperationContext.Current.GetCallbackChannel <MyCallBackHandler>().CDBurnt();
        }
Exemple #8
0
        /// <summary>
        /// Examines and reports the burn device characteristics such
        /// as Product ID, Revision Level, Feature Set and Profiles.
        /// </summary>
        /// <param name="recorder">Burning Device. Must be initialized.</param>
        public void DisplayRecorderCharacteristics(IDiscRecorder2 recorder)
        {
            // Create a DiscMaster2 object to obtain an inventory of CD/DVD drives.
            IDiscMaster2 discMaster = new MsftDiscMaster2();

            //*** - Formating the way to display info on the supported recoders
            Console.WriteLine("--------------------------------------------------------------------------------");
            Console.WriteLine("ActiveRecorderId: {0}".PadLeft(22), recorder.ActiveDiscRecorder);
            Console.WriteLine("Vendor Id: {0}".PadLeft(22), recorder.VendorId);
            Console.WriteLine("Product Id: {0}".PadLeft(22), recorder.ProductId);
            Console.WriteLine("Product Revision: {0}".PadLeft(22), recorder.ProductRevision);
            Console.WriteLine("VolumeName: {0}".PadLeft(22), recorder.VolumeName);
            Console.WriteLine("Can Load Media: {0}".PadLeft(22), recorder.DeviceCanLoadMedia);
            Console.WriteLine("Device Number: {0}".PadLeft(22), recorder.LegacyDeviceNumber);

            foreach (String mountPoint in recorder.VolumePathNames)
            {
                Console.WriteLine("Mount Point: {0}".PadLeft(22), mountPoint);
            }

            foreach (IMAPI_FEATURE_PAGE_TYPE supportedFeature in recorder.SupportedFeaturePages)
            {
                Console.WriteLine("Feature: {0}".PadLeft(22), supportedFeature.ToString("F"));
            }

            Console.WriteLine("Current Features");
            foreach (IMAPI_FEATURE_PAGE_TYPE currentFeature in recorder.CurrentFeaturePages)
            {
                Console.WriteLine("Feature: {0}".PadLeft(22), currentFeature.ToString("F"));
            }

            Console.WriteLine("Supported Profiles");
            foreach (IMAPI_PROFILE_TYPE supportedProfile in recorder.SupportedProfiles)
            {
                Console.WriteLine("Profile: {0}".PadLeft(22), supportedProfile.ToString("F"));
            }

            Console.WriteLine("Current Profiles");
            foreach (IMAPI_PROFILE_TYPE currentProfile in recorder.CurrentProfiles)
            {
                Console.WriteLine("Profile: {0}".PadLeft(22), currentProfile.ToString("F"));
            }

            Console.WriteLine("Supported Mode Pages");
            foreach (IMAPI_MODE_PAGE_TYPE supportedModePage in recorder.SupportedModePages)
            {
                Console.WriteLine("Mode Page: {0}".PadLeft(22), supportedModePage.ToString("F"));
            }

            Console.WriteLine("\n----- Finished content -----");
        }
Exemple #9
0
        public void UpdateDriveList()
        {
            IDiscMaster2 discMaster = new MsftDiscMaster2();
            //  IEnumerator ie = discMaster.GetEnumerator();
            int count          = discMaster.Count;
            int cursorPosition = -1;
            int i;

            if (driveCount == discMaster.Count)
            {
                return;
            }
            if (!driveListBox.Items.IsEmpty)
            {
                driveListBox.Items.Clear();
            }
            if (discMaster.Count == 0)
            {
                selectedSpeed = 0;
                driveListBox.Items.Add("");
                //driveListBox.SelectedIndex = 0;
                driveListBox.IsEnabled = false;
                return;
            }

            driveId = new String[discMaster.Count];
            for (i = 0; i < count; ++i)
            {
                IDiscRecorder2 recorder = new MsftDiscRecorder2();
                String         s        = discMaster[i];
                if (s == selectedDrive)
                {
                    cursorPosition = i;
                }
                driveId[i] = s;
                recorder.InitializeDiscRecorder(s);
                s = recorder.ProductId;
                this.driveListBox.Items.Add(s);
            }
            if (cursorPosition == -1)
            {
                selectedSpeed  = 0;
                cursorPosition = 0;
            }
            driveListBox.SelectedIndex = cursorPosition;
            selectedDrive          = discMaster[cursorPosition];
            driveListBox.IsEnabled = true;
        }
Exemple #10
0
        public IList<MsftDiscRecorder2> GetDiscRecorders()
        {
            var result = new List<MsftDiscRecorder2>();
            var discMaster = new MsftDiscMaster2();
            if (!discMaster.IsSupportedEnvironment)
                return result;
            foreach (string uniqueRecorderID in discMaster)
            {
                var discRecorder2 = new MsftDiscRecorder2();
                discRecorder2.InitializeDiscRecorder(uniqueRecorderID);

                result.Add(discRecorder2);
            }

            return result;
        }
Exemple #11
0
        public bool DetectCDRoms(ref vComboBox lst)
        {
            bool            flag    = false;
            MsftDiscMaster2 gClass0 = null;

            try
            {
                try
                {
                    gClass0 = (MsftDiscMaster2)(new GClass0());
                    if (gClass0.IsSupportedEnvironment)
                    {
                        foreach (string str in gClass0)
                        {
                            MsftDiscRecorder2 msftDiscRecorder2Class = (MsftDiscRecorder2)(new MsftDiscRecorder2Class());
                            msftDiscRecorder2Class.InitializeDiscRecorder(str);
                            string   str1      = msftDiscRecorder2Class.VolumePathNames[0].ToString();
                            string   productId = msftDiscRecorder2Class.ProductId;
                            ListItem listItem  = new ListItem()
                            {
                                Text       = string.Format("{0} [{1}]", str1, productId),
                                Tag        = msftDiscRecorder2Class,
                                ImageIndex = 0
                            };
                            lst.Items.Add(listItem);
                            flag = true;
                        }
                        if (lst.Items.Count > 0)
                        {
                            lst.SelectedIndex = 0;
                        }
                    }
                }
                catch (COMException cOMException)
                {
                    throw;
                }
            }
            finally
            {
                if (gClass0 != null)
                {
                    Marshal.ReleaseComObject(gClass0);
                }
            }
            return(flag);
        }
        /// <summary>
        /// 获取光驱设备列表
        /// </summary>
        /// <returns></returns>
        public static List <Recorder> GetRecorderList()
        {
            List <Recorder> recordList = new List <Recorder>();

            // Create a DiscMaster2 object to connect to optical drives.
            MsftDiscMaster2 discMaster = new MsftDiscMaster2();

            for (int i = 0; i < discMaster.Count; i++)
            {
                if (discMaster[i] != null)
                {
                    Recorder recorder = new Recorder(discMaster[i]);
                    recordList.Add(recorder);
                }
            }
            return(recordList);
        }
Exemple #13
0
    static void Main(string[] args)
    {
        // Index to recording drive.
        int index = 2;

        // Create a DiscMaster2 object to connect to CD/DVD drives.
        IDiscMaster2 discMaster = new MsftDiscMaster2();

        // Initialize the DiscRecorder object for the specified burning device.
        IDiscRecorder2 recorder = new MsftDiscRecorder2();

        recorder.InitializeDiscRecorder(discMaster[index]);

        IMAPIv2.Samples samples = new IMAPIv2.Samples();

        samples.BurnDirectory(recorder, @"D:\Utils");
    }
Exemple #14
0
        /// <summary>
        /// Initialize the form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_Load(object sender, EventArgs e)
        {
            //
            // Determine the current recording devices
            //
            MsftDiscMaster2 discMaster = null;

            try
            {
                discMaster = new MsftDiscMaster2();

                if (!discMaster.IsSupportedEnvironment)
                {
                    return;
                }
                foreach (string uniqueRecorderId in discMaster)
                {
                    var discRecorder2 = new MsftDiscRecorder2();
                    discRecorder2.InitializeDiscRecorder(uniqueRecorderId);

                    devicesComboBox.Items.Add(discRecorder2);
                }
                if (devicesComboBox.Items.Count > 0)
                {
                    devicesComboBox.SelectedIndex = 0;
                }
            }
            catch (COMException ex)
            {
                MessageBox.Show(ex.Message,
                                string.Format("Error:{0} - Please install IMAPI2", ex.ErrorCode),
                                MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            finally
            {
                if (discMaster != null)
                {
                    Marshal.ReleaseComObject(discMaster);
                }
            }

            labelStatusText.Text = string.Empty;
            UpdateCapacity();
        }
Exemple #15
0
        public void cekIMAPI()
        {
            MsftDiscMaster2 Master = null;

            try
            {
                Master = new MsftDiscMaster2();

                if (!Master.IsSupportedEnvironment)
                {
                    return;
                }
                foreach (string uniqueRecorderID in Master)
                {
                    MsftDiscRecorder2 Recorder = new MsftDiscRecorder2();
                    Recorder.InitializeDiscRecorder(uniqueRecorderID);
                    comboBoxDrive.Items.Add(Recorder);
                }
                if (comboBoxDrive.Items.Count > 0)
                {
                    comboBoxDrive.SelectedIndex = 0;
                }
            }

            catch
            {
                suaraGalat(true);

                MessageBox.Show(this, "Sepertinya IMAPI2 tidak ditemukan dalam Sistem Operasi ini.",
                                pesan, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                kembaliKeFormUtama();
            }

            finally
            {
                if (Master != null)
                {
                    Marshal.ReleaseComObject(Master);
                }
            }
        }
Exemple #16
0
        public List <IDiscRecorder2> findAllDisk()
        {
            List <IDiscRecorder2> RecordDisk_List = new List <IDiscRecorder2>();

            //
            // Determine the current recording devices
            //
            MsftDiscMaster2 discMaster = null;

            try
            {
                discMaster = new MsftDiscMaster2();

                if (!discMaster.IsSupportedEnvironment)
                {
                    return(null);
                }
                foreach (string uniqueRecorderId in discMaster)
                {
                    var discRecorder2 = new MsftDiscRecorder2();
                    discRecorder2.InitializeDiscRecorder(uniqueRecorderId);

                    //MessageBox.Show(discRecorder2.ProductId);
                    RecordDisk_List.Add(discRecorder2);
                    //devicesComboBox.Items.Add();
                }
            }
            catch
            {
                MessageBox.Show(string.Format("Error:{0} - Please install IMAPI2"));
                return(null);
            }
            finally
            {
                if (discMaster != null)
                {
                    Marshal.ReleaseComObject(discMaster);
                }
            }

            return(RecordDisk_List);
        }
Exemple #17
0
        /// <summary>
        /// Initialize the form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_Load(object sender, EventArgs e)
        {
            //
            // Determine the current recording devices
            //
            MsftDiscMaster2 discMaster = null;
            try
            {
                discMaster = new MsftDiscMaster2();

                if (!discMaster.IsSupportedEnvironment)
                    return;
                foreach (string uniqueRecorderId in discMaster)
                {
                    var discRecorder2 = new MsftDiscRecorder2();
                    discRecorder2.InitializeDiscRecorder(uniqueRecorderId);

                    devicesComboBox.Items.Add(discRecorder2);
                }
                if (devicesComboBox.Items.Count > 0)
                {
                    devicesComboBox.SelectedIndex = 0;
                }
            }
            catch (COMException ex)
            {
                MessageBox.Show(ex.Message,
                    string.Format("Error:{0} - Please install IMAPI2", ex.ErrorCode),
                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            finally
            {
                if (discMaster != null)
                {
                    Marshal.ReleaseComObject(discMaster);
                }
            }

            labelStatusText.Text = string.Empty;
            UpdateCapacity();
        }
Exemple #18
0
        public ImageMaster()
        {
            List <DiscRecorder> recorders = new List <DiscRecorder>();

            _media       = PhysicalMedia.Unknown;
            _nodes       = new List <IMediaNode>();
            _mediaStates = new ReadOnlyCollection <MediaState>(new List <MediaState> {
                MediaState.Unknown
            });

            MsftDiscMaster2 discMaster = null;

            try
            {
                discMaster = new MsftDiscMaster2();

                if (!discMaster.IsSupportedEnvironment)
                {
                    throw new NotSupportedException(
                              "Either the environment does not contain one or more optical devices or the " +
                              "execution context has no permission to access the devices.");
                }

                foreach (string uniqueRecorderId in discMaster)
                {
                    recorders.Add(new DiscRecorder(uniqueRecorderId));
                }
                _recorders = new ReadOnlySelectableCollection <DiscRecorder>(recorders);
            }
            catch (COMException ex)
            {
                throw new NotSupportedException("IMAP2 not found on this system. It will need to be installed (ErrorCode = " + ex.ErrorCode + ").", ex);
            }
            finally
            {
                if (discMaster != null)
                {
                    Marshal.ReleaseComObject(discMaster);
                }
            }
        }
Exemple #19
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            _dictionares = new Dictionares();
            MsftDiscMaster2 discMaster = null;

            try
            {
                discMaster = new MsftDiscMaster2();
                if (!discMaster.IsSupportedEnvironment)
                {
                    return;
                }
                foreach (string uniqueRecorderId in discMaster)
                {
                    var tempDiscRecorder = new MsftDiscRecorder2();
                    tempDiscRecorder.InitializeDiscRecorder(uniqueRecorderId);
                    devicesComboBox.Items.Add(tempDiscRecorder);
                }
                if (devicesComboBox.Items.Count > 0)
                {
                    devicesComboBox.SelectedIndex = 0;
                }
            }
            catch (COMException ex)
            {
                MessageBox.Show(ex.Message,
                                string.Format("Error:{0} - Please install IMAPI2", ex.ErrorCode),
                                MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            finally
            {
                if (discMaster != null)
                {
                    Marshal.ReleaseComObject(discMaster);
                }
            }
            InitVolumeLabel();
        }
Exemple #20
0
        public BurnerSrvImpl()
        {
            try
            {
                discMaster = new MsftDiscMaster2();

                if (!discMaster.IsSupportedEnvironment)
                {
                    return;
                }

                //Creo la lista con i masterizzatori
                foreach (string uniqueRecorderId in discMaster)
                {
                    var discRecorder2 = new MsftDiscRecorder2();
                    discRecorder2.InitializeDiscRecorder(uniqueRecorderId);
                    System.Diagnostics.Trace.WriteLine("[Volume]: " + discRecorder2.VolumePathNames.GetValue(0));
                    _listRecorders.Add(discRecorder2);
                }

                // Setto alcuni valori di Default
                ejectMedia   = true;
                closeMedia   = false;
                quickFormat  = true;
                discRecorder = _listRecorders.First();
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message, string.Format("Error:{0} - Please install IMAPI2", ex.ErrorCode));
                return;
            }
            finally
            {
                if (discMaster != null)
                {
                    Marshal.ReleaseComObject(discMaster);
                }
            }
        }
Exemple #21
0
        static BurnHelper()
        {
            var discMaster = new MsftDiscMaster2();

            try
            {
                _recorders = new List <IDiscRecorder2>();
                for (var i = 0; i < discMaster.Count; ++i)
                {
                    IDiscFormat2Data mi = new MsftDiscFormat2Data();
                    try
                    {
                        IDiscRecorder2 rec = new MsftDiscRecorder2();
                        rec.InitializeDiscRecorder(discMaster[i]);

                        //remove the comment for next 2 lines
                        mi.Recorder = rec;
                        if (mi.IsRecorderSupported(rec))
                        {
                            _recorders.Add(rec);
                        }
                    }
                    catch (Exception)
                    {
                        //throw;
                    }
                    finally
                    {
                        Marshal.FinalReleaseComObject(mi);
                    }
                }
            }
            finally
            {
                Marshal.FinalReleaseComObject(discMaster);
            }
        }
Exemple #22
0
        /// <summary>
        /// Get the current media type from drive letter
        /// </summary>
        /// <param name="drive"></param>
        /// <returns></returns>
        /// <remarks>
        /// This may eventually be replaced by Aaru.Devices being able to be about 10x more accurate.
        /// This will also end up making it so that IMAPI2 is no longer necessary. Unfortunately, that
        /// will only work for .NET Core 3.1 and beyond.
        /// </remarks>
        public static (MediaType?, string) GetMediaType(Drive drive)
        {
            // Take care of the non-optical stuff first
            // TODO: See if any of these can be more granular, like Optical is
            if (drive.InternalDriveType == InternalDriveType.Floppy)
            {
                return(MediaType.FloppyDisk, null);
            }
            else if (drive.InternalDriveType == InternalDriveType.HardDisk)
            {
                return(MediaType.HardDisk, null);
            }
            else if (drive.InternalDriveType == InternalDriveType.Removable)
            {
                return(MediaType.FlashDrive, null);
            }

            // Get the current drive information
            string deviceId = null;
            bool   loaded   = false;

            try
            {
                // Get the device ID first
                var searcher = new ManagementObjectSearcher(
                    "root\\CIMV2",
                    $"SELECT * FROM Win32_CDROMDrive WHERE Id = '{drive.Letter}:\'");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    deviceId = (string)queryObj["DeviceID"];
                    loaded   = (bool)queryObj["MediaLoaded"];
                }

                // If we got no valid device, we don't care and just return
                if (deviceId == null)
                {
                    return(null, "Device could not be found");
                }
                else if (!loaded)
                {
                    return(null, "Device is not reporting media loaded");
                }

#if NET_FRAMEWORK
                MsftDiscMaster2 discMaster = new MsftDiscMaster2();
                deviceId = deviceId.ToLower().Replace('\\', '#').Replace('/', '#');
                string id = null;
                foreach (var disc in discMaster)
                {
                    if (disc.ToString().Contains(deviceId))
                    {
                        id = disc.ToString();
                    }
                }

                // If we couldn't find the drive, we don't care and return
                if (id == null)
                {
                    return(null, "Device ID could not be found");
                }

                // Create the required objects for reading from the drive
                MsftDiscRecorder2 recorder = new MsftDiscRecorder2();
                recorder.InitializeDiscRecorder(id);
                MsftDiscFormat2Data dataWriter = new MsftDiscFormat2Data();

                // If the recorder is not supported, just return
                if (!dataWriter.IsRecorderSupported(recorder))
                {
                    return(null, "IMAPI2 recorder not supported");
                }

                // Otherwise, set the recorder to get information from
                dataWriter.Recorder = recorder;

                var media = dataWriter.CurrentPhysicalMediaType;
                return(media.IMAPIToMediaType(), null);
#else
                // TODO: This entire .NET Core path still doesn't work
                // This may honestly require an entire import of IMAPI2 stuff and then try
                // as best as possible to get it working.

                return(null, "Media detection only supported on .NET Framework");
#endif
            }
            catch (Exception ex)
            {
                return(null, ex.Message);
            }
        }
Exemple #23
0
        /// <summary>
        /// Get the current media type from drive letter
        /// </summary>
        /// <param name="drive"></param>
        /// <returns></returns>
        /// <remarks>
        /// https://stackoverflow.com/questions/11420365/detecting-if-disc-is-in-dvd-drive
        /// </remarks>
        public static MediaType?GetMediaType(Drive drive)
        {
            // Take care of the non-optical stuff first
            // TODO: See if any of these can be more granular, like Optical is
            if (drive.InternalDriveType == InternalDriveType.Floppy)
            {
                return(MediaType.FloppyDisk);
            }
            else if (drive.InternalDriveType == InternalDriveType.HardDisk)
            {
                return(MediaType.HardDisk);
            }
            else if (drive.InternalDriveType == InternalDriveType.Removable)
            {
                return(MediaType.FlashDrive);
            }

            // Get the DeviceID and MediaType from the current drive letter
            string deviceId  = null;
            int    mediaType = 0;

            try
            {
                // Get the device ID first
                var searcher = new ManagementObjectSearcher(
                    "root\\CIMV2",
                    $"SELECT * FROM Win32_CDROMDrive WHERE Id = '{drive.Letter}:\'");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    deviceId = (string)queryObj["DeviceID"];

                    #region Possibly useful fields

                    //foreach (var property in queryObj.Properties)
                    //{
                    //    Console.WriteLine(property);
                    //}

                    //// Capabilities list
                    //ushort?[] capabilities = (ushort?[])queryObj["Capabilities"];

                    //// Internal name of the device
                    //string caption = (string)queryObj["Caption"];

                    //// Flags for the file system, see FileSystemFlags
                    //uint? fileSystemFlagsEx = (uint?)queryObj["FileSystemFlagsEx"];

                    //// "CD Writer" doesn't fit https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-cdromdrive
                    //string mediaTypeString = (string)queryObj["MediaType"];

                    //// Internal name of the device (Seems like a duplicate of Caption)
                    //string name = (string)queryObj["Name"];

                    //// Full device ID for the drive (Seems like duplicate of DeviceID)
                    //string pnpDeviceId = (string)queryObj["PNPDeviceId"];

                    //// Size of the loaded media (extrapolate disc type from this?)
                    //ulong? size = (ulong?)queryObj["Size"];

                    #endregion
                }

                // If we got no valid device, we don't care and just return
                if (deviceId == null)
                {
                    return(null);
                }

#if NET_FRAMEWORK
                MsftDiscMaster2 discMaster = new MsftDiscMaster2();
                deviceId = deviceId.ToLower().Replace('\\', '#');
                string id = null;
                foreach (var disc in discMaster)
                {
                    if (disc.ToString().Contains(deviceId))
                    {
                        id = disc.ToString();
                    }
                }

                // If we couldn't find the drive, we don't care and return
                if (id == null)
                {
                    return(null);
                }

                // Otherwise, we get the media type, if any
                MsftDiscRecorder2 recorder = new MsftDiscRecorder2();
                recorder.InitializeDiscRecorder(id);
                MsftDiscFormat2Data dataWriter = new MsftDiscFormat2Data();
                dataWriter.Recorder = recorder;
                var media = dataWriter.CurrentPhysicalMediaType;
                if (media != IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_UNKNOWN)
                {
                    return(media.IMAPIToMediaType());
                }

                return(null);
#else
                // TODO: This entire .NET Core path still doesn't work
                // This may honestly require an entire import of IMAPI2 stuff and then try
                // as best as possible to get it working.

                // Now try to get the physical media associated
                searcher = new ManagementObjectSearcher(
                    "root\\CIMV2",
                    $"SELECT * FROM Win32_PhysicalMedia");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    foreach (var property in queryObj.Properties)
                    {
                        Console.WriteLine(property);
                    }

                    mediaType = (int)(queryObj["MediaType"] ?? 0);
                }

                return(((PhysicalMediaType)mediaType).ToMediaType());
#endif
            }
            catch
            {
                // We don't care what the error was
                return(null);
            }
        }
Exemple #24
0
        /// <summary>
        /// Initialize the form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_Load(object sender, EventArgs e)
        {
            cls_main main_func = new cls_main();
            if (main_func.check_for_components(false))
            {
                if (!File.Exists(appdir + "umk_manager_08.exe")) { pict_mngr.Visible = false; };
                if (Directory.Exists(appdir + "system\\service") == false) { chk_service_enabled.Enabled = false; } else { chk_service_enabled.Enabled = true; }
                main_func.create_registry();
                prj_exist = true;
                umk_folder = main_func.get_value_from_infofile(appdir + "configs\\settings.ini", "umk_folder");
                if (umk_folder == "")
                {
                    MessageBox.Show("УМК не найдены. Запустите УМК Менеджер, чтобы указать правильный путь к директории с УМК.", "УМК не найдены!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }
                else
                {
                    if (Microsoft.VisualBasic.Strings.Right(umk_folder, 1)== "\\")
                    {
                        umk_folder = Microsoft.VisualBasic.Strings.Left(umk_folder, umk_folder.Length-1);
                    };
                    if (Microsoft.VisualBasic.Strings.Left(umk_folder, 6) == "APPDIR")
                    {
                        umk_folder = main_func.ReplaceAll(umk_folder, "APPDIR\\", appdir);
                    }
                 }
                clear_form();
                show_dg_open();
                if (Environment.OSVersion.Version.Major > 5)
                {
                    MsftDiscMaster2 discMaster = null;
                    try
                    {
                        discMaster = new MsftDiscMaster2();

                        if (!discMaster.IsSupportedEnvironment)
                            return;
                        foreach (string uniqueRecorderID in discMaster)
                        {
                            MsftDiscRecorder2 discRecorder2 = new MsftDiscRecorder2();
                            discRecorder2.InitializeDiscRecorder(uniqueRecorderID);

                            devicesComboBox.Items.Add(discRecorder2);
                        }
                        if (devicesComboBox.Items.Count > 0)
                        {
                            devicesComboBox.SelectedIndex = 0;
                        }
                    }
                    catch (COMException ex)
                    {
                        MessageBox.Show(ex.Message,
                            string.Format("Error:{0} - Пожалуйста, установите IMAPI2", ex.ErrorCode),
                            MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        return;
                    }
                    finally
                    {
                        if (discMaster != null)
                        {
                            Marshal.ReleaseComObject(discMaster);
                        }
                    }
                    //
                    // Create the volume label based on the current date
                    //
                    DateTime now = DateTime.Now;
                    textBoxLabel.Text = now.Year + "_" + now.Month + "_" + now.Day;

                    labelStatusText.Text = string.Empty;
                    labelFormatStatusText.Text = string.Empty;

                    //
                    // Select no verification, by default
                    //
                    comboBoxVerification.SelectedIndex = 0;

                    UpdateCapacity();
                }
                else
                {
                    devicesComboBox.Visible = false;
                    label43.Visible = false;
                    MessageBox.Show("В данной версии ОС некоторые функции программы будут недоступны!", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                Application.Exit();
            }
        }
Exemple #25
0
        /// <summary>
        /// Initializes the drive.  Detects available DVD drives and the media inserted in each drive.
        /// </summary>
        /// <returns>The result of the detection.</returns>
        public override DriveStatus Initialize()
        {
            DriveStatus result = DriveStatus.NoDrive;

            try
            {
                MsftDiscMaster2 discMaster = new MsftDiscMaster2();
                if (!discMaster.IsSupportedEnvironment || discMaster.Count <= 0)
                {
                    result = DriveStatus.NoDrive;
                }
                else
                {
                    bool possibleDriveFound = false;
                    foreach (string recorderID in discMaster)
                    {
                        try
                        {
                            MsftDiscRecorder2 discRecorder2 = new MsftDiscRecorder2();
                            discRecorder2.InitializeDiscRecorder(recorderID);

                            // Check that the drive is supported
                            bool supportsBurn = false;
                            foreach (IMAPI_FEATURE_PAGE_TYPE type in discRecorder2.SupportedFeaturePages)
                            {
                                switch (type)
                                {
                                case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_RANDOMLY_WRITABLE:
                                case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_INCREMENTAL_STREAMING_WRITABLE:
                                case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_WRITE_ONCE:
                                case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_DVD_DASH_WRITE:
                                case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_LAYER_JUMP_RECORDING:
                                case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_BD_WRITE:
                                case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_HD_DVD_WRITE:
                                    supportsBurn = true;
                                    break;
                                }

                                if (supportsBurn)
                                {
                                    break;
                                }
                            }

                            // This device does not support buring, skip it.
                            if (!supportsBurn)
                            {
                                continue;
                            }

                            MsftDiscFormat2Data discFormatData = new MsftDiscFormat2Data();
                            if (!String.IsNullOrEmpty(discRecorder2.ExclusiveAccessOwner))
                            {
                                result = DriveStatus.DriveNotReady;
                            }
                            else if (discFormatData.IsCurrentMediaSupported(discRecorder2))
                            {
                                discFormatData.Recorder = discRecorder2;

                                // Detect the media
                                if (!discFormatData.MediaHeuristicallyBlank)
                                {
                                    result = DriveStatus.MediaNotBlank;
                                }
                                else if (2048L * discFormatData.TotalSectorsOnMedia < this.ImageReader.ImageFile.Length)
                                {
                                    if (!possibleDriveFound)
                                    {
                                        result = DriveStatus.MediaTooSmall;
                                    }
                                }
                                else
                                {
                                    // Valid media found, use this drive.
                                    result = this.SetActiveDrive(recorderID);

                                    // Set the write speed
                                    SetWriteSpeed(discFormatData);

                                    break;
                                }
                            }
                            else if (!possibleDriveFound)
                            {
                                // Check if the media has files on it since IsCurrentMediaSupported returns false when the media is not recordable.
                                DriveInfo info = new DriveInfo((string)discRecorder2.VolumePathNames[0]);
                                if (!info.IsReady)
                                {
                                    result = DriveStatus.NoMedia;
                                }
                                else if (info.RootDirectory.GetFiles().Length > 0 ||
                                         info.RootDirectory.GetDirectories().Length > 0)
                                {
                                    result = DriveStatus.MediaNotBlank;
                                }
                            }

                            // If we found a drive with media, save that as a possible drive, but keep
                            // looking in case there is a drive with valid media.
                            possibleDriveFound = result != DriveStatus.NoDrive && result != DriveStatus.NoMedia;
                        }
                        catch (COMException ex)
                        {
                            switch ((uint)ex.ErrorCode)
                            {
                            case 0xC0AA0205:     // E_IMAPI_RECORDER_MEDIA_BECOMING_READY
                            case 0xC0AA0206:     // E_IMAPI_RECORDER_MEDIA_FORMAT_IN_PROGRESS
                            case 0xC0AA0207:     // E_IMAPI_RECORDER_MEDIA_BUSY
                            case 0xC0AA020D:     // E_IMAPI_RECORDER_COMMAND_TIMEOUT
                            case 0xC0AA0210:     // E_IMAPI_RECORDER_LOCKED
                                result = DriveStatus.DriveNotReady;
                                break;

                            default:
                                result = DriveStatus.InvalidMedia;
                                this.Logging.WriteException("Error trying to read media.", ex);
                                break;
                            }
                        }
                    }
                }
            }
            catch (COMException ex)
            {
                result = DriveStatus.NoDrive;
                this.Logging.WriteException("Error trying to read drives.", ex);
            }

            return(result);
        }
    static void Main(string[] args)
    {
        // Index to recording drive.
        int index = 0;

        // Create a DiscMaster2 object to connect to CD/DVD drives.
        IDiscMaster2 discMaster = new MsftDiscMaster2();

        // Initialize the DiscRecorder object for the specified burning device.
        IDiscRecorder2 recorder = new MsftDiscRecorder2();
        recorder.InitializeDiscRecorder(discMaster[index]);

        IMAPIv2.Samples samples = new IMAPIv2.Samples();

        samples.BurnDirectory(recorder, @"D:\Utils");
    }
        /// <summary>
        /// Examines and reports the burn device characteristics such 
        /// as Product ID, Revision Level, Feature Set and Profiles.
        /// </summary>
        /// <param name="recorder">Burning Device. Must be initialized.</param>
        public void DisplayRecorderCharacteristics(IDiscRecorder2 recorder)
        {
            // Create a DiscMaster2 object to obtain an inventory of CD/DVD drives.
            IDiscMaster2 discMaster = new MsftDiscMaster2();

            //*** - Formating the way to display info on the supported recoders
            Console.WriteLine("--------------------------------------------------------------------------------");
            Console.WriteLine("ActiveRecorderId: {0}".PadLeft(22), recorder.ActiveDiscRecorder);
            Console.WriteLine("Vendor Id: {0}".PadLeft(22), recorder.VendorId);
            Console.WriteLine("Product Id: {0}".PadLeft(22), recorder.ProductId);
            Console.WriteLine("Product Revision: {0}".PadLeft(22), recorder.ProductRevision);
            Console.WriteLine("VolumeName: {0}".PadLeft(22), recorder.VolumeName);
            Console.WriteLine("Can Load Media: {0}".PadLeft(22), recorder.DeviceCanLoadMedia);
            Console.WriteLine("Device Number: {0}".PadLeft(22), recorder.LegacyDeviceNumber);

            foreach (String mountPoint in recorder.VolumePathNames)
            {
                Console.WriteLine("Mount Point: {0}".PadLeft(22), mountPoint);
            }

            foreach (IMAPI_FEATURE_PAGE_TYPE supportedFeature in recorder.SupportedFeaturePages)
            {
                Console.WriteLine("Feature: {0}".PadLeft(22), supportedFeature.ToString("F"));
            }

            Console.WriteLine("Current Features");
            foreach (IMAPI_FEATURE_PAGE_TYPE currentFeature in recorder.CurrentFeaturePages)
            {
                Console.WriteLine("Feature: {0}".PadLeft(22), currentFeature.ToString("F"));
            }

            Console.WriteLine("Supported Profiles");
            foreach (IMAPI_PROFILE_TYPE supportedProfile in recorder.SupportedProfiles)
            {
                Console.WriteLine("Profile: {0}".PadLeft(22), supportedProfile.ToString("F"));
            }

            Console.WriteLine("Current Profiles");
            foreach (IMAPI_PROFILE_TYPE currentProfile in recorder.CurrentProfiles)
            {
                Console.WriteLine("Profile: {0}".PadLeft(22), currentProfile.ToString("F"));
            }

            Console.WriteLine("Supported Mode Pages");
            foreach (IMAPI_MODE_PAGE_TYPE supportedModePage in recorder.SupportedModePages)
            {
                Console.WriteLine("Mode Page: {0}".PadLeft(22), supportedModePage.ToString("F"));
            }

            Console.WriteLine("\n----- Finished content -----");
        }
Exemple #28
0
        /// <summary>
        /// Initializes the drive.  Detects available DVD drives and the media inserted in each drive.
        /// </summary>
        /// <returns>The result of the detection.</returns>
        public override DriveStatus Initialize()
        {
            DriveStatus result = DriveStatus.NoDrive;

            try
            {
                MsftDiscMaster2 discMaster = new MsftDiscMaster2();
                if (!discMaster.IsSupportedEnvironment || discMaster.Count <= 0)
                {
                    result = DriveStatus.NoDrive;
                }
                else
                {
                    bool possibleDriveFound = false;
                    foreach (string recorderID in discMaster)
                    {
                        try
                        {
                            MsftDiscRecorder2 discRecorder2 = new MsftDiscRecorder2();
                            discRecorder2.InitializeDiscRecorder(recorderID);

                            // Check that the drive is supported
                            bool supportsBurn = false;
                            foreach (IMAPI_FEATURE_PAGE_TYPE type in discRecorder2.SupportedFeaturePages)
                            {
                                switch (type)
                                {
                                    case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_RANDOMLY_WRITABLE:
                                    case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_INCREMENTAL_STREAMING_WRITABLE:
                                    case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_WRITE_ONCE:
                                    case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_DVD_DASH_WRITE:
                                    case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_LAYER_JUMP_RECORDING:
                                    case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_BD_WRITE:
                                    case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_HD_DVD_WRITE:
                                        supportsBurn = true;
                                        break;
                                }

                                if (supportsBurn)
                                {
                                    break;
                                }
                            }

                            // This device does not support buring, skip it.
                            if (!supportsBurn)
                            {
                                continue;
                            }

                            MsftDiscFormat2Data discFormatData = new MsftDiscFormat2Data();
                            if (!String.IsNullOrEmpty(discRecorder2.ExclusiveAccessOwner))
                            {
                                result = DriveStatus.DriveNotReady;
                            }
                            else if (discFormatData.IsCurrentMediaSupported(discRecorder2))
                            {
                                discFormatData.Recorder = discRecorder2;

                                // Detect the media
                                if (!discFormatData.MediaHeuristicallyBlank)
                                {
                                    result = DriveStatus.MediaNotBlank;
                                }
                                else if (2048L * discFormatData.TotalSectorsOnMedia < this.ImageReader.ImageFile.Length)
                                {
                                    if (!possibleDriveFound)
                                    {
                                        result = DriveStatus.MediaTooSmall;
                                    }
                                }
                                else
                                {
                                    // Valid media found, use this drive.
                                    result = this.SetActiveDrive(recorderID);

                                    // Set the write speed
                                    SetWriteSpeed(discFormatData);

                                    break;
                                }
                            }
                            else if (!possibleDriveFound)
                            {
                                // Check if the media has files on it since IsCurrentMediaSupported returns false when the media is not recordable.
                                DriveInfo info = new DriveInfo((string)discRecorder2.VolumePathNames[0]);
                                if (!info.IsReady)
                                {
                                    result = DriveStatus.NoMedia;
                                }
                                else if (info.RootDirectory.GetFiles().Length > 0
                                     || info.RootDirectory.GetDirectories().Length > 0)
                                {
                                    result = DriveStatus.MediaNotBlank;
                                }
                            }

                            // If we found a drive with media, save that as a possible drive, but keep
                            // looking in case there is a drive with valid media.
                            possibleDriveFound = result != DriveStatus.NoDrive && result != DriveStatus.NoMedia;
                        }
                        catch (COMException ex)
                        {
                            switch ((uint)ex.ErrorCode)
                            {
                                case 0xC0AA0205: // E_IMAPI_RECORDER_MEDIA_BECOMING_READY
                                case 0xC0AA0206: // E_IMAPI_RECORDER_MEDIA_FORMAT_IN_PROGRESS
                                case 0xC0AA0207: // E_IMAPI_RECORDER_MEDIA_BUSY
                                case 0xC0AA020D: // E_IMAPI_RECORDER_COMMAND_TIMEOUT
                                case 0xC0AA0210: // E_IMAPI_RECORDER_LOCKED
                                    result = DriveStatus.DriveNotReady;
                                    break;
                                default:
                                    result = DriveStatus.InvalidMedia;
                                    this.Logging.WriteException("Error trying to read media.", ex);
                                    break;
                            }
                        }
                    }
                }
            }
            catch (COMException ex)
            {
                result = DriveStatus.NoDrive;
                this.Logging.WriteException("Error trying to read drives.", ex);
            }

            return result;
        }
Exemple #29
0
        private void FormDvdWriter_Load(object sender, EventArgs e)
        {
            bool isHavingDisk = false;
            bool isHaveUSB    = false;

            txtFilename.Text = Path.GetFileName(_filePath);

            long filesize = (new FileInfo(_filePath)).Length;

            txtFileSize.Text = (filesize < 1000000000 ?
                                string.Format("{0} MB", filesize / 1000000) :
                                string.Format("{0:F2} GB", (float)filesize / 1000000000.0));

            // Determine the current recording devices
            MsftDiscMaster2 discMaster = null;

            try
            {
                discMaster = new MsftDiscMaster2();

                if (discMaster.IsSupportedEnvironment)
                {
                    foreach (string uniqueRecorderId in discMaster)
                    {
                        var discRecorder2 = new MsftDiscRecorder2();
                        discRecorder2.InitializeDiscRecorder(uniqueRecorderId);

                        listDrive1.Items.Add(discRecorder2);
                        listDrive2.Items.Add(discRecorder2);
                    }

                    if (listDrive1.Items.Count <= 0)
                    {
                        listDrive1.Enabled       = false;
                        listDrive1.SelectedIndex = -1;

                        listDrive2.Enabled       = false;
                        listDrive2.SelectedIndex = -1;
                    }
                    else if (listDrive1.Items.Count == 1)
                    {
                        listDrive1.SelectedIndex = 0;

                        listDrive2.Enabled       = false;
                        listDrive2.SelectedIndex = 0;

                        isHavingDisk = true;
                    }
                    else
                    {
                        listDrive1.SelectedIndex = 0;

                        listDrive2.SelectedIndex = 1;
                        isHavingDisk             = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Thiết bị không hỗ trợ thư viện IMAPI2");
                Log.WriteLine(ex.ToString());
                return;
            }
            finally
            {
                if (discMaster != null)
                {
                    Marshal.ReleaseComObject(discMaster);
                }
            }

            var driveList = DriveInfo.GetDrives();

            foreach (DriveInfo drive in driveList)
            {
                if (drive.DriveType == DriveType.Removable)
                {
                    listDrive3.Items.Add(drive.Name);
                }

                if (listDrive3.Items.Count > 0)
                {
                    listDrive3.SelectedIndex = 0;
                    isHaveUSB         = true;
                    btnWrite3.Enabled = true;
                }
                else
                {
                    btnWrite3.Enabled = false;
                }
            }

            if (!(isHaveUSB || isHaveUSB))
            {
                MessageBox.Show("Không tìm thấy ổ đĩa/USB phù hợp");
                DialogResult = DialogResult.Cancel;
                Hide();
                Close();
            }

            // Create the volume label based on the current date if needed
            if (_sessionName.Equals(""))
            {
                _sessionName = DateTime.Now.ToString("yyyyMMdd_HHmm");
            }
        }
Exemple #30
0
        /// <summary>
        /// Get the current media type from drive letter
        /// </summary>
        /// <param name="drive"></param>
        /// <returns></returns>
        /// <remarks>
        /// This may eventually be replaced by Aaru.Devices being able to be about 10x more accurate.
        /// This will also end up making it so that IMAPI2 is no longer necessary. Unfortunately, that
        /// will only work for .NET Core 3.1 and beyond.
        /// </remarks>
        public (MediaType?, string) GetMediaType()
        {
            // Take care of the non-optical stuff first
            // TODO: See if any of these can be more granular, like Optical is
            if (this.InternalDriveType == Data.InternalDriveType.Floppy)
            {
                return(MediaType.FloppyDisk, null);
            }
            else if (this.InternalDriveType == Data.InternalDriveType.HardDisk)
            {
                return(MediaType.HardDisk, null);
            }
            else if (this.InternalDriveType == Data.InternalDriveType.Removable)
            {
                return(MediaType.FlashDrive, null);
            }

#if NET_FRAMEWORK
            // Get the current drive information
            string deviceId = null;
            bool   loaded   = false;
            try
            {
                // Get the device ID first
                var searcher = new ManagementObjectSearcher(
                    "root\\CIMV2",
                    $"SELECT * FROM Win32_CDROMDrive WHERE Id = '{this.Letter}:\'");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    deviceId = (string)queryObj["DeviceID"];
                    loaded   = (bool)queryObj["MediaLoaded"];
                }

                // If we got no valid device, we don't care and just return
                if (deviceId == null)
                {
                    return(null, "Device could not be found");
                }
                else if (!loaded)
                {
                    return(null, "Device is not reporting media loaded");
                }

                MsftDiscMaster2 discMaster = new MsftDiscMaster2();
                deviceId = deviceId.ToLower().Replace('\\', '#').Replace('/', '#');
                string id = null;
                foreach (var disc in discMaster)
                {
                    if (disc.ToString().Contains(deviceId))
                    {
                        id = disc.ToString();
                    }
                }

                // If we couldn't find the drive, we don't care and return
                if (id == null)
                {
                    return(null, "Device ID could not be found");
                }

                // Create the required objects for reading from the drive
                MsftDiscRecorder2 recorder = new MsftDiscRecorder2();
                recorder.InitializeDiscRecorder(id);
                MsftDiscFormat2Data dataWriter = new MsftDiscFormat2Data();

                // If the recorder is not supported, just return
                if (!dataWriter.IsRecorderSupported(recorder))
                {
                    return(null, "IMAPI2 recorder not supported");
                }

                // Otherwise, set the recorder to get information from
                dataWriter.Recorder = recorder;

                var media = dataWriter.CurrentPhysicalMediaType;
                return(media.IMAPIToMediaType(), null);
            }
            catch (Exception ex)
            {
                return(null, ex.Message);
            }
#else
            try
            {
                var device = new AaruDevices.Device(this.Name);
                if (device.Error)
                {
                    return(null, "Could not open device");
                }
                else if (device.Type != DeviceType.ATAPI && device.Type != DeviceType.SCSI)
                {
                    return(null, "Device does not support media type detection");
                }

                // TODO: In order to get the disc type, Aaru.Core will need to be included as a
                // package. Unfortunately, it currently has a conflict with one of the required libraries:
                // System.Text.Encoding.CodePages (BOS uses >= 5.0.0, DotNetZip uses >= 4.5.0 && < 5.0.0)
            }
            catch (Exception ex)
            {
                return(null, ex.Message);
            }

            return(null, "Media detection only supported on .NET Framework");
#endif
        }
Exemple #31
0
        /// <summary>
        /// Get the media type for a device path using the Aaru libraries
        /// </summary>
        /// <param name="devicePath">Path to the device</param>
        /// <param name="internalDriveType">Current internal drive type</param>
        /// <returns>MediaType, null on error</returns>
        private static (MediaType?, string) GetMediaType(string devicePath, InternalDriveType?internalDriveType)
        {
            char driveLetter = devicePath == null || !devicePath.Any() ? '\0' : devicePath[0];

            // Take care of the non-optical stuff first
            // TODO: See if any of these can be more granular, like Optical is
            if (internalDriveType == Data.InternalDriveType.Floppy)
            {
                return(MediaType.FloppyDisk, null);
            }
            else if (internalDriveType == Data.InternalDriveType.HardDisk)
            {
                return(MediaType.HardDisk, null);
            }
            else if (internalDriveType == Data.InternalDriveType.Removable)
            {
                return(MediaType.FlashDrive, null);
            }

            // Get the current drive information
            string deviceId = null;
            bool   loaded   = false;

            try
            {
                // Get the device ID first
                var searcher = new ManagementObjectSearcher(
                    "root\\CIMV2",
                    $"SELECT * FROM Win32_CDROMDrive WHERE Id = '{driveLetter}:\'");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    deviceId = (string)queryObj["DeviceID"];
                    loaded   = (bool)queryObj["MediaLoaded"];
                }

                // If we got no valid device, we don't care and just return
                if (deviceId == null)
                {
                    return(null, "Device could not be found");
                }
                else if (!loaded)
                {
                    return(null, "Device is not reporting media loaded");
                }

                MsftDiscMaster2 discMaster = new MsftDiscMaster2();
                deviceId = deviceId.ToLower().Replace('\\', '#').Replace('/', '#');
                string id = null;
                foreach (var disc in discMaster)
                {
                    if (disc.ToString().Contains(deviceId))
                    {
                        id = disc.ToString();
                    }
                }

                // If we couldn't find the drive, we don't care and return
                if (id == null)
                {
                    return(null, "Device ID could not be found");
                }

                // Create the required objects for reading from the drive
                MsftDiscRecorder2 recorder = new MsftDiscRecorder2();
                recorder.InitializeDiscRecorder(id);
                MsftDiscFormat2Data dataWriter = new MsftDiscFormat2Data();

                // If the recorder is not supported, just return
                if (!dataWriter.IsRecorderSupported(recorder))
                {
                    return(null, "IMAPI2 recorder not supported");
                }

                // Otherwise, set the recorder to get information from
                dataWriter.Recorder = recorder;

                var media = dataWriter.CurrentPhysicalMediaType;
                return(media.IMAPIToMediaType(), null);
            }
            catch (Exception ex)
            {
                return(null, ex.Message);
            }
        }
Exemple #32
0
        /// <summary>
        /// Get the current disc type from drive letter
        /// </summary>
        /// <param name="driveLetter"></param>
        /// <returns></returns>
        /// <remarks>
        /// https://stackoverflow.com/questions/11420365/detecting-if-disc-is-in-dvd-drive
        /// </remarks>
        public static MediaType?GetDiscType(char?driveLetter)
        {
            // Get the DeviceID from the current drive letter
            string deviceId = null;

            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                                                 "SELECT * FROM Win32_CDROMDrive WHERE Id = '" + driveLetter + ":\'");

                var collection = searcher.Get();
                foreach (ManagementObject queryObj in collection)
                {
                    deviceId = (string)queryObj["DeviceID"];
                }
            }
            catch
            {
                // We don't care what the error was
                return(null);
            }

            // If we got no valid device, we don't care and just return
            if (deviceId == null)
            {
                return(null);
            }

            // Get all relevant disc information
            try
            {
                MsftDiscMaster2 discMaster = new MsftDiscMaster2();
                deviceId = deviceId.ToLower().Replace('\\', '#');
                string id = null;
                foreach (var disc in discMaster)
                {
                    if (disc.ToString().Contains(deviceId))
                    {
                        id = disc.ToString();
                    }
                }

                // If we couldn't find the drive, we don't care and return
                if (id == null)
                {
                    return(null);
                }

                // Otherwise, we get the media type, if any
                MsftDiscRecorder2 recorder = new MsftDiscRecorder2();
                recorder.InitializeDiscRecorder(id);
                MsftDiscFormat2Data dataWriter = new MsftDiscFormat2Data();
                dataWriter.Recorder = recorder;
                var media = dataWriter.CurrentPhysicalMediaType;
                if (media != IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_UNKNOWN)
                {
                    return(Converters.ToMediaType(media));
                }
            }
            catch
            {
                // We don't care what the error is
            }

            return(null);
        }
Exemple #33
-1
        public DevicesManager()
        {
            discMaster = new MsftDiscMaster2();

            devicesList = new List <MsftDiscRecorder2>();
            try
            {
                if (!discMaster.IsSupportedEnvironment)
                {
                    return;
                }
                foreach (string uniqueRecorderId in discMaster)
                {
                    var discRecorder2 = new MsftDiscRecorder2();
                    discRecorder2.InitializeDiscRecorder(uniqueRecorderId);

                    devicesList.Add(discRecorder2);
                }
            }
            catch (COMException)
            {
                return;
            }
            finally
            {
                if (discMaster != null)
                {
                    Marshal.ReleaseComObject(discMaster);
                }
            }
        }