Exemple #1
0
        internal void Reposition(string name, long newPosition)
        {
            BundledFileInfo bfi = GetFileInfo(name);

            if (bfi != null)
            {
                bfi.Position = newPosition;
            }
        }
Exemple #2
0
        internal IDictionary <string, byte[]> GetFiles(params string[] fileNames)
        {
            if (!readLock.Wait(-1))
            {
                throw new Exception("Failed to obtain read lock for FileBundle " + Path);
            }

            try
            {
                using (FileStream fs = new FileStream(Path, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read))
                {
                    BundleIndex index = new BundleIndex(fs);
                    fs.Seek(0, SeekOrigin.Begin);

                    SortedList <string, byte[]> files = new SortedList <string, byte[]>(fileNames.Length);
                    foreach (string fileName in fileNames)
                    {
                        if (fileName == null)
                        {
                            continue;
                        }

                        BundledFileInfo bfi = index.GetFileInfo(fileName);
                        if (bfi == null)
                        {
                            continue;
                        }
                        fs.Seek(bfi.Position, SeekOrigin.Begin);

                        string name;
                        byte[] data;
                        ReadItem(fs, out name, out data);

                        if (name != fileName)
                        {
                            throw new Exception("Bundle is corrupt. Item name at item location (" + name + ") does not match item name from index (" + fileName + ").");
                        }

                        files.Add(name, data);
                    }
                    return(files);
                }
            }
            finally
            {
                readLock.Release();
            }
        }