Skip to content
Snippets Groups Projects
Commit 0dd1be68 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

replace models when a new version of the app is detected

parent d41d51a1
No related branches found
No related tags found
No related merge requests found
...@@ -8,46 +8,66 @@ ...@@ -8,46 +8,66 @@
{ {
// Override point for customization after application launch. // Override point for customization after application launch.
self.modelListController = (ModelListController *)self.window.rootViewController; self.modelListController = (ModelListController *)self.window.rootViewController;
if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]) { if([[UIDevice currentDevice].model isEqualToString:@"iPad"] ||
[[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPadStoryboard" bundle:nil]; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPadStoryboard" bundle:nil];
self.splitViewController = [storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"]; self.splitViewController = [storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"];
} }
compute = false; compute = false;
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
{ // Copy resource files if the version of the app has changed
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"]; NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[[NSUserDefaults standardUserDefaults] synchronize]; NSString *prefsv = [prefs stringForKey:@"OnelabModelsVersion"];
NSString *bundlev = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
if (!prefsv || ![prefsv isEqualToString:bundlev]) {
NSLog(@"Updating models to version %@", bundlev);
[prefs setObject:bundlev forKey:@"OnelabModelsVersion"];
[prefs synchronize];
[Utils copyRes]; [Utils copyRes];
} }
else{
NSLog(@"Leaving models as-is (version %@)", prefsv);
}
return YES; return YES;
} }
- (void)applicationWillResignActive:(UIApplication *)application - (void)applicationWillResignActive:(UIApplication *)application
{ {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Sent when the application is about to move from active to inactive
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. // state. This can occur for certain types of temporary interruptions (such as
// an incoming phone call or SMS message) or when the user quits the
// application and it begins the transition to the background state. Use this
// method to pause ongoing tasks, disable timers, and throttle down OpenGL ES
// frame rates. Games should use this method to pause the game.
} }
- (void)applicationDidEnterBackground:(UIApplication *)application - (void)applicationDidEnterBackground:(UIApplication *)application
{ {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // Use this method to release shared resources, save user data, invalidate
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. // timers, and store enough application state information to restore your
// application to its current state in case it is terminated later. If your
// application supports background execution, this method is called instead
// of applicationWillTerminate: when the user quits.
} }
- (void)applicationWillEnterForeground:(UIApplication *)application - (void)applicationWillEnterForeground:(UIApplication *)application
{ {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. // Called as part of the transition from the background to the inactive state;
// here you can undo many of the changes made on entering the background.
} }
- (void)applicationDidBecomeActive:(UIApplication *)application - (void)applicationDidBecomeActive:(UIApplication *)application
{ {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. // Restart any tasks that were paused (or not yet started) while the
// application was inactive. If the application was previously in the
// background, optionally refresh the user interface.
[[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil];
} }
- (void)applicationWillTerminate:(UIApplication *)application - (void)applicationWillTerminate:(UIApplication *)application
{ {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. // Called when the application is about to terminate. Save data if
// appropriate. See also applicationDidEnterBackground:.
} }
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
@implementation Model @implementation Model
-(id) initWithName:(NSString *)name { -(id) initWithName:(NSString *)name
{
self = [super init]; self = [super init];
if(self) { if(self) {
_name = name; _name = name;
...@@ -14,7 +15,8 @@ ...@@ -14,7 +15,8 @@
return self; return self;
} }
-(id) initWithName:(NSString *)name withSummary:(NSString *)summary withFile:(NSString *)file { -(id) initWithName:(NSString *)name withSummary:(NSString *)summary withFile:(NSString *)file
{
self = [super init]; self = [super init];
if(self) { if(self) {
_name = name; _name = name;
...@@ -26,33 +28,41 @@ ...@@ -26,33 +28,41 @@
return self; return self;
} }
-(NSString *) getName { -(NSString *) getName
{
return _name; return _name;
} }
-(NSString *) getSummary { -(NSString *) getSummary
{
return _summary; return _summary;
} }
-(NSString *) getFile { -(NSString *) getFile
{
return _file; return _file;
} }
-(NSURL *) getUrl { -(NSURL *) getUrl
{
return _url; return _url;
} }
-(UIImage *) getPreview { -(UIImage *) getPreview
{
return _preview; return _preview;
} }
-(void) setSummary:(NSString *)summary { -(void) setSummary:(NSString *)summary
{
_summary = summary; _summary = summary;
} }
-(void) setFile:(NSString *)file { -(void) setFile:(NSString *)file
{
_file = file; _file = file;
} }
-(void) setPreview:(NSString *)path { -(void) setPreview:(NSString *)path
{
_preview = [UIImage imageWithContentsOfFile:path]; _preview = [UIImage imageWithContentsOfFile:path];
} }
-(void) setUrl:(NSString *)url { -(void) setUrl:(NSString *)url
{
_url = [NSURL URLWithString:url]; _url = [NSURL URLWithString:url];
} }
@end @end
...@@ -128,7 +128,8 @@ ...@@ -128,7 +128,8 @@
actionSheet.tag = indexPath.row; actionSheet.tag = indexPath.row;
[actionSheet showInView:self.view]; [actionSheet showInView:self.view];
} }
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) { switch (buttonIndex) {
case 1: case 1:
[[UIApplication sharedApplication] openURL:[[models objectAtIndex:actionSheet.tag] getUrl]]; [[UIApplication sharedApplication] openURL:[[models objectAtIndex:actionSheet.tag] getUrl]];
...@@ -203,8 +204,7 @@ ...@@ -203,8 +204,7 @@
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{ {
if ([[segue identifier] isEqualToString:@"showModelSegue"]) if ([[segue identifier] isEqualToString:@"showModelSegue"]) {
{
ModelViewController *modelViewController = [segue destinationViewController]; ModelViewController *modelViewController = [segue destinationViewController];
modelViewController.initialModel = selectedModel; modelViewController.initialModel = selectedModel;
} }
......
...@@ -74,8 +74,7 @@ ...@@ -74,8 +74,7 @@
- (void)refreshOptions - (void)refreshOptions
{ {
NSInteger nrow = [self.tableView numberOfRowsInSection:1]; NSInteger nrow = [self.tableView numberOfRowsInSection:1];
if(PView::list.size() == 0) if(PView::list.size() == 0) {
{
NSMutableArray *array = [[NSMutableArray alloc] init]; NSMutableArray *array = [[NSMutableArray alloc] init];
for(NSInteger i = 0; i<nrow; i++) for(NSInteger i = 0; i<nrow; i++)
[array addObject:[NSIndexPath indexPathForRow:i inSection:1]]; [array addObject:[NSIndexPath indexPathForRow:i inSection:1]];
...@@ -83,8 +82,7 @@ ...@@ -83,8 +82,7 @@
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithArray:array] withRowAnimation:UITableViewRowAnimationAutomatic]; [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithArray:array] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates]; [self.tableView endUpdates];
} }
else if(nrow < PView::list.size()) else if(nrow < PView::list.size()) {
{
NSMutableArray *array = [[NSMutableArray alloc] init]; NSMutableArray *array = [[NSMutableArray alloc] init];
for(NSInteger i = nrow; i<PView::list.size(); i++) for(NSInteger i = nrow; i<PView::list.size(); i++)
[array addObject:[NSIndexPath indexPathForRow:i-nrow inSection:1]]; [array addObject:[NSIndexPath indexPathForRow:i-nrow inSection:1]];
......
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
-(id)init -(id)init
{ {
self = [super init]; self = [super init];
if(self) if(self) {
{
label = [[UILabel alloc] init]; label = [[UILabel alloc] init];
[label setBackgroundColor:[UIColor clearColor]]; [label setBackgroundColor:[UIColor clearColor]];
} }
...@@ -112,8 +111,7 @@ ...@@ -112,8 +111,7 @@
-(id) initWithNumber:(onelab::number) number -(id) initWithNumber:(onelab::number) number
{ {
self = [super init]; self = [super init];
if(self) if(self) {
{
label.alpha = (number.getReadOnly())? 0.439216f : 1.0f; label.alpha = (number.getReadOnly())? 0.439216f : 1.0f;
[label setText:[NSString stringWithCString:number.getShortName().c_str() encoding:[NSString defaultCStringEncoding]]]; [label setText:[NSString stringWithCString:number.getShortName().c_str() encoding:[NSString defaultCStringEncoding]]];
name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]]; name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]];
...@@ -176,8 +174,7 @@ ...@@ -176,8 +174,7 @@
-(id) initWithNumber:(onelab::number) number -(id) initWithNumber:(onelab::number) number
{ {
self = [super init]; self = [super init];
if(self) if(self) {
{
label.alpha = (number.getReadOnly())? 0.439216f : 1.0f; label.alpha = (number.getReadOnly())? 0.439216f : 1.0f;
[label setText:[NSString stringWithCString:number.getShortName().c_str() encoding:[NSString defaultCStringEncoding]]]; [label setText:[NSString stringWithCString:number.getShortName().c_str() encoding:[NSString defaultCStringEncoding]]];
name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]]; name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]];
...@@ -227,8 +224,7 @@ ...@@ -227,8 +224,7 @@
-(id) initWithNumber:(onelab::number) number -(id) initWithNumber:(onelab::number) number
{ {
self = [super init]; self = [super init];
if(self) if(self) {
{
name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]]; name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]];
label.alpha = (number.getReadOnly())? 0.439216f : 1.0f; label.alpha = (number.getReadOnly())? 0.439216f : 1.0f;
stepper = [[UIStepper alloc] init]; stepper = [[UIStepper alloc] init];
...@@ -276,8 +272,7 @@ ...@@ -276,8 +272,7 @@
-(id) initWithNumber:(onelab::number) number -(id) initWithNumber:(onelab::number) number
{ {
self = [super init]; self = [super init];
if(self) if(self) {
{
label.alpha = (number.getReadOnly())? 0.439216f : 1.0f; label.alpha = (number.getReadOnly())? 0.439216f : 1.0f;
name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]]; name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]];
slider = [[UISlider alloc] init]; slider = [[UISlider alloc] init];
...@@ -335,8 +330,7 @@ ...@@ -335,8 +330,7 @@
-(id)initWithNumber:(onelab::number)number -(id)initWithNumber:(onelab::number)number
{ {
self = [super init]; self = [super init];
if(self) if(self) {
{
label.alpha = (number.getReadOnly())? 0.439216f : 1.0f; label.alpha = (number.getReadOnly())? 0.439216f : 1.0f;
[label setText:[NSString stringWithCString:number.getShortName().c_str() encoding:[NSString defaultCStringEncoding]]]; [label setText:[NSString stringWithCString:number.getShortName().c_str() encoding:[NSString defaultCStringEncoding]]];
name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]]; name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]];
......
...@@ -78,8 +78,7 @@ ...@@ -78,8 +78,7 @@
ParameterNumberStepper *param = [[ParameterNumberStepper alloc] initWithNumber:p]; ParameterNumberStepper *param = [[ParameterNumberStepper alloc] initWithNumber:p];
[section addObject:param]; [section addObject:param];
} }
else else {
{
ParameterNumberRange *param = [[ParameterNumberRange alloc] initWithNumber:p]; ParameterNumberRange *param = [[ParameterNumberRange alloc] initWithNumber:p];
[section addObject:param]; [section addObject:param];
} }
...@@ -245,7 +244,6 @@ ...@@ -245,7 +244,6 @@
#pragma mark - Table View #pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{ {
return [_sections count]; return [_sections count];
......
...@@ -24,8 +24,7 @@ ...@@ -24,8 +24,7 @@
{ {
[super viewDidLoad]; [super viewDidLoad];
// Do any additional setup after loading the view. // Do any additional setup after loading the view.
if(_pview) if(_pview) {
{
[_Name setText:[NSString stringWithCString:_pview->getData()->getName().c_str() encoding:[NSString defaultCStringEncoding]]]; [_Name setText:[NSString stringWithCString:_pview->getData()->getName().c_str() encoding:[NSString defaultCStringEncoding]]];
[_IntervalsType setDataSource:self]; [_IntervalsType setDataSource:self];
[_IntervalsType setDelegate:self]; [_IntervalsType setDelegate:self];
...@@ -106,7 +105,8 @@ ...@@ -106,7 +105,8 @@
[_Intervals endEditing:YES]; [_Intervals endEditing:YES];
} }
- (void)viewDidUnload { - (void)viewDidUnload
{
[self setName:nil]; [self setName:nil];
[self setRaiseZ:nil]; [self setRaiseZ:nil];
[self setIntervals:nil]; [self setIntervals:nil];
......
...@@ -14,12 +14,14 @@ ...@@ -14,12 +14,14 @@
NSString *resPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"files"]; NSString *resPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"files"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath = [paths objectAtIndex:0]; //Get the docs directory NSString *docPath = [paths objectAtIndex:0]; //Get the docs directory
NSArray *resContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:resPath error:NULL]; NSArray *resContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:resPath error:NULL];
//[[NSFileManager defaultManager] removeItemAtPath:[docPath stringByAppendingString:@"/"] error:nil];
for (NSString *obj in resContents){ for (NSString *obj in resContents){
NSLog(@"Replacing model %@", obj);
NSString *modelSrc = [[resPath stringByAppendingString:@"/"] stringByAppendingString:obj];
NSString *modelDst = [[docPath stringByAppendingString:@"/"] stringByAppendingString:obj];
[[NSFileManager defaultManager] removeItemAtPath:modelDst error:nil];
NSError *error; NSError *error;
if (![[NSFileManager defaultManager] copyItemAtPath:[resPath stringByAppendingPathComponent:obj] toPath:[docPath stringByAppendingPathComponent:obj] error:&error]) if (![[NSFileManager defaultManager] copyItemAtPath:modelSrc toPath:modelDst error:&error])
NSLog(@"Error: %@", error); NSLog(@"Error: %@", error);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment