public ISheet GetSheet(string name)
        {
            const string ExHPathFormat = "exd/{0}.exh";

            if (_Sheets.TryGetValue(name, out WeakReference <ISheet> sheetRef) && sheetRef.TryGetTarget(out ISheet sheet))
            {
                return(sheet);
            }

            //name = FixName(name);
            if (!_AvailableSheets.Contains(name))
            {
                throw new KeyNotFoundException($"Unknown sheet '{name}'");
            }

            string exhPath = string.Format(ExHPathFormat, name);
            File   exh     = PackCollection.GetFile(exhPath);

            Header header = CreateHeader(name, exh);

            sheet = CreateSheet(header);

            _Sheets.GetOrAdd(name, n => new WeakReference <ISheet>(sheet)).SetTarget(sheet);
            return(sheet);
        }
        private void BuildIndex()
        {
            File exRoot = PackCollection.GetFile("exd/root.exl");

            List <string> available = new List <string>();

            using (MemoryStream ms = new MemoryStream(exRoot.GetData())) {
                using (StreamReader s = new StreamReader(ms, Encoding.ASCII)) {
                    s.ReadLine(); // EXLT,2

                    while (!s.EndOfStream)
                    {
                        string line = s.ReadLine();
                        if (string.IsNullOrWhiteSpace(line))
                        {
                            continue;
                        }

                        string[] split = line.Split(',');
                        if (split.Length != 2)
                        {
                            continue;
                        }

                        string name = split[0];
                        int    id   = int.Parse(split[1]);

                        available.Add(name);
                        if (id >= 0)
                        {
                            _SheetIdentifiers.Add(id, name);
                        }
                    }
                }
            }

            _AvailableSheets = new HashSet <string>(available);
        }
Esempio n. 3
0
        public ShPkFile(File sourceFile) {
            SourceFile = sourceFile;

            Build();
        }
 public RelationalHeader(RelationalExCollection collection, string name, File file)
     : base(collection, name, file)
 {
     _Columns = base.Columns.Cast<RelationalColumn>().ToArray();
 }
Esempio n. 5
0
 protected virtual Header CreateHeader(string name, File file)
 {
     return(new Header(this, name, file));
 }
        public bool TryGetFile(uint hash, out File value)
        {
            WeakReference<File> fileRef;
            if (_Files.TryGetValue(hash, out fileRef) && fileRef.TryGetTarget(out value))
                return true;

            Index2File index;
            if (Index.Files.TryGetValue(hash, out index)) {
                value = FileFactory.Get(this.Pack, index);
                if (_Files.ContainsKey(hash))
                    _Files[hash].SetTarget(value);
                else
                    _Files.Add(hash, new WeakReference<File>(value));
                return true;
            }

            value = null;
            return false;
        }
 public bool TryGetFile(string path, out File value)
 {
     uint hash;/*
     if (!_FilePathMap.TryGetValue(path, out hash))
         _FilePathMap.Add(path, hash = Hash.Compute(path));*/
     hash = Hash.Compute(path);
     var result = TryGetFile(hash, out value);
     if (result)
         value.Path = path;
     return result;
 }
        public bool TryGetFile(string name, out File file)
        {
            uint hash;/*
            if (!_FileNameMap.TryGetValue(name, out hash))
                _FileNameMap.Add(name, hash = Hash.Compute(name));*/
            hash = Hash.Compute(name);

            var result = TryGetFile(hash, out file);
            if (result)
                file.Path = string.Format("{0}/{1}", this.Path, name);
            return result;
        }
        public bool TryGetFile(uint key, out File file)
        {
            WeakReference<File> fileRef;
            if (_Files.TryGetValue(key, out fileRef) && fileRef.TryGetTarget(out file))
                return true;

            IndexFile index;
            if (Index.Files.TryGetValue(key, out index)) {
                file = FileFactory.Get(this.Pack, index);
                if (_Files.ContainsKey(key))
                    _Files[key].SetTarget(file);
                else
                    _Files.Add(key, new WeakReference<File>(file));
                return true;
            }

            file = null;
            return false;
        }
        public bool TryGetFile(uint directoryKey, uint fileKey, out File file)
        {
            Directory dir;
            if (TryGetDirectory(directoryKey, out dir))
                return dir.TryGetFile(fileKey, out file);

            file = null;
            return false;
        }
        public bool TryGetFile(string path, out File file)
        {
            var lastSeperator = path.LastIndexOf('/');
            if (lastSeperator < 0) {
                file = null;
                return false;
            }

            var dirPath = path.Substring(0, lastSeperator);
            var baseName = path.Substring(lastSeperator + 1);
            Directory dir;
            if (TryGetDirectory(dirPath, out dir))
                return dir.TryGetFile(baseName, out file);

            file = null;
            return false;
        }