Commit 6f49af0b authored by Felix Paul Kühne's avatar Felix Paul Kühne

downloads: let the user download anything over http and save it in a way it is...

downloads: let the user download anything over http and save it in a way it is displayed in the library (closes #16928)

It's the user's responsibility if it doesn't play
parent ff70ae0d
......@@ -114,20 +114,11 @@
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"])) {
if ([URLtoSave.lastPathComponent isSupportedFormat] || [URLtoSave.lastPathComponent.pathExtension isEqualToString:@""]) {
[_currentDownloads addObject:URLtoSave];
[_currentDownloadFilename addObject:@""];
self.urlField.text = @"";
[self.downloadsTable reloadData];
[self _triggerNextDownload];
} else {
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];
}
[_currentDownloads addObject:URLtoSave];
[_currentDownloadFilename addObject:@""];
self.urlField.text = @"";
[self.downloadsTable reloadData];
[self _triggerNextDownload];
} else {
VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"SCHEME_NOT_SUPPORTED", nil)
message:[NSString stringWithFormat:NSLocalizedString(@"SCHEME_NOT_SUPPORTED_LONG", nil), URLtoSave.scheme]
......
......@@ -50,6 +50,11 @@
_fileName = fileName;
else
_fileName = [url.lastPathComponent stringByRemovingPercentEncoding];
if (_fileName.pathExtension.length == 0 || ![_fileName isSupportedFormat]) {
_fileName = [_fileName stringByAppendingPathExtension:@"vlc"];
}
_filePath = [basePath stringByAppendingPathComponent:_fileName];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:basePath])
......@@ -98,34 +103,19 @@
{
_statusCode = [response statusCode];
if (_statusCode == 200) {
if (![[response suggestedFilename] isSupportedFormat]) {
VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", nil)
message:[NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", nil), [response suggestedFilename]]
_expectedDownloadSize = [response expectedContentLength];
APLog(@"expected download size: %lli", _expectedDownloadSize);
if (_expectedDownloadSize < [[UIDevice currentDevice] freeDiskspace].longLongValue)
[self.delegate downloadStarted];
else {
[_urlConnection cancel];
[self _downloadEnded];
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_CANCEL", nil)
cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil)
otherButtonTitles:nil];
[alert show];
[_urlConnection cancel];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:_filePath])
[fileManager removeItemAtPath:_filePath error:nil];
[self _downloadEnded];
} else {
_expectedDownloadSize = [response expectedContentLength];
APLog(@"expected download size: %lli", _expectedDownloadSize);
if (_expectedDownloadSize < [[UIDevice currentDevice] freeDiskspace].longLongValue)
[self.delegate downloadStarted];
else {
[_urlConnection cancel];
[self _downloadEnded];
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];
}
}
} else {
APLog(@"unhandled status code %lu", (unsigned long)_statusCode);
......
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