Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ZipHelper.cs
Go to the documentation of this file.
2
3internal static class ZipHelper
4{
5 private static readonly DateTime s_invalidDateIndicator = new DateTime(1980, 1, 1, 0, 0, 0);
6
7 internal static bool RequiresUnicode(string test)
8 {
9 foreach (char c in test)
10 {
11 if (c > '~' || c < ' ')
12 {
13 return true;
14 }
15 }
16 return false;
17 }
18
19 internal static void ReadBytes(Stream stream, byte[] buffer, int bytesToRead)
20 {
21 int num = bytesToRead;
22 int num2 = 0;
23 while (num > 0)
24 {
25 int num3 = stream.Read(buffer, num2, num);
26 if (num3 == 0)
27 {
29 }
30 num2 += num3;
31 num -= num3;
32 }
33 }
34
35 internal static DateTime DosTimeToDateTime(uint dateTime)
36 {
37 if (dateTime == 0)
38 {
40 }
41 int year = (int)(1980 + (dateTime >> 25));
42 int month = (int)((dateTime >> 21) & 0xF);
43 int day = (int)((dateTime >> 16) & 0x1F);
44 int hour = (int)((dateTime >> 11) & 0x1F);
45 int minute = (int)((dateTime >> 5) & 0x3F);
46 int second = (int)((dateTime & 0x1F) * 2);
47 try
48 {
49 return new DateTime(year, month, day, hour, minute, second, 0);
50 }
52 {
54 }
55 catch (ArgumentException)
56 {
58 }
59 }
60
61 internal static uint DateTimeToDosTime(DateTime dateTime)
62 {
63 int num = (dateTime.Year - 1980) & 0x7F;
64 num = (num << 4) + dateTime.Month;
65 num = (num << 5) + dateTime.Day;
66 num = (num << 5) + dateTime.Hour;
67 num = (num << 6) + dateTime.Minute;
68 return (uint)((num << 5) + dateTime.Second / 2);
69 }
70
71 internal static bool SeekBackwardsToSignature(Stream stream, uint signatureToFind, int maxBytesToRead)
72 {
73 int bufferPointer = 0;
74 uint num = 0u;
75 byte[] array = new byte[32];
76 bool flag = false;
77 bool flag2 = false;
78 int num2 = 0;
79 while (!flag2 && !flag && num2 <= maxBytesToRead)
80 {
81 flag = SeekBackwardsAndRead(stream, array, out bufferPointer);
82 while (bufferPointer >= 0 && !flag2)
83 {
84 num = (num << 8) | array[bufferPointer];
85 if (num == signatureToFind)
86 {
87 flag2 = true;
88 }
89 else
90 {
91 bufferPointer--;
92 }
93 }
94 num2 += array.Length;
95 }
96 if (!flag2)
97 {
98 return false;
99 }
100 stream.Seek(bufferPointer, SeekOrigin.Current);
101 return true;
102 }
103
104 internal static void AdvanceToPosition(this Stream stream, long position)
105 {
106 long num = position - stream.Position;
107 while (num != 0L)
108 {
109 int count = (int)((num > 64) ? 64 : num);
110 int num2 = stream.Read(new byte[64], 0, count);
111 if (num2 == 0)
112 {
114 }
115 num -= num2;
116 }
117 }
118
119 private static bool SeekBackwardsAndRead(Stream stream, byte[] buffer, out int bufferPointer)
120 {
121 if (stream.Position >= buffer.Length)
122 {
123 stream.Seek(-buffer.Length, SeekOrigin.Current);
124 ReadBytes(stream, buffer, buffer.Length);
125 stream.Seek(-buffer.Length, SeekOrigin.Current);
126 bufferPointer = buffer.Length - 1;
127 return false;
128 }
129 int num = (int)stream.Position;
130 stream.Seek(0L, SeekOrigin.Begin);
131 ReadBytes(stream, buffer, num);
132 stream.Seek(0L, SeekOrigin.Begin);
133 bufferPointer = num - 1;
134 return true;
135 }
136}
static bool RequiresUnicode(string test)
Definition ZipHelper.cs:7
static readonly DateTime s_invalidDateIndicator
Definition ZipHelper.cs:5
static void ReadBytes(Stream stream, byte[] buffer, int bytesToRead)
Definition ZipHelper.cs:19
static DateTime DosTimeToDateTime(uint dateTime)
Definition ZipHelper.cs:35
static bool SeekBackwardsToSignature(Stream stream, uint signatureToFind, int maxBytesToRead)
Definition ZipHelper.cs:71
static bool SeekBackwardsAndRead(Stream stream, byte[] buffer, out int bufferPointer)
Definition ZipHelper.cs:119
static uint DateTimeToDosTime(DateTime dateTime)
Definition ZipHelper.cs:61
static void AdvanceToPosition(this Stream stream, long position)
Definition ZipHelper.cs:104
static string UnexpectedEndOfStream
Definition SR.cs:120
Definition SR.cs:7