浏览代码

httpDownloader: check for available space left on device prior to downloading

Signed-off-by: Felix Paul Kühne <fkuehne@videolan.org>
Pierre SAGASPE 10 年之前
父节点
当前提交
d7e19aa01e
共有 1 个文件被更改,包括 9 次插入1 次删除
  1. 9 1
      Sources/VLCHTTPFileDownloader.m

+ 9 - 1
Sources/VLCHTTPFileDownloader.m

@@ -14,6 +14,7 @@
 #import "VLCHTTPFileDownloader.h"
 #import "NSString+SupportedMedia.h"
 #import "VLCAppDelegate.h"
+#import "UIDevice+VLC.h"
 
 @interface VLCHTTPFileDownloader ()
 {
@@ -122,7 +123,14 @@
             [self _downloadEnded];
         } else {
             _expectedDownloadSize = [response expectedContentLength];
-            [self.delegate downloadStarted];
+            if (_expectedDownloadSize  < [[UIDevice currentDevice] freeDiskspace].longLongValue)
+                [self.delegate downloadStarted];
+            else {
+                [_urlConnection cancel];
+                [self _downloadEnded];
+                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"DISK_FULL", nil) message:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), _fileName, [[UIDevice currentDevice] model]] delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil) otherButtonTitles:nil];
+                [alert show];
+            }
             APLog(@"expected download size: %lu", (unsigned long)_expectedDownloadSize);
         }
     } else {