modified resource packager to create the modrules.xml file for iOS port
updated app delegate to download both the core and core_ios file. Still have the version number hard coded into the app.
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
#import "ASIHTTPRequest.h"
|
||||
#import "ZipArchive.h"
|
||||
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
|
||||
@implementation wagicAppDelegate
|
||||
|
||||
@synthesize window;
|
||||
@@ -11,10 +13,31 @@
|
||||
@synthesize wagicDownloadController;
|
||||
@synthesize hostReach, wifiReach, internetReach;
|
||||
|
||||
- (void) updateComplete: (id) notificationMsg
|
||||
{
|
||||
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
||||
|
||||
[dnc postNotificationName: @"initializeGame" object: self];
|
||||
[dnc removeObserver: self name: @"coreComplete" object: nil];
|
||||
[dnc removeObserver: self name: @"iosConfigComplete" object: nil];
|
||||
|
||||
}
|
||||
|
||||
- (void) initIosUpdate: (id) notificationMsg
|
||||
{
|
||||
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
||||
[dnc addObserver: self selector: @selector(updateComplete:) name: @"iosConfigComplete" object: nil];
|
||||
[wagicDownloadController performSelectorInBackground: @selector(startDownload:) withObject:@"iosConfig"];
|
||||
}
|
||||
|
||||
- (void) downloadResources
|
||||
{
|
||||
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
||||
|
||||
[dnc addObserver:self selector:@selector(initIosUpdate:) name:@"coreComplete" object: nil];
|
||||
|
||||
wagicDownloadController = [[WagicDownloadProgressViewController alloc] init];
|
||||
[wagicDownloadController startDownload: @"core"];
|
||||
[wagicDownloadController performSelectorInBackground: @selector(startDownload:) withObject:@"core"];
|
||||
|
||||
[self.window addSubview: wagicDownloadController.view];
|
||||
[self.window makeKeyWindow];
|
||||
@@ -108,7 +131,7 @@
|
||||
NSArray *docsPathContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: docsPath error:nil];
|
||||
NSCompoundPredicate *compoundPredicate = [[NSCompoundPredicate alloc] initWithType:NSAndPredicateType subpredicates: [NSArray arrayWithObjects: [NSPredicate predicateWithFormat:@"self ENDSWITH '.zip'"], [NSPredicate predicateWithFormat:@"NOT (self BEGINSWITH 'core_')"], nil]];
|
||||
|
||||
NSArray *coreFiles = [docsPathContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self BEGINSWITH 'core_'"]];
|
||||
NSArray *coreFiles = [docsPathContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self BEGINSWITH 'core_0171'"]];
|
||||
|
||||
NSArray *resourceZipFiles = [docsPathContents filteredArrayUsingPredicate: compoundPredicate];
|
||||
NSString *userPath = [NSString stringWithFormat: @"%@/User", docsPath];
|
||||
@@ -158,7 +181,7 @@
|
||||
NSArray *resDirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: resPath error:nil];
|
||||
NSArray *coreFiles = [resDirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self BEGINSWITH 'core_'"]];
|
||||
|
||||
if ([coreFiles count] > 0)
|
||||
if ([coreFiles count] >= 2)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ def createStandardResFile():
|
||||
def createIosResFile():
|
||||
print 'Preparing Resource Package for iOS'
|
||||
utilities = ZipUtilities()
|
||||
filename = 'core_017_iOS.zip'
|
||||
createResZipFile( filename )
|
||||
filename = 'core_0171_iOS.zip'
|
||||
#createResZipFile( filename )
|
||||
zip_file = zipfile.ZipFile(filename, 'a', zipfile.ZIP_STORED)
|
||||
zip_file.write("../../iOS/Res/rules/modrules.xml", "rules/modrules.xml", zipfile.ZIP_STORED)
|
||||
zip_file.close()
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
@synthesize downloadMessageStatus;
|
||||
|
||||
static NSString *kDownloadUrlPath = @"http://wagic.googlecode.com/files/";
|
||||
static NSString *kDownloadFileName = @"core_017_iOS.zip";
|
||||
static NSString *kDownloadFileName = @"core_0171.zip";
|
||||
static NSString *kDownloadIosUpdateFileName = @"core_0171_iOS.zip";
|
||||
|
||||
|
||||
|
||||
@@ -52,44 +53,76 @@ static NSString *kDownloadFileName = @"core_017_iOS.zip";
|
||||
|
||||
- (void) startDownload: (NSString *) downloadType
|
||||
{
|
||||
[self.downloadMessageStatus setText: [NSString stringWithFormat: @"Please wait while the %@ files are being downloaded.", downloadType]];
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
[self.downloadMessageStatus performSelectorOnMainThread:@selector(setText:) withObject:[NSString stringWithFormat: @"Please wait while the %@ files are being downloaded.", downloadType] waitUntilDone: NO ];
|
||||
|
||||
if ( downloadProgressView != nil )
|
||||
{
|
||||
[downloadProgressView removeFromSuperview];
|
||||
[downloadProgressView release], downloadProgressView = nil;
|
||||
}
|
||||
|
||||
downloadProgressView = [[UIProgressView alloc] initWithProgressViewStyle: UIProgressViewStyleDefault];
|
||||
[self.downloadProgressView setFrame: CGRectMake(0, 0, 250, 50)];
|
||||
[self.downloadProgressView setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight ];
|
||||
|
||||
[self.view addSubview: downloadProgressView];
|
||||
[self handleRotation: self.interfaceOrientation];
|
||||
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,
|
||||
NSUserDomainMask, YES);
|
||||
NSString *systemResourceDirectory = [[paths objectAtIndex:0] stringByAppendingString: @"/Res"];
|
||||
NSString *userResourceDirectory = [[paths objectAtIndex: 0] stringByAppendingString: @"/User"];
|
||||
NSString *downloadFilePath = [systemResourceDirectory stringByAppendingString: [NSString stringWithFormat: @"/%@", kDownloadFileName]];
|
||||
|
||||
NSError *error = nil;
|
||||
// make sure Res directory exists
|
||||
if ( ![[NSFileManager defaultManager] fileExistsAtPath: systemResourceDirectory] )
|
||||
[[NSFileManager defaultManager] createDirectoryAtPath:systemResourceDirectory withIntermediateDirectories: YES attributes:nil error: &error];
|
||||
|
||||
if (error != nil)
|
||||
{
|
||||
NSLog(@"Error in creating System Directory! %@", [error localizedDescription]);
|
||||
error = nil;
|
||||
}
|
||||
|
||||
// make sure the User directory exists as well
|
||||
if ( ![[NSFileManager defaultManager] fileExistsAtPath: userResourceDirectory] )
|
||||
[[NSFileManager defaultManager] createDirectoryAtPath: userResourceDirectory withIntermediateDirectories: YES attributes:nil error: &error];
|
||||
|
||||
if (error != nil)
|
||||
{
|
||||
NSLog(@"Error in creating User Directory! %@", [error localizedDescription]);
|
||||
error = nil;
|
||||
}
|
||||
|
||||
// if an error occurred while creating the directory, game can't really run so do something
|
||||
// TODO: throw out a notification and deal with error
|
||||
|
||||
NSURL *url = nil;
|
||||
NSString *downloadFilename = nil;
|
||||
// determine which file to download
|
||||
if ([downloadType isEqualToString: @"core"])
|
||||
{
|
||||
url = [NSURL URLWithString: [NSString stringWithFormat: @"%@/%@", kDownloadUrlPath, kDownloadFileName]];
|
||||
downloadFilename = kDownloadFileName;
|
||||
}
|
||||
else if ( [downloadType isEqualToString: @"iosConfig"] )
|
||||
{
|
||||
downloadFilename = kDownloadIosUpdateFileName;
|
||||
}
|
||||
else if ( [downloadType isEqualToString: @"someOtherType"] )
|
||||
{
|
||||
NSLog( @"Not Implemented for type: %@", downloadType);
|
||||
}
|
||||
|
||||
url = [NSURL URLWithString: [NSString stringWithFormat: @"%@/%@", kDownloadUrlPath, downloadFilename]];
|
||||
NSString *downloadFilePath = [systemResourceDirectory stringByAppendingString: [NSString stringWithFormat: @"/%@", downloadFilename]];
|
||||
|
||||
NSLog(@"Downloading %@", [url absoluteURL]);
|
||||
|
||||
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
|
||||
[request setTemporaryFileDownloadPath: [NSString stringWithFormat: @"%@.tmp", userResourceDirectory]];
|
||||
|
||||
[request setTemporaryFileDownloadPath: [NSString stringWithFormat: @"%@/%@.tmp", systemResourceDirectory, downloadFilename]];
|
||||
|
||||
[request setDownloadDestinationPath: downloadFilePath];
|
||||
[request setDownloadProgressDelegate: downloadProgressView];
|
||||
[request setShouldContinueWhenAppEntersBackground: YES];
|
||||
@@ -98,7 +131,8 @@ static NSString *kDownloadFileName = @"core_017_iOS.zip";
|
||||
[request setCompletionBlock:^{
|
||||
wagicAppDelegate *appDelegate = (wagicAppDelegate *)[[UIApplication sharedApplication] delegate];
|
||||
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
||||
[dnc postNotificationName:@"initializeGame" object: appDelegate];
|
||||
NSLog(@"Saving to %@", downloadFilePath);
|
||||
[dnc postNotificationName: [NSString stringWithFormat: @"%@Complete", downloadType] object: appDelegate];
|
||||
|
||||
}];
|
||||
[request setFailedBlock:^{
|
||||
@@ -116,6 +150,8 @@ static NSString *kDownloadFileName = @"core_017_iOS.zip";
|
||||
}];
|
||||
|
||||
[request startAsynchronous];
|
||||
|
||||
[pool drain], pool = nil;
|
||||
}
|
||||
|
||||
- (id) init
|
||||
|
||||
Reference in New Issue
Block a user