mirror of
https://github.com/moparisthebest/keepass2android
synced 2025-01-30 14:40:21 -05:00
Added Check if Database changed
This commit is contained in:
parent
44ec0e0a04
commit
b4784b2128
@ -43,12 +43,14 @@ namespace keepass2android
|
|||||||
public PwGroup root;
|
public PwGroup root;
|
||||||
public PwDatabase pm;
|
public PwDatabase pm;
|
||||||
public IOConnectionInfo mIoc;
|
public IOConnectionInfo mIoc;
|
||||||
|
public DateTime mLastChangeDate;
|
||||||
public SearchDbHelper searchHelper;
|
public SearchDbHelper searchHelper;
|
||||||
|
|
||||||
public DrawableFactory drawFactory = new DrawableFactory();
|
public DrawableFactory drawFactory = new DrawableFactory();
|
||||||
|
|
||||||
private bool loaded = false;
|
private bool loaded = false;
|
||||||
|
|
||||||
|
private bool mReloadRequested = false;
|
||||||
|
|
||||||
public bool Loaded {
|
public bool Loaded {
|
||||||
get { return loaded;}
|
get { return loaded;}
|
||||||
@ -73,20 +75,64 @@ namespace keepass2android
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool DidOpenFileChange()
|
||||||
|
{
|
||||||
|
if ((Loaded == false) || (mIoc.IsLocalFile() == false))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return System.IO.File.GetLastWriteTimeUtc(mIoc.Path) > mLastChangeDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CheckForOpenFileChanged(Activity activity)
|
||||||
|
{
|
||||||
|
if (DidOpenFileChange())
|
||||||
|
{
|
||||||
|
if (mReloadRequested)
|
||||||
|
{
|
||||||
|
|
||||||
|
activity.SetResult(KeePass.EXIT_RELOAD_DB);
|
||||||
|
activity.Finish();
|
||||||
|
}
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||||
|
builder.SetTitle(activity.GetString(Resource.String.AskReloadFile_title));
|
||||||
|
|
||||||
|
builder.SetMessage(activity.GetString(Resource.String.AskReloadFile));
|
||||||
|
|
||||||
|
builder.SetPositiveButton(activity.GetString(Android.Resource.String.Yes), new EventHandler<DialogClickEventArgs>((dlgSender, dlgEvt) =>
|
||||||
|
{
|
||||||
|
mReloadRequested = true;
|
||||||
|
activity.SetResult(KeePass.EXIT_RELOAD_DB);
|
||||||
|
activity.Finish();
|
||||||
|
|
||||||
|
}));
|
||||||
|
|
||||||
|
builder.SetNegativeButton(activity.GetString(Android.Resource.String.No), new EventHandler<DialogClickEventArgs>((dlgSender, dlgEvt) =>
|
||||||
|
{
|
||||||
|
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
Dialog dialog = builder.Create();
|
||||||
|
dialog.Show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void LoadData (Context ctx, IOConnectionInfo iocInfo, String password, String keyfile, UpdateStatus status)
|
public void LoadData(Context ctx, IOConnectionInfo iocInfo, String password, String keyfile, UpdateStatus status)
|
||||||
{
|
{
|
||||||
mIoc = iocInfo;
|
mIoc = iocInfo;
|
||||||
|
|
||||||
KeePassLib.PwDatabase pwDatabase = new KeePassLib.PwDatabase ();
|
KeePassLib.PwDatabase pwDatabase = new KeePassLib.PwDatabase();
|
||||||
|
|
||||||
KeePassLib.Keys.CompositeKey key = new KeePassLib.Keys.CompositeKey ();
|
KeePassLib.Keys.CompositeKey key = new KeePassLib.Keys.CompositeKey();
|
||||||
key.AddUserKey (new KeePassLib.Keys.KcpPassword (password));
|
key.AddUserKey(new KeePassLib.Keys.KcpPassword(password));
|
||||||
if (!String.IsNullOrEmpty (keyfile)) {
|
if (!String.IsNullOrEmpty(keyfile))
|
||||||
|
{
|
||||||
|
|
||||||
try { key.AddUserKey(new KeePassLib.Keys.KcpKeyFile(keyfile)); }
|
try
|
||||||
catch(Exception)
|
{
|
||||||
|
key.AddUserKey(new KeePassLib.Keys.KcpKeyFile(keyfile));
|
||||||
|
} catch (Exception)
|
||||||
{
|
{
|
||||||
throw new KeyFileException();
|
throw new KeyFileException();
|
||||||
}
|
}
|
||||||
@ -94,6 +140,14 @@ namespace keepass2android
|
|||||||
|
|
||||||
pwDatabase.Open(iocInfo, key, status);
|
pwDatabase.Open(iocInfo, key, status);
|
||||||
|
|
||||||
|
if (iocInfo.IsLocalFile())
|
||||||
|
{
|
||||||
|
mLastChangeDate = System.IO.File.GetLastWriteTimeUtc(iocInfo.Path);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
mLastChangeDate = DateTime.MinValue;
|
||||||
|
}
|
||||||
|
|
||||||
root = pwDatabase.RootGroup;
|
root = pwDatabase.RootGroup;
|
||||||
populateGlobals(root);
|
populateGlobals(root);
|
||||||
|
|
||||||
@ -210,6 +264,7 @@ namespace keepass2android
|
|||||||
mIoc = null;
|
mIoc = null;
|
||||||
loaded = false;
|
loaded = false;
|
||||||
locked = false;
|
locked = false;
|
||||||
|
mReloadRequested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAllGroupsAsDirty() {
|
public void markAllGroupsAsDirty() {
|
||||||
|
@ -47,6 +47,7 @@ namespace keepass2android
|
|||||||
public const Android.App.Result EXIT_CLOSE_AFTER_SEARCH = Android.App.Result.FirstUser+6;
|
public const Android.App.Result EXIT_CLOSE_AFTER_SEARCH = Android.App.Result.FirstUser+6;
|
||||||
public const Android.App.Result EXIT_CHANGE_DB = Android.App.Result.FirstUser+7;
|
public const Android.App.Result EXIT_CHANGE_DB = Android.App.Result.FirstUser+7;
|
||||||
public const Android.App.Result EXIT_FORCE_LOCK_AND_CHANGE_DB = Android.App.Result.FirstUser+8;
|
public const Android.App.Result EXIT_FORCE_LOCK_AND_CHANGE_DB = Android.App.Result.FirstUser+8;
|
||||||
|
public const Android.App.Result EXIT_RELOAD_DB = Android.App.Result.FirstUser+9;
|
||||||
|
|
||||||
protected override void OnCreate (Bundle bundle)
|
protected override void OnCreate (Bundle bundle)
|
||||||
{
|
{
|
||||||
|
@ -40,10 +40,15 @@ namespace keepass2android
|
|||||||
mIoc = App.getDB().mIoc;
|
mIoc = App.getDB().mIoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnResume() {
|
|
||||||
|
protected override void OnResume()
|
||||||
|
{
|
||||||
base.OnResume();
|
base.OnResume();
|
||||||
|
|
||||||
TimeoutHelper.checkShutdown(this, mIoc);
|
if (TimeoutHelper.checkShutdown(this, mIoc))
|
||||||
|
return;
|
||||||
|
|
||||||
|
App.getDB().CheckForOpenFileChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,12 +50,17 @@ namespace keepass2android
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnResume() {
|
protected override void OnResume()
|
||||||
|
{
|
||||||
base.OnResume();
|
base.OnResume();
|
||||||
|
|
||||||
TimeoutHelper.checkShutdown(this, mIoc);
|
if (TimeoutHelper.checkShutdown(this, mIoc))
|
||||||
|
return;
|
||||||
|
|
||||||
|
App.getDB().CheckForOpenFileChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,7 +239,29 @@ namespace keepass2android
|
|||||||
App.getDB().Locked = false;
|
App.getDB().Locked = false;
|
||||||
LaunchNextActivity();
|
LaunchNextActivity();
|
||||||
break;
|
break;
|
||||||
|
case KeePass.EXIT_RELOAD_DB:
|
||||||
|
//if the activity was killed, fill password/keyfile so the user can directly hit load again
|
||||||
|
if (App.getDB().Loaded)
|
||||||
|
{
|
||||||
|
if (App.getDB().pm.MasterKey.ContainsType(typeof(KcpPassword)))
|
||||||
|
{
|
||||||
|
|
||||||
|
KcpPassword kcpPassword = (KcpPassword)App.getDB().pm.MasterKey.GetUserKey(typeof(KcpPassword));
|
||||||
|
String password = kcpPassword.Password.ReadString();
|
||||||
|
|
||||||
|
setEditText(Resource.Id.password, password);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (App.getDB().pm.MasterKey.ContainsType(typeof(KcpKeyFile)))
|
||||||
|
{
|
||||||
|
|
||||||
|
KcpKeyFile kcpKeyfile = (KcpKeyFile)App.getDB().pm.MasterKey.GetUserKey(typeof(KcpKeyFile));
|
||||||
|
|
||||||
|
setEditText(Resource.Id.pass_keyfile, kcpKeyfile.Path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unloadDatabase();
|
||||||
|
break;
|
||||||
case Android.App.Result.Ok:
|
case Android.App.Result.Ok:
|
||||||
if (requestCode == Intents.REQUEST_CODE_FILE_BROWSE) {
|
if (requestCode == Intents.REQUEST_CODE_FILE_BROWSE) {
|
||||||
String filename = data.DataString;
|
String filename = data.DataString;
|
||||||
|
@ -1021,6 +1021,12 @@ namespace keepass2android
|
|||||||
// aapt resource value: 0x7f0500eb
|
// aapt resource value: 0x7f0500eb
|
||||||
public const int AskOverwriteBinary_yes = 2131034347;
|
public const int AskOverwriteBinary_yes = 2131034347;
|
||||||
|
|
||||||
|
// aapt resource value: 0x7f0500f3
|
||||||
|
public const int AskReloadFile = 2131034355;
|
||||||
|
|
||||||
|
// aapt resource value: 0x7f0500f2
|
||||||
|
public const int AskReloadFile_title = 2131034354;
|
||||||
|
|
||||||
// aapt resource value: 0x7f0500ed
|
// aapt resource value: 0x7f0500ed
|
||||||
public const int AttachFailed = 2131034349;
|
public const int AttachFailed = 2131034349;
|
||||||
|
|
||||||
|
@ -212,6 +212,8 @@
|
|||||||
<string name="AskDeletePermanentlyEntry">Do you want to delete this entry permanently? Press No to recycle.</string>
|
<string name="AskDeletePermanentlyEntry">Do you want to delete this entry permanently? Press No to recycle.</string>
|
||||||
<string name="AskDeletePermanentlyGroup">Do you want to delete this group permanently? Press No to recycle.</string>
|
<string name="AskDeletePermanentlyGroup">Do you want to delete this group permanently? Press No to recycle.</string>
|
||||||
<string name="AskDeletePermanently_title">Delete permanently?</string>
|
<string name="AskDeletePermanently_title">Delete permanently?</string>
|
||||||
|
<string name="AskReloadFile_title">Reload file?</string>
|
||||||
|
<string name="AskReloadFile">The file which is currently open was changed by another program. Do you want to reload it?</string>
|
||||||
<string-array name="clipboard_timeout_options">
|
<string-array name="clipboard_timeout_options">
|
||||||
<item>30 seconds</item>
|
<item>30 seconds</item>
|
||||||
<item>1 minute</item>
|
<item>1 minute</item>
|
||||||
|
@ -53,6 +53,8 @@ namespace keepass2android
|
|||||||
if (! mDontSave) {
|
if (! mDontSave) {
|
||||||
try {
|
try {
|
||||||
mDb.SaveData (mCtx);
|
mDb.SaveData (mCtx);
|
||||||
|
if (mDb.mIoc.IsLocalFile())
|
||||||
|
mDb.mLastChangeDate = System.IO.File.GetLastWriteTimeUtc(mDb.mIoc.Path);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
/* TODO KPDesktop:
|
/* TODO KPDesktop:
|
||||||
* catch(Exception exSave)
|
* catch(Exception exSave)
|
||||||
|
@ -91,13 +91,15 @@ namespace keepass2android
|
|||||||
return ioc.GetDisplayName() != other.GetDisplayName();
|
return ioc.GetDisplayName() != other.GetDisplayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkShutdown(Activity act, IOConnectionInfo ioc) {
|
public static bool checkShutdown(Activity act, IOConnectionInfo ioc) {
|
||||||
if (( App.getDB().Loaded && (App.isShutdown() || App.getDB().Locked) )
|
if (( App.getDB().Loaded && (App.isShutdown() || App.getDB().Locked) )
|
||||||
|| (iocChanged(ioc, App.getDB().mIoc))) //file was changed from ActionSend-Intent
|
|| (iocChanged(ioc, App.getDB().mIoc))) //file was changed from ActionSend-Intent
|
||||||
{
|
{
|
||||||
act.SetResult(KeePass.EXIT_LOCK);
|
act.SetResult(KeePass.EXIT_LOCK);
|
||||||
act.Finish();
|
act.Finish();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user