Commit e9870f66 authored by Carola Nitz's avatar Carola Nitz

VLCHTTPFileDownloader: only download files that are supported by VLC

This essentially reverts commit 95ad1b17
We ended up with a succesful download for a not supported format which we then didn't display in the library.
The user couldn't play or delete the downloaded file.
Instead of showing not supported files in the library, we're not allowing downloads in the first place.
parent cdd386fc
...@@ -97,6 +97,7 @@ ...@@ -97,6 +97,7 @@
"ERROR_NUMBER" = "Error %i occured"; "ERROR_NUMBER" = "Error %i occured";
"DOWNLOAD_FAILED" = "Download failed"; "DOWNLOAD_FAILED" = "Download failed";
"FILE_NOT_SUPPORTED" = "File format not supported"; "FILE_NOT_SUPPORTED" = "File format not supported";
"FILE_NOT_SUPPORTED_LONG" = "The file format used by %@ is not supported by this version of VLC for iOS.";
"SCHEME_NOT_SUPPORTED" = "Address scheme not supported"; "SCHEME_NOT_SUPPORTED" = "Address scheme not supported";
"SCHEME_NOT_SUPPORTED_LONG" = "The address scheme (%@) is not supported. Please use an address starting with HTTP, HTTPS or FTP."; "SCHEME_NOT_SUPPORTED_LONG" = "The address scheme (%@) is not supported. Please use an address starting with HTTP, HTTPS or FTP.";
"LIBRARY_ALL_FILES" = "All Files"; "LIBRARY_ALL_FILES" = "All Files";
......
...@@ -120,20 +120,31 @@ typedef NS_ENUM(NSUInteger, VLCDownloadScheme) { ...@@ -120,20 +120,31 @@ typedef NS_ENUM(NSUInteger, VLCDownloadScheme) {
{ {
if ([self.urlField.text length] > 0) { if ([self.urlField.text length] > 0) {
NSURL *URLtoSave = [NSURL URLWithString:self.urlField.text]; NSURL *URLtoSave = [NSURL URLWithString:self.urlField.text];
if (([URLtoSave.scheme isEqualToString:@"http"] || [URLtoSave.scheme isEqualToString:@"https"] || [URLtoSave.scheme isEqualToString:@"ftp"])) { if (![URLtoSave.lastPathComponent isSupportedFormat] && ![URLtoSave.lastPathComponent.pathExtension isEqualToString:@""]) {
[_currentDownloads addObject:URLtoSave]; VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", nil)
[_currentDownloadFilename addObject:@""]; message:[NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", nil), URLtoSave.lastPathComponent]
self.urlField.text = @""; delegate:self
[self.downloadsTable reloadData]; cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
[self _triggerNextDownload]; otherButtonTitles:nil];
} else { [alert show];
return;
}
if (![URLtoSave.scheme isEqualToString:@"http"] & ![URLtoSave.scheme isEqualToString:@"https"] && ![URLtoSave.scheme isEqualToString:@"ftp"]) {
VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"SCHEME_NOT_SUPPORTED", nil) VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"SCHEME_NOT_SUPPORTED", nil)
message:[NSString stringWithFormat:NSLocalizedString(@"SCHEME_NOT_SUPPORTED_LONG", nil), URLtoSave.scheme] message:[NSString stringWithFormat:NSLocalizedString(@"SCHEME_NOT_SUPPORTED_LONG", nil), URLtoSave.scheme]
delegate:self delegate:self
cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil) cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
otherButtonTitles:nil]; otherButtonTitles:nil];
[alert show]; [alert show];
return;
} }
[_currentDownloads addObject:URLtoSave];
[_currentDownloadFilename addObject:@""];
self.urlField.text = @"";
[self.downloadsTable reloadData];
[self _triggerNextDownload];
} }
} }
......
...@@ -105,18 +105,28 @@ ...@@ -105,18 +105,28 @@
if (_statusCode == 200) { if (_statusCode == 200) {
_expectedDownloadSize = [response expectedContentLength]; _expectedDownloadSize = [response expectedContentLength];
APLog(@"expected download size: %lli", _expectedDownloadSize); APLog(@"expected download size: %lli", _expectedDownloadSize);
if (_expectedDownloadSize < [[UIDevice currentDevice] VLCFreeDiskSpace].longLongValue) if (![[response suggestedFilename] isSupportedFormat]) { //handle unsupported format
[self.delegate downloadStarted]; VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", nil)
else { message:[NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", nil), [response suggestedFilename]]
cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil)
otherButtonTitles:nil];
[alert show];
[_urlConnection cancel]; [_urlConnection cancel];
[self _downloadEnded]; [self _downloadEnded];
return;
}
if (_expectedDownloadSize > [[UIDevice currentDevice] VLCFreeDiskSpace].longLongValue) { //handle too big a download
VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"DISK_FULL", nil) VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"DISK_FULL", nil)
message:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), _fileName, [[UIDevice currentDevice] model]] message:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), _fileName, [[UIDevice currentDevice] model]]
delegate:self delegate:self
cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil) cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil)
otherButtonTitles:nil]; otherButtonTitles:nil];
[alert show]; [alert show];
[_urlConnection cancel];
[self _downloadEnded];
return;
} }
[self.delegate downloadStarted];
} else { } else {
APLog(@"unhandled status code %lu", (unsigned long)_statusCode); APLog(@"unhandled status code %lu", (unsigned long)_statusCode);
if ([self.delegate respondsToSelector:@selector(downloadFailedWithErrorDescription:)]) if ([self.delegate respondsToSelector:@selector(downloadFailedWithErrorDescription:)])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment