예제 #1
0
        private void recursingBackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            /*FolderRecurser recurser = new FolderRecurser(flacDir.Text, ignoreList.ToArray(), copyFiles, rwl);
             *
             * Thread recurserThread = new Thread(new ThreadStart(recurser.recurseDirs));
             * recurserThread.IsBackground = false;
             * recurserThread.Start();
             *
             * while(recurserThread.IsAlive) {
             * }
             * recurserThread.Join();*/

            BackgroundWorker bw = sender as BackgroundWorker;

            EncoderParams args = (EncoderParams)e.Argument;

            FolderRecurser recurser = args.Recurser;

            recurser.recurseDirs();

            args.JobQueue = recurser.getJobQueue();
            jobQueue      = args.JobQueue;

            e.Result = args;

            bw.ReportProgress(20, args.JobQueue.Count);
        }
예제 #2
0
        public void encode()
        {
            // this section should be kept in case of bad config files, etc.
            if (encoder.SelectedIndex == 0)
            {
                if (String.IsNullOrEmpty(oggPath))
                {
                    oggPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + dirSeparator + "oggenc.exe";
                }
            }
            else
            {
                if (String.IsNullOrEmpty(lamePath))
                {
                    lamePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + dirSeparator + "lame.exe";
                }
                if (String.IsNullOrEmpty(flacexe))
                {
                    flacexe = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + dirSeparator + "flac.exe";
                }
            }

            // set up status bar
            encodeStatus.Text    = "Recursing directories...";
            encodeProgress.Width = 175;             // this seems to change the width in Mono, but only the Designer seems to affect the width in Windows
            encodeProgress.Value = 0;
            encodeProgress.MarqueeAnimationSpeed = 50;
            encodeProgress.Style   = ProgressBarStyle.Marquee;
            encodeProgress.Visible = true;

            encodeAborted = false;

            ignoreList = new List <String>();
            String[] split = new String[0];
            if (!String.IsNullOrEmpty(ignoredExts))
            {
                split = ignoredExts.Split(' ');
                foreach (String ext in split)
                {
                    if (!String.IsNullOrEmpty(ext))
                    {
                        ignoreList.Add(ext);
                    }
                }
            }

            copyList = new List <String>();
            if (!String.IsNullOrEmpty(copiedExts))
            {
                split = copiedExts.Split(' ');
                foreach (String ext in split)
                {
                    if (!String.IsNullOrEmpty(ext))
                    {
                        copyList.Add(ext);
                    }
                }
            }

            // make sure source and destination directories are given
            if (String.IsNullOrEmpty(flacDir.Text) || String.IsNullOrEmpty(outputDir.Text))
            {
                MessageBox.Show("The Flac directory and destination directory must both be specified", "Specify directories", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, false);
                encodeStatus.Text      = "Ready";
                encodeProgress.Visible = false;
                encodeButton.Enabled   = true;
                return;
            }

            // make sure source directory exists
            if (!Directory.Exists(flacDir.Text))
            {
                MessageBox.Show("The source directory does not exist.", "Non-existent source directory", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, false);
                encodeStatus.Text      = "Ready";
                encodeProgress.Visible = false;
                encodeButton.Enabled   = true;
                return;
            }

            resultsList = new List <EncoderResults>();

            String flacDirString = flacDir.Text.Trim();

            if (flacDirString.EndsWith(dirSeparator))
            {
                flacDirString = flacDirString.TrimEnd(new char[1] {
                    System.IO.Path.DirectorySeparatorChar
                });
            }
            String outputDirString = outputDir.Text.Trim();

            if (outputDirString.EndsWith(dirSeparator))
            {
                outputDirString = outputDirString.TrimEnd(new char[1] {
                    System.IO.Path.DirectorySeparatorChar
                });
            }

            FolderRecurser recurser = new FolderRecurser(flacDirString, ignoreList.ToArray(), copyList.ToArray(), copyFiles, rwl);

            int threads;

            rwl.AcquireWriterLock(-1);              // -1 == wait forever for the lock
            try {
                threads = (int)threadCounter.Value; // Value is a System::Decimal, hence the cast
            }
            finally {
                rwl.ReleaseWriterLock();
            }

            EncoderParams args = new EncoderParams();

            args.Recurser        = recurser;
            args.FlacDir         = flacDirString;
            args.OutputDir       = outputDirString;
            args.SelectedEncoder = (EncoderParams.EncoderChoice)encoder.SelectedIndex;
            args.CliParams       = cliParams.Text;
            args.Threads         = threads;
            args.CopyFiles       = copyFiles;
            args.FlacExe         = flacexe;
            args.OggPath         = oggPath;
            args.LamePath        = lamePath;
            args.MetaflacPath    = metaflacPath;
            args.OpusPath        = opusPath;
            args.Hidewin         = hidewin;
            args.IgnoreList      = ignoreList;
            args.CopyList        = copyList;
            args.ThirdPartyLame  = thirdPartyLame;
            args.GainType        = replayGainType;
            args.MaxImageSize    = maxImageSize;

            this.recursingBackgroundWorker1.RunWorkerAsync(args);
        }