From 3a64e4aa2e96d1fc902213a9fe6d383f5054b7c7 Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Mon, 4 Apr 2016 21:59:36 +0200 Subject: [PATCH] import keyfile and database to NoBackup-Internal files folder instead of standard app files directory --- src/Kp2aBusinessLogic/Io/BuiltInFileStorage.cs | 3 ++- src/Kp2aBusinessLogic/Io/IoUtil.cs | 3 ++- src/keepass2android/settings/DatabaseSettingsActivity.cs | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Kp2aBusinessLogic/Io/BuiltInFileStorage.cs b/src/Kp2aBusinessLogic/Io/BuiltInFileStorage.cs index b3bf4245..9d33b991 100644 --- a/src/Kp2aBusinessLogic/Io/BuiltInFileStorage.cs +++ b/src/Kp2aBusinessLogic/Io/BuiltInFileStorage.cs @@ -252,7 +252,8 @@ namespace keepass2android.Io //check if we need to request the external-storage-permission at runtime if (ioc.IsLocalFile()) { - bool requiresPermission = !ioc.Path.StartsWith(activity.Activity.FilesDir.CanonicalPath); + bool requiresPermission = !(ioc.Path.StartsWith(activity.Activity.FilesDir.CanonicalPath) + || ioc.Path.StartsWith(activity.Activity.NoBackupFilesDir.CanonicalPath)); var extDirectory = activity.Activity.GetExternalFilesDir(null); if ((extDirectory != null) && (ioc.Path.StartsWith(extDirectory.CanonicalPath))) diff --git a/src/Kp2aBusinessLogic/Io/IoUtil.cs b/src/Kp2aBusinessLogic/Io/IoUtil.cs index 74368c36..f38c010b 100644 --- a/src/Kp2aBusinessLogic/Io/IoUtil.cs +++ b/src/Kp2aBusinessLogic/Io/IoUtil.cs @@ -53,13 +53,14 @@ namespace keepass2android.Io try { File filesDir = context.FilesDir.CanonicalFile; + File noBackupDir = context.NoBackupFilesDir.CanonicalFile; File ourFile = new File(path).CanonicalFile; //http://www.java2s.com/Tutorial/Java/0180__File/Checkswhetherthechilddirectoryisasubdirectoryofthebasedirectory.htm File parentFile = ourFile; while (parentFile != null) { - if (filesDir.Equals(parentFile)) + if ((filesDir.Equals(parentFile) || noBackupDir.Equals(parentFile))) { return true; } diff --git a/src/keepass2android/settings/DatabaseSettingsActivity.cs b/src/keepass2android/settings/DatabaseSettingsActivity.cs index 10715896..ae22bb52 100644 --- a/src/keepass2android/settings/DatabaseSettingsActivity.cs +++ b/src/keepass2android/settings/DatabaseSettingsActivity.cs @@ -764,7 +764,7 @@ namespace keepass2android targetPath = targetPath.Trim("|\\?*<\":>+[]/'".ToCharArray()); if (targetPath == "") targetPath = "imported"; - if (new File(Activity.FilesDir, targetPath).Exists()) + if (new File(Activity.NoBackupFilesDir, targetPath).Exists()) { int c = 1; var ext = UrlUtil.GetExtension(targetPath); @@ -775,9 +775,9 @@ namespace keepass2android targetPath = filenameWithoutExt + c; if (!String.IsNullOrEmpty(ext)) targetPath += "." + ext; - } while (new File(Activity.FilesDir, targetPath).Exists()); + } while (new File(Activity.NoBackupFilesDir, targetPath).Exists()); } - var targetIoc = IOConnectionInfo.FromPath(new File(Activity.FilesDir, targetPath).CanonicalPath); + var targetIoc = IOConnectionInfo.FromPath(new File(Activity.NoBackupFilesDir, targetPath).CanonicalPath); IoUtil.Copy(targetIoc, sourceIoc, App.Kp2a); return targetIoc;