public PackageStream(string packageFile, string path)
        {
#if !MOBILE
            log.InfoFormat("open package file {0} from {1}", path, packageFile);
#endif
            var zipFile = PackageStream.GetZipFile(PackageStream.NormalizePath(packageFile));

            if (zipFile == null)
            {
                throw PackageStream.FileNotFoundException(path, packageFile);
            }

            var entryIndex = zipFile.FindEntry(path, true);
            if (entryIndex == -1)
            {
                throw PackageStream.FileNotFoundException(path, packageFile);
            }

            try
            {
                _zipStream = zipFile.GetInputStream(entryIndex);
            }
            catch (Exception ex)
            {
                throw new IOException(string.Format("failed to open {0} in {1}", path, packageFile), ex);
            }
        }
Exemple #2
0
        public PackageStream(string packageFile, string path)
        {
            Log.InfoFormat("open package file {0} from {1}", path, packageFile);
            var zipFile = PackageStream.GetCachedZipFile(PackageStream.NormalizePath(packageFile));

            try
            {
                var entryIndex = zipFile.FindEntry(path, true);
                _zipStream = zipFile.GetInputStream(entryIndex);
            }
            catch (Exception)
            {
                throw new FileNotFoundException($"cannot find {path} in {packageFile}");
            }
        }
        public static long?GetCrc(string packageFile, string path)
        {
#if !MOBILE
            log.InfoFormat("open package file {0} from {1}", path, packageFile);
#endif
            var zipFile = PackageStream.GetZipFile(PackageStream.NormalizePath(packageFile));
            try
            {
                var entryIndex = zipFile.FindEntry(path, true);
                var entry      = zipFile[entryIndex];
                return(entry.HasCrc ? entry.Crc : (long?)null);
            }
            catch (Exception)
            {
                throw PackageStream.FileNotFoundException(path, packageFile);
            }
        }
Exemple #4
0
        private static ZipFile GetCachedZipFile(string packageFile)
        {
            if (!File.Exists(packageFile))
            {
                return(null);
            }

            packageFile = PackageStream.NormalizePath(packageFile);

            if (!SCachedZipFiles.TryGetValue(packageFile, out ZipFile zipFile))
            {
                var stream = File.OpenRead(packageFile);

                zipFile = new ZipFile(stream);

                lock (SCachedZipFilesSyncObject)
                    SCachedZipFiles[packageFile] = zipFile;
            }

            return(zipFile);
        }