void LoadDescriptor() { using (Stream zipStream = PackageFile.OpenRead()) using (var zip = new ZipFile(zipStream)) { var entries = zip.Cast<ZipEntry>(); ZipEntry descriptorFile = entries.FirstOrDefault(x => x.Name.EndsWith(".wrapdesc")); if (descriptorFile == null) throw new InvalidOperationException(String.Format("The package '{0}' doesn't contain a valid .wrapdesc file.", PackageFile.Name)); ZipEntry versionFile = entries.SingleOrDefault(x => x.Name.EqualsNoCase("version")); Version versionFromVersionFile = versionFile != null ? zip.Read(versionFile, x => x.ReadString().ToVersion()) : null; var descriptor = zip.Read(descriptorFile, x => new PackageDescriptorReader().Read(x)); _descriptor = new DefaultPackageInfo(PackageFile.Name, versionFromVersionFile, descriptor); if (Descriptor.Version == null) throw new InvalidOperationException("The package '{0}' doesn't have a valid version, looked in the 'wrapdesc' file, in 'version' and in the package file-name."); } }
void LoadDescriptor() { using (Stream zipStream = PackageFile.OpenRead()) using (var zip = new ZipFile(zipStream)) { var entries = zip.Cast<ZipEntry>(); ZipEntry descriptorFile = entries.FirstOrDefault(x => x.Name.EndsWithNoCase(".wrapdesc")); if (descriptorFile == null) return; ZipEntry versionFile = entries.SingleOrDefault(x => x.Name.EqualsNoCase("version")); SemanticVersion versionFromVersionFile = versionFile != null ? zip.Read(versionFile, x => x.ReadString().Replace("\r","").Replace("\n", "").ToSemVer()) : null; _descriptor = zip.Read(descriptorFile, x => new PackageDescriptorReader().Read(x)); _semver = _descriptor.SemanticVersion ?? versionFromVersionFile ?? _descriptor.Version.ToSemVer(); } }