Ejemplo n.º 1
0
        private void AnalyzeMedia(List <string> files)
        {
            if (!ValidateInput())
            {
                return;
            }

            DialogResult        dlgResult        = DialogResult.OK;
            List <TaskSettings> taskSettingsList = new List <TaskSettings>();

            MediaWizardOptions mo = Adapter.GetMediaType(files);

            if (mo.ShowWizard)
            {
                ShowMediaWizard(ref mo, files);
            }

            if (mo.PromptShown)
            {
                dlgResult = mo.DialogResult;
            }
            else
            {
                // fill previous settings
                mo.CreateTorrent     = App.Settings.ProfileActive.CreateTorrent;
                mo.CreateScreenshots = App.Settings.ProfileActive.CreateScreenshots;
                mo.UploadScreenshots = App.Settings.ProfileActive.UploadScreenshots;
            }

            if (!mo.PromptShown && App.Settings.ShowMediaWizardAlways)
            {
                MediaWizard mw = new MediaWizard(files);
                dlgResult = mw.ShowDialog();
                if (dlgResult == DialogResult.OK)
                {
                    mo = mw.Options;
                }
            }

            if (dlgResult == DialogResult.OK)
            {
                if (mo.MediaTypeChoice == MediaType.MediaCollection)
                {
                    TaskSettings ts = new TaskSettings();
                    ts.MediaOptions = mo;

                    files.Sort();
                    string firstPath = files[0];
                    PrepareNewMedia(ts, File.Exists(firstPath) ? Path.GetDirectoryName(files[0]) : firstPath);
                    foreach (string p in files)
                    {
                        if (File.Exists(p))
                        {
                            ts.Media.FileCollection.Add(p);
                        }
                    }
                    taskSettingsList.Add(ts);
                }
                else
                {
                    foreach (string fd in files)
                    {
                        if (File.Exists(fd) || Directory.Exists(fd))
                        {
                            TaskSettings ts = new TaskSettings();
                            ts.MediaOptions = mo;

                            PrepareNewMedia(ts, fd);
                            ts.Media.DiscType = MediaHelper.GetSourceType(fd);

                            if (ts.Media.DiscType == SourceType.Bluray)
                            {
                                ts.Media.Overall         = new MediaFile(FileSystemHelper.GetLargestFilePathFromDir(fd), cboSource.Text);
                                ts.Media.Overall.Summary = BDInfo(fd);
                            }

                            if (!string.IsNullOrEmpty(txtTitle.Text))
                            {
                                ts.Media.SetTitle(txtTitle.Text);
                            }

                            taskSettingsList.Add(ts);
                        }
                    }
                }

                foreach (TaskSettings ts in taskSettingsList)
                {
                    WorkerTask task = WorkerTask.CreateTask(ts);
                    task.UploadProgressChanged  += Task_UploadProgressChanged;
                    task.MediaLoaded            += Task_MediaLoaded;
                    task.StatusChanged          += Task_StatusChanged;
                    task.ScreenshotUploaded     += Task_ScreenshotUploaded;
                    task.TorrentInfoCreated     += Task_TorrentInfoCreated;
                    task.TorrentProgressChanged += Task_TorrentProgressChanged;
                    task.TaskCompleted          += Task_TaskCompleted;
                    TaskManager.Start(task);
                }

                UpdateGuiControls();
                pBar.Value = 0;
            }
        }