From 779300236a4bc3cda33fbdf91411b7a40c17b16d Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 15 May 2005 20:46:43 +0000 Subject: Implemented load/save and tidied some editor control bugs --- Util.cs | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'Util.cs') diff --git a/Util.cs b/Util.cs index ea67003..f7b3bab 100644 --- a/Util.cs +++ b/Util.cs @@ -20,6 +20,7 @@ using System; using System.Windows.Forms; using System.Text; +using System.IO; namespace BitmapFontEd { @@ -56,6 +57,66 @@ namespace BitmapFontEd MessageBoxButtons.OK,MessageBoxIcon.Information); } + + public static uint ReadUint(Stream str) + { + uint l=0; + + for(int f=0;f<4;f++) + { + int b=str.ReadByte(); + l|=(uint)(b<<(f*8)); + } + + return l; + } + + public static int ReadInt(Stream str) + { + int l=0; + + for(int f=0;f<4;f++) + { + int b=str.ReadByte(); + l|=b<<(f*8); + } + + return l; + } + + public static void WriteUint(Stream str, uint l) + { + for(uint f=0;f<4;f++) + { + str.WriteByte((byte)(l&0xff)); + l=l>>8; + } + } + + public static void WriteInt(Stream str, int l) + { + for(uint f=0;f<4;f++) + { + str.WriteByte((byte)(l&0xff)); + l=l>>8; + } + } + + public static void WriteString(Stream str, string s) + { + byte[] b=Encoding.ASCII.GetBytes(s); + + str.Write(b,0,b.Length); + } + + public static string ReadString(Stream str, int len) + { + byte[] b=new byte[len]; + + str.Read(b,0,len); + return Encoding.ASCII.GetString(b); + } + private Util() { } -- cgit v1.2.3