SolarGalaxa
New member
- Joined
- Mar 16, 2014
- Messages
- 1
- Programming Experience
- 3-5
I'm converting this open source app to C# (MonoMac) and am stuck because of some Python code.
My C# Code:
More specifically, how do I do the following in C#?
Thanks,
Shane.
C#:
[B]from[/B] [COLOR=#555555]common[/COLOR] [B]import[/B] [B]* #(don't need this, C# has Binary tools)[/B]
[B]class[/B] [COLOR=#445588][B]U8[/B][/COLOR](WiiArchive):
[B]class[/B] [COLOR=#445588][B]U8Header[/B][/COLOR](Struct):
__endian__ [B]=[/B] Struct[B].[/B]BE
[B]def[/B] [COLOR=#990000][B]__format__[/B][/COLOR]([COLOR=#999999]self[/COLOR]):
[COLOR=#999999]self[/COLOR][B].[/B]tag [B]=[/B] Struct[B].[/B]string([COLOR=#009999]4[/COLOR])
[COLOR=#999999]self[/COLOR][B].[/B]rootnode_offset [B]=[/B] Struct[B].[/B]uint32
[COLOR=#999999]self[/COLOR][B].[/B]header_size [B]=[/B] Struct[B].[/B]uint32
[COLOR=#999999]self[/COLOR][B].[/B]data_offset [B]=[/B] Struct[B].[/B]uint32
[COLOR=#999999]self[/COLOR][B].[/B]zeroes [B]=[/B] Struct[B].[/B]string([COLOR=#009999]16[/COLOR])
[B]class[/B] [COLOR=#445588][B]U8Node[/B][/COLOR](Struct):
__endian__ [B]=[/B] Struct[B].[/B]BE
[B]def[/B] [COLOR=#990000][B]__format__[/B][/COLOR]([COLOR=#999999]self[/COLOR]):
[COLOR=#999999]self[/COLOR][B].[/B]type [B]=[/B] Struct[B].[/B]uint16
[COLOR=#999999]self[/COLOR][B].[/B]name_offset [B]=[/B] Struct[B].[/B]uint16
[COLOR=#999999]self[/COLOR][B].[/B]data_offset [B]=[/B] Struct[B].[/B]uint32
[COLOR=#999999]self[/COLOR][B].[/B]size [B]=[/B] Struct[B].[/B]uint32
[B]def[/B] [COLOR=#990000][B]__init__[/B][/COLOR]([COLOR=#999999]self[/COLOR]):
[COLOR=#999999]self[/COLOR][B].[/B]files [B]=[/B] []
[B]def[/B] [COLOR=#990000][B]_dump[/B][/COLOR]([COLOR=#999999]self[/COLOR]):
header [B]=[/B] [COLOR=#999999]self[/COLOR][B].[/B]U8Header()
rootnode [B]=[/B] [COLOR=#999999]self[/COLOR][B].[/B]U8Node()
[COLOR=#999988][I]# constants[/I][/COLOR]
header[B].[/B]tag [B]=[/B] [COLOR=#DD1144]"U[/COLOR][COLOR=#DD1144]\xAA[/COLOR][COLOR=#DD1144]8-"[/COLOR]
header[B].[/B]rootnode_offset [B]=[/B] [COLOR=#009999]0x20[/COLOR]
header[B].[/B]zeroes [B]=[/B] [COLOR=#DD1144]"[/COLOR][COLOR=#DD1144]\x00[/COLOR][COLOR=#DD1144]"[/COLOR] [B]*[/B] [COLOR=#009999]16[/COLOR]
rootnode[B].[/B]type [B]=[/B] [COLOR=#009999]0x0100[/COLOR]
nodes [B]=[/B] []
strings [B]=[/B] [COLOR=#DD1144]'[/COLOR][COLOR=#DD1144]\x00[/COLOR][COLOR=#DD1144]'[/COLOR]
data [B]=[/B] [COLOR=#DD1144]''[/COLOR]
My C# Code:
C#:
[FONT=Menlo][COLOR=#0000ff]using[/COLOR][COLOR=#000000] System[/COLOR][COLOR=#000000];[/COLOR]
[COLOR=#0000ff]using[/COLOR][COLOR=#000000] System[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]IO[/COLOR][COLOR=#000000];[/COLOR]
[COLOR=#0000ff]using[/COLOR][COLOR=#000000] System[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Collections[/COLOR][COLOR=#000000];[/COLOR]
[COLOR=#0000ff]namespace[/COLOR][COLOR=#000000] Blackhole[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]IO[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Archive[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#0000ff]public[/COLOR][COLOR=#000000] [/COLOR][COLOR=#0000ff]class[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2b8faf]Archive[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#0000ff]public[/COLOR][COLOR=#000000] [/COLOR][COLOR=#0000ff]struct[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2b8faf]U8Header[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#0000ff]public[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2b8faf]String[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]tag[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2b8faf]UInt32[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]0x55AA382D[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000];[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#0000ff]public[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2b8faf]UInt32[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]rootnode_offset[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]0x20[/COLOR][COLOR=#000000];[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#0000ff]public[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2b8faf]UInt32[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]header_size[/COLOR][COLOR=#000000];[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#0000ff]public[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2b8faf]UInt32[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]data_offset[/COLOR][COLOR=#000000];[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#0000ff]public[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2b8faf]String[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]zeros[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]0x0[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]*[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]16[/COLOR][COLOR=#000000];[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#000000]}[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#0000ff]public[/COLOR][COLOR=#000000] [/COLOR][COLOR=#0000ff]struct[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2b8faf]U8Node[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#0000ff]public[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2b8faf]UInt16[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]type_offset[/COLOR][COLOR=#000000];[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#0000ff]public[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2b8faf]UInt16[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]name_offset[/COLOR][COLOR=#000000];[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#0000ff]public[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2b8faf]UInt32[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]data_offset[/COLOR][COLOR=#000000];[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#0000ff]public[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2b8faf]UInt32[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]size[/COLOR][COLOR=#000000];[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#000000]}[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#0000ff]public[/COLOR][COLOR=#000000] [/COLOR][COLOR=#0000ff]void[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]dumpArchive[/COLOR][COLOR=#000000]([/COLOR][COLOR=#2b8faf]String[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]fileName[/COLOR][COLOR=#000000])[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#0000ff]using[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]([/COLOR][COLOR=#2b8faf]MemoryStream[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]inMemory[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] [/COLOR][COLOR=#0000ff]new[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2b8faf]MemoryStream[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]fileName[/COLOR][COLOR=#000000]))[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#0000ff]using[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]([/COLOR][COLOR=#2b8faf]BinaryReader[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]reader[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] [/COLOR][COLOR=#0000ff]new[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2b8faf]BinaryReader[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]inMemory[/COLOR][COLOR=#000000]))[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#000000]}[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#000000]}[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#000000]}[/COLOR]
[COLOR=#000000] [/COLOR][COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR][/FONT][FONT=Menlo]
[/FONT]
More specifically, how do I do the following in C#?
C#:
nodes [B]=[/B] []
strings [B]=[/B] [COLOR=#DD1144]'[/COLOR][COLOR=#DD1144]\x00[/COLOR][COLOR=#DD1144]'[/COLOR]
data [B]=[/B] [COLOR=#DD1144]''[/COLOR]
C#:
[B]def[/B] [COLOR=#990000][B]__init__[/B][/COLOR]([COLOR=#999999]self[/COLOR]):
[COLOR=#999999]self[/COLOR][B].[/B]files [B]=[/B] []
Thanks,
Shane.
Last edited: