Example #1
0
        private void SetRowAction(DataGridViewRow row, TVFile.Actions action)
        {
            TVFile tvFile = GetRowTVFile(row);

            tvFile.Action = action;
            UpdateDataGridRow(row);
        }
Example #2
0
        /// <summary> Process a row of the data grid. Returns false if there are no more rows to lookup. </summary>
        protected bool ProcessRow()
        {
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                TVFile tvFile = GetRowTVFile(row);
                if (!tvFile.NeedsProcessing)
                {
                    continue;
                }

                int numExceptions = 0;
                try {
                    tvFile.PopulateEpisode();
                    UpdateDataGridRow(row);
                } catch (Exception e) {
                    // this can happen if the eu removes items from the list while process is occurring
                    if (numExceptions++ > 10)
                    {
                        throw e;                       // unless it's actually a problem
                    }
                }

                backgroundWorker1.ReportProgress(0);
                return(true);
            }

            return(false);
        }
Example #3
0
        public ShowSelectionForm(TVFile tvFile)
        {
            InitializeComponent();

            labelFilename.Text = tvFile.OriginalFile.Name;
            textBoxSearch.Text = tvFile.Episode.RawShowName;
        }
Example #4
0
        public void UpdateDataGridRow(DataGridViewRow row)
        {
            TVFile tvFile = GetRowTVFile(row);

            row.Cells["filename"].Value = tvFile.OriginalFile.Name;
            row.Cells["filetype"].Value = tvFile.Extension_Trimmed;
            row.Cells["action"].Value   = tvFile.Action;
            row.Cells["error"].Value    = tvFile.ErrorMessage;
            row.Cells["show"].Value     = tvFile.Episode != null ? tvFile.Episode.ShowName : "";
            row.Cells["episode"].Value  = tvFile.Episode != null ? tvFile.Episode.EpisodeName : "";
        }
Example #5
0
        private void requeryFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                TVFile tvFile = GetRowTVFile(row);
                tvFile.Action       = Config.DefaultAction;
                tvFile.ErrorMessage = "";
                tvFile.Episode      = null;
                UpdateDataGridRow(row);
            }

            // start the background process
            if (!backgroundWorker1.IsBusy)
            {
                backgroundWorker1.RunWorkerAsync();
            }
        }
Example #6
0
        public void AddFile(FileInfo addFile)
        {
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                TVFile tvf = GetRowTVFile(row);
                if (tvf.OriginalFile.FullName == addFile.FullName)
                {
                    return;                                                // already exists
                }
            }

            TVFile tvFile = new TVFile(addFile);

            Log("Adding [" + addFile.FullName + "]");
            int rowIndex = dataGridView1.Rows.Add(new object[] { tvFile });

            UpdateDataGridRow(dataGridView1.Rows[rowIndex]);
        }
Example #7
0
        private void manuallySelectEpisodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // order the selected rows
            List <DataGridViewRow> sortedRows = new List <DataGridViewRow>();

            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                sortedRows.Add(row);
            }
            sortedRows = sortedRows.OrderBy(o => o.Cells["filename"].Value).ToList();

            string previouslySelectedEpisodeName = "";

            foreach (DataGridViewRow row in sortedRows)
            {
                TVFile tvFile = GetRowTVFile(row);
                if (tvFile.Episode == null || string.IsNullOrWhiteSpace(tvFile.Episode.ShowName))
                {
                    continue;                                                                               // must at least have the showname
                }
                // show chooser dialog
                EpisodeSelectionForm episodeForm = new EpisodeSelectionForm(tvFile, previouslySelectedEpisodeName);
                DialogResult         result      = episodeForm.ShowDialog();
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                if (result == DialogResult.Ignore || string.IsNullOrWhiteSpace(episodeForm.SelectedEpisodeName))
                {
                    continue;
                }

                // update season/episode
                tvFile.Episode.Season         = episodeForm.SelectedSeason;
                tvFile.Episode.EpisodeNumber  = episodeForm.SelectedEpisodeNumber;
                tvFile.Episode.EpisodeName    = episodeForm.SelectedEpisodeName;
                previouslySelectedEpisodeName = episodeForm.SelectedEpisodeName;
                tvFile.Action       = Config.DefaultAction;
                tvFile.ErrorMessage = "";
                UpdateDataGridRow(row);
            }
        }
Example #8
0
        private void manuallySelectShowToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TVFile tvFile = GetSelectedRowTVFile(); // GetRowTVFile(dataGridView1.SelectedRows[0]);

            if (tvFile.Episode == null)
            {
                return;
            }

            ShowSelectionForm showForm = new ShowSelectionForm(tvFile);

            if (showForm.ShowDialog() == DialogResult.Cancel || showForm.SelectedShowId == 0)
            {
                return;
            }

            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                // set show for each selected item
                tvFile = GetRowTVFile(row);
                if (tvFile.Episode == null)
                {
                    continue;
                }

                // set cache item
                Config.SetTVMazeMapping(tvFile.Episode.RawShowName, showForm.SelectedShowId);
                tvFile.Episode = null;
                tvFile.Action  = Config.DefaultAction;
                UpdateDataGridRow(row);
            }
            Config.Save();

            // start the background process
            if (!backgroundWorker1.IsBusy)
            {
                backgroundWorker1.RunWorkerAsync();
            }
        }
Example #9
0
        private void contextMenuStripFile_Opening(object sender, CancelEventArgs e)
        {
            // Tag should contain the current RowIndex
            if (contextMenuStripFile.Tag == null || (int)contextMenuStripFile.Tag < 0)
            {
                e.Cancel = true;
            }

            int             rowIndex = (int)contextMenuStripFile.Tag;
            DataGridViewRow row      = dataGridView1.Rows[rowIndex];

            // if the current item is not selected, select it now
            if (!dataGridView1.SelectedRows.Contains(row))
            {
                dataGridView1.ClearSelection();
                row.Selected = true;
            }

            TVFile tvFile = GetSelectedRowTVFile();

            manuallySelectShowToolStripMenuItem.Enabled    = tvFile.Episode != null;
            manuallySelectEpisodeToolStripMenuItem.Enabled = tvFile.Episode != null;
        }
Example #10
0
        public EpisodeSelectionForm(TVFile tvFile, string previouslySelectedEpisodeName = "")
        {
            InitializeComponent();

            labelFilepath.Text = tvFile.OriginalFile.Name;
            labelShowName.Text = tvFile.Episode.ShowName;

            // get list of episodes and display in combo box
            try {
                List <string> episodeList = TVMaze.GetEpisodeList(tvFile.Episode.TVMazeId);
                episodeList.Reverse(); // let's make the last one first
                foreach (string episodeResult in episodeList)
                {
                    comboBoxEpisodes.Items.Add(new EpisodeSelectionComboItem(episodeResult));
                }
            } catch (TVMazeException tvExc) {
                // something went wrong, couldn't get episodes
            }

            if (comboBoxEpisodes.Items.Count == 0)
            {
                comboBoxEpisodes.Items.Add(new EpisodeSelectionComboItem("-1,-1,(No Episodes)"));
            }
            comboBoxEpisodes.SelectedItem = comboBoxEpisodes.Items[0];

            if (!string.IsNullOrWhiteSpace(previouslySelectedEpisodeName))
            {
                for (int i = 0; i < comboBoxEpisodes.Items.Count - 1; i++)
                {
                    if (((EpisodeSelectionComboItem)comboBoxEpisodes.Items[i]).EpisodeName == previouslySelectedEpisodeName)
                    {
                        comboBoxEpisodes.SelectedItem = comboBoxEpisodes.Items[i + 1];
                        break;
                    }
                }
            }
        }
Example #11
0
        private void buttonProcess_Click(object sender, EventArgs e)
        {
            Log("Begin action processing");
            List <DirectoryInfo> processedDirectories = new List <DirectoryInfo>();

            int n = progressBar1.Value = 1;

            progressBar1.Maximum = dataGridView1.Rows.Count + 1;
            progressBar1.Visible = true;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                TVFile tvFile     = GetRowTVFile(row);
                bool   anyTrouble = false;
                try {
                    switch (tvFile.Action)
                    {
                    case TVFile.Actions.Ignore:
                        break;

                    case TVFile.Actions.Delete:
                        processedDirectories.Add(tvFile.OriginalFile.Directory);
                        tvFile.OriginalFile.Delete();
                        break;

                    case TVFile.Actions.Move:
                    case TVFile.Actions.Copy:
                        processedDirectories.Add(tvFile.OriginalFile.Directory);
                        FileInfo newFile = new FileInfo(Path.Combine(Config.TVShowRoot.FullName, tvFile.GetNewFilepath()));
                        if (tvFile.OriginalFile.FullName.ToLower() == newFile.FullName.ToLower())
                        {
                            break;                                                                           // file is already where it needs to be
                        }
                        if (!newFile.Directory.Exists)
                        {
                            newFile.Directory.Create();
                        }
                        if (newFile.Exists && Config.ReplaceExistingFiles)
                        {
                            newFile.Delete();
                            newFile.Refresh();     // if we don't do this, then the subsequent call to .Exists is wrong
                        }
                        if (!newFile.Exists)
                        {
                            if (tvFile.Action == TVFile.Actions.Move)
                            {
                                tvFile.OriginalFile.MoveTo(newFile.FullName);
                            }
                            else if (tvFile.Action == TVFile.Actions.Copy)
                            {
                                tvFile.OriginalFile.CopyTo(newFile.FullName);                                                // this hangs with large files - maybe implement this some day: https://stackoverflow.com/a/27179497/3140552 or this https://www.pinvoke.net/default.aspx/kernel32.CopyFileEx
                            }
                        }
                        else
                        {
                            anyTrouble          = true;
                            tvFile.Action       = TVFile.Actions.Ignore;
                            tvFile.ErrorMessage = "Destination file exists";
                            UpdateDataGridRow(row);
                        }
                        break;
                    }
                } catch (Exception exc) {
                    anyTrouble          = true;
                    tvFile.Action       = TVFile.Actions.Error;
                    tvFile.ErrorMessage = exc.Message;
                    UpdateDataGridRow(row);
                }

                if (!anyTrouble)
                {
                    row.Visible = false;
                }
                progressBar1.Value = ++n;
                Application.DoEvents();
            }
            progressBar1.Visible = false;

            while (DeleteInvisibleRow())
            {
                ;
            }

            dataGridView1.AutoResizeColumns();

            // clean up empty directories (deepest ones first)
            Log("Cleaning up empty directories");
            foreach (string directoryName in processedDirectories.Select(o => o.FullName).Distinct().OrderByDescending(o => o.Length))
            {
                DirectoryInfo di = new DirectoryInfo(directoryName);
                Log("Checking [" + di.FullName + "]");
                di.Refresh(); // maybe this will clear up some of these random errors
                if (di.Exists && di.GetDirectories().Count() + di.GetFiles().Count() == 0)
                {
                    Log("Deleting [" + di.FullName + "]");
                    di.Delete();
                }
            }

            buttonProcess.Enabled = dataGridView1.Rows.Count > 0;
        }