import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.http.HttpStatus;
import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.files.services.FileDownloader;
import com.owncloud.android.operations.RemoteOperation;
import com.owncloud.android.operations.RemoteOperationResult;
+import com.owncloud.android.utils.FileStorageUtils;
import eu.alefzero.webdav.OnDatatransferProgressListener;
import eu.alefzero.webdav.WebdavClient;
*/
public class DownloadFileOperation extends RemoteOperation {
- private static final String TAG = DownloadFileOperation.class.getCanonicalName();
+ private static final String TAG = DownloadFileOperation.class.getSimpleName();
- private Account mAccount = null;
+ private Account mAccount;
private OCFile mFile;
- private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
-
private Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();
+ private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
+ private long mModificationTimestamp = 0;
public DownloadFileOperation(Account account, OCFile file) {
}
public String getSavePath() {
- return FileDownloader.getSavePath(mAccount.name) + mFile.getRemotePath();
+ String path = mFile.getStoragePath(); // re-downloads should be done over the original file
+ if (path != null && path.length() > 0) {
+ return path;
+ }
+ return FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile);
}
public String getTmpPath() {
- return FileDownloader.getTemporalPath(mAccount.name) + mFile.getRemotePath();
+ return FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath();
}
public String getRemotePath() {
return mFile.getFileLength();
}
+ public long getModificationTimestamp() {
+ return (mModificationTimestamp > 0) ? mModificationTimestamp : mFile.getModificationTimestamp();
+ }
+
public void addDatatransferProgressListener (OnDatatransferProgressListener listener) {
mDataTransferListeners.add(listener);
protected RemoteOperationResult run(WebdavClient client) {
RemoteOperationResult result = null;
File newFile = null;
- boolean moved = false;
+ boolean moved = true;
/// download will be performed to a temporal file, then moved to the final location
File tmpFile = new File(getTmpPath());
}
}
savedFile = true;
+ Header modificationTime = get.getResponseHeader("Last-Modified");
+ if (modificationTime != null) {
+ Date d = WebdavUtils.parseResponseDate((String) modificationTime.getValue());
+ mModificationTimestamp = (d != null) ? d.getTime() : 0;
+ }
} else {
client.exhaustResponse(get.getResponseBodyAsStream());