masakih

あれとこれコンバータ (プロジェクト終了)

  • R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamewindowspythonphpguic翻訳omegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

あれとこれのコンバータ


Commit MetaInfo

Révisiona7f51e709eba8a0b8a3e641f0cc4006225a796c7 (tree)
l'heure2011-12-01 23:58:14
Auteurmasakih <masakih@user...>
Commitermasakih

Message de Log

色々変更。

Change Summary

Modification

--- a/BathyScapheDataConverter/BSDCAppDelegate.h
+++ b/BathyScapheDataConverter/BSDCAppDelegate.h
@@ -9,9 +9,13 @@
99 #import <Cocoa/Cocoa.h>
1010
1111 @class BSCoreDataManager;
12+@class BSCDProgressPanelController;
1213
1314 @interface BSDCAppDelegate : NSObject <NSApplicationDelegate>
1415
16+@property (retain) BSCDProgressPanelController *panel;
17+@property NSModalSession session;
18+@property (retain) NSDate *startTime;
1519 @property (retain) BSCoreDataManager *cdManager;
1620 @property (assign) IBOutlet NSWindow *window;
1721
--- a/BathyScapheDataConverter/BSDCAppDelegate.m
+++ b/BathyScapheDataConverter/BSDCAppDelegate.m
@@ -9,6 +9,7 @@
99 #import "BSDCAppDelegate.h"
1010
1111 #import "BSCoreDataManager.h"
12+#import "SQLiteDB.h"
1213 #import "DatabaseManager.h"
1314 #import "BSCDProgressPanelController.h"
1415
@@ -19,6 +20,9 @@
1920
2021 @implementation BSDCAppDelegate
2122
23+@synthesize panel;
24+@synthesize session;
25+@synthesize startTime;
2226 @synthesize window = _window;
2327 @synthesize cdManager;
2428
@@ -65,37 +69,32 @@
6569 return bathyscapheSupportFolderPath;
6670 }
6771
68-- (void)setTimeToPanel:(BSCDProgressPanelController *)panel since:(NSDate *)date
72+- (void)updateTime
6973 {
7074 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]];
7276 }
73-- (IBAction)convertToSQLite:(id)sender
77+- (SQLiteReservedQuery *)sqlForInsertion
7478 {
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;
8180
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;
8982
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+{
9092 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 ...";
9594 panel.amount = [boards count];
9695 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;
9998
10099 panel.count++;
101100 if(NSNotFound != [dm boardIDForURLString:board.boardURL]) {
@@ -105,58 +104,100 @@
105104
106105 [dm registerBoardName:board.boardName URLString:board.boardURL];
107106 }
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 ...";
119113 for(BSBoardInformationObject *board in boards) {
120- [self setTimeToPanel:panel since:startTime];
121- if( ([NSApp runModalSession:session] != NSRunContinuesResponse) ) goto finish;
122-
114+ [self updateTime];
123115 NSUInteger boardID = [dm boardIDForURLString:board.boardURL];
124116 NSSet *threads = board.threads;
125117 panel.amount = [threads count];
126118 for(BSThreadInformationObject *thread in threads) {
119+ if( ([NSApp runModalSession:session] != NSRunContinuesResponse) ) return;
120+
127121 NSAutoreleasePool *pool2 = [[NSAutoreleasePool alloc] init];
128- [self setTimeToPanel:panel since:startTime];
122+ [self updateTime];
129123 panel.count++;
130124 panel.message = [NSString stringWithFormat:@"Converting thread informations ...\n%@", board.boardName];
131125
132126 if( ([NSApp runModalSession:session] != NSRunContinuesResponse) ) {
133127 [pool2 release];
134- goto finish;
128+ return;
135129 }
136130
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+
143145 if(thread.lastWrittenDate) {
144146 [dm setLastWriteDate:thread.lastWrittenDate
145147 atBoardID:boardID
146148 threadIdentifier:thread.threadID];
147149 }
148-
149- // number of read
150-
150+
151151 // label
152+ if(thread.threadLabel) {
153+ [dm setLabel:[thread.threadLabel integerValue]
154+ boardName:board.boardName
155+ threadIdentifier:thread.threadID];
156+ }
152157
153158 [pool2 release];
154159 }
155160 panel.amount = 0;
156161 panel.count = 0;
157162 }
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];
158188
189+ panel.message = @"Converting board histories ...";
190+ //
159191
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 ...";
160201 // Fav
161202
162203 finish:
@@ -164,6 +205,15 @@ finish:
164205 [NSApp endModalSession:session];
165206 [panel.window close];
166207 [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];
167218 }
168-
169219 @end