コード例 #1
0
        private void WriteAudioFilesThread(object o)
        {
            object[] p = (object[])o;

            CUESheet cueSheet = (CUESheet)p[0];
            string   outDir   = (string)p[1];
            CUEStyle cueStyle = (CUEStyle)p[2];

            try {
                cueSheet.WriteAudioFiles(outDir, cueStyle, new SetStatus(this.SetStatus));
                this.Invoke((MethodInvoker) delegate() {
                    if (_batchPaths.Count == 0)
                    {
                        SetupControls(false);
                    }
                    ShowFinishedMessage(cueSheet.PaddedToFrame);
                });
            }
            catch (StopException) {
                _batchPaths.Clear();
                this.Invoke((MethodInvoker) delegate() {
                    SetupControls(false);
                    MessageBox.Show("Conversion was stopped.", "Stopped", MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                });
            }
            catch (Exception ex) {
                this.Invoke((MethodInvoker) delegate() {
                    if (_batchPaths.Count == 0)
                    {
                        SetupControls(false);
                    }
                    if (!ShowErrorMessage(ex))
                    {
                        _batchPaths.Clear();
                        SetupControls(false);
                    }
                });
            }

            if (_batchPaths.Count != 0)
            {
                _batchPaths.RemoveAt(0);
                this.BeginInvoke((MethodInvoker) delegate() {
                    if (_batchPaths.Count == 0)
                    {
                        SetupControls(false);
                        ShowBatchDoneMessage();
                    }
                    else
                    {
                        StartConvert();
                    }
                });
            }
        }
コード例 #2
0
        public void StartConvert()
        {
            try
            {
                CUESheet cueSheet = new CUESheet(_profile._config);
                cueSheet.PasswordRequired += new EventHandler <CompressionPasswordRequiredEventArgs>(PasswordRequired);
                cueSheet.CUEToolsProgress += new EventHandler <CUEToolsProgressEventArgs>(SetStatus);

                _workThread              = new Thread(WriteAudioFilesThread);
                _workClass               = cueSheet;
                _workThread.Priority     = ThreadPriority.BelowNormal;
                _workThread.IsBackground = true;
                _workThread.Start(cueSheet);
            }
            catch (Exception ex)
            {
                Text = "Error: " + ex.Message;
                textBox1.Show();
                textBox1.Text += "Error: " + ex.Message + "\r\n";
                textBox1.Text += "----------------------------------------------------------\r\n";
                textBox1.Select(0, 0);
            }
        }
コード例 #3
0
        private void CorrectCUEThread(object p)
        {
            string[] paths      = (string[])p;
            bool     oneSuccess = false;
            bool     cancel     = false;

            foreach (string path in paths)
            {
                if (Path.GetExtension(path).ToLower() == ".cue")
                {
                    try {
                        CUESheet.CorrectAudioFilenames(path, true);
                        oneSuccess = true;
                    }
                    catch (Exception ex) {
                        Invoke((MethodInvoker) delegate() {
                            cancel = (MessageBox.Show(this, path + Environment.NewLine +
                                                      Environment.NewLine + ex.Message, "Error", MessageBoxButtons.OKCancel,
                                                      MessageBoxIcon.Error) == DialogResult.Cancel);
                        });
                        if (cancel)
                        {
                            break;
                        }
                    }
                }
            }

            if (oneSuccess)
            {
                Invoke((MethodInvoker) delegate() {
                    MessageBox.Show(this, "Filename correction is complete!", "Done",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                });
            }
        }
コード例 #4
0
        private void WriteAudioFilesThread(object o)
        {
            CUESheet       cueSheet = (CUESheet)o;
            CUEToolsScript script   = _profile._script == null || !_profile._config.scripts.ContainsKey(_profile._script) ? null : _profile._config.scripts[_profile._script];

            try
            {
                _startedAt = DateTime.Now;
                if (_batchPaths.Count != 0)
                {
                    pathIn = _batchPaths[0];
                }

                pathIn = Path.GetFullPath(pathIn);

                this.Invoke((MethodInvoker) delegate()
                {
                    textBox1.Text += "Processing " + pathIn + ":\r\n";
                    textBox1.Select(0, 0);
                });

                if (!File.Exists(pathIn) && !Directory.Exists(pathIn))
                {
                    throw new Exception("Input CUE Sheet not found.");
                }

                if (_profile._action == CUEAction.CorrectFilenames)
                {
                    throw new Exception("CorrectFilenames action not yet supported in commandline mode.");
                }
                if (_profile._action == CUEAction.CreateDummyCUE)
                {
                    throw new Exception("CreateDummyCUE action not yet supported in commandline mode.");
                }

                bool useAR = _profile._action == CUEAction.Verify || _profile._ARVerifyOnEncode;

                cueSheet.Action      = _profile._action;
                cueSheet.OutputStyle = _profile._CUEStyle;
                cueSheet.WriteOffset = _profile._writeOffset;
                cueSheet.Open(pathIn);
                if (useAR)
                {
                    cueSheet.UseAccurateRip();
                }

                pathOut = CUESheet.GenerateUniqueOutputPath(_profile._config,
                                                            _profile._outputTemplate,
                                                            _profile._CUEStyle == CUEStyle.SingleFileWithCUE ? "." + _profile._outputAudioFormat : ".cue",
                                                            _profile._action,
                                                            new NameValueCollection(),
                                                            pathIn,
                                                            cueSheet);
                if (pathOut == "" || (_profile._action != CUEAction.Verify && File.Exists(pathOut)))
                {
                    throw new Exception("Could not generate output path.");
                }

                cueSheet.GenerateFilenames(_profile._outputAudioType, _profile._outputAudioFormat, pathOut);
                cueSheet.UsePregapForFirstTrackInSingleFile = false;

                if (script == null)
                {
                    cueSheet.Go();
                }
                else
                {
                    /* status = */ cueSheet.ExecuteScript(script);
                }
                this.Invoke((MethodInvoker) delegate()
                {
                    if (_batchPaths.Count == 0)
                    {
                        Text = "Done.";
                    }

                    //TimeSpan span = DateTime.Now - _startedAt;
                    progressBar2.Value = 0;
                    if (cueSheet.IsCD)
                    {
                        textBox1.Text += cueSheet.LOGContents;
                        textBox1.Show();
                    }
                    else if (useAR)
                    {
                        textBox1.Text += CUESheetLogWriter.GetAccurateRipLog(cueSheet);
                        textBox1.Show();
                    }
                    textBox1.Text += "----------------------------------------------------------\r\n";
                    textBox1.Select(0, 0);
                });
            }
            catch (StopException)
            {
                _batchPaths.Clear();
                this.Invoke((MethodInvoker) delegate()
                {
                    Text               = "Aborted.";
                    textBox1.Text     += "Aborted.";
                    progressBar2.Value = 0;
                });
            }
#if !DEBUG
            catch (Exception ex)
            {
                this.Invoke((MethodInvoker) delegate()
                {
                    Text = "Error: " + ex.Message;
                    textBox1.Show();
                    textBox1.Text += "Error";
                    for (Exception e = ex; e != null; e = e.InnerException)
                    {
                        textBox1.Text += ": " + e.Message;
                    }
                    textBox1.Text += "\r\n----------------------------------------------------------\r\n";
                    textBox1.Select(0, 0);
                });
            }
#endif

            if (_batchPaths.Count != 0)
            {
                _batchPaths.RemoveAt(0);
                this.BeginInvoke((MethodInvoker) delegate()
                {
                    if (_batchPaths.Count == 0)
                    {
                        Text = "All done.";
                    }
                    else
                    {
                        StartConvert();
                    }
                });
            }
        }
コード例 #5
0
        private void GenerateFilenames(CUESheet cueSheet, string singleFormat, string trackFormat, string extension, bool replaceSpaces, bool keepOriginal)
        {
            List <string> find, replace;
            string        filename;
            int           iTrack;

            find    = new List <string>();
            replace = new List <string>();

            find.Add("%D");             // 0: Album artist
            find.Add("%C");             // 1: Album title
            find.Add("%N");             // 2: Track number
            find.Add("%A");             // 3: Track artist
            find.Add("%T");             // 4: Track title

            replace.Add(EmptyStringToNull(CleanseString(cueSheet.Artist)));
            replace.Add(EmptyStringToNull(CleanseString(cueSheet.Title)));
            replace.Add(null);
            replace.Add(null);
            replace.Add(null);

            if (keepOriginal && cueSheet.HasSingleFilename)
            {
                cueSheet.SingleFilename = Path.ChangeExtension(cueSheet.SingleFilename, extension);
            }
            else
            {
                filename = ReplaceMultiple(singleFormat, find, replace);
                if (filename == null)
                {
                    filename = "Range";
                }
                if (replaceSpaces)
                {
                    filename = filename.Replace(' ', '_');
                }
                filename += extension;

                cueSheet.SingleFilename = filename;
            }

            for (iTrack = -1; iTrack < cueSheet.TrackCount; iTrack++)
            {
                bool htoa = (iTrack == -1);

                if (keepOriginal && htoa && cueSheet.HasHTOAFilename)
                {
                    cueSheet.HTOAFilename = Path.ChangeExtension(cueSheet.HTOAFilename, extension);
                }
                else if (keepOriginal && !htoa && cueSheet.HasTrackFilenames)
                {
                    cueSheet.TrackFilenames[iTrack] = Path.ChangeExtension(
                        cueSheet.TrackFilenames[iTrack], extension);
                }
                else
                {
                    string trackStr = htoa ? "01.00" : String.Format("{0:00}", iTrack + 1);
                    string artist   = cueSheet.Tracks[htoa ? 0 : iTrack].Artist;
                    string title    = htoa ? "(HTOA)" : cueSheet.Tracks[iTrack].Title;

                    replace[2] = trackStr;
                    replace[3] = EmptyStringToNull(CleanseString(artist));
                    replace[4] = EmptyStringToNull(CleanseString(title));

                    filename = ReplaceMultiple(trackFormat, find, replace);
                    if (filename == null)
                    {
                        filename = replace[2];
                    }
                    if (replaceSpaces)
                    {
                        filename = filename.Replace(' ', '_');
                    }
                    filename += extension;

                    if (htoa)
                    {
                        cueSheet.HTOAFilename = filename;
                    }
                    else
                    {
                        cueSheet.TrackFilenames[iTrack] = filename;
                    }
                }
            }
        }
コード例 #6
0
        private void StartConvert()
        {
            string   pathIn, pathOut, outDir, extension;
            bool     outputExists, outputAudio;
            CUESheet cueSheet;
            CUEStyle cueStyle;

            try {
                _workThread = null;
                if (_batchPaths.Count != 0)
                {
                    txtInputPath.Text = _batchPaths[0];
                }
                pathIn      = txtInputPath.Text;
                outputAudio = !chkNoAudioOutput.Checked;

                if (!File.Exists(pathIn))
                {
                    throw new Exception("Input CUE Sheet not found.");
                }

                cueSheet = new CUESheet(pathIn, _autoCorrectFilenames);

                cueStyle = SelectedCUEStyle;

                if (rbFLAC.Checked)
                {
                    extension = ".flac";
                }
                else if (rbWavPack.Checked)
                {
                    extension = ".wv";
                }
                else
                {
                    extension = ".wav";
                }

                cueSheet.WriteOffset = _writeOffset;

                BuildCharMap(chkRemoveSpecial.Checked, txtSpecialExceptions.Text);
                GenerateFilenames(cueSheet, txtSingleFilenameFormat.Text, txtTrackFilenameFormat.Text,
                                  extension, chkReplaceSpaces.Checked, chkKeepOriginalFilenames.Checked);
                UpdateOutputPath(cueSheet.Artist, cueSheet.Title);
                pathOut = txtOutputPath.Text;
                outDir  = Path.GetDirectoryName(pathOut);

                outputExists = File.Exists(pathOut);
                if (outputAudio)
                {
                    if (cueStyle == CUEStyle.SingleFile)
                    {
                        outputExists |= File.Exists(Path.Combine(outDir, cueSheet.SingleFilename));
                    }
                    else
                    {
                        if ((cueStyle == CUEStyle.GapsAppended) && _preserveHTOA)
                        {
                            outputExists |= File.Exists(Path.Combine(outDir, cueSheet.HTOAFilename));
                        }
                        for (int i = 0; i < cueSheet.TrackCount; i++)
                        {
                            outputExists |= File.Exists(Path.Combine(outDir, cueSheet.TrackFilenames[i]));
                        }
                    }
                }
                if (outputExists)
                {
                    DialogResult dlgRes = MessageBox.Show("One or more output file already exists, " +
                                                          "do you want to overwrite?", "Overwrite?", (_batchPaths.Count == 0) ?
                                                          MessageBoxButtons.YesNo : MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

                    if (dlgRes == DialogResult.Cancel)
                    {
                        _batchPaths.Clear();
                    }
                    if (dlgRes != DialogResult.Yes)
                    {
                        goto SkipConversion;
                    }
                }

                cueSheet.PreserveHTOA = _preserveHTOA;
                cueSheet.UsePregapForFirstTrackInSingleFile = _usePregapForFirstTrackInSingleFile && !outputAudio;
                cueSheet.FLACCompressionLevel = _flacCompressionLevel;
                cueSheet.FLACVerify           = _flacVerify;
                cueSheet.WVCompressionMode    = _wvCompressionMode;
                cueSheet.WVExtraMode          = _wvExtraMode;

                if (!Directory.Exists(outDir))
                {
                    Directory.CreateDirectory(outDir);
                }

                cueSheet.Write(pathOut, cueStyle);

                if (outputAudio)
                {
                    object[] p = new object[3];

                    _workThread = new Thread(WriteAudioFilesThread);
                    _workClass  = cueSheet;

                    p[0] = cueSheet;
                    p[1] = outDir;
                    p[2] = cueStyle;

                    SetupControls(true);
                    _workThread.Start(p);
                }
                else
                {
                    ShowFinishedMessage(cueSheet.PaddedToFrame);
                }
            }
            catch (Exception ex) {
                if (!ShowErrorMessage(ex))
                {
                    _batchPaths.Clear();
                }
            }

SkipConversion:
            if ((_workThread == null) && (_batchPaths.Count != 0))
            {
                _batchPaths.RemoveAt(0);
                if (_batchPaths.Count == 0)
                {
                    ShowBatchDoneMessage();
                }
                else
                {
                    StartConvert();
                }
            }
        }