1 | unit UEngFile;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils;
|
---|
9 |
|
---|
10 | type
|
---|
11 |
|
---|
12 | { TEngFile }
|
---|
13 |
|
---|
14 | TEngFile = class
|
---|
15 | private
|
---|
16 | function DecodeString(Data: array of Byte): string;
|
---|
17 | public
|
---|
18 | FileName: string;
|
---|
19 | Lines: TStringList;
|
---|
20 | procedure LoadFromFile(FileName: string);
|
---|
21 | constructor Create;
|
---|
22 | destructor Destroy; override;
|
---|
23 | end;
|
---|
24 |
|
---|
25 | implementation
|
---|
26 |
|
---|
27 | const
|
---|
28 | Dictionary: string = ' etainosrlhcdupmtasio wb rnsdalmh ieorasnrtlc synstcloer dtgesionr ufmsw tep.icae oiadur laeiyodeia otruetoakhlr eiu,.oansrctlaileoiratpeaoip bm';
|
---|
29 |
|
---|
30 | { TEngFile }
|
---|
31 |
|
---|
32 | function TEngFile.DecodeString(Data: array of Byte): string;
|
---|
33 | var
|
---|
34 | I: Integer;
|
---|
35 | begin
|
---|
36 | Result := '';
|
---|
37 | for I := 0 to Length(Data) - 1 do begin
|
---|
38 | if (Data[I] and $80) > 0 then begin
|
---|
39 | Result := Result + Dictionary[(Data[I] and $7f) shr 3 + 1];
|
---|
40 | Result := Result + Dictionary[(Data[I] and $7f) + 16 + 1];
|
---|
41 | end else
|
---|
42 | if Data[I] <> 0 then
|
---|
43 | Result := Result + Chr(Data[I]);
|
---|
44 | end;
|
---|
45 | end;
|
---|
46 |
|
---|
47 | procedure TEngFile.LoadFromFile(FileName: string);
|
---|
48 | var
|
---|
49 | F: TFileStream;
|
---|
50 | Buffer: array of Byte;
|
---|
51 | I: Integer;
|
---|
52 | Addr: array of Word;
|
---|
53 | begin
|
---|
54 | Lines.Clear;
|
---|
55 | F := TFileStream.Create(FileName, fmOpenRead);
|
---|
56 | { // Read string address array
|
---|
57 | SetLength(Addr, 1);
|
---|
58 | Addr[0] := F.ReadWord;
|
---|
59 | while F.Position < Addr[0] do begin
|
---|
60 | SetLength(Addr, Length(Addr) + 1);
|
---|
61 | Addr[Length(Addr) - 1] := F.ReadWord;
|
---|
62 | end;
|
---|
63 |
|
---|
64 | // Read and decode strings
|
---|
65 | for I := 0 to Length(Addr) - 1 do begin
|
---|
66 | F.Position := Addr[I];
|
---|
67 | if I < Length(Addr) - 1 then SetLength(Buffer, Addr[I + 1] - Addr[I])
|
---|
68 | else SetLength(Buffer, F.Size - Addr[I]);
|
---|
69 | F.Read(Buffer[0], Length(Buffer));
|
---|
70 | Lines.Add(DecodeString(Buffer));
|
---|
71 | end;
|
---|
72 | }
|
---|
73 | SetLength(Buffer, F.Size);
|
---|
74 | F.Read(Buffer[0], F.Size);
|
---|
75 | Lines.Add(DecodeString(Buffer));
|
---|
76 | F.Free;
|
---|
77 | end;
|
---|
78 |
|
---|
79 | constructor TEngFile.Create;
|
---|
80 | begin
|
---|
81 | Lines := TStringList.Create;
|
---|
82 | end;
|
---|
83 |
|
---|
84 | destructor TEngFile.Destroy;
|
---|
85 | begin
|
---|
86 | FreeAndNil(Lines);
|
---|
87 | inherited Destroy;
|
---|
88 | end;
|
---|
89 |
|
---|
90 | end.
|
---|
91 |
|
---|