GLS.ArchiveManager.pas 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. //
  2. // The graphics engine GLScene
  3. //
  4. unit GLS.ArchiveManager;
  5. (* Archive manager - the class to work with archives *)
  6. {$I Stage.Defines.inc}
  7. interface
  8. uses
  9. System.Classes,
  10. System.SysUtils,
  11. GLS.ApplicationFileIO,
  12. GLS.PersistentClasses,
  13. Stage.Strings;
  14. type
  15. TCompressionLevel = (clNone, clFastest, clDefault, clMax, clLevel1, clLevel2,
  16. clLevel3, clLevel4, clLevel5, clLevel6, clLevel7, clLevel8, clLevel9);
  17. // BaseArchive class
  18. TGLBaseArchive = class(TGLDataFile)
  19. protected
  20. FFileName: string;
  21. FContentList: TStrings;
  22. FCompressionLevel: TCompressionLevel;
  23. procedure SetCompressionLevel(aValue: TCompressionLevel); Virtual;
  24. public
  25. constructor Create(AOwner: TPersistent); override;
  26. destructor Destroy; override;
  27. property ContentList: TStrings read FContentList;
  28. property CompressionLevel: TCompressionLevel read FCompressionLevel
  29. write SetCompressionLevel default clNone;
  30. procedure Clear; virtual; abstract;
  31. function ContentExists(ContentName: string): boolean; virtual; abstract;
  32. function GetContent(Stream: TStream; index: integer): TStream; overload;
  33. virtual; abstract;
  34. function GetContent(ContentName: string): TStream; overload;
  35. virtual; abstract;
  36. function GetContent(index: integer): TStream; overload; virtual; abstract;
  37. function GetContentSize(index: integer): integer; overload;
  38. virtual; abstract;
  39. function GetContentSize(ContentName: string): integer; overload;
  40. virtual; abstract;
  41. procedure AddFromStream(ContentName, Path: string; FS: TStream);
  42. virtual; abstract;
  43. procedure AddFromFile(FileName, Path: string); virtual; abstract;
  44. procedure RemoveContent(index: integer); overload; virtual; abstract;
  45. procedure RemoveContent(ContentName: string); overload; virtual; abstract;
  46. procedure Extract(index: integer; NewName: string); overload;
  47. virtual; abstract;
  48. procedure Extract(ContentName, NewName: string); overload; virtual;
  49. abstract;
  50. end;
  51. TGLBaseArchiveClass = class of TGLBaseArchive;
  52. // Archive registration classes to use proper srchiver for extensions like:
  53. // GLFilePak, GLFileZLib etc.
  54. (* The type to record a registered class *)
  55. TGLArchiveFileFormat = class
  56. public
  57. BaseArchiveClass: TGLBaseArchiveClass;
  58. Extension: string;
  59. Description: string;
  60. DescResID: integer;
  61. end;
  62. // The list of registered classes
  63. TGLArchiveFileFormatsList = class(TGLPersistentObjectList)
  64. public
  65. destructor Destroy; override;
  66. procedure Add(const Ext, Desc: string; DescID: integer;
  67. AClass: TGLBaseArchiveClass);
  68. function FindExt(Ext: string): TGLBaseArchiveClass;
  69. function FindFromFileName(const FileName: string): TGLBaseArchiveClass;
  70. procedure Remove(AClass: TGLBaseArchiveClass);
  71. end;
  72. // Using the collection item for simultaneous work with several archives
  73. TGLLibArchive = class(TCollectionItem)
  74. private
  75. vArchive: TGLBaseArchive;
  76. ArcClass: TGLBaseArchiveClass;
  77. FFileName: string;
  78. FName: string;
  79. procedure SetCompressionLevel(aValue: TCompressionLevel);
  80. function GetCompressionLevel: TCompressionLevel;
  81. function GetContentList: TStrings;
  82. procedure SetName(const val: string);
  83. protected
  84. function GetDisplayName: string; override;
  85. public
  86. constructor Create(ACollection: TCollection); override;
  87. destructor Destroy; override;
  88. property CompressionLevel: TCompressionLevel read GetCompressionLevel
  89. write SetCompressionLevel default clDefault;
  90. procedure CreateArchive(FileName: string;
  91. OverwriteExistingFile: boolean = False);
  92. property ContentList: TStrings read GetContentList;
  93. procedure LoadFromFile(aFileName: string); overload;
  94. procedure LoadFromFile(aFileName, aAchiverType: string); overload;
  95. procedure Clear;
  96. function ContentExists(aContentName: string): boolean;
  97. property FileName: string read FFileName;
  98. function GetContent(aindex: integer): TStream; overload;
  99. function GetContent(aContentName: string): TStream; overload;
  100. function GetContentSize(aindex: integer): integer; overload;
  101. function GetContentSize(aContentName: string): integer; overload;
  102. procedure AddFromStream(aContentName, aPath: string; aF: TStream); overload;
  103. procedure AddFromStream(aContentName: string; aF: TStream); overload;
  104. procedure AddFromFile(aFileName, aPath: string); overload;
  105. procedure AddFromFile(aFileName: string); overload;
  106. procedure RemoveContent(aindex: integer); overload;
  107. procedure RemoveContent(aContentName: string); overload;
  108. procedure Extract(aindex: integer; aNewName: string); overload;
  109. procedure Extract(aContentName, aNewName: string); overload;
  110. published
  111. property Name: string read FName write SetName;
  112. end;
  113. TGLLibArchives = class(TOwnedCollection)
  114. protected
  115. procedure SetItems(index: integer; const val: TGLLibArchive);
  116. function GetItems(index: integer): TGLLibArchive;
  117. public
  118. constructor Create(AOwner: TComponent);
  119. function Owner: TPersistent;
  120. function IndexOf(const Item: TGLLibArchive): integer;
  121. function Add: TGLLibArchive;
  122. function FindItemID(ID: integer): TGLLibArchive;
  123. property Items[index: integer]: TGLLibArchive read GetItems
  124. write SetItems; default;
  125. // searching archiver by name
  126. function GetArchiveByFileName(const AName: string): TGLLibArchive;
  127. function GetFileNameOfArchive(aValue: TGLLibArchive): string;
  128. // searching needed item
  129. function MakeUniqueName(const nameRoot: string): string;
  130. function GetLibArchiveByName(const AName: string): TGLLibArchive;
  131. function GetNameOfLibArchive(const Archive: TGLLibArchive): string;
  132. end;
  133. // ArchiveManager class
  134. TGLSArchiveManager = class(TComponent)
  135. private
  136. FArchives: TGLLibArchives;
  137. Procedure SetArchives(aValue: TGLLibArchives);
  138. public
  139. constructor Create(AOwner: TComponent); override;
  140. destructor Destroy; override;
  141. function GetArchiveByFileName(const AName: string): TGLLibArchive;
  142. function GetFileNameOfArchive(const aArchive: TGLLibArchive): string;
  143. function GetContent(aContentName: string): TStream;
  144. function ContentExists(aContentName: string): boolean;
  145. function OpenArchive(aFileName: string): TGLLibArchive; overload;
  146. function OpenArchive(aFileName, aAchiverType: string): TGLLibArchive;
  147. overload;
  148. procedure CloseArchive(aArchive: TGLLibArchive);
  149. published
  150. property Archives: TGLLibArchives read FArchives write SetArchives;
  151. end;
  152. EInvalidArchiveFile = class(Exception);
  153. // getting a class of accessed archiver
  154. function GetArchiveFileFormats: TGLArchiveFileFormatsList;
  155. procedure RegisterArchiveFormat(const AExtension, ADescription: string;
  156. AClass: TGLBaseArchiveClass);
  157. procedure UnregisterArchiveFormat(AClass: TGLBaseArchiveClass);
  158. // Caution!!! Work for one archive manager only
  159. function GetArchiveManager: TGLSArchiveManager;
  160. // GLS.ApplicationFileIO
  161. // These functions are used to automate loading
  162. // User enters LoadFromFile and through these functions gets the result
  163. function ArcCreateFileStream(const FileName: string; mode: word): TStream;
  164. function ArcFileStreamExists(const FileName: string): boolean;
  165. // ------------------------------------------------------------------
  166. implementation
  167. // ------------------------------------------------------------------
  168. var
  169. vArchiveFileFormats: TGLArchiveFileFormatsList;
  170. vArchiveManager: TGLSArchiveManager;
  171. function GetArchiveFileFormats: TGLArchiveFileFormatsList;
  172. begin
  173. if not Assigned(vArchiveFileFormats) then
  174. vArchiveFileFormats := TGLArchiveFileFormatsList.Create;
  175. Result := vArchiveFileFormats;
  176. end;
  177. procedure RegisterArchiveFormat(const AExtension, ADescription: string;
  178. AClass: TGLBaseArchiveClass);
  179. begin
  180. RegisterClass(AClass);
  181. GetArchiveFileFormats.Add(AExtension, ADescription, 0, AClass);
  182. end;
  183. procedure UnregisterArchiveFormat(AClass: TGLBaseArchiveClass);
  184. begin
  185. if Assigned(vArchiveFileFormats) then
  186. vArchiveFileFormats.Remove(AClass);
  187. end;
  188. function GetArchiveManager: TGLSArchiveManager;
  189. begin
  190. Result := vArchiveManager;
  191. end;
  192. function ArcCreateFileStream(const FileName: string; mode: word): TStream;
  193. begin
  194. If GetArchiveManager <> nil then
  195. with GetArchiveManager do
  196. if ContentExists(FileName) then
  197. begin
  198. Result := GetContent(FileName);
  199. Exit;
  200. end;
  201. if FileExists(FileName) then
  202. begin
  203. Result := TFileStream.Create(FileName, mode);
  204. Exit;
  205. // why create a file stream when a file is not found ???
  206. { end
  207. else begin
  208. Result := TFileStream.Create(FileName, fmCreate or fmShareDenyWrite);
  209. Exit; }
  210. end;
  211. Result := nil;
  212. end;
  213. function ArcFileStreamExists(const FileName: string): boolean;
  214. begin
  215. If GetArchiveManager <> nil then
  216. with GetArchiveManager do
  217. if ContentExists(FileName) then
  218. begin
  219. Result := True;
  220. Exit;
  221. end;
  222. Result := FileExists(FileName);
  223. end;
  224. // ******************************************************************************
  225. // TGLLibArchive
  226. constructor TGLLibArchive.Create(ACollection: TCollection);
  227. begin
  228. inherited Create(ACollection);
  229. FName := TGLLibArchives(ACollection).MakeUniqueName('LibArchive');
  230. end;
  231. destructor TGLLibArchive.Destroy;
  232. begin
  233. Clear;
  234. inherited Destroy;
  235. end;
  236. procedure TGLLibArchive.SetCompressionLevel(aValue: TCompressionLevel);
  237. begin
  238. if vArchive = nil then
  239. Exit;
  240. vArchive.CompressionLevel := aValue;
  241. end;
  242. function TGLLibArchive.GetCompressionLevel: TCompressionLevel;
  243. begin
  244. Result := clDefault;
  245. if vArchive = nil then
  246. Exit;
  247. Result := vArchive.CompressionLevel;
  248. end;
  249. procedure TGLLibArchive.CreateArchive(FileName: string;
  250. OverwriteExistingFile: boolean = False);
  251. var
  252. fFile: TFileStream;
  253. begin
  254. if OverwriteExistingFile or not FileExists(FileName) then
  255. begin
  256. fFile := TFileStream.Create(FileName, fmCreate);
  257. fFile.Free;
  258. end;
  259. end;
  260. procedure TGLLibArchive.LoadFromFile(aFileName: string);
  261. var
  262. Ext: string;
  263. begin
  264. Ext := LowerCase(ExtractFileExt(aFileName));
  265. Delete(Ext, 1, 1);
  266. LoadFromFile(aFileName, Ext);
  267. end;
  268. procedure TGLLibArchive.LoadFromFile(aFileName, aAchiverType: string);
  269. begin
  270. if not FileExists(aFileName) then
  271. Exit;
  272. ArcClass := GetArchiveFileFormats.FindExt(aAchiverType);
  273. If ArcClass = nil then
  274. begin
  275. raise Exception.Create(ClassName +
  276. ': Unable to find module archiver to expand ' + aAchiverType);
  277. Exit;
  278. end;
  279. vArchive := ArcClass.Create(nil);
  280. vArchive.LoadFromFile(aFileName);
  281. FFileName := aFileName;
  282. end;
  283. procedure TGLLibArchive.Clear;
  284. begin
  285. if vArchive = nil then
  286. Exit;
  287. vArchive.Clear;
  288. vArchive.Free;
  289. ArcClass := nil;
  290. FFileName := '';
  291. end;
  292. function TGLLibArchive.ContentExists(aContentName: string): boolean;
  293. begin
  294. Result := False;
  295. if vArchive = nil then
  296. Exit;
  297. Result := vArchive.ContentExists(aContentName)
  298. end;
  299. function TGLLibArchive.GetContent(aindex: integer): TStream;
  300. begin
  301. Result := nil;
  302. if vArchive = nil then
  303. Exit;
  304. Result := vArchive.GetContent(aindex)
  305. end;
  306. function TGLLibArchive.GetContent(aContentName: string): TStream;
  307. begin
  308. Result := nil;
  309. if vArchive = nil then
  310. Exit;
  311. Result := vArchive.GetContent(aContentName)
  312. end;
  313. function TGLLibArchive.GetContentSize(aindex: integer): integer;
  314. begin
  315. Result := -1;
  316. if vArchive = nil then
  317. Exit;
  318. Result := vArchive.GetContentSize(aindex)
  319. end;
  320. function TGLLibArchive.GetContentSize(aContentName: string): integer;
  321. begin
  322. Result := -1;
  323. if vArchive = nil then
  324. Exit;
  325. Result := vArchive.GetContentSize(aContentName)
  326. end;
  327. procedure TGLLibArchive.AddFromStream(aContentName, aPath: string; aF: TStream);
  328. begin
  329. if vArchive = nil then
  330. Exit;
  331. vArchive.AddFromStream(aContentName, aPath, aF)
  332. end;
  333. procedure TGLLibArchive.AddFromStream(aContentName: string; aF: TStream);
  334. begin
  335. if vArchive = nil then
  336. Exit;
  337. vArchive.AddFromStream(aContentName, '', aF)
  338. end;
  339. procedure TGLLibArchive.AddFromFile(aFileName, aPath: string);
  340. begin
  341. if vArchive = nil then
  342. Exit;
  343. vArchive.AddFromFile(aFileName, aPath)
  344. end;
  345. procedure TGLLibArchive.AddFromFile(aFileName: string);
  346. begin
  347. if vArchive = nil then
  348. Exit;
  349. vArchive.AddFromFile(aFileName, '')
  350. end;
  351. procedure TGLLibArchive.RemoveContent(aindex: integer);
  352. begin
  353. if vArchive = nil then
  354. Exit;
  355. vArchive.RemoveContent(aindex)
  356. end;
  357. procedure TGLLibArchive.RemoveContent(aContentName: string);
  358. begin
  359. if vArchive = nil then
  360. Exit;
  361. vArchive.RemoveContent(aContentName)
  362. end;
  363. procedure TGLLibArchive.Extract(aindex: integer; aNewName: string);
  364. begin
  365. if vArchive = nil then
  366. Exit;
  367. vArchive.Extract(aindex, aNewName)
  368. end;
  369. procedure TGLLibArchive.Extract(aContentName, aNewName: string);
  370. begin
  371. if vArchive = nil then
  372. Exit;
  373. vArchive.Extract(aContentName, aNewName)
  374. end;
  375. function TGLLibArchive.GetContentList: TStrings;
  376. begin
  377. Result := nil;
  378. if vArchive = nil then
  379. Exit;
  380. Result := vArchive.ContentList;
  381. end;
  382. procedure TGLLibArchive.SetName(const val: string);
  383. begin
  384. if val <> FName then
  385. begin
  386. if not(csLoading in TComponent(TGLLibArchives(Collection).GetOwner)
  387. .ComponentState) then
  388. begin
  389. if TGLLibArchives(Collection).GetLibArchiveByName(val) <> Self then
  390. FName := TGLLibArchives(Collection).MakeUniqueName(val)
  391. else
  392. FName := val;
  393. end
  394. else
  395. FName := val;
  396. end;
  397. end;
  398. function TGLLibArchive.GetDisplayName: string;
  399. begin
  400. Result := Name;
  401. end;
  402. procedure TGLLibArchives.SetItems(index: integer; const val: TGLLibArchive);
  403. begin
  404. GetItems(Index).Assign(val);
  405. end;
  406. function TGLLibArchives.GetItems(index: integer): TGLLibArchive;
  407. begin
  408. Result := TGLLibArchive(inherited GetItem(Index));
  409. end;
  410. constructor TGLLibArchives.Create(AOwner: TComponent);
  411. begin
  412. inherited Create(AOwner, TGLLibArchive);
  413. end;
  414. function TGLLibArchives.Owner: TPersistent;
  415. begin
  416. Result := GetOwner;
  417. end;
  418. function TGLLibArchives.IndexOf(const Item: TGLLibArchive): integer;
  419. var
  420. I: integer;
  421. begin
  422. Result := -1;
  423. if Count <> 0 then
  424. for I := 0 to Count - 1 do
  425. if GetItems(I) = Item then
  426. begin
  427. Result := I;
  428. Exit;
  429. end;
  430. end;
  431. function TGLLibArchives.Add: TGLLibArchive;
  432. begin
  433. Result := (inherited Add) as TGLLibArchive;
  434. end;
  435. function TGLLibArchives.FindItemID(ID: integer): TGLLibArchive;
  436. begin
  437. Result := (inherited FindItemID(ID)) as TGLLibArchive;
  438. end;
  439. function TGLLibArchives.GetArchiveByFileName(const AName: string): TGLLibArchive;
  440. var
  441. I: integer;
  442. Arc: TGLLibArchive;
  443. begin
  444. for I := 0 to Count - 1 do
  445. begin
  446. Arc := TGLLibArchive(inherited Items[I]);
  447. if Arc.FileName = AName then
  448. begin
  449. Result := Arc;
  450. Exit;
  451. end;
  452. end;
  453. Result := nil;
  454. end;
  455. function TGLLibArchives.GetFileNameOfArchive(aValue: TGLLibArchive): string;
  456. var
  457. ArcIndex: integer;
  458. begin
  459. ArcIndex := IndexOf(aValue);
  460. if ArcIndex <> -1 then
  461. Result := GetItems(ArcIndex).FileName
  462. else
  463. Result := '';
  464. end;
  465. function TGLLibArchives.MakeUniqueName(const nameRoot: string): string;
  466. var
  467. I: integer;
  468. begin
  469. Result := nameRoot;
  470. I := 1;
  471. while GetLibArchiveByName(Result) <> nil do
  472. begin
  473. Result := nameRoot + IntToStr(I);
  474. Inc(I);
  475. end;
  476. end;
  477. function TGLLibArchives.GetLibArchiveByName(const AName: string): TGLLibArchive;
  478. var
  479. I: integer;
  480. Arc: TGLLibArchive;
  481. begin
  482. for I := 0 to Count - 1 do
  483. begin
  484. Arc := TGLLibArchive(inherited Items[I]);
  485. if (Arc.Name = AName) then
  486. begin
  487. Result := Arc;
  488. Exit;
  489. end;
  490. end;
  491. Result := nil;
  492. end;
  493. function TGLLibArchives.GetNameOfLibArchive(const Archive: TGLLibArchive): string;
  494. var
  495. MatIndex: integer;
  496. begin
  497. MatIndex := IndexOf(Archive);
  498. if MatIndex <> -1 then
  499. Result := GetItems(MatIndex).Name
  500. else
  501. Result := '';
  502. end;
  503. // ******************************************************************************
  504. { TGLArchiveFileFormatsList }
  505. destructor TGLArchiveFileFormatsList.Destroy;
  506. begin
  507. Clean;
  508. inherited Destroy;
  509. end;
  510. procedure TGLArchiveFileFormatsList.Add(const Ext, Desc: string;
  511. DescID: integer; AClass: TGLBaseArchiveClass);
  512. var
  513. newRec: TGLArchiveFileFormat;
  514. begin
  515. newRec := TGLArchiveFileFormat.Create;
  516. with newRec do
  517. begin
  518. Extension := AnsiLowerCase(Ext);
  519. BaseArchiveClass := AClass;
  520. Description := Desc;
  521. DescResID := DescID;
  522. end;
  523. inherited Add(newRec);
  524. end;
  525. function TGLArchiveFileFormatsList.FindExt(Ext: string): TGLBaseArchiveClass;
  526. var
  527. I: integer;
  528. begin
  529. Ext := AnsiLowerCase(Ext);
  530. for I := Count - 1 downto 0 do
  531. with TGLArchiveFileFormat(Items[I]) do
  532. begin
  533. if Extension = Ext then
  534. begin
  535. Result := BaseArchiveClass;
  536. Exit;
  537. end;
  538. end;
  539. Result := nil;
  540. end;
  541. function TGLArchiveFileFormatsList.FindFromFileName(const FileName: string)
  542. : TGLBaseArchiveClass;
  543. var
  544. Ext: string;
  545. begin
  546. Ext := ExtractFileExt(FileName);
  547. System.Delete(Ext, 1, 1);
  548. Result := FindExt(Ext);
  549. if not Assigned(Result) then
  550. raise EInvalidArchiveFile.CreateFmt(strUnknownExtension,
  551. [Ext, 'GLFile' + UpperCase(Ext)]);
  552. end;
  553. procedure TGLArchiveFileFormatsList.Remove(AClass: TGLBaseArchiveClass);
  554. var
  555. I: integer;
  556. begin
  557. for I := Count - 1 downto 0 do
  558. begin
  559. if TGLArchiveFileFormat(Items[I]).BaseArchiveClass.InheritsFrom(AClass) then
  560. DeleteAndFree(I);
  561. end;
  562. end;
  563. // ******************************************************************************
  564. { TGLBaseArchive }
  565. procedure TGLBaseArchive.SetCompressionLevel(aValue: TCompressionLevel);
  566. begin
  567. if FCompressionLevel <> aValue then
  568. FCompressionLevel := aValue;
  569. end;
  570. constructor TGLBaseArchive.Create(AOwner: TPersistent);
  571. begin
  572. inherited Create(AOwner);
  573. FContentList := TStringList.Create;
  574. FCompressionLevel := clDefault;
  575. end;
  576. destructor TGLBaseArchive.Destroy;
  577. begin
  578. FContentList.Free;
  579. inherited Destroy;
  580. end;
  581. // ******************************************************************************
  582. { TGLSArchiveManager }
  583. constructor TGLSArchiveManager.Create(AOwner: TComponent);
  584. begin
  585. inherited Create(AOwner);
  586. FArchives := TGLLibArchives.Create(Self);
  587. vArchiveManager := Self;
  588. vAFIOCreateFileStream := ArcCreateFileStream;
  589. vAFIOFileStreamExists := ArcFileStreamExists;
  590. end;
  591. destructor TGLSArchiveManager.Destroy;
  592. begin
  593. vArchiveManager := nil;
  594. vAFIOCreateFileStream := nil;
  595. vAFIOFileStreamExists := nil;
  596. FArchives.Free;
  597. inherited Destroy;
  598. end;
  599. procedure TGLSArchiveManager.SetArchives(aValue: TGLLibArchives);
  600. begin
  601. FArchives.Assign(aValue);
  602. end;
  603. function TGLSArchiveManager.GetArchiveByFileName(const AName: string)
  604. : TGLLibArchive;
  605. begin
  606. Result := FArchives.GetArchiveByFileName(AName);
  607. end;
  608. function TGLSArchiveManager.GetFileNameOfArchive(const aArchive
  609. : TGLLibArchive): string;
  610. begin
  611. Result := FArchives.GetFileNameOfArchive(aArchive)
  612. end;
  613. function TGLSArchiveManager.GetContent(aContentName: string): TStream;
  614. var
  615. I: integer;
  616. begin
  617. Result := nil;
  618. With FArchives do
  619. for I := 0 to Count - 1 do
  620. if Items[I].ContentExists(aContentName) then
  621. begin
  622. Result := Items[I].GetContent(aContentName);
  623. Exit;
  624. end;
  625. end;
  626. function TGLSArchiveManager.ContentExists(aContentName: string): boolean;
  627. var
  628. I: integer;
  629. begin
  630. Result := False;
  631. With FArchives do
  632. for I := 0 to Count - 1 do
  633. if Items[I].ContentExists(aContentName) then
  634. begin
  635. Result := Items[I].ContentExists(aContentName);
  636. Exit;
  637. end;
  638. end;
  639. function TGLSArchiveManager.OpenArchive(aFileName: string): TGLLibArchive;
  640. begin
  641. Result := FArchives.Add;
  642. Result.LoadFromFile(aFileName);
  643. end;
  644. function TGLSArchiveManager.OpenArchive(aFileName, aAchiverType: string)
  645. : TGLLibArchive;
  646. begin
  647. Result := FArchives.Add;
  648. Result.LoadFromFile(aFileName, aAchiverType);
  649. end;
  650. procedure TGLSArchiveManager.CloseArchive(aArchive: TGLLibArchive);
  651. begin
  652. FArchives.Delete(FArchives.IndexOf(aArchive));
  653. end;
  654. // -----------------------------------------------------------
  655. initialization
  656. // -----------------------------------------------------------
  657. RegisterClasses([TGLSArchiveManager, TGLLibArchives]);
  658. finalization
  659. FreeAndNil(vArchiveFileFormats);
  660. end.