X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/f3ba107585a68d4108a546f30bf71e13fd22f6ec..9ae0e1746ad60925dc18e19d2f63f5780ec75872:/src/eu/alefzero/owncloud/files/services/FileDownloader.java diff --git a/src/eu/alefzero/owncloud/files/services/FileDownloader.java b/src/eu/alefzero/owncloud/files/services/FileDownloader.java index 1b510cb7..b0dd2b26 100644 --- a/src/eu/alefzero/owncloud/files/services/FileDownloader.java +++ b/src/eu/alefzero/owncloud/files/services/FileDownloader.java @@ -13,6 +13,7 @@ import android.app.PendingIntent; import android.app.Service; import android.content.ContentValues; import android.content.Intent; +import android.net.Uri; import android.os.Environment; import android.os.Handler; import android.os.HandlerThread; @@ -35,7 +36,8 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis public static final String EXTRA_FILE_PATH = "FILE_PATH"; public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH"; public static final String EXTRA_FILE_SIZE = "FILE_SIZE"; - public static final String ACCOUNT_NAME = "ACCOUNT_NAME"; + public static final String ACCOUNT_NAME = "ACCOUNT_NAME"; + private static final String TAG = "FileDownloader"; private NotificationManager mNotificationMngr; @@ -81,14 +83,16 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis } } - public static final String getSavePath() { + public static final String getSavePath(String accountName) { File sdCard = Environment.getExternalStorageDirectory(); - return sdCard.getAbsolutePath() + "/owncloud/"; + return sdCard.getAbsolutePath() + "/owncloud/" + Uri.encode(accountName, "@"); + // URL encoding is an 'easy fix' to overcome that NTFS and FAT32 don't allow ":" in file names, that can be in the accountName since 0.1.190B } - public static final String getTemporalPath() { + public static final String getTemporalPath(String accountName) { File sdCard = Environment.getExternalStorageDirectory(); - return sdCard.getAbsolutePath() + "/owncloud.tmp/"; + return sdCard.getAbsolutePath() + "/owncloud/tmp/" + Uri.encode(accountName, "@"); + // URL encoding is an 'easy fix' to overcome that NTFS and FAT32 don't allow ":" in file names, that can be in the accountName since 0.1.190B } @Override @@ -154,7 +158,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis /// download will be in a temporal file - File tmpFile = new File(getTemporalPath() + mAccount.name + mFilePath); + File tmpFile = new File(getTemporalPath(mAccount.name) + mFilePath); /// create status notification to show the download progress mNotification = new Notification(R.drawable.icon, getString(R.string.downloader_download_in_progress_ticker), System.currentTimeMillis()); @@ -172,26 +176,29 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis tmpFile.getParentFile().mkdirs(); mDownloadsInProgress.put(buildRemoteName(mAccount.name, mRemotePath), tmpFile.getAbsolutePath()); File newFile = null; - if (wdc.downloadFile(mRemotePath, tmpFile)) { - newFile = new File(getSavePath() + mAccount.name + mFilePath); - newFile.getParentFile().mkdirs(); - boolean moved = tmpFile.renameTo(newFile); + try { + if (wdc.downloadFile(mRemotePath, tmpFile)) { + newFile = new File(getSavePath(mAccount.name) + mFilePath); + newFile.getParentFile().mkdirs(); + boolean moved = tmpFile.renameTo(newFile); - if (moved) { - ContentValues cv = new ContentValues(); - cv.put(ProviderTableMeta.FILE_STORAGE_PATH, newFile.getAbsolutePath()); - getContentResolver().update( - ProviderTableMeta.CONTENT_URI, - cv, - ProviderTableMeta.FILE_NAME + "=? AND " - + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?", - new String[] { - mFilePath.substring(mFilePath.lastIndexOf('/') + 1), - mAccount.name }); - downloadResult = true; + if (moved) { + ContentValues cv = new ContentValues(); + cv.put(ProviderTableMeta.FILE_STORAGE_PATH, newFile.getAbsolutePath()); + getContentResolver().update( + ProviderTableMeta.CONTENT_URI, + cv, + ProviderTableMeta.FILE_NAME + "=? AND " + + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?", + new String[] { + mFilePath.substring(mFilePath.lastIndexOf('/') + 1), + mAccount.name }); + downloadResult = true; + } } + } finally { + mDownloadsInProgress.remove(buildRemoteName(mAccount.name, mRemotePath)); } - mDownloadsInProgress.remove(buildRemoteName(mAccount.name, mRemotePath)); /// notify result