Browse Source

app delegate: fix major leak of data transmitted by 3rd party apps (close #9011)

The input folder was never emptied and therefore stacking up every media opened from within another app. The implemented solution moves received data directly to Documents without asking the user if s/he would like to save it or not. This matches iBooks behavior and many other apps
Felix Paul Kühne 12 years ago
parent
commit
9a21057f55
1 changed files with 9 additions and 20 deletions
  1. 9 20
      AspenProject/VLCAppDelegate.m

+ 9 - 20
AspenProject/VLCAppDelegate.m

@@ -20,7 +20,6 @@
 #import "UINavigationController+Theme.h"
 
 @interface VLCAppDelegate () <PAPasscodeViewControllerDelegate, DirectoryWatcherDelegate> {
-    NSURL *_tempURL;
     PAPasscodeViewController *_passcodeLockController;
     VLCDropboxTableViewController *_dropboxTableViewController;
 
@@ -81,9 +80,15 @@
         APLog(@"%@ requested %@ to be opened", sourceApplication, url);
 
         if (url.isFileURL) {
-            UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"SAVE_FILE", @"") message:[NSString stringWithFormat:NSLocalizedString(@"SAVE_FILE_LONG", @""), url.lastPathComponent] delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", @"") otherButtonTitles:NSLocalizedString(@"BUTTON_SAVE", @""), nil];
-            _tempURL = url;
-            [alert show];
+            NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+            NSString *directoryPath = searchPaths[0];
+            NSURL *destinationURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", directoryPath, url.lastPathComponent]];
+            NSError *theError;
+            [[NSFileManager defaultManager] moveItemAtURL:url toURL:destinationURL error:&theError];
+            if (theError.code != noErr)
+                APLog(@"saving the file failed (%i): %@", theError.code, theError.localizedDescription);
+
+            [self updateMediaList];
         } else {
             NSURL *parsedUrl = [self parseOpenURL:url];
             [_playlistViewController openMovieFromURL:parsedUrl];
@@ -120,22 +125,6 @@
     return url;
 }
 
-- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
-{
-    if (buttonIndex == 1) {
-        NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
-        NSString *directoryPath = searchPaths[0];
-        NSURL *destinationURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", directoryPath, _tempURL.lastPathComponent]];
-        NSError *theError;
-        [[NSFileManager defaultManager] copyItemAtURL:_tempURL toURL:destinationURL error:&theError];
-        if (theError.code != noErr)
-            APLog(@"saving the file failed (%i): %@", theError.code, theError.localizedDescription);
-
-        [self updateMediaList];
-    } else
-        [_playlistViewController openMovieFromURL:_tempURL];
-}
-
 - (void)applicationWillResignActive:(UIApplication *)application
 {
     [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];