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 @@
"ERROR_NUMBER" = "Error %i occured";
"DOWNLOAD_FAILED" = "Download failed";
"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_LONG" = "The address scheme (%@) is not supported. Please use an address starting with HTTP, HTTPS or FTP.";
"LIBRARY_ALL_FILES" = "All Files";
......
......@@ -120,20 +120,31 @@ typedef NS_ENUM(NSUInteger, VLCDownloadScheme) {
{
if ([self.urlField.text length] > 0) {
NSURL *URLtoSave = [NSURL URLWithString:self.urlField.text];
if (([URLtoSave.scheme isEqualToString:@"http"] || [URLtoSave.scheme isEqualToString:@"https"] || [URLtoSave.scheme isEqualToString:@"ftp"])) {
[_currentDownloads addObject:URLtoSave];
[_currentDownloadFilename addObject:@""];
self.urlField.text = @"";
[self.downloadsTable reloadData];
[self _triggerNextDownload];
} else {
if (![URLtoSave.lastPathComponent isSupportedFormat] && ![URLtoSave.lastPathComponent.pathExtension isEqualToString:@""]) {
VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", nil)
message:[NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", nil), URLtoSave.lastPathComponent]
delegate:self
cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
otherButtonTitles:nil];
[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)
message:[NSString stringWithFormat:NSLocalizedString(@"SCHEME_NOT_SUPPORTED_LONG", nil), URLtoSave.scheme]
delegate:self
cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
otherButtonTitles:nil];
[alert show];
return;
}
[_currentDownloads addObject:URLtoSave];
[_currentDownloadFilename addObject:@""];
self.urlField.text = @"";
[self.downloadsTable reloadData];
[self _triggerNextDownload];
}
}
......
......@@ -105,18 +105,28 @@
if (_statusCode == 200) {
_expectedDownloadSize = [response expectedContentLength];
APLog(@"expected download size: %lli", _expectedDownloadSize);
if (_expectedDownloadSize < [[UIDevice currentDevice] VLCFreeDiskSpace].longLongValue)
[self.delegate downloadStarted];
else {
if (![[response suggestedFilename] isSupportedFormat]) { //handle unsupported format
VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", nil)
message:[NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", nil), [response suggestedFilename]]
cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil)
otherButtonTitles:nil];
[alert show];
[_urlConnection cancel];
[self _downloadEnded];
return;
}
if (_expectedDownloadSize > [[UIDevice currentDevice] VLCFreeDiskSpace].longLongValue) { //handle too big a download
VLCAlertView *alert = [[VLCAlertView 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];
[_urlConnection cancel];
[self _downloadEnded];
return;
}
[self.delegate downloadStarted];
} else {
APLog(@"unhandled status code %lu", (unsigned long)_statusCode);
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