Example #1
0
        public void LoadData(Superbundle.IDataInfo dataInfo, Stream output)
        {
            if (dataInfo.InlineData != null)
            {
                if (dataInfo.Size == dataInfo.OriginalSize)
                {
                    if (dataInfo.InlineData.Length != dataInfo.Size)
                    {
                        throw new InvalidOperationException();
                    }

                    output.WriteBytes(dataInfo.InlineData);
                    return;
                }

                using (var temp = new MemoryStream(dataInfo.InlineData, false))
                {
                    CompressionHelper.Decompress(temp, output, dataInfo.OriginalSize);
                }
                return;
            }

            foreach (var installChunkManager in this._InstallChunkManagers.Values)
            {
                if (installChunkManager.LoadData(dataInfo, output) == true)
                {
                    return;
                }
            }

            throw new DataLoadException(string.Format("could not find chunk '{0}'", dataInfo.SHA1));
        }
        public void Load(Superbundle.IDataInfo dataInfo, Stream output)
        {
            if (dataInfo.Size == dataInfo.OriginalSize)
            {
                if (dataInfo.InlineData != null)
                {
                    if (dataInfo.InlineData.Length != dataInfo.Size)
                    {
                        throw new InvalidOperationException();
                    }

                    output.WriteBytes(dataInfo.InlineData);
                }
                else
                {
                    var chunkInfo = this._Lookup.GetChunkVariant(dataInfo);
                    if (chunkInfo == null)
                    {
                        throw new InvalidOperationException();
                    }

                    Load(chunkInfo, output);
                }
            }
            else
            {
                MemoryStream temp;

                if (dataInfo.InlineData != null)
                {
                    if (dataInfo.InlineData.Length != dataInfo.Size)
                    {
                        throw new InvalidOperationException();
                    }

                    temp = new MemoryStream(dataInfo.InlineData, false);
                }
                else
                {
                    var chunkInfo = this._Lookup.GetChunkVariant(dataInfo);
                    if (chunkInfo == null)
                    {
                        throw new InvalidOperationException();
                    }

                    temp = new MemoryStream();
                    Load(chunkInfo, temp);
                    temp.Position = 0;
                }

                using (temp)
                {
                    Decompress(temp, output, dataInfo.OriginalSize);
                }
            }
        }
Example #3
0
        public static void Extract(Superbundle.IDataInfo bundleInfo, ICatalogEntryInfo catalogInfo, Stream output)
        {
            if (bundleInfo == null)
            {
                throw new ArgumentNullException("bundleInfo");
            }

            if (catalogInfo == null)
            {
                throw new ArgumentNullException("catalogInfo");
            }

            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            Stream input;

            if (bundleInfo.InlineData != null)
            {
                if (bundleInfo.InlineData.Length != bundleInfo.Size)
                {
                    throw new InvalidOperationException();
                }

                input = new MemoryStream(bundleInfo.InlineData, false);
            }
            else
            {
                input          = File.OpenRead(catalogInfo.DataPath);
                input.Position = catalogInfo.Offset;
            }

            using (input)
            {
                if (bundleInfo.Size == bundleInfo.OriginalSize)
                {
                    output.WriteFromStream(input, bundleInfo.Size);
                }
                else
                {
                    Decompress(input, output, bundleInfo.OriginalSize);
                }
            }
        }
Example #4
0
        public ICatalogEntryInfo GetEntry(Superbundle.IDataInfo entry)
        {
            List <EntryInfo> infos;

            if (this._EntryInfo.TryGetValue(entry.SHA1.Text, out infos) == false)
            {
                return(null);
            }

            foreach (var candidate in infos)
            {
                if (candidate.CompressedSize == entry.Size &&
                    (candidate.UncompressedSize == 0 || candidate.UncompressedSize == entry.OriginalSize))
                {
                    return(candidate);
                }
            }

            return(null);
        }
Example #5
0
 public IChunkVariantInfo GetChunkVariant(Superbundle.IDataInfo resourceInfo)
 {
     return(this.GetChunkVariant(resourceInfo.SHA1, resourceInfo.Size));
 }