public byte[] Extract(string fpath) { Debug.Assert(!string.IsNullOrEmpty(fpath)); fpath = fpath.TrimStart('/'); byte[] content = null; try { var fkey = _files[fpath] as string; content = _files.ContainsKey(fpath) ? _cache[fkey] as byte[] : null; if (content == null) { if (File.Exists(WebPackage)) { using (FileStream fs = new FileStream(WebPackage, FileMode.Open, FileAccess.Read, FileShare.Read)) content = ZipStream.Extract(fs, fpath); } else { // package not exists. using (MemoryStream fs = new MemoryStream(Resources.ResourceManager.GetObject("web") as byte[])) content = ZipStream.Extract(fs, fpath); } // file not exists in _cache. if (content != null) { string key = _files.ContainsKey(fpath) ? _files[fpath] as string : Guid.NewGuid().ToString(); _cache[key] = content; _files[fpath] = key; } } } catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; } return(content); }
public bool Exists(string fpath) { Debug.Assert(!string.IsNullOrEmpty(fpath)); fpath = fpath.TrimStart('/'); bool exists = false; try { exists = _files.ContainsKey(fpath); if (!exists) { if (File.Exists(WebPackage)) { using (FileStream fs = new FileStream(WebPackage, FileMode.Open, FileAccess.Read, FileShare.Read)) exists = ZipStream.IsExists(fs, fpath); } else { // package not exists. using (MemoryStream fs = new MemoryStream(Resources.ResourceManager.GetObject("web") as byte[])) exists = ZipStream.IsExists(fs, fpath); } } if (exists) { if (!_files.ContainsKey(fpath)) { _files[fpath] = Guid.NewGuid().ToString(); } } } catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; } return(exists); }