127 lines
4.4 KiB
Objective-C
127 lines
4.4 KiB
Objective-C
//
|
|
// WRPreloadBookManager.h
|
|
// WeRead (读书)
|
|
// Reverse-engineered header
|
|
//
|
|
// Preload manager. Predicts which chapters to preload based on book ranking
|
|
// and user behavior. Manages encryption keys for preloaded content.
|
|
// Supports whole-book preloading and incremental chapter preloading.
|
|
//
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
@class WRBook;
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Preload scene types
|
|
// ---------------------------------------------------------------------------
|
|
typedef NS_ENUM(NSInteger, WRPreloadScene) {
|
|
WRPreloadSceneNone = 0,
|
|
WRPreloadSceneShelf = 1, // Preload from bookshelf
|
|
WRPreloadSceneReading = 2, // Preload next chapters while reading
|
|
WRPreloadSceneWiFi = 3, // Aggressive preload on WiFi
|
|
WRPreloadSceneManual = 4, // User-initiated preload
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// WRPreloadBookManager
|
|
// ---------------------------------------------------------------------------
|
|
@interface WRPreloadBookManager : NSObject
|
|
|
|
// --- Ivars (from binary analysis) ---
|
|
// {
|
|
// NSMutableDictionary *_preloadState; // bookId -> preload state dict
|
|
// }
|
|
|
|
@property (nonatomic, strong, readonly) NSMutableDictionary *preloadState;
|
|
|
|
#pragma mark - Class Methods: Encryption Key Storage
|
|
|
|
/// Save an encryption key for a preloaded book.
|
|
/// @param key The encryption key data (hex or raw).
|
|
/// @param path The file path where the key is associated.
|
|
/// @param bookId The book identifier.
|
|
+ (void)saveEncryptKey:(NSString *)key
|
|
forPath:(NSString *)path
|
|
bookId:(NSString *)bookId;
|
|
|
|
/// Retrieve the stored encryption key for a book.
|
|
/// @param path The associated file path.
|
|
/// @param bookId The book identifier.
|
|
/// @return The encryption key string, or nil.
|
|
+ (nullable NSString *)encryptKeyForPath:(NSString *)path
|
|
bookId:(NSString *)bookId;
|
|
|
|
/// Remove a stored encryption key.
|
|
+ (void)removeEncryptKeyForPath:(NSString *)path
|
|
bookId:(NSString *)bookId;
|
|
|
|
#pragma mark - Class Methods: Filename Dictionary
|
|
|
|
/// Save a filename mapping dictionary for a book.
|
|
/// Maps content keys to actual filenames in the tar archive.
|
|
+ (void)saveFileNameDict:(NSDictionary<NSString *, NSString *> *)dict
|
|
bookId:(NSString *)bookId;
|
|
|
|
/// Look up a filename by key for a given book.
|
|
+ (nullable NSString *)fileNameForKey:(NSString *)key
|
|
bookId:(NSString *)bookId;
|
|
|
|
/// Remove a filename mapping entry.
|
|
+ (void)removeFileNameForKey:(NSString *)key
|
|
bookId:(NSString *)bookId;
|
|
|
|
#pragma mark - Class Methods: Cache Management
|
|
|
|
/// Clear all preload key-value caches.
|
|
+ (void)clearKV;
|
|
|
|
/// Remove all preload data for a specific book.
|
|
+ (void)removeKVWithBookId:(NSString *)bookId;
|
|
|
|
#pragma mark - Instance Methods: Preloading
|
|
|
|
/// Preload an entire book (all chapters).
|
|
/// @param book The book model to preload.
|
|
/// @param scene The preload context/scene.
|
|
- (void)_preloadWholeBook:(WRBook *)book scene:(WRPreloadScene)scene;
|
|
|
|
/// Preload chapters starting from a given index.
|
|
/// @param book The book model.
|
|
/// @param fromChapterIdx Starting chapter index.
|
|
- (void)preloadWithBook:(WRBook *)book fromChapterIdx:(NSInteger)fromChapterIdx;
|
|
|
|
/// Download specific chapters for a book.
|
|
/// @param book The book model.
|
|
/// @param uids Array of chapter UIDs to download.
|
|
- (void)downloadBook:(WRBook *)book uids:(NSArray<NSString *> *)uids;
|
|
|
|
/// Clean up all preloaded book data.
|
|
- (void)cleanUpPreloadBook;
|
|
|
|
/// Calculate preload cache size and optionally clear it.
|
|
/// @param completion Called with the total size in bytes.
|
|
/// @param onlyCalc YES to only calculate, NO to also clear.
|
|
- (void)calcAndClearPreloadBookWithCompletion:(void (^)(NSUInteger totalSize))completion
|
|
onlyCalc:(BOOL)onlyCalc;
|
|
|
|
#pragma mark - Additional Methods (23 total, reconstructed)
|
|
|
|
/// Check if a book is currently being preloaded.
|
|
- (BOOL)isPreloadingBookId:(NSString *)bookId;
|
|
|
|
/// Get the preload progress for a book (0.0 - 1.0).
|
|
- (float)preloadProgressForBookId:(NSString *)bookId;
|
|
|
|
/// Cancel an ongoing preload for a book.
|
|
- (void)cancelPreloadForBookId:(NSString *)bookId;
|
|
|
|
/// Determine which chapters should be preloaded next.
|
|
- (NSArray<NSString *> *)predictedChapterUidsForBook:(WRBook *)book;
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|