Refactoring:
Wiped out the historical partial Java naming conventions, replaced by C# removed unused fields/parameters removed many unused usings ... (Thanks to ReSharper :-))
This commit is contained in:
@@ -1,13 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using Android.Content.Res;
|
||||
using KeePassLib;
|
||||
@@ -17,9 +7,9 @@ namespace keepass2android
|
||||
{
|
||||
public interface IDrawableFactory
|
||||
{
|
||||
void assignDrawableTo (ImageView iv, Resources res, PwDatabase db, PwIcon icon, PwUuid customIconId);
|
||||
void AssignDrawableTo (ImageView iv, Resources res, PwDatabase db, PwIcon icon, PwUuid customIconId);
|
||||
|
||||
Drawable getIconDrawable(Resources res, PwDatabase db, PwIcon icon, PwUuid customIconId);
|
||||
Drawable GetIconDrawable(Resources res, PwDatabase db, PwIcon icon, PwUuid customIconId);
|
||||
|
||||
|
||||
void Clear();
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using KeePassLib.Serialization;
|
||||
|
||||
namespace keepass2android
|
||||
|
||||
@@ -47,15 +47,15 @@
|
||||
<Compile Include="database\edit\ActionOnFinish.cs" />
|
||||
<Compile Include="database\edit\AddEntry.cs" />
|
||||
<Compile Include="database\edit\AddGroup.cs" />
|
||||
<Compile Include="database\edit\CreateDB.cs" />
|
||||
<Compile Include="database\edit\CreateDb.cs" />
|
||||
<Compile Include="database\edit\DeleteEntry.cs" />
|
||||
<Compile Include="database\edit\DeleteGroup.cs" />
|
||||
<Compile Include="database\edit\DeleteRunnable.cs" />
|
||||
<Compile Include="database\edit\FileOnFinish.cs" />
|
||||
<Compile Include="database\edit\LoadDB.cs" />
|
||||
<Compile Include="database\edit\LoadDb.cs" />
|
||||
<Compile Include="database\edit\OnFinish.cs" />
|
||||
<Compile Include="database\edit\RunnableOnFinish.cs" />
|
||||
<Compile Include="database\edit\SaveDB.cs" />
|
||||
<Compile Include="database\edit\SaveDb.cs" />
|
||||
<Compile Include="database\edit\SetPassword.cs" />
|
||||
<Compile Include="database\edit\UpdateEntry.cs" />
|
||||
<Compile Include="IKp2aApp.cs" />
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
public enum PreferenceKey
|
||||
|
||||
@@ -15,69 +15,59 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using Java.Lang;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
public class ProgressTask {
|
||||
private Context mCtx;
|
||||
private Handler mHandler;
|
||||
private RunnableOnFinish mTask;
|
||||
private ProgressDialog mPd;
|
||||
private IKp2aApp mApp;
|
||||
private readonly Handler _handler;
|
||||
private readonly RunnableOnFinish _task;
|
||||
private readonly ProgressDialog _progressDialog;
|
||||
private readonly IKp2aApp _app;
|
||||
|
||||
public ProgressTask(IKp2aApp app, Context ctx, RunnableOnFinish task, UiStringKey messageKey) {
|
||||
mTask = task;
|
||||
mHandler = new Handler();
|
||||
mApp = app;
|
||||
_task = task;
|
||||
_handler = new Handler();
|
||||
_app = app;
|
||||
|
||||
// Show process dialog
|
||||
mPd = new ProgressDialog(ctx);
|
||||
mPd.SetTitle(mApp.GetResourceString(UiStringKey.progress_title));
|
||||
mPd.SetMessage(mApp.GetResourceString(messageKey));
|
||||
_progressDialog = new ProgressDialog(ctx);
|
||||
_progressDialog.SetTitle(_app.GetResourceString(UiStringKey.progress_title));
|
||||
_progressDialog.SetMessage(_app.GetResourceString(messageKey));
|
||||
|
||||
// Set code to run when this is finished
|
||||
mTask.setStatus(new UpdateStatus(mApp, mHandler, mPd));
|
||||
mTask.mFinish = new AfterTask(task.mFinish, mHandler, mPd);
|
||||
_task.SetStatus(new UpdateStatus(_app, _handler, _progressDialog));
|
||||
_task.OnFinishToRun = new AfterTask(task.OnFinishToRun, _handler, _progressDialog);
|
||||
|
||||
}
|
||||
|
||||
public void run() {
|
||||
public void Run() {
|
||||
// Show process dialog
|
||||
mPd.Show();
|
||||
_progressDialog.Show();
|
||||
|
||||
|
||||
// Start Thread to Run task
|
||||
Thread t = new Thread(mTask.run);
|
||||
Thread t = new Thread(_task.Run);
|
||||
t.Start();
|
||||
|
||||
}
|
||||
|
||||
private class AfterTask : OnFinish {
|
||||
|
||||
ProgressDialog mPd;
|
||||
readonly ProgressDialog _progressDialog;
|
||||
|
||||
public AfterTask (OnFinish finish, Handler handler, ProgressDialog pd): base(finish, handler)
|
||||
{
|
||||
mPd = pd;
|
||||
_progressDialog = pd;
|
||||
}
|
||||
|
||||
public override void run() {
|
||||
base.run();
|
||||
public override void Run() {
|
||||
base.Run();
|
||||
|
||||
// Remove the progress dialog
|
||||
mHandler.Post(delegate() {mPd.Dismiss();});
|
||||
Handler.Post(delegate {_progressDialog.Dismiss();});
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -15,44 +15,31 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using KeePassLib;
|
||||
using Android.Preferences;
|
||||
using System.Text.RegularExpressions;
|
||||
using KeePassLib.Collections;
|
||||
using KeePassLib.Interfaces;
|
||||
using KeePassLib.Utility;
|
||||
using Android.Util;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
public class SearchDbHelper
|
||||
{
|
||||
private IKp2aApp mApp;
|
||||
private readonly IKp2aApp _app;
|
||||
|
||||
|
||||
public SearchDbHelper(IKp2aApp app) {
|
||||
mApp = app;
|
||||
_app = app;
|
||||
}
|
||||
|
||||
|
||||
public PwGroup searchForText (Database database, string str)
|
||||
public PwGroup SearchForText (Database database, string str)
|
||||
{
|
||||
SearchParameters sp = new SearchParameters();
|
||||
sp.SearchString = str;
|
||||
SearchParameters sp = new SearchParameters {SearchString = str};
|
||||
|
||||
return search(database, sp);
|
||||
return Search(database, sp);
|
||||
}
|
||||
public PwGroup search(Database database, SearchParameters sp)
|
||||
public PwGroup Search(Database database, SearchParameters sp)
|
||||
{
|
||||
|
||||
if(sp.RegularExpression) // Validate regular expression
|
||||
@@ -60,14 +47,13 @@ namespace keepass2android
|
||||
new Regex(sp.SearchString);
|
||||
}
|
||||
|
||||
string strGroupName = mApp.GetResourceString(UiStringKey.search_results) + " (\"" + sp.SearchString + "\")";
|
||||
PwGroup pgResults = new PwGroup(true, true, strGroupName, PwIcon.EMailSearch);
|
||||
pgResults.IsVirtual = true;
|
||||
|
||||
string strGroupName = _app.GetResourceString(UiStringKey.search_results) + " (\"" + sp.SearchString + "\")";
|
||||
PwGroup pgResults = new PwGroup(true, true, strGroupName, PwIcon.EMailSearch) {IsVirtual = true};
|
||||
|
||||
PwObjectList<PwEntry> listResults = pgResults.Entries;
|
||||
|
||||
|
||||
database.root.SearchEntries(sp, listResults, new NullStatusLogger());
|
||||
database.Root.SearchEntries(sp, listResults, new NullStatusLogger());
|
||||
|
||||
|
||||
return pgResults;
|
||||
@@ -76,7 +62,7 @@ namespace keepass2android
|
||||
}
|
||||
|
||||
|
||||
public PwGroup searchForExactUrl (Database database, string url)
|
||||
public PwGroup SearchForExactUrl (Database database, string url)
|
||||
{
|
||||
SearchParameters sp = SearchParameters.None;
|
||||
sp.SearchInUrls = true;
|
||||
@@ -87,14 +73,13 @@ namespace keepass2android
|
||||
new Regex(sp.SearchString);
|
||||
}
|
||||
|
||||
string strGroupName = mApp.GetResourceString(UiStringKey.search_results) + " (\"" + sp.SearchString + "\")";
|
||||
PwGroup pgResults = new PwGroup(true, true, strGroupName, PwIcon.EMailSearch);
|
||||
pgResults.IsVirtual = true;
|
||||
|
||||
string strGroupName = _app.GetResourceString(UiStringKey.search_results) + " (\"" + sp.SearchString + "\")";
|
||||
PwGroup pgResults = new PwGroup(true, true, strGroupName, PwIcon.EMailSearch) {IsVirtual = true};
|
||||
|
||||
PwObjectList<PwEntry> listResults = pgResults.Entries;
|
||||
|
||||
|
||||
database.root.SearchEntries(sp, listResults, new NullStatusLogger());
|
||||
database.Root.SearchEntries(sp, listResults, new NullStatusLogger());
|
||||
|
||||
|
||||
return pgResults;
|
||||
@@ -106,15 +91,14 @@ namespace keepass2android
|
||||
return UrlUtil.GetHost(url.Trim());
|
||||
}
|
||||
|
||||
public PwGroup searchForHost(Database database, String url, bool allowSubdomains)
|
||||
public PwGroup SearchForHost(Database database, String url, bool allowSubdomains)
|
||||
{
|
||||
String host = extractHost(url);
|
||||
string strGroupName = mApp.GetResourceString(UiStringKey.search_results) + " (\"" + host + "\")";
|
||||
PwGroup pgResults = new PwGroup(true, true, strGroupName, PwIcon.EMailSearch);
|
||||
pgResults.IsVirtual = true;
|
||||
string strGroupName = _app.GetResourceString(UiStringKey.search_results) + " (\"" + host + "\")";
|
||||
PwGroup pgResults = new PwGroup(true, true, strGroupName, PwIcon.EMailSearch) {IsVirtual = true};
|
||||
if (String.IsNullOrWhiteSpace(host))
|
||||
return pgResults;
|
||||
foreach (PwEntry entry in database.entries.Values)
|
||||
foreach (PwEntry entry in database.Entries.Values)
|
||||
{
|
||||
String otherHost = extractHost(entry.Strings.ReadSafe(PwDefs.UrlField));
|
||||
if ((allowSubdomains) && (otherHost.StartsWith("www.")))
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
public enum UiStringKey
|
||||
|
||||
@@ -16,45 +16,37 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using KeePassLib.Interfaces;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
public class UpdateStatus: IStatusLogger {
|
||||
private ProgressDialog mPD;
|
||||
IKp2aApp mApp;
|
||||
private Handler mHandler;
|
||||
private readonly ProgressDialog _progressDialog;
|
||||
readonly IKp2aApp _app;
|
||||
private readonly Handler _handler;
|
||||
|
||||
public UpdateStatus() {
|
||||
|
||||
}
|
||||
|
||||
public UpdateStatus(IKp2aApp app, Handler handler, ProgressDialog pd) {
|
||||
mApp = app;
|
||||
mPD = pd;
|
||||
mHandler = handler;
|
||||
_app = app;
|
||||
_progressDialog = pd;
|
||||
_handler = handler;
|
||||
}
|
||||
|
||||
public void updateMessage(UiStringKey stringKey) {
|
||||
if ( mApp != null && mPD != null && mHandler != null ) {
|
||||
mHandler.Post( () => {mPD.SetMessage(mApp.GetResourceString(stringKey));});
|
||||
public void UpdateMessage(UiStringKey stringKey) {
|
||||
if ( _app != null && _progressDialog != null && _handler != null ) {
|
||||
_handler.Post( () => {_progressDialog.SetMessage(_app.GetResourceString(stringKey));});
|
||||
}
|
||||
}
|
||||
|
||||
public void updateMessage (String message)
|
||||
public void UpdateMessage (String message)
|
||||
{
|
||||
if ( mApp!= null && mPD != null && mHandler != null ) {
|
||||
mHandler.Post(() => {mPD.SetMessage(message); } );
|
||||
if ( _app!= null && _progressDialog != null && _handler != null ) {
|
||||
_handler.Post(() => {_progressDialog.SetMessage(message); } );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +69,7 @@ namespace keepass2android
|
||||
|
||||
public bool SetText (string strNewText, LogStatusType lsType)
|
||||
{
|
||||
updateMessage(strNewText);
|
||||
UpdateMessage(strNewText);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,18 +17,8 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
|
||||
using KeePassLib;
|
||||
using KeePassLib.Interfaces;
|
||||
using KeePassLib.Serialization;
|
||||
|
||||
namespace keepass2android
|
||||
@@ -37,38 +27,38 @@ namespace keepass2android
|
||||
public class Database {
|
||||
|
||||
|
||||
public Dictionary<PwUuid, PwGroup> groups = new Dictionary<PwUuid, PwGroup>(new PwUuidEqualityComparer());
|
||||
public Dictionary<PwUuid, PwEntry> entries = new Dictionary<PwUuid, PwEntry>(new PwUuidEqualityComparer());
|
||||
public HashSet<PwGroup> dirty = new HashSet<PwGroup>(new PwGroupEqualityFromIdComparer());
|
||||
public PwGroup root;
|
||||
public PwDatabase pm;
|
||||
public IOConnectionInfo mIoc;
|
||||
public DateTime mLastChangeDate;
|
||||
public SearchDbHelper searchHelper;
|
||||
public Dictionary<PwUuid, PwGroup> Groups = new Dictionary<PwUuid, PwGroup>(new PwUuidEqualityComparer());
|
||||
public Dictionary<PwUuid, PwEntry> Entries = new Dictionary<PwUuid, PwEntry>(new PwUuidEqualityComparer());
|
||||
public HashSet<PwGroup> Dirty = new HashSet<PwGroup>(new PwGroupEqualityFromIdComparer());
|
||||
public PwGroup Root;
|
||||
public PwDatabase KpDatabase;
|
||||
public IOConnectionInfo Ioc;
|
||||
public DateTime LastChangeDate;
|
||||
public SearchDbHelper SearchHelper;
|
||||
|
||||
public IDrawableFactory drawableFactory;
|
||||
public IDrawableFactory DrawableFactory;
|
||||
|
||||
IKp2aApp app;
|
||||
readonly IKp2aApp _app;
|
||||
|
||||
public Database(IDrawableFactory drawableFactory, IKp2aApp app)
|
||||
{
|
||||
this.drawableFactory = drawableFactory;
|
||||
this.app = app;
|
||||
DrawableFactory = drawableFactory;
|
||||
_app = app;
|
||||
}
|
||||
|
||||
private bool loaded = false;
|
||||
private bool _loaded;
|
||||
|
||||
private bool mReloadRequested = false;
|
||||
private bool _reloadRequested;
|
||||
|
||||
public bool ReloadRequested
|
||||
{
|
||||
get { return mReloadRequested; }
|
||||
set { mReloadRequested = value; }
|
||||
get { return _reloadRequested; }
|
||||
set { _reloadRequested = value; }
|
||||
}
|
||||
|
||||
public bool Loaded {
|
||||
get { return loaded;}
|
||||
set { loaded = value; }
|
||||
get { return _loaded;}
|
||||
set { _loaded = value; }
|
||||
}
|
||||
|
||||
public bool Open
|
||||
@@ -76,34 +66,34 @@ namespace keepass2android
|
||||
get { return Loaded && (!Locked); }
|
||||
}
|
||||
|
||||
bool locked;
|
||||
bool _locked;
|
||||
public bool Locked
|
||||
{
|
||||
get
|
||||
{
|
||||
return locked;
|
||||
return _locked;
|
||||
}
|
||||
set
|
||||
{
|
||||
locked = value;
|
||||
_locked = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool DidOpenFileChange()
|
||||
{
|
||||
if ((Loaded == false) || (mIoc.IsLocalFile() == false))
|
||||
if ((Loaded == false) || (Ioc.IsLocalFile() == false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return System.IO.File.GetLastWriteTimeUtc(mIoc.Path) > mLastChangeDate;
|
||||
return System.IO.File.GetLastWriteTimeUtc(Ioc.Path) > LastChangeDate;
|
||||
}
|
||||
|
||||
|
||||
public void LoadData(IKp2aApp app, IOConnectionInfo iocInfo, String password, String keyfile, UpdateStatus status)
|
||||
{
|
||||
mIoc = iocInfo;
|
||||
Ioc = iocInfo;
|
||||
|
||||
KeePassLib.PwDatabase pwDatabase = new KeePassLib.PwDatabase();
|
||||
PwDatabase pwDatabase = new PwDatabase();
|
||||
|
||||
KeePassLib.Keys.CompositeKey key = new KeePassLib.Keys.CompositeKey();
|
||||
key.AddUserKey(new KeePassLib.Keys.KcpPassword(password));
|
||||
@@ -123,33 +113,22 @@ namespace keepass2android
|
||||
|
||||
if (iocInfo.IsLocalFile())
|
||||
{
|
||||
mLastChangeDate = System.IO.File.GetLastWriteTimeUtc(iocInfo.Path);
|
||||
LastChangeDate = System.IO.File.GetLastWriteTimeUtc(iocInfo.Path);
|
||||
} else
|
||||
{
|
||||
mLastChangeDate = DateTime.MinValue;
|
||||
LastChangeDate = DateTime.MinValue;
|
||||
}
|
||||
|
||||
root = pwDatabase.RootGroup;
|
||||
populateGlobals(root);
|
||||
Root = pwDatabase.RootGroup;
|
||||
PopulateGlobals(Root);
|
||||
|
||||
|
||||
Loaded = true;
|
||||
pm = pwDatabase;
|
||||
searchHelper = new SearchDbHelper(app);
|
||||
KpDatabase = pwDatabase;
|
||||
SearchHelper = new SearchDbHelper(app);
|
||||
}
|
||||
|
||||
bool quickUnlockEnabled = false;
|
||||
public bool QuickUnlockEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return quickUnlockEnabled;
|
||||
}
|
||||
set
|
||||
{
|
||||
quickUnlockEnabled = value;
|
||||
}
|
||||
}
|
||||
public bool QuickUnlockEnabled { get; set; }
|
||||
|
||||
//KeyLength of QuickUnlock at time of loading the database.
|
||||
//This is important to not allow an attacker to set the length to 1 when QuickUnlock is started already.
|
||||
@@ -160,7 +139,7 @@ namespace keepass2android
|
||||
}
|
||||
|
||||
public PwGroup SearchForText(String str) {
|
||||
PwGroup group = searchHelper.searchForText(this, str);
|
||||
PwGroup group = SearchHelper.searchForText(this, str);
|
||||
|
||||
return group;
|
||||
|
||||
@@ -168,19 +147,19 @@ namespace keepass2android
|
||||
|
||||
public PwGroup Search(SearchParameters searchParams)
|
||||
{
|
||||
return searchHelper.search(this, searchParams);
|
||||
return SearchHelper.search(this, searchParams);
|
||||
}
|
||||
|
||||
|
||||
public PwGroup SearchForExactUrl(String url) {
|
||||
PwGroup group = searchHelper.searchForExactUrl(this, url);
|
||||
PwGroup group = SearchHelper.searchForExactUrl(this, url);
|
||||
|
||||
return group;
|
||||
|
||||
}
|
||||
|
||||
public PwGroup SearchForHost(String url, bool allowSubdomains) {
|
||||
PwGroup group = searchHelper.searchForHost(this, url, allowSubdomains);
|
||||
PwGroup group = SearchHelper.searchForHost(this, url, allowSubdomains);
|
||||
|
||||
return group;
|
||||
|
||||
@@ -189,68 +168,43 @@ namespace keepass2android
|
||||
|
||||
public void SaveData(Context ctx) {
|
||||
|
||||
pm.UseFileTransactions = app.GetBooleanPreference(PreferenceKey.UseFileTransactions);
|
||||
pm.Save(null);
|
||||
KpDatabase.UseFileTransactions = _app.GetBooleanPreference(PreferenceKey.UseFileTransactions);
|
||||
KpDatabase.Save(null);
|
||||
|
||||
}
|
||||
class SaveStatusLogger: IStatusLogger
|
||||
{
|
||||
#region IStatusLogger implementation
|
||||
public void StartLogging (string strOperation, bool bWriteOperationToLog)
|
||||
{
|
||||
}
|
||||
public void EndLogging ()
|
||||
{
|
||||
}
|
||||
public bool SetProgress (uint uPercent)
|
||||
{
|
||||
Android.Util.Log.Debug("DEBUG", "Progress: " + uPercent+"%");
|
||||
return true;
|
||||
}
|
||||
public bool SetText (string strNewText, LogStatusType lsType)
|
||||
{
|
||||
Android.Util.Log.Debug("DEBUG", strNewText);
|
||||
return true;
|
||||
}
|
||||
public bool ContinueWork ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
private void populateGlobals (PwGroup currentGroup)
|
||||
private void PopulateGlobals (PwGroup currentGroup)
|
||||
{
|
||||
|
||||
var childGroups = currentGroup.Groups;
|
||||
var childEntries = currentGroup.Entries;
|
||||
|
||||
foreach (PwEntry e in childEntries) {
|
||||
entries [e.Uuid] = e;
|
||||
Entries [e.Uuid] = e;
|
||||
}
|
||||
foreach (PwGroup g in childGroups) {
|
||||
groups[g.Uuid] = g;
|
||||
populateGlobals(g);
|
||||
Groups[g.Uuid] = g;
|
||||
PopulateGlobals(g);
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
groups.Clear();
|
||||
entries.Clear();
|
||||
dirty.Clear();
|
||||
drawableFactory.Clear();
|
||||
Groups.Clear();
|
||||
Entries.Clear();
|
||||
Dirty.Clear();
|
||||
DrawableFactory.Clear();
|
||||
|
||||
root = null;
|
||||
pm = null;
|
||||
mIoc = null;
|
||||
loaded = false;
|
||||
locked = false;
|
||||
mReloadRequested = false;
|
||||
Root = null;
|
||||
KpDatabase = null;
|
||||
Ioc = null;
|
||||
_loaded = false;
|
||||
_locked = false;
|
||||
_reloadRequested = false;
|
||||
}
|
||||
|
||||
public void markAllGroupsAsDirty() {
|
||||
foreach ( PwGroup group in groups.Values ) {
|
||||
dirty.Add(group);
|
||||
public void MarkAllGroupsAsDirty() {
|
||||
foreach ( PwGroup group in Groups.Values ) {
|
||||
Dirty.Add(group);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,16 +16,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
@@ -33,34 +24,34 @@ namespace keepass2android
|
||||
{
|
||||
public delegate void ActionToPerformOnFinsh(bool success, String message);
|
||||
|
||||
ActionToPerformOnFinsh actionToPerform;
|
||||
readonly ActionToPerformOnFinsh _actionToPerform;
|
||||
|
||||
public ActionOnFinish(ActionToPerformOnFinsh actionToPerform) : base(null, null)
|
||||
{
|
||||
this.actionToPerform = actionToPerform;
|
||||
_actionToPerform = actionToPerform;
|
||||
}
|
||||
|
||||
public ActionOnFinish(ActionToPerformOnFinsh actionToPerform, OnFinish finish) : base(finish)
|
||||
{
|
||||
this.actionToPerform = actionToPerform;
|
||||
_actionToPerform = actionToPerform;
|
||||
}
|
||||
|
||||
public ActionOnFinish(ActionToPerformOnFinsh actionToPerform, Handler handler) : base(handler)
|
||||
{
|
||||
this.actionToPerform = actionToPerform;
|
||||
_actionToPerform = actionToPerform;
|
||||
}
|
||||
|
||||
public override void run()
|
||||
public override void Run()
|
||||
{
|
||||
if (this.mMessage == null)
|
||||
this.mMessage = "";
|
||||
if (this.mHandler != null)
|
||||
if (Message == null)
|
||||
Message = "";
|
||||
if (Handler != null)
|
||||
{
|
||||
this.mHandler.Post(() => {actionToPerform(this.mSuccess, this.mMessage);});
|
||||
Handler.Post(() => {_actionToPerform(Success, Message);});
|
||||
}
|
||||
else
|
||||
actionToPerform(this.mSuccess, this.mMessage);
|
||||
base.run();
|
||||
_actionToPerform(Success, Message);
|
||||
base.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,79 +15,69 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using KeePassLib;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
public class AddEntry : RunnableOnFinish {
|
||||
protected Database mDb;
|
||||
private PwEntry mEntry;
|
||||
private PwGroup mParentGroup;
|
||||
private Context mCtx;
|
||||
protected Database Db;
|
||||
private readonly PwEntry _entry;
|
||||
private readonly PwGroup _parentGroup;
|
||||
private readonly Context _ctx;
|
||||
|
||||
public static AddEntry getInstance(Context ctx, Database db, PwEntry entry, PwGroup parentGroup, OnFinish finish) {
|
||||
public static AddEntry GetInstance(Context ctx, Database db, PwEntry entry, PwGroup parentGroup, OnFinish finish) {
|
||||
|
||||
return new AddEntry(ctx, db, entry, parentGroup, finish);
|
||||
}
|
||||
|
||||
protected AddEntry(Context ctx, Database db, PwEntry entry, PwGroup parentGroup, OnFinish finish):base(finish) {
|
||||
mCtx = ctx;
|
||||
mParentGroup = parentGroup;
|
||||
mDb = db;
|
||||
mEntry = entry;
|
||||
_ctx = ctx;
|
||||
_parentGroup = parentGroup;
|
||||
Db = db;
|
||||
_entry = entry;
|
||||
|
||||
mFinish = new AfterAdd(db, entry, mFinish);
|
||||
OnFinishToRun = new AfterAdd(db, entry, OnFinishToRun);
|
||||
}
|
||||
|
||||
|
||||
public override void run() {
|
||||
mParentGroup.AddEntry(mEntry, true);
|
||||
public override void Run() {
|
||||
_parentGroup.AddEntry(_entry, true);
|
||||
|
||||
// Commit to disk
|
||||
SaveDB save = new SaveDB(mCtx, mDb, mFinish);
|
||||
save.run();
|
||||
SaveDb save = new SaveDb(_ctx, Db, OnFinishToRun);
|
||||
save.Run();
|
||||
}
|
||||
|
||||
private class AfterAdd : OnFinish {
|
||||
protected Database mDb;
|
||||
private PwEntry mEntry;
|
||||
private readonly Database _db;
|
||||
private readonly PwEntry _entry;
|
||||
|
||||
public AfterAdd(Database db, PwEntry entry, OnFinish finish):base(finish) {
|
||||
mDb = db;
|
||||
mEntry = entry;
|
||||
_db = db;
|
||||
_entry = entry;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void run() {
|
||||
if ( mSuccess ) {
|
||||
public override void Run() {
|
||||
if ( Success ) {
|
||||
|
||||
PwGroup parent = mEntry.ParentGroup;
|
||||
PwGroup parent = _entry.ParentGroup;
|
||||
|
||||
// Mark parent group dirty
|
||||
mDb.dirty.Add(parent);
|
||||
_db.Dirty.Add(parent);
|
||||
|
||||
// Add entry to global
|
||||
mDb.entries[mEntry.Uuid] = mEntry;
|
||||
_db.Entries[_entry.Uuid] = _entry;
|
||||
|
||||
} else {
|
||||
//TODO test fail
|
||||
mEntry.ParentGroup.Entries.Remove(mEntry);
|
||||
_entry.ParentGroup.Entries.Remove(_entry);
|
||||
}
|
||||
|
||||
base.run();
|
||||
base.Run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,82 +16,71 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using KeePassLib;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
public class AddGroup : RunnableOnFinish {
|
||||
internal Database mDb;
|
||||
private String mName;
|
||||
private int mIconID;
|
||||
internal PwGroup mGroup;
|
||||
internal PwGroup mParent;
|
||||
protected bool mDontSave;
|
||||
Context mCtx;
|
||||
internal Database Db;
|
||||
private readonly String _name;
|
||||
private readonly int _iconId;
|
||||
internal PwGroup Group;
|
||||
internal PwGroup Parent;
|
||||
protected bool DontSave;
|
||||
readonly Context _ctx;
|
||||
|
||||
|
||||
public static AddGroup getInstance(Context ctx, Database db, String name, int iconid, PwGroup parent, OnFinish finish, bool dontSave) {
|
||||
public static AddGroup GetInstance(Context ctx, Database db, String name, int iconid, PwGroup parent, OnFinish finish, bool dontSave) {
|
||||
return new AddGroup(ctx, db, name, iconid, parent, finish, dontSave);
|
||||
}
|
||||
|
||||
|
||||
private AddGroup(Context ctx, Database db, String name, int iconid, PwGroup parent, OnFinish finish, bool dontSave): base(finish) {
|
||||
mCtx = ctx;
|
||||
mDb = db;
|
||||
mName = name;
|
||||
mIconID = iconid;
|
||||
mParent = parent;
|
||||
mDontSave = dontSave;
|
||||
_ctx = ctx;
|
||||
Db = db;
|
||||
_name = name;
|
||||
_iconId = iconid;
|
||||
Parent = parent;
|
||||
DontSave = dontSave;
|
||||
|
||||
mFinish = new AfterAdd(this, mFinish);
|
||||
OnFinishToRun = new AfterAdd(this, OnFinishToRun);
|
||||
}
|
||||
|
||||
|
||||
public override void run() {
|
||||
PwDatabase pm = mDb.pm;
|
||||
public override void Run() {
|
||||
|
||||
// Generate new group
|
||||
mGroup = new PwGroup(true, true, mName, (PwIcon)mIconID);
|
||||
mParent.AddGroup(mGroup, true);
|
||||
Group = new PwGroup(true, true, _name, (PwIcon)_iconId);
|
||||
Parent.AddGroup(Group, true);
|
||||
|
||||
// Commit to disk
|
||||
SaveDB save = new SaveDB(mCtx, mDb, mFinish, mDontSave);
|
||||
save.run();
|
||||
SaveDb save = new SaveDb(_ctx, Db, OnFinishToRun, DontSave);
|
||||
save.Run();
|
||||
}
|
||||
|
||||
private class AfterAdd : OnFinish {
|
||||
|
||||
AddGroup addGroup;
|
||||
readonly AddGroup _addGroup;
|
||||
|
||||
public AfterAdd(AddGroup addGroup,OnFinish finish): base(finish) {
|
||||
this.addGroup = addGroup;
|
||||
_addGroup = addGroup;
|
||||
}
|
||||
|
||||
|
||||
public override void run() {
|
||||
public override void Run() {
|
||||
|
||||
if ( mSuccess ) {
|
||||
if ( Success ) {
|
||||
// Mark parent group dirty
|
||||
addGroup.mDb.dirty.Add(addGroup.mParent);
|
||||
_addGroup.Db.Dirty.Add(_addGroup.Parent);
|
||||
|
||||
// Add group to global list
|
||||
addGroup.mDb.groups[addGroup.mGroup.Uuid] = addGroup.mGroup;
|
||||
_addGroup.Db.Groups[_addGroup.Group.Uuid] = _addGroup.Group;
|
||||
} else {
|
||||
addGroup.mParent.Groups.Remove(addGroup.mGroup);
|
||||
_addGroup.Parent.Groups.Remove(_addGroup.Group);
|
||||
}
|
||||
|
||||
base.run();
|
||||
base.Run();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,69 +15,59 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using KeePassLib.Serialization;
|
||||
using KeePassLib.Keys;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
public class CreateDB : RunnableOnFinish {
|
||||
public class CreateDb : RunnableOnFinish {
|
||||
|
||||
private const int DEFAULT_ENCRYPTION_ROUNDS = 1000;
|
||||
private const int DefaultEncryptionRounds = 1000;
|
||||
|
||||
private IOConnectionInfo mIoc;
|
||||
private bool mDontSave;
|
||||
private Context mCtx;
|
||||
private IKp2aApp mApp;
|
||||
private readonly IOConnectionInfo _ioc;
|
||||
private readonly bool _dontSave;
|
||||
private readonly Context _ctx;
|
||||
private readonly IKp2aApp _app;
|
||||
|
||||
public CreateDB(IKp2aApp app, Context ctx, IOConnectionInfo ioc, OnFinish finish, bool dontSave): base(finish) {
|
||||
mCtx = ctx;
|
||||
mIoc = ioc;
|
||||
mDontSave = dontSave;
|
||||
mApp = app;
|
||||
public CreateDb(IKp2aApp app, Context ctx, IOConnectionInfo ioc, OnFinish finish, bool dontSave): base(finish) {
|
||||
_ctx = ctx;
|
||||
_ioc = ioc;
|
||||
_dontSave = dontSave;
|
||||
_app = app;
|
||||
}
|
||||
|
||||
|
||||
public override void run() {
|
||||
Database db = mApp.CreateNewDatabase();
|
||||
public override void Run() {
|
||||
Database db = _app.CreateNewDatabase();
|
||||
|
||||
db.pm = new KeePassLib.PwDatabase();
|
||||
db.KpDatabase = new KeePassLib.PwDatabase();
|
||||
//Key will be changed/created immediately after creation:
|
||||
CompositeKey tempKey = new CompositeKey();
|
||||
db.pm.New(mIoc, tempKey);
|
||||
db.KpDatabase.New(_ioc, tempKey);
|
||||
|
||||
|
||||
db.pm.KeyEncryptionRounds = DEFAULT_ENCRYPTION_ROUNDS;
|
||||
db.pm.Name = "Keepass2Android Password Database";
|
||||
db.KpDatabase.KeyEncryptionRounds = DefaultEncryptionRounds;
|
||||
db.KpDatabase.Name = "Keepass2Android Password Database";
|
||||
|
||||
|
||||
// Set Database state
|
||||
db.root = db.pm.RootGroup;
|
||||
db.mIoc = mIoc;
|
||||
db.Root = db.KpDatabase.RootGroup;
|
||||
db.Ioc = _ioc;
|
||||
db.Loaded = true;
|
||||
db.searchHelper = new SearchDbHelper(mApp);
|
||||
db.SearchHelper = new SearchDbHelper(_app);
|
||||
|
||||
// Add a couple default groups
|
||||
AddGroup internet = AddGroup.getInstance(mCtx, db, "Internet", 1, db.pm.RootGroup, null, true);
|
||||
internet.run();
|
||||
AddGroup email = AddGroup.getInstance(mCtx, db, "eMail", 19, db.pm.RootGroup, null, true);
|
||||
email.run();
|
||||
AddGroup internet = AddGroup.GetInstance(_ctx, db, "Internet", 1, db.KpDatabase.RootGroup, null, true);
|
||||
internet.Run();
|
||||
AddGroup email = AddGroup.GetInstance(_ctx, db, "eMail", 19, db.KpDatabase.RootGroup, null, true);
|
||||
email.Run();
|
||||
|
||||
// Commit changes
|
||||
SaveDB save = new SaveDB(mCtx, db, mFinish, mDontSave);
|
||||
mFinish = null;
|
||||
save.run();
|
||||
SaveDb save = new SaveDb(_ctx, db, OnFinishToRun, _dontSave);
|
||||
OnFinishToRun = null;
|
||||
save.Run();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,28 +16,19 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using KeePassLib;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
public class DeleteEntry : DeleteRunnable {
|
||||
|
||||
private PwEntry mEntry;
|
||||
private readonly PwEntry _entry;
|
||||
|
||||
public DeleteEntry(Context ctx, IKp2aApp app, PwEntry entry, OnFinish finish):base(finish, app) {
|
||||
mCtx = ctx;
|
||||
mDb = app.GetDb();
|
||||
mEntry = entry;
|
||||
Ctx = ctx;
|
||||
Db = app.GetDb();
|
||||
_entry = entry;
|
||||
|
||||
}
|
||||
|
||||
@@ -45,7 +36,7 @@ namespace keepass2android
|
||||
{
|
||||
get
|
||||
{
|
||||
return CanRecycleGroup(mEntry.ParentGroup);
|
||||
return CanRecycleGroup(_entry.ParentGroup);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,15 +48,15 @@ namespace keepass2android
|
||||
}
|
||||
}
|
||||
|
||||
public override void run() {
|
||||
public override void Run() {
|
||||
|
||||
PwDatabase pd = mDb.pm;
|
||||
PwDatabase pd = Db.KpDatabase;
|
||||
|
||||
PwGroup pgRecycleBin = pd.RootGroup.FindGroup(pd.RecycleBinUuid, true);
|
||||
|
||||
bool bUpdateGroupList = false;
|
||||
DateTime dtNow = DateTime.Now;
|
||||
PwEntry pe = mEntry;
|
||||
PwEntry pe = _entry;
|
||||
PwGroup pgParent = pe.ParentGroup;
|
||||
if(pgParent != null)
|
||||
{
|
||||
@@ -77,19 +68,19 @@ namespace keepass2android
|
||||
PwDeletedObject pdo = new PwDeletedObject(pe.Uuid, dtNow);
|
||||
pd.DeletedObjects.Add(pdo);
|
||||
|
||||
mFinish = new ActionOnFinish( (success, message) =>
|
||||
{
|
||||
if ( success ) {
|
||||
// Mark parent dirty
|
||||
if ( pgParent != null ) {
|
||||
mDb.dirty.Add(pgParent);
|
||||
OnFinishToRun = new ActionOnFinish((success, message) =>
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
// Mark parent dirty
|
||||
Db.Dirty.Add(pgParent);
|
||||
}
|
||||
} else {
|
||||
// Let's not bother recovering from a failure to save a deleted entry. It is too much work.
|
||||
mApp.SetShutdown();
|
||||
}
|
||||
|
||||
}, this.mFinish);
|
||||
else
|
||||
{
|
||||
// Let's not bother recovering from a failure to save a deleted entry. It is too much work.
|
||||
App.SetShutdown();
|
||||
}
|
||||
}, OnFinishToRun);
|
||||
}
|
||||
else // Recycle
|
||||
{
|
||||
@@ -98,27 +89,25 @@ namespace keepass2android
|
||||
pgRecycleBin.AddEntry(pe, true, true);
|
||||
pe.Touch(false);
|
||||
|
||||
mFinish = new ActionOnFinish( (success, message) =>
|
||||
OnFinishToRun = new ActionOnFinish( (success, message) =>
|
||||
{
|
||||
if ( success ) {
|
||||
// Mark previous parent dirty
|
||||
if ( pgParent != null ) {
|
||||
mDb.dirty.Add(pgParent);
|
||||
}
|
||||
Db.Dirty.Add(pgParent);
|
||||
// Mark new parent dirty
|
||||
mDb.dirty.Add(pgRecycleBin);
|
||||
Db.Dirty.Add(pgRecycleBin);
|
||||
} else {
|
||||
// Let's not bother recovering from a failure to save a deleted entry. It is too much work.
|
||||
mApp.SetShutdown();
|
||||
App.SetShutdown();
|
||||
}
|
||||
|
||||
}, this.mFinish);
|
||||
}, OnFinishToRun);
|
||||
}
|
||||
}
|
||||
|
||||
// Commit database
|
||||
SaveDB save = new SaveDB(mCtx, mDb, mFinish, false);
|
||||
save.run();
|
||||
SaveDb save = new SaveDb(Ctx, Db, OnFinishToRun, false);
|
||||
save.Run();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,16 +16,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using KeePassLib;
|
||||
|
||||
namespace keepass2android
|
||||
@@ -33,33 +24,31 @@ namespace keepass2android
|
||||
|
||||
public class DeleteGroup : DeleteRunnable {
|
||||
|
||||
private PwGroup mGroup;
|
||||
private Activity mAct;
|
||||
protected bool mDontSave;
|
||||
private PwGroup _group;
|
||||
protected bool DontSave;
|
||||
|
||||
public DeleteGroup(Context ctx, IKp2aApp app, PwGroup group, Activity act, OnFinish finish)
|
||||
public DeleteGroup(Context ctx, IKp2aApp app, PwGroup group, OnFinish finish)
|
||||
: base(finish, app)
|
||||
{
|
||||
setMembers(ctx, app, group, act, false);
|
||||
SetMembers(ctx, app, group, false);
|
||||
}
|
||||
/*
|
||||
public DeleteGroup(Context ctx, Database db, PwGroup group, Activity act, OnFinish finish, bool dontSave)
|
||||
: base(finish)
|
||||
{
|
||||
setMembers(ctx, db, group, act, dontSave);
|
||||
SetMembers(ctx, db, group, act, dontSave);
|
||||
}
|
||||
|
||||
public DeleteGroup(Context ctx, Database db, PwGroup group, OnFinish finish, bool dontSave):base(finish) {
|
||||
setMembers(ctx, db, group, null, dontSave);
|
||||
SetMembers(ctx, db, group, null, dontSave);
|
||||
}
|
||||
*/
|
||||
private void setMembers(Context ctx, IKp2aApp app, PwGroup group, Activity act, bool dontSave)
|
||||
private void SetMembers(Context ctx, IKp2aApp app, PwGroup group, bool dontSave)
|
||||
{
|
||||
base.setMembers(ctx, app.GetDb());
|
||||
base.SetMembers(ctx, app.GetDb());
|
||||
|
||||
mGroup = group;
|
||||
mAct = act;
|
||||
mDontSave = dontSave;
|
||||
_group = group;
|
||||
DontSave = dontSave;
|
||||
|
||||
}
|
||||
|
||||
@@ -67,7 +56,7 @@ namespace keepass2android
|
||||
{
|
||||
get
|
||||
{
|
||||
return CanRecycleGroup(mGroup);
|
||||
return CanRecycleGroup(_group);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,13 +69,13 @@ namespace keepass2android
|
||||
}
|
||||
|
||||
|
||||
public override void run() {
|
||||
public override void Run() {
|
||||
//from KP Desktop
|
||||
PwGroup pg = mGroup;
|
||||
PwGroup pg = _group;
|
||||
PwGroup pgParent = pg.ParentGroup;
|
||||
if(pgParent == null) return; // Can't remove virtual or root group
|
||||
|
||||
PwDatabase pd = mDb.pm;
|
||||
PwDatabase pd = Db.KpDatabase;
|
||||
PwGroup pgRecycleBin = pd.RootGroup.FindGroup(pd.RecycleBinUuid, true);
|
||||
|
||||
pgParent.Groups.Remove(pg);
|
||||
@@ -97,7 +86,7 @@ namespace keepass2android
|
||||
|
||||
PwDeletedObject pdo = new PwDeletedObject(pg.Uuid, DateTime.Now);
|
||||
pd.DeletedObjects.Add(pdo);
|
||||
mFinish = new AfterDeletePermanently(mFinish, mApp, mGroup);
|
||||
OnFinishToRun = new AfterDeletePermanently(OnFinishToRun, App, _group);
|
||||
}
|
||||
else // Recycle
|
||||
{
|
||||
@@ -106,59 +95,59 @@ namespace keepass2android
|
||||
|
||||
pgRecycleBin.AddGroup(pg, true, true);
|
||||
pg.Touch(false);
|
||||
mFinish = new ActionOnFinish((success, message) =>
|
||||
OnFinishToRun = new ActionOnFinish((success, message) =>
|
||||
{
|
||||
if ( success ) {
|
||||
// Mark new parent (Recycle bin) dirty
|
||||
PwGroup parent = mGroup.ParentGroup;
|
||||
PwGroup parent = _group.ParentGroup;
|
||||
if ( parent != null ) {
|
||||
mDb.dirty.Add(parent);
|
||||
Db.Dirty.Add(parent);
|
||||
}
|
||||
//Mark old parent dirty:
|
||||
mDb.dirty.Add(pgParent);
|
||||
Db.Dirty.Add(pgParent);
|
||||
} else {
|
||||
// Let's not bother recovering from a failure to save a deleted group. It is too much work.
|
||||
mApp.SetShutdown();
|
||||
App.SetShutdown();
|
||||
}
|
||||
}, this.mFinish);
|
||||
}, OnFinishToRun);
|
||||
}
|
||||
|
||||
// Save
|
||||
SaveDB save = new SaveDB(mCtx, mDb, mFinish, mDontSave);
|
||||
save.run();
|
||||
SaveDb save = new SaveDb(Ctx, Db, OnFinishToRun, DontSave);
|
||||
save.Run();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private class AfterDeletePermanently : OnFinish {
|
||||
IKp2aApp mApp;
|
||||
readonly IKp2aApp _app;
|
||||
|
||||
PwGroup mGroup;
|
||||
readonly PwGroup _group;
|
||||
|
||||
public AfterDeletePermanently(OnFinish finish, IKp2aApp app, PwGroup group):base(finish) {
|
||||
this.mApp = app;
|
||||
this.mGroup = group;
|
||||
_app = app;
|
||||
_group = group;
|
||||
}
|
||||
|
||||
public override void run() {
|
||||
if ( mSuccess ) {
|
||||
public override void Run() {
|
||||
if ( Success ) {
|
||||
// Remove from group global
|
||||
mApp.GetDb().groups.Remove(mGroup.Uuid);
|
||||
_app.GetDb().Groups.Remove(_group.Uuid);
|
||||
|
||||
// Remove group from the dirty global (if it is present), not a big deal if this fails (doesn't throw)
|
||||
mApp.GetDb().dirty.Remove(mGroup);
|
||||
_app.GetDb().Dirty.Remove(_group);
|
||||
|
||||
// Mark parent dirty
|
||||
PwGroup parent = mGroup.ParentGroup;
|
||||
PwGroup parent = _group.ParentGroup;
|
||||
if ( parent != null ) {
|
||||
mApp.GetDb().dirty.Add(parent);
|
||||
_app.GetDb().Dirty.Add(parent);
|
||||
}
|
||||
} else {
|
||||
// Let's not bother recovering from a failure to save a deleted group. It is too much work.
|
||||
mApp.SetShutdown();
|
||||
_app.SetShutdown();
|
||||
}
|
||||
|
||||
base.run();
|
||||
base.Run();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,50 +1,39 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using KeePassLib;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
public abstract class DeleteRunnable : RunnableOnFinish
|
||||
{
|
||||
public DeleteRunnable(OnFinish finish, IKp2aApp app):base(finish)
|
||||
protected DeleteRunnable(OnFinish finish, IKp2aApp app):base(finish)
|
||||
{
|
||||
mApp = app;
|
||||
App = app;
|
||||
}
|
||||
|
||||
protected IKp2aApp mApp;
|
||||
protected IKp2aApp App;
|
||||
|
||||
protected Database mDb;
|
||||
protected Database Db;
|
||||
|
||||
protected Context mCtx;
|
||||
protected Context Ctx;
|
||||
|
||||
protected void setMembers(Context ctx, Database db)
|
||||
protected void SetMembers(Context ctx, Database db)
|
||||
{
|
||||
mCtx = ctx;
|
||||
mDb = db;
|
||||
Ctx = ctx;
|
||||
Db = db;
|
||||
}
|
||||
|
||||
|
||||
private bool mDeletePermanently = true;
|
||||
private bool _deletePermanently = true;
|
||||
|
||||
public bool DeletePermanently
|
||||
{
|
||||
get
|
||||
{
|
||||
return mDeletePermanently;
|
||||
return _deletePermanently;
|
||||
}
|
||||
set
|
||||
{
|
||||
mDeletePermanently = value;
|
||||
_deletePermanently = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +45,7 @@ namespace keepass2android
|
||||
protected bool CanRecycleGroup(PwGroup pgParent)
|
||||
{
|
||||
bool bShiftPressed = false;
|
||||
PwDatabase pd = mDb.pm;
|
||||
PwDatabase pd = Db.KpDatabase;
|
||||
PwGroup pgRecycleBin = pd.RootGroup.FindGroup(pd.RecycleBinUuid, true);
|
||||
bool bPermanent = false;
|
||||
if (pgParent != null)
|
||||
@@ -80,27 +69,30 @@ namespace keepass2android
|
||||
protected void EnsureRecycleBin(ref PwGroup pgRecycleBin,
|
||||
ref bool bGroupListUpdateRequired)
|
||||
{
|
||||
if ((mDb == null) || (mDb.pm == null)) { return; }
|
||||
if ((Db == null) || (Db.KpDatabase == null)) { return; }
|
||||
|
||||
if(pgRecycleBin == mDb.pm.RootGroup)
|
||||
if(pgRecycleBin == Db.KpDatabase.RootGroup)
|
||||
{
|
||||
pgRecycleBin = null;
|
||||
}
|
||||
|
||||
if(pgRecycleBin == null)
|
||||
{
|
||||
pgRecycleBin = new PwGroup(true, true, mApp.GetResourceString(UiStringKey.RecycleBin),
|
||||
PwIcon.TrashBin);
|
||||
pgRecycleBin.EnableAutoType = false;
|
||||
pgRecycleBin.EnableSearching = false;
|
||||
pgRecycleBin.IsExpanded = false;
|
||||
mDb.pm.RootGroup.AddGroup(pgRecycleBin, true);
|
||||
pgRecycleBin = new PwGroup(true, true, App.GetResourceString(UiStringKey.RecycleBin),
|
||||
PwIcon.TrashBin)
|
||||
{
|
||||
EnableAutoType = false,
|
||||
EnableSearching = false,
|
||||
IsExpanded = false
|
||||
};
|
||||
|
||||
Db.KpDatabase.RootGroup.AddGroup(pgRecycleBin, true);
|
||||
|
||||
mDb.pm.RecycleBinUuid = pgRecycleBin.Uuid;
|
||||
Db.KpDatabase.RecycleBinUuid = pgRecycleBin.Uuid;
|
||||
|
||||
bGroupListUpdateRequired = true;
|
||||
}
|
||||
else { System.Diagnostics.Debug.Assert(pgRecycleBin.Uuid.EqualsValue(mDb.pm.RecycleBinUuid)); }
|
||||
else { System.Diagnostics.Debug.Assert(pgRecycleBin.Uuid.EqualsValue(Db.KpDatabase.RecycleBinUuid)); }
|
||||
}
|
||||
|
||||
protected abstract UiStringKey QuestionsResourceId
|
||||
@@ -108,31 +100,31 @@ namespace keepass2android
|
||||
get;
|
||||
}
|
||||
|
||||
public void start()
|
||||
public void Start()
|
||||
{
|
||||
if (CanRecycle)
|
||||
{
|
||||
mApp.AskYesNoCancel(UiStringKey.AskDeletePermanently_title,
|
||||
App.AskYesNoCancel(UiStringKey.AskDeletePermanently_title,
|
||||
QuestionsResourceId,
|
||||
new EventHandler<DialogClickEventArgs>((dlgSender, dlgEvt) =>
|
||||
{
|
||||
DeletePermanently = true;
|
||||
ProgressTask pt = new ProgressTask(mApp, mCtx, this, UiStringKey.saving_database);
|
||||
pt.run();
|
||||
}),
|
||||
new EventHandler<DialogClickEventArgs>((dlgSender, dlgEvt) => {
|
||||
DeletePermanently = false;
|
||||
ProgressTask pt = new ProgressTask(mApp, mCtx, this, UiStringKey.saving_database);
|
||||
pt.run();
|
||||
}),
|
||||
new EventHandler<DialogClickEventArgs>((dlgSender, dlgEvt) => {}),
|
||||
mCtx);
|
||||
(dlgSender, dlgEvt) =>
|
||||
{
|
||||
DeletePermanently = true;
|
||||
ProgressTask pt = new ProgressTask(App, Ctx, this, UiStringKey.saving_database);
|
||||
pt.run();
|
||||
},
|
||||
(dlgSender, dlgEvt) => {
|
||||
DeletePermanently = false;
|
||||
ProgressTask pt = new ProgressTask(App, Ctx, this, UiStringKey.saving_database);
|
||||
pt.run();
|
||||
},
|
||||
(dlgSender, dlgEvt) => {},
|
||||
Ctx);
|
||||
|
||||
|
||||
|
||||
} else
|
||||
{
|
||||
ProgressTask pt = new ProgressTask(mApp, mCtx, this, UiStringKey.saving_database);
|
||||
ProgressTask pt = new ProgressTask(App, Ctx, this, UiStringKey.saving_database);
|
||||
pt.run();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,34 +16,21 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
public abstract class FileOnFinish : OnFinish {
|
||||
private String mFilename = "";
|
||||
|
||||
public FileOnFinish(FileOnFinish finish):base(finish) {
|
||||
private String _filename = "";
|
||||
|
||||
protected FileOnFinish(FileOnFinish finish):base(finish) {
|
||||
}
|
||||
|
||||
public void setFilename(String filename) {
|
||||
mFilename = filename;
|
||||
|
||||
public string Filename
|
||||
{
|
||||
get { return _filename; }
|
||||
set { _filename = value; }
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
return mFilename;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,98 +16,85 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using Android.Preferences;
|
||||
using KeePassLib.Serialization;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
public class LoadDB : RunnableOnFinish {
|
||||
private IOConnectionInfo mIoc;
|
||||
private String mPass;
|
||||
private String mKey;
|
||||
private IKp2aApp mApp;
|
||||
private Context mCtx;
|
||||
private bool mRememberKeyfile;
|
||||
public class LoadDb : RunnableOnFinish {
|
||||
private readonly IOConnectionInfo _ioc;
|
||||
private readonly String _pass;
|
||||
private readonly String _key;
|
||||
private readonly IKp2aApp _app;
|
||||
private readonly bool _rememberKeyfile;
|
||||
|
||||
public LoadDB(IKp2aApp app, Context ctx, IOConnectionInfo ioc, String pass, String key, OnFinish finish): base(finish)
|
||||
public LoadDb(IKp2aApp app, IOConnectionInfo ioc, String pass, String key, OnFinish finish): base(finish)
|
||||
{
|
||||
mApp = app;
|
||||
mCtx = ctx;
|
||||
mIoc = ioc;
|
||||
mPass = pass;
|
||||
mKey = key;
|
||||
_app = app;
|
||||
_ioc = ioc;
|
||||
_pass = pass;
|
||||
_key = key;
|
||||
|
||||
|
||||
mRememberKeyfile = app.GetBooleanPreference(PreferenceKey.remember_keyfile);
|
||||
_rememberKeyfile = app.GetBooleanPreference(PreferenceKey.remember_keyfile);
|
||||
}
|
||||
|
||||
|
||||
public override void run ()
|
||||
public override void Run ()
|
||||
{
|
||||
try {
|
||||
mApp.GetDb().LoadData (mApp, mIoc, mPass, mKey, mStatus);
|
||||
_app.GetDb().LoadData (_app, _ioc, _pass, _key, Status);
|
||||
|
||||
saveFileData (mIoc, mKey);
|
||||
SaveFileData (_ioc, _key);
|
||||
|
||||
} catch (KeyFileException) {
|
||||
finish(false, /*TODO Localize: use Keepass error text KPRes.KeyFileError (including "or invalid format")*/ mApp.GetResourceString(UiStringKey.keyfile_does_not_exist));
|
||||
Finish(false, /*TODO Localize: use Keepass error text KPRes.KeyFileError (including "or invalid format")*/ _app.GetResourceString(UiStringKey.keyfile_does_not_exist));
|
||||
}
|
||||
catch (Exception e) {
|
||||
finish(false, "An error occured: " + e.Message);
|
||||
Finish(false, "An error occured: " + e.Message);
|
||||
return;
|
||||
}
|
||||
/* catch (InvalidPasswordException e) {
|
||||
finish(false, mCtx.GetString(Resource.String.InvalidPassword));
|
||||
finish(false, Ctx.GetString(Resource.String.InvalidPassword));
|
||||
return;
|
||||
} catch (FileNotFoundException e) {
|
||||
finish(false, mCtx.GetString(Resource.String.FileNotFound));
|
||||
finish(false, Ctx.GetString(Resource.String.FileNotFound));
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
finish(false, e.getMessage());
|
||||
return;
|
||||
} catch (KeyFileEmptyException e) {
|
||||
finish(false, mCtx.GetString(Resource.String.keyfile_is_empty));
|
||||
finish(false, Ctx.GetString(Resource.String.keyfile_is_empty));
|
||||
return;
|
||||
} catch (InvalidAlgorithmException e) {
|
||||
finish(false, mCtx.GetString(Resource.String.invalid_algorithm));
|
||||
finish(false, Ctx.GetString(Resource.String.invalid_algorithm));
|
||||
return;
|
||||
} catch (InvalidKeyFileException e) {
|
||||
finish(false, mCtx.GetString(Resource.String.keyfile_does_not_exist));
|
||||
finish(false, Ctx.GetString(Resource.String.keyfile_does_not_exist));
|
||||
return;
|
||||
} catch (InvalidDBSignatureException e) {
|
||||
finish(false, mCtx.GetString(Resource.String.invalid_db_sig));
|
||||
finish(false, Ctx.GetString(Resource.String.invalid_db_sig));
|
||||
return;
|
||||
} catch (InvalidDBVersionException e) {
|
||||
finish(false, mCtx.GetString(Resource.String.unsupported_db_version));
|
||||
finish(false, Ctx.GetString(Resource.String.unsupported_db_version));
|
||||
return;
|
||||
} catch (InvalidDBException e) {
|
||||
finish(false, mCtx.GetString(Resource.String.error_invalid_db));
|
||||
finish(false, Ctx.GetString(Resource.String.error_invalid_db));
|
||||
return;
|
||||
} catch (OutOfMemoryError e) {
|
||||
finish(false, mCtx.GetString(Resource.String.error_out_of_memory));
|
||||
finish(false, Ctx.GetString(Resource.String.error_out_of_memory));
|
||||
return;
|
||||
}
|
||||
*/
|
||||
finish(true);
|
||||
Finish(true);
|
||||
}
|
||||
|
||||
private void saveFileData(IOConnectionInfo ioc, String key) {
|
||||
private void SaveFileData(IOConnectionInfo ioc, String key) {
|
||||
|
||||
if (!mRememberKeyfile)
|
||||
if (!_rememberKeyfile)
|
||||
{
|
||||
key = "";
|
||||
}
|
||||
mApp.StoreOpenedFileAsRecent(ioc, key);
|
||||
_app.StoreOpenedFileAsRecent(ioc, key);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,72 +16,65 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
public abstract class OnFinish
|
||||
{
|
||||
protected bool mSuccess;
|
||||
protected String mMessage;
|
||||
protected bool Success;
|
||||
protected String Message;
|
||||
|
||||
protected OnFinish mOnFinish;
|
||||
protected Handler mHandler;
|
||||
|
||||
public OnFinish() {
|
||||
protected OnFinish BaseOnFinish;
|
||||
protected Handler Handler;
|
||||
|
||||
protected OnFinish() {
|
||||
}
|
||||
|
||||
protected OnFinish(Handler handler) {
|
||||
BaseOnFinish = null;
|
||||
Handler = handler;
|
||||
}
|
||||
|
||||
protected OnFinish(OnFinish finish, Handler handler) {
|
||||
BaseOnFinish = finish;
|
||||
Handler = handler;
|
||||
}
|
||||
|
||||
protected OnFinish(OnFinish finish) {
|
||||
BaseOnFinish = finish;
|
||||
Handler = null;
|
||||
}
|
||||
|
||||
public OnFinish(Handler handler) {
|
||||
mOnFinish = null;
|
||||
mHandler = handler;
|
||||
public void SetResult(bool success, String message) {
|
||||
Success = success;
|
||||
Message = message;
|
||||
}
|
||||
|
||||
public OnFinish(OnFinish finish, Handler handler) {
|
||||
mOnFinish = finish;
|
||||
mHandler = handler;
|
||||
public void SetResult(bool success) {
|
||||
Success = success;
|
||||
}
|
||||
|
||||
public OnFinish(OnFinish finish) {
|
||||
mOnFinish = finish;
|
||||
mHandler = null;
|
||||
}
|
||||
|
||||
public void setResult(bool success, String message) {
|
||||
mSuccess = success;
|
||||
mMessage = message;
|
||||
}
|
||||
|
||||
public void setResult(bool success) {
|
||||
mSuccess = success;
|
||||
}
|
||||
|
||||
public virtual void run() {
|
||||
if ( mOnFinish != null ) {
|
||||
public virtual void Run() {
|
||||
if ( BaseOnFinish != null ) {
|
||||
// Pass on result on call finish
|
||||
mOnFinish.setResult(mSuccess, mMessage);
|
||||
BaseOnFinish.SetResult(Success, Message);
|
||||
|
||||
if ( mHandler != null ) {
|
||||
mHandler.Post(mOnFinish.run);
|
||||
if ( Handler != null ) {
|
||||
Handler.Post(BaseOnFinish.Run);
|
||||
} else {
|
||||
mOnFinish.run();
|
||||
BaseOnFinish.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void displayMessage(Context ctx) {
|
||||
displayMessage(ctx, mMessage);
|
||||
protected void DisplayMessage(Context ctx) {
|
||||
DisplayMessage(ctx, Message);
|
||||
}
|
||||
|
||||
public static void displayMessage(Context ctx, string message)
|
||||
public static void DisplayMessage(Context ctx, string message)
|
||||
{
|
||||
if ( !String.IsNullOrEmpty(message) ) {
|
||||
Toast.MakeText(ctx, message, ToastLength.Long).Show();
|
||||
|
||||
@@ -15,48 +15,38 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
public abstract class RunnableOnFinish {
|
||||
|
||||
public OnFinish mFinish;
|
||||
public UpdateStatus mStatus;
|
||||
|
||||
public RunnableOnFinish(OnFinish finish) {
|
||||
mFinish = finish;
|
||||
public OnFinish OnFinishToRun;
|
||||
public UpdateStatus Status;
|
||||
|
||||
protected RunnableOnFinish(OnFinish finish) {
|
||||
OnFinishToRun = finish;
|
||||
}
|
||||
|
||||
protected void finish(bool result, String message) {
|
||||
if ( mFinish != null ) {
|
||||
mFinish.setResult(result, message);
|
||||
mFinish.run();
|
||||
protected void Finish(bool result, String message) {
|
||||
if ( OnFinishToRun != null ) {
|
||||
OnFinishToRun.SetResult(result, message);
|
||||
OnFinishToRun.Run();
|
||||
}
|
||||
}
|
||||
|
||||
protected void finish(bool result) {
|
||||
if ( mFinish != null ) {
|
||||
mFinish.setResult(result);
|
||||
mFinish.run();
|
||||
protected void Finish(bool result) {
|
||||
if ( OnFinishToRun != null ) {
|
||||
OnFinishToRun.SetResult(result);
|
||||
OnFinishToRun.Run();
|
||||
}
|
||||
}
|
||||
|
||||
public void setStatus(UpdateStatus status) {
|
||||
mStatus = status;
|
||||
public void SetStatus(UpdateStatus status) {
|
||||
Status = status;
|
||||
}
|
||||
|
||||
abstract public void run();
|
||||
abstract public void Run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,46 +15,37 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
public class SaveDB : RunnableOnFinish {
|
||||
private Database mDb;
|
||||
private bool mDontSave;
|
||||
private Context mCtx;
|
||||
public class SaveDb : RunnableOnFinish {
|
||||
private readonly Database _db;
|
||||
private readonly bool _dontSave;
|
||||
private readonly Context _ctx;
|
||||
|
||||
public SaveDB(Context ctx, Database db, OnFinish finish, bool dontSave): base(finish) {
|
||||
mCtx = ctx;
|
||||
mDb = db;
|
||||
mDontSave = dontSave;
|
||||
public SaveDb(Context ctx, Database db, OnFinish finish, bool dontSave): base(finish) {
|
||||
_ctx = ctx;
|
||||
_db = db;
|
||||
_dontSave = dontSave;
|
||||
}
|
||||
|
||||
public SaveDB(Context ctx, Database db, OnFinish finish):base(finish) {
|
||||
mCtx = ctx;
|
||||
mDb = db;
|
||||
mDontSave = false;
|
||||
public SaveDb(Context ctx, Database db, OnFinish finish):base(finish) {
|
||||
_ctx = ctx;
|
||||
_db = db;
|
||||
_dontSave = false;
|
||||
}
|
||||
|
||||
|
||||
public override void run ()
|
||||
public override void Run ()
|
||||
{
|
||||
|
||||
if (! mDontSave) {
|
||||
if (! _dontSave) {
|
||||
try {
|
||||
mDb.SaveData (mCtx);
|
||||
if (mDb.mIoc.IsLocalFile())
|
||||
mDb.mLastChangeDate = System.IO.File.GetLastWriteTimeUtc(mDb.mIoc.Path);
|
||||
_db.SaveData (_ctx);
|
||||
if (_db.Ioc.IsLocalFile())
|
||||
_db.LastChangeDate = System.IO.File.GetLastWriteTimeUtc(_db.Ioc.Path);
|
||||
} catch (Exception e) {
|
||||
/* TODO KPDesktop:
|
||||
* catch(Exception exSave)
|
||||
@@ -63,12 +54,12 @@ namespace keepass2android
|
||||
bSuccess = false;
|
||||
}
|
||||
*/
|
||||
finish (false, e.Message);
|
||||
Finish (false, e.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
finish(true);
|
||||
Finish(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,16 +15,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using KeePassLib;
|
||||
using KeePassLib.Keys;
|
||||
|
||||
@@ -32,40 +23,40 @@ namespace keepass2android
|
||||
{
|
||||
public class SetPassword : RunnableOnFinish {
|
||||
|
||||
private String mPassword;
|
||||
private String mKeyfile;
|
||||
private Database mDb;
|
||||
private bool mDontSave;
|
||||
private Context mCtx;
|
||||
private readonly String _password;
|
||||
private readonly String _keyfile;
|
||||
private readonly Database _db;
|
||||
private readonly bool _dontSave;
|
||||
private readonly Context _ctx;
|
||||
|
||||
public SetPassword(Context ctx, Database db, String password, String keyfile, OnFinish finish): base(finish) {
|
||||
mCtx = ctx;
|
||||
mDb = db;
|
||||
mPassword = password;
|
||||
mKeyfile = keyfile;
|
||||
mDontSave = false;
|
||||
_ctx = ctx;
|
||||
_db = db;
|
||||
_password = password;
|
||||
_keyfile = keyfile;
|
||||
_dontSave = false;
|
||||
}
|
||||
|
||||
public SetPassword(Context ctx, Database db, String password, String keyfile, OnFinish finish, bool dontSave): base(finish) {
|
||||
mCtx = ctx;
|
||||
mDb = db;
|
||||
mPassword = password;
|
||||
mKeyfile = keyfile;
|
||||
mDontSave = dontSave;
|
||||
_ctx = ctx;
|
||||
_db = db;
|
||||
_password = password;
|
||||
_keyfile = keyfile;
|
||||
_dontSave = dontSave;
|
||||
}
|
||||
|
||||
|
||||
public override void run ()
|
||||
public override void Run ()
|
||||
{
|
||||
PwDatabase pm = mDb.pm;
|
||||
PwDatabase pm = _db.KpDatabase;
|
||||
CompositeKey newKey = new CompositeKey ();
|
||||
if (String.IsNullOrEmpty (mPassword) == false) {
|
||||
newKey.AddUserKey (new KcpPassword (mPassword));
|
||||
if (String.IsNullOrEmpty (_password) == false) {
|
||||
newKey.AddUserKey (new KcpPassword (_password));
|
||||
}
|
||||
if (String.IsNullOrEmpty (mKeyfile) == false) {
|
||||
if (String.IsNullOrEmpty (_keyfile) == false) {
|
||||
try {
|
||||
newKey.AddUserKey (new KcpKeyFile (mKeyfile));
|
||||
} catch (Exception exKF) {
|
||||
newKey.AddUserKey (new KcpKeyFile (_keyfile));
|
||||
} catch (Exception) {
|
||||
//TODO MessageService.ShowWarning (strKeyFile, KPRes.KeyFileError, exKF);
|
||||
return;
|
||||
}
|
||||
@@ -78,29 +69,29 @@ namespace keepass2android
|
||||
pm.MasterKey = newKey;
|
||||
|
||||
// Save Database
|
||||
mFinish = new AfterSave(previousKey, previousMasterKeyChanged, pm, mFinish);
|
||||
SaveDB save = new SaveDB(mCtx, mDb, mFinish, mDontSave);
|
||||
save.run();
|
||||
OnFinishToRun = new AfterSave(previousKey, previousMasterKeyChanged, pm, OnFinishToRun);
|
||||
SaveDb save = new SaveDb(_ctx, _db, OnFinishToRun, _dontSave);
|
||||
save.Run();
|
||||
}
|
||||
|
||||
private class AfterSave : OnFinish {
|
||||
private CompositeKey mBackup;
|
||||
private DateTime mPreviousKeyChanged;
|
||||
private PwDatabase mDb;
|
||||
private readonly CompositeKey _backup;
|
||||
private readonly DateTime _previousKeyChanged;
|
||||
private PwDatabase _db;
|
||||
|
||||
public AfterSave(CompositeKey backup, DateTime previousKeyChanged, PwDatabase db, OnFinish finish): base(finish) {
|
||||
mPreviousKeyChanged = previousKeyChanged;
|
||||
mBackup = backup;
|
||||
mDb = db;
|
||||
_previousKeyChanged = previousKeyChanged;
|
||||
_backup = backup;
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public override void run() {
|
||||
if ( ! mSuccess ) {
|
||||
mDb.MasterKey = mBackup;
|
||||
mDb.MasterKeyChanged = mPreviousKeyChanged;
|
||||
public override void Run() {
|
||||
if ( ! Success ) {
|
||||
_db.MasterKey = _backup;
|
||||
_db.MasterKeyChanged = _previousKeyChanged;
|
||||
}
|
||||
|
||||
base.run();
|
||||
base.Run();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,81 +15,67 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using KeePassLib;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
public class UpdateEntry : RunnableOnFinish {
|
||||
private Database mDb;
|
||||
private PwEntry mOldE;
|
||||
private PwEntry mNewE;
|
||||
private Context mCtx;
|
||||
private readonly Database _db;
|
||||
private readonly Context _ctx;
|
||||
|
||||
public UpdateEntry(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinish finish):base(finish) {
|
||||
mCtx = ctx;
|
||||
mDb = db;
|
||||
mOldE = oldE;
|
||||
mNewE = newE;
|
||||
_ctx = ctx;
|
||||
_db = db;
|
||||
|
||||
mFinish = new AfterUpdate(oldE, newE, db, finish);
|
||||
OnFinishToRun = new AfterUpdate(oldE, newE, db, finish);
|
||||
}
|
||||
|
||||
|
||||
public override void run() {
|
||||
public override void Run() {
|
||||
// Commit to disk
|
||||
SaveDB save = new SaveDB(mCtx, mDb, mFinish);
|
||||
save.run();
|
||||
SaveDb save = new SaveDb(_ctx, _db, OnFinishToRun);
|
||||
save.Run();
|
||||
}
|
||||
|
||||
private class AfterUpdate : OnFinish {
|
||||
private PwEntry mBackup;
|
||||
private PwEntry mUpdatedEntry;
|
||||
private Database mDb;
|
||||
private readonly PwEntry _backup;
|
||||
private readonly PwEntry _updatedEntry;
|
||||
private readonly Database _db;
|
||||
|
||||
public AfterUpdate(PwEntry backup, PwEntry updatedEntry, Database db, OnFinish finish):base(finish) {
|
||||
mBackup = backup;
|
||||
mUpdatedEntry = updatedEntry;
|
||||
mDb = db;
|
||||
_backup = backup;
|
||||
_updatedEntry = updatedEntry;
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public override void run() {
|
||||
if ( mSuccess ) {
|
||||
public override void Run() {
|
||||
if ( Success ) {
|
||||
// Mark group dirty if title, icon or Expiry stuff changes
|
||||
if ( ! mBackup.Strings.ReadSafe (PwDefs.TitleField).Equals(mUpdatedEntry.Strings.ReadSafe (PwDefs.TitleField))
|
||||
|| ! mBackup.IconId.Equals(mUpdatedEntry.IconId)
|
||||
|| ! mBackup.CustomIconUuid.EqualsValue(mUpdatedEntry.CustomIconUuid)
|
||||
|| mBackup.Expires != mUpdatedEntry.Expires
|
||||
|| (mBackup.Expires && (! mBackup.ExpiryTime.Equals(mUpdatedEntry.ExpiryTime)))
|
||||
if ( ! _backup.Strings.ReadSafe (PwDefs.TitleField).Equals(_updatedEntry.Strings.ReadSafe (PwDefs.TitleField))
|
||||
|| ! _backup.IconId.Equals(_updatedEntry.IconId)
|
||||
|| ! _backup.CustomIconUuid.EqualsValue(_updatedEntry.CustomIconUuid)
|
||||
|| _backup.Expires != _updatedEntry.Expires
|
||||
|| (_backup.Expires && (! _backup.ExpiryTime.Equals(_updatedEntry.ExpiryTime)))
|
||||
)
|
||||
|
||||
{
|
||||
PwGroup parent = mUpdatedEntry.ParentGroup;
|
||||
PwGroup parent = _updatedEntry.ParentGroup;
|
||||
if ( parent != null ) {
|
||||
|
||||
// Mark parent group dirty
|
||||
mDb.dirty.Add(parent);
|
||||
_db.Dirty.Add(parent);
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If we fail to save, back out changes to global structure
|
||||
//TODO test fail
|
||||
mUpdatedEntry.AssignProperties(mBackup, false, true, false);
|
||||
_updatedEntry.AssignProperties(_backup, false, true, false);
|
||||
}
|
||||
|
||||
base.run();
|
||||
base.Run();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user