BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | Properties | List of all members
BrawlLib.Internal.IO.FileMap Class Reference
Inheritance diagram for BrawlLib.Internal.IO.FileMap:
BrawlLib.Internal.IO.cFileMap BrawlLib.Internal.IO.wFileMap

Public Member Functions

virtual void Dispose ()
 

Static Public Member Functions

static FileMap FromFile (string path)
 
static FileMap FromFile (string path, FileMapProtect prot)
 
static FileMap FromFile (string path, FileMapProtect prot, int offset, int length)
 
static FileMap FromFile (string path, FileMapProtect prot, int offset, int length, FileOptions options)
 
static FileMap FromTempFile (int length)
 
static FileMap FromTempFile (int length, out string path)
 
static FileMap FromStream (FileStream stream)
 
static FileMap FromStream (FileStream stream, FileMapProtect prot)
 
static FileMap FromStream (FileStream stream, FileMapProtect prot, int offset, int length)
 
static FileMap FromStreamInternal (FileStream stream, FileMapProtect prot, int offset, int length)
 

Protected Attributes

VoidPtr _addr
 
int _length
 
string _path
 
FileStream _baseStream
 

Properties

VoidPtr Address [get]
 
int Length [get, set]
 
string FilePath [get]
 
FileStream BaseStream [get]
 

Member Function Documentation

◆ Dispose()

virtual void BrawlLib.Internal.IO.FileMap.Dispose ( )
inlinevirtual

Reimplemented in BrawlLib.Internal.IO.wFileMap, and BrawlLib.Internal.IO.cFileMap.

34 {
35 if (_baseStream != null)
36 {
37 _baseStream.Close();
38 _baseStream.Dispose();
39 _baseStream = null;
40 }
41
42 //#if DEBUG
43 // Console.WriteLine("Closing file map: {0}", _path);
44 //#endif
45 GC.SuppressFinalize(this);
46 }
FileStream _baseStream
Definition: FileMap.cs:14

◆ FromFile() [1/4]

static FileMap BrawlLib.Internal.IO.FileMap.FromFile ( string  path)
inlinestatic
49 {
50 return FromFile(path, FileMapProtect.ReadWrite, 0, 0);
51 }
static FileMap FromFile(string path)
Definition: FileMap.cs:48
FileMapProtect
Definition: FileMap.cs:175

◆ FromFile() [2/4]

static FileMap BrawlLib.Internal.IO.FileMap.FromFile ( string  path,
FileMapProtect  prot 
)
inlinestatic
54 {
55 return FromFile(path, prot, 0, 0);
56 }

◆ FromFile() [3/4]

static FileMap BrawlLib.Internal.IO.FileMap.FromFile ( string  path,
FileMapProtect  prot,
int  offset,
int  length 
)
inlinestatic
59 {
60 return FromFile(path, prot, 0, 0, FileOptions.RandomAccess);
61 }

◆ FromFile() [4/4]

static FileMap BrawlLib.Internal.IO.FileMap.FromFile ( string  path,
FileMapProtect  prot,
int  offset,
int  length,
FileOptions  options 
)
inlinestatic
64 {
65 FileStream stream;
66 FileMap map;
67
68 try // Use a temp file in order to prevent writelocks
69 {
70 string tempPath = Path.GetTempFileName();
71 File.Copy(path, tempPath, true);
72 stream = new FileStream(tempPath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, 8,
73 options | FileOptions.DeleteOnClose);
74 }
75 catch // Just open the file normally
76 {
77 stream = new FileStream(path, FileMode.Open,
78 prot == FileMapProtect.ReadWrite ? FileAccess.ReadWrite : FileAccess.Read, FileShare.Read, 8,
79 options);
80 }
81
82 try
83 {
84 map = FromStreamInternal(stream, prot, offset, length);
85 }
86 catch (Exception)
87 {
88 stream.Dispose();
89 throw;
90 }
91
92 map._path = path; // Preserve true path
93 return map;
94 }
static FileMap FromStreamInternal(FileStream stream, FileMapProtect prot, int offset, int length)
Definition: FileMap.cs:152

◆ FromStream() [1/3]

static FileMap BrawlLib.Internal.IO.FileMap.FromStream ( FileStream  stream)
inlinestatic
118 {
119 return FromStream(stream, FileMapProtect.ReadWrite, 0, 0);
120 }
static FileMap FromStream(FileStream stream)
Definition: FileMap.cs:117

◆ FromStream() [2/3]

static FileMap BrawlLib.Internal.IO.FileMap.FromStream ( FileStream  stream,
FileMapProtect  prot 
)
inlinestatic
123 {
124 return FromStream(stream, prot, 0, 0);
125 }

◆ FromStream() [3/3]

static FileMap BrawlLib.Internal.IO.FileMap.FromStream ( FileStream  stream,
FileMapProtect  prot,
int  offset,
int  length 
)
inlinestatic
128 {
129 //FileStream newStream = new FileStream(stream.Name, FileMode.Open, prot == FileMapProtect.Read ? FileAccess.Read : FileAccess.ReadWrite, FileShare.Read, 8, FileOptions.RandomAccess);
130 //try { return FromStreamInternal(newStream, prot, offset, length); }
131 //catch (Exception x) { newStream.Dispose(); throw x; }
132
133 if (length == 0)
134 {
135 length = (int) stream.Length;
136 }
137
138 switch (Environment.OSVersion.Platform)
139 {
140 case PlatformID.Win32NT:
141 return new wFileMap(stream.SafeFileHandle.DangerousGetHandle(), prot, offset, (uint) length)
142 {_path = stream.Name};
143 default:
144 return new cFileMap(stream, prot, offset, length) {_path = stream.Name};
145 }
146
147 //#if DEBUG
148 // Console.WriteLine("Opening file map: {0}", stream.Name);
149 //#endif
150 }
string _path
Definition: FileMap.cs:13

◆ FromStreamInternal()

static FileMap BrawlLib.Internal.IO.FileMap.FromStreamInternal ( FileStream  stream,
FileMapProtect  prot,
int  offset,
int  length 
)
inlinestatic
153 {
154 if (length == 0)
155 {
156 length = (int) stream.Length;
157 }
158
159 switch (Environment.OSVersion.Platform)
160 {
161 case PlatformID.Win32NT:
162 return new wFileMap(stream.SafeFileHandle.DangerousGetHandle(), prot, offset, (uint) length)
163 {_baseStream = stream, _path = stream.Name};
164 default:
165 return new cFileMap(stream, prot, offset, length) {_baseStream = stream, _path = stream.Name};
166 }
167
168 //#if DEBUG
169 // Console.WriteLine("Opening file map: {0}", stream.Name);
170 //#endif
171 }

◆ FromTempFile() [1/2]

static FileMap BrawlLib.Internal.IO.FileMap.FromTempFile ( int  length)
inlinestatic
97 {
98 return FromTempFile(length, out string path);
99 }
static FileMap FromTempFile(int length)
Definition: FileMap.cs:96

◆ FromTempFile() [2/2]

static FileMap BrawlLib.Internal.IO.FileMap.FromTempFile ( int  length,
out string  path 
)
inlinestatic
102 {
103 path = Path.GetTempFileName();
104 FileStream stream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite,
105 FileShare.Read, 8, FileOptions.RandomAccess | FileOptions.DeleteOnClose);
106 try
107 {
108 return FromStreamInternal(stream, FileMapProtect.ReadWrite, 0, length);
109 }
110 catch (Exception)
111 {
112 stream.Dispose();
113 throw;
114 }
115 }

Member Data Documentation

◆ _addr

VoidPtr BrawlLib.Internal.IO.FileMap._addr
protected

◆ _baseStream

FileStream BrawlLib.Internal.IO.FileMap._baseStream
protected

◆ _length

int BrawlLib.Internal.IO.FileMap._length
protected

◆ _path

string BrawlLib.Internal.IO.FileMap._path
protected

Property Documentation

◆ Address

VoidPtr BrawlLib.Internal.IO.FileMap.Address
get

◆ BaseStream

FileStream BrawlLib.Internal.IO.FileMap.BaseStream
get

◆ FilePath

string BrawlLib.Internal.IO.FileMap.FilePath
get

◆ Length

int BrawlLib.Internal.IO.FileMap.Length
getset
19 {
20 get => _length;
21 set => _length = value;
22 }
int _length
Definition: FileMap.cs:12

The documentation for this class was generated from the following file: