Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
VideoLAN
VLC-iOS
Commits
862b0df7
Commit
862b0df7
authored
Jun 16, 2013
by
Felix Paul Kühne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dropbox: prevent concurrent downloads
parent
79397cbb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
5 deletions
+50
-5
AspenProject/VLCDropboxController.h
AspenProject/VLCDropboxController.h
+3
-0
AspenProject/VLCDropboxController.m
AspenProject/VLCDropboxController.m
+47
-5
No files found.
AspenProject/VLCDropboxController.h
View file @
862b0df7
...
...
@@ -18,6 +18,8 @@
-
(
void
)
operationWithProgressInformationStarted
;
-
(
void
)
currentProgressInformation
:(
float
)
progress
;
-
(
void
)
operationWithProgressInformationStopped
;
-
(
void
)
numberOfFilesWaitingToBeDownloadedChanged
;
@end
@interface
VLCDropboxController
:
NSObject
<
DBRestClientDelegate
,
DBSessionDelegate
,
DBNetworkRequestDelegate
>
...
...
@@ -25,6 +27,7 @@
@property
(
nonatomic
,
retain
)
id
delegate
;
@property
(
nonatomic
,
readonly
)
NSArray
*
currentListFiles
;
@property
(
nonatomic
,
readonly
)
BOOL
sessionIsLinked
;
@property
(
nonatomic
,
readonly
)
NSInteger
numberOfFilesWaitingToBeDownloaded
;
-
(
void
)
startSession
;
-
(
void
)
logout
;
...
...
AspenProject/VLCDropboxController.m
View file @
862b0df7
...
...
@@ -17,6 +17,9 @@
DBRestClient
*
_restClient
;
NSArray
*
_currentFileList
;
NSMutableArray
*
_listOfDropboxFilesToDownload
;
BOOL
_downloadInProgress
;
NSInteger
_outstandingNetworkRequests
;
}
...
...
@@ -58,16 +61,41 @@
-
(
void
)
downloadFileToDocumentFolder
:(
DBMetadata
*
)
file
{
if
(
!
file
.
isDirectory
)
{
NSArray
*
searchPaths
=
NSSearchPathForDirectoriesInDomains
(
NSDocumentDirectory
,
NSUserDomainMask
,
YES
);
NSString
*
filePath
=
[
searchPaths
[
0
]
stringByAppendingFormat
:
@"/%@"
,
file
.
filename
];
if
(
!
_listOfDropboxFilesToDownload
)
_listOfDropboxFilesToDownload
=
[[
NSMutableArray
alloc
]
init
];
[
_listOfDropboxFilesToDownload
addObject
:
file
];
[[
self
restClient
]
loadFile
:
file
.
path
intoPath
:
filePath
];
if
([
self
.
delegate
respondsToSelector
:
@selector
(
numberOfFilesWaitingToBeDownloadedChanged
)])
[
self
.
delegate
numberOfFilesWaitingToBeDownloadedChanged
];
if
([
self
.
delegate
respondsToSelector
:
@selector
(
operationWithProgressInformationStarted
)])
[
self
.
delegate
operationWithProgressInformationStarted
];
[
self
_triggerNextDownload
];
}
}
-
(
void
)
_triggerNextDownload
{
if
(
_listOfDropboxFilesToDownload
.
count
>
0
&&
!
_downloadInProgress
)
{
[
self
_reallyDownloadFileToDocumentFolder
:
_listOfDropboxFilesToDownload
[
0
]];
[
_listOfDropboxFilesToDownload
removeObjectAtIndex
:
0
];
if
([
self
.
delegate
respondsToSelector
:
@selector
(
numberOfFilesWaitingToBeDownloadedChanged
)])
[
self
.
delegate
numberOfFilesWaitingToBeDownloadedChanged
];
}
}
-
(
void
)
_reallyDownloadFileToDocumentFolder
:(
DBMetadata
*
)
file
{
NSArray
*
searchPaths
=
NSSearchPathForDirectoriesInDomains
(
NSDocumentDirectory
,
NSUserDomainMask
,
YES
);
NSString
*
filePath
=
[
searchPaths
[
0
]
stringByAppendingFormat
:
@"/%@"
,
file
.
filename
];
[[
self
restClient
]
loadFile
:
file
.
path
intoPath
:
filePath
];
if
([
self
.
delegate
respondsToSelector
:
@selector
(
operationWithProgressInformationStarted
)])
[
self
.
delegate
operationWithProgressInformationStarted
];
_downloadInProgress
=
YES
;
}
#pragma mark - restClient delegate
-
(
BOOL
)
_supportedFileExtension
:(
NSString
*
)
filename
{
...
...
@@ -110,6 +138,9 @@
if
([
self
.
delegate
respondsToSelector
:
@selector
(
operationWithProgressInformationStopped
)])
[
self
.
delegate
operationWithProgressInformationStopped
];
_downloadInProgress
=
NO
;
[
self
_triggerNextDownload
];
}
-
(
void
)
restClient
:(
DBRestClient
*
)
client
loadFileFailedWithError
:(
NSError
*
)
error
...
...
@@ -117,6 +148,9 @@
APLog
(
@"DBFile download failed with error %i"
,
error
.
code
);
if
([
self
.
delegate
respondsToSelector
:
@selector
(
operationWithProgressInformationStopped
)])
[
self
.
delegate
operationWithProgressInformationStopped
];
_downloadInProgress
=
NO
;
[
self
_triggerNextDownload
];
}
-
(
void
)
restClient
:(
DBRestClient
*
)
client
loadProgress
:(
CGFloat
)
progress
forFile
:(
NSString
*
)
destPath
...
...
@@ -154,4 +188,12 @@
return
_currentFileList
;
}
-
(
NSInteger
)
numberOfFilesWaitingToBeDownloaded
{
if
(
_listOfDropboxFilesToDownload
)
return
_listOfDropboxFilesToDownload
.
count
;
return
0
;
}
@end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment