project_files/HedgewarsMobile/Classes/RestoreViewController.m
author antonc27 <antonc27@mail.ru>
Mon, 19 Oct 2015 03:39:47 +0200
branchios-revival
changeset 11217 e68b3e392091
parent 11207 279ed2931be8
child 11232 0425d60cd046
permissions -rw-r--r--
- Big refactoring of front-end Settings for both iPhone and iPad: - - Fixed crash when receiving Memory Warning after dismissing Settings on iPhone - - Set ARC flags for MGSplitVCs as it now updated for iOS 8 - - All sub-settings VCs now recreated each time they presented - - SettingsContainerViewController removed - - Other small improvements
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5220
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
     1
/*
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
6700
e04da46ee43c the most important commit of the year
koda
parents: 6353
diff changeset
     3
 * Copyright (c) 2009-2012 Vittorio Giovara <vittorio.giovara@gmail.com>
5220
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
     4
 *
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
     8
 *
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    12
 * GNU General Public License for more details.
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    13
 *
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 6869
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
5220
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    17
 */
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    18
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    19
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    20
#import "RestoreViewController.h"
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    21
#import "GameInterfaceBridge.h"
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    22
11205
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    23
@interface RestoreViewController ()
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    24
@property (retain, nonatomic) IBOutlet UIButton *restoreButton;
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    25
@property (retain, nonatomic) IBOutlet UIButton *dismissButton;
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    26
@end
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    27
5220
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    28
@implementation RestoreViewController
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    29
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    30
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    31
    return rotationManager(interfaceOrientation);
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    32
}
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    33
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    34
-(IBAction) buttonReleased:(id) sender {
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    35
    UIButton *theButton = (UIButton *)sender;
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    36
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    37
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    38
    if (theButton.tag != 0) {
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    39
        [[AudioManagerController mainManager] playClickSound];
11116
102684240fe8 - Interscreen transitions fixed
Anton Malmygin <antonc27@mail.ru>
parents: 10108
diff changeset
    40
        [GameInterfaceBridge registerCallingController:self.presentingViewController];
11207
279ed2931be8 - Fix for wrong path of restored game
antonc27 <antonc27@mail.ru>
parents: 11205
diff changeset
    41
        
279ed2931be8 - Fix for wrong path of restored game
antonc27 <antonc27@mail.ru>
parents: 11205
diff changeset
    42
        // Since iOS 8, the file system layout of app containers has changed.
279ed2931be8 - Fix for wrong path of restored game
antonc27 <antonc27@mail.ru>
parents: 11205
diff changeset
    43
        // So, we must rely now on saved game filename, not full path.
279ed2931be8 - Fix for wrong path of restored game
antonc27 <antonc27@mail.ru>
parents: 11205
diff changeset
    44
        NSString *oldSavedGamePath = [[NSUserDefaults standardUserDefaults] objectForKey:@"savedGamePath"];
279ed2931be8 - Fix for wrong path of restored game
antonc27 <antonc27@mail.ru>
parents: 11205
diff changeset
    45
        NSString *savedGameFile = [oldSavedGamePath lastPathComponent];
279ed2931be8 - Fix for wrong path of restored game
antonc27 <antonc27@mail.ru>
parents: 11205
diff changeset
    46
        NSString *newSavedGamePath = [NSString stringWithFormat:@"%@%@", SAVES_DIRECTORY(), savedGameFile];
279ed2931be8 - Fix for wrong path of restored game
antonc27 <antonc27@mail.ru>
parents: 11205
diff changeset
    47
        
279ed2931be8 - Fix for wrong path of restored game
antonc27 <antonc27@mail.ru>
parents: 11205
diff changeset
    48
        [GameInterfaceBridge startSaveGame:newSavedGamePath];
5220
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    49
    } else {
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    50
        [[AudioManagerController mainManager] playBackSound];
5220
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    51
        [defaults setObject:@"" forKey:@"savedGamePath"];
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    52
        [defaults synchronize];
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    53
    }
11116
102684240fe8 - Interscreen transitions fixed
Anton Malmygin <antonc27@mail.ru>
parents: 10108
diff changeset
    54
    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
5220
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    55
}
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    56
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    57
-(void) viewDidLoad {
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    58
    [super viewDidLoad];
11205
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    59
    
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    60
    [self.restoreButton applyDarkBlueQuickStyle];
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    61
    [self.dismissButton applyDarkBlueQuickStyle];
5220
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    62
}
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    63
5666
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    64
-(void) didReceiveMemoryWarning {
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    65
    [super didReceiveMemoryWarning];
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    66
}
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    67
5220
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    68
-(void) viewDidUnload {
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    69
    [super viewDidUnload];
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    70
}
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    71
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    72
-(void) dealloc {
11205
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    73
    [_restoreButton release];
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    74
    [_dismissButton release];
5220
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    75
    [super dealloc];
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    76
}
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    77
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    78
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    79
@end