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 @@
{
// Override point for customization after application launch.
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];
self.splitViewController = [storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"];
}
compute = false;
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
// Copy resource files if the version of the app has changed
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
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];
}
else{
NSLog(@"Leaving models as-is (version %@)", prefsv);
}
return YES;
}
- (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.
// 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.
// 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. 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
{
// 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.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
// 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. If your
// application supports background execution, this method is called instead
// of applicationWillTerminate: when the user quits.
}
- (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
{
// 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];
}
- (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
......
......@@ -2,7 +2,8 @@
@implementation Model
-(id) initWithName:(NSString *)name {
-(id) initWithName:(NSString *)name
{
self = [super init];
if(self) {
_name = name;
......@@ -14,7 +15,8 @@
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];
if(self) {
_name = name;
......@@ -26,33 +28,41 @@
return self;
}
-(NSString *) getName {
-(NSString *) getName
{
return _name;
}
-(NSString *) getSummary {
-(NSString *) getSummary
{
return _summary;
}
-(NSString *) getFile {
-(NSString *) getFile
{
return _file;
}
-(NSURL *) getUrl {
-(NSURL *) getUrl
{
return _url;
}
-(UIImage *) getPreview {
-(UIImage *) getPreview
{
return _preview;
}
-(void) setSummary:(NSString *)summary {
-(void) setSummary:(NSString *)summary
{
_summary = summary;
}
-(void) setFile:(NSString *)file {
-(void) setFile:(NSString *)file
{
_file = file;
}
-(void) setPreview:(NSString *)path {
-(void) setPreview:(NSString *)path
{
_preview = [UIImage imageWithContentsOfFile:path];
}
-(void) setUrl:(NSString *)url {
-(void) setUrl:(NSString *)url
{
_url = [NSURL URLWithString:url];
}
@end
......@@ -128,7 +128,8 @@
actionSheet.tag = indexPath.row;
[actionSheet showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 1:
[[UIApplication sharedApplication] openURL:[[models objectAtIndex:actionSheet.tag] getUrl]];
......@@ -203,8 +204,7 @@
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showModelSegue"])
{
if ([[segue identifier] isEqualToString:@"showModelSegue"]) {
ModelViewController *modelViewController = [segue destinationViewController];
modelViewController.initialModel = selectedModel;
}
......
......@@ -74,8 +74,7 @@
- (void)refreshOptions
{
NSInteger nrow = [self.tableView numberOfRowsInSection:1];
if(PView::list.size() == 0)
{
if(PView::list.size() == 0) {
NSMutableArray *array = [[NSMutableArray alloc] init];
for(NSInteger i = 0; i<nrow; i++)
[array addObject:[NSIndexPath indexPathForRow:i inSection:1]];
......@@ -83,8 +82,7 @@
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithArray:array] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}
else if(nrow < PView::list.size())
{
else if(nrow < PView::list.size()) {
NSMutableArray *array = [[NSMutableArray alloc] init];
for(NSInteger i = nrow; i<PView::list.size(); i++)
[array addObject:[NSIndexPath indexPathForRow:i-nrow inSection:1]];
......
......@@ -4,8 +4,7 @@
-(id)init
{
self = [super init];
if(self)
{
if(self) {
label = [[UILabel alloc] init];
[label setBackgroundColor:[UIColor clearColor]];
}
......@@ -112,8 +111,7 @@
-(id) initWithNumber:(onelab::number) number
{
self = [super init];
if(self)
{
if(self) {
label.alpha = (number.getReadOnly())? 0.439216f : 1.0f;
[label setText:[NSString stringWithCString:number.getShortName().c_str() encoding:[NSString defaultCStringEncoding]]];
name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]];
......@@ -176,8 +174,7 @@
-(id) initWithNumber:(onelab::number) number
{
self = [super init];
if(self)
{
if(self) {
label.alpha = (number.getReadOnly())? 0.439216f : 1.0f;
[label setText:[NSString stringWithCString:number.getShortName().c_str() encoding:[NSString defaultCStringEncoding]]];
name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]];
......@@ -227,8 +224,7 @@
-(id) initWithNumber:(onelab::number) number
{
self = [super init];
if(self)
{
if(self) {
name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]];
label.alpha = (number.getReadOnly())? 0.439216f : 1.0f;
stepper = [[UIStepper alloc] init];
......@@ -276,8 +272,7 @@
-(id) initWithNumber:(onelab::number) number
{
self = [super init];
if(self)
{
if(self) {
label.alpha = (number.getReadOnly())? 0.439216f : 1.0f;
name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]];
slider = [[UISlider alloc] init];
......@@ -335,8 +330,7 @@
-(id)initWithNumber:(onelab::number)number
{
self = [super init];
if(self)
{
if(self) {
label.alpha = (number.getReadOnly())? 0.439216f : 1.0f;
[label setText:[NSString stringWithCString:number.getShortName().c_str() encoding:[NSString defaultCStringEncoding]]];
name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]];
......
......@@ -78,8 +78,7 @@
ParameterNumberStepper *param = [[ParameterNumberStepper alloc] initWithNumber:p];
[section addObject:param];
}
else
{
else {
ParameterNumberRange *param = [[ParameterNumberRange alloc] initWithNumber:p];
[section addObject:param];
}
......@@ -245,7 +244,6 @@
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [_sections count];
......
......@@ -24,8 +24,7 @@
{
[super viewDidLoad];
// Do any additional setup after loading the view.
if(_pview)
{
if(_pview) {
[_Name setText:[NSString stringWithCString:_pview->getData()->getName().c_str() encoding:[NSString defaultCStringEncoding]]];
[_IntervalsType setDataSource:self];
[_IntervalsType setDelegate:self];
......@@ -106,7 +105,8 @@
[_Intervals endEditing:YES];
}
- (void)viewDidUnload {
- (void)viewDidUnload
{
[self setName:nil];
[self setRaiseZ:nil];
[self setIntervals:nil];
......
......@@ -14,12 +14,14 @@
NSString *resPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"files"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath = [paths objectAtIndex:0]; //Get the docs directory
NSArray *resContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:resPath error:NULL];
//[[NSFileManager defaultManager] removeItemAtPath:[docPath stringByAppendingString:@"/"] error:nil];
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;
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);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment