HaloOnlineLib.Resources.ResourceDataManager.Replace C# (CSharp) Method

Replace() public method

Replaces the raw data for a resource.
Thrown if the input stream is not open for reading.
public Replace ( ResourceReference resource, Stream dataStream ) : void
resource ResourceReference The resource whose data should be replaced. On success, the reference will be adjusted to account for the new data.
dataStream Stream The stream to read the new data from.
return void
        public void Replace(ResourceReference resource, Stream dataStream)
        {
            if (resource == null)
                throw new ArgumentNullException("resource");
            if (!dataStream.CanRead)
                throw new ArgumentException("The input stream is not open for reading", "dataStream");

            var cache = GetCache(resource);
            using (var stream = cache.File.Open(FileMode.Open, FileAccess.ReadWrite))
            {
                var dataSize = (int)(dataStream.Length - dataStream.Position);
                var data = new byte[dataSize];
                dataStream.Read(data, 0, dataSize);
                var compressedSize = cache.Cache.Compress(stream, resource.Index, data);
                resource.CompressedSize = compressedSize;
                resource.DecompressedSize = (uint)dataSize;
                resource.LocationFlags &= ~(ResourceLocationFlags.UseChecksum | ResourceLocationFlags.UseChecksum2);
            }
        }