-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMarioZip.pas
More file actions
349 lines (328 loc) · 8.51 KB
/
MarioZip.pas
File metadata and controls
349 lines (328 loc) · 8.51 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
unit MarioZip;//V0.2
interface
uses
Windows, SysUtils, Classes, ZipMstr, Forms, mario;
////////Procedures that use's basic units////////
Procedure ZZExtractFile(ZFileName:String; aZipObject:TZipMaster); Overload;
Procedure ZZExtractFile(ZFileName, DestinationFile:String; aZipObject:TZipMaster); Overload;
//Disabled cause the comp really has major bugs with this
//function ZZExtractFileToStream(ZFileName:String; aZipObject:TZipMaster):TMemoryStream;
Procedure ZZDeleteFile(ZFileName:String; aZipObject:TZipMaster; isDir:Boolean = False);
Function ZZgetFileList(aZipObject:TZipMaster):TStringList;
Function ZZAddFile(SrcFile, DestName:string;aZipObject:TZipMaster):Boolean; Overload;
Function ZZAddfile(SrcFile:String; aZipObject:TZipMaster):Boolean; Overload;
Function ZZGetFileSize(SrcFile:String; aZipObject:TZipMaster):Int64;
Function ZZGetFileCompSize(SrcFile:String; aZipObject:TZipMaster):Int64;
Function zzGetFileListC(ContainingStr:String; aZipObject:TZipMaster) : TStringList;
var
zzBusy : Boolean =false;
implementation
Procedure ZZExtractFile(ZFileName:String; aZipObject:TZipMaster);
Var
Tmpstr01 :String;
i : Integer;
extractfile : boolean;
Begin
Try
i := 0;
extractfile := true;
while (zzBusy = true) and
(i < 10) do Begin
MatDelay(100);
inc(i);
End;
zzBusy := True;
While i < aZipObject.Count do begin
If aZipObject.DirEntry[i].FileName = ZFileName then Begin
extractfile := true;
i := aZipObject.Count +1;
End
Else Begin
extractfile:=false;
inc(i);
End;
If extractfile = false then exit;
If FileExists(ZFileName) then
DeleteFile(ZFileName);
If Not FileExists(aZipObject.ZipFileName) then
Exit;
aZipObject.FSpecArgs.Clear;
aZipObject.FSpecArgs.Add(ExtractFileName(ZFileName));
if not DirectoryExists(ExtractFilePath(ZFileName)) then
CreateDirectory(Pchar(ExtractFilePath(ZFileName)),nil);
Tmpstr01 := ExtractFilePath(ZFileName);
aZipObject.ExtrBaseDir := ExtractFilePath(ZFileName);
aZipObject.Extract;
Tmpstr01 := ExtractFileName(ZFileName);
end
Except
End;
zzBusy := false;
//1
End;
Procedure ZZExtractFile(ZFileName, DestinationFile:String; aZipObject:TZipMaster);
Var
i : Integer;
FileSize : Integer;
Begin
Try
i := 0;
while (zzBusy = true) and
(i < 10) do Begin
MatDelay(100);
inc(i);
End;
zzBusy := True;
aZipObject.ZipStream.Clear;
If Not FileExists(aZipObject.ZipFileName) then
Exit;
aZipObject.ExtractFileToStream(ZFileName);
FileSize := aZipObject.ZipStream.Size;
If FileSize > 0 then
aZipObject.ZipStream.SaveToFile(DestinationFile)
Else
If FileSize = 0 then
if FileExists(DestinationFile) then
DeleteFile(DestinationFile);
Finally
zzBusy := false;
Application.ProcessMessages;
End;
End;
{function ZZExtractFileToStream(ZFileName:String; aZipObject:TZipMaster):TMemoryStream;
Var
Tmpstr01 :String;
aStream :TMemoryStream;
Begin
Try
aStream := TMemoryStream.Create;
aZipObject.FSpecArgs.Clear;
aZipObject.FSpecArgs.Add(ExtractFileName(ZFileName));
Tmpstr01 := ExtractFilePath(ZFileName);
aStream := aZipObject.ExtractFileToStream(ZFileName);
Finally
Result := aStream ;
End;
//1
end;}
Procedure ZZDeleteFile(ZFileName:String; aZipObject:TZipMaster; isDir:Boolean = False);
Var
i : Integer;
Delete : Boolean;
Begin
Try
i := 0;
while (zzBusy = true) and
(i < 10) do Begin
MatDelay(100);
inc(i);
End;
zzBusy := True;
i := 0;
Delete := False;
While i < aZipObject.Count do begin
If isDir = false then Begin
If LowerCase(aZipObject.DirEntry[i].FileName) = LowerCase(ZFileName) then
Delete := True;
End
Else Begin
If isDir = true then
If pos(ZFileName,aZipObject.DirEntry[i].FileName) > 0 then
Delete := True;
End;
If Delete then Begin
aZipObject.FSpecArgs.Clear;
aZipObject.FSpecArgs.Add(aZipObject.DirEntry[i].FileName);
aZipObject.Delete;
//i := aZipObject.Count;
end;
Delete := False;
Inc(i);
End;
Finally
Application.ProcessMessages;
zzBusy := false;
End;
End;
function ZZgetFileList(aZipObject:TZipMaster):TStringList;
Var
aList : TStringList;
i : Integer;
apointr : pZipDirEntry;
Begin
Try
i := 0;
while (zzBusy = true) and
(i < 10) do Begin
MatDelay(100);
inc(i);
End;
zzBusy := True;
aList := TStringList.Create;
for i := 0 to aZipObject.ZipContents.Count -1 do
Begin
apointr := aZipObject.ZipContents.Items[i];
aList.Add(apointr.FileName);
End;
Finally
Result := aList;
zzBusy := false;
End;
End;
Function ZZAddFile(SrcFile, DestName:string;aZipObject:TZipMaster):Boolean;
Var
//aStream : TMemoryStream;
dne : Integer;
i : Integer;
begin
Try
i := 0;
Result := false;
{while (aZipObject.ZipBusy = true) and
(i < 10) do Begin
MatDelay(100);
inc(i);
End;}
i := 0;
While (MatFileInUse(aZipObject.ZipFileName) = true) and
(i < 10) do Begin
MatDelay(200);
inc(i);
End;
zzBusy := True;
Try
//aStream := TMemoryStream.Create;
Try
aZipObject.FSpecArgs.Clear;
aZipObject.ZipStream.Clear;
aZipObject.ZipStream.Clear;
Application.ProcessMessages;
Except
End;
iF FileExists(SrcFile) then
aZipObject.ZipStream.LoadFromFile(SrcFile);
dne := aZipObject.AddStreamToFile(DestName,DateTimeToFileDate(now),0);
While dne <> 0 do
dne := aZipObject.AddStreamToFile(DestName,DateTimeToFileDate(now),0);
Result := True;
except
Result := False;
End;
Finally
zzBusy := false;
//aStream.Free;
End;
end;
Function ZZAddfile(SrcFile:String; aZipObject:TZipMaster):Boolean;
Var
i : Integer;
Begin
Try
i := 0;
{while (zzBusy = true) and
(i < 10) do Begin
MatDelay(100);
inc(i);
End;}
i := 0;
While (MatFileInUse(aZipObject.ZipFileName) = true) and
(i < 10) do Begin
MatDelay(100);
inc(i);
End;
zzBusy := True;
Try
aZipObject.FSpecArgs.Clear;
Application.ProcessMessages;
Except
End;
aZipObject.FSpecArgs.Add(SrcFile);
aZipObject.Add;
Result := true;
except
Result := False;
end;
zzBusy := false;
end;
Function ZZGetFileSize(SrcFile:String; aZipObject:TZipMaster):Int64;
Var
i : Integer;
size : Int64;
Begin
Try
i :=0;
while (zzBusy = true) and
(i < 10) do Begin
MatDelay(100);
inc(i);
End;
zzBusy := True;
i := 0;
While i < aZipObject.Count do begin
If aZipObject.DirEntry[i].FileName = SrcFile then Begin
size := aZipObject.DirEntry[i].UncompressedSize;
i := aZipObject.Count +1;
End;
inc(i);
End;
if size = 5622850926413640 then
Size := 0;
Finally
result := size;
zzBusy := false;
Application.ProcessMessages;
End;
End;
Function ZZGetFileCompSize(SrcFile:String; aZipObject:TZipMaster):Int64;
Var
i : Integer;
size : Int64;
Begin
i :=0;
while (zzBusy = true) and
(i < 10) do Begin
MatDelay(100);
inc(i);
End;
zzBusy := True;
i := 0;
size := 0;
While i < aZipObject.Count do begin
If aZipObject.DirEntry[i].FileName = SrcFile then Begin
size := aZipObject.DirEntry[i].CompressedSize;
i := aZipObject.Count +1;
End;
inc(i);
End;
if size = 5622850926413640 then
Size := 0;
result := size;
zzBusy := false;
End;
Function zzGetFileListC(ContainingStr:String; aZipObject:TZipMaster) : TStringList;
Var
aList : TStringList;
i : Integer;
Begin
Try
i := 0;
while (zzBusy = true) and
(i < 10) do Begin
MatDelay(100);
inc(i);
End;
zzBusy := True;
aList := TStringList.Create;
i := 0;
While i < aZipObject.Count do begin
If pos(ContainingStr, aZipObject.DirEntry[i].FileName) > 0 then Begin
aList.Add(aZipObject.DirEntry[i].FileName);
End;
inc(i);
End;
Result := aList;
Finally
zzBusy := false;
end;
End;
End.