コード例 #1
0
        }// -----------------------------------------

        // -
        public override void start()
        {
            CrushParams p = jobData;

            LOG.line();
            LOG.log("=== CONVERTING A CD with the following parameters :");
            LOG.log("- Input : {0}", p.inputFile);
            LOG.log("- Output Dir : {0}", p.outputDir);
            LOG.log("- Temp Dir : {0}", p.tempDir);
            LOG.log("- CD Title  : {0}", p.cdTitle);
            LOG.log("- Audio Quality : {0}", CDCRUSH.getAudioQualityString(p.audioQuality));
            base.start();
        }// -----------------------------------------
コード例 #2
0
        // --
        public JobCrush(CrushParams p) : base("Compress CD")
        {
            // Check for input files
            // :: --------------------
            if (!CDCRUSH.check_file_(p.inputFile, ".cue"))
            {
                fail(msg: CDCRUSH.ERROR);
                return;
            }

            if (string.IsNullOrEmpty(p.outputDir))
            {
                p.outputDir = Path.GetDirectoryName(p.inputFile);
            }

            if (!FileTools.createDirectory(p.outputDir))
            {
                fail(msg: "Can't create Output Dir " + p.outputDir);
                return;
            }

            p.tempDir = Path.Combine(CDCRUSH.TEMP_FOLDER, Guid.NewGuid().ToString().Substring(0, 12));
            if (!FileTools.createDirectory(p.tempDir))
            {
                fail(msg: "Can't create TEMP dir");
                return;
            }

            // IMPORTANT!! sharedData gets set by value, NOT A POINTER, do not make changes to p after this
            jobData = p;

            // --
            // - Read the CUE file ::
            add(new CTask((t) =>
            {
                var cd     = new CueReader();
                jobData.cd = cd;

                if (!cd.load(p.inputFile))
                {
                    t.fail(msg: cd.ERROR);
                    return;
                }

                // Post CD CUE load ::

                // In case user named the CD, otherwise it's going to be the same
                if (!string.IsNullOrWhiteSpace(p.cdTitle))
                {
                    cd.CD_TITLE = FileTools.sanitizeFilename(p.cdTitle);
                }

                // Real quality to string name
                cd.CD_AUDIO_QUALITY = CDCRUSH.getAudioQualityString(p.audioQuality);

                // This flag notes that all files will go to the TEMP folder
                jobData.workFromTemp = !cd.MULTIFILE;

                // Generate the final arc name now that I have the CD TITLE
                jobData.finalArcPath = Path.Combine(p.outputDir, cd.CD_TITLE + ".arc");

                t.complete();
            }, "Reading", true));


            // - Cut tracks
            // ---------------------------
            add(new TaskCutTrackFiles());

            // - Compress tracks
            // ---------------------
            add(new CTask((t) =>
            {
                CueReader cd = jobData.cd;
                foreach (CueTrack tr in cd.tracks)
                {
                    addNextAsync(new TaskCompressTrack(tr));
                }        //--
                t.complete();
            }, "Preparing"));


            // Create Archive
            // Add all tracks to the final archive
            // ---------------------
            add(new CTask((t) => {
                CueReader cd = jobData.cd;

                // -- Get list of files::
                System.Collections.ArrayList files = new System.Collections.ArrayList();
                foreach (var tr in cd.tracks)
                {
                    files.Add(tr.workingFile);             // Working file is valid, was set earlier
                }

                // Compress all the track files
                var arc = new FreeArc(CDCRUSH.TOOLS_PATH);
                t.handleCliReport(arc);
                arc.compress((string[])files.ToArray(typeof(string)), jobData.finalArcPath, p.compressionLevel);

                t.killExtra = () => arc.kill();
            }, "Compressing"));


            // - Create CD SETTINGS and push it to the final archive
            // ( I am appending these files so that they can be quickly loaded later )
            // --------------------
            add(new CTask((t) =>
            {
                CueReader cd = jobData.cd;

                        #if DEBUG
                cd.debugInfo();
                        #endif

                string path_settings = Path.Combine(p.tempDir, CDCRUSH.CDCRUSH_SETTINGS);
                if (!cd.saveJson(path_settings))
                {
                    t.fail(msg: cd.ERROR);
                    return;
                }

                // - Cover Image Set?
                string path_cover;
                if (p.cover != null)
                {
                    path_cover = Path.Combine(p.tempDir, CDCRUSH.CDCRUSH_COVER);
                    File.Copy(p.cover, path_cover);
                }
                else
                {
                    path_cover = null;
                }

                // - Append the file(s)
                var arc = new FreeArc(CDCRUSH.TOOLS_PATH);
                t.handleCliReport(arc);
                arc.appendFiles(new string[] { path_settings, path_cover }, jobData.finalArcPath);

                t.killExtra = () => arc.kill();
            }, "Finalizing"));

            // - Get post data
            add(new CTask((t) =>
            {
                var finfo           = new FileInfo(jobData.finalArcPath);
                jobData.crushedSize = (int)finfo.Length;
                t.complete();
            }, "Finalizing"));

            // -- COMPLETE --
        }// -----------------------------------------
コード例 #3
0
        // --
        public JobConvertCue(CrushParams p) : base("Convert CD")
        {
            // Check for input files
            // :: --------------------
            if (!CDCRUSH.check_file_(p.inputFile, ".cue"))
            {
                fail(msg: CDCRUSH.ERROR);
                return;
            }

            if (string.IsNullOrEmpty(p.outputDir))
            {
                p.outputDir = Path.GetDirectoryName(p.inputFile);
            }

            // : NEW :
            // : ALWAYS Create a subfolder to avoid overwriting the source files
            p.outputDir = CDCRUSH.checkCreateUniqueOutput(p.outputDir, p.cdTitle + CDCRUSH.RESTORED_FOLDER_SUFFIX);
            if (p.outputDir == null)
            {
                fail("Output Dir Error " + p.outputDir);
                return;
            }

            // -
            p.tempDir = Path.Combine(CDCRUSH.TEMP_FOLDER, Guid.NewGuid().ToString().Substring(0, 12));
            if (!FileTools.createDirectory(p.tempDir))
            {
                fail(msg: "Can't create TEMP dir");
                return;
            }

            // Useful to know.
            p.flag_convert_only = true;

            // IMPORTANT!! sharedData gets set by value, NOT A POINTER, do not make changes to p after this
            jobData = p;

            hack_setExpectedProgTracks(p.expectedTracks + 2);

            // --
            // - Read the CUE file ::
            add(new CTask((t) =>
            {
                var cd     = new CueReader();
                jobData.cd = cd;

                if (!cd.load(p.inputFile))
                {
                    t.fail(msg: cd.ERROR);
                    return;
                }

                // --
                if (cd.tracks.Count == 1)
                {
                    t.fail(msg: "No point in converting. No audio tracks on the cd.");
                    return;
                }

                // Meaning the tracks are going to be extracted in the temp folder
                jobData.flag_sourceTracksOnTemp = (!cd.MULTIFILE && cd.tracks.Count > 1);

                // In case user named the CD, otherwise it's going to be the same
                if (!string.IsNullOrWhiteSpace(p.cdTitle))
                {
                    cd.CD_TITLE = FileTools.sanitizeFilename(p.cdTitle);
                }

                // Real quality to string name
                cd.CD_AUDIO_QUALITY = CDCRUSH.getAudioQualityString(p.audioQuality);

                t.complete();
            }, "-Reading"));


            // - Cut tracks
            // ---------------------------
            add(new TaskCutTrackFiles());

            // - Compress tracks
            // ---------------------
            add(new CTask((t) =>
            {
                // Only encode the audio tracks
                foreach (CueTrack tr in (jobData.cd as CueReader).tracks)
                {
                    if (!tr.isData)
                    {
                        addNextAsync(new TaskCompressTrack(tr));
                    }
                }
                t.complete();
            }, "-Preparing"));

            // - Create new CUE file
            // --------------------
            add(new CTask((t) =>
            {
                CueReader cd = jobData.cd;

                // DEV: So far :
                // track.trackFile is UNSET. cd.saveCue needs it to be set.
                // track.workingFile points to a valid file, some might be in TEMP folder and some in input folder (data tracks)

                int stepProgress = (int)Math.Round(100.0f / cd.tracks.Count);

                // -- Move files to output folder
                foreach (var track in cd.tracks)
                {
                    if (!cd.MULTIFILE)
                    {
                        // Fix the index times to start with 00:00:00
                        track.setNewTimesReset();
                    }

                    string ext = Path.GetExtension(track.workingFile);

                    track.trackFile = $"{cd.CD_TITLE} (track {track.trackNo}){ext}";

                    // Data track was not cut or encoded.
                    // It's in the input folder, don't move it
                    if (track.isData && cd.MULTIFILE)
                    {
                        FileTools.tryCopy(track.workingFile, Path.Combine(p.outputDir, track.trackFile));
                    }
                    else
                    {
                        // TaskCompress already put the audio files on the output folder
                        // But it's no big deal calling it again
                        // This is for the data tracks that are on the temp folder
                        FileTools.tryMove(track.workingFile, Path.Combine(p.outputDir, track.trackFile));
                    }

                    t.PROGRESS += stepProgress;
                }

                //-- Create the new CUE file
                if (!cd.saveCUE(Path.Combine(p.outputDir, cd.CD_TITLE + ".cue")))
                {
                    t.fail(cd.ERROR); return;
                }

                t.complete();
            }, "Finalizing"));

            // -- COMPLETE --
        }// -----------------------------------------
コード例 #4
0
        // --
        public JobConvertCue(CrushParams p) : base("Convert CD")
        {
            // Check for input files
            // :: --------------------
            if (!CDCRUSH.check_file_(p.inputFile, ".cue"))
            {
                fail(msg: CDCRUSH.ERROR);
                return;
            }

            if (string.IsNullOrEmpty(p.outputDir))
            {
                p.outputDir = Path.GetDirectoryName(p.inputFile);
            }

            // : NEW :
            // : ALWAYS Create a subfolder to avoid overwriting the source files
            try {
                p.outputDir = Path.Combine(p.outputDir, p.cdTitle + FOLDER_SUFFIX);
            }
            catch (ArgumentException) {
                fail("Output Dir Error " + p.outputDir);
                return;
            }

            if (!FileTools.createDirectory(p.outputDir))
            {
                fail(msg: "Can't create Output Dir " + p.outputDir);
                return;
            }

            p.tempDir = Path.Combine(CDCRUSH.TEMP_FOLDER, Guid.NewGuid().ToString().Substring(0, 12));
            if (!FileTools.createDirectory(p.tempDir))
            {
                fail(msg: "Can't create TEMP dir");
                return;
            }

            // IMPORTANT!! sharedData gets set by value, NOT A POINTER, do not make changes to p after this
            jobData = p;

            // --
            // - Read the CUE file ::
            add(new CTask((t) =>
            {
                var cd     = new CueReader();
                jobData.cd = cd;

                if (!cd.load(p.inputFile))
                {
                    t.fail(msg: cd.ERROR);
                    return;
                }

                // Post CD CUE load ::

                // In case user named the CD, otherwise it's going to be the same
                if (!string.IsNullOrWhiteSpace(p.cdTitle))
                {
                    cd.CD_TITLE = FileTools.sanitizeFilename(p.cdTitle);
                }

                // Real quality to string name
                cd.CD_AUDIO_QUALITY = CDCRUSH.getAudioQualityString(p.audioQuality);

                // This flag notes that all files will go to the TEMP folder
                jobData.workFromTemp = !cd.MULTIFILE;

                t.complete();
            }, "Reading", true));


            // - Cut tracks
            // ---------------------------
            add(new TaskCutTrackFiles());

            // - Compress tracks
            // ---------------------
            add(new CTask((t) =>
            {
                // Only encode the audio tracks
                foreach (CueTrack tr in (jobData.cd as CueReader).tracks)
                {
                    if (!tr.isData)
                    {
                        addNextAsync(new TaskCompressTrack(tr));
                    }
                }
                t.complete();
            }, "Preparing"));

            // - Create new CUE file
            // --------------------
            add(new CTask((t) =>
            {
                CueReader cd = jobData.cd;

                // DEV: So far :
                // track.trackFile is UNSET. cd.saveCue needs it to be set.
                // track.workingFile points to a valid file, some might be in TEMP folder and some in input folder (data tracks)

                // -- Move files to output folder
                foreach (var track in cd.tracks)
                {
                    if (!cd.MULTIFILE)
                    {
                        // Fix the index times to start with 00:00:00
                        track.setNewTimesReset();
                    }

                    string ext = Path.GetExtension(track.workingFile);

                    track.trackFile = $"{cd.CD_TITLE} (track {track.trackNo}){ext}";

                    // Data track was not cut or encoded.
                    // It's in the input folder, don't move it
                    if (track.isData && cd.MULTIFILE)
                    {
                        FileTools.tryCopy(track.workingFile, Path.Combine(p.outputDir, track.trackFile));
                    }
                    else
                    {
                        FileTools.tryMove(track.workingFile, Path.Combine(p.outputDir, track.trackFile));
                    }
                }

                //-- Create the new CUE file
                if (!cd.saveCUE(Path.Combine(p.outputDir, cd.CD_TITLE + ".cue")))
                {
                    t.fail(cd.ERROR); return;
                }

                t.complete();
            }, "Finalizing"));

            // -- COMPLETE --
        }// -----------------------------------------