Browse Source

URL handling: add error handling and behave correctly when saving files

Felix Paul Kühne 12 years ago
parent
commit
f73746474a
1 changed files with 6 additions and 5 deletions
  1. 6 5
      AspenProject/VLCAppDelegate.m

+ 6 - 5
AspenProject/VLCAppDelegate.m

@@ -43,7 +43,7 @@
     if (_playlistViewController && url != nil) {
         APLog(@"%@ requested %@ to be opened", sourceApplication, url);
 
-        if (url.isFileURL || [url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"]) {
+        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];
@@ -59,14 +59,15 @@
     if (buttonIndex == 1) {
         NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
         NSString *directoryPath = searchPaths[0];
-        NSURL *destinationURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@/%@", directoryPath, _tempURL.lastPathComponent]];
+        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];
-    }
-
-    [_playlistViewController openMovieFromURL:_tempURL];
+    } else
+        [_playlistViewController openMovieFromURL:_tempURL];
 }
 
 - (void)applicationWillResignActive:(UIApplication *)application