Exemplo n.º 1
0
        public byte[] Extract(string fpath)
        {
            this.Assert(!string.IsNullOrEmpty(fpath));
            if (fpath.StartsWith("/"))
            {
                fpath = fpath.TrimStart('/');
            }

            byte[] content = null;
            try
            {
                content = _webCache.Extract(fpath);
                if (content == null)
                {
                    //if (File.Exists(_pkgLocation))
                    if (Path.IsPathRooted(_pkgLocation))
                    {
                        using (FileStream fs = new FileStream(_pkgLocation, FileMode.Open, FileAccess.Read, FileShare.Read))
                            content = ZipStream.Extract(fs, fpath);
                    }
                    else
                    {
                        var assembly = System.Reflection.Assembly.GetEntryAssembly();
                        var rs       = assembly.GetManifestResourceStream(_pkgLocation);
                        content = ZipStream.Extract(rs, fpath);
                    }
                    if (content != null)
                    {
                        _webCache.Add(fpath, content);
                    }
                }
            }
            catch (Exception ex) { TraceLog.WriteException(ex); throw; }
            return(content);
        }