void miMoveBottom_Click(object sender, EventArgs e) { int n = TaskList.Items.Count - 1; int i = TaskList.SelectedItems.Count; if (n > 0 && i > 0) { TaskList.BeginUpdate(); int fi = TaskList.SelectedItems.IndexOf(TaskList.FocusedItem); while (i-- > 0) { ListViewItem item = TaskList.SelectedItems[i]; int ii = item.Index; if (ii < n) { item.Remove(); TaskList.Items.Insert(n, item); } n--; } if (fi >= 0) { TaskList.SelectedItems[fi].Focused = true; } TaskList.EndUpdate(); } }
void miMoveUp_Click(object sender, EventArgs e) { if (TaskList.Items.Count > 1 && TaskList.SelectedItems.Count > 0) { TaskList.BeginUpdate(); int n = 0; int fi = TaskList.FocusedItem.Index; foreach (ListViewItem item in TaskList.SelectedItems) { int ii = item.Index; if (ii > n) { item.Remove(); TaskList.Items.Insert(ii - 1, item); } else { n++; } } if (fi > n) { TaskList.Items[fi - 1].Focused = true; } TaskList.EndUpdate(); } }
public MainForm() { var psi = new ProcessStartInfo(); psi.FileName = Application.StartupPath + "\\aria2c.exe"; psi.Arguments = "-k2M -x9 -j9 --enable-rpc=true --auto-file-renaming=false --max-download-result=9" + //" --all-proxy=127.0.0.1:8787" + " -l- --log-level=" + AppConfig.Settings.LogLevel + " --stop-with-process=" + Process.GetCurrentProcess().Id; psi.WindowStyle = ProcessWindowStyle.Minimized; Process p = Process.Start(psi); while (!Util.NativeMethods.IsWindowVisible(p.MainWindowHandle)) { Thread.Sleep(5); } Aria2Wnd = p.MainWindowHandle; ShowAria2(AppConfig.Settings.Trace); InitializeComponent(); Tray.Icon = Icon; Tray.Text = Text; // Load tasks ... TaskList.BeginUpdate(); foreach (string s in AppConfig.Settings.Tasks) { NewTask(s); } TaskList.EndUpdate(); AppConfig.Settings.Tasks.Clear(); // Load settings ... FBD.SelectedPath = Directory.Exists(AppConfig.Settings.SavePath) ? AppConfig.Settings.SavePath : AppConfig.Settings.SavePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); Web.ProxyAddr = AppConfig.Settings.Proxy; OFD.FileName = AppConfig.Settings.ExternalDownloader; (miLanguage.DropDownItems[AppConfig.Settings.Language] as ToolStripMenuItem).Checked = true; (miParseOnly.DropDownItems[AppConfig.Settings.ExternalMethod] as ToolStripMenuItem).Checked = true; (miTrace.DropDownItems[AppConfig.Settings.LogLevel] as ToolStripMenuItem).Checked = true; miParseOnly.Checked = AppConfig.Settings.ParseOnly; Parser.Trace = miTrace.Checked = AppConfig.Settings.Trace; Web.UseProxy = miProxy.Checked = AppConfig.Settings.UseProxy; MainSplit.Panel2Collapsed = !(miLog.Checked = AppConfig.Settings.Log) && !Parser.Trace; foreach (ToolStripMenuItem mi in miParseOnly.DropDownItems) { mi.Visible = miParseOnly.Checked; } foreach (ToolStripMenuItem mi in miTrace.DropDownItems) { mi.Visible = miTrace.Checked; } Viewer.ClipboardChanged += Viewer_ClipboardChanged; Viewer.Enabled = miClipboard.Checked = AppConfig.Settings.Clipboard; }
//int count = 0; void downloader_ProgressChanged(object sender, ProgressChangedEventArgs e) { if (!Program.IsClosing) { var downloader = sender as Downloader; var item = downloader.Tag as ListViewItem; switch (e.ProgressPercentage) { case Downloader.STATUS: //TaskList_ColumnClick(null, null); Log(e.UserState as string, sender); break; case Downloader.FILEINFO: item.SubItems[ITEM_NAME].Text = downloader.FileName; if (downloader.FileSize > 0) { item.SubItems[ITEM_SIZE].Text = Util.ToSize(downloader.FileSize); } break; case Downloader.CHANGEURL: item.Name = e.UserState as string; break; case Downloader.NEWURL: StartDownload(e.UserState as string); break; default: #if false if (count == 0) { TaskList.BeginUpdate(); } count++; #endif long progress = (long)e.UserState; long filesize = downloader.FileSize; int speed = downloader.Speed; item.SubItems[ITEM_SIZE].Text = Util.ToSize(downloader.FileSize); item.SubItems[ITEM_SPEED].Text = Util.ToSpeed(speed); if (filesize > 0) { string s = (progress / (double)filesize).ToString("P1"); if (s == "100.0%" && progress < filesize) { s = "99.9%"; } item.SubItems[ITEM_DONE].Text = s; Taskbar.SetProgressValue(progress, filesize); item.SubItems[ITEM_ETA].Text = speed != 0 ? TimeSpan.FromSeconds((filesize - progress) / speed).ToString() : string.Empty; } #if false if (count >= PWeb.Count) { count = 0; TaskList.EndUpdate(); } #endif break; } } }