/* * Copyright 2020-2024, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef PACKAGE_ICON_TAR_REPOSITORY_H #define PACKAGE_ICON_TAR_REPOSITORY_H #include #include #include #include #include #include #include "IconTarPtr.h" #include "LRUCache.h" #include "PackageIconRepository.h" typedef BReference IconTarPtrRef; class PackageIconTarRepository : public PackageIconRepository { public: PackageIconTarRepository(); virtual ~PackageIconTarRepository(); status_t Init(BPath& tarPath); void AddIconTarPtr(const BString& pkgName, BitmapSize size, off_t offset); virtual status_t GetIcon(const BString& pkgName, uint32 size, BitmapHolderRef& bitmapHolderRef); virtual bool HasAnyIcon(const BString& pkgName); virtual void Clear(); private: void _Close(); const char* _ToIconCacheKeySuffix(BitmapSize size); const HashString _ToIconCacheKey(const BString& pkgName, BitmapSize size); IconTarPtrRef _GetOrCreateIconTarPtr(const BString& pkgName); IconTarPtrRef _GetIconTarPtr(const BString& pkgName) const; status_t _CreateIconFromTarOffset(off_t offset, BitmapHolderRef& bitmapHolderRef); status_t _GetDefaultIcon(uint32 size, BitmapHolderRef& bitmapHolderRef); static BitmapSize _BestStoredSize(const IconTarPtrRef iconTarPtrRef, int32 desiredSize); void _InitDefaultVectorIcon(); private: BLocker fLock; BPositionIO* fTarIo; LRUCache fIconCache; HashMap fIconTarPtrs; uint8* fDefaultIconVectorData; size_t fDefaultIconVectorDataSize; LRUCache fDefaultIconCache; BMallocIO* fIconDataBuffer; }; #endif // PACKAGE_ICON_TAR_REPOSITORY_H