Ejemplo n.º 1
0
        private void CloseFormCancel(object sender, FormClosingEventArgs e)
        {
            if (!isAbortedOrFinished)
            {
                DialogResult cancelResult = MessageBox.Show("The renaming process will be aborted.\n\nDo you want to continue?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (cancelResult == DialogResult.Yes)
                {
                    isAbortedOrFinished = true;
                    RenamingProgressBar.SetState(3);
                }

                e.Cancel = true;
            }
        }
Ejemplo n.º 2
0
        private async Task RenameTorrentFiles()
        {
            int success = 0, timeout = 0, failed = 0, current = 1, total = FileNamesOldNewListView.Items.Count;

            Invoke((MethodInvoker) delegate
            {
                TotalFilesLabel.Text        = $"Total files: {FileNamesOldNewListView.Items.Count}";
                RenamingProgressBar.Maximum = total;
            });
            for (int i = 0; i < FileNamesOldNewListView.Items.Count; i++)
            {
                if (!isAbortedOrFinished)
                {
                    string                curFilePath = null, newFileName = null;
                    TorrentInfo           torrent      = null;
                    Globals.RequestResult renameResult = Globals.RequestResult.Unknown;
                    Invoke((MethodInvoker) delegate
                    {
                        ListViewItem fileItem = FileNamesOldNewListView.Items[i];
                        FileNamesOldNewListView.Items[i].EnsureVisible();
                        FriendlyTorrentFileInfo friendlyTorrentFileInfo = (FriendlyTorrentFileInfo)fileItem.Tag;
                        curFilePath = friendlyTorrentFileInfo.InitialPath;
                        newFileName = friendlyTorrentFileInfo.NewestName;
                        torrent     = friendlyTorrentFileInfo.ParentTorrent;
                        CurrentFileRenameLabel.Text = $"File {current} of {total}: {FileNamesOldNewListView.Items[i].Text}";
                        if (RenamingProgressBar.Value + 2 <= RenamingProgressBar.Maximum)
                        {
                            RenamingProgressBar.Value += 2;
                            RenamingProgressBar.Value--;
                        }
                        else
                        {
                            RenamingProgressBar.Maximum++;
                            RenamingProgressBar.Value += 2;
                            RenamingProgressBar.Value--;
                            RenamingProgressBar.Maximum--;
                        }
                    });
                    if (curFilePath != null && newFileName != null && torrent != null && (curFilePath != newFileName))
                    {
                        renameResult = await Globals.SessionHandler.RenameTorrent(curFilePath, newFileName, torrent);

                        switch (renameResult)
                        {
                        case Globals.RequestResult.Success:
                            success++;
                            Invoke((MethodInvoker) delegate
                            {
                                FileNamesOldNewListView.Items[i].ImageIndex = 3;
                                SuccessFilesLabel.Text = $"Success: {success}";
                            });
                            break;

                        case Globals.RequestResult.Timeout:
                            timeout++;
                            Invoke((MethodInvoker) delegate
                            {
                                FileNamesOldNewListView.Items[i].ImageIndex = 4;
                                TimedOutFilesLabel.Text = $"Timed out: {timeout}";
                            }); break;

                        case Globals.RequestResult.Error:
                            failed++;
                            Invoke((MethodInvoker) delegate
                            {
                                FileNamesOldNewListView.Items[i].ImageIndex = 5;
                                ErrorFilesLabel.Text = $"Error: {failed}";
                            }); break;

                        case Globals.RequestResult.Unknown:
                            Invoke((MethodInvoker) delegate
                            {
                                FileNamesOldNewListView.Items[i].ImageIndex = 5;
                            }); break;

                        default:
                            MessageBox.Show("An unknown error has occurred. The renaming process will be cancelled.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            RenamingProgressBar.SetState(1);
                            isAbortedOrFinished = true;
                            break;
                        }
                    }
                    else
                    {
                        success++;
                        Invoke((MethodInvoker) delegate
                        {
                            FileNamesOldNewListView.Items[i].ImageIndex = 3;
                            SuccessFilesLabel.Text = $"Success: {success}";
                        });
                    }
                    current++;
                }
                else
                {
                    break;
                }
            }
        }
Ejemplo n.º 3
0
 private void AbortButtonClick(object sender, EventArgs e)
 {
     isAbortedOrFinished = true;
     RenamingProgressBar.SetState(3);
 }