Skip to content

Commit ac81a03

Browse files
committedJan 16, 2016
Clean up some silly casts
1 parent f8b5b20 commit ac81a03

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed
 

‎Library/Ark/ArkPackage.cs

+16-16
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ public class ArkPackage : AbstractPackage
9090
private ArkDirectory root;
9191
private Stream[] contentFiles;
9292
private MultiStream contentFileMeta;
93-
private ulong[] arkFileSizes;
94-
private ulong totalArkFileSizes;
93+
private long[] arkFileSizes;
94+
private long totalArkFileSizes;
9595

9696
public override string FileName { get; }
9797
public override IDirectory RootDirectory => root;
@@ -106,13 +106,13 @@ public static bool IsArk(string fn)
106106
public static bool IsArk(Stream s)
107107
{
108108
s.Position = 0;
109-
uint version = (uint)s.ReadInt32LE();
109+
uint version = s.ReadUInt32LE();
110110
if (version > 6)
111111
{
112112
// hdr is encrypted, probably
113113
using (var decryptor = new HdrCryptStream(s))
114114
{
115-
version = (uint)decryptor.ReadInt32LE();
115+
version = decryptor.ReadUInt32LE();
116116
}
117117
}
118118
return version <= 6 && version >= 3;
@@ -139,7 +139,7 @@ public ArkPackage(string pathToHdr)
139139
using (var hdr = new FileStream(pathToHdr, FileMode.Open, FileAccess.Read))
140140
{
141141
Stream actualHdr = hdr;
142-
uint version = (uint)hdr.ReadInt32LE();
142+
uint version = hdr.ReadUInt32LE();
143143
if(version > 6)
144144
{
145145
// hdr is encrypted, probably
@@ -149,7 +149,7 @@ public ArkPackage(string pathToHdr)
149149
decryptor.Read(arr, 0, (int)decryptor.Length);
150150
actualHdr = new MemoryStream(arr);
151151
}
152-
version = (uint)actualHdr.ReadInt32LE();
152+
version = actualHdr.ReadUInt32LE();
153153
}
154154
readHeader(actualHdr, pathToHdr, version);
155155
}
@@ -169,11 +169,11 @@ private void readHeader(Stream header, string headerPath, uint version)
169169
{
170170
throw new Exception("Ark header appears to be invalid (.ark count mismatch).");
171171
}
172-
arkFileSizes = new ulong[numArks];
172+
arkFileSizes = new long[numArks];
173173
for (var i = 0; i < numArks; i++)
174174
{
175175
// All versions except 4 use 32-bit file sizes.
176-
arkFileSizes[i] = (ulong)(version == 4 ? header.ReadInt64LE() : header.ReadInt32LE());
176+
arkFileSizes[i] = (version == 4 ? header.ReadInt64LE() : header.ReadInt32LE());
177177
totalArkFileSizes += arkFileSizes[i];
178178
}
179179

@@ -196,7 +196,7 @@ private void readHeader(Stream header, string headerPath, uint version)
196196
// Version 6: appears to checksums or something for each content file
197197
if (version == 6)
198198
{
199-
uint numChecksums = (uint)header.ReadInt32LE();
199+
uint numChecksums = header.ReadUInt32LE();
200200
header.Seek(4 * numChecksums, SeekOrigin.Current);
201201
}
202202
}
@@ -214,7 +214,7 @@ private void readHeader(Stream header, string headerPath, uint version)
214214
contentFileMeta = new MultiStream(contentFiles);
215215

216216
// All versions: read file tables.
217-
uint fileNameTableSize = (uint)header.ReadInt32LE();
217+
uint fileNameTableSize = header.ReadUInt32LE();
218218

219219
// Save position of filename table for later.
220220
long tableOffset = header.Position;
@@ -224,7 +224,7 @@ private void readHeader(Stream header, string headerPath, uint version)
224224
// Rather than read all filenames with their offsets, we read all the
225225
// offsets first, then read the filenames. This saves a lot of seeking
226226
// back-and-forth within the header.
227-
uint numFileNames = (uint)header.ReadInt32LE();
227+
uint numFileNames = header.ReadUInt32LE();
228228
if (numFileNames > fileNameTableSize)
229229
{
230230
throw new Exception("Ark header appears to be invalid (number of filenames exceeds filename table size).");
@@ -253,16 +253,16 @@ private void readHeader(Stream header, string headerPath, uint version)
253253
// Directories are not explicitly stored. Rather, they are inferred
254254
// by the path string each file has, which tells you in which folder
255255
// the file lives.
256-
uint numFiles = (uint)header.ReadInt32LE();
256+
uint numFiles = header.ReadUInt32LE();
257257
root = new ArkDirectory(null, ROOT_DIR);
258258
for (var i = 0; i < numFiles; i++)
259259
{
260260
// Version 3 uses 32-bit file offsets
261-
long arkFileOffset = (version == 3 ? (header.ReadInt32LE() & 0xFFFFFFFF) : header.ReadInt64LE());
261+
long arkFileOffset = (version == 3 ? header.ReadUInt32LE() : header.ReadInt64LE());
262262
int filenameStringId = header.ReadInt32LE();
263-
int dirStringId = header.ReadInt32LE();
264-
uint size = (uint)header.ReadInt32LE();
265-
uint zero = (uint)header.ReadInt32LE();
263+
uint dirStringId = header.ReadUInt32LE();
264+
uint size = header.ReadUInt32LE();
265+
uint zero = header.ReadUInt32LE();
266266
if (zero == 0)
267267
{
268268
ArkDirectory parent = makeOrGetDir(fileNames[dirStringId]);

‎Library/STFS/STFSFile.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public System.IO.Stream GetStream()
9292
{
9393
dataBlocks = container.GetFileBlocks(startBlock, numBlocks, false);
9494
}
95-
return new STFSFileStream(container, dataBlocks, (uint)Size);
95+
return new STFSFileStream(container, dataBlocks, Size);
9696
}
9797
}
9898

@@ -105,7 +105,7 @@ public class STFSFileStream : System.IO.Stream
105105
int[] blocks;
106106
long position;
107107

108-
internal STFSFileStream(STFSPackage container, int[] blocks, uint size)
108+
internal STFSFileStream(STFSPackage container, int[] blocks, long size)
109109
{
110110
Length = size;
111111
this.blocks = blocks;

‎Library/STFS/STFSPackage.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ private STFSPackage(System.IO.Stream input)
281281
curBlockStream.ReadInt24LE();
282282
int startBlock = curBlockStream.ReadInt24LE();
283283
int parentDir = curBlockStream.ReadInt16BE();
284-
uint size = (uint)curBlockStream.ReadInt32BE();
284+
uint size = curBlockStream.ReadUInt32BE();
285285
int update = curBlockStream.ReadInt32BE();
286286
int access = curBlockStream.ReadInt32BE();
287287
STFSDirectory parent;

0 commit comments

Comments
 (0)
Please sign in to comment.