/// <param name="download_url">Url of file to download</param> /// <param name="download_dest">Directory where to save the file</param> /// <param name="checksumField">Checksum instance of file or null</param> /// <returns> /// An <see cref="Capuchin.Downloaders.AbstractDownloader" /> instance to /// download the given file /// </returns> internal int DownloadFile(string download_url, string download_dest, string signature, checksum checksumField) { Download dl = new Download(this.downloadsIndex, download_url, download_dest, signature, checksumField); Downloaders.AbstractDownloader downloader = this.GetDownloader(this.downloadsIndex, dl); downloader.Status += new Downloaders.StatusHandler( this.OnDownloadStatus ); downloader.Finished += new Downloaders.FinishedHandler( this.DownloadFinishedCallback ); Thread downloaderThread = new Thread( new ThreadStart(downloader.Download) ); dl.Downloader = downloaderThread; lock (this) { this.Downloads.Add( this.downloadsIndex, dl ); this.downloadsIndex++; downloaderThread.Start(); } Log.Info("Started downloading file {0} to {1} with id '{2}'", download_url, download_dest, this.downloadsIndex-1); return (this.downloadsIndex-1); }
/// <summary>Check checksum and signature of the file</summary> /// <param name="local_file">Path to the downloaded file</param> /// <param name="signature">URL of the signature file</param> /// <param name="checksumField">Checksum information</param> internal void CheckFile(string local_file, string signature, checksum checksumField) { Log.Info ("Checking file"); if (checksumField != null) { FileStream fs = new FileStream( local_file, FileMode.Open ); ChecksumVerifier cv = new ChecksumVerifier( fs, checksumField ); fs.Close(); Log.Info("Checksum valid for {0}: {1}", local_file, cv.IsValid); if (!cv.IsValid) { // Checksum is invalid File.Delete(local_file); return; } } if (signature != null) { GnuPGVerifier gv = new GnuPGVerifier(local_file, signature); Log.Info("Signature valid for {0}: {1}", local_file, gv.IsValid); if (!gv.IsValid) { // Signature invalid File.Delete(local_file); return; } } }