Skip to content

Commit

Permalink
Merge branch 'release/4.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
jnavarrom committed Oct 29, 2018
2 parents f164b75 + ca05bf2 commit 9c92484
Show file tree
Hide file tree
Showing 156 changed files with 4,362 additions and 3,558 deletions.
48 changes: 26 additions & 22 deletions MEGA.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions iMEGA/API/Requests/MEGAGetPublicNodeRequestDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

@interface MEGAGetPublicNodeRequestDelegate : MEGABaseRequestDelegate

@property (nonatomic) BOOL savePublicHandle;

- (id)init NS_UNAVAILABLE;

- (instancetype)initWithCompletion:(void (^)(MEGARequest *request, MEGAError *error))completion;
Expand Down
5 changes: 5 additions & 0 deletions iMEGA/API/Requests/MEGAGetPublicNodeRequestDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ - (void)onRequestStart:(MEGASdk *)api request:(MEGARequest *)request {
- (void)onRequestFinish:(MEGASdk *)api request:(MEGARequest *)request error:(MEGAError *)error {
[super onRequestFinish:api request:request error:error];

if (error.type == MEGAErrorTypeApiOk && self.savePublicHandle && request.publicNode) {
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithUnsignedLongLong:request.publicNode.handle] forKey:@"kLastPublicHandleAccessed"];
[[NSUserDefaults standardUserDefaults] setDouble:[NSDate date].timeIntervalSince1970 forKey:@"kLastPublicTimestampAccessed"];
}

if (self.completion) {
self.completion(request, error);
}
Expand Down
102 changes: 32 additions & 70 deletions iMEGA/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#import "MyAccountHallViewController.h"
#import "SettingsTableViewController.h"
#import "SharedItemsViewController.h"
#import "TwoFactorAuthenticationViewController.h"
#import "UnavailableLinkView.h"
#import "UpgradeTableViewController.h"

Expand Down Expand Up @@ -421,7 +422,7 @@ - (void)applicationDidEnterBackground:(UIApplication *)application {
- (void)applicationWillEnterForeground:(UIApplication *)application {
MEGALogDebug(@"Application will enter foreground");

if (self.wasAppSuspended) {
if (self.wasAppSuspended && [MEGASdkManager sharedMEGAChatSdk].numCalls == 0) {
//If the app has been suspended, we assume that the sockets have been closed, so we have to reconnect.
[[MEGAReachabilityManager sharedManager] reconnect];
} else {
Expand Down Expand Up @@ -474,18 +475,11 @@ - (void)applicationWillTerminate:(UIApplication *)application {
}

if ([[[[MEGASdkManager sharedMEGASdk] downloadTransfers] size] integerValue] == 0) {
[self removeUnfinishedTransfersOnFolder:[Helper pathForOffline]];

NSError *error = nil;
if (![[NSFileManager defaultManager] removeItemAtPath:[[NSFileManager defaultManager] downloadsDirectory] error:&error]) {
MEGALogError(@"Remove item at path failed with error: %@", error);
}
[NSFileManager.defaultManager mnz_removeFolderContentsRecursivelyAtPath:[Helper pathForOffline] forItemsExtension:@"mega"];
[NSFileManager.defaultManager mnz_removeItemAtPath:[NSFileManager.defaultManager downloadsDirectory]];
}
if ([[[[MEGASdkManager sharedMEGASdk] uploadTransfers] size] integerValue] == 0) {
NSError *error = nil;
if (![[NSFileManager defaultManager] removeItemAtPath:[[NSFileManager defaultManager] uploadsDirectory] error:&error]) {
MEGALogError(@"Remove item at path failed with error: %@", error);
}
[NSFileManager.defaultManager mnz_removeItemAtPath:[NSFileManager.defaultManager uploadsDirectory]];
}
}

Expand Down Expand Up @@ -642,10 +636,10 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N
#pragma mark - Private

- (void)setupAppearance {
[UINavigationBar appearance].titleTextAttributes = @{NSFontAttributeName:[UIFont mnz_SFUISemiBoldWithSize:17.0f], NSForegroundColorAttributeName:UIColor.whiteColor};
[UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[MEGANavigationController.class]].titleTextAttributes = @{NSFontAttributeName:[UIFont mnz_SFUISemiBoldWithSize:17.0f], NSForegroundColorAttributeName:UIColor.whiteColor};
[UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[MEGANavigationController.class]].barStyle = UIBarStyleBlack;
[UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[MEGANavigationController.class]].barTintColor = UIColor.mnz_redMain;
[UINavigationBar appearance].tintColor = UIColor.whiteColor;
[UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[MEGANavigationController.class]].tintColor = UIColor.whiteColor;
[UINavigationBar appearance].translucent = NO;

//QLPreviewDocument
Expand Down Expand Up @@ -1057,23 +1051,6 @@ - (BOOL)manageQuickActionType:(NSString *)type {
return quickActionManaged;
}

- (void)removeUnfinishedTransfersOnFolder:(NSString *)directory {
NSArray *directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directory error:nil];
for (NSString *item in directoryContents) {
NSDictionary *attributesDictionary = [[NSFileManager defaultManager] attributesOfItemAtPath:[directory stringByAppendingPathComponent:item] error:nil];
if ([attributesDictionary objectForKey:NSFileType] == NSFileTypeDirectory) {
[self removeUnfinishedTransfersOnFolder:[directory stringByAppendingPathComponent:item]];
} else {
if ([item.pathExtension.lowercaseString isEqualToString:@"mega"]) {
NSError *error = nil;
if (![[NSFileManager defaultManager] removeItemAtPath:[directory stringByAppendingPathComponent:item] error:&error]) {
MEGALogError(@"Remove item at path failed with error: %@", error);
}
}
}
}
}

- (void)startTimerAPI_EAGAIN {
timerAPI_EAGAIN = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(showServersTooBusy) userInfo:nil repeats:NO];
}
Expand Down Expand Up @@ -1499,11 +1476,7 @@ - (void)copyDatabasesForExtensions {
for (NSString *filename in applicationSupportContent) {
if ([filename containsString:@"megaclient"] || [filename containsString:@"karere"]) {
NSString *destinationPath = [groupSupportPath stringByAppendingPathComponent:filename];
if ([fileManager fileExistsAtPath:destinationPath]) {
if (![fileManager removeItemAtPath:destinationPath error:&error]) {
MEGALogError(@"Remove item at path failed with error: %@", error);
}
}
[NSFileManager.defaultManager mnz_removeItemAtPath:destinationPath];
if (![fileManager copyItemAtPath:[applicationSupportDirectoryString stringByAppendingPathComponent:filename] toPath:destinationPath error:&error]) {
MEGALogError(@"Copy item at path failed with error: %@", error);
}
Expand Down Expand Up @@ -1658,9 +1631,7 @@ - (void)renameAttributesAtPath:(NSString *)v2Path v3Path:(NSString *)v3Path {

if ([base64Filename isEqualToString:@"AAAAAAAA"]) {
if (attributePath.mnz_isImagePathExtension) {
if ([[NSFileManager defaultManager] fileExistsAtPath:attributePath]) {
[[NSFileManager defaultManager] removeItemAtPath:attributePath error:nil];
}
[NSFileManager.defaultManager mnz_removeItemAtPath:attributePath];
} else {
NSString *newAttributePath = [v3Path stringByAppendingPathComponent:attributeFilename];
[[NSFileManager defaultManager] moveItemAtPath:attributePath toPath:newAttributePath error:nil];
Expand All @@ -1675,24 +1646,18 @@ - (void)renameAttributesAtPath:(NSString *)v2Path v3Path:(NSString *)v3Path {
directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:v2Path error:nil];

if ([directoryContent count] == 0) {
if ([[NSFileManager defaultManager] fileExistsAtPath:v2Path]) {
[[NSFileManager defaultManager] removeItemAtPath:v2Path error:nil];
}
[NSFileManager.defaultManager mnz_removeItemAtPath:v2Path];
}
}

- (void)cameraUploadsSettingsCompatibility {
// PhotoSync old location of completed uploads
NSString *oldCompleted = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"PhotoSync/completed.plist"];
if ([[NSFileManager defaultManager] fileExistsAtPath:oldCompleted]) {
[[NSFileManager defaultManager] removeItemAtPath:oldCompleted error:nil];
}
[NSFileManager.defaultManager mnz_removeItemAtPath:oldCompleted];

// PhotoSync v2 location of completed uploads
NSString *v2Completed = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"PhotoSync/com.plist"];
if ([[NSFileManager defaultManager] fileExistsAtPath:v2Completed]) {
[[NSFileManager defaultManager] removeItemAtPath:v2Completed error:nil];
}
[NSFileManager.defaultManager mnz_removeItemAtPath:v2Completed];

// PhotoSync settings
NSString *oldPspPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"PhotoSync/psp.plist"];
Expand All @@ -1719,22 +1684,13 @@ - (void)cameraUploadsSettingsCompatibility {
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:NO] forKey:kIsUploadVideosEnabled];
}

[[NSFileManager defaultManager] removeItemAtPath:v2PspPath error:nil];
[NSFileManager.defaultManager mnz_removeItemAtPath:v2PspPath];
}
}

- (void)removeOldStateCache {
NSString *libraryDirectory = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:libraryDirectory error:nil];

for (NSString *item in directoryContent) {
if([item.pathExtension isEqualToString:@"db"]) {
NSString *stateCachePath = [libraryDirectory stringByAppendingPathComponent:item];
if ([[NSFileManager defaultManager] fileExistsAtPath:stateCachePath]) {
[[NSFileManager defaultManager] removeItemAtPath:stateCachePath error:nil];
}
}
}
[NSFileManager.defaultManager mnz_removeFolderContentsRecursivelyAtPath:libraryDirectory forItemsExtension:@"db"];
}

- (void)languageCompatibility {
Expand Down Expand Up @@ -1868,9 +1824,7 @@ - (void)onUsersUpdate:(MEGASdk *)api userList:(MEGAUserList *)userList {
if ([user hasChangedType:MEGAUserChangeTypeAvatar]) { //If you have changed your avatar, remove the old and request the new one
NSString *userBase64Handle = [MEGASdk base64HandleForUserHandle:user.handle];
NSString *avatarFilePath = [[Helper pathForSharedSandboxCacheDirectory:@"thumbnailsV3"] stringByAppendingPathComponent:userBase64Handle];
if ([[NSFileManager defaultManager] fileExistsAtPath:avatarFilePath]) {
[[NSFileManager defaultManager] removeItemAtPath:avatarFilePath error:nil];
}
[NSFileManager.defaultManager mnz_removeItemAtPath:avatarFilePath];
[[MEGASdkManager sharedMEGASdk] getAvatarUser:user destinationFilePath:avatarFilePath];
}

Expand All @@ -1891,9 +1845,7 @@ - (void)onUsersUpdate:(MEGASdk *)api userList:(MEGAUserList *)userList {
if ([user hasChangedType:MEGAUserChangeTypeAvatar]) {
NSString *userBase64Handle = [MEGASdk base64HandleForUserHandle:user.handle];
NSString *avatarFilePath = [[Helper pathForSharedSandboxCacheDirectory:@"thumbnailsV3"] stringByAppendingPathComponent:userBase64Handle];
if ([[NSFileManager defaultManager] fileExistsAtPath:avatarFilePath]) {
[[NSFileManager defaultManager] removeItemAtPath:avatarFilePath error:nil];
}
[NSFileManager.defaultManager mnz_removeItemAtPath:avatarFilePath];
[[MEGASdkManager sharedMEGASdk] getAvatarUser:user destinationFilePath:avatarFilePath];
}
if ([user hasChangedType:MEGAUserChangeTypeFirstname]) {
Expand Down Expand Up @@ -2058,13 +2010,14 @@ - (void)onRequestFinish:(MEGASdk *)api request:(MEGARequest *)request error:(MEG

case MEGAErrorTypeApiESid: {
if (self.urlType == URLTypeCancelAccountLink) {
self.urlType = URLTypeDefault;
[Helper logout];

UIAlertController *accountCanceledSuccessfullyAlertController = [UIAlertController alertControllerWithTitle:AMLocalizedString(@"accountCanceledSuccessfully", @"During account cancellation (deletion)") message:nil preferredStyle:UIAlertControllerStyleAlert];
[accountCanceledSuccessfullyAlertController addAction:[UIAlertAction actionWithTitle:AMLocalizedString(@"ok", @"Button title to accept something") style:UIAlertActionStyleCancel handler:nil]];

[UIApplication.mnz_visibleViewController presentViewController:accountCanceledSuccessfullyAlertController animated:YES completion:nil];
[UIApplication.mnz_visibleViewController presentViewController:accountCanceledSuccessfullyAlertController animated:YES completion:^{
self.urlType = URLTypeDefault;
}];
return;
}

Expand All @@ -2089,10 +2042,7 @@ - (void)onRequestFinish:(MEGASdk *)api request:(MEGARequest *)request error:(MEG
if ([request type] == MEGARequestTypeSetAttrFile) {
MEGANode *node = [api nodeForHandle:request.nodeHandle];
NSString *thumbnailFilePath = [Helper pathForNode:node inSharedSandboxCacheDirectory:@"thumbnailsV3"];
BOOL thumbnailExists = [[NSFileManager defaultManager] fileExistsAtPath:thumbnailFilePath];
if (thumbnailExists) {
[[NSFileManager defaultManager] removeItemAtPath:thumbnailFilePath error:nil];
}
[NSFileManager.defaultManager mnz_removeItemAtPath:thumbnailFilePath];
}

break;
Expand Down Expand Up @@ -2279,6 +2229,18 @@ - (void)onRequestFinish:(MEGASdk *)api request:(MEGARequest *)request error:(MEG
} else if (self.urlType == URLTypeCancelAccountLink) {
[self presentConfirmViewControllerType:ConfirmTypeCancelAccount link:request.link email:request.email];
} else if (self.urlType == URLTypeRecoverLink) {
if ([UIApplication.sharedApplication.keyWindow.rootViewController isKindOfClass:MEGANavigationController.class]) {
MEGANavigationController *navigationController = (MEGANavigationController *)UIApplication.sharedApplication.keyWindow.rootViewController;
if ([navigationController.topViewController isKindOfClass:TwoFactorAuthenticationViewController.class]) {
[navigationController popViewControllerAnimated:NO];

if ([navigationController.topViewController isKindOfClass:LoginViewController.class]) {
LoginViewController *loginVC = (LoginViewController *)navigationController.topViewController;
[loginVC cleanPasswordTextField];
}
}
}

if (request.flag) {
UIAlertController *masterKeyLoggedInAlertController;
if ([SAMKeychain passwordForService:@"MEGA" account:@"sessionV3"]) {
Expand Down
6 changes: 3 additions & 3 deletions iMEGA/Camera uploads/MEGAAssetOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ - (void)main {
if (![[NSFileManager defaultManager] moveItemAtPath:absoluteFilePath toPath:newFilePath error:&error]) {
MEGALogError(@"Move item at path failed with error: %@", error);
}
[[MEGASdkManager sharedMEGASdk] startUploadWithLocalPath:[newFilePath stringByReplacingOccurrencesOfString:[NSHomeDirectory() stringByAppendingString:@"/"] withString:@""] parent:self.parentNode appData:appData isSourceTemporary:YES delegate:self];
[[MEGASdkManager sharedMEGASdk] startUploadWithLocalPath:newFilePath.mnz_relativeLocalPath parent:self.parentNode appData:appData isSourceTemporary:YES delegate:self];
} else {
[[MEGASdkManager sharedMEGASdk] startUploadWithLocalPath:[filePath stringByReplacingOccurrencesOfString:[NSHomeDirectory() stringByAppendingString:@"/"] withString:@""] parent:self.parentNode appData:appData isSourceTemporary:YES delegate:self];
[[MEGASdkManager sharedMEGASdk] startUploadWithLocalPath:filePath.mnz_relativeLocalPath parent:self.parentNode appData:appData isSourceTemporary:YES delegate:self];
}
} node:^(MEGANode *node) {
if ([[[MEGASdkManager sharedMEGASdk] parentNodeForNode:node] handle] == self.parentNode.handle) {
Expand Down Expand Up @@ -241,7 +241,7 @@ - (void)onTransferFinish:(MEGASdk *)api transfer:(MEGATransfer *)transfer error:
} else {
[self completeOperation];
}
} else if (self.isCameraUploads) {
} else if (self.isCameraUploads && api.isLoggedIn) {
[[CameraUploads syncManager] resetOperationQueue];
}
return;
Expand Down
Loading

0 comments on commit 9c92484

Please sign in to comment.