예제 #1
0
        /// <summary>
        /// Generate the preview in seperate thread.
        /// </summary>
        private void generatePreview()
        {
            // Fire event to tell MainForm to update the settings
            if (GeneretePreview != null)
            {
                GeneretePreview(this, EventArgs.Empty);
            }

            populateEpisodeComboBox();

            string tempPreviewDir = Path.GetTempPath() + ConstantSettings.TempPreviewDirName;

            if (Directory.Exists(tempPreviewDir))
            {
                try
                {
                    Directory.Delete(tempPreviewDir, true);
                }
                catch
                {
                    //UtilsMsg.showErrMsg("Unable to delete the temporary directory at:\n" + tempPreviewDir);
                }
            }

            // Create the temporary directory
            try
            {
                Directory.CreateDirectory(tempPreviewDir);
            }
            catch
            {
                UtilsMsg.showErrMsg("Cannot write to " + tempPreviewDir + "\nTry checking the directory's permissions.");
                return;
            }

            Logger.Instance.info("Preview: GO!");
            Logger.Instance.writeSettingsToLog();

            // Start the worker thread
            try
            {
                WorkerVars workerVars = new WorkerVars(null, tempPreviewDir, WorkerVars.SubsProcessingType.Preview);

                // Create a background thread
                BackgroundWorker bw = new BackgroundWorker();
                bw.DoWork             += new DoWorkEventHandler(bw_DoWork);
                bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);

                // Create a progress dialog on the UI thread
                dialogProgress = new DialogProgress();

                bw.RunWorkerAsync(workerVars);

                // Lock up the UI with this modal progress form
                // TODO: for some reason, on Mono/Linux the parent dialog is not
                // re-enabled after the child modal goes away, leaving the form
                // permanently grayed out. So as a workaround, we use Show() instead of
                // ShowDialog()
                //dialogProgress.ShowDialog();
                dialogProgress.Show();
                //dialogProgress = null;
            }
            catch (Exception e1)
            {
                UtilsMsg.showErrMsg("Something went wrong before preview could be generated.\n" + e1);
                return;
            }
        }