copy - iOS: Copying file from bundle on application start-up -


when user first uses application, should copy configuration file bundle folder. user can fiddle file, , if mess can press ' restore ' delete file , copy again bundle.

- (void) resetpresets {     log_( @"copying tunings file 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     [self loadprofilesfromfile: tuningspath ];      // auto-sets active preset index 0 & saves prefs     self.activethemeindex = 0; } 

relies on simple category:

#import "nsfilemanager+addons.h"   @implementation nsfilemanager ( nsfilemanager_addons )  + (nsstring *) appsupportdir {      nsarray* paths = nssearchpathfordirectoriesindomains(                                                          nsapplicationsupportdirectory,                                                          nsuserdomainmask,                                                           yes                                                          );      nsstring* appsupportdir = [paths objectatindex: 0];      return appsupportdir; }  @end 

this line causing problem:

    [filemanager copyitematpath: origtuningspath                          topath: tuningspath                           error: & error ]; 

and console output:

[presets init] presets -> first run! setting default presets copying tunings file 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

why complaining there no such file or directory? there should not such file existing. when copy file new location don't expect file there.

so guess complaining directory. have fished directory out using standard method. going on? not right directory using? or doing else wrong?

the directories returned nssearchpathfordirectoriesindomains not guaranteed exist; need create them yourself, if necessary (see the documentation). nsfilemanager's createdirectoryatpath:withintermediatedirectories:attributes:error: can that.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -