diff --git a/JGE/src/JFileSystem.cpp b/JGE/src/JFileSystem.cpp index 8ff89cf29..117c0dc05 100644 --- a/JGE/src/JFileSystem.cpp +++ b/JGE/src/JFileSystem.cpp @@ -89,19 +89,10 @@ JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath) string userPath = _userPath; #ifdef IOS - //copy the RES folder over to the Documents folder - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSError *error; NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [[paths objectAtIndex:0] stringByAppendingString: @"/Res"]; - NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath] - stringByAppendingPathComponent:@"Res"]; - // copy the Res folder over to the Documents directory if it doesn't exist. - if ( ![fileManager fileExistsAtPath: documentsDirectory]) - [fileManager copyItemAtPath:resourceDBFolderPath toPath:documentsDirectory error:&error]; - userPath = [documentsDirectory cStringUsingEncoding:1]; userPath += "/"; systemPath = ""; diff --git a/JGE/src/iOS/wagicAppDelegate.h b/JGE/src/iOS/wagicAppDelegate.h index 95019f5c1..098ee7892 100755 --- a/JGE/src/iOS/wagicAppDelegate.h +++ b/JGE/src/iOS/wagicAppDelegate.h @@ -1,16 +1,25 @@ #import - +#import "Reachability.h" +#import "WagicDownloadProgressViewController.h" @class EAGLViewController; @interface wagicAppDelegate : NSObject { UIWindow *window; EAGLViewController *glViewController; + //Reachability variables + Reachability* hostReach; + Reachability* internetReach; + Reachability* wifiReach; + } +- (void) rotateBackgroundImage:(UIInterfaceOrientation)fromInterfaceOrientation toInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation; - (void) handleWEngineCommand:(NSString *) command; @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) EAGLViewController *glViewController; +@property (nonatomic, retain) WagicDownloadProgressViewController *wagicDownloadController; +@property (nonatomic, retain) Reachability *hostReach, *internetReach, *wifiReach; @end diff --git a/JGE/src/iOS/wagicAppDelegate.m b/JGE/src/iOS/wagicAppDelegate.m index 1113dac3e..b4a582ddf 100755 --- a/JGE/src/iOS/wagicAppDelegate.m +++ b/JGE/src/iOS/wagicAppDelegate.m @@ -1,52 +1,120 @@ #import "wagicAppDelegate.h" #import "EAGLView.h" #import "EAGLViewController.h" - +#import "ASIHTTPRequest.h" +#import "ZipArchive.h" @implementation wagicAppDelegate @synthesize window; @synthesize glViewController; +@synthesize wagicDownloadController; +@synthesize hostReach, wifiReach, internetReach; + + +- (void) downloadResources +{ + wagicDownloadController = [[WagicDownloadProgressViewController alloc] init]; + + [self.window addSubview: wagicDownloadController.view]; + [self.window makeKeyWindow]; + +} + + +- (BOOL) hasResourceFiles +{ + NSFileManager *fileManager = [NSFileManager defaultManager]; + + NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, + NSUserDomainMask, YES); + NSString *userResourceDirectory = [[paths objectAtIndex:0] stringByAppendingString: @"/Res"]; + + if (![fileManager fileExistsAtPath: userResourceDirectory] ) + { + return NO; + } + + return YES; +} + + +- (void) startGame +{ + glViewController = [[EAGLViewController alloc] init]; + [self.wagicDownloadController release]; + [self.window addSubview:self.glViewController.view]; + + NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter]; + [dnc removeObserver: self name: @"readyToStartGame" object: nil]; +} + + +- (void)dealloc +{ + [window release]; + [glViewController release]; + [hostReach release]; + [wifiReach release]; + [internetReach release]; + + [super dealloc]; +} - (void) applicationDidFinishLaunching:(UIApplication *)application { - glViewController = [[EAGLViewController alloc] init]; + self.glViewController = nil; + + NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter]; + [dnc addObserver:self selector:@selector(startGame) name:@"readyToStartGame" object: nil]; + + // check to see if the Res folder exists. If it does continue + // otherwise bring up the download dialog and download the core files + // once downloaded, extract the files and kick off the game. + BOOL requiresResourceUpdate = [self hasResourceFiles]; + if (!requiresResourceUpdate) + { + [self downloadResources]; + } + else + { + [self startGame]; + } - [self.window addSubview:self.glViewController.view]; [self.window makeKeyAndVisible]; } - (void)applicationWillResignActive:(UIApplication *)application { - EAGLView *eaglView = (EAGLView *)self.glViewController.view; - [eaglView stopAnimation]; + if ( [self.glViewController.view respondsToSelector: @selector(stopAnimation)]) + [self.glViewController.view stopAnimation]; } - (void)applicationDidBecomeActive:(UIApplication *)application { - EAGLView *eaglView = (EAGLView *)self.glViewController.view; - [eaglView startAnimation]; + if ( [self.glViewController.view respondsToSelector: @selector(stopAnimation)]) + [self.glViewController.view startAnimation]; } - (void)applicationWillEnterForeground:(UIApplication *)application { - EAGLView *eaglView = (EAGLView *)self.glViewController.view; - [eaglView startAnimation]; + if ( [self.glViewController.view respondsToSelector: @selector(stopAnimation)]) + [self.glViewController.view startAnimation]; } - (void)applicationDidEnterBackground:(UIApplication *)application { - EAGLView *eaglView = (EAGLView *)self.glViewController.view; - [eaglView stopAnimation]; + if ( [self.glViewController.view respondsToSelector: @selector(stopAnimation)]) + [self.glViewController.view stopAnimation]; } - (void)applicationWillTerminate:(UIApplication *)application { - EAGLView *eaglView = (EAGLView *)self.glViewController.view; - [eaglView stopAnimation]; + if ( [self.glViewController.view respondsToSelector: @selector(stopAnimation)]) + [self.glViewController.view stopAnimation]; } @@ -69,12 +137,56 @@ } -- (void)dealloc -{ - [window release]; - [glViewController release]; - [super dealloc]; +- (void) rotateBackgroundImage:(UIInterfaceOrientation)fromInterfaceOrientation toInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation +{ + bool isPhone = (UI_USER_INTERFACE_IDIOM()) == UIUserInterfaceIdiomPhone; + + if (isPhone) + { + UIImage *bgImage = [UIImage imageNamed: @"Default-Portrait.png"]; + [[[self.window subviews] objectAtIndex: 0] setBackgroundColor: [UIColor colorWithPatternImage: bgImage]]; + } + else + { + [self.window setBackgroundColor: [UIColor clearColor]]; + if (UIInterfaceOrientationIsLandscape( toInterfaceOrientation)) { + UIImage *bgImage = [UIImage imageNamed: @"Default-Landscape"]; + [[[self.window subviews] objectAtIndex: 0] setBackgroundColor: [UIColor colorWithPatternImage: bgImage]]; + } + else { + UIImage *bgImage = [UIImage imageNamed: @"Default-Portrait.png"]; + [[[self.window subviews] objectAtIndex: 0] setBackgroundColor: [UIColor colorWithPatternImage: bgImage]]; + [self.window setBackgroundColor: [UIColor colorWithPatternImage: bgImage]]; + } + } } + +#pragma mark Application Contents + +- (BOOL) isNetworkAvailable +{ + BOOL netAvailable = NO; + NSDate *startTime = [[[NSDate alloc ] init] autorelease]; + + hostReach = [[Reachability reachabilityForGoogleDNS] retain]; + + NetworkStatus netStatus = [hostReach currentReachabilityStatus]; + + + if (netStatus == ReachableViaWiFi || netStatus == ReachableViaWWAN) { + netAvailable = YES; + } + + //[[QLog log] logOption: kLogOptionTiming withFormat:@"isNetworkAvailble? %5.2f", [startTime timeIntervalSinceNow]]; + + [hostReach release]; + + return netAvailable; +} + + +#pragma mark - + @end diff --git a/projects/mtg/bin/Res/rules/modrules.xml b/projects/mtg/bin/Res/rules/modrules.xml index 4d135c141..f54a67aa9 100644 --- a/projects/mtg/bin/Res/rules/modrules.xml +++ b/projects/mtg/bin/Res/rules/modrules.xml @@ -7,13 +7,11 @@ - + - @@ -42,4 +40,4 @@ - \ No newline at end of file +