コード例 #1
0
        string GetOutputPath(string cacheDirectory, PartialZipDownload part)
        {
            var outputPath = new FileInfo(Path.Combine(cacheDirectory, part.Id, part.ToFile));

            outputPath.Directory.Create();
            return(outputPath.FullName);
        }
コード例 #2
0
        async Task <bool> ExtractPartAndValidate(PartialZipDownload part, Stream partInputStream, string cacheDirectory)
        {
            string fileHash = null;

            var outputPath = GetOutputPath(cacheDirectory, part);

            using (var iis = new System.IO.Compression.DeflateStream(partInputStream, System.IO.Compression.CompressionMode.Decompress))
                //using (var iis = new ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream (partInputStream, new ICSharpCode.SharpZipLib.Zip.Compression.Inflater (true)))
                using (var fs = File.Open(outputPath, FileMode.Create)) {
                    await iis.CopyToAsync(fs).ConfigureAwait(false);

                    await fs.FlushAsync().ConfigureAwait(false);

                    fs.Seek(0, SeekOrigin.Begin);
                    fileHash = DownloadUtils.HashMd5(fs);
                    LogDebugMessage("Hash of Downloaded File: {0}", fileHash);

                    fs.Close();
                }

            if (!string.IsNullOrEmpty(part.Md5) && !part.Md5.Equals(fileHash, StringComparison.InvariantCultureIgnoreCase))
            {
                // TODO: HANDLE
                LogMessage("File MD5 Hash was invalid, deleting file: {0}", part.ToFile);
                File.Delete(outputPath);
                return(false);
            }

            return(true);
        }
コード例 #3
0
 public bool IsAlreadyDownloaded(string cacheDirectory, PartialZipDownload partialZipDownload)
 {
     return(File.Exists(Path.Combine(cacheDirectory, partialZipDownload.Id, partialZipDownload.ToFile)));
 }