System.IO Extension

Post here the finished release of your halo 2 mod project.
Post Reply
User avatar
XZodia
Staff
Posts: 2208
Joined: Sun Dec 09, 2007 2:09 pm
Location: UK
Contact:

System.IO Extension

Post by XZodia »

This is a little something I whipped up, since I've never been satisfied with existing forms of reading/writing data to a file...

The main class in this library is the DataStream which is a wrapper which combines the binary reader and binary writer with a few extra features:
  • Bookmark Stack -
    • IMO this is one of the best ideas I've ever come up with, its also very simple. If you are at a point in a file but you want to go to another part of the file and then return (eg for a reflexive), simply ".PushBookmark" to add a return point and ".PopBookmark" to return. An understanding of the stack structure is good to understand how useful this is.
    3 Different String Read/Write Methods -
    • When reading or writing a string you can specify how to do so. There are 3 options, Characters Only (When reading this requires the user to specify the character count), Null Terminated and System IO Standard.
      Reverse bool: If true the string is automatically reversed after read / before write.
    Memory Stream Read/Write -
    • Just a simple wrapper that returns a MemoryStream instead of a byte array.
    Flags Read/Write - Ability to read/write the included Flags class.
    IDatatizable Read/Write - Ability to read/write any user defined class/struct via the included IDatatizable interface.
    Extendible Design - The Binary Reader and Binary Writer are exposed to inherited class to allow you to easily add your own read/write functions.
The IDatatizable interface adds a Write(DataStream) void to your class/struct where you can write whatever info you like to write your class. To read your class/struct from a DataStream add a constructor with just a DataStream variable and read whatever info you like.

The Flags class is an abstact class with 4 ready made inherited classes (8,16,32,64 bits). To see how to expand on these look at the source. The Flags class uses a compact algorithm which I came up with to read/write bits, people who hate messy code should like it :P

Bare in mind I haven't tested any of this, so if you find any bugs let me know (its possible the flags write in reverse for halo standards but its easy to fix if this is the case)

Source Code Here
Attachments
System.IO Extension.zip
(4.1 KiB) Downloaded 316 times
Image
JacksonCougar wrote:I find you usually have great ideas.
JacksonCougar wrote:Ah fuck. Why must you always be right? Why.
User avatar
Eaton
Posts: 608
Joined: Mon Apr 21, 2008 7:44 pm
Location: USA
Contact:

Re: System.IO Extension

Post by Eaton »

Looks useful... Even though I don't know how to use it. :P
User avatar
Aumaan Anubis
Staff
Posts: 1812
Joined: Thu Dec 13, 2007 12:18 am
Contact:

Re: System.IO Extension

Post by Aumaan Anubis »

Yeah, I'm guessing it's an upgraded System.IO(gasp, how'd I figure that out? :P ) thing for C# programming. Used particularly(at least for me), reading and writing from files.
User avatar
XZodia
Staff
Posts: 2208
Joined: Sun Dec 09, 2007 2:09 pm
Location: UK
Contact:

Re: System.IO Extension

Post by XZodia »

small code update uploaded but couldn't be bothered updating the source =P
Image
JacksonCougar wrote:I find you usually have great ideas.
JacksonCougar wrote:Ah fuck. Why must you always be right? Why.
Post Reply