public void Start() { if (CanRecycle) { App.AskYesNoCancel(UiStringKey.AskDeletePermanently_title, QuestionsResourceId, (dlgSender, dlgEvt) => { DeletePermanently = true; ProgressTask pt = new ProgressTask(App, Ctx, this); pt.Run(); }, (dlgSender, dlgEvt) => { DeletePermanently = false; ProgressTask pt = new ProgressTask(App, Ctx, this); pt.Run(); }, (dlgSender, dlgEvt) => {}, Ctx); } else { ProgressTask pt = new ProgressTask(App, Ctx, this); pt.Run(); } }
private void CreateDatabase(bool makeCurrent) { var keyfileCheckbox = FindViewById <CheckBox>(Resource.Id.use_keyfile); string password; if (!TryGetPassword(out password)) { return; } // Verify that a password or keyfile is set if (password.Length == 0 && !keyfileCheckbox.Checked) { Toast.MakeText(this, Resource.String.error_nopass, ToastLength.Long).Show(); return; } //create the key CompositeKey newKey = new CompositeKey(); if (String.IsNullOrEmpty(password) == false) { newKey.AddUserKey(new KcpPassword(password)); } if (String.IsNullOrEmpty(_keyfileFilename) == false) { try { var ioc = IOConnectionInfo.FromPath(_keyfileFilename); using (var stream = App.Kp2a.GetFileStorage(ioc).OpenFileForRead(ioc)) { byte[] keyfileData = Util.StreamToMemoryStream(stream).ToArray(); newKey.AddUserKey(new KcpKeyFile(keyfileData, ioc, true)); } } catch (Exception) { Toast.MakeText(this, Resource.String.error_adding_keyfile, ToastLength.Long).Show(); return; } } // Create the new database CreateDb create = new CreateDb(App.Kp2a, this, _ioc, new LaunchGroupActivity(_ioc, this), false, newKey, makeCurrent); ProgressTask createTask = new ProgressTask( App.Kp2a, this, create); createTask.Run(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.set_password); SetTitle(Resource.String.password_title); // Ok button Button okButton = (Button)FindViewById(Resource.Id.ok); okButton.Click += (sender, e) => { TextView passView = (TextView)FindViewById(Resource.Id.pass_password); String pass = passView.Text; TextView passConfView = (TextView)FindViewById(Resource.Id.pass_conf_password); String confpass = passConfView.Text; // Verify that passwords match if (!pass.Equals(confpass)) { // Passwords do not match Toast.MakeText(Context, Resource.String.error_pass_match, ToastLength.Long).Show(); return; } TextView keyfileView = (TextView)FindViewById(Resource.Id.pass_keyfile); String keyfile = keyfileView.Text; Keyfile = keyfile; // Verify that a password or keyfile is set if (pass.Length == 0 && keyfile.Length == 0) { Toast.MakeText(Context, Resource.String.error_nopass, ToastLength.Long).Show(); return; } SetPassword sp = new SetPassword(_activity, App.Kp2a, pass, keyfile, new AfterSave(_activity, this, null, new Handler())); ProgressTask pt = new ProgressTask(App.Kp2a, _activity, sp); pt.Run(); }; // Cancel button Button cancelButton = (Button)FindViewById(Resource.Id.cancel); cancelButton.Click += (sender, e) => { Cancel(); }; }
protected override void SaveFile(IOConnectionInfo ioc) { var task = new EntryActivity.WriteBinaryTask(_activity, App.Kp2a, new ActionOnFinish(_activity, (success, message, activity) => { if (!success) { Toast.MakeText(activity, message, ToastLength.Long).Show(); } } ), ((EntryActivity)_activity).Entry.Binaries.Get(_binaryToSave), ioc); ProgressTask pt = new ProgressTask(App.Kp2a, _activity, task); pt.Run(); }
private void AddAutoOpenEntryForDatabase(Database db) { PwGroup autoOpenGroup = null; var rootGroup = App.Kp2a.CurrentDb.KpDatabase.RootGroup; foreach (PwGroup pgSub in rootGroup.Groups) { if (pgSub.Name == "AutoOpen") { autoOpenGroup = pgSub; break; } } if (autoOpenGroup == null) { AddGroup addGroupTask = AddGroup.GetInstance(this, App.Kp2a, "AutoOpen", 1, null, rootGroup, null, true); addGroupTask.Run(); autoOpenGroup = addGroupTask.Group; } PwEntry newEntry = new PwEntry(true, true); newEntry.Strings.Set(PwDefs.TitleField, new ProtectedString(false, App.Kp2a.GetFileStorage(db.Ioc).GetDisplayName(db.Ioc))); newEntry.Strings.Set(PwDefs.UrlField, new ProtectedString(false, TryMakeRelativePath(App.Kp2a.CurrentDb, db.Ioc))); var password = db.KpDatabase.MasterKey.GetUserKey <KcpPassword>(); newEntry.Strings.Set(PwDefs.PasswordField, password == null ? new ProtectedString(true, "") : password.Password); var keyfile = db.KpDatabase.MasterKey.GetUserKey <KcpKeyFile>(); if ((keyfile != null) && (keyfile.Ioc != null)) { newEntry.Strings.Set(PwDefs.UserNameField, new ProtectedString(false, TryMakeRelativePath(App.Kp2a.CurrentDb, keyfile.Ioc))); } newEntry.Strings.Set(KeeAutoExecExt._ifDevice, new ProtectedString(false, KeeAutoExecExt.BuildIfDevice(new Dictionary <string, bool>() { { KeeAutoExecExt.ThisDeviceId, true } }))); var addTask = new AddEntry(this, App.Kp2a, newEntry, autoOpenGroup, new ActionOnFinish(this, (success, message, activity) => (activity as ConfigureChildDatabasesActivity)?.Update())); ProgressTask pt = new ProgressTask(App.Kp2a, this, addTask); pt.Run(); }
public void Run(bool allowOverwriteCurrentTask = false) { if ((!allowOverwriteCurrentTask) && (_currentTask != null)) { throw new Exception("Cannot start another ProgressTask while ProgressTask is already running! " + _task.GetType().Name + "/" + _currentTask._task.GetType().Name); } _currentTask = this; // Show process dialog _progressDialog.Show(); // Start Thread to Run task _thread = new Thread(_task.Run); _thread.Start(); }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (AppTask.TryGetFromActivityResult(data, ref AppTask)) { //make sure the app task is passed to the calling activity AppTask.SetActivityResult(this, KeePass.ExitNormal); } if ((GroupEditActivity.RequestCodeGroupEdit == requestCode) && (resultCode == Result.Ok)) { String groupName = data.Extras.GetString(GroupEditActivity.KeyName); int groupIconId = data.Extras.GetInt(GroupEditActivity.KeyIconId); PwUuid groupCustomIconId = new PwUuid(MemUtil.HexStringToByteArray(data.Extras.GetString(GroupEditActivity.KeyCustomIconId))); String strGroupUuid = data.Extras.GetString(GroupEditActivity.KeyGroupUuid); GroupBaseActivity act = this; Handler handler = new Handler(); RunnableOnFinish task; if (strGroupUuid == null) { task = AddGroup.GetInstance(this, App.Kp2a, groupName, groupIconId, groupCustomIconId, Group, new RefreshTask(handler, this), false); } else { PwUuid groupUuid = new PwUuid(MemUtil.HexStringToByteArray(strGroupUuid)); task = new EditGroup(this, App.Kp2a, groupName, (PwIcon)groupIconId, groupCustomIconId, App.Kp2a.GetDb().Groups[groupUuid], new RefreshTask(handler, this)); } ProgressTask pt = new ProgressTask(App.Kp2a, act, task); pt.Run(); } if (resultCode == KeePass.ExitCloseAfterTaskComplete) { AppTask.SetActivityResult(this, KeePass.ExitCloseAfterTaskComplete); Finish(); } if (resultCode == KeePass.ExitReloadDb) { AppTask.SetActivityResult(this, KeePass.ExitReloadDb); Finish(); } }
private void InsertElements() { MoveElementsTask moveElementsTask = (MoveElementsTask)AppTask; IEnumerable <IStructureItem> elementsToMove = moveElementsTask.Uuids.Select(uuid => App.Kp2a.GetDb().KpDatabase.RootGroup.FindObject(uuid, true, null)); var moveElement = new MoveElements(elementsToMove.ToList(), Group, this, App.Kp2a, new ActionOnFinish((success, message) => { StopMovingElements(); if (!String.IsNullOrEmpty(message)) { Toast.MakeText(this, message, ToastLength.Long).Show(); } })); var progressTask = new ProgressTask(App.Kp2a, this, moveElement); progressTask.Run(); }
public void SynchronizeDatabase(Action runAfterSuccess) { var filestorage = App.Kp2a.GetFileStorage(App.Kp2a.CurrentDb.Ioc); RunnableOnFinish task; OnFinish onFinish = new ActionOnFinish(_activity, (success, message, activity) => { if (!String.IsNullOrEmpty(message)) { Toast.MakeText(activity, message, ToastLength.Long).Show(); } // Tell the adapter to refresh it's list BaseAdapter adapter = (activity as GroupBaseActivity)?.ListAdapter; adapter?.NotifyDataSetChanged(); if (App.Kp2a.CurrentDb?.OtpAuxFileIoc != null) { var task2 = new SyncOtpAuxFile(_activity, App.Kp2a.CurrentDb.OtpAuxFileIoc); task2.OnFinishToRun = new ActionOnFinish(_activity, (b, s, activeActivity) => { runAfterSuccess(); }); new ProgressTask(App.Kp2a, activity, task2).Run(true); } else { runAfterSuccess(); } }); if (filestorage is CachingFileStorage) { task = new SynchronizeCachedDatabase(_activity, App.Kp2a, onFinish); } else { task = new CheckDatabaseForChanges(_activity, App.Kp2a, onFinish); } var progressTask = new ProgressTask(App.Kp2a, _activity, task); progressTask.Run(); }
private void ExportTo(IOConnectionInfo ioc) { var exportDb = new ExportDb(App.Kp2a, new ActionOnFinish(delegate(bool success, string message) { if (!success) { Toast.MakeText(this, message, ToastLength.Long).Show(); } else { Toast.MakeText(this, GetString(Resource.String.export_database_successful), ToastLength.Long).Show(); } Finish(); } ), _ffp[_fileFormatIndex], ioc); ProgressTask pt = new ProgressTask(App.Kp2a, this, exportDb); pt.Run(); }
protected override void SaveFile(IOConnectionInfo ioc) { var exportDb = new ExportDatabaseActivity.ExportDb(_activity, App.Kp2a, new ActionOnFinish(_activity, (success, message, activity) => { if (!success) { Toast.MakeText(activity, message, ToastLength.Long).Show(); } else { Toast.MakeText(activity, _activity.GetString(Resource.String.export_database_successful), ToastLength.Long).Show(); } activity.Finish(); } ), _ffp, ioc); ProgressTask pt = new ProgressTask(App.Kp2a, _activity, exportDb); pt.Run(); }
internal void AddUrlToEntry(string url, Action finishAction) { PwEntry initialEntry = Entry.CloneDeep(); PwEntry newEntry = Entry; newEntry.History = newEntry.History.CloneDeep(); newEntry.CreateBackup(null); newEntry.Touch(true, false); // Touch *after* backup //if there is no URL in the entry, set that field. If it's already in use, use an additional (not existing) field if (String.IsNullOrEmpty(newEntry.Strings.ReadSafe(PwDefs.UrlField))) { newEntry.Strings.Set(PwDefs.UrlField, new ProtectedString(false, url)); } else { int c = 1; while (newEntry.Strings.Get("KP2A_URL_" + c) != null) { c++; } newEntry.Strings.Set("KP2A_URL_" + c, new ProtectedString(false, url)); } //save the entry: ActionOnFinish closeOrShowError = new ActionOnFinish((success, message) => { OnFinish.DisplayMessage(this, message); finishAction(); }); RunnableOnFinish runnable = new UpdateEntry(this, App.Kp2a, initialEntry, newEntry, closeOrShowError); ProgressTask pt = new ProgressTask(App.Kp2a, this, runnable); pt.Run(); }
private void AlgorithmPrefChange(object sender, Preference.PreferenceChangeEventArgs preferenceChangeEventArgs) { var db = App.Kp2a.GetDb(); var previousCipher = db.KpDatabase.DataCipherUuid; db.KpDatabase.DataCipherUuid = new PwUuid(MemUtil.HexStringToByteArray((string)preferenceChangeEventArgs.NewValue)); SaveDb save = new SaveDb(Activity, App.Kp2a, new ActionOnFinish((success, message) => { if (!success) { db.KpDatabase.DataCipherUuid = previousCipher; Toast.MakeText(Activity, message, ToastLength.Long).Show(); return; } preferenceChangeEventArgs.Preference.Summary = CipherPool.GlobalPool.GetCipher(db.KpDatabase.DataCipherUuid).DisplayName; })); ProgressTask pt = new ProgressTask(App.Kp2a, Activity, save); pt.Run(); }
private void PrepareTemplates(Database db) { Preference pref = FindPreference("AddTemplates_pref_key"); if ((!db.DatabaseFormat.SupportsTemplates) || (AddTemplateEntries.ContainsAllTemplates(App.Kp2a))) { pref.Enabled = false; } else { pref.PreferenceClick += (sender, args) => { ProgressTask pt = new ProgressTask(App.Kp2a, Activity, new AddTemplateEntries(Activity, App.Kp2a, new ActionOnFinish( delegate { pref.Enabled = false; }))); pt.Run(); }; } }
private void PrepareDatabaseName(Database db) { Preference databaseName = FindPreference(GetString(Resource.String.database_name_key)); if (!db.DatabaseFormat.HasDatabaseName) { ((PreferenceScreen)FindPreference(GetString(Resource.String.db_key))).RemovePreference(databaseName); } else { databaseName.Enabled = db.CanWrite; ((EditTextPreference)databaseName).EditText.Text = db.KpDatabase.Name; ((EditTextPreference)databaseName).Text = db.KpDatabase.Name; databaseName.PreferenceChange += (sender, e) => { DateTime previousNameChanged = db.KpDatabase.NameChanged; String previousName = db.KpDatabase.Name; db.KpDatabase.Name = e.NewValue.ToString(); SaveDb save = new SaveDb(Activity, App.Kp2a, new ActionOnFinish((success, message) => { if (!success) { db.KpDatabase.Name = previousName; db.KpDatabase.NameChanged = previousNameChanged; Toast.MakeText(Activity, message, ToastLength.Long).Show(); } else { // Name is reflected in notification, so update it App.Kp2a.UpdateOngoingNotification(); } })); ProgressTask pt = new ProgressTask(App.Kp2a, Activity, save); pt.Run(); }; } }
private void Synchronize() { var filestorage = App.Kp2a.GetFileStorage(App.Kp2a.GetDb().Ioc); RunnableOnFinish task; OnFinish onFinish = new ActionOnFinish(this, (success, message, activity) => { if (!String.IsNullOrEmpty(message)) { Toast.MakeText(activity, message, ToastLength.Long).Show(); } // Tell the adapter to refresh it's list BaseAdapter adapter = (BaseAdapter)((GroupBaseActivity)activity)?.ListAdapter; adapter?.NotifyDataSetChanged(); if (App.Kp2a.GetDb().OtpAuxFileIoc != null) { var task2 = new SyncOtpAuxFile(this, App.Kp2a.GetDb().OtpAuxFileIoc); new ProgressTask(App.Kp2a, activity, task2).Run(true); } }); if (filestorage is CachingFileStorage) { task = new SynchronizeCachedDatabase(this, App.Kp2a, onFinish); } else { task = new CheckDatabaseForChanges(this, App.Kp2a, onFinish); } var progressTask = new ProgressTask(App.Kp2a, this, task); progressTask.Run(); }
public void Start() { string messageSuffix = ShowDatabaseIocInStatus ? "(" + App.GetFileStorage(Db.Ioc).GetDisplayName(Db.Ioc) + ")" : ""; if (CanRecycle) { App.AskYesNoCancel(UiStringKey.AskDeletePermanently_title, QuestionRecycleResourceId, (dlgSender, dlgEvt) => { DeletePermanently = true; ProgressTask pt = new ProgressTask(App, Ctx, this); pt.Run(); }, (dlgSender, dlgEvt) => { DeletePermanently = false; ProgressTask pt = new ProgressTask(App, Ctx, this); pt.Run(); }, (dlgSender, dlgEvt) => { }, Ctx, messageSuffix); } else { App.AskYesNoCancel(UiStringKey.AskDeletePermanently_title, QuestionNoRecycleResourceId, (dlgSender, dlgEvt) => { ProgressTask pt = new ProgressTask(App, Ctx, this); pt.Run(); }, null, (dlgSender, dlgEvt) => { }, Ctx, messageSuffix); } }
public bool OnActionItemClicked(ActionMode mode, IMenuItem item) { var listView = FragmentManager.FindFragmentById <GroupListFragment>(Resource.Id.list_fragment).ListView; var checkedItemPositions = listView.CheckedItemPositions; List <IStructureItem> checkedItems = new List <IStructureItem>(); for (int i = 0; i < checkedItemPositions.Size(); i++) { if (checkedItemPositions.ValueAt(i)) { checkedItems.Add(((PwGroupListAdapter)ListAdapter).GetItemAtPosition(checkedItemPositions.KeyAt(i))); } } //shouldn't happen, just in case... if (!checkedItems.Any()) { return(false); } Handler handler = new Handler(); switch (item.ItemId) { case Resource.Id.menu_delete: DeleteMultipleItems task = new DeleteMultipleItems((GroupBaseActivity)Activity, App.Kp2a.GetDb(), checkedItems, new GroupBaseActivity.RefreshTask(handler, ((GroupBaseActivity)Activity)), App.Kp2a); task.Start(); break; case Resource.Id.menu_move: var navMove = new NavigateToFolderAndLaunchMoveElementTask(checkedItems.First().ParentGroup, checkedItems.Select(i => i.Uuid).ToList(), ((GroupBaseActivity)Activity).IsSearchResult); ((GroupBaseActivity)Activity).StartTask(navMove); break; case Resource.Id.menu_copy: var copyTask = new CopyEntry((GroupBaseActivity)Activity, App.Kp2a, (PwEntry)checkedItems.First(), new GroupBaseActivity.RefreshTask(handler, ((GroupBaseActivity)Activity))); ProgressTask pt = new ProgressTask(App.Kp2a, Activity, copyTask); pt.Run(); break; case Resource.Id.menu_navigate: NavigateToFolder navNavigate = new NavigateToFolder(checkedItems.First().ParentGroup, true); ((GroupBaseActivity)Activity).StartTask(navNavigate); break; case Resource.Id.menu_edit: GroupEditActivity.Launch(Activity, checkedItems.First().ParentGroup, (PwGroup)checkedItems.First()); break; default: return(false); } listView.ClearChoices(); ((BaseAdapter)ListAdapter).NotifyDataSetChanged(); if (_mode != null) { mode.Finish(); } return(true); }
protected override void OnStart() { ProgressTask.SetNewActiveActivity(this); base.OnStart(); Kp2aLog.Log(ClassName + ".OnStart" + " " + ID); }
protected override void OnCreate(Bundle savedInstanceState) { _design.ApplyTheme(); base.OnCreate(savedInstanceState); AddPreferencesFromResource(Resource.Xml.preferences); // Re-use the change handlers for the application settings FindPreference(GetString(Resource.String.keyfile_key)).PreferenceChange += AppSettingsActivity.OnRememberKeyFileHistoryChanged; FindPreference(GetString(Resource.String.ShowUnlockedNotification_key)).PreferenceChange += AppSettingsActivity.OnShowUnlockedNotificationChanged; Util.PrepareNoDonatePreference(this, FindPreference(GetString(Resource.String.NoDonateOption_key))); Preference designPref = FindPreference(GetString(Resource.String.design_key)); if (!_design.HasThemes()) { try { ((PreferenceScreen)FindPreference(GetString(Resource.String.display_prefs_key))).RemovePreference(designPref); } catch (Exception ex) { Kp2aLog.Log(ex.ToString()); throw; } } else { designPref.PreferenceChange += (sender, args) => Recreate(); } Database db = App.Kp2a.GetDb(); Preference rounds = FindPreference(GetString(Resource.String.rounds_key)); rounds.PreferenceChange += (sender, e) => SetRounds(db, e.Preference); rounds.Enabled = db.CanWrite; Preference defaultUser = FindPreference(GetString(Resource.String.default_username_key)); if (!db.DatabaseFormat.HasDefaultUsername) { ((PreferenceScreen) FindPreference(GetString(Resource.String.db_key))).RemovePreference(defaultUser); } else { defaultUser.Enabled = db.CanWrite; ((EditTextPreference)defaultUser).EditText.Text = db.KpDatabase.DefaultUserName; ((EditTextPreference)defaultUser).Text = db.KpDatabase.DefaultUserName; defaultUser.PreferenceChange += (sender, e) => { DateTime previousUsernameChanged = db.KpDatabase.DefaultUserNameChanged; String previousUsername = db.KpDatabase.DefaultUserName; db.KpDatabase.DefaultUserName = e.NewValue.ToString(); SaveDb save = new SaveDb(this, App.Kp2a, new ActionOnFinish((success, message) => { if (!success) { db.KpDatabase.DefaultUserName = previousUsername; db.KpDatabase.DefaultUserNameChanged = previousUsernameChanged; Toast.MakeText(this, message, ToastLength.Long).Show(); } })); ProgressTask pt = new ProgressTask(App.Kp2a, this, save); pt.Run(); }; } Preference databaseName = FindPreference(GetString(Resource.String.database_name_key)); if (!db.DatabaseFormat.HasDatabaseName) { ((PreferenceScreen) FindPreference(GetString(Resource.String.db_key))).RemovePreference(databaseName); } else { databaseName.Enabled = db.CanWrite; ((EditTextPreference) databaseName).EditText.Text = db.KpDatabase.Name; ((EditTextPreference) databaseName).Text = db.KpDatabase.Name; databaseName.PreferenceChange += (sender, e) => { DateTime previousNameChanged = db.KpDatabase.NameChanged; String previousName = db.KpDatabase.Name; db.KpDatabase.Name = e.NewValue.ToString(); SaveDb save = new SaveDb(this, App.Kp2a, new ActionOnFinish((success, message) => { if (!success) { db.KpDatabase.Name = previousName; db.KpDatabase.NameChanged = previousNameChanged; Toast.MakeText(this, message, ToastLength.Long).Show(); } else { // Name is reflected in notification, so update it App.Kp2a.UpdateOngoingNotification(); } })); ProgressTask pt = new ProgressTask(App.Kp2a, this, save); pt.Run(); }; } Preference changeMaster = FindPreference(GetString(Resource.String.master_pwd_key)); if (App.Kp2a.GetDb().CanWrite) { changeMaster.Enabled = true; changeMaster.PreferenceClick += delegate { new SetPasswordDialog(this).Show(); }; } try { //depending on Android version, we offer to use a transparent icon for QuickUnlock or use the notification priority (since API level 16) Preference hideQuickUnlockTranspIconPref = FindPreference(GetString(Resource.String.QuickUnlockIconHidden_key)); Preference hideQuickUnlockIconPref = FindPreference(GetString(Resource.String.QuickUnlockIconHidden16_key)); var quickUnlockScreen = ((PreferenceScreen)FindPreference(GetString(Resource.String.QuickUnlock_prefs_key))); if ((int)Android.OS.Build.VERSION.SdkInt >= 16) { quickUnlockScreen.RemovePreference(hideQuickUnlockTranspIconPref); FindPreference(GetString(Resource.String.ShowUnlockedNotification_key)).PreferenceChange += (sender, args) => App.Kp2a.UpdateOngoingNotification(); hideQuickUnlockIconPref.PreferenceChange += delegate { App.Kp2a.UpdateOngoingNotification(); }; } else { //old version: only show transparent quickUnlock and no option to hide unlocked icon: quickUnlockScreen.RemovePreference(hideQuickUnlockIconPref); FindPreference(GetString(Resource.String.QuickUnlockIconHidden_key)).PreferenceChange += delegate { App.Kp2a.UpdateOngoingNotification(); }; ((PreferenceScreen)FindPreference(GetString(Resource.String.display_prefs_key))).RemovePreference( FindPreference(GetString(Resource.String.ShowUnlockedNotification_key))); } } catch (Exception ex) { Kp2aLog.Log(ex.ToString()); } SetRounds(db, rounds); Preference algorithm = FindPreference(GetString(Resource.String.algorithm_key)); SetAlgorithm(db, algorithm); UpdateImportDbPref(); UpdateImportKeyfilePref(); //AppSettingsActivity.PrepareKeyboardSwitchingPreferences(this); _switchPrefManager = new AppSettingsActivity.KeyboardSwitchPrefManager(this); AppSettingsActivity.PrepareSeparateNotificationsPreference(this); }
private void Synchronize() { var filestorage = App.Kp2a.GetFileStorage(App.Kp2a.GetDb().Ioc); RunnableOnFinish task; OnFinish onFinish = new ActionOnFinish((success, message) => { if (!String.IsNullOrEmpty(message)) Toast.MakeText(this, message, ToastLength.Long).Show(); // Tell the adapter to refresh it's list BaseAdapter adapter = (BaseAdapter)ListAdapter; adapter.NotifyDataSetChanged(); if (App.Kp2a.GetDb().OtpAuxFileIoc != null) { var task2 = new SyncOtpAuxFile(App.Kp2a.GetDb().OtpAuxFileIoc); new ProgressTask(App.Kp2a, this, task2).Run(); } }); if (filestorage is CachingFileStorage) { task = new SynchronizeCachedDatabase(this, App.Kp2a, onFinish); } else { task = new CheckDatabaseForChanges(this, App.Kp2a, onFinish); } var progressTask = new ProgressTask(App.Kp2a, this, task); progressTask.Run(); }
protected override void OnStop() { base.OnStop(); Kp2aLog.Log(ClassName + ".OnStop" + " " + ID); ProgressTask.RemoveActiveActivity(this); }
public void LoadFromRemoteWithDomain() { //warning, looks like credentials are no longer valid var ioc = RemoteDomainIoc; //note: this property is defined in "TestLoadDbCredentials.cs" which is deliberately excluded from Git because the credentials are not public! var app = new TestKp2aApp(); app.ServerCertificateErrorResponse = true; //accept invalid cert app.CreateNewDatabase(); bool loadSuccesful = false; LoadDb task = new LoadDb(app, ioc, null, CreateKey("a"), null, new ActionOnFinish((success, message) => { if (!success) Android.Util.Log.Debug("KP2ATest", "error loading db: " + message); loadSuccesful = success; }) ); ProgressTask pt = new ProgressTask(app, Application.Context, task); Android.Util.Log.Debug("KP2ATest", "Running ProgressTask"); pt.Run(); pt.JoinWorkerThread(); Android.Util.Log.Debug("KP2ATest", "PT.run finished"); Assert.IsTrue(loadSuccesful, "didn't succesfully load database :-("); }
private IKp2aApp PerformLoad(string filenameWithoutDir, string password, string keyfile) { Android.Util.Log.Debug("KP2ATest", "Starting for " + filenameWithoutDir + " with " + password + "/" + keyfile); IKp2aApp app = new TestKp2aApp(); app.CreateNewDatabase(); bool loadSuccesful = false; var key = CreateKey(password, keyfile); string loadErrorMessage = ""; LoadDb task = new LoadDb(app, new IOConnectionInfo {Path = TestDbDirectory + filenameWithoutDir}, null, key, keyfile, new ActionOnFinish((success, message) => { loadErrorMessage = message; if (!success) Android.Util.Log.Debug("KP2ATest", "error loading db: " + message); loadSuccesful = success; }) ); ProgressTask pt = new ProgressTask(app, Application.Context, task); Android.Util.Log.Debug("KP2ATest", "Running ProgressTask"); pt.Run(); pt.JoinWorkerThread(); Android.Util.Log.Debug("KP2ATest", "PT.run finished"); Assert.IsTrue(loadSuccesful, "didn't succesfully load database :-( " + loadErrorMessage); return app; }
protected override void OnCreate(Bundle savedInstanceState) { ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this); long usageCount = prefs.GetLong(GetString(Resource.String.UsageCount_key), 0); ISharedPreferencesEditor edit = prefs.Edit(); edit.PutLong(GetString(Resource.String.UsageCount_key), usageCount + 1); edit.Commit(); _showPassword = !prefs.GetBoolean(GetString(Resource.String.maskpass_key), Resources.GetBoolean(Resource.Boolean.maskpass_default)); RequestWindowFeature(WindowFeatures.IndeterminateProgress); _activityDesign.ApplyTheme(); base.OnCreate(savedInstanceState); SetEntryView(); Database db = App.Kp2a.GetDb(); // Likely the app has been killed exit the activity if (!db.Loaded || (App.Kp2a.QuickLocked)) { Finish(); return; } SetResult(KeePass.ExitNormal); Intent i = Intent; PwUuid uuid = new PwUuid(MemUtil.HexStringToByteArray(i.GetStringExtra(KeyEntry))); _pos = i.GetIntExtra(KeyRefreshPos, -1); _appTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent); Entry = db.Entries[uuid]; // Refresh Menu contents in case onCreateMenuOptions was called before Entry was set ActivityCompat.InvalidateOptionsMenu(this); // Update last access time. Entry.Touch(false); if (PwDefs.IsTanEntry(Entry) && prefs.GetBoolean(GetString(Resource.String.TanExpiresOnUse_key), Resources.GetBoolean(Resource.Boolean.TanExpiresOnUse_default)) && ((Entry.Expires == false) || Entry.ExpiryTime > DateTime.Now)) { PwEntry backupEntry = Entry.CloneDeep(); Entry.ExpiryTime = DateTime.Now; Entry.Expires = true; Entry.Touch(true); RequiresRefresh(); UpdateEntry update = new UpdateEntry(this, App.Kp2a, backupEntry, Entry, null); ProgressTask pt = new ProgressTask(App.Kp2a, this, update); pt.Run(); } FillData(); SetupEditButtons(); App.Kp2a.GetDb().LastOpenedEntry = new PwEntryOutput(Entry, App.Kp2a.GetDb().KpDatabase); _pluginActionReceiver = new PluginActionReceiver(this); RegisterReceiver(_pluginActionReceiver, new IntentFilter(Strings.ActionAddEntryAction)); _pluginFieldReceiver = new PluginFieldReceiver(this); RegisterReceiver(_pluginFieldReceiver, new IntentFilter(Strings.ActionSetEntryField)); new Thread(NotifyPluginsOnOpen).Start(); //the rest of the things to do depends on the current app task: _appTask.CompleteOnCreateEntryActivity(this); }
void SaveEntry() { Database db = App.Kp2a.GetDb(); EntryEditActivity act = this; if (!ValidateBeforeSaving()) { return; } PwEntry initialEntry = State.EntryInDatabase.CloneDeep(); PwEntry newEntry = State.EntryInDatabase; //Clone history and re-assign: newEntry.History = newEntry.History.CloneDeep(); //Based on KeePass Desktop bool bCreateBackup = (!State.IsNew); if (bCreateBackup) { newEntry.CreateBackup(null); } if (State.SelectedIcon) { newEntry.IconId = State.SelectedIconId; newEntry.CustomIconUuid = State.SelectedCustomIconId; } //else the State.EntryInDatabase.Icon /* KPDesktop * if(m_cbCustomForegroundColor.Checked) * newEntry.ForegroundColor = m_clrForeground; * else newEntry.ForegroundColor = Color.Empty; * if(m_cbCustomBackgroundColor.Checked) * newEntry.BackgroundColor = m_clrBackground; * else newEntry.BackgroundColor = Color.Empty; * */ UpdateEntryFromUi(newEntry); newEntry.Binaries = State.Entry.Binaries; newEntry.Expires = State.Entry.Expires; if (newEntry.Expires) { newEntry.ExpiryTime = State.Entry.ExpiryTime; } newEntry.Touch(true, false); // Touch *after* backup StrUtil.NormalizeNewLines(newEntry.Strings, true); bool bUndoBackup = false; PwCompareOptions cmpOpt = (PwCompareOptions.NullEmptyEquivStd | PwCompareOptions.IgnoreTimes); if (bCreateBackup) { cmpOpt |= PwCompareOptions.IgnoreLastBackup; } if (newEntry.EqualsEntry(initialEntry, cmpOpt, MemProtCmpMode.CustomOnly)) { // No modifications at all => restore last mod time and undo backup newEntry.LastModificationTime = initialEntry.LastModificationTime; bUndoBackup = bCreateBackup; } else if (bCreateBackup) { // If only history items have been modified (deleted) => undo // backup, but without restoring the last mod time PwCompareOptions cmpOptNh = (cmpOpt | PwCompareOptions.IgnoreHistory); if (newEntry.EqualsEntry(initialEntry, cmpOptNh, MemProtCmpMode.CustomOnly)) { bUndoBackup = true; } } if (bUndoBackup) { newEntry.History.RemoveAt(newEntry.History.UCount - 1); } newEntry.MaintainBackups(db.KpDatabase); //if ( newEntry.Strings.ReadSafe (PwDefs.TitleField).Equals(State.Entry.Strings.ReadSafe (PwDefs.TitleField)) ) { // SetResult(KeePass.EXIT_REFRESH); //} else { //it's safer to always update the title as we might add further information in the title like expiry etc. SetResult(KeePass.ExitRefreshTitle); //} RunnableOnFinish runnable; ActionOnFinish closeOrShowError = new ActionOnFinish((success, message) => { if (success) { Finish(); } else { OnFinish.DisplayMessage(this, message); } }); ActionOnFinish afterAddEntry = new ActionOnFinish((success, message) => { if (success) { _appTask.AfterAddNewEntry(this, newEntry); } }, closeOrShowError); if (State.IsNew) { runnable = AddEntry.GetInstance(this, App.Kp2a, newEntry, State.ParentGroup, afterAddEntry); } else { runnable = new UpdateEntry(this, App.Kp2a, initialEntry, newEntry, closeOrShowError); } ProgressTask pt = new ProgressTask(App.Kp2a, act, runnable); pt.Run(); }
public AfterTask(Activity activity, OnFinish finish, Handler handler, ProgressTask pt) : base(activity, finish, handler) { _progressTask = pt; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.set_password); SetTitle(Resource.String.password_title); // Ok button Button okButton = (Button) FindViewById(Resource.Id.ok); okButton.Click += (sender, e) => { TextView passView = (TextView) FindViewById(Resource.Id.pass_password); String pass = passView.Text; TextView passConfView = (TextView) FindViewById(Resource.Id.pass_conf_password); String confpass = passConfView.Text; // Verify that passwords match if ( ! pass.Equals(confpass) ) { // Passwords do not match Toast.MakeText(Context, Resource.String.error_pass_match, ToastLength.Long).Show(); return; } TextView keyfileView = (TextView) FindViewById(Resource.Id.pass_keyfile); String keyfile = keyfileView.Text; Keyfile = keyfile; // Verify that a password or keyfile is set if ( pass.Length == 0 && keyfile.Length == 0 ) { Toast.MakeText(Context, Resource.String.error_nopass, ToastLength.Long).Show(); return; } SetPassword sp = new SetPassword(Context, App.Kp2a, pass, keyfile, new AfterSave(this, _finish, new Handler())); ProgressTask pt = new ProgressTask(App.Kp2a, Context, sp); pt.Run(); }; // Cancel button Button cancelButton = (Button) FindViewById(Resource.Id.cancel); cancelButton.Click += (sender,e) => { Cancel(); if ( _finish != null ) { _finish.Run(); } }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); if (IsFinishing) { return; } SetResult(KeePass.ExitNormal); Log.Warn(Tag, "Creating group view"); Intent intent = Intent; PwUuid id = RetrieveGroupId(intent); Database db = App.Kp2a.CurrentDb; if (db != null) { Group = id == null ? db.Root : db.GroupsById[id]; } Log.Warn(Tag, "Retrieved group"); if (Group == null) { Log.Warn(Tag, "Group was null"); return; } if (AddGroupEnabled) { // Add Group button View addGroup = FindViewById(Resource.Id.fabAddNewGroup); addGroup.Click += (sender, e) => { GroupEditActivity.Launch(this, Group); }; } if (AddEntryEnabled) { View addEntry = FindViewById(Resource.Id.fabAddNewEntry); addEntry.Click += (sender, e) => { if (App.Kp2a.CurrentDb.DatabaseFormat.SupportsTemplates && !AddTemplateEntries.ContainsAllTemplates(App.Kp2a.CurrentDb) && PreferenceManager.GetDefaultSharedPreferences(this).GetBoolean(Askaddtemplates, true)) { App.Kp2a.AskYesNoCancel(UiStringKey.AskAddTemplatesTitle, UiStringKey.AskAddTemplatesMessage, UiStringKey.yes, UiStringKey.no, (o, args) => { //yes ProgressTask pt = new ProgressTask(App.Kp2a, this, new AddTemplateEntries(this, App.Kp2a, new ActionOnFinish(this, (success, message, activity) => ((GroupActivity)activity)?.StartAddEntry()))); pt.Run(); }, (o, args) => { var edit = PreferenceManager.GetDefaultSharedPreferences(this).Edit(); edit.PutBoolean(Askaddtemplates, false); edit.Commit(); //no StartAddEntry(); }, null, this); } else { StartAddEntry(); } }; } SetGroupTitle(); SetGroupIcon(); FragmentManager.FindFragmentById <GroupListFragment>(Resource.Id.list_fragment).ListAdapter = new PwGroupListAdapter(this, Group); Log.Warn(Tag, "Finished creating group"); }
protected override void OnCreate(Bundle savedInstanceState) { ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this); long usageCount = prefs.GetLong(GetString(Resource.String.UsageCount_key), 0); ISharedPreferencesEditor edit = prefs.Edit(); edit.PutLong(GetString(Resource.String.UsageCount_key), usageCount + 1); edit.Commit(); _showPassword = !prefs.GetBoolean(GetString(Resource.String.maskpass_key), Resources.GetBoolean(Resource.Boolean.maskpass_default)); base.OnCreate(savedInstanceState); RequestWindowFeature(WindowFeatures.IndeterminateProgress); new ActivityDesign(this).ApplyTheme(); SetEntryView(); Database db = App.Kp2a.GetDb(); // Likely the app has been killed exit the activity if (!db.Loaded || (App.Kp2a.QuickLocked)) { Finish(); return; } SetResult(KeePass.ExitNormal); Intent i = Intent; PwUuid uuid = new PwUuid(MemUtil.HexStringToByteArray(i.GetStringExtra(KeyEntry))); _pos = i.GetIntExtra(KeyRefreshPos, -1); _appTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent); Entry = db.Entries[uuid]; Android.Util.Log.Debug("KP2A", "Notes: " + Entry.Strings.ReadSafe(PwDefs.NotesField)); // Refresh Menu contents in case onCreateMenuOptions was called before Entry was set ActivityCompat.InvalidateOptionsMenu(this); // Update last access time. Entry.Touch(false); if (PwDefs.IsTanEntry(Entry) && prefs.GetBoolean(GetString(Resource.String.TanExpiresOnUse_key), Resources.GetBoolean(Resource.Boolean.TanExpiresOnUse_default)) && ((Entry.Expires == false) || Entry.ExpiryTime > DateTime.Now)) { PwEntry backupEntry = Entry.CloneDeep(); Entry.ExpiryTime = DateTime.Now; Entry.Expires = true; Entry.Touch(true); RequiresRefresh(); UpdateEntry update = new UpdateEntry(this, App.Kp2a, backupEntry, Entry, null); ProgressTask pt = new ProgressTask(App.Kp2a, this, update); pt.Run(); } FillData(); SetupEditButtons(); SetupMoveButtons (); App.Kp2a.GetDb().LastOpenedEntry = new PwEntryOutput(Entry, App.Kp2a.GetDb().KpDatabase); _pluginActionReceiver = new PluginActionReceiver(this); RegisterReceiver(_pluginActionReceiver, new IntentFilter(Strings.ActionAddEntryAction)); _pluginFieldReceiver = new PluginFieldReceiver(this); RegisterReceiver(_pluginFieldReceiver, new IntentFilter(Strings.ActionSetEntryField)); new Thread(NotifyPluginsOnOpen).Start(); //the rest of the things to do depends on the current app task: _appTask.CompleteOnCreateEntryActivity(this); }
protected TestKp2aApp LoadDatabase(string filename, string password, string keyfile) { var app = CreateTestKp2aApp(); app.CreateNewDatabase(); bool loadSuccesful = false; LoadDb task = new LoadDb(app, new IOConnectionInfo() { Path = filename }, null, CreateKey(password, keyfile), keyfile, new ActionOnFinish((success, message) => { if (!success) Kp2aLog.Log(message); loadSuccesful = success; }) ); ProgressTask pt = new ProgressTask(app, Application.Context, task); pt.Run(); pt.JoinWorkerThread(); Assert.IsTrue(loadSuccesful); return app; }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (AppTask.TryGetFromActivityResult(data, ref AppTask)) { //make sure the app task is passed to the calling activity AppTask.SetActivityResult(this, KeePass.ExitNormal); } if (resultCode == Result.Ok) { String groupName = data.Extras.GetString(GroupEditActivity.KeyName); int groupIconId = data.Extras.GetInt(GroupEditActivity.KeyIconId); PwUuid groupCustomIconId = new PwUuid(MemUtil.HexStringToByteArray(data.Extras.GetString(GroupEditActivity.KeyCustomIconId))); String strGroupUuid = data.Extras.GetString(GroupEditActivity.KeyGroupUuid); GroupBaseActivity act = this; Handler handler = new Handler(); RunnableOnFinish task; if (strGroupUuid == null) { task = AddGroup.GetInstance(this, App.Kp2a, groupName, groupIconId, Group, new RefreshTask(handler, this), false); } else { PwUuid groupUuid = new PwUuid(MemUtil.HexStringToByteArray(strGroupUuid)); task = new EditGroup(this, App.Kp2a, groupName, (PwIcon) groupIconId, groupCustomIconId, App.Kp2a.GetDb().Groups[groupUuid], new RefreshTask(handler, this)); } ProgressTask pt = new ProgressTask(App.Kp2a, act, task); pt.Run(); } if (resultCode == KeePass.ExitCloseAfterTaskComplete) { AppTask.SetActivityResult(this, KeePass.ExitCloseAfterTaskComplete); Finish(); } if (resultCode == KeePass.ExitReloadDb) { AppTask.SetActivityResult(this, KeePass.ExitReloadDb); Finish(); } }
public void LoadFromRemote1And1WrongCredentials() { var ioc = RemoteIoc1and1WrongCredentials; //note: this property is defined in "TestLoadDbCredentials.cs" which is deliberately excluded from Git because the credentials are not public! IKp2aApp app = new TestKp2aApp(); app.CreateNewDatabase(); bool loadSuccesful = false; bool gotError = false; LoadDb task = new LoadDb(app, ioc, null, CreateKey("test"), null, new ActionOnFinish((success, message) => { if (!success) { Android.Util.Log.Debug("KP2ATest", "error loading db: " + message); gotError = true; } loadSuccesful = success; }) ); ProgressTask pt = new ProgressTask(app, Application.Context, task); Android.Util.Log.Debug("KP2ATest", "Running ProgressTask"); pt.Run(); pt.JoinWorkerThread(); Android.Util.Log.Debug("KP2ATest", "PT.run finished"); Assert.IsFalse(loadSuccesful); Assert.IsTrue(gotError); }
private void InsertElement() { MoveElementTask moveElementTask = (MoveElementTask)AppTask; IStructureItem elementToMove = App.Kp2a.GetDb().KpDatabase.RootGroup.FindObject(moveElementTask.Uuid, true, null); var moveElement = new MoveElement(elementToMove, Group, this, App.Kp2a, new ActionOnFinish((success, message) => { StopMovingElement(); if (!String.IsNullOrEmpty(message)) Toast.MakeText(this, message, ToastLength.Long).Show();})); var progressTask = new ProgressTask(App.Kp2a, this, moveElement); progressTask.Run(); }
public void LoadWithAcceptedCertificateTrustFailure() { var ioc = RemoteCertFailureIoc; //note: this property is defined in "TestLoadDbCredentials.cs" which is deliberately excluded from Git because the credentials are not public! var app = new TestKp2aApp(); app.ServerCertificateErrorResponse = true; app.CreateNewDatabase(); bool loadSuccesful = false; LoadDb task = new LoadDb(app, ioc, null, CreateKey("test"), null, new ActionOnFinish((success, message) => { if (!success) Android.Util.Log.Debug("KP2ATest", "error loading db: " + message); loadSuccesful = success; }) ); ProgressTask pt = new ProgressTask(app, Application.Context, task); Android.Util.Log.Debug("KP2ATest", "Running ProgressTask"); pt.Run(); pt.JoinWorkerThread(); Android.Util.Log.Debug("KP2ATest", "PT.run finished"); Assert.IsTrue(loadSuccesful, "database should be loaded because invalid certificates are accepted"); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); if (IsFinishing) { return; } SetResult(KeePass.ExitNormal); Log.Warn(Tag, "Creating group view"); Intent intent = Intent; PwUuid id = RetrieveGroupId(intent); Database db = App.Kp2a.CurrentDb; if (id == null) { Group = db.Root; } else { Group = db.GroupsById[id]; } Log.Warn(Tag, "Retrieved group"); if (Group == null) { Log.Warn(Tag, "Group was null"); return; } if (AddGroupEnabled) { // Add Group button View addGroup = FindViewById(Resource.Id.fabAddNewGroup); addGroup.Click += (sender, e) => { GroupEditActivity.Launch(this, Group); }; } if (AddEntryEnabled) { View addEntry = FindViewById(Resource.Id.fabAddNewEntry); addEntry.Click += (sender, e) => { if (App.Kp2a.CurrentDb.DatabaseFormat.SupportsTemplates && !AddTemplateEntries.ContainsAllTemplates(App.Kp2a.CurrentDb) && PreferenceManager.GetDefaultSharedPreferences(this).GetBoolean(Askaddtemplates, true)) { App.Kp2a.AskYesNoCancel(UiStringKey.AskAddTemplatesTitle, UiStringKey.AskAddTemplatesMessage, UiStringKey.yes, UiStringKey.no, (o, args) => { //yes ProgressTask pt = new ProgressTask(App.Kp2a, this, new AddTemplateEntries(this, App.Kp2a, new ActionOnFinish(this, (success, message, activity) => ((GroupActivity)activity)?.StartAddEntry()))); pt.Run(); }, (o, args) => { var edit = PreferenceManager.GetDefaultSharedPreferences(this).Edit(); edit.PutBoolean(Askaddtemplates, false); edit.Commit(); //no StartAddEntry(); }, null, this); } else { StartAddEntry(); } }; } SetGroupTitle(); SetGroupIcon(); FragmentManager.FindFragmentById <GroupListFragment>(Resource.Id.list_fragment).ListAdapter = new PwGroupListAdapter(this, Group); Log.Warn(Tag, "Finished creating group"); var ioc = App.Kp2a.CurrentDb.Ioc; OptionalOut <UiStringKey> reason = new OptionalOut <UiStringKey>(); if (App.Kp2a.GetFileStorage(ioc).IsReadOnly(ioc, reason)) { bool hasShownReadOnlyReason = PreferenceManager.GetDefaultSharedPreferences(this) .GetBoolean(App.Kp2a.CurrentDb.IocAsHexString() + "_readonlyreason", false); if (!hasShownReadOnlyReason) { var b = new AlertDialog.Builder(this); b.SetTitle(Resource.String.FileReadOnlyTitle); b.SetMessage(GetString(Resource.String.FileReadOnlyMessagePre) + " " + App.Kp2a.GetResourceString(reason.Result)); b.SetPositiveButton(Android.Resource.String.Ok, (sender, args) => { PreferenceManager.GetDefaultSharedPreferences(this). Edit().PutBoolean(App.Kp2a.CurrentDb.IocAsHexString() + "_readonlyreason", true).Commit(); }); b.Show(); } } }
public void LoadAndSaveFromRemote1And1Ftp() { var ioc = RemoteIoc1and1Ftp; //note: this property is defined in "TestLoadDbCredentials.cs" which is deliberately excluded from Git because the credentials are not public! var app = new TestKp2aApp(); app.CreateNewDatabase(); bool loadSuccesful = false; LoadDb task = new LoadDb(app, ioc, null, CreateKey("test"), null, new ActionOnFinish((success, message) => { if (!success) Android.Util.Log.Debug("KP2ATest", "error loading db: " + message); loadSuccesful = success; }) ); ProgressTask pt = new ProgressTask(app, Application.Context, task); Android.Util.Log.Debug("KP2ATest", "Running ProgressTask"); pt.Run(); pt.JoinWorkerThread(); Android.Util.Log.Debug("KP2ATest", "PT.run finished"); Assert.IsTrue(loadSuccesful, "didn't succesfully load database :-("); Assert.IsTrue(TrySaveDatabase(app), "didn't successfully save database."); }
private void CreateDatabase() { var keyfileCheckbox = FindViewById<CheckBox>(Resource.Id.use_keyfile); string password; if (!TryGetPassword(out password)) return; // Verify that a password or keyfile is set if (password.Length == 0 && !keyfileCheckbox.Checked) { Toast.MakeText(this, Resource.String.error_nopass, ToastLength.Long).Show(); return; } //create the key CompositeKey newKey = new CompositeKey(); if (String.IsNullOrEmpty(password) == false) { newKey.AddUserKey(new KcpPassword(password)); } if (String.IsNullOrEmpty(_keyfileFilename) == false) { try { newKey.AddUserKey(new KcpKeyFile(_keyfileFilename)); } catch (Exception) { Toast.MakeText(this, Resource.String.error_adding_keyfile, ToastLength.Long).Show(); return; } } // Create the new database CreateDb create = new CreateDb(App.Kp2a, this, _ioc, new LaunchGroupActivity(_ioc, this), false, newKey); ProgressTask createTask = new ProgressTask( App.Kp2a, this, create); createTask.Run(); }
private void ExportTo(IOConnectionInfo ioc) { var exportDb = new ExportDb(App.Kp2a, new ActionOnFinish(delegate(bool success, string message) { if (!success) Toast.MakeText(this, message, ToastLength.Long).Show(); else Toast.MakeText(this, GetString(Resource.String.export_database_successful), ToastLength.Long).Show(); Finish(); } ), _ffp[_fileFormatIndex], ioc); ProgressTask pt = new ProgressTask(App.Kp2a, this, exportDb); pt.Run(); }
void SaveEntry() { Database db = App.Kp2a.GetDb(); EntryEditActivity act = this; if (!ValidateBeforeSaving()) return; PwEntry initialEntry = State.EntryInDatabase.CloneDeep(); PwEntry newEntry = State.EntryInDatabase; //Clone history and re-assign: newEntry.History = newEntry.History.CloneDeep(); //Based on KeePass Desktop bool bCreateBackup = (!State.IsNew); if(bCreateBackup) newEntry.CreateBackup(null); if (State.SelectedIcon == false) { if (State.IsNew) { newEntry.IconId = PwIcon.Key; } else { // Keep previous icon, if no new one was selected } } else { newEntry.IconId = State.SelectedIconId; newEntry.CustomIconUuid = State.SelectedCustomIconId; } /* KPDesktop if(m_cbCustomForegroundColor.Checked) newEntry.ForegroundColor = m_clrForeground; else newEntry.ForegroundColor = Color.Empty; if(m_cbCustomBackgroundColor.Checked) newEntry.BackgroundColor = m_clrBackground; else newEntry.BackgroundColor = Color.Empty; */ UpdateEntryFromUi(newEntry); newEntry.Binaries = State.Entry.Binaries; newEntry.Expires = State.Entry.Expires; if (newEntry.Expires) { newEntry.ExpiryTime = State.Entry.ExpiryTime; } newEntry.Touch(true, false); // Touch *after* backup StrUtil.NormalizeNewLines(newEntry.Strings, true); bool bUndoBackup = false; PwCompareOptions cmpOpt = (PwCompareOptions.NullEmptyEquivStd | PwCompareOptions.IgnoreTimes); if(bCreateBackup) cmpOpt |= PwCompareOptions.IgnoreLastBackup; if(newEntry.EqualsEntry(initialEntry, cmpOpt, MemProtCmpMode.CustomOnly)) { // No modifications at all => restore last mod time and undo backup newEntry.LastModificationTime = initialEntry.LastModificationTime; bUndoBackup = bCreateBackup; } else if(bCreateBackup) { // If only history items have been modified (deleted) => undo // backup, but without restoring the last mod time PwCompareOptions cmpOptNh = (cmpOpt | PwCompareOptions.IgnoreHistory); if(newEntry.EqualsEntry(initialEntry, cmpOptNh, MemProtCmpMode.CustomOnly)) bUndoBackup = true; } if(bUndoBackup) newEntry.History.RemoveAt(newEntry.History.UCount - 1); newEntry.MaintainBackups(db.KpDatabase); //if ( newEntry.Strings.ReadSafe (PwDefs.TitleField).Equals(State.Entry.Strings.ReadSafe (PwDefs.TitleField)) ) { // SetResult(KeePass.EXIT_REFRESH); //} else { //it's safer to always update the title as we might add further information in the title like expiry etc. SetResult(KeePass.ExitRefreshTitle); //} RunnableOnFinish runnable; ActionOnFinish closeOrShowError = new ActionOnFinish((success, message) => { if (success) { Finish(); } else { OnFinish.DisplayMessage(this, message); } }); ActionOnFinish afterAddEntry = new ActionOnFinish((success, message) => { if (success) _appTask.AfterAddNewEntry(this, newEntry); },closeOrShowError); if ( State.IsNew ) { runnable = AddEntry.GetInstance(this, App.Kp2a, newEntry, State.ParentGroup, afterAddEntry); } else { runnable = new UpdateEntry(this, App.Kp2a, initialEntry, newEntry, closeOrShowError); } ProgressTask pt = new ProgressTask(App.Kp2a, act, runnable); pt.Run(); }