0 people like it.

arcanum #1

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
48: 
49: 
50: 
51: 
52: 
53: 
54: 
55: 
56: 
57: 
58: 
59: 
60: 
61: 
62: 
63: 
64: 
65: 
66: 
67: 
68: 
69: 
70: 
71: 
72: 
73: 
74: 
75: 
76: 
77: 
78: 
79: 
80: 
81: 
82: 
83: 
84: 
85: 
86: 
87: 
88: 
89: 
90: 
91: 
module Divided.ArcanumFiles

open System
open System.IO
open System.IO.Compression
open System.Text
open System.Collections.Generic

let private FileMagic = 827605316
let private CompressedMagic = 0x00000002
let private DirectoryMagic = 0x00000400
let private FooterSize = 28L

let private readSequence (array : byte []) (stream : Stream) pos len =
    let ret = stream.Read(array, pos, len)
    if ret <> len then
        EndOfStreamException() |> raise
    else
        ()

let inline private readByteOrDie (stream : Stream) =
    let ret = stream.ReadByte()
    if ret = -1 then
        EndOfStreamException() |> raise
    else
        ret

let private readInt32 (stream : Stream) =
    let u4 = readByteOrDie stream
    let u3 = readByteOrDie stream
    let u2 = readByteOrDie stream
    let u1 = readByteOrDie stream
    (u4 <<< 24) ||| (u3 <<< 16) ||| (u2 <<< 8) ||| u1

let private readLittleInt32 (stream : Stream) =
    let u1 = readByteOrDie stream
    let u2 = readByteOrDie stream
    let u3 = readByteOrDie stream
    let u4 = readByteOrDie stream
    (u4 <<< 24) ||| (u3 <<< 16) ||| (u2 <<< 8) ||| u1

type ArcanumFile =
    { Compressed: bool; CompressedSize: int32; Offset: int32; Filename: string; Size: int32 }
    member o.GetContents(stream : Stream) =
        let size = o.Size |> int
        stream.Position <- (int64 o.Offset) + (if o.Compressed then 2L else 0L)
        let buf = Array.zeroCreate size
        if o.Compressed then
            use stream = new DeflateStream(stream, CompressionMode.Decompress, true)
            readSequence buf stream 0 size
        else
            readSequence buf stream 0 size
        buf

type ArcanumDat(DatStream : Stream) =
    let _files =
        let sizeTotal = DatStream.Length
        let endOfMetadata = sizeTotal - FooterSize
        DatStream.Position <- endOfMetadata
        let buf16 = Array.zeroCreate 16
        readSequence buf16 DatStream 0 16
        let fileMagic = readInt32 DatStream
        if fileMagic <> FileMagic then
            IOException "bad magic" |> raise
        readInt32 DatStream |> ignore
        let dictSize = readLittleInt32 DatStream
        DatStream.Position <- sizeTotal - (int64 dictSize)
        let entryCount = readLittleInt32 DatStream
        let buf = Array.zeroCreate 1024 |> ref
        let dict = Dictionary(entryCount)
        for i in 0 .. entryCount - 1 do
            let len = readLittleInt32 DatStream
            if len > (!buf).Length then
                Array.Resize(buf, len)
            readSequence !buf DatStream 0 len
            let filename = Encoding.ASCII.GetString(!buf, 0, (len - 1)).ToLowerInvariant()
            readInt32 DatStream |> ignore
            let flags = readLittleInt32 DatStream
            let decompressedSize = readLittleInt32 DatStream
            let compressedSize = readLittleInt32 DatStream
            let offset = readLittleInt32 DatStream
            let compressed = (flags &&& CompressedMagic) <> 0
            if flags &&& DirectoryMagic = 0 then
                dict.Add(filename, { Compressed = compressed; CompressedSize = compressedSize; Offset = offset; Filename = filename; Size = decompressedSize })
        dict
    interface IDisposable with
        member o.Dispose() = DatStream.Close()
    new(filename : String) = new ArcanumDat(File.OpenRead(filename))
    member o.GetFilenames() = _files.Keys
    member o.Files with get filename = _files.[filename]
    override o.ToString() = String.Format("#<ArcanumDat {0:x} {1} total>", o.GetHashCode(), _files.Count)
namespace Divided
module ArcanumFiles

from Divided
namespace System
namespace System.IO
namespace System.IO.Compression
namespace System.Text
namespace System.Collections
namespace System.Collections.Generic
val private FileMagic : int

Full name: Divided.ArcanumFiles.FileMagic
val private CompressedMagic : int

Full name: Divided.ArcanumFiles.CompressedMagic
val private DirectoryMagic : int

Full name: Divided.ArcanumFiles.DirectoryMagic
val private FooterSize : int64

Full name: Divided.ArcanumFiles.FooterSize
val private readSequence : array:byte [] -> stream:Stream -> pos:int -> len:int -> unit

Full name: Divided.ArcanumFiles.readSequence
Multiple items
val array : byte []

--------------------
type 'T array = 'T []

Full name: Microsoft.FSharp.Core.array<_>
Multiple items
val byte : value:'T -> byte (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.byte

--------------------
type byte = Byte

Full name: Microsoft.FSharp.Core.byte
val stream : Stream
type Stream =
  inherit MarshalByRefObject
  member BeginRead : buffer:byte[] * offset:int * count:int * callback:AsyncCallback * state:obj -> IAsyncResult
  member BeginWrite : buffer:byte[] * offset:int * count:int * callback:AsyncCallback * state:obj -> IAsyncResult
  member CanRead : bool
  member CanSeek : bool
  member CanTimeout : bool
  member CanWrite : bool
  member Close : unit -> unit
  member CopyTo : destination:Stream -> unit + 1 overload
  member Dispose : unit -> unit
  member EndRead : asyncResult:IAsyncResult -> int
  ...

Full name: System.IO.Stream
val pos : int
val len : int
val ret : int
Stream.Read(buffer: byte [], offset: int, count: int) : int
Multiple items
type EndOfStreamException =
  inherit IOException
  new : unit -> EndOfStreamException + 2 overloads

Full name: System.IO.EndOfStreamException

--------------------
EndOfStreamException() : unit
EndOfStreamException(message: string) : unit
EndOfStreamException(message: string, innerException: exn) : unit
val raise : exn:Exception -> 'T

Full name: Microsoft.FSharp.Core.Operators.raise
val private readByteOrDie : stream:Stream -> int

Full name: Divided.ArcanumFiles.readByteOrDie
Stream.ReadByte() : int
val private readInt32 : stream:Stream -> int

Full name: Divided.ArcanumFiles.readInt32
val u4 : int
val u3 : int
val u2 : int
val u1 : int
val private readLittleInt32 : stream:Stream -> int

Full name: Divided.ArcanumFiles.readLittleInt32
type ArcanumFile =
  {Compressed: bool;
   CompressedSize: int32;
   Offset: int32;
   Filename: string;
   Size: int32;}
  member GetContents : stream:Stream -> byte []

Full name: Divided.ArcanumFiles.ArcanumFile
ArcanumFile.Compressed: bool
type bool = Boolean

Full name: Microsoft.FSharp.Core.bool
ArcanumFile.CompressedSize: int32
Multiple items
val int32 : value:'T -> int32 (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int32

--------------------
type int32 = Int32

Full name: Microsoft.FSharp.Core.int32
ArcanumFile.Offset: int32
ArcanumFile.Filename: string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = String

Full name: Microsoft.FSharp.Core.string
ArcanumFile.Size: int32
val o : ArcanumFile
member ArcanumFile.GetContents : stream:Stream -> byte []

Full name: Divided.ArcanumFiles.ArcanumFile.GetContents
val size : int
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
property Stream.Position: int64
Multiple items
val int64 : value:'T -> int64 (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int64

--------------------
type int64 = Int64

Full name: Microsoft.FSharp.Core.int64

--------------------
type int64<'Measure> = int64

Full name: Microsoft.FSharp.Core.int64<_>
val buf : byte []
type Array =
  member Clone : unit -> obj
  member CopyTo : array:Array * index:int -> unit + 1 overload
  member GetEnumerator : unit -> IEnumerator
  member GetLength : dimension:int -> int
  member GetLongLength : dimension:int -> int64
  member GetLowerBound : dimension:int -> int
  member GetUpperBound : dimension:int -> int
  member GetValue : [<ParamArray>] indices:int[] -> obj + 7 overloads
  member Initialize : unit -> unit
  member IsFixedSize : bool
  ...

Full name: System.Array
val zeroCreate : count:int -> 'T []

Full name: Microsoft.FSharp.Collections.Array.zeroCreate
val stream : DeflateStream
Multiple items
type DeflateStream =
  inherit Stream
  new : stream:Stream * mode:CompressionMode -> DeflateStream + 1 overload
  member BaseStream : Stream
  member BeginRead : array:byte[] * offset:int * count:int * asyncCallback:AsyncCallback * asyncState:obj -> IAsyncResult
  member BeginWrite : array:byte[] * offset:int * count:int * asyncCallback:AsyncCallback * asyncState:obj -> IAsyncResult
  member CanRead : bool
  member CanSeek : bool
  member CanWrite : bool
  member EndRead : asyncResult:IAsyncResult -> int
  member EndWrite : asyncResult:IAsyncResult -> unit
  member Flush : unit -> unit
  ...

Full name: System.IO.Compression.DeflateStream

--------------------
DeflateStream(stream: Stream, mode: CompressionMode) : unit
DeflateStream(stream: Stream, mode: CompressionMode, leaveOpen: bool) : unit
type CompressionMode =
  | Decompress = 0
  | Compress = 1

Full name: System.IO.Compression.CompressionMode
field CompressionMode.Decompress = 0
Multiple items
type ArcanumDat =
  interface IDisposable
  new : DatStream:Stream -> ArcanumDat
  new : filename:String -> ArcanumDat
  member GetFilenames : unit -> KeyCollection<string,ArcanumFile>
  override ToString : unit -> string
  member Files : filename:string -> ArcanumFile with get

Full name: Divided.ArcanumFiles.ArcanumDat

--------------------
new : filename:String -> ArcanumDat
new : DatStream:Stream -> ArcanumDat
val DatStream : Stream
val sizeTotal : int64
property Stream.Length: int64
val endOfMetadata : int64
val buf16 : byte []
val fileMagic : int
Multiple items
type IOException =
  inherit SystemException
  new : unit -> IOException + 3 overloads

Full name: System.IO.IOException

--------------------
IOException() : unit
IOException(message: string) : unit
IOException(message: string, hresult: int) : unit
IOException(message: string, innerException: exn) : unit
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
val dictSize : int
val entryCount : int
val buf : byte [] ref
Multiple items
val ref : value:'T -> 'T ref

Full name: Microsoft.FSharp.Core.Operators.ref

--------------------
type 'T ref = Ref<'T>

Full name: Microsoft.FSharp.Core.ref<_>
val dict : Dictionary<string,ArcanumFile>
Multiple items
type Dictionary<'TKey,'TValue> =
  new : unit -> Dictionary<'TKey, 'TValue> + 5 overloads
  member Add : key:'TKey * value:'TValue -> unit
  member Clear : unit -> unit
  member Comparer : IEqualityComparer<'TKey>
  member ContainsKey : key:'TKey -> bool
  member ContainsValue : value:'TValue -> bool
  member Count : int
  member GetEnumerator : unit -> Enumerator<'TKey, 'TValue>
  member GetObjectData : info:SerializationInfo * context:StreamingContext -> unit
  member Item : 'TKey -> 'TValue with get, set
  ...
  nested type Enumerator
  nested type KeyCollection
  nested type ValueCollection

Full name: System.Collections.Generic.Dictionary<_,_>

--------------------
Dictionary() : unit
Dictionary(capacity: int) : unit
Dictionary(comparer: IEqualityComparer<'TKey>) : unit
Dictionary(dictionary: IDictionary<'TKey,'TValue>) : unit
Dictionary(capacity: int, comparer: IEqualityComparer<'TKey>) : unit
Dictionary(dictionary: IDictionary<'TKey,'TValue>, comparer: IEqualityComparer<'TKey>) : unit
val i : int32
Array.Resize<'T>(array: byref<'T []>, newSize: int) : unit
val filename : string
type Encoding =
  member BodyName : string
  member Clone : unit -> obj
  member CodePage : int
  member DecoderFallback : DecoderFallback with get, set
  member EncoderFallback : EncoderFallback with get, set
  member EncodingName : string
  member Equals : value:obj -> bool
  member GetByteCount : chars:char[] -> int + 3 overloads
  member GetBytes : chars:char[] -> byte[] + 5 overloads
  member GetCharCount : bytes:byte[] -> int + 2 overloads
  ...

Full name: System.Text.Encoding
property Encoding.ASCII: Encoding
Encoding.GetString(bytes: byte []) : string
Encoding.GetString(bytes: byte [], index: int, count: int) : string
val flags : int
val decompressedSize : int
val compressedSize : int
val offset : int
val compressed : bool
Dictionary.Add(key: string, value: ArcanumFile) : unit
type IDisposable =
  member Dispose : unit -> unit

Full name: System.IDisposable
val o : ArcanumDat
override ArcanumDat.Dispose : unit -> unit

Full name: Divided.ArcanumFiles.ArcanumDat.Dispose
Stream.Close() : unit
val filename : String
Multiple items
type String =
  new : value:char -> string + 7 overloads
  member Chars : int -> char
  member Clone : unit -> obj
  member CompareTo : value:obj -> int + 1 overload
  member Contains : value:string -> bool
  member CopyTo : sourceIndex:int * destination:char[] * destinationIndex:int * count:int -> unit
  member EndsWith : value:string -> bool + 2 overloads
  member Equals : obj:obj -> bool + 2 overloads
  member GetEnumerator : unit -> CharEnumerator
  member GetHashCode : unit -> int
  ...

Full name: System.String

--------------------
String(value: nativeptr<char>) : unit
String(value: nativeptr<sbyte>) : unit
String(value: char []) : unit
String(c: char, count: int) : unit
String(value: nativeptr<char>, startIndex: int, length: int) : unit
String(value: nativeptr<sbyte>, startIndex: int, length: int) : unit
String(value: char [], startIndex: int, length: int) : unit
String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: Encoding) : unit
type File =
  static member AppendAllLines : path:string * contents:IEnumerable<string> -> unit + 1 overload
  static member AppendAllText : path:string * contents:string -> unit + 1 overload
  static member AppendText : path:string -> StreamWriter
  static member Copy : sourceFileName:string * destFileName:string -> unit + 1 overload
  static member Create : path:string -> FileStream + 3 overloads
  static member CreateText : path:string -> StreamWriter
  static member Decrypt : path:string -> unit
  static member Delete : path:string -> unit
  static member Encrypt : path:string -> unit
  static member Exists : path:string -> bool
  ...

Full name: System.IO.File
File.OpenRead(path: string) : FileStream
member ArcanumDat.GetFilenames : unit -> Dictionary`2.KeyCollection<string,ArcanumFile>

Full name: Divided.ArcanumFiles.ArcanumDat.GetFilenames
val _files : Dictionary<string,ArcanumFile>
property Dictionary.Keys: Dictionary`2.KeyCollection<string,ArcanumFile>
member ArcanumDat.Files : filename:string -> ArcanumFile with get

Full name: Divided.ArcanumFiles.ArcanumDat.Files
override ArcanumDat.ToString : unit -> string

Full name: Divided.ArcanumFiles.ArcanumDat.ToString
String.Format(format: string, [<ParamArray>] args: obj []) : string
String.Format(format: string, arg0: obj) : string
String.Format(provider: IFormatProvider, format: string, [<ParamArray>] args: obj []) : string
String.Format(format: string, arg0: obj, arg1: obj) : string
String.Format(format: string, arg0: obj, arg1: obj, arg2: obj) : string
Object.GetHashCode() : int
property Dictionary.Count: int
Raw view Test code New version

More information

Link:http://fssnip.net/bh
Posted:14 years ago
Author:
Tags: