private void EnsurePackageFiles() { if ((this._files == null) || ((this._expandedFolderPath == null) || !this._expandedFileSystem.DirectoryExists(this._expandedFolderPath))) { this._files = new Dictionary <string, PhysicalPackageFile>(); this._supportedFrameworks = null; PackageName key = new PackageName(base.Id, base.Version); if (!ReferenceEquals(this._expandedFileSystem, _tempFileSystem) && !this._forceUseCache) { this._expandedFolderPath = this.GetExpandedFolderPath(); } else { Tuple <string, DateTimeOffset> tuple; DateTimeOffset lastModified = this._fileSystem.GetLastModified(this._packagePath); if (!_cachedExpandedFolder.TryGetValue(key, out tuple) || (tuple.Item2 < lastModified)) { tuple = Tuple.Create <string, DateTimeOffset>(this.GetExpandedFolderPath(), lastModified); _cachedExpandedFolder[key] = tuple; } this._expandedFolderPath = tuple.Item1; } using (Stream stream = this.GetStream()) { using (IEnumerator <PackagePart> enumerator = (from part in Package.Open(stream).GetParts() where ZipPackage.IsPackageFile(part) select part).GetEnumerator()) { string path; string str2; goto TR_0023; TR_000E: PhysicalPackageFile file1 = new PhysicalPackageFile(); file1.SourcePath = this._expandedFileSystem.GetFullPath(str2); file1.TargetPath = path; this._files[path] = file1; TR_0023: while (true) { if (enumerator.MoveNext()) { PackagePart current = enumerator.Current; path = UriUtility.GetPath(current.Uri); str2 = Path.Combine(this._expandedFolderPath, path); bool flag = true; if (this._expandedFileSystem.FileExists(str2)) { using (Stream stream2 = current.GetStream()) { using (Stream stream3 = this._expandedFileSystem.OpenFile(str2)) { flag = stream2.Length != stream3.Length; } } } if (flag) { Stream stream4 = current.GetStream(); try { using (Stream stream5 = this._expandedFileSystem.CreateFile(str2)) { stream4.CopyTo(stream5); } } catch (Exception) { } finally { if (stream4 != null) { stream4.Dispose(); } } } } else { return; } break; } goto TR_000E; } } } }
private void EnsurePackageFiles() { if (_files != null && _expandedFolderPath != null && _expandedFileSystem.DirectoryExists(_expandedFolderPath)) { return; } _files = new Dictionary <string, PhysicalPackageFile>(); _supportedFrameworks = null; var packageName = new PackageName(Id, Version); // Only use the cache for expanded folders under %temp%. if (_expandedFileSystem == _tempFileSystem) { _expandedFolderPath = _cachedExpandedFolder.GetOrAdd(packageName, _ => GetExpandedFolderPath()); } else { _expandedFolderPath = GetExpandedFolderPath(); } using (Stream stream = GetStream()) { Package package = Package.Open(stream); // unzip files inside package var files = from part in package.GetParts() where ZipPackage.IsPackageFile(part) select part; // now copy all package's files to disk foreach (PackagePart file in files) { string path = UriUtility.GetPath(file.Uri); string filePath = Path.Combine(_expandedFolderPath, path); using (Stream partStream = file.GetStream()) { // only copy the package part to disk if there doesn't exist // a file with the same name. if (!_expandedFileSystem.FileExists(filePath)) { using (Stream targetStream = _expandedFileSystem.CreateFile(filePath)) { partStream.CopyTo(targetStream); } } } var packageFile = new PhysicalPackageFile { SourcePath = _expandedFileSystem.GetFullPath(filePath), TargetPath = path }; _files[path] = packageFile; } } }