//
//  iPhlyAppDelegate.m
//  iPhly
//
//  Created by Ari Krupnik on 4/27/10.
//  Copyright lib.aero 2010. All rights reserved.
//

#import "iPhlyAppDelegate.h"
#import "RootViewController.h"
#import "ModelProcessor.h"

@implementation iPhlyAppDelegate

@synthesize window;
@synthesize navigationController;

- (void) createModelsDirAndCopyFilesIfFirstLanuch {
	NSFileManager * fm = [NSFileManager defaultManager];
	NSString * modelsDirS = [ModelProcessor modelsDir];
	if(![fm fileExistsAtPath: modelsDirS]) {
		[fm createDirectoryAtPath: modelsDirS withIntermediateDirectories: YES attributes: nil error: NULL];
		
		for(NSString * bundleFile in [[NSBundle mainBundle] pathsForResourcesOfType: MODEL_CONFIG_FILE_EXTENSION inDirectory: nil]) {
			NSString * fsFile = [modelsDirS stringByAppendingPathComponent: [bundleFile lastPathComponent]];
			[fm copyItemAtPath: bundleFile toPath: fsFile error: NULL];
		}
	}
}


#pragma mark -
#pragma mark Application lifecycle

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
    
    // Override point for customization after app launch    
	
	[self createModelsDirAndCopyFilesIfFirstLanuch];
	
	[window addSubview:[navigationController view]];
    [window makeKeyAndVisible];
}


- (void)applicationWillTerminate:(UIApplication *)application {
	// Save data if appropriate
}


#pragma mark -
#pragma mark Memory management

- (void)dealloc {
	[navigationController release];
	[window release];
	[super dealloc];
}


@end

