private void frmDownloader_Load(object sender, System.EventArgs e) { try { //bool progressBar; //long size; this.cancelEvent = new AutoResetEvent(false); //fileNameLabel.text=System.IO.Path.Get // if(progressBar) // { // this.lblfilesize.Text =size.ToString(); // } this.fileNameLabel.Text = System.IO.Path.GetFileName(this.strurldownload); this.lbldestination.Text = this.strurlStore; // System.Windows.Forms.MessageBox.Show(ToShortPathName(this.strurlStore)); DownloadInstructions instructions = new DownloadInstructions (this.strurldownload, this.strurlStore); ThreadPool.QueueUserWorkItem(new WaitCallback(this.SingleDownload), instructions); } catch (Exception exp) { WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("Managecontents==>frmDownloader.cs 500", exp, null, false); } }
private void SingleDownload(object data) { //this.Invoke(this.activeStateChanger, new object[]{true, true}); try { DownloadInstructions instructions = (DownloadInstructions)data; //GetFileSize(url, out progressKnown); //this.Invoke(this.fileNameChanger, new object[]{Path.GetFileName(instructions.Destination)}); using (FileDownloader dL = new FileDownloader()) { dL.ProgressChanged += new DownloadProgressHandler(this.SingleProgressChanged); dL.StateChanged += new DownloadProgressHandler(this.StateChanged); dL.Download(instructions.URLs, instructions.Destination, this.cancelEvent); } } catch (Exception exp) { WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("Managecontents==>frmDownloader.cs 354", exp, null, false); } //this.Invoke(this.activeStateChanger, new object[]{false, true}); }
private DownloadInstructions ParseDownloadInstructionsV1(DownloadInstructions instructions, XmlDocument doc) { //public string InstructionsVersion { get; set; } (already got) //public string ModVersion { get; set; } //public string ClientVersion { get; set; } //public DownloadTypes DownloadType { get; set; } //public string UpdateURL { get; set; } foreach (XmlNode node in doc.ChildNodes[1].ChildNodes) { switch (node.Name) { case "ModVersion": instructions.ModVersion = node.InnerText.Trim(); break; case "ClientVersion": instructions.ClientVersion = node.InnerText.Trim(); break; case "DownloadType": instructions.DownloadType = (DownloadTypes)Enum.Parse(instructions.DownloadType.GetType(), node.InnerText.Trim()); break; case "UpdateURL": instructions.UpdateURL = node.InnerText.Trim(); break; case "DownloadFilename": instructions.DownloadFilename = node.InnerText.Trim(); break; } } return(instructions); }
private DownloadInstructions ParseDownloadInstructions(XmlDocument doc, string databaseZipFileDownloadLocation) { DownloadInstructions instructions = new DownloadInstructions() { DownloadedDatabaseZipFileLocation = databaseZipFileDownloadLocation }; string formatVersion = doc.DocumentElement.Attributes["formatVersion"].Value.Trim(); instructions.InstructionsVersion = formatVersion; switch (formatVersion) { case "1.0": ParseDownloadInstructionsV1(instructions, doc); break; } return(instructions); }
private void frmDownloader_Load(object sender, System.EventArgs e) { try { //bool progressBar; //long size; this.cancelEvent = new AutoResetEvent(false); //fileNameLabel.text=System.IO.Path.Get // if(progressBar) // { // this.lblfilesize.Text =size.ToString(); // } this.fileNameLabel.Text = System.IO.Path.GetFileName(this.strurldownload); this.lbldestination.Text=this.strurlStore; // System.Windows.Forms.MessageBox.Show(ToShortPathName(this.strurlStore)); DownloadInstructions instructions = new DownloadInstructions (this.strurldownload,this.strurlStore); ThreadPool.QueueUserWorkItem(new WaitCallback(this.SingleDownload), instructions); } catch(Exception exp) { WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("Managecontents==>frmDownloader.cs 500",exp,null,false); } }
private async Task <bool> ProcessWotmodUpdate(DatabasePackage package) { Logging.Editor("Processing wotmod update"); DownloadInstructions downloadInstructions = package.DownloadInstructions; UpdateInstructions updateInstructions = package.UpdateInstructions; //verify that only one wotmod file exists in database file and get crc Logging.Editor("Checking for only 1 .wotmod file in the database zip file"); using (ZipFile databaseZip = new ZipFile(downloadInstructions.DownloadedDatabaseZipFileLocation)) { ZipEntry wotmodEntry = null; foreach (ZipEntry entry in databaseZip) { if (entry.FileName.Contains(".wotmod")) { Logging.Editor("Found entry {0}", LogLevel.Info, entry.FileName); if (wotmodEntry != null) { Logging.Editor("Entry for wotmod processing already exists and will be overriden!", LogLevel.Error); } wotmodEntry = entry; updateInstructions.WotmodOldFilenameInZip = entry.FileName; } } updateInstructions.WotmodDatabaseMD5 = await Utils.CreateMD5HashAsync(wotmodEntry.OpenReader()); } //compare md5 of file in database zip to md5 of downloaded file updateInstructions.WotmodDownloadedMD5 = await Utils.CreateMD5HashAsync(downloadInstructions.DownloadedFileLocation); Logging.Editor("MD5 of download wotmod: {0}", LogLevel.Info, updateInstructions.WotmodDownloadedMD5); Logging.Editor("MD5 of database wotmod: {0}", LogLevel.Info, updateInstructions.WotmodDatabaseMD5); if (updateInstructions.WotmodDownloadedMD5.Equals(updateInstructions.WotmodDatabaseMD5)) { Logging.Editor("MD5 files match, no need to update package"); //DEBUG: comment this out to test method return(false); } //update wotmod file in zip Logging.Editor("MD5s don't match, updating wotmod in database zip with downloaded one"); using (ZipFile databaseZip = new ZipFile(downloadInstructions.DownloadedDatabaseZipFileLocation)) { //remove current entry and add new entry await Task.Run(() => { databaseZip.RemoveEntry(databaseZip[updateInstructions.WotmodOldFilenameInZip]); databaseZip.AddEntry(updateInstructions.WotmodFilenameInZip, File.ReadAllBytes(downloadInstructions.DownloadedFileLocation)); }); //process patch instructions Logging.Editor("Processing patches"); int patchesCount = 0; foreach (PatchUpdate patchUpdate in updateInstructions.PatchUpdates) { Logging.Editor("Processing patch {0} of {1}", LogLevel.Info, ++patchesCount, updateInstructions.PatchUpdates.Count); Logging.Editor(patchUpdate.PatchUpdateInformation); Utils.AllowUIToUpdate(); if (!ProcessUpdatePatch(patchUpdate, databaseZip, package.PackageName)) { Logging.Editor("Failed to process update patch {0}", LogLevel.Error, patchesCount); return(false); } } //save zip changes to disk Logging.Editor("Saving zip file changes to disk"); databaseZip.SaveProgress += DatabaseZip_SaveProgress; await Task.Run(() => { databaseZip.Save(); }); } Logging.Editor("Save complete"); AutoUpdateProgressBar.Value = AutoUpdateProgressBar.Minimum; return(true); }