[124] | 1 | unit _FileTypes;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | uses
|
---|
[240] | 6 | TypeDefs, _TreeElement, Classes, Forms, _DataTypes;
|
---|
[124] | 7 |
|
---|
| 8 |
|
---|
| 9 | type
|
---|
[245] | 10 | TRawCache = record
|
---|
| 11 | DatOffset: Integer;
|
---|
| 12 | RawStream: TMemoryStream;
|
---|
| 13 | end;
|
---|
| 14 |
|
---|
[248] | 15 | TResource = class(TTreeElement)
|
---|
[206] | 16 | protected
|
---|
[231] | 17 | FFileInfo: TFileInfo;
|
---|
[210] | 18 | FFileStream: TMemoryStream;
|
---|
[245] | 19 | FRawCaches: array of TRawCache;
|
---|
[126] | 20 |
|
---|
[212] | 21 | FCached: Boolean;
|
---|
| 22 | FChanged: Boolean;
|
---|
[248] | 23 | FReplaced: Boolean;
|
---|
[212] | 24 |
|
---|
[206] | 25 | FDataFields: TBlock;
|
---|
[126] | 26 |
|
---|
[214] | 27 | FEditor: TFrame;
|
---|
| 28 | FOpened: Boolean;
|
---|
| 29 |
|
---|
[241] | 30 | function GetChildCount: Integer; override;
|
---|
| 31 | function GetChild(ID: Integer): TTreeElement; override;
|
---|
| 32 | function GetCaption: String; override;
|
---|
| 33 | function GetType: String; override;
|
---|
[240] | 34 | function GetEditor: TFrame;
|
---|
[126] | 35 | function GetFieldByOffset(Offset: Integer): TDataField;
|
---|
[245] | 36 | function GetRawCacheID(Offset: Integer): Integer;
|
---|
[240] | 37 | procedure SetOpened(Opened: Boolean); virtual;
|
---|
| 38 | published
|
---|
[124] | 39 | public
|
---|
[206] | 40 | constructor Create(ConnectionID, FileID: Integer); virtual;
|
---|
| 41 | procedure Free;
|
---|
| 42 |
|
---|
[213] | 43 | procedure InitDataFields; virtual;
|
---|
[214] | 44 | procedure InitEditor; virtual;
|
---|
[213] | 45 |
|
---|
[240] | 46 | procedure ReCreateFile(fs: TStream);
|
---|
| 47 |
|
---|
| 48 | procedure CacheFile;
|
---|
| 49 | procedure CacheRawFile(Offset: Integer);
|
---|
[245] | 50 | procedure CacheAllRawFiles;
|
---|
| 51 | procedure DiscardFileCache;
|
---|
| 52 | procedure DiscardRawCache(Offset: Integer);
|
---|
| 53 | procedure DiscardAllRawCaches;
|
---|
| 54 | procedure StoreFileCache;
|
---|
| 55 | procedure StoreRawCache(Offset: Integer);
|
---|
| 56 | procedure StoreAllRawCaches;
|
---|
[240] | 57 |
|
---|
[210] | 58 | property FileStream: TMemoryStream read FFileStream;
|
---|
[231] | 59 | property FileInfo: TFileInfo read FFileInfo;
|
---|
[206] | 60 |
|
---|
[212] | 61 | property Cached: Boolean read FCached;
|
---|
| 62 | property Changed: Boolean read FChanged write FChanged;
|
---|
| 63 |
|
---|
[240] | 64 | property Editor: TFrame read GetEditor;
|
---|
| 65 | property Opened: Boolean read FOpened write SetOpened;
|
---|
[214] | 66 |
|
---|
[126] | 67 | property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
|
---|
[124] | 68 | end;
|
---|
| 69 |
|
---|
[248] | 70 | type
|
---|
| 71 | TFileType = class of TResource;
|
---|
[124] | 72 |
|
---|
[207] | 73 |
|
---|
| 74 |
|
---|
[124] | 75 | implementation
|
---|
| 76 |
|
---|
[126] | 77 | uses
|
---|
[241] | 78 | DatLinks, RawList, ConnectionManager, Dialogs, _MetaTypes, _MetaManager,
|
---|
| 79 | SysUtils;
|
---|
[126] | 80 |
|
---|
[124] | 81 | { TFileType }
|
---|
| 82 |
|
---|
[248] | 83 | procedure TResource.CacheFile;
|
---|
[240] | 84 | begin
|
---|
| 85 | if not Assigned(FFileStream) then
|
---|
| 86 | begin
|
---|
| 87 | FFileStream := TMemoryStream.Create;
|
---|
| 88 | ConManager.Connection[FConnectionID].LoadDatFile(FFileInfo.ID, TStream(FFileStream));
|
---|
| 89 | end;
|
---|
| 90 | end;
|
---|
| 91 |
|
---|
| 92 |
|
---|
[248] | 93 | procedure TResource.CacheRawFile(Offset: Integer);
|
---|
[240] | 94 | var
|
---|
| 95 | i: Integer;
|
---|
| 96 | begin
|
---|
[245] | 97 | for i := 0 to High(FRawCaches) do
|
---|
[240] | 98 | begin
|
---|
[245] | 99 | if FRawCaches[i].DatOffset = Offset then
|
---|
[240] | 100 | begin
|
---|
[245] | 101 | if not Assigned(FRawCaches[i].RawStream) then
|
---|
[240] | 102 | begin
|
---|
[245] | 103 | FRawCaches[i].RawStream := TMemoryStream.Create;
|
---|
| 104 | ConManager.Connection[ConnectionID].LoadRawFile(FFileInfo.ID, Offset, TStream(FRawCaches[i].RawStream));
|
---|
[240] | 105 | end;
|
---|
| 106 | end;
|
---|
| 107 | end;
|
---|
| 108 | end;
|
---|
| 109 |
|
---|
[248] | 110 | procedure TResource.CacheAllRawFiles;
|
---|
[245] | 111 | var
|
---|
| 112 | i: Integer;
|
---|
| 113 | begin
|
---|
| 114 | for i := 0 to High(FRawCaches) do
|
---|
| 115 | CacheRawFile(FRawCaches[i].DatOffset);
|
---|
| 116 | end;
|
---|
[240] | 117 |
|
---|
[245] | 118 |
|
---|
| 119 |
|
---|
[248] | 120 | procedure TResource.DiscardFileCache;
|
---|
[245] | 121 | begin
|
---|
| 122 | if Assigned(FFileStream) then
|
---|
| 123 | FFileStream.Free;
|
---|
| 124 | FFileStream := nil;
|
---|
| 125 | end;
|
---|
| 126 |
|
---|
[248] | 127 | procedure TResource.DiscardRawCache(Offset: Integer);
|
---|
[245] | 128 | var
|
---|
| 129 | i: Integer;
|
---|
| 130 | begin
|
---|
| 131 | for i := 0 to High(FRawCaches) do
|
---|
| 132 | begin
|
---|
| 133 | if FRawCaches[i].DatOffset = Offset then
|
---|
| 134 | begin
|
---|
| 135 | if Assigned(FRawCaches[i].RawStream) then
|
---|
| 136 | FRawCaches[i].RawStream.Free;
|
---|
| 137 | FRawCaches[i].RawStream := nil;
|
---|
| 138 | end;
|
---|
| 139 | end;
|
---|
| 140 | end;
|
---|
| 141 |
|
---|
[248] | 142 | procedure TResource.DiscardAllRawCaches;
|
---|
[245] | 143 | var
|
---|
| 144 | i: Integer;
|
---|
| 145 | begin
|
---|
| 146 | for i := 0 to High(FRawCaches) do
|
---|
| 147 | DiscardRawCache(FRawCaches[i].DatOffset);
|
---|
| 148 | end;
|
---|
| 149 |
|
---|
[248] | 150 | procedure TResource.StoreFileCache;
|
---|
[245] | 151 | begin
|
---|
| 152 | Exit;
|
---|
| 153 | end;
|
---|
| 154 |
|
---|
[248] | 155 | procedure TResource.StoreRawCache(Offset: Integer);
|
---|
[245] | 156 | begin
|
---|
| 157 | Exit;
|
---|
| 158 | end;
|
---|
| 159 |
|
---|
[248] | 160 | procedure TResource.StoreAllRawCaches;
|
---|
[245] | 161 | var
|
---|
| 162 | i: Integer;
|
---|
| 163 | begin
|
---|
| 164 | for i := 0 to High(FRawCaches) do
|
---|
| 165 | StoreRawCache(FRawCaches[i].DatOffset);
|
---|
| 166 | end;
|
---|
| 167 |
|
---|
| 168 |
|
---|
| 169 |
|
---|
| 170 |
|
---|
| 171 |
|
---|
[248] | 172 | procedure TResource.SetOpened(Opened: Boolean);
|
---|
[240] | 173 | begin
|
---|
| 174 | FOpened := Opened;
|
---|
| 175 | end;
|
---|
| 176 |
|
---|
| 177 |
|
---|
[248] | 178 | constructor TResource.Create(ConnectionID, FileID: Integer);
|
---|
[245] | 179 | var
|
---|
| 180 | rawlist: TRawDataList;
|
---|
| 181 | i: Integer;
|
---|
[126] | 182 | begin
|
---|
| 183 | FConnectionID := ConnectionID;
|
---|
[231] | 184 | FFileInfo := ConManager.Connection[ConnectionID].GetFileInfo(FileID);
|
---|
[126] | 185 |
|
---|
[245] | 186 | rawlist := ConManager.Connection[ConnectionID].GetRawList(FileID);
|
---|
| 187 | SetLength(FRawCaches, Length(rawlist));
|
---|
| 188 | for i := 0 to High(rawlist) do
|
---|
| 189 | FRawCaches[i].DatOffset := rawlist[i].SrcOffset;
|
---|
[240] | 190 |
|
---|
[212] | 191 | FCached := False;
|
---|
| 192 | FChanged := False;
|
---|
[206] | 193 |
|
---|
[238] | 194 | FDataFields := nil;
|
---|
| 195 | FEditor := nil;
|
---|
| 196 |
|
---|
[212] | 197 | if not (Self is TFile_Empty) then
|
---|
[233] | 198 | InitDataFields;
|
---|
[126] | 199 | end;
|
---|
| 200 |
|
---|
| 201 |
|
---|
[248] | 202 | procedure TResource.Free;
|
---|
[206] | 203 | begin
|
---|
| 204 | FDataFields.Free;
|
---|
| 205 | end;
|
---|
| 206 |
|
---|
[126] | 207 |
|
---|
[248] | 208 | function TResource.GetFieldByOffset(Offset: Integer): TDataField;
|
---|
[124] | 209 | begin
|
---|
[206] | 210 | Result := FDataFields.FieldByOffset[Offset];
|
---|
[124] | 211 | end;
|
---|
| 212 |
|
---|
[126] | 213 |
|
---|
[248] | 214 | function TResource.GetRawCacheID(Offset: Integer): Integer;
|
---|
[245] | 215 | var
|
---|
| 216 | i: Integer;
|
---|
| 217 | begin
|
---|
| 218 | Result := -1;
|
---|
| 219 | for i := 0 to High(FRawCaches) do
|
---|
| 220 | if FRawCaches[i].DatOffset = Offset then
|
---|
| 221 | Result := i;
|
---|
| 222 | end;
|
---|
| 223 |
|
---|
[248] | 224 | function TResource.GetType: String;
|
---|
[241] | 225 | begin
|
---|
| 226 | Result := FFileInfo.Extension;
|
---|
| 227 | end;
|
---|
| 228 |
|
---|
[248] | 229 | function TResource.GetCaption: String;
|
---|
[212] | 230 | begin
|
---|
[233] | 231 | Result := FFileInfo.Name;
|
---|
| 232 | if Result = '' then
|
---|
| 233 | Result := 'Unnamed';
|
---|
[241] | 234 | Result := Result + ' (' + IntToStr(FFileInfo.ID) + ')';
|
---|
[212] | 235 | end;
|
---|
| 236 |
|
---|
[248] | 237 | function TResource.GetChild(ID: Integer): TTreeElement;
|
---|
[232] | 238 | begin
|
---|
[233] | 239 | Result := FDataFields.Child[ID];
|
---|
[232] | 240 | end;
|
---|
| 241 |
|
---|
[248] | 242 | function TResource.GetChildCount: Integer;
|
---|
[126] | 243 | begin
|
---|
[233] | 244 | if FDataFields <> nil then
|
---|
[238] | 245 | Result := FDataFields.ChildCount
|
---|
| 246 | else
|
---|
| 247 | Result := 0;
|
---|
[126] | 248 | end;
|
---|
| 249 |
|
---|
| 250 |
|
---|
[248] | 251 | function TResource.GetEditor: TFrame;
|
---|
[240] | 252 | begin
|
---|
| 253 | if not Assigned(FEditor) then
|
---|
| 254 | InitEditor;
|
---|
| 255 | Result := FEditor;
|
---|
| 256 | end;
|
---|
| 257 |
|
---|
| 258 |
|
---|
[248] | 259 | procedure TResource.InitDataFields;
|
---|
[213] | 260 | begin
|
---|
| 261 | if Assigned(FDataFields) then
|
---|
| 262 | Exit;
|
---|
[233] | 263 | FFileStream := TMemoryStream.Create;
|
---|
| 264 | ConManager.Connection[FConnectionID].LoadDatFile(FFileInfo.ID, TStream(FFileStream));
|
---|
[213] | 265 | end;
|
---|
| 266 |
|
---|
[215] | 267 |
|
---|
[248] | 268 | procedure TResource.InitEditor;
|
---|
[214] | 269 | begin
|
---|
| 270 | Exit;
|
---|
| 271 | end;
|
---|
| 272 |
|
---|
[215] | 273 |
|
---|
[240] | 274 | //*********************************************************
|
---|
| 275 | //*********************************************************
|
---|
| 276 | //*********************************************************
|
---|
[248] | 277 | procedure TResource.ReCreateFile(fs: TStream);
|
---|
[240] | 278 | const
|
---|
| 279 | temp0: array[0..31] of Byte =
|
---|
| 280 | ($AD,$DE,$AD,$DE,$AD,$DE,$AD,$DE,
|
---|
| 281 | $AD,$DE,$AD,$DE,$AD,$DE,$AD,$DE,
|
---|
| 282 | $AD,$DE,$AD,$DE,$AD,$DE,$AD,$DE,
|
---|
| 283 | $AD,$DE,$AD,$DE,$AD,$DE,$AD,$DE);
|
---|
| 284 | var
|
---|
| 285 | count: Integer;
|
---|
| 286 | begin
|
---|
| 287 | FDataFields.WriteData(fs);
|
---|
| 288 | count := fs.Size mod 32;
|
---|
| 289 | if count > 0 then
|
---|
| 290 | fs.Write(temp0[count], 32 - count);
|
---|
| 291 | end;
|
---|
| 292 | //*********************************************************
|
---|
| 293 | //*********************************************************
|
---|
| 294 | //*********************************************************
|
---|
| 295 |
|
---|
[124] | 296 | end.
|
---|