Ejemplo n.º 1
0
        }        // -----------------------------------------

        /// <summary>
        /// Compress a CD to output folder
        /// </summary>
        /// <param name="_Input">Input file, must be `.cue`</param>
        /// <param name="_Output">Output folder, If null, it will be same as input file folder</param>
        /// <param name="_Audio">Audio Quality to encode the audio tracks with.</param>
        /// <param name="_Cover">Cover Image to store in the archive</param>
        /// <param name="_Title">Title of the CD</param>
        /// <param name="onComplete">Completed (completeStatus,MD5,CrushedSize)</param>
        /// <returns></returns>
        public static bool crushCD(string _Input, string _Output, int _Audio, string _Cover, string _Title,
                                   Action <bool, string, int> onComplete)
        {
            // NOTE : JOB checks for input file
            if (LOCKED)
            {
                ERROR = "Engine is working"; return(false);
            }
            if (!FFMPEG_OK)
            {
                ERROR = "FFmpeg is not set"; return(false);
            }

            LOCKED = true;

            var par = new CrushParams();

            par.inputFile    = _Input;
            par.outputDir    = _Output;
            par.audioQuality = _Audio;
            par.cover        = _Cover;
            par.cdTitle      = _Title;

            var j = new JobCrush(par);

            j.MAX_CONCURRENT = MAX_TASKS;

            j.onComplete = (s) =>
            {
                LOCKED = false;
                ERROR  = j.ERROR[1];
                if (s)
                {
                    CueReader cd = (CueReader)j.jobData.cd;
                    onComplete(s, cd.getFirstDataTrackMD5(), j.jobData.crushedSize);                           // Hack, send CDINFO and SIZE as well
                }
                else
                {
                    onComplete(s, "", 0);
                }
            };

            j.onJobStatus = jobStatusHandler;                           // For status and progress updates
            j.start();

            return(true);
        }        // -----------------------------------------
Ejemplo n.º 2
0
        }        // -----------------------------------------

        /// <summary>
        /// Take a crushed archive and extract only the info file, Returns a customized object with some info
        /// </summary>
        /// <param name="arcFile"></param>
        /// <param name="onComplete">(null) if error</param>
        public static bool loadQuickInfo(string arcFile, Action <Object> onComplete)
        {
            if (LOCKED)
            {
                ERROR = "LOCKED";
                return(false);
            }

            if (!check_file_(arcFile, CDCRUSH_EXTENSION))
            {
                return(false);
            }

            LOCKED = true;

            // Delete old files from previous quickInfos
            FileTools.tryDelete(Path.Combine(TEMP_FOLDER, CDCRUSH_SETTINGS));
            FileTools.tryDelete(Path.Combine(TEMP_FOLDER, CDCRUSH_COVER));

            var arc = new FreeArc(TOOLS_PATH);

            // --
            arc.onComplete = (success) =>
            {
                LOCKED = false;

                if (success)                // OK
                {
                    // Continue
                    var cd = new CueReader();
                    if (!cd.loadJson(Path.Combine(TEMP_FOLDER, CDCRUSH_SETTINGS)))
                    {
                        ERROR = cd.ERROR;
                        onComplete(null);
                        return;
                    }

                    var info = new
                    {
                        title  = cd.CD_TITLE,
                        size0  = (int)new FileInfo(arcFile).Length,
                        size1  = cd.CD_TOTAL_SIZE,
                        audio  = cd.CD_AUDIO_QUALITY,
                        tracks = cd.tracks.Count,
                        md5    = cd.getFirstDataTrackMD5(),
                        cover  = Path.Combine(TEMP_FOLDER, CDCRUSH_COVER)
                    };

                    onComplete(info);
                }
                else
                {
                    ERROR = arc.ERROR;
                    onComplete(null);
                }
            };

            // : Actually extract
            arc.extractFiles(arcFile, new[] { CDCRUSH_SETTINGS, CDCRUSH_COVER }, TEMP_FOLDER);

            return(true);
        }        // -----------------------------------------