Exemple #1
0
        /// <summary>
        /// Loads data from disk if it isn't already loaded.
        /// </summary>
        public void Load()
        {
            if (Loaded)
            {
                return;
            }
            if (!Written)
            {
                // This shouldn't happen.
                throw new InvalidOperationException("Tried to load unwritten block.");
            }

            GameSave.PushStreamPosition(Address.Item1);
#if DebugVerboseBlocks
            Console.WriteLine("Reading {0} from {1}", GetType(), source);
#endif

            Stream stream = GameSave.GetBlobFile(_address.Item1);
            stream.Seek(_address.Item2, SeekOrigin.Begin);
            var reader = new BinaryReader(stream);

            ReadData(reader);

            Loaded = true;

            UpdateLength();

#if DebugVerboseBlocks
            Console.WriteLine("Read {0} from {1} to {2} == {3}", GetType(), Address, Address.Item2 + Length, stream.Position);
#endif
#if AssertBlockLength
            if (Address.Item2 + Length != stream.Position)
            {
                throw new Exception("Length mismatch in " + GetType() + "!");
            }
#endif
            GameSave.PopStreamPosition(Address.Item1);

            UpdateRecursiveUsedSpace();
        }