public bool HasLump(BinaryStateLump lump)
        {
            string   name = BinaryStateFileNames.GetReadName(lump);
            ZipEntry e;

            return(_entriesbyname.TryGetValue(name, out e));
        }
示例#2
0
 public bool GetLump(BinaryStateLump lump, bool abort, Action <BinaryReader, long> callback)
 {
     return(GetLump(lump, abort, delegate(Stream s, long length)
     {
         var br = new BinaryReader(s);
         callback(br, length);
     }));
 }
示例#3
0
 public bool GetLump(BinaryStateLump lump, bool abort, Action <TextReader> callback)
 {
     return(GetLump(lump, abort, delegate(Stream s, long unused)
     {
         var tr = new StreamReader(s);
         callback(tr);
     }));
 }
示例#4
0
 static BinaryStateLump()
 {
     foreach (var prop in typeof(BinaryStateLump).GetProperties(BindingFlags.Public | BindingFlags.Static))
     {
         var    attr  = prop.GetCustomAttributes(false).OfType <NameAttribute>().Single();
         object value = new BinaryStateLump(attr.Name, attr.Ext);
         prop.SetValue(null, value, null);
     }
 }
示例#5
0
 public void PutLump(BinaryStateLump lump, Action <BinaryWriter> callback)
 {
     PutLump(lump, delegate(Stream s)
     {
         var bw = new BinaryWriter(s);
         callback(bw);
         bw.Flush();
     });
 }
示例#6
0
 public void PutLump(BinaryStateLump lump, Action <TextWriter> callback)
 {
     PutLump(lump, delegate(Stream s)
     {
         TextWriter tw = new StreamWriter(s);
         callback(tw);
         tw.Flush();
     });
 }
示例#7
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();
        }
示例#8
0
        /// <param name="lump">lump to retrieve</param>
        /// <param name="abort">pass true to throw exception instead of returning false</param>
        /// <param name="callback">function to call with the desired stream</param>
        /// <returns>true iff stream was loaded</returns>
        /// <exception cref="Exception">stream not found and <paramref name="abort"/> is <see langword="true"/></exception>
        public bool GetLump(BinaryStateLump lump, bool abort, Action <Stream, long> callback)
        {
            if (_entriesByName.TryGetValue(lump.ReadName, out var e))
            {
                using var zs = _zip.GetInputStream(e);
                callback(zs, e.Size);

                return(true);
            }

            if (abort)
            {
                throw new Exception($"Essential zip section not found: {lump.ReadName}");
            }

            return(false);
        }
示例#9
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)
        {
            ZipEntry e;

            if (_entriesbyname.TryGetValue(lump.ReadName, out e))
            {
                using (var zs = _zip.GetInputStream(e))
                {
                    callback(zs, e.Size);
                }

                return(true);
            }

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

            return(false);
        }
示例#10
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);
        }
示例#11
0
		public void PutLump(BinaryStateLump lump, Action<Stream> callback)
		{
			_zip.WriteItem(lump.WriteName, callback);
		}
示例#12
0
		public void PutLump(BinaryStateLump lump, Action<BinaryWriter> callback)
		{
			PutLump(lump, delegate(Stream s)
			{
				var bw = new BinaryWriter(s);
				callback(bw);
				bw.Flush();
			});
		}
示例#13
0
 public static string Get(BinaryStateLump lump)
 {
     return(LumpNames[lump]);
 }
示例#14
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();
		}
 public static string GetReadName(BinaryStateLump lump)
 {
     return(ReadNames[lump]);
 }
        public void PutLump(BinaryStateLump lump, Action <Stream> callback)
        {
            var name = BinaryStateFileNames.GetWriteName(lump);

            _zip.WriteItem(name, callback);
        }
示例#17
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;
		}
示例#18
0
 public IndexedStateLump(BinaryStateLump root)
 {
     _root = root;
     Ext   = _root.Ext;
     Calc();
 }
示例#19
0
 public static string GetWriteName(BinaryStateLump lump)
 {
     return WriteNames[lump];
 }
示例#20
0
 static void AddLumpName(BinaryStateLump token, string name)
 {
     ReadNames[token] = Path.GetFileNameWithoutExtension(name);
     WriteNames[token] = name;
 }
示例#21
0
 public static string GetReadName(BinaryStateLump lump)
 {
     return ReadNames[lump];
 }
示例#22
0
 public void PutLump(BinaryStateLump lump, Action<Stream> callback)
 {
     var name = BinaryStateFileNames.GetWriteName(lump);
     _zip.WriteItem(name, callback);
 }
示例#23
0
 public bool HasLump(BinaryStateLump lump)
 {
     string name = BinaryStateFileNames.GetReadName(lump);
     ZipEntry e;
     return _entriesbyname.TryGetValue(name, out e);
 }
示例#24
0
		public void PutLump(BinaryStateLump lump, Action<TextWriter> callback)
		{
			PutLump(lump, delegate(Stream s)
			{
				TextWriter tw = new StreamWriter(s);
				callback(tw);
				tw.Flush();
			});
		}
示例#25
0
		public IndexedStateLump(BinaryStateLump root)
		{
			_root = root;
			Ext = _root.Ext;
			Calc();
		}
 public static string GetWriteName(BinaryStateLump lump)
 {
     return(WriteNames[lump]);
 }
示例#27
0
		public bool HasLump(BinaryStateLump lump)
		{
			ZipEntry e;
			return _entriesbyname.TryGetValue(lump.ReadName, out e);
		}
示例#28
0
        public bool HasLump(BinaryStateLump lump)
        {
            ZipEntry e;

            return(_entriesbyname.TryGetValue(lump.ReadName, out e));
        }
示例#29
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)
		{
			ZipEntry e;
			if (_entriesbyname.TryGetValue(lump.ReadName, out e))
			{
				using (var zs = _zip.GetInputStream(e))
				{
					callback(zs, e.Size);
				}

				return true;
			}
			
			if (abort)
			{
				throw new Exception("Essential zip section not found: " + lump.ReadName);
			}
			
			return false;
		}
 static void AddLumpName(BinaryStateLump token, string name)
 {
     ReadNames[token]  = Path.GetFileNameWithoutExtension(name);
     WriteNames[token] = name;
 }
示例#31
0
		public bool GetLump(BinaryStateLump lump, bool abort, Action<BinaryReader, long> callback)
		{
			return GetLump(lump, abort, delegate(Stream s, long length)
			{
				var br = new BinaryReader(s);
				callback(br, length);
			});
		}
示例#32
0
 public void PutLump(BinaryStateLump lump, Action <Stream> callback)
 {
     _zip.WriteItem(lump.WriteName, callback);
 }
示例#33
0
		public bool GetLump(BinaryStateLump lump, bool abort, Action<TextReader> callback)
		{
			return GetLump(lump, abort, delegate(Stream s, long unused)
			{
				var tr = new StreamReader(s);
				callback(tr);
			});
		}
示例#34
0
		static BinaryStateLump()
		{
			foreach (var prop in typeof(BinaryStateLump).GetProperties(BindingFlags.Public | BindingFlags.Static))
			{
				var attr = prop.GetCustomAttributes(false).OfType<NameAttribute>().Single();
				object value = new BinaryStateLump(attr.Name, attr.Ext);
				prop.SetValue(null, value, null);
			}
		}
示例#35
0
		public static string Get(BinaryStateLump lump)
		{
			return LumpNames[lump];
		}