Commit f6420e75 authored by Felix Paul Kühne's avatar Felix Paul Kühne

http file downloader: don't let MLKit get hold of a partially downloaded file

instead, download to the same cache folder we are using for wifi upload
parent 64cd4782
......@@ -35,9 +35,9 @@
- (void)downloadFileFromURL:(NSURL *)url
{
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
_fileName = url.lastPathComponent;
_filePath = [searchPaths[0] stringByAppendingPathComponent:_fileName];
_filePath = [[searchPaths[0] stringByAppendingPathComponent:@"Upload"] stringByAppendingPathComponent:_fileName];
_expectedDownloadSize = _receivedDataSize = 0;
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
_urlConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
......@@ -53,9 +53,9 @@
- (void)downloadFileFromURLwithFileName:(NSURL *)url fileNameOfMedia:(NSString*) fileName
{
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
_fileName = fileName;
_filePath = [searchPaths[0] stringByAppendingPathComponent:_fileName];
_filePath = [[searchPaths[0] stringByAppendingPathComponent:@"Upload"] stringByAppendingPathComponent:_fileName];
_expectedDownloadSize = _receivedDataSize = 0;
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
_urlConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
......@@ -116,8 +116,6 @@
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
APLog(@"http file download complete");
VLCAppDelegate * appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate performSelectorOnMainThread:@selector(updateMediaList) withObject:nil waitUntilDone:NO];
[self _downloadEnded];
}
......@@ -152,6 +150,18 @@
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate activateIdleTimer];
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *libraryPath = searchPaths[0];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *finalFilePath = [libraryPath stringByAppendingPathComponent:_fileName];
if ([fileManager fileExistsAtPath:_filePath]) {
[fileManager moveItemAtPath:_filePath toPath:finalFilePath error:nil];
VLCAppDelegate * appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate performSelectorOnMainThread:@selector(updateMediaList) withObject:nil waitUntilDone:NO];
}
[self.delegate downloadEnded];
}
......
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