2011-07-21 12 views
1

ユーザーが初めて自分のアプリケーションを使用するときは、バンドルから設定ファイルをいくつかのフォルダにコピーする必要があります。ユーザーはこのファイルを操作することができます。ファイルを壊してしまった場合は、単に「復元」を押してファイルを削除し、バンドルから再度コピーします。iOS:アプリケーションの起動時にバンドルからファイルをコピーする

- (void) resetPresets 
{ 
    LOG_(@"Copying tunings file from original..."); 

    // copy default tunings -> curr tunings file 

    NSString* appSupportDir = [NSFileManager appSupportDir]; 
    NSString* tuningsPath = [appSupportDir stringByAppendingPathComponent: @"tunings.txt"]; 

    NSBundle* bundle = [NSBundle mainBundle]; 
    NSString* origTuningsPath = [bundle pathForResource: @"tuningsOriginal" 
               ofType: @"txt" ]; 


    NSFileManager* fileManager = [NSFileManager defaultManager]; 
    NSError* error = nil; 

    if([fileManager fileExistsAtPath: tuningsPath]) 
    { 
     [fileManager removeItemAtPath: tuningsPath 
           error: & error ]; 
     if(error) 
      LOG(@"\n ERROR: %@ \n %@ \n", [error userInfo], [error localizedFailureReason]); 
    } 


    assert([fileManager fileExistsAtPath: origTuningsPath]); 

    [fileManager copyItemAtPath: origTuningsPath 
         toPath: tuningsPath 
          error: & error ]; 

    if(error) 
     LOG(@"\n ERROR: %@ \n %@ \n", [error userInfo], [error localizedFailureReason]); 


    LOG(@"done!"); 


    // load profiles from it 
    [self loadProfilesFromFile: tuningsPath ]; 

    // auto-sets active preset index to 0 & saves prefs 
    self.activeThemeIndex = 0; 
} 

簡単なカテゴリに依存しています:

[fileManager copyItemAtPath: origTuningsPath 
         toPath: tuningsPath 
          error: & error ]; 

、これはコンソール出力です:

#import "NSFileManager+addons.h" 


@implementation NSFileManager (NSFileManager_addons) 

+ (NSString *) appSupportDir 
{ 

    NSArray* paths = NSSearchPathForDirectoriesInDomains(
                 NSApplicationSupportDirectory, 
                 NSUserDomainMask, 
                 YES 
                 ); 

    NSString* appSupportDir = [paths objectAtIndex: 0]; 

    return appSupportDir; 
} 

@end 

これが問題を引き起こしてラインである

[presets init] Presets -> first run! Setting up with default presets Copying tunings file from original... ERROR: { NSDestinationFilePath = "/var/mobile/Applications/38FC3C65-74AF-4892-B48D-A3508A8CF404/Library/Application Support/tunings.txt"; NSFilePath = "/var/mobile/Applications/38FC3C65-74AF-4892-B48D-A3508A8CF404/Fork.app/tuningsOriginal.txt"; NSUserStringVariant = Copy; } No such file or directory

なぜそれはsuがないと不平を言うのですか? chファイルまたはディレクトリ?明らかに、そのようなファイルは存在してはいけません。ファイルを新しい場所にコピーすると、そこにファイルがあるとは思わないでしょう。

だから私はそれがディレクトリについて不平を言っていると思う。しかし、私はかなり標準的な方法を使用してディレクトリを釣り上げました。何が起こっている?これは正しいディレクトリではありませんか?それとも別のことをやっているのですか?

答えて

関連する問題