Created
May 2, 2009 07:44
-
-
Save haoyayoi/105457 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SqliteInitialize.h | |
// | |
// Created by haoyayoi on 09/05/02. | |
// Copyright 2009 haoyayoi. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface SqliteInitialize : NSObject { | |
} | |
+ (SqliteInitialize *)setup; | |
+ (NSString *)writebleDBPath:(NSString *)sqlname; | |
- (BOOL)copyDB:(NSString *)sqlname; | |
@end | |
@implementation SqliteInitialize | |
+ (SqliteInitialize *)setup { | |
return [[[SqliteInitialize alloc] init] autorelease]; | |
} | |
+ (NSString *)writebleDBPath:(NSString *)sqlname { | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString *documentsDirectory = [paths objectAtIndex:0]; | |
return [documentsDirectory stringByAppendingPathComponent:sqlname]; | |
} | |
- (BOOL)copyDB:(NSString *)sqlname { | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
NSError *error; | |
NSString *writableDBPath = [SqliteInitialize writebleDBPath]; | |
BOOL success = [fileManager fileExistsAtPath:writableDBPath]; | |
if(!success){ | |
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:sqlname]; | |
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error]; | |
} | |
return success; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment