Granted that accounts different only in port number won't mix their files in the...
authorDavid A. Velasco <dvelasco@solidgear.es>
Mon, 30 Jul 2012 10:02:34 +0000 (12:02 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Mon, 30 Jul 2012 10:02:34 +0000 (12:02 +0200)
AndroidManifest.xml
src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java
src/eu/alefzero/owncloud/files/services/FileDownloader.java
src/eu/alefzero/owncloud/ui/activity/AuthenticatorActivity.java

index 597c27b..4c27b14 100644 (file)
@@ -18,7 +18,7 @@
  -->\r
 <manifest package="eu.alefzero.owncloud"\r
     android:versionCode="1"\r
  -->\r
 <manifest package="eu.alefzero.owncloud"\r
     android:versionCode="1"\r
-    android:versionName="0.1.189B" xmlns:android="http://schemas.android.com/apk/res/android">\r
+    android:versionName="0.1.190B" xmlns:android="http://schemas.android.com/apk/res/android">\r
 \r
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />\r
     <uses-permission android:name="android.permission.USE_CREDENTIALS" />\r
 \r
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />\r
     <uses-permission android:name="android.permission.USE_CREDENTIALS" />\r
index b6fa918..f0d0db2 100644 (file)
@@ -27,6 +27,7 @@ import java.util.Vector;
 
 import eu.alefzero.owncloud.db.ProviderMeta;
 import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
 
 import eu.alefzero.owncloud.db.ProviderMeta;
 import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
+import eu.alefzero.owncloud.files.services.FileDownloader;
 import android.accounts.Account;
 import android.content.ContentProviderClient;
 import android.content.ContentProviderOperation;
 import android.accounts.Account;
 import android.content.ContentProviderClient;
 import android.content.ContentProviderOperation;
@@ -378,8 +379,7 @@ public class FileDataStorageManager implements DataStorageManager {
                         .getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)));
                 if (file.getStoragePath() == null) {
                     // try to find existing file and bind it with current account
                         .getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)));
                 if (file.getStoragePath() == null) {
                     // try to find existing file and bind it with current account
-                    File sdCard = Environment.getExternalStorageDirectory();
-                    File f = new File(sdCard.getAbsolutePath() + "/owncloud/" + mAccount.name + file.getRemotePath());
+                    File f = new File(FileDownloader.getSavePath(mAccount.name) + file.getRemotePath());
                     if (f.exists())
                         file.setStoragePath(f.getAbsolutePath());
                 }
                     if (f.exists())
                         file.setStoragePath(f.getAbsolutePath());
                 }
index af327a5..b0dd2b2 100644 (file)
@@ -13,6 +13,7 @@ import android.app.PendingIntent;
 import android.app.Service;\r
 import android.content.ContentValues;\r
 import android.content.Intent;\r
 import android.app.Service;\r
 import android.content.ContentValues;\r
 import android.content.Intent;\r
+import android.net.Uri;\r
 import android.os.Environment;\r
 import android.os.Handler;\r
 import android.os.HandlerThread;\r
 import android.os.Environment;\r
 import android.os.Handler;\r
 import android.os.HandlerThread;\r
@@ -82,14 +83,16 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
         }\r
     }\r
     \r
         }\r
     }\r
     \r
-    public static final String getSavePath() {\r
+    public static final String getSavePath(String accountName) {\r
         File sdCard = Environment.getExternalStorageDirectory();\r
         File sdCard = Environment.getExternalStorageDirectory();\r
-        return sdCard.getAbsolutePath() + "/owncloud/";\r
+        return sdCard.getAbsolutePath() + "/owncloud/" + Uri.encode(accountName, "@");   \r
+            // 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\r
     }\r
     \r
     }\r
     \r
-    public static final String getTemporalPath() {\r
+    public static final String getTemporalPath(String accountName) {\r
         File sdCard = Environment.getExternalStorageDirectory();\r
         File sdCard = Environment.getExternalStorageDirectory();\r
-        return sdCard.getAbsolutePath() + "/owncloud.tmp/";\r
+        return sdCard.getAbsolutePath() + "/owncloud/tmp/" + Uri.encode(accountName, "@");\r
+            // 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\r
     }\r
 \r
     @Override\r
     }\r
 \r
     @Override\r
@@ -155,7 +158,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
 \r
         \r
         /// download will be in a temporal file\r
 \r
         \r
         /// download will be in a temporal file\r
-        File tmpFile = new File(getTemporalPath() + mAccount.name + mFilePath);\r
+        File tmpFile = new File(getTemporalPath(mAccount.name) + mFilePath);\r
         \r
         /// create status notification to show the download progress\r
         mNotification = new Notification(R.drawable.icon, getString(R.string.downloader_download_in_progress_ticker), System.currentTimeMillis());\r
         \r
         /// create status notification to show the download progress\r
         mNotification = new Notification(R.drawable.icon, getString(R.string.downloader_download_in_progress_ticker), System.currentTimeMillis());\r
@@ -175,7 +178,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
         File newFile = null;\r
         try {\r
             if (wdc.downloadFile(mRemotePath, tmpFile)) {\r
         File newFile = null;\r
         try {\r
             if (wdc.downloadFile(mRemotePath, tmpFile)) {\r
-                newFile = new File(getSavePath() + mAccount.name + mFilePath);\r
+                newFile = new File(getSavePath(mAccount.name) + mFilePath);\r
                 newFile.getParentFile().mkdirs();\r
                 boolean moved = tmpFile.renameTo(newFile);\r
             \r
                 newFile.getParentFile().mkdirs();\r
                 boolean moved = tmpFile.renameTo(newFile);\r
             \r
index 60f8c88..5c9d093 100644 (file)
@@ -20,6 +20,7 @@ package eu.alefzero.owncloud.ui.activity;
 \r
 import java.net.MalformedURLException;\r
 import java.net.URL;\r
 \r
 import java.net.MalformedURLException;\r
 import java.net.URL;\r
+import java.net.URLEncoder;\r
 \r
 import android.accounts.Account;\r
 import android.accounts.AccountAuthenticatorActivity;\r
 \r
 import android.accounts.Account;\r
 import android.accounts.AccountAuthenticatorActivity;\r
@@ -167,6 +168,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 \r
             String username = username_text.getText().toString().trim();\r
             String accountName = username + "@" + url.getHost();\r
 \r
             String username = username_text.getText().toString().trim();\r
             String accountName = username + "@" + url.getHost();\r
+            if (url.getPort() >= 0) {\r
+                accountName += ":" + url.getPort();\r
+            }\r
             Account account = new Account(accountName,\r
                     AccountAuthenticator.ACCOUNT_TYPE);\r
             AccountManager accManager = AccountManager.get(this);\r
             Account account = new Account(accountName,\r
                     AccountAuthenticator.ACCOUNT_TYPE);\r
             AccountManager accManager = AccountManager.get(this);\r