-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPV_Pack.pas
110 lines (88 loc) · 2.31 KB
/
PV_Pack.pas
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
unit PV_Pack;
{$mode objfpc}{$H+}
//PV Pack
//https://github.com/PascalVault
//Licence: MIT
//Last update: 2023-10-04
interface
uses
Classes, SysUtils, DateUtils, Dialogs;
type
{ TPack }
TPack = class
private
FStream: TStream;
public
constructor Create(Str: TStream); virtual; abstract;
destructor Destroy; virtual; abstract;
function AddFile(Str: TStream; Name: String): Boolean; virtual; abstract;
procedure SetComment(Comment: String); virtual; abstract;
end;
TFileRec = record
Name: String;
Offset: Cardinal;
Size: Cardinal;
PackedSize: Cardinal;
Hash: Cardinal;
end;
{ TFileList }
TFileList = class
private
FSize: Integer;
FCount: Integer;
FArray: array of TFileRec;
public
constructor Create;
procedure Add(Name: String; Offset, Size, PackedSize, Hash: Cardinal);
function GetFile(Index: Integer): TFileRec;
property Count: Integer read FCount;
property Files[Index: Integer]: TFileRec read GetFile; default;
end;
function DosTime(Time: TDateTime = -1): Word;
function DosDate(Time: TDateTime = -1): Word;
function UnixStamp(Time: TDateTime = -1): Int64;
implementation
function DosTime(Time: TDateTime): Word;
var Temp: Cardinal;
begin
if Time = -1 then Time := Now();
Temp := DateTimeToDosDateTime(Time);
Result := Temp and $FFFF;
end;
function DosDate(Time: TDateTime): Word;
var Temp: Cardinal;
begin
if Time = -1 then Time := Now();
Temp := DateTimeToDosDateTime(Time);
Result := Temp shr 16;
end;
function UnixStamp(Time: TDateTime): Int64;
begin
if Time = -1 then Time := Now();
Result := DateTimeToUnix(Time, True);
end;
{ TFileList }
constructor TFileList.Create;
begin
FSize := 1000;
FCount := 0;
SetLength(FArray, FSize);
end;
procedure TFileList.Add(Name: String; Offset, Size, PackedSize, Hash: Cardinal);
begin
if FCount > FSize-1 then begin
Inc(FSize, 1000);
SetLength(FArray, FSize);
end;
FArray[FCount].Name := Name;
FArray[FCount].Offset := Offset;
FArray[FCount].Size := Size;
FArray[FCount].PackedSize := PackedSize;
FArray[FCount].Hash := Hash;
Inc(FCount);
end;
function TFileList.GetFile(Index: Integer): TFileRec;
begin
Result := FArray[Index];
end;
end.