3 |
// BathyScaphe |
// BathyScaphe |
4 |
// |
// |
5 |
// Created by Hori,Masaki on 06/08/13. |
// Created by Hori,Masaki on 06/08/13. |
6 |
// Copyright 2006-2010 BathyScaphe Project. All rights reserved. |
// Copyright 2006-2010,2012 BathyScaphe Project. All rights reserved. |
7 |
// encoding="UTF-8" |
// encoding="UTF-8" |
8 |
// |
// |
9 |
|
|
22 |
static NSURL *datURLForBoardIDStringAndThreadID(NSString *boardIDString, NSString *threadID); |
static NSURL *datURLForBoardIDStringAndThreadID(NSString *boardIDString, NSString *threadID); |
23 |
static BOOL shouldCheckItemHeader(id dict); |
static BOOL shouldCheckItemHeader(id dict); |
24 |
|
|
25 |
@interface BSBoardListItemHEADCheckTask(Private) |
@interface BSBoardListItemHEADCheckTask () |
26 |
|
@property (copy) NSString *amountString; |
27 |
|
@property (copy) NSString *descString; |
28 |
|
|
29 |
- (NSArray *)threadInfomations; |
- (NSArray *)threadInfomations; |
30 |
- (BSDownloadTask *)sendHEADMethod:(NSURL *)url; |
- (BSDownloadTask *)sendHEADMethod:(NSURL *)url; |
31 |
- (void)resetNewStatus; |
- (void)resetNewStatus; |
33 |
@end |
@end |
34 |
|
|
35 |
@implementation BSBoardListItemHEADCheckTask |
@implementation BSBoardListItemHEADCheckTask |
36 |
|
@synthesize amountString; |
37 |
|
@synthesize descString; |
38 |
|
|
39 |
+ (id)taskWithThreadList:(BSDBThreadList *)list |
+ (id)taskWithThreadList:(BSDBThreadList *)list |
40 |
{ |
{ |
41 |
return [[[self alloc] initWithThreadList:list] autorelease]; |
return [[[self alloc] initWithThreadList:list] autorelease]; |
44 |
- (id)initWithThreadList:(BSDBThreadList *)list |
- (id)initWithThreadList:(BSDBThreadList *)list |
45 |
{ |
{ |
46 |
if (self = [super init]) { |
if (self = [super init]) { |
47 |
targetList = list; //[list retain]; |
targetList = list; |
48 |
item = [[list boardListItem] retain]; |
item = [[list boardListItem] retain]; |
49 |
} |
} |
50 |
|
|
53 |
|
|
54 |
- (void)dealloc |
- (void)dealloc |
55 |
{ |
{ |
|
// [targetList release]; |
|
56 |
[item release]; |
[item release]; |
57 |
[amountString release]; |
[amountString release]; |
58 |
[descString release]; |
[descString release]; |
61 |
} |
} |
62 |
|
|
63 |
#pragma mark - |
#pragma mark - |
64 |
- (id)identifier |
+ (NSSet *)keyPathsForValuesAffectingMessage |
65 |
{ |
{ |
66 |
return [NSString stringWithFormat:@"%@-%p", self, self]; |
return [NSSet setWithObjects:@"amountString", @"descString", nil]; |
67 |
} |
} |
|
|
|
68 |
- (NSString *)title |
- (NSString *)title |
69 |
{ |
{ |
70 |
NSString *format = NSLocalizedStringFromTable(@"Checking SmartBoard(%@).", @"ThreadsList", @""); |
NSString *format = NSLocalizedStringFromTable(@"Checking SmartBoard(%@).", @"ThreadsList", @""); |
71 |
return [NSString stringWithFormat:format, [item name]]; |
return [NSString stringWithFormat:format, [item name]]; |
72 |
} |
} |
73 |
|
|
|
- (void)setAmountString:(NSString *)str |
|
|
{ |
|
|
id temp = amountString; |
|
|
@synchronized(self) { |
|
|
[self willChangeValueForKey:@"message"]; |
|
|
amountString = [str retain]; |
|
|
[self didChangeValueForKey:@"message"]; |
|
|
} |
|
|
[temp release]; |
|
|
} |
|
|
|
|
|
- (NSString *)amountString |
|
|
{ |
|
|
id result; |
|
|
@synchronized(self) { |
|
|
result = [[amountString retain] autorelease]; |
|
|
} |
|
|
return result; |
|
|
} |
|
|
|
|
|
- (void)setDescString:(NSString *)str |
|
|
{ |
|
|
id temp = descString; |
|
|
@synchronized(self) { |
|
|
[self willChangeValueForKey:@"message"]; |
|
|
descString = [str retain]; |
|
|
[self didChangeValueForKey:@"message"]; |
|
|
} |
|
|
[temp release]; |
|
|
} |
|
|
|
|
|
- (NSString *)descString |
|
|
{ |
|
|
id result; |
|
|
@synchronized(self) { |
|
|
result = [[descString retain] autorelease]; |
|
|
} |
|
|
return result; |
|
|
} |
|
|
|
|
74 |
- (NSString *)message |
- (NSString *)message |
75 |
{ |
{ |
76 |
NSString *descStr = [self descString]; |
NSString *descStr = self.descString; |
77 |
NSString *amountStr = [self amountString]; |
NSString *amountStr = self.amountString; |
78 |
|
|
79 |
if (descStr && amountStr) { |
if (descStr && amountStr) { |
80 |
return [NSString stringWithFormat:@"%@ (%@)", descStr, amountStr]; |
return [NSString stringWithFormat:@"%@ (%@)", descStr, amountStr]; |
100 |
[finishedSound_ play]; |
[finishedSound_ play]; |
101 |
} |
} |
102 |
|
|
103 |
- (void)doExecuteWithLayout:(CMRThreadLayout *)layout |
- (void)excute |
104 |
{ |
{ |
105 |
[self resetNewStatus]; |
[self resetNewStatus]; |
106 |
|
|
107 |
NSArray *threads = [self threadInfomations]; |
NSArray *threads = [self threadInfomations]; |
|
// NSEnumerator *threadsEnum; |
|
|
// id thread; |
|
108 |
NSMutableArray *updatedThreads = [NSMutableArray array]; |
NSMutableArray *updatedThreads = [NSMutableArray array]; |
109 |
|
|
110 |
// [self checkHOGE]; |
// [self checkHOGE]; |
115 |
NSInteger numberOfChecked = 0; // HEAD を送信した回数 |
NSInteger numberOfChecked = 0; // HEAD を送信した回数 |
116 |
NSString *amoutFormat = NSLocalizedStringFromTable(@"%ld/%ld (%ld skiped)", @"ThreadsList", @""); |
NSString *amoutFormat = NSLocalizedStringFromTable(@"%ld/%ld (%ld skiped)", @"ThreadsList", @""); |
117 |
|
|
118 |
[self setAmountString:[NSString stringWithFormat:amoutFormat, |
self.amountString = [NSString stringWithFormat:amoutFormat, |
119 |
(long)numberOfFinishCheck, (long)numberOfAllTarget, (long)numberOfSkip]]; |
(long)numberOfFinishCheck, (long)numberOfAllTarget, (long)numberOfSkip]; |
120 |
[self setDescString:NSLocalizedStringFromTable(@"Checking thread", @"ThreadsList", @"")]; |
self.descString = NSLocalizedStringFromTable(@"Checking thread", @"ThreadsList", @""); |
121 |
|
|
|
// threadsEnum = [threads objectEnumerator]; |
|
|
// while(thread = [threadsEnum nextObject]) { |
|
122 |
for (id thread in threads) { |
for (id thread in threads) { |
123 |
|
if(self.isInterrupted) return; |
124 |
|
|
125 |
id pool = [[NSAutoreleasePool alloc] init]; |
id pool = [[NSAutoreleasePool alloc] init]; |
126 |
|
|
127 |
id dl; |
id dl; |
128 |
id response; |
id response; |
129 |
id newMod; |
id newMod; |
130 |
|
|
131 |
[self checkIsInterrupted]; |
self.amountString = [NSString stringWithFormat:amoutFormat, |
132 |
[self setAmountString:[NSString stringWithFormat:amoutFormat, |
++numberOfFinishCheck, numberOfAllTarget, numberOfSkip]; |
|
++numberOfFinishCheck, numberOfAllTarget, numberOfSkip]]; |
|
133 |
|
|
134 |
if (!shouldCheckItemHeader(thread)) { |
if (!shouldCheckItemHeader(thread)) { |
135 |
[pool release]; |
[pool release]; |
137 |
continue; |
continue; |
138 |
} |
} |
139 |
|
|
|
// NSString *boardName = [thread valueForColumn:BoardNameColumn]; |
|
140 |
NSString *threadID = [thread valueForColumn:ThreadIDColumn]; |
NSString *threadID = [thread valueForColumn:ThreadIDColumn]; |
141 |
NSString *modDate = [thread valueForColumn:ModifiedDateColumn]; |
NSString *modDate = [thread valueForColumn:ModifiedDateColumn]; |
142 |
NSString *boardID = [thread valueForColumn:BoardIDColumn]; |
NSString *boardID = [thread valueForColumn:BoardIDColumn]; |
150 |
[checker startChecking]; |
[checker startChecking]; |
151 |
while ([checker isChecking]) { |
while ([checker isChecking]) { |
152 |
id pool2 = [[NSAutoreleasePool alloc] init]; |
id pool2 = [[NSAutoreleasePool alloc] init]; |
153 |
@try { |
[loop runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; |
154 |
[loop runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; |
[pool2 release]; |
|
} |
|
|
@catch(id ex) { |
|
|
// do nothing. |
|
|
@throw; |
|
|
} |
|
|
@finally { |
|
|
[pool2 release]; |
|
|
} |
|
155 |
} |
} |
156 |
if (!(checker.lastError) && checker.isUpdated) { |
if (!(checker.lastError) && checker.isUpdated) { |
157 |
[updatedThreads addObject:thread]; |
[updatedThreads addObject:thread]; |
184 |
[targetList updateCursor]; |
[targetList updateCursor]; |
185 |
|
|
186 |
} |
} |
|
// - (void) finalizeWhenInterrupted; |
|
187 |
|
|
188 |
- (NSArray *)threadInfomations |
- (NSArray *)threadInfomations |
189 |
{ |
{ |
192 |
NSString *table = [item query]; |
NSString *table = [item query]; |
193 |
if (!table) return nil; |
if (!table) return nil; |
194 |
|
|
195 |
[self setDescString:NSLocalizedStringFromTable(@"Collecting infomation of thread", @"ThreadsList", @"")]; |
self.descString = NSLocalizedStringFromTable(@"Collecting infomation of thread", @"ThreadsList", @""); |
196 |
|
|
197 |
db = [[DatabaseManager defaultManager] databaseForCurrentThread]; |
db = [[DatabaseManager defaultManager] databaseForCurrentThread]; |
198 |
|
|
323 |
NSURL *boardURL; |
NSURL *boardURL; |
324 |
CMRHostHandler *handler; |
CMRHostHandler *handler; |
325 |
|
|
|
// boardURL = [[BoardManager defaultManager] URLForBoardName:boardName]; |
|
326 |
boardURL = [NSURL URLWithString:[[DatabaseManager defaultManager] urlStringForBoardID:[boardIDString unsignedIntegerValue]]]; |
boardURL = [NSURL URLWithString:[[DatabaseManager defaultManager] urlStringForBoardID:[boardIDString unsignedIntegerValue]]]; |
327 |
handler = [CMRHostHandler hostHandlerForURL:boardURL]; |
handler = [CMRHostHandler hostHandlerForURL:boardURL]; |
328 |
|
|
332 |
- (BSDownloadTask *)sendHEADMethod:(NSURL *)url |
- (BSDownloadTask *)sendHEADMethod:(NSURL *)url |
333 |
{ |
{ |
334 |
BSDownloadTask *dlTask = [[BSDownloadTask alloc] initWithURL:url method:@"HEAD"]; |
BSDownloadTask *dlTask = [[BSDownloadTask alloc] initWithURL:url method:@"HEAD"]; |
335 |
[dlTask doExecuteWithLayout:nil]; |
[dlTask synchronousDownLoad]; |
336 |
|
|
337 |
return [dlTask autorelease]; |
return [dlTask autorelease]; |
338 |
} |
} |
341 |
{ |
{ |
342 |
SQLiteDB *db = [[DatabaseManager defaultManager] databaseForCurrentThread]; |
SQLiteDB *db = [[DatabaseManager defaultManager] databaseForCurrentThread]; |
343 |
|
|
344 |
[self setDescString:NSLocalizedStringFromTable(@"Reseting new threads status.", @"ThreadsList", @"")]; |
self.descString = NSLocalizedStringFromTable(@"Reseting new threads status.", @"ThreadsList", @""); |
345 |
|
|
346 |
if (db && [db beginTransaction]) { |
if (db && [db beginTransaction]) { |
347 |
id cursor = nil; |
id cursor = nil; |
385 |
} |
} |
386 |
NSInteger numberOfAllTarget = [threads count]; |
NSInteger numberOfAllTarget = [threads count]; |
387 |
NSInteger numberOfFinishCheck = 0; |
NSInteger numberOfFinishCheck = 0; |
388 |
[self setAmountString:[NSString stringWithFormat:@"%ld/%ld", (long)numberOfFinishCheck, (long)numberOfAllTarget]]; |
self.amountString = [NSString stringWithFormat:@"%ld/%ld", (long)numberOfFinishCheck, (long)numberOfAllTarget]; |
389 |
[self setDescString:NSLocalizedStringFromTable(@"Updating database", @"ThreadsList", @"")]; |
self.descString = NSLocalizedStringFromTable(@"Updating database", @"ThreadsList", @""); |
390 |
|
|
391 |
SQLiteDB *db = [[DatabaseManager defaultManager] databaseForCurrentThread]; |
SQLiteDB *db = [[DatabaseManager defaultManager] databaseForCurrentThread]; |
392 |
NSString *query = [NSString stringWithFormat: |
NSString *query = [NSString stringWithFormat: |
397 |
ThreadStatusColumn, (long)ThreadHeadModifiedStatus, |
ThreadStatusColumn, (long)ThreadHeadModifiedStatus, |
398 |
BoardIDColumn, ThreadIDColumn]; |
BoardIDColumn, ThreadIDColumn]; |
399 |
if (db && [db beginTransaction]) { |
if (db && [db beginTransaction]) { |
|
// id threadsEnum = [threads objectEnumerator]; |
|
|
// id thread; |
|
|
|
|
400 |
SQLiteReservedQuery *rQuery = [db reservedQuery:query]; |
SQLiteReservedQuery *rQuery = [db reservedQuery:query]; |
401 |
|
|
|
// while(thread = [threadsEnum nextObject]) { |
|
402 |
for (id thread in threads) { |
for (id thread in threads) { |
403 |
[self checkIsInterrupted]; |
if(self.isInterrupted) goto abort; |
404 |
[self setAmountString:[NSString stringWithFormat:@"%ld/%ld", (long)++numberOfFinishCheck, (long)numberOfAllTarget]]; |
self.amountString = [NSString stringWithFormat:@"%ld/%ld", (long)++numberOfFinishCheck, (long)numberOfAllTarget]; |
405 |
|
|
406 |
const char *format = F_NSNumberOfInt F_NSString; |
const char *format = F_NSNumberOfInt F_NSString; |
407 |
[rQuery cursorWithFormat:format, [thread valueForColumn:BoardIDColumn], [thread valueForColumn:ThreadIDColumn]]; |
[rQuery cursorWithFormat:format, [thread valueForColumn:BoardIDColumn], [thread valueForColumn:ThreadIDColumn]]; |
409 |
|
|
410 |
[db commitTransaction]; |
[db commitTransaction]; |
411 |
} |
} |
412 |
|
|
413 |
|
abort: |
414 |
|
[db rollbackTransaction]; |
415 |
} |
} |
416 |
@end |
@end |
417 |
|
|