Skip to content

Commit

Permalink
還是在嘗試解決有時候抓完整本是空的的問題
Browse files Browse the repository at this point in the history
  • Loading branch information
DaidoujiChen committed Dec 9, 2014
1 parent 6896bbf commit 9cb4c2e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 48 deletions.
10 changes: 2 additions & 8 deletions e-Hentai.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -925,10 +925,7 @@
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/e-Hentai/ThirdParty/GooglePlus",
);
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "e-Hentai/e-Hentai-Prefix.pch";
HEADER_SEARCH_PATHS = (
Expand All @@ -954,10 +951,7 @@
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/e-Hentai/ThirdParty/GooglePlus",
);
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "e-Hentai/e-Hentai-Prefix.pch";
HEADER_SEARCH_PATHS = (
Expand Down
10 changes: 5 additions & 5 deletions e-Hentai/HentaiDownloadCenter/HentaiDownloadBookOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ - (void)checkEndOfFile {

//如果 cache 有暫存就殺光光
[[[FilesManager cacheFolder] fcd:@"Hentai"] rd:self.hentaiKey];
LWPSafe(
[HentaiSaveLibraryArray insertObject:saveInfo atIndex:0];
[HentaiCacheLibraryDictionary removeObjectForKey:self.hentaiKey];
LWPForceWrite();
)
[LightWeightPlist lwpSafe:^{
[HentaiSaveLibraryArray insertObject:saveInfo atIndex:0];
[HentaiCacheLibraryDictionary removeObjectForKey:self.hentaiKey];
LWPForceWrite();
}];
[[self portal:HentaiDownloadSuccessNotification] send:[DaiPortalPackage item:self.hentaiInfo[@"title"]]];
[self hentaiFinish];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
[searchBar resignFirstResponder];
if (self.delegate) {
LWPSafe(
HentaiPrefer[@"searchText"] = self.searchBar.text;
LWPForceWrite();
);
[LightWeightPlist lwpSafe:^{
HentaiPrefer[@"searchText"] = self.searchBar.text;
LWPForceWrite();
}];
[self.delegate onSearchFilterDone];
}
[self dismissViewControllerAnimated:YES completion:nil];
Expand Down
42 changes: 21 additions & 21 deletions e-Hentai/PhotoViewController/PhotoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ - (void)saveAction {

- (void)deleteAction {
[[FilesManager documentFolder] rd:self.hentaiKey];
LWPSafe(
[HentaiSaveLibraryArray removeObjectAtIndex:self.downloadKey];
LWPForceWrite();
)
[LightWeightPlist lwpSafe:^{
[HentaiSaveLibraryArray removeObjectAtIndex:self.downloadKey];
LWPForceWrite();
}];
[self backAction];
}

Expand Down Expand Up @@ -142,10 +142,10 @@ - (void)setupInitValues {
}
else {
self.hentaiResults = [NSMutableDictionary dictionary];
LWPSafe(
[HentaiCacheLibraryDictionary removeObjectForKey:self.hentaiKey];
LWPForceWrite();
)
[LightWeightPlist lwpSafe:^{
[HentaiCacheLibraryDictionary removeObjectForKey:self.hentaiKey];
LWPForceWrite();
}];
}
}
else {
Expand Down Expand Up @@ -240,10 +240,10 @@ - (void)checkEndOfFile {
FMStream *saveFolder = [[FilesManager documentFolder] fcd:@"Hentai"];
[self.hentaiFilesManager moveToPath:[saveFolder.currentPath stringByAppendingPathComponent:self.hentaiKey]];
NSDictionary *saveInfo = @{ @"hentaiKey":self.hentaiKey, @"images":self.hentaiImageURLs, @"hentaiResult":self.hentaiResults, @"hentaiInfo":self.hentaiInfo };
LWPSafe(
[HentaiSaveLibraryArray insertObject:saveInfo atIndex:0];
LWPForceWrite();
)
[LightWeightPlist lwpSafe:^{
[HentaiSaveLibraryArray insertObject:saveInfo atIndex:0];
LWPForceWrite();
}];
self.downloadKey = [HentaiSaveLibraryArray indexOfObject:saveInfo];
[self setupForAlreadyDownloadKey:self.downloadKey];
[DaiInboxHUD hide];
Expand Down Expand Up @@ -442,15 +442,15 @@ - (void)viewWillDisappear:(BOOL)animated {
//結束時把 queue 清掉, 並且記錄目前已下載的東西有哪些
[self.hentaiQueue cancelAllOperations];

LWPSafe(
if (self.downloadKey != NSNotFound) {
[HentaiCacheLibraryDictionary removeObjectForKey:self.hentaiKey];
}
else {
HentaiCacheLibraryDictionary[self.hentaiKey] = self.hentaiResults;
}
LWPForceWrite();
)
[LightWeightPlist lwpSafe:^{
if (self.downloadKey != NSNotFound) {
[HentaiCacheLibraryDictionary removeObjectForKey:self.hentaiKey];
}
else {
HentaiCacheLibraryDictionary[self.hentaiKey] = self.hentaiResults;
}
LWPForceWrite();
}];
}

@end
8 changes: 4 additions & 4 deletions e-Hentai/SettingViewController/SettingViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ @implementation SettingViewController

- (IBAction)cleanCacheAction:(id)sender {
[[FilesManager cacheFolder] rd:@"Hentai"];
LWPSafe(
[HentaiCacheLibraryDictionary removeAllObjects];
LWPForceWrite();
)
[LightWeightPlist lwpSafe:^{
[HentaiCacheLibraryDictionary removeAllObjects];
LWPForceWrite();
}];
[self cacheFolderSize];
}

Expand Down
6 changes: 1 addition & 5 deletions e-Hentai/ThirdParty/LightWeightPlist/LightWeightPlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@
#define LWPDelete(fmt) [LightWeightPlist lwpDelete:fmt]
#define LWPForceWrite() [LightWeightPlist lwpForceWrite]

#define LWPSafe(fmt) \
@synchronized([LightWeightPlist class]) { \
fmt; \
}

@interface LightWeightPlist : NSObject

#pragma mark - Common

+ (void)lwpDelete:(NSString *)key;
+ (void)lwpForceWrite;
+ (void)lwpSafe:(void (^)(void))safeBlock;

#pragma mark - Array

Expand Down
11 changes: 10 additions & 1 deletion e-Hentai/ThirdParty/LightWeightPlist/LightWeightPlist.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ + (void)lwpForceWrite
[lwpCache removeAllObjects];
}

+ (void)lwpSafe:(void (^)(void))safeBlock
{
if ([NSThread isMainThread]) {
safeBlock();
} else {
dispatch_async(dispatch_get_main_queue(), safeBlock);
}
}

#pragma mark - array

+ (NSMutableArray *)lwpArray:(NSString *)key
Expand Down Expand Up @@ -90,4 +99,4 @@ + (NSMutableDictionary *)lwpDictionaryFromResource:(NSString *)key
return [self objectFromCache:key];
}

@end
@end

0 comments on commit 9cb4c2e

Please sign in to comment.