/// <summary>
 /// Auto-load Preview file if encoded was unexpectedly closed.
 /// </summary>
 /// <returns>The previous preview encoding settings.</returns>
 public async Task<MediaEncoderSettings> AutoLoadPreviewFileAsync() {
     if (File.Exists(PathManager.PreviewSettingsFile)) {
         MediaEncoderSettings settings = MediaEncoderSettings.Load(PathManager.PreviewSettingsFile);
         if (!File.Exists(PathManager.PreviewSourceFile) && File.Exists(settings.FilePath)) {
             double? SourceFps = settings.SourceFrameRate; // Keep FPS in case it cannot be read from the file.
             await PreparePreviewFile(settings, false, false);
             if (!settings.SourceFrameRate.HasValue)
                 settings.SourceFrameRate = SourceFps;
         }
         settings.JobIndex = -1;
         return settings;
     }
     return null;
 }
        /// <summary>
        /// Automatically reloads jobs if the encoder was unexpectedly closed.
        /// </summary>
        public void AutoLoadJobs() {
            try {
                if (!Directory.Exists(PathManager.TempFilesPath))
                    Directory.CreateDirectory(PathManager.TempFilesPath);
            }
            catch {
                return;
            }

            var JobList = Directory.EnumerateFiles(PathManager.TempFilesPath, "Job*_Settings.xml");
            int Index = 0;
            MediaEncoderSettings settings;
            //List<Task> TaskList = new List<Task>();

            // Get list of interrupted jobs.
            foreach (string item in JobList) {
                // Load settings file.
                settings = null;
                try {
                    settings = MediaEncoderSettings.Load(item);
                }
                catch { }

                // Resume job.
                if (int.TryParse(Path.GetFileName(item).Replace("Job", "").Replace("_Settings.xml", ""), out Index)) {
                    if (Index > JobIndex)
                        JobIndex = Index;

                    if (settings != null && File.Exists(settings.InputFile) && File.Exists(settings.ScriptFile) && File.Exists(settings.SettingsFile) && File.Exists(settings.FilePath)) {
                        ProcessingQueue.Add(settings);
                        //TaskList.Add(StartJobAsync(settings));
                    } else {
                        // Resume job failed, delete files.
                        PathManager.DeleteJobFiles(settings.JobIndex);
                    }
                }
            }
        }