public void CreateAndSaveLocal() { IKp2aApp app = new TestKp2aApp(); IOConnectionInfo ioc = new IOConnectionInfo {Path = DefaultFilename}; File outputDir = new File(DefaultDirectory); outputDir.Mkdirs(); File targetFile = new File(ioc.Path); if (targetFile.Exists()) targetFile.Delete(); bool createSuccesful = false; //create the task: CreateDb createDb = new CreateDb(app, Application.Context, ioc, new ActionOnFinish((success, message) => { createSuccesful = success; if (!success) Android.Util.Log.Debug("KP2A_Test", message); }), false); //run it: createDb.Run(); //check expectations: Assert.IsTrue(createSuccesful); Assert.IsNotNull(app.GetDb()); Assert.IsNotNull(app.GetDb().KpDatabase); //the create task should create two groups: Assert.AreEqual(2, app.GetDb().KpDatabase.RootGroup.Groups.Count()); //ensure the the database can be loaded from file: PwDatabase loadedDb = new PwDatabase(); loadedDb.Open(ioc, new CompositeKey(), null, new KdbxDatabaseFormat(KdbxFormat.Default)); //Check whether the databases are equal AssertDatabasesAreEqual(loadedDb, app.GetDb().KpDatabase); }
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(); }
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(); }