void worker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; IArchive compressed = e.Argument as IArchive; DownloadableAddon addon = archiveToAddon[compressed]; string destinationDirectory = this.main.path; int i = 0; foreach (var entry in compressed.Entries) { if (i == 0) { addonToRootPath[addon] = entry.FilePath.Replace("/", ""); } if (!entry.IsDirectory) { try { entry.WriteToDirectory(destinationDirectory, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite); List <object> objectsToGive = new List <object>(); objectsToGive.Add(i); objectsToGive.Add(addon); bytesRecievedOfAddon[addon] += entry.Size; } catch (Exception ex) { ErrorWriter.writeError(ex.Message + " " + ex.StackTrace); } //worker.ReportProgress(1, objectsToGive); } i++; } }
public void extractRar(DownloadableAddon addon, String extention) { try { BackgroundWorker worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.DoWork += new DoWorkEventHandler(worker_DoWork); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged); IArchive compressed = ArchiveFactory.Open(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\" + addon.fileName); compressed.CompressedBytesRead += new EventHandler <CompressedBytesReadEventArgs>(compressed_CompressedBytesRead); archiveToAddon.Add(compressed, addon); backgroundWorkerToAddon.Add(worker, addon); addonToBackgroundDownloader.Add(addon, worker); backGroundWorkerToArchive.Add(worker, compressed); bytesRecievedOfAddon.Add(addon, 0); worker.RunWorkerAsync(compressed); } catch (Exception ex) { int num = (int)MessageBox.Show("Fehler beim entpacken: " + ex.Message); this.main.reportProgress(addon, " - Fehler beim entpacken.", true); } }
private void webClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { WebClient w = (WebClient)sender; speedCounter.Remove(w); this.main.reportProgress(e.UserState as DownloadableAddon, "Entpacke...", true); this.main.AllowUIToUpdate(); DownloadableAddon addon = e.UserState as DownloadableAddon; addon.fileName = System.IO.Path.GetFileName(addon.Link); string extension = Path.GetExtension(addon.fileName); if (extension == ".zip" && false) { this.extractZip(addon); this.removeDownloadedAddon(addon); } else { this.extractRar(addon, extension); } /*else * { * int num = (int)MessageBox.Show("Das addon " + addon.fileName + " hat ein unbekanntes dateiformat. (Es werden nur .zip und .rar erkannt"); * }*/ ConfigManager.writeVersionFileForAddon(addon, this.main.path); }
private bool isNewerVersionOfAddonUploaded(DownloadableAddon addon) { foreach (System.Windows.Controls.CheckBox checkBox in (IEnumerable)this.listAddons.Items) { if ((checkBox.Content as string).Equals(addon.name) && checkBox.Tag != null && checkBox.Tag is DownloadableAddon) { return((checkBox.Tag as DownloadableAddon).version < addon.version); } } return(true); }
public void removeDownloadedAddon(DownloadableAddon addon) { try { System.IO.File.Delete(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\" + addon.fileName); } catch (Exception ex) { int num = (int)MessageBox.Show("Konnte Addon " + addon.name + " nicht löschen. " + ex.Message); } }
void compressed_CompressedBytesRead(object sender, CompressedBytesReadEventArgs e) { DownloadableAddon addon = archiveToAddon[sender as IArchive]; BackgroundWorker worker = addonToBackgroundDownloader[addon]; List <object> objectsToGive = new List <object>(); objectsToGive.Add(e.CompressedBytesRead); objectsToGive.Add(addon); worker.ReportProgress(1, objectsToGive); }
void worker_ProgressChanged(object sender, ProgressChangedEventArgs e) { List <Object> objects = e.UserState as List <Object>; long BytesRecieved = (long)objects[0]; DownloadableAddon addon = objects[1] as DownloadableAddon; BytesRecieved += bytesRecievedOfAddon[addon]; long TotalBytesToRecieve = backGroundWorkerToArchive[addonToBackgroundDownloader[addon]].TotalSize; double d1 = (double)(BytesRecieved / 1000L) / 1000.0; string str1 = this.doubleToShortenedString(d1); double d2 = (double)(TotalBytesToRecieve / 1000L) / 1000.0; string str2 = this.doubleToShortenedString(d2); double d3 = 100.0 / d2 * d1; this.main.reportProgress(addon, " Entpacke: " + str1 + " MB / " + str2 + " MB (" + this.doubleToShortenedString(d3) + "%)", false); }
public void downloadAddon(DownloadableAddon addon) { bool flag = false; string str = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\"; flag = false; WebClient webClient = (WebClient) new WebClient(); webClient.Proxy = (IWebProxy)null; webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(this.webClient_DownloadFileCompleted); webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(this.webClient_DownloadProgressChanged); webClient.DownloadFileAsync(new Uri(addon.Link), str + System.IO.Path.GetFileName(addon.Link), (object)addon); NetSpeedCounter counter = new NetSpeedCounter(webClient); speedCounter.Add(webClient, counter); counter.Start(); }
public void addonWasSuccesfullyExtracted(DownloadableAddon addon) { --this.currentDownloadCount; System.Windows.Controls.CheckBox checkBox1 = (System.Windows.Controls.CheckBox)null; foreach (System.Windows.Controls.CheckBox checkBox2 in (IEnumerable)this.listAllPheonixAddons.Items) { if ((checkBox2.Tag as DownloadableAddon).name.Equals(addon.fileName)) { checkBox1 = checkBox2; break; } } if (checkBox1 == null) { return; } this.checkForAddons(true); this.getDownloadableAddons(); }
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { DownloadableAddon addon = backgroundWorkerToAddon[sender as BackgroundWorker]; IArchive archive = backGroundWorkerToArchive[sender as BackgroundWorker]; String pathName = addonToRootPath[addon]; archiveToAddon.Remove(archive); backgroundWorkerToAddon.Remove(sender as BackgroundWorker); addonToBackgroundDownloader.Remove(addon); backGroundWorkerToArchive.Remove(sender as BackgroundWorker); addonToRootPath.Remove(addon); this.main.reportProgress(addon, " durchsuche Ordner", false); List <String> pathes = new List <string>(); getRealModFolders(main.path + "\\" + pathName, ref pathes); copyFoldersToRightPosition(pathes); this.main.reportProgress(addon, " Fertig.", false); }
public void extractZip(DownloadableAddon addon) { try { string fileName = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\" + addon.fileName; string baseDirectory = this.main.path; using (ZipFile zipFile = ZipFile.Read(fileName)) { foreach (ZipEntry zipEntry in zipFile) { zipEntry.Extract(baseDirectory, ExtractExistingFileAction.OverwriteSilently); } } this.main.addonWasSuccesfullyExtracted(addon); } catch (Exception ex) { int num = (int)MessageBox.Show("Fehler beim entpacken: " + ex.Message); this.main.reportProgress(addon, " - Fehler beim entpacken.", true); } }