// 已知清单文件校验值和大小的情况下, 可以使用此接口, 略过 checksum 文件的获取 public static void GetManifestDirect(string localPathRoot, DownloadWorker worker, FileEntry fileEntry, string password, Action <Manifest, FileEntry> callback) { var manifestPath = Path.Combine(localPathRoot, Manifest.ManifestFileName); var manifest_t = ParseManifestFile(manifestPath, fileEntry, password); if (manifest_t != null) { callback(manifest_t, fileEntry); } else { var manifestJob = new DownloadWorker.JobInfo(Manifest.ManifestFileName, fileEntry.checksum, "Manifest", 0, fileEntry.size, manifestPath) { emergency = true, callback = () => { var manifest = ParseManifestStream(File.OpenRead(manifestPath), fileEntry, password); callback(manifest, fileEntry); } }; worker.AddJob(manifestJob); } }
// 基本流程: // 在不知道清单文件校验值和大小的情况下, 使用此接口尝试先下载 checksum 文件, 得到清单文件信息 public static void GetManifest(string localPathRoot, DownloadWorker worker, string checksum, int size, int rsize, string password, Action <Manifest, FileEntry> callback) { if (checksum != null && size != 0 && rsize != 0) { var fileEntry = new FileEntry() { name = Manifest.ManifestFileName, checksum = checksum, size = size, rsize = rsize }; GetManifestDirect(localPathRoot, worker, fileEntry, password, callback); return; } if (!Directory.Exists(localPathRoot)) { Directory.CreateDirectory(localPathRoot); } ReadRemoteFile(ResourceManager.urls, Manifest.ChecksumFileName, content => { var fileEntry = JsonUtility.FromJson <FileEntry>(content); GetManifestDirect(localPathRoot, worker, fileEntry, password, callback); return(true); }); }
private void PatchInstallButton_Click(object sender, EventArgs e) { bool isPatch = true; List <bool> InstallerArguments = new List <bool>(); InstallerArguments.Add(isPatch); InstallerPage.Visible = true; page2patched.Visible = false; DownloadWorker.RunWorkerAsync(InstallerArguments); }
// 基本流程: // 在不知道清单文件校验值和大小的情况下, 使用此接口尝试先下载 checksum 文件, 得到清单文件信息 public static void GetManifest(string localPathRoot, DownloadWorker worker, string checksum, int size, int rsize, string password, int chunkSize, Action <Manifest, ManifestEntry> callback) { if (checksum != null && size > 0 && rsize > 0 && chunkSize > 0) { var fileEntry = new ManifestEntry() { name = Manifest.ManifestFileName, checksum = checksum, size = size, rsize = rsize, chunkSize = chunkSize, }; GetManifestDirect(localPathRoot, worker, fileEntry, password, callback); return; } if (!Directory.Exists(localPathRoot)) { Directory.CreateDirectory(localPathRoot); } ReadRemoteFile(ResourceManager.urls, Manifest.ChecksumFileName, content => { try { if (string.IsNullOrEmpty(content)) { Debug.LogWarning("checksum 无内容"); } else { var fileEntry = JsonUtility.FromJson <ManifestEntry>(content); if (fileEntry != null) { // Debug.LogFormat("checksum {0} {1}", fileEntry.checksum, fileEntry.size); GetManifestDirect(localPathRoot, worker, fileEntry, password, callback); return(true); } Debug.LogWarningFormat("checksum 无法解析 {0}", content); } } catch (Exception exception) { Debug.LogErrorFormat("checksum 解析异常 {0}\n{1}", content, exception); } return(false); }); }
private void OfficialInstallbutton_Click(object sender, EventArgs e) { if (InstallActions.CheckSteamSkinDirectoryExists(SteamSkinPath)) { bool isPatch = false; List <bool> InstallerArguments = new List <bool>(); InstallerArguments.Add(isPatch); page1.Visible = false; InstallerPage.Visible = true; DownloadWorker.RunWorkerAsync(InstallerArguments); } else { MessageBox.Show("No Steam Skin directory found."); } }
private void ImportButton_Click(object sender, EventArgs e) { var youtubeMatch = new Regex(@"youtu(?:\.be|be\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)").Match(TextBox1.Text); if (youtubeMatch.Success) { TextBox1.Enabled = false; ImportButton.Enabled = false; DownloadWorker.RunWorkerAsync("youtube.com/watch?v=" + youtubeMatch.Groups[1].Value); ToolStripStatusLabel1.Text = "Status: Downloading"; } else { MessageBox.Show("Invalid YouTube URL.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); TextBox1.Enabled = true; ImportButton.Enabled = true; } }
private void Button_Click(object sender, RoutedEventArgs e) { //var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(5)); //var token = tokenSource.Token; //if (_running) //{ // _tokenSource.Cancel(); // _running = false; // return; //} //running = true; ToggleButton(false); var testlist = XmlReader.GetXmlFiles(AppSettings.GetXmlFileName()); var lists = DownloadLoader.Partition(testlist, 5); SetupTimer(); // Create and collect tasks in list _starttime = DateTime.Now; var tasks = lists.Select(list => Task.Factory.StartNew(() => { var worker = new DownloadWorker(); worker.Progressed += (o, args) => { lock (this) { _count++; } Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate { var procent = ((100 * _count) / testlist.Count); ProgressBar.Value = procent; ProgressLabel.Content = procent + "%"; //CountLabel.Content = "Total items cleanse: " + _count; if (_count > 0) { EstimateTimeLabel.Content = "Time: " + EstimateTime(testlist.Count).ToString(); } }); }; var path = Directory.GetCurrentDirectory() + AppSettings.GetImagePath(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var result = worker.DownloadeImage(list.ToList(), path); return(result); }, _tokenSource.Token)).ToList(); Task.Factory.StartNew(() => { var results = new List <Log>(); // Wait till all tasks completed foreach (var result in tasks.Select(task => task.Result)) { results.AddRange(result.ToList()); } var path = Directory.GetCurrentDirectory() + AppSettings.GetLogPath(); _timer.Stop(); LogMaker.MakeListLog(results, path); }, _tokenSource.Token); SetupListBox(); }
void dlForm_Download(object sender, DownloadEventArgs e) { if (!String.IsNullOrEmpty(e.Path)) { var worker = new DownloadWorker(e.Path); worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged); worker.RunWorkerAsync(); } }
private void Diagnostics_Load(object sender, EventArgs e) { try { _daddy._ThreadProgressBarTitle = _daddy.GetTranslator().GetString("LblDownloadInProgress"); _daddy.CreateThreadProgressBarEnh(); // Wait for the creation of the bar while (_daddy._ThreadProgressBar == null) { Thread.Sleep(10); Application.DoEvents(); } _daddy._ThreadProgressBar.progressBar1.Maximum = 31; _daddy._ThreadProgressBar.lblWait.Text = "Performing diagnostics..."; ListViewItem item = null; int nb = 0; // Proxy ? if (_daddy.GetProxy() != null) { CreateEntry("OK", "Proxy status", "Defined"); } else { CreateEntry("OK", "Proxy status", "Undefined"); } // Internet access ? if (_daddy.CheckInternetAccess()) { CreateEntry("OK", "Internet access", "Available"); } else { CreateEntry("KO", "Internet access", "Not available"); } // GC account ? String cryptedpass = ConfigurationManager.AppSettings["ownerpassword"]; String username = ConfigurationManager.AppSettings["owner"]; if (username != "") { CreateEntry("OK", "Geocaching login", "Filled"); } else { CreateEntry("KO", "Geocaching login", "Empty"); } if (cryptedpass != "") { CreateEntry("OK", "Geocaching password", "Filled"); } else { CreateEntry("KO", "Geocaching password", "Empty"); } CookieContainer cookie = null; if ((username != "") && (cryptedpass != "")) { cookie = _daddy.CheckGCAccount(true, true); if (cookie != null) { CreateEntry("OK", "Geocaching authentication", "Success"); } else { CreateEntry("KO", "Geocaching authentication", "Error during authentication"); } } else { CreateEntry("KO", "Geocaching authentication", "Login and/or password empty"); } // MGM websites String urlupdate = ConfigurationManager.AppSettings["urlupdate"]; List <string> urls = urlupdate.Split(';').ToList <string>(); foreach (String url in urls) { try { String rep = MyTools.GetRequest(new Uri(url), _daddy.GetProxy(), 2000); if (rep != "") { CreateEntry("OK", "MGM website", "Available: " + url); } else { CreateEntry("KO", "MGM website", "Not available: " + url); } } catch { item = CreateEntry("KO", "MGM website availability", "Not available: " + url); } } // PQ download ? if (cookie == null) { CreateEntry("KO", "Pocket Queries download", "User not authenticated"); } else { String html = _daddy.GetPQDownloadHTML(cookie); PQDownloadHMI pq = new PQDownloadHMI(_daddy); nb = pq.Populate(html, true); if (nb != 0) { CreateEntry("OK", "Pocket Queries download", "Available PQs: " + nb.ToString()); } else { CreateEntry("KO", "Pocket Queries download", "Available PQs: " + nb.ToString()); } } // Images OfflineCacheData ocd = new OfflineCacheData(); WebClient client = new WebClient(); client.Proxy = _daddy.GetProxy(); string htmlCode = client.DownloadString("http://coord.info/GC2MQGF"); DownloadWorker dwnd = new DownloadWorker(_daddy); dwnd.GetImageFromParsingImpl(ocd, false, htmlCode); String s = ""; nb = 0; List <string> images = new List <string>(); foreach (KeyValuePair <String, OfflineImageWeb> paire in ocd._ImageFilesSpoilers) { OfflineImageWeb oid = paire.Value; s += oid._name + ";"; images.Add(oid._name); nb++; } // ;;; if (nb == 4) { if ( (images[0] == "[SPOILER] Cache") && //(images[1] == "Départ du sentier / Start of the trail") && // les accents peuvent faire chier (images[2] == "Le Saule Pleureur / The Weeping Willow") && (images[3] == "Le Saule Pleureur / The Weeping Willow") ) { CreateEntry("OK", "Image/Spoilers download", "Good count and names"); } else { CreateEntry("KO", "Image/Spoilers download", "Bad names"); } } else { CreateEntry("KO", "Image/Spoilers download", "Bad count"); } // Completion d'une cache if (cookie == null) { CreateEntry("KO", "Cache update", "User not authenticated"); } else { htmlCode = _daddy.GetCacheHTMLFromClientImpl("http://coord.info/GCX076", cookie); Geocache geo = new Geocache(_daddy); DataForStatsRetrieval dataforstats = new DataForStatsRetrieval(); dataforstats.cookieJar = cookie; dataforstats.firstQuestion = false; dataforstats.inbmissed = 0; dataforstats.stopScoreRetrieval = false; nb = _daddy._iNbModifiedCaches; _daddy.CompleteCacheFromHTML(geo, htmlCode, null, dataforstats, true); _daddy._iNbModifiedCaches = nb; if (CheckCacheContent(geo)) { CreateEntry("OK", "Cache update", "General success"); } else { CreateEntry("KO", "Cache update", "General failure"); } } _daddy.KillThreadProgressBarEnh(); } catch (Exception exc) { _daddy.KillThreadProgressBarEnh(); _daddy.ShowException("", _daddy.GetTranslator().GetString("FMenuDiagnostics"), exc); } }
private void Button_Click(object sender, RoutedEventArgs e) { //var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(5)); //var token = tokenSource.Token; //if (_running) //{ // _tokenSource.Cancel(); // _running = false; // return; //} //running = true; ToggleButton(false); var testlist = XmlReader.GetXmlFiles(AppSettings.GetXmlFileName()); var lists = DownloadLoader.Partition(testlist, 5); SetupTimer(); // Create and collect tasks in list _starttime = DateTime.Now; var tasks = lists.Select(list => Task.Factory.StartNew(() => { var worker = new DownloadWorker(); worker.Progressed += (o, args) => { lock (this) { _count++; } Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate { var procent = ((100 * _count) / testlist.Count); ProgressBar.Value = procent; ProgressLabel.Content = procent + "%"; //CountLabel.Content = "Total items cleanse: " + _count; if (_count > 0) { EstimateTimeLabel.Content = "Time: " + EstimateTime(testlist.Count).ToString(); } }); }; var path = Directory.GetCurrentDirectory() + AppSettings.GetImagePath(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var result = worker.DownloadeImage(list.ToList(), path); return result; }, _tokenSource.Token)).ToList(); Task.Factory.StartNew(() => { var results = new List<Log>(); // Wait till all tasks completed foreach (var result in tasks.Select(task => task.Result)) { results.AddRange(result.ToList()); } var path = Directory.GetCurrentDirectory() + AppSettings.GetLogPath(); _timer.Stop(); LogMaker.MakeListLog(results, path); }, _tokenSource.Token); SetupListBox(); }