void miTrace_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { foreach (ToolStripMenuItem mi in miTrace.DropDownItems) { mi.Checked = false; } (e.ClickedItem as ToolStripMenuItem).Checked = true; AppConfig.Settings.LogLevel = e.ClickedItem.Name; Aria2.SetOptions("log:,log-level:" + AppConfig.Settings.LogLevel); Aria2.SetOptions("log:-"); // restart logging }
void Download_File(string url) { string r = string.IsNullOrEmpty(Referer) ? null : string.Format(", \"referer\":\"{0}\"", Referer); string s = string.IsNullOrEmpty(FileName) ? null : string.Format(", \"out\":\"{0}\"", FileName); string t = string.Format("[\"{0}\"], {{\"dir\":\"{1}\"{2}{3}}}", url, SavePath.Replace("\\", "/"), r, s); int retrys = url.Contains("pornhub") ? -1 : 3; retry: // add a new download task to aria2 id = Aria2.AddUri(t); if (string.IsNullOrEmpty(id)) { throw new Exception("addUri fail"); } // begin download do { Thread.Sleep(1000); s = Aria2.TellStatus(id, "errorCode, downloadSpeed, completedLength, status, files"); Int32.TryParse(Util.GetSubStr(s, "errorCode\":\"", "\""), out ErrCode); Int32.TryParse(Util.GetSubStr(s, "downloadSpeed\":\"", "\""), out Speed); Int64.TryParse(Util.GetSubStr(s, "completedLength\":\"", "\""), out Transfered); if (FileSize == 0) { FileName = Path.GetFileName(Util.GetSubStr(s, "path\":\"", "\"")); FileSize = Int64.Parse(Util.GetSubStr(s, "\"length\":\"", "\"")); ReportProgress(FILEINFO); } ReportProgress(PROGRESS, Transfered); } while (!CancellationPending && (s.Contains("status\":\"active") || s.Contains("status\":\"paused"))); // end download Aria2.Remove(id); if (ErrCode != 0) { if (ErrCode < 8 && retrys-- != 0) { goto retry; } try { s = ErrMsgs[ErrCode]; } catch { s = "unknown error occurred"; } throw new Exception(s); } }
void BtnReloadClick(object sender, EventArgs e) { Aria2.SetOptions("split:" + MaxConnections.Text, true); }
void MaxConnections_SelectedIndexChanged(object sender, EventArgs e) { AppConfig.Settings.MaxConnections = Convert.ToInt32(MaxConnections.Text); Aria2.SetOptions("split:" + MaxConnections.Text, true); }