allow importing database to internal folder
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Android.Content;
|
||||
using Java.IO;
|
||||
using KeePassLib.Serialization;
|
||||
|
||||
@@ -46,5 +47,50 @@ namespace keepass2android.Io
|
||||
}
|
||||
return iocParent;
|
||||
}
|
||||
|
||||
public static bool IsInInternalDirectory(string path, Context context)
|
||||
{
|
||||
try
|
||||
{
|
||||
File filesDir = context.FilesDir.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))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
parentFile = parentFile.ParentFile;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Kp2aLog.Log(e.ToString());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void Copy(IOConnectionInfo targetIoc, IOConnectionInfo sourceIoc, IKp2aApp app)
|
||||
{
|
||||
IFileStorage sourceStorage = app.GetFileStorage(sourceIoc, false); //don't cache source. file won't be used ever again
|
||||
IFileStorage targetStorage = app.GetFileStorage(targetIoc);
|
||||
|
||||
using (
|
||||
var writeTransaction = targetStorage.OpenWriteTransaction(targetIoc,
|
||||
app.GetBooleanPreference(
|
||||
PreferenceKey.UseFileTransactions)))
|
||||
{
|
||||
using (var writeStream = writeTransaction.OpenFile())
|
||||
{
|
||||
sourceStorage.OpenFileForRead(sourceIoc).CopyTo(writeStream);
|
||||
}
|
||||
writeTransaction.CommitWrite();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,16 +293,6 @@ namespace keepass2android.Io
|
||||
return false; //TODO implement. note, however, that we MAY return false even if it's read-only
|
||||
}
|
||||
|
||||
public bool IsPermanentLocation(IOConnectionInfo ioc)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsReadOnly(IOConnectionInfo ioc)
|
||||
{
|
||||
return false; //TODO implement. note, however, that we MAY return false even if it's read-only
|
||||
}
|
||||
|
||||
public void OnCreate(IFileStorageSetupActivity activity, Bundle savedInstanceState)
|
||||
{
|
||||
_jfs.OnCreate(((IJavaFileStorageFileStorageSetupActivity)activity), savedInstanceState);
|
||||
|
||||
Reference in New Issue
Block a user