Advertisement
Guest User

Untitled

a guest
Dec 7th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //- (void)applicationDidFinishLaunching:(UIApplication *)application
  2. //{
  3. //  // Override point for customization after app launch
  4. //  [window setRootViewController:viewController];
  5. //  [window makeKeyAndVisible];
  6. //}
  7. //
  8. //
  9. //
  10. //
  11. //@end
  12.  
  13. #pragma mark
  14. #pragma mark
  15.  
  16. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  17.    
  18.  
  19.     NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
  20.     [NSURLCache setSharedURLCache:sharedCache];
  21.     [sharedCache release];
  22.     sharedCache = nil;
  23.    
  24.     NSArray* keys =
  25.     [[NSBundle mainBundle] URLsForResourcesWithExtension:@"key"
  26.                                             subdirectory:nil];
  27.     for (NSURL* url in keys) {
  28.         NSString* filename = url.pathComponents.lastObject;
  29.         NSString* name = [filename stringByDeletingPathExtension];
  30.         NSError* error;
  31.         if (![self copyKeyFile:name error:&error]) {
  32.             NSLog(@"%@", error);
  33.         }
  34.     }
  35.  
  36.     [window setRootViewController:viewController];
  37.     [window makeKeyAndVisible];
  38.    
  39.     return YES;
  40. }
  41.  
  42. -(BOOL)copyKeyFile:(NSString*)name error:(NSError**)error {
  43.     NSURL* documentsPath =
  44.     [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
  45.                                            inDomains:NSUserDomainMask].firstObject;
  46.     NSString* filePath = [NSString stringWithFormat:@"cprocsp/keys/test.000/%@.key", name];
  47.     NSString* headerDst = [documentsPath.path stringByAppendingPathComponent:filePath];
  48.    
  49.     NSString* dirPath = [documentsPath.path stringByAppendingPathComponent:@"cprocsp/keys/test.000"];
  50.    
  51.     if(![[NSFileManager defaultManager] createDirectoryAtPath:dirPath
  52.                                   withIntermediateDirectories:YES
  53.                                                    attributes:nil
  54.                                                         error:error]) {
  55.         NSLog(@"Error: Create folder failed %@: %@", dirPath, *error);
  56.         return NO;
  57.     }
  58.    
  59.     NSString* headerSrc =
  60.     [[NSBundle mainBundle] pathForResource:name
  61.                                     ofType:@"key"];
  62.    
  63.     [[NSFileManager defaultManager] removeItemAtPath:headerDst
  64.                                                error:nil];
  65.    
  66.     return [[NSFileManager defaultManager] copyItemAtPath:headerSrc
  67.                                                    toPath:headerDst
  68.                                                     error:error];
  69.    
  70. }
  71.  
  72. #pragma mark
  73. #pragma mark
  74.  
  75. - (void)dealloc {
  76.     [viewController release];
  77.     [window release];
  78.     [super dealloc];
  79. }
  80.  
  81. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement