/*
iPhly: Radio Control on the iPhone

Copyright (C) 2010-2011 Ari Krupnik & Associates

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License V2
as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#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

