private void ReportError(BurnResult aBurnResult, ProjectType aProjectType)
 {
     if (BurningFailed != null)
     {
         BurningFailed(aBurnResult, aProjectType);
     }
 }
        private void burnManager_BurningFailed(BurnResult eBurnResult, ProjectType eProjectType)
        {
            if (lbBurningStatus.InvokeRequired)
            {
                ThreadSafeBurnAudioFailedDelegate d = burnManager_BurningFailed;
                lbBurningStatus.Invoke(d, new object[] { eBurnResult, eProjectType });
                return;
            }

            lbBurningStatus.Text = string.Format(localisation.ToString("Burning", "Failed"),
                                                 Enum.GetName(typeof(BurnResult), eBurnResult));
            log.Error("Burning Failed: {0}", Enum.GetName(typeof(BurnResult), eBurnResult));
        }
        public BurnResult BurnIsoFile(ProjectType aProjectType, string aIsoToBurn)
        {
            ReportProgress(BurnStatus.Checking, 0);
            BurnResult result = BurnResult.Unknown;

            if (!IsBurningPossible(aProjectType, true, out result))
            {
                ReportError(result, aProjectType);
                return(result);
            }
            result = BurnIsoToDisk(aIsoToBurn, false);
            if (result != BurnResult.Successful)
            {
                ReportError(result, aProjectType);
            }
            return(result);
        }
        public BurnResult BurnFolder(ProjectType aProjectType, string aPathToBurn)
        {
            ReportProgress(BurnStatus.Checking, 0);
            BurnResult result = BurnResult.Unknown;

            if (!IsBurningPossible(aProjectType, true, out result))
            {
                ReportError(result, aProjectType);
                return(result);
            }
            // make sure it always ends with a slash;
            string fullPathname = Path.GetDirectoryName(aPathToBurn + @"\") + @"\";

            if (!CheckRequiredSpaceForPath(aProjectType, fullPathname))
            {
                result = BurnResult.NotEnoughSpace;
                ReportError(result, aProjectType);
                return(result);
            }

            string unixFilename = "\"" + fullPathname.Replace('\\', '/') + "\"";
            string cacheFile    = Path.Combine(Path.GetTempPath(), "MP2-temp.iso");
            // build iso from path
            string IsoBuildArgs = DeviceHelper.GetCommonParamsForIsocreation("MP-II_" + DateTime.Now.ToShortDateString(),
                                                                             cacheFile);

            IsoBuildArgs += DeviceHelper.GetParamsByMedia(aProjectType);
            IsoBuildArgs += unixFilename;

            log.Info("BurnManager: Creating ISO of folder: {0} as {1}", fullPathname, cacheFile);
            DeviceHelper.ExecuteProcReturnStdOut("mkisofs.exe", IsoBuildArgs, 1800000);
            // assume 30 minutes max to create a 4,7 GB Iso

            result = BurnIsoToDisk(cacheFile, true);
            if (result != BurnResult.Successful)
            {
                ReportError(result, aProjectType);
            }
            return(result);
        }
        public BurnResult BurnAudioCd(List <string> aFilesToBurn)
        {
            List <string> MyCommandOutput = new List <string>(50);

            ReportProgress(BurnStatus.Checking, 0);
            BurnResult result = BurnResult.Unknown;

            if (!IsBurningPossible(ProjectType.AudioCD, true, out result))
            {
                ReportError(result, ProjectType.AudioCD);
                return(result);
            }

            string audioFiles = "";

            foreach (string audiofile in aFilesToBurn)
            {
                audioFiles += "\"" + audiofile + "\" ";
            }

            string burnCdArgs = DeviceHelper.GetCommonParamsForDevice(CurrentDrive);

            burnCdArgs += string.Format(" -speed={0}", CurrentDrive.SelectedWriteSpeed);
            burnCdArgs += " -pad -audio " + audioFiles;
            log.Info("BurnManager: Start Burning of Audio CD");
            ReportProgress(BurnStatus.Burning, 0);

            MyCommandOutput = DeviceHelper.ExecuteProcReturnStdOut("cdrecord.exe", burnCdArgs, 3600000);

            if (CurrentStatus == BurnStatus.Finished && !MyCommandOutput.Contains(@"A write error occured."))
            {
                return(BurnResult.Successful);
            }
            else
            {
                ReportError(result, ProjectType.AudioCD);
                return(BurnResult.ErrorBurning);
            }
        }
        public BurnResult BurnCdClone()
        {
            // readcd dev=3,0,0 speed=52 -clone -noerror f=/cygdrive/D/Temp/Burner/testcd.iso
            // cdda2wav dev=3,0,0 verbose-level=summary -gui -bulk -no-infofile track=1+2 /cygdrive/D/Temp/Burner/track
            ReportProgress(BurnStatus.Checking, 0);
            BurnResult result = BurnResult.Unknown;

            if (!IsBurningPossible(ProjectType.DataCD, false, out result))
            {
                ReportError(result, ProjectType.DataCD);
                return(result);
            }
            string cacheFile  = Path.Combine(Path.GetTempPath(), "MP2-temp.iso");
            string readCdArgs = "dev=" + CurrentDrive.BusId + " retries=128 -v -clone -nocorr -notrunc f=\"" + cacheFile +
                                "\"";

            log.Info("BurnManager: Creating clone of inserted disk as {0}", cacheFile);
            ReportProgress(BurnStatus.Caching, 0);
            DeviceHelper.ExecuteProcReturnStdOut("readcd.exe", readCdArgs, 900000); // assume 15 minutes max for cloning

            // Swap source cd for the burning medium
            DeviceHelper.ExecuteProcReturnStdOut("cdrecord.exe", "dev=" + CurrentDrive.BusId + " -eject", 10000);
            Thread.Sleep(15000); // add input handler here

            if (!IsBurningPossible(ProjectType.DataCD, true, out result))
            {
                ReportError(result, ProjectType.DataCD);
                return(result);
            }
            result = BurnIsoToDisk(cacheFile, true);
            if (result != BurnResult.Successful)
            {
                ReportError(result, ProjectType.DataCD);
            }
            return(result);
        }
 private void burnManager_BurningFailed(BurnResult eBurnResult, ProjectType eProjectType)
 {
     log.Info("BurnEvent: Burning of {0} failed with result: {1}", eProjectType.ToString(), eBurnResult.ToString());
 }
        private void burnManager_BurningFailed(BurnResult eBurnResult, ProjectType eProjectType)
        {
            if (lbBurningStatus.InvokeRequired)
              {
            ThreadSafeBurnAudioFailedDelegate d = burnManager_BurningFailed;
            lbBurningStatus.Invoke(d, new object[] {eBurnResult, eProjectType});
            return;
              }

              lbBurningStatus.Text = string.Format(localisation.ToString("Burning", "Failed"),
                                           Enum.GetName(typeof (BurnResult), eBurnResult));
              log.Error("Burning Failed: {0}", Enum.GetName(typeof (BurnResult), eBurnResult));
        }
        private void BurningThread()
        {
            log.Trace(">>>");
            List <string> outFiles = new List <string>();
            bool          bError   = false;

            foreach (DataGridViewRow row in dataGridViewBurn.Rows)
            {
                TrackData track   = bindingList[row.Index];
                string    outFile = String.Format(@"{0}\{1}.wav", tmpBurnDirectory,
                                                  Path.GetFileNameWithoutExtension(track.FullFileName));

                int stream = Bass.BASS_StreamCreateFile(track.FullFileName, 0, 0, BASSFlag.BASS_STREAM_DECODE);
                if (stream == 0)
                {
                    bError = true;
                    log.Error("Error creating stream for {0}.", track.FullFileName);
                    continue;
                }

                // In order to burn a file to CD, it must be stereo and 44kz
                // To make sure that we have that, we create a mixer channel and add our stream to it
                // The mixer will do the resampling
                int mixer = BassMix.BASS_Mixer_StreamCreate(44100, 2, BASSFlag.BASS_STREAM_DECODE);
                if (mixer == 0)
                {
                    bError = true;
                    log.Error("Error creating mixer for {0}.", track.FullFileName);
                    continue;
                }

                // Now add the stream to the mixer
                BassMix.BASS_Mixer_StreamAddChannel(mixer, stream, 0);

                log.Info("Decoding to WAV: {0}", track.FullFileName);
                BassEnc.BASS_Encode_Start(mixer, outFile, BASSEncode.BASS_ENCODE_PCM, null, IntPtr.Zero);

                long pos        = 0;
                long chanLength = Bass.BASS_ChannelGetLength(stream);

                byte[] encBuffer = new byte[20000]; // our encoding buffer
                while (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING)
                {
                    // getting sample data will automatically feed the encoder
                    int len = Bass.BASS_ChannelGetData(mixer, encBuffer, encBuffer.Length);
                    pos = Bass.BASS_ChannelGetPosition(mixer);
                    double percentComplete = pos / (double)chanLength * 100.0;
                    dataGridViewBurn.Rows[row.Index].Cells[0].Value = (int)percentComplete;
                }
                outFiles.Add(outFile);
                dataGridViewBurn.Rows[row.Index].Cells[0].Value = 100;
                BassEnc.BASS_Encode_Stop(mixer);
                Bass.BASS_StreamFree(stream);
                Bass.BASS_StreamFree(mixer);
            }

            burnManager.BurningFailed      += burnManager_BurningFailed;
            burnManager.BurnProgressUpdate += burnManager_BurnProgressUpdate;
            if (!bError && MediaAllowsBurning())
            {
                foreach (DataGridViewRow row in dataGridViewBurn.Rows)
                {
                    dataGridViewBurn.Rows[row.Index].Cells[0].Value = 0;
                }

                BurnResult result = burnManager.BurnAudioCd(outFiles);
                if (result == BurnResult.Successful)
                {
                    log.Info("Burning of Audio CD was successful");
                }
                else
                {
                    log.Error("Burning of Audio CD failed");
                }
            }

            log.Trace("<<<");
        }
Example #10
0
 private void burnManager_BurningFailed(BurnResult eBurnResult, ProjectType eProjectType)
 {
     log.Info("BurnEvent: Burning of {0} failed with result: {1}", eProjectType.ToString(), eBurnResult.ToString());
 }
 private void ReportError(BurnResult aBurnResult, ProjectType aProjectType)
 {
     if (BurningFailed != null)
     BurningFailed(aBurnResult, aProjectType);
 }
        /// <summary>
        ///   Query this to find out e.g. whether to display the option to burn for a specific item.
        /// </summary>
        /// <param name = "aProjectType">Does the item need a DVD or maybe an Audio-CD?</param>
        /// <param name = "aCheckMediaStatus">Check the current inserted media as well and fail if not suitable</param>
        /// <param name = "aBurnResult">For details on errors. Set to "Unknown" when calling</param>
        /// <returns></returns>
        public bool IsBurningPossible(ProjectType aProjectType, bool aCheckMediaStatus, out BurnResult aBurnResult)
        {
            // No burner found / set
              if (CurrentDrive == null)
              {
            aBurnResult = BurnResult.NoDriveAvailable;
            return false;
              }
              // E.g. CD-Burner does not support Data-DVD
              if (!MediaTypeSupport.CheckBurnerRequirements(aProjectType, CurrentDrive))
              {
            aBurnResult = BurnResult.UnsupportedInput;
            return false;
              }

              // Is the currently inserted Media ready for burning?
              if (aCheckMediaStatus)
              {
            // Check whether the correct type (CD,DVD) of media is inserted
            if (!MediaTypeSupport.CheckInsertedMediaType(aProjectType, CurrentDrive))
            {
              aBurnResult = BurnResult.WrongMediaType;
              return false;
            }
            // E.g. Does our DVD-R writer support the DVD+RW in tray
            if (!CheckInsertedMediaSupported(CurrentDrive))
            {
              aBurnResult = BurnResult.UnsupportedMedia;
              return false;
            }
            // Check if disk was already finalized, Auto-Blank Rewritable media
            if (!CheckInsertedMediaBlankStatus(CurrentDrive, true))
            {
              aBurnResult = BurnResult.NotEnoughSpace;
              return false;
            }
              }

              aBurnResult = BurnResult.Ready;
              return true;
        }
Example #13
0
        /// <summary>
        ///   Query this to find out e.g. whether to display the option to burn for a specific item.
        /// </summary>
        /// <param name = "aProjectType">Does the item need a DVD or maybe an Audio-CD?</param>
        /// <param name = "aCheckMediaStatus">Check the current inserted media as well and fail if not suitable</param>
        /// <param name = "aBurnResult">For details on errors. Set to "Unknown" when calling</param>
        /// <returns></returns>
        public bool IsBurningPossible(ProjectType aProjectType, bool aCheckMediaStatus, out BurnResult aBurnResult)
        {
            // No burner found / set
            if (CurrentDrive == null)
            {
                aBurnResult = BurnResult.NoDriveAvailable;
                return(false);
            }
            // E.g. CD-Burner does not support Data-DVD
            if (!MediaTypeSupport.CheckBurnerRequirements(aProjectType, CurrentDrive))
            {
                aBurnResult = BurnResult.UnsupportedInput;
                return(false);
            }

            // Is the currently inserted Media ready for burning?
            if (aCheckMediaStatus)
            {
                // Check whether the correct type (CD,DVD) of media is inserted
                if (!MediaTypeSupport.CheckInsertedMediaType(aProjectType, CurrentDrive))
                {
                    aBurnResult = BurnResult.WrongMediaType;
                    return(false);
                }
                // E.g. Does our DVD-R writer support the DVD+RW in tray
                if (!CheckInsertedMediaSupported(CurrentDrive))
                {
                    aBurnResult = BurnResult.UnsupportedMedia;
                    return(false);
                }
                // Check if disk was already finalized, Auto-Blank Rewritable media
                if (!CheckInsertedMediaBlankStatus(CurrentDrive, true))
                {
                    aBurnResult = BurnResult.NotEnoughSpace;
                    return(false);
                }
            }

            aBurnResult = BurnResult.Ready;
            return(true);
        }