ReadViewSDK/Doc/WXRead/decompiled/WREpubParser.h
2026-05-21 19:40:51 +08:00

112 lines
4.3 KiB
Objective-C

//
// WREpubParser.h
// WeRead (微信读书)
// Reverse-engineered header
//
// EPUB file parser. Parses OPF (content.opf), NCX (toc.ncx), and XHTML chapter files.
// Resolves EPUB structure: container.xml -> content.opf -> spine -> chapters.
// Returns chapter list and resource mapping.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@class WRBook;
@class WHAlbumInfo;
// ---------------------------------------------------------------------------
// Error domain and codes for EPUB parsing failures
// ---------------------------------------------------------------------------
extern NSString *const WREpubParserErrorDomain;
typedef NS_ENUM(NSInteger, WREpubParserErrorCode) {
WREpubParserErrorFileNotFound = -1000,
WREpubParserErrorContainerParseFail = -1001,
WREpubParserErrorOPFParseFail = -1002,
WREpubParserErrorNCXParseFail = -1003,
WREpubParserErrorSpineEmpty = -1004,
WREpubParserErrorChapterLoadFail = -1005,
WREpubParserErrorDecryptionFail = -1006,
};
// ---------------------------------------------------------------------------
// WREpubParserDelegate
// ---------------------------------------------------------------------------
@protocol WREpubParserDelegate <NSObject>
@optional
/// Called when the EPUB controller encounters a fatal parsing error.
/// The parser invokes this on the delegate (typically a UIViewController)
/// so the UI layer can present the error to the user.
- (void)epubController:(id)controller didFailWithError:(NSError *)error;
@end
// ---------------------------------------------------------------------------
// WREpubParser
// ---------------------------------------------------------------------------
@interface WREpubParser : NSObject
// --- Ivars (from binary analysis) ---
// {
// NSString *_epubFilePath; // path to the .epub file on disk
// NSString *_baseDirectory; // extracted root directory
// NSError *_lastError; // most recent parse error
// UIViewController *_epubController; // weak ref to presenting controller
// WRBook *_book; // associated book model
// WHAlbumInfo *_albumInfo; // album / collection metadata
// }
@property (nonatomic, copy, readonly) NSString *epubFilePath;
@property (nonatomic, copy, readonly) NSString *baseDirectory;
@property (nonatomic, strong, readonly, nullable) NSError *lastError;
@property (nonatomic, weak, nullable) id<WREpubParserDelegate> delegate;
@property (nonatomic, strong, readonly, nullable) WRBook *book;
@property (nonatomic, strong, readonly, nullable) WHAlbumInfo *albumInfo;
/// Chapters parsed from the spine, in reading order.
@property (nonatomic, strong, readonly) NSArray<NSDictionary *> *chapters;
/// Resource map: relative path -> absolute path for images, CSS, fonts, etc.
@property (nonatomic, strong, readonly) NSDictionary<NSString *, NSString *> *resourceMap;
/// Ordered list of spine item IDs (for navigation).
@property (nonatomic, strong, readonly) NSArray<NSString *> *spineItemIDs;
#pragma mark - Initialization
- (instancetype)initWithFilePath:(NSString *)path
book:(nullable WRBook *)book;
#pragma mark - Parsing
/// Parse the EPUB archive. Returns YES on success.
- (BOOL)parse:(NSError *_Nullable *_Nullable)error;
/// Parse container.xml and return the path to the OPF file.
- (nullable NSString *)parseContainerXML:(NSError *_Nullable *_Nullable)error;
/// Parse content.opf and populate chapters + resourceMap.
- (BOOL)parseOPFAtRelativePath:(NSString *)opfRelPath
error:(NSError *_Nullable *_Nullable)error;
/// Parse toc.ncx and return the table-of-contents tree.
- (nullable NSArray *)parseNCX:(NSError *_Nullable *_Nullable)error;
/// Read and return the XHTML content of a single chapter.
- (nullable NSString *)contentForChapterAtIndex:(NSUInteger)index
error:(NSError *_Nullable *_Nullable)error;
/// Resolve a relative resource path to an absolute file path.
- (nullable NSString *)absolutePathForResource:(NSString *)relativePath;
#pragma mark - Delegate callback (internal)
- (void)notifyDelegateOfError:(NSError *)error;
@end
NS_ASSUME_NONNULL_END