Ejemplo n.º 1
0
        public bool HasLump(BinaryStateLump lump)
        {
            string   name = BinaryStateFileNames.GetReadName(lump);
            ZipEntry e;

            return(_entriesbyname.TryGetValue(name, out e));
        }
Ejemplo n.º 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);
     }));
 }
Ejemplo n.º 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);
     }));
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 5
0
 public void PutLump(BinaryStateLump lump, Action <BinaryWriter> callback)
 {
     PutLump(lump, delegate(Stream s)
     {
         var bw = new BinaryWriter(s);
         callback(bw);
         bw.Flush();
     });
 }
Ejemplo n.º 6
0
 public void PutLump(BinaryStateLump lump, Action <TextWriter> callback)
 {
     PutLump(lump, delegate(Stream s)
     {
         TextWriter tw = new StreamWriter(s);
         callback(tw);
         tw.Flush();
     });
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 11
0
		public void PutLump(BinaryStateLump lump, Action<Stream> callback)
		{
			_zip.WriteItem(lump.WriteName, callback);
		}
Ejemplo n.º 12
0
		public void PutLump(BinaryStateLump lump, Action<BinaryWriter> callback)
		{
			PutLump(lump, delegate(Stream s)
			{
				var bw = new BinaryWriter(s);
				callback(bw);
				bw.Flush();
			});
		}
Ejemplo n.º 13
0
 public static string Get(BinaryStateLump lump)
 {
     return(LumpNames[lump]);
 }
Ejemplo n.º 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();
		}
Ejemplo n.º 15
0
 public static string GetReadName(BinaryStateLump lump)
 {
     return(ReadNames[lump]);
 }
Ejemplo n.º 16
0
        public void PutLump(BinaryStateLump lump, Action <Stream> callback)
        {
            var name = BinaryStateFileNames.GetWriteName(lump);

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

            return(_entriesbyname.TryGetValue(lump.ReadName, out e));
        }
Ejemplo n.º 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;
		}
Ejemplo n.º 30
0
 static void AddLumpName(BinaryStateLump token, string name)
 {
     ReadNames[token]  = Path.GetFileNameWithoutExtension(name);
     WriteNames[token] = name;
 }
Ejemplo n.º 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);
			});
		}
Ejemplo n.º 32
0
 public void PutLump(BinaryStateLump lump, Action <Stream> callback)
 {
     _zip.WriteItem(lump.WriteName, callback);
 }
Ejemplo n.º 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);
			});
		}
Ejemplo n.º 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);
			}
		}
Ejemplo n.º 35
0
		public static string Get(BinaryStateLump lump)
		{
			return LumpNames[lump];
		}