import keyfile and database to NoBackup-Internal files folder instead of standard app files directory

This commit is contained in:
Philipp Crocoll 2016-04-04 21:59:36 +02:00
parent 9c45bcb090
commit 3a64e4aa2e
3 changed files with 7 additions and 5 deletions

View File

@ -252,7 +252,8 @@ namespace keepass2android.Io
//check if we need to request the external-storage-permission at runtime //check if we need to request the external-storage-permission at runtime
if (ioc.IsLocalFile()) 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); var extDirectory = activity.Activity.GetExternalFilesDir(null);
if ((extDirectory != null) && (ioc.Path.StartsWith(extDirectory.CanonicalPath))) if ((extDirectory != null) && (ioc.Path.StartsWith(extDirectory.CanonicalPath)))

View File

@ -53,13 +53,14 @@ namespace keepass2android.Io
try try
{ {
File filesDir = context.FilesDir.CanonicalFile; File filesDir = context.FilesDir.CanonicalFile;
File noBackupDir = context.NoBackupFilesDir.CanonicalFile;
File ourFile = new File(path).CanonicalFile; File ourFile = new File(path).CanonicalFile;
//http://www.java2s.com/Tutorial/Java/0180__File/Checkswhetherthechilddirectoryisasubdirectoryofthebasedirectory.htm //http://www.java2s.com/Tutorial/Java/0180__File/Checkswhetherthechilddirectoryisasubdirectoryofthebasedirectory.htm
File parentFile = ourFile; File parentFile = ourFile;
while (parentFile != null) while (parentFile != null)
{ {
if (filesDir.Equals(parentFile)) if ((filesDir.Equals(parentFile) || noBackupDir.Equals(parentFile)))
{ {
return true; return true;
} }

View File

@ -764,7 +764,7 @@ namespace keepass2android
targetPath = targetPath.Trim("|\\?*<\":>+[]/'".ToCharArray()); targetPath = targetPath.Trim("|\\?*<\":>+[]/'".ToCharArray());
if (targetPath == "") if (targetPath == "")
targetPath = "imported"; targetPath = "imported";
if (new File(Activity.FilesDir, targetPath).Exists()) if (new File(Activity.NoBackupFilesDir, targetPath).Exists())
{ {
int c = 1; int c = 1;
var ext = UrlUtil.GetExtension(targetPath); var ext = UrlUtil.GetExtension(targetPath);
@ -775,9 +775,9 @@ namespace keepass2android
targetPath = filenameWithoutExt + c; targetPath = filenameWithoutExt + c;
if (!String.IsNullOrEmpty(ext)) if (!String.IsNullOrEmpty(ext))
targetPath += "." + 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); IoUtil.Copy(targetIoc, sourceIoc, App.Kp2a);
return targetIoc; return targetIoc;