}        // -----------------------------------------

        // --
        // Create ARC
        private void btn_arc_Click(object sender, EventArgs e)
        {
            if (SELECTED_FILES == null)
            {
                return;
            }

            var app = new FreeArc(prog.CDCRUSH.TOOLS_PATH);

            app.onComplete = (s) => {
                LOG.log("--FreeArc Complete :: {0}", s);
            };

            app.onProgress = (p) => {
                LOG.log("--FreeArc Got Progress :: {0}", p);
            };

            string destFolder   = Path.GetDirectoryName(SELECTED_FILES[0]);
            string destFilename = Path.GetFileNameWithoutExtension(SELECTED_FILES[0]);
            string finalpath    = Path.Combine(destFolder, destFilename + "_test_.arc");

            if (!string.IsNullOrEmpty(txt_files_2.Text))
            {
                finalpath = txt_files_2.Text;
            }

            app.compress(SELECTED_FILES, finalpath, 7);
        }        // -----------------------------------------
Example #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 --
        }// -----------------------------------------