瀏覽代碼

Granted that accounts different only in port number won't mix their files in the same local folder

David A. Velasco 13 年之前
父節點
當前提交
c06007b98a

+ 1 - 1
AndroidManifest.xml

@@ -18,7 +18,7 @@
  -->
 <manifest package="eu.alefzero.owncloud"
     android:versionCode="1"
-    android:versionName="0.1.189B" xmlns:android="http://schemas.android.com/apk/res/android">
+    android:versionName="0.1.190B" xmlns:android="http://schemas.android.com/apk/res/android">
 
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />
     <uses-permission android:name="android.permission.USE_CREDENTIALS" />

+ 2 - 2
src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java

@@ -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.files.services.FileDownloader;
 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
-                    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());
                 }

+ 9 - 6
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;
@@ -82,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
@@ -155,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());
@@ -175,7 +178,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
         File newFile = null;
         try {
             if (wdc.downloadFile(mRemotePath, tmpFile)) {
-                newFile = new File(getSavePath() + mAccount.name + mFilePath);
+                newFile = new File(getSavePath(mAccount.name) + mFilePath);
                 newFile.getParentFile().mkdirs();
                 boolean moved = tmpFile.renameTo(newFile);
             

+ 4 - 0
src/eu/alefzero/owncloud/ui/activity/AuthenticatorActivity.java

@@ -20,6 +20,7 @@ package eu.alefzero.owncloud.ui.activity;
 
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLEncoder;
 
 import android.accounts.Account;
 import android.accounts.AccountAuthenticatorActivity;
@@ -167,6 +168,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 
             String username = username_text.getText().toString().trim();
             String accountName = username + "@" + url.getHost();
+            if (url.getPort() >= 0) {
+                accountName += ":" + url.getPort();
+            }
             Account account = new Account(accountName,
                     AccountAuthenticator.ACCOUNT_TYPE);
             AccountManager accManager = AccountManager.get(this);