protected override void Initialize()
        {
            base.Initialize();

            if (this.State == ConversionState.Failed)
            {
                return;
            }

            if (this.ConversionPreset == null)
            {
                throw new System.Exception("The conversion preset must be valid.");
            }

            // Initialize converters.
            if (this.ConversionPreset.OutputType == OutputType.Pdf)
            {
                this.intermediateFilePath = this.OutputFilePath;
            }
            else
            {
                // Generate intermediate file path.
                string fileName = Path.GetFileNameWithoutExtension(this.InputFilePath);
                string tempPath = Path.GetTempPath();
                this.intermediateFilePath = PathHelpers.GenerateUniquePath(tempPath + fileName + ".pdf");

                ConversionPreset intermediatePreset = new ConversionPreset("Pdf to image", this.ConversionPreset, "pdf");
                this.pdf2ImageConversionJob = ConversionJobFactory.Create(intermediatePreset, this.intermediateFilePath);
                this.pdf2ImageConversionJob.PrepareConversion(this.OutputFilePaths);
            }
        }
        protected override void Initialize()
        {
            base.Initialize();

            if (this.ConversionPreset == null)
            {
                throw new Exception("The conversion preset must be valid.");
            }

            // Generate intermediate file path.
            string fileName = Path.GetFileName(this.OutputFilePath);
            string tempPath = Path.GetTempPath();

            this.intermediateFilePath = PathHelpers.GenerateUniquePath(tempPath + fileName + ".png");

            // Convert input in png file to send it to ffmpeg for the ico conversion.
            ConversionPreset intermediatePreset = new ConversionPreset("To compatible image", OutputType.Png, this.ConversionPreset.InputTypes.ToArray());

            intermediatePreset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageClampSizePowerOf2, "True");
            intermediatePreset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageMaximumSize, "256");
            this.pngConversionJob = ConversionJobFactory.Create(intermediatePreset, this.InputFilePath);
            this.pngConversionJob.PrepareConversion(this.intermediateFilePath);

            // Convert png file into ico.
            this.icoConversionJob = new ConversionJob_FFMPEG(this.ConversionPreset, this.intermediateFilePath);
            this.icoConversionJob.PrepareConversion(this.OutputFilePath);
        }
예제 #3
0
        protected override void Initialize()
        {
            base.Initialize();

            if (this.ConversionPreset == null)
            {
                throw new Exception("The conversion preset must be valid.");
            }

            string extension = System.IO.Path.GetExtension(this.InputFilePath);

            extension = extension.ToLowerInvariant().Substring(1, extension.Length - 1);

            string inputFilePath = string.Empty;

            // If the output is an image start to convert it into png before send it to ffmpeg.
            if (Helpers.GetExtensionCategory(extension) == Helpers.InputCategoryNames.Image && extension != "png")
            {
                // Generate intermediate file path.
                string fileName = Path.GetFileName(this.OutputFilePath);
                string tempPath = Path.GetTempPath();
                this.intermediateFilePath = PathHelpers.GenerateUniquePath(tempPath + fileName + ".png");

                // Convert input in png file to send it to ffmpeg for the gif conversion.
                ConversionPreset intermediatePreset = new ConversionPreset("To compatible image", OutputType.Png, this.ConversionPreset.InputTypes.ToArray());
                this.pngConversionJob = ConversionJobFactory.Create(intermediatePreset, this.InputFilePath);
                this.pngConversionJob.PrepareConversion(this.intermediateFilePath);

                inputFilePath = this.intermediateFilePath;
            }
            else
            {
                inputFilePath = this.InputFilePath;
            }

            // Convert png file into ico.
            this.gifConversionJob = new ConversionJob_FFMPEG(this.ConversionPreset, inputFilePath);
            this.gifConversionJob.PrepareConversion(this.OutputFilePath);
        }
        protected override void Initialize()
        {
            base.Initialize();

            if (this.ConversionPreset == null)
            {
                throw new Exception("The conversion preset must be valid.");
            }

            // Retrieve and check drive letter.
            string pathDriveLetter = PathHelpers.GetPathDriveLetter(this.InputFilePath);

            if (pathDriveLetter.Length == 0)
            {
                this.ConversionFailed(Properties.Resources.ErrorFailToRetrieveInputPathDriveLetter);
                return;
            }

            char driveLetter = pathDriveLetter[0];

            this.diskDrive            = new Ripper.CDDrive();
            this.diskDrive.CDRemoved += new EventHandler(this.CdDriveCdRemoved);

            bool driveLetterFound = false;

            char[] driveLetters = Ripper.CDDrive.GetCDDriveLetters();
            for (int index = 0; index < driveLetters.Length; index++)
            {
                driveLetterFound |= driveLetters[index] == driveLetter;
            }

            if (!driveLetterFound)
            {
                Debug.Log($"Invalid drive letter {driveLetter}.");
                this.ConversionFailed(Properties.Resources.ErrorFailToRetrieveInputPathDriveLetter);
                return;
            }

            // Retrieve and track number.
            try
            {
                this.cdaTrackNumber = PathHelpers.GetCDATrackNumber(this.InputFilePath);
            }
            catch (Exception)
            {
                Debug.Log($"Input path: '{this.InputFilePath}'.");
                this.ConversionFailed(Properties.Resources.ErrorFailToRetrieveTrackNumber);
                return;
            }

            if (this.diskDrive.IsOpened)
            {
                this.ConversionFailed(Properties.Resources.ErrorFailToUseCDDriveOpen);
                return;
            }

            if (!this.diskDrive.Open(driveLetter))
            {
                this.ConversionFailed(string.Format(Properties.Resources.ErrorFailToReadCDDrive, driveLetter));
                return;
            }

            // Generate intermediate file path.
            string fileName = Path.GetFileName(this.OutputFilePath);
            string tempPath = Path.GetTempPath();

            this.intermediateFilePath = PathHelpers.GenerateUniquePath(tempPath + fileName + ".wav");

            // Sub conversion job (for compression).
            this.compressionConversionJob = ConversionJobFactory.Create(this.ConversionPreset, this.intermediateFilePath);
            this.compressionConversionJob.PrepareConversion(this.OutputFilePath);
            this.compressionThread = Helpers.InstantiateThread("CDACompressionThread", this.CompressAsync);
        }