GLS.ArchiveManager.pas 20 KB

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