1 /* 2 * Copyright 2020-2024, Andrew Lindesay <apl@lindesay.co.nz>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 #ifndef PACKAGE_ICON_TAR_REPOSITORY_H 6 #define PACKAGE_ICON_TAR_REPOSITORY_H 7 8 9 #include <DataIO.h> 10 #include <HashMap.h> 11 #include <HashString.h> 12 #include <Locker.h> 13 #include <Path.h> 14 #include <Referenceable.h> 15 16 #include "IconTarPtr.h" 17 #include "LRUCache.h" 18 #include "PackageIconRepository.h" 19 20 21 typedef BReference<IconTarPtr> IconTarPtrRef; 22 23 24 class PackageIconTarRepository : public PackageIconRepository { 25 public: 26 PackageIconTarRepository(); 27 virtual ~PackageIconTarRepository(); 28 29 status_t Init(BPath& tarPath); 30 31 void AddIconTarPtr(const BString& pkgName, 32 BitmapSize size, off_t offset); 33 virtual status_t GetIcon(const BString& pkgName, uint32 size, 34 BitmapHolderRef& bitmapHolderRef); 35 virtual bool HasAnyIcon(const BString& pkgName); 36 virtual void Clear(); 37 38 private: 39 void _Close(); 40 41 const char* _ToIconCacheKeyPart(BitmapSize size); 42 const HashString _ToIconCacheKey(const BString& pkgName, BitmapSize storedSize, 43 uint32 size); 44 45 IconTarPtrRef _GetOrCreateIconTarPtr(const BString& pkgName); 46 IconTarPtrRef _GetIconTarPtr(const BString& pkgName) const; 47 48 status_t _CreateIconFromTarOffset(off_t offset, BitmapSize bitmapSize, 49 uint32 size, BitmapHolderRef& bitmapHolderRef); 50 51 status_t _GetDefaultIcon(uint32 size, BitmapHolderRef& bitmapHolderRef); 52 53 static BitmapSize _BestStoredSize(const IconTarPtrRef iconTarPtrRef, 54 int32 desiredSize); 55 56 void _InitDefaultVectorIcon(); 57 58 private: 59 BLocker fLock; 60 BPositionIO* fTarIo; 61 LRUCache<HashString, BitmapHolderRef> 62 fIconCache; 63 HashMap<HashString, IconTarPtrRef> 64 fIconTarPtrs; 65 66 uint8* fDefaultIconVectorData; 67 size_t fDefaultIconVectorDataSize; 68 LRUCache<HashString, BitmapHolderRef> 69 fDefaultIconCache; 70 71 BMallocIO* fIconDataBuffer; 72 }; 73 74 #endif // PACKAGE_ICON_TAR_REPOSITORY_H 75