forked from NSGod/ichm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCHMDocumentFile.h
146 lines (89 loc) · 4.13 KB
/
CHMDocumentFile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// CHMDocumentFile.h
// ichm
//
// Created by Mark Douma on 4/15/2016.
//
// Copyright © 2016 Mark Douma.
#import <Foundation/Foundation.h>
struct chmFile;
@class CHMTableOfContents;
@class CHMDocumentFile;
@class CHMLinkItem;
@class CHMArchiveItem;
@protocol CHMDocumentFileSearchDelegate <NSObject>
@optional
- (void)documentFileDidPrepareSearchIndex:(CHMDocumentFile *)aDocumentFile;
// `aSearchResults` is an NSArray of `CHMSearchResult`s
- (void)documentFile:(CHMDocumentFile *)aDocumentFile didUpdateSearchResults:(NSArray *)aSearchResults;
@end
enum {
CHMDocumentFileDefaultStringEncoding = 0,
};
enum {
CHMDocumentFileSearchInFile = 1,
CHMDocumentFileSearchInIndex = 2,
};
typedef NSUInteger CHMDocumentFileSearchMode;
@interface CHMDocumentFile : NSObject {
NSString *filePath;
struct chmFile *chmFileHandle;
NSString *title;
NSString *homePath;
NSString *tableOfContentsPath;
NSString *indexPath;
CHMTableOfContents *tableOfContents;
CHMTableOfContents *index;
NSMutableArray *searchResults;
CHMArchiveItem *archiveItems;
NSMutableArray *allArchiveItems;
SKIndexRef skIndex;
NSMutableData *searchIndexData;
BOOL hasPreparedSearchIndex;
BOOL isPreparingSearchIndex;
NSCondition *searchIndexCondition;
NSStringEncoding encoding;
NSString *encodingName;
NSStringEncoding customEncoding;
NSString *customEncodingName;
id <CHMDocumentFileSearchDelegate> searchDelegate; // non-retained
}
// NOTE: error reporting isn't yet implemented
+ (id)documentFileWithContentsOfFile:(NSString *)path error:(NSError **)outError;
- (id)initWithContentsOfFile:(NSString *)path error:(NSError **)outError;
@property (readonly, nonatomic, retain) NSString *filePath;
@property (readonly, nonatomic, retain) NSString *title;
@property (readonly, nonatomic, retain) NSString *homePath;
@property (readonly, nonatomic, retain) NSString *tableOfContentsPath;
@property (readonly, nonatomic, retain) NSString *indexPath;
@property (readonly, retain) CHMTableOfContents *tableOfContents;
@property (readonly, retain) CHMTableOfContents *index;
// returns the root-level CHMArchiveItem
@property (readonly, nonatomic, retain) CHMArchiveItem *archiveItems;
// returns an array of all CHMArchiveItem, including the root item and all its descendants
@property (readonly, nonatomic, retain) NSArray *allArchiveItems;
- (CHMArchiveItem *)archiveItemAtPath:(NSString *)absolutePath;
- (CHMArchiveItem *)archiveItemAtPath:(NSString *)relativePath relativeToArchiveItem:(CHMArchiveItem *)anItem;
- (CHMLinkItem *)linkItemAtPath:(NSString *)absolutePath;
#pragma mark - encodings
@property (readonly, assign) NSStringEncoding encoding;
@property (readonly, retain) NSString *encodingName; // IANA
@property (readonly, assign) NSStringEncoding customEncoding;
@property (readonly, retain) NSString *customEncodingName; // IANA
// to set or clear a custom encoding; to clear, pass `CHMDocumentFileDefaultStringEncoding` and `nil`
- (void)setCustomEncoding:(NSStringEncoding)aCustomEncoding customEncodingName:(NSString *)aCustomEncodingName;
// convenience, returns `customEncodingName` if non-nil (in other words, one is set), otherwise returns `encodingName`.
@property (readonly, nonatomic, retain) NSString *currentEncodingName;
#pragma mark - search
// sets/gets whether instances automatically prepare search kit index upon creation
// default is YES
+ (BOOL)automaticallyPreparesSearchIndex;
+ (void)setAutomaticallyPreparesSearchIndex:(BOOL)shouldPrepare;
// whether this particular instance's search index has been prepared
@property (readonly, assign) BOOL hasPreparedSearchIndex;
// Asynchronously prepares the search index. Use the `documentFileDidPrepareSearchIndex:` search delegate method to learn when the preparation is complete.
- (void)prepareSearchIndex;
@property (assign) id <CHMDocumentFileSearchDelegate> searchDelegate;
@property (readonly, nonatomic, retain) NSArray *searchResults;
- (void)searchForString:(NSString *)searchString usingMode:(CHMDocumentFileSearchMode)searchMode;
@end