あれとこれのコンバータ
Revision | a7f51e709eba8a0b8a3e641f0cc4006225a796c7 (tree) |
---|---|
Zeit | 2011-12-01 23:58:14 |
Autor | masakih <masakih@user...> |
Commiter | masakih |
色々変更。
@@ -9,9 +9,13 @@ | ||
9 | 9 | #import <Cocoa/Cocoa.h> |
10 | 10 | |
11 | 11 | @class BSCoreDataManager; |
12 | +@class BSCDProgressPanelController; | |
12 | 13 | |
13 | 14 | @interface BSDCAppDelegate : NSObject <NSApplicationDelegate> |
14 | 15 | |
16 | +@property (retain) BSCDProgressPanelController *panel; | |
17 | +@property NSModalSession session; | |
18 | +@property (retain) NSDate *startTime; | |
15 | 19 | @property (retain) BSCoreDataManager *cdManager; |
16 | 20 | @property (assign) IBOutlet NSWindow *window; |
17 | 21 |
@@ -9,6 +9,7 @@ | ||
9 | 9 | #import "BSDCAppDelegate.h" |
10 | 10 | |
11 | 11 | #import "BSCoreDataManager.h" |
12 | +#import "SQLiteDB.h" | |
12 | 13 | #import "DatabaseManager.h" |
13 | 14 | #import "BSCDProgressPanelController.h" |
14 | 15 |
@@ -19,6 +20,9 @@ | ||
19 | 20 | |
20 | 21 | @implementation BSDCAppDelegate |
21 | 22 | |
23 | +@synthesize panel; | |
24 | +@synthesize session; | |
25 | +@synthesize startTime; | |
22 | 26 | @synthesize window = _window; |
23 | 27 | @synthesize cdManager; |
24 | 28 |
@@ -65,37 +69,32 @@ | ||
65 | 69 | return bathyscapheSupportFolderPath; |
66 | 70 | } |
67 | 71 | |
68 | -- (void)setTimeToPanel:(BSCDProgressPanelController *)panel since:(NSDate *)date | |
72 | +- (void)updateTime | |
69 | 73 | { |
70 | 74 | NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0.0]; |
71 | - panel.progressTime = [NSDate dateWithTimeIntervalSince1970:[now timeIntervalSinceDate:date] - [[NSTimeZone systemTimeZone] secondsFromGMT]]; | |
75 | + panel.progressTime = [NSDate dateWithTimeIntervalSince1970:[now timeIntervalSinceDate:startTime] - [[NSTimeZone systemTimeZone] secondsFromGMT]]; | |
72 | 76 | } |
73 | -- (IBAction)convertToSQLite:(id)sender | |
77 | +- (SQLiteReservedQuery *)sqlForInsertion | |
74 | 78 | { |
75 | - NSDate *startTime = [NSDate dateWithTimeIntervalSinceNow:0.0]; | |
76 | - | |
77 | - BSCDProgressPanelController *panel = [[BSCDProgressPanelController alloc] init]; | |
78 | - [self setTimeToPanel:panel since:startTime]; | |
79 | - panel.label = @"Convert from CoreData to SQLite data"; | |
80 | - panel.message = @"Converting data ..."; | |
79 | + static SQLiteReservedQuery *query = nil; | |
81 | 80 | |
82 | - NSModalSession session = [NSApp beginModalSessionForWindow:panel.window]; | |
83 | - | |
84 | - if( ([NSApp runModalSession:session] != NSRunContinuesResponse) ) goto finish; | |
85 | - | |
86 | - BSCoreDataManager *cdm = [BSCoreDataManager defaultManager]; | |
87 | - NSArray *boards = [cdm fetchDataForEntityName:@"BoardInformation" predicate:nil]; | |
88 | - [self setTimeToPanel:panel since:startTime]; | |
81 | + if(query) return query; | |
89 | 82 | |
83 | + NSString *sql = [NSString stringWithFormat:@"INSERT INTO %@ ( %@, %@, %@, %@, %@, %@, %@, %@ ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?)", | |
84 | + ThreadInfoTableName, | |
85 | + BoardIDColumn, ThreadIDColumn, ThreadNameColumn, NumberOfAllColumn, NumberOfReadColumn, ModifiedDateColumn, ThreadStatusColumn, | |
86 | + IsDatOchiColumn]; | |
87 | + query = [[SQLiteReservedQuery alloc] initWithQuery:sql usingSQLiteDB:[[DatabaseManager defaultManager] databaseForCurrentThread]]; | |
88 | + return query; | |
89 | +} | |
90 | +- (void)convertBoards:(NSArray *)boards | |
91 | +{ | |
90 | 92 | DatabaseManager *dm = [DatabaseManager defaultManager]; |
91 | - [self setTimeToPanel:panel since:startTime]; | |
92 | - | |
93 | - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
94 | - panel.message = @"Converting board informations ..."; | |
93 | + panel.message = @"Converting board informations ..."; | |
95 | 94 | panel.amount = [boards count]; |
96 | 95 | for(BSBoardInformationObject *board in boards) { |
97 | - [self setTimeToPanel:panel since:startTime]; | |
98 | - if( ([NSApp runModalSession:session] != NSRunContinuesResponse) ) goto finish; | |
96 | + [self updateTime]; | |
97 | + if( ([NSApp runModalSession:session] != NSRunContinuesResponse) ) return; | |
99 | 98 | |
100 | 99 | panel.count++; |
101 | 100 | if(NSNotFound != [dm boardIDForURLString:board.boardURL]) { |
@@ -105,58 +104,100 @@ | ||
105 | 104 | |
106 | 105 | [dm registerBoardName:board.boardName URLString:board.boardURL]; |
107 | 106 | } |
108 | - panel.amount = 0; | |
109 | - panel.count = 0; | |
110 | - [pool release]; | |
111 | - [self setTimeToPanel:panel since:startTime]; | |
112 | - | |
113 | - panel.message = @"Converting board histories ..."; | |
114 | - | |
115 | - | |
116 | - [self setTimeToPanel:panel since:startTime]; | |
117 | - pool = [[NSAutoreleasePool alloc] init]; | |
118 | - panel.message = @"Converting thread informations ..."; | |
107 | +} | |
108 | + | |
109 | +- (void)convertThreadsInBoards:(NSArray *)boards | |
110 | +{ | |
111 | + DatabaseManager *dm = [DatabaseManager defaultManager]; | |
112 | + panel.message = @"Converting thread informations ..."; | |
119 | 113 | for(BSBoardInformationObject *board in boards) { |
120 | - [self setTimeToPanel:panel since:startTime]; | |
121 | - if( ([NSApp runModalSession:session] != NSRunContinuesResponse) ) goto finish; | |
122 | - | |
114 | + [self updateTime]; | |
123 | 115 | NSUInteger boardID = [dm boardIDForURLString:board.boardURL]; |
124 | 116 | NSSet *threads = board.threads; |
125 | 117 | panel.amount = [threads count]; |
126 | 118 | for(BSThreadInformationObject *thread in threads) { |
119 | + if( ([NSApp runModalSession:session] != NSRunContinuesResponse) ) return; | |
120 | + | |
127 | 121 | NSAutoreleasePool *pool2 = [[NSAutoreleasePool alloc] init]; |
128 | - [self setTimeToPanel:panel since:startTime]; | |
122 | + [self updateTime]; | |
129 | 123 | panel.count++; |
130 | 124 | panel.message = [NSString stringWithFormat:@"Converting thread informations ...\n%@", board.boardName]; |
131 | 125 | |
132 | 126 | if( ([NSApp runModalSession:session] != NSRunContinuesResponse) ) { |
133 | 127 | [pool2 release]; |
134 | - goto finish; | |
128 | + return; | |
135 | 129 | } |
136 | 130 | |
137 | - [dm insertThreadOfIdentifier:thread.threadID | |
138 | - title:thread.threadName | |
139 | - count:[thread.numberOfAll integerValue] | |
140 | - date:thread.modifiedDate | |
141 | - isDatOchi:[thread.isDatOchi boolValue] | |
142 | - atBoard:boardID]; | |
131 | +// NSString *sql = [NSString stringWithFormat:@"INSERT INTO %@ ( %@, %@, %@, %@, %@, %@, %@, %@ ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?)", | |
132 | +// ThreadInfoTableName, | |
133 | +// BoardIDColumn, ThreadIDColumn, ThreadNameColumn, NumberOfAllColumn, NumberOfReadColumn, ModifiedDateColumn, ThreadStatusColumn, | |
134 | +// IsDatOchiColumn]; | |
135 | + | |
136 | + SQLiteReservedQuery *sqlForInsertion = [self sqlForInsertion]; | |
137 | + [sqlForInsertion cursorWithFormat: | |
138 | + F_Int F_NSString F_NSString F_NSNumberOfInt F_NSNumberOfInt F_NSNumberOfDouble F_NSNumberOfInt F_NSNumberOfInt, | |
139 | + boardID, thread.threadID, | |
140 | + thread.threadName, thread.numberOfAll, thread.numberOfRead, | |
141 | + thread.modifiedDate ? [NSNumber numberWithDouble:[thread.modifiedDate timeIntervalSince1970]] : nil, | |
142 | + thread.threadStatus, | |
143 | + thread.isDatOchi]; | |
144 | + | |
143 | 145 | if(thread.lastWrittenDate) { |
144 | 146 | [dm setLastWriteDate:thread.lastWrittenDate |
145 | 147 | atBoardID:boardID |
146 | 148 | threadIdentifier:thread.threadID]; |
147 | 149 | } |
148 | - | |
149 | - // number of read | |
150 | - | |
150 | + | |
151 | 151 | // label |
152 | + if(thread.threadLabel) { | |
153 | + [dm setLabel:[thread.threadLabel integerValue] | |
154 | + boardName:board.boardName | |
155 | + threadIdentifier:thread.threadID]; | |
156 | + } | |
152 | 157 | |
153 | 158 | [pool2 release]; |
154 | 159 | } |
155 | 160 | panel.amount = 0; |
156 | 161 | panel.count = 0; |
157 | 162 | } |
163 | +} | |
164 | + | |
165 | +- (void)doConvertToSQLite | |
166 | +{ | |
167 | + self.startTime = [NSDate dateWithTimeIntervalSinceNow:0.0]; | |
168 | + self.panel = [[[BSCDProgressPanelController alloc] init] autorelease]; | |
169 | + | |
170 | + [self updateTime]; | |
171 | + panel.label = @"Convert from CoreData to SQLite data"; | |
172 | + panel.message = @"Converting data ..."; | |
173 | + | |
174 | + self.session = [NSApp beginModalSessionForWindow:panel.window]; | |
175 | + | |
176 | + if( ([NSApp runModalSession:session] != NSRunContinuesResponse) ) goto finish; | |
177 | + | |
178 | + BSCoreDataManager *cdm = [BSCoreDataManager defaultManager]; | |
179 | + NSArray *boards = [cdm fetchDataForEntityName:@"BoardInformation" predicate:nil]; | |
180 | + [self updateTime]; | |
181 | + | |
182 | + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
183 | + [self convertBoards:boards]; | |
184 | + panel.amount = 0; | |
185 | + panel.count = 0; | |
186 | + [pool release]; | |
187 | + [self updateTime]; | |
158 | 188 | |
189 | + panel.message = @"Converting board histories ..."; | |
190 | + // | |
159 | 191 | |
192 | + [self updateTime]; | |
193 | + pool = [[NSAutoreleasePool alloc] init]; | |
194 | + [self convertThreadsInBoards:boards]; | |
195 | + panel.amount = 0; | |
196 | + panel.count = 0; | |
197 | + [pool release]; | |
198 | + [self updateTime]; | |
199 | + | |
200 | + panel.message = @"Converting Favorites ..."; | |
160 | 201 | // Fav |
161 | 202 | |
162 | 203 | finish: |
@@ -164,6 +205,15 @@ finish: | ||
164 | 205 | [NSApp endModalSession:session]; |
165 | 206 | [panel.window close]; |
166 | 207 | [panel release]; |
208 | + | |
209 | + NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0.0]; | |
210 | + NSLog(@"Finish %@", [NSDate dateWithTimeIntervalSince1970:[now timeIntervalSinceDate:startTime] - [[NSTimeZone systemTimeZone] secondsFromGMT]]); | |
211 | +} | |
212 | +- (IBAction)convertToSQLite:(id)sender | |
213 | +{ | |
214 | + SQLiteDB *db = [[DatabaseManager defaultManager] databaseForCurrentThread]; | |
215 | + [db beginTransaction]; | |
216 | + [self doConvertToSQLite]; | |
217 | + [db commitTransaction]; | |
167 | 218 | } |
168 | - | |
169 | 219 | @end |