| 1 | unit _FileTypes;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | TypeDefs, _TreeElement, Classes, Forms, _DataTypes;
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 10 | TFile = class(TTreeElement)
|
|---|
| 11 | protected
|
|---|
| 12 | FFileInfo: TFileInfo;
|
|---|
| 13 | FFileStream: TMemoryStream;
|
|---|
| 14 | FRawCaches: array of TMemoryStream;
|
|---|
| 15 |
|
|---|
| 16 | FCached: Boolean;
|
|---|
| 17 | FChanged: Boolean;
|
|---|
| 18 |
|
|---|
| 19 | FDataFields: TBlock;
|
|---|
| 20 |
|
|---|
| 21 | FEditor: TFrame;
|
|---|
| 22 | FOpened: Boolean;
|
|---|
| 23 |
|
|---|
| 24 | function GetChildCount: Integer; override;
|
|---|
| 25 | function GetChild(ID: Integer): TTreeElement; override;
|
|---|
| 26 | function GetCaption: String; override;
|
|---|
| 27 | function GetType: String; override;
|
|---|
| 28 | function GetEditor: TFrame;
|
|---|
| 29 | function GetFieldByOffset(Offset: Integer): TDataField;
|
|---|
| 30 | procedure SetOpened(Opened: Boolean); virtual;
|
|---|
| 31 | published
|
|---|
| 32 | public
|
|---|
| 33 | constructor Create(ConnectionID, FileID: Integer); virtual;
|
|---|
| 34 | procedure Free;
|
|---|
| 35 |
|
|---|
| 36 | procedure InitDataFields; virtual;
|
|---|
| 37 | procedure InitEditor; virtual;
|
|---|
| 38 |
|
|---|
| 39 | procedure ReCreateFile(fs: TStream);
|
|---|
| 40 |
|
|---|
| 41 | procedure CacheFile;
|
|---|
| 42 | procedure CacheRawFile(Offset: Integer);
|
|---|
| 43 |
|
|---|
| 44 | property FileStream: TMemoryStream read FFileStream;
|
|---|
| 45 | property FileInfo: TFileInfo read FFileInfo;
|
|---|
| 46 |
|
|---|
| 47 | property Cached: Boolean read FCached;
|
|---|
| 48 | property Changed: Boolean read FChanged write FChanged;
|
|---|
| 49 |
|
|---|
| 50 | property Editor: TFrame read GetEditor;
|
|---|
| 51 | property Opened: Boolean read FOpened write SetOpened;
|
|---|
| 52 |
|
|---|
| 53 | property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
|
|---|
| 54 | end;
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 | TFileType = class of TFile;
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 | implementation
|
|---|
| 62 |
|
|---|
| 63 | uses
|
|---|
| 64 | DatLinks, RawList, ConnectionManager, Dialogs, _MetaTypes, _MetaManager,
|
|---|
| 65 | SysUtils;
|
|---|
| 66 |
|
|---|
| 67 | { TFileType }
|
|---|
| 68 |
|
|---|
| 69 | procedure TFile.CacheFile;
|
|---|
| 70 | begin
|
|---|
| 71 | if not Assigned(FFileStream) then
|
|---|
| 72 | begin
|
|---|
| 73 | FFileStream := TMemoryStream.Create;
|
|---|
| 74 | ConManager.Connection[FConnectionID].LoadDatFile(FFileInfo.ID, TStream(FFileStream));
|
|---|
| 75 | end;
|
|---|
| 76 | end;
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 | procedure TFile.CacheRawFile(Offset: Integer);
|
|---|
| 80 | var
|
|---|
| 81 | rawlist: TRawDataList;
|
|---|
| 82 | i: Integer;
|
|---|
| 83 | begin
|
|---|
| 84 | rawlist := ConManager.Connection[ConnectionID].GetRawList(FFileInfo.ID);
|
|---|
| 85 | if Length(rawlist) > 0 then
|
|---|
| 86 | begin
|
|---|
| 87 | for i := 0 to High(rawlist) do
|
|---|
| 88 | begin
|
|---|
| 89 | if rawlist[i].SrcOffset = Offset then
|
|---|
| 90 | begin
|
|---|
| 91 | if not Assigned(FRawCaches[i]) then
|
|---|
| 92 | begin
|
|---|
| 93 | FRawCaches[i] := TMemoryStream.Create;
|
|---|
| 94 | ConManager.Connection[ConnectionID].LoadRawFile(FFileInfo.ID, Offset, TStream(FRawCaches[i]));
|
|---|
| 95 | end;
|
|---|
| 96 | end;
|
|---|
| 97 | end;
|
|---|
| 98 | end;
|
|---|
| 99 | end;
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 | procedure TFile.SetOpened(Opened: Boolean);
|
|---|
| 103 | begin
|
|---|
| 104 | FOpened := Opened;
|
|---|
| 105 | end;
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 | constructor TFile.Create(ConnectionID, FileID: Integer);
|
|---|
| 109 | begin
|
|---|
| 110 | FConnectionID := ConnectionID;
|
|---|
| 111 | FFileInfo := ConManager.Connection[ConnectionID].GetFileInfo(FileID);
|
|---|
| 112 |
|
|---|
| 113 | SetLength(FRawCaches, Length(ConManager.Connection[ConnectionID].GetRawList(FileID)));
|
|---|
| 114 |
|
|---|
| 115 | FCached := False;
|
|---|
| 116 | FChanged := False;
|
|---|
| 117 |
|
|---|
| 118 | FDataFields := nil;
|
|---|
| 119 | FEditor := nil;
|
|---|
| 120 |
|
|---|
| 121 | if not (Self is TFile_Empty) then
|
|---|
| 122 | InitDataFields;
|
|---|
| 123 | end;
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 | procedure TFile.Free;
|
|---|
| 127 | begin
|
|---|
| 128 | FDataFields.Free;
|
|---|
| 129 | end;
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 | function TFile.GetFieldByOffset(Offset: Integer): TDataField;
|
|---|
| 133 | begin
|
|---|
| 134 | Result := FDataFields.FieldByOffset[Offset];
|
|---|
| 135 | end;
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 | function TFile.GetType: String;
|
|---|
| 139 | begin
|
|---|
| 140 | Result := FFileInfo.Extension;
|
|---|
| 141 | end;
|
|---|
| 142 |
|
|---|
| 143 | function TFile.GetCaption: String;
|
|---|
| 144 | begin
|
|---|
| 145 | Result := FFileInfo.Name;
|
|---|
| 146 | if Result = '' then
|
|---|
| 147 | Result := 'Unnamed';
|
|---|
| 148 | Result := Result + ' (' + IntToStr(FFileInfo.ID) + ')';
|
|---|
| 149 | end;
|
|---|
| 150 |
|
|---|
| 151 | function TFile.GetChild(ID: Integer): TTreeElement;
|
|---|
| 152 | begin
|
|---|
| 153 | Result := FDataFields.Child[ID];
|
|---|
| 154 | end;
|
|---|
| 155 |
|
|---|
| 156 | function TFile.GetChildCount: Integer;
|
|---|
| 157 | begin
|
|---|
| 158 | if FDataFields <> nil then
|
|---|
| 159 | Result := FDataFields.ChildCount
|
|---|
| 160 | else
|
|---|
| 161 | Result := 0;
|
|---|
| 162 | end;
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 | function TFile.GetEditor: TFrame;
|
|---|
| 166 | begin
|
|---|
| 167 | if not Assigned(FEditor) then
|
|---|
| 168 | InitEditor;
|
|---|
| 169 | Result := FEditor;
|
|---|
| 170 | end;
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 | procedure TFile.InitDataFields;
|
|---|
| 174 | begin
|
|---|
| 175 | if Assigned(FDataFields) then
|
|---|
| 176 | Exit;
|
|---|
| 177 | FFileStream := TMemoryStream.Create;
|
|---|
| 178 | ConManager.Connection[FConnectionID].LoadDatFile(FFileInfo.ID, TStream(FFileStream));
|
|---|
| 179 | end;
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 | procedure TFile.InitEditor;
|
|---|
| 183 | begin
|
|---|
| 184 | Exit;
|
|---|
| 185 | end;
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 | //*********************************************************
|
|---|
| 189 | //*********************************************************
|
|---|
| 190 | //*********************************************************
|
|---|
| 191 | procedure TFile.ReCreateFile(fs: TStream);
|
|---|
| 192 | const
|
|---|
| 193 | temp0: array[0..31] of Byte =
|
|---|
| 194 | ($AD,$DE,$AD,$DE,$AD,$DE,$AD,$DE,
|
|---|
| 195 | $AD,$DE,$AD,$DE,$AD,$DE,$AD,$DE,
|
|---|
| 196 | $AD,$DE,$AD,$DE,$AD,$DE,$AD,$DE,
|
|---|
| 197 | $AD,$DE,$AD,$DE,$AD,$DE,$AD,$DE);
|
|---|
| 198 | var
|
|---|
| 199 | count: Integer;
|
|---|
| 200 | begin
|
|---|
| 201 | FDataFields.WriteData(fs);
|
|---|
| 202 | count := fs.Size mod 32;
|
|---|
| 203 | if count > 0 then
|
|---|
| 204 | fs.Write(temp0[count], 32 - count);
|
|---|
| 205 | end;
|
|---|
| 206 | //*********************************************************
|
|---|
| 207 | //*********************************************************
|
|---|
| 208 | //*********************************************************
|
|---|
| 209 |
|
|---|
| 210 | end.
|
|---|