Beispiel #1
0
        public void PutLump(BinaryStateLump lump, Action <Stream> callback)
        {
            var name = BinaryStateFileNames.Get(lump);
            var e    = new ZipEntry(name);

            if (Global.Config.SaveStateCompressionLevelNormal == 0)
            {
                e.CompressionMethod = CompressionMethod.Stored;
            }
            else
            {
                e.CompressionMethod = CompressionMethod.Deflated;
            }
            _zip.PutNextEntry(e);
            callback(_zip);
            _zip.CloseEntry();
        }
Beispiel #2
0
        /// <summary>
        /// Gets a lump
        /// </summary>
        /// <param name="lump">lump to retriever</param>
        /// <param name="abort">true to throw exception on failure</param>
        /// <param name="callback">function to call with the desired stream</param>
        /// <returns>true if callback was called and stream was loaded</returns>
        public bool GetLump(BinaryStateLump lump, bool abort, Action <Stream, long> callback)
        {
            var name = BinaryStateFileNames.Get(lump);
            var e    = _zip.GetEntry(name);

            if (e != null)
            {
                using (var zs = _zip.GetInputStream(e))
                {
                    callback(zs, e.Size);
                }

                return(true);
            }

            if (abort)
            {
                throw new Exception("Essential zip section not found: " + name);
            }

            return(false);
        }