コード例 #1
0
ファイル: UpdateEntry.cs プロジェクト: pythe/wristpass
 public override void Run()
 {
     // Commit to disk
     SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun);
     save.SetStatusLogger(StatusLogger);
     save.Run();
 }
コード例 #2
0
        public override void Run()
        {
            StatusLogger.UpdateMessage(UiStringKey.SettingPassword);
            PwDatabase   pm     = _app.GetDb().KpDatabase;
            CompositeKey newKey = new CompositeKey();

            if (String.IsNullOrEmpty(_password) == false)
            {
                newKey.AddUserKey(new KcpPassword(_password));
            }
            if (String.IsNullOrEmpty(_keyfile) == false)
            {
                try {
                    newKey.AddUserKey(new KcpKeyFile(_keyfile));
                } catch (Exception) {
                    //TODO MessageService.ShowWarning (strKeyFile, KPRes.KeyFileError, exKF);
                    return;
                }
            }

            DateTime     previousMasterKeyChanged = pm.MasterKeyChanged;
            CompositeKey previousKey = pm.MasterKey;

            pm.MasterKeyChanged = DateTime.Now;
            pm.MasterKey        = newKey;

            // Save Database
            _onFinishToRun = new AfterSave(previousKey, previousMasterKeyChanged, pm, OnFinishToRun);
            SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun, _dontSave);

            save.SetStatusLogger(StatusLogger);
            save.Run();
        }
コード例 #3
0
        public override void Run()
        {
            // Commit to disk
            SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun);

            save.SetStatusLogger(StatusLogger);
            save.Run();
        }
コード例 #4
0
ファイル: EditGroup.cs プロジェクト: pythe/wristpass
        public override void Run()
        {
            // modify group:
            Group.Name = _name;
            Group.IconId = _iconId;
            Group.CustomIconUuid = _customIconId;
            Group.Touch(true);

            // Commit to disk
            SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun);
            save.SetStatusLogger(StatusLogger);
            save.Run();
        }
コード例 #5
0
ファイル: EditGroup.cs プロジェクト: zofuthan/keepass2android
        public override void Run()
        {
            // modify group:
            Group.Name           = _name;
            Group.IconId         = _iconId;
            Group.CustomIconUuid = _customIconId;
            Group.Touch(true);

            // Commit to disk
            SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun);

            save.SetStatusLogger(StatusLogger);
            save.Run();
        }
コード例 #6
0
ファイル: TestBase.cs プロジェクト: pythe/wristpass
 public static bool TrySaveDatabase(IKp2aApp app)
 {
     bool saveSuccesful = false;
     SaveDb save = new SaveDb(Application.Context, app, new ActionOnFinish((success, message) =>
         {
             saveSuccesful = success;
             if (!success)
             {
                 Kp2aLog.Log("Error during TestBase.SaveDatabase: " + message);
             }
         }), false);
     save.Run();
     save.JoinWorkerThread();
     return saveSuccesful;
 }
コード例 #7
0
        public override void Run()
        {
            StatusLogger.UpdateMessage(UiStringKey.AddingGroup);
            // Generate new group
            Group = new PwGroup(true, true, _name, (PwIcon)_iconId);
            if (_groupCustomIconId != null)
            {
                Group.CustomIconUuid = _groupCustomIconId;
            }
            Parent.AddGroup(Group, true);

            // Commit to disk
            SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun, DontSave);

            save.SetStatusLogger(StatusLogger);
            save.Run();
        }
コード例 #8
0
        public override void Run()
        {
            StatusLogger.UpdateMessage(UiStringKey.AddingEntry);

            List <PwEntry> addedEntries;
            var            templateGroup = AddTemplates(out addedEntries);

            if (addedEntries.Any())
            {
                _app.DirtyGroups.Add(templateGroup);

                // Commit to disk
                SaveDb save = new SaveDb(_ctx, _app, _app.CurrentDb, OnFinishToRun);
                save.SetStatusLogger(StatusLogger);
                save.Run();
            }
        }
コード例 #9
0
ファイル: AddEntry.cs プロジェクト: pythe/wristpass
        public override void Run()
        {
            StatusLogger.UpdateMessage(UiStringKey.AddingEntry);

            //make sure we're not adding the entry if it was added before.
            //(this might occur in very rare cases where the user dismissis the save dialog
            //by rotating the screen while saving and then presses save again)
            if (_parentGroup.FindEntry(_entry.Uuid, false) == null)
            {
                _parentGroup.AddEntry(_entry, true);
            }

            // Commit to disk
            SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun);
            save.SetStatusLogger(StatusLogger);
            save.Run();
        }
コード例 #10
0
ファイル: CreateDB.cs プロジェクト: 77rusa/README
        public override void Run()
        {
            StatusLogger.UpdateMessage(UiStringKey.progress_create);
            Database db = _app.CreateNewDatabase(_makeCurrent);

            db.KpDatabase = new KeePassLib.PwDatabase();

            if (_key == null)
            {
                _key = new CompositeKey();                 //use a temporary key which should be changed after creation
            }

            db.KpDatabase.New(_ioc, _key, _app.GetFileStorage(_ioc).GetFilenameWithoutPathAndExt(_ioc));

            db.KpDatabase.KdfParameters = (new AesKdf()).GetDefaultParameters();
            db.KpDatabase.Name          = "Keepass2Android Password Database";
            //re-set the name of the root group because the PwDatabase uses UrlUtil which is not appropriate for all file storages:
            db.KpDatabase.RootGroup.Name = _app.GetFileStorage(_ioc).GetFilenameWithoutPathAndExt(_ioc);

            // Set Database state
            db.Root         = db.KpDatabase.RootGroup;
            db.SearchHelper = new SearchDbHelper(_app);

            // Add a couple default groups
            AddGroup internet = AddGroup.GetInstance(_ctx, _app, "Internet", 1, null, db.KpDatabase.RootGroup, null, true);

            internet.Run();
            AddGroup email = AddGroup.GetInstance(_ctx, _app, "eMail", 19, null, db.KpDatabase.RootGroup, null, true);

            email.Run();

            List <PwEntry>     addedEntries;
            AddTemplateEntries addTemplates = new AddTemplateEntries(_ctx, _app, null);

            addTemplates.AddTemplates(out addedEntries);

            // Commit changes
            SaveDb save = new SaveDb(_ctx, _app, db, OnFinishToRun, _dontSave);

            save.SetStatusLogger(StatusLogger);
            _onFinishToRun = null;
            save.Run();

            db.UpdateGlobals();
        }
コード例 #11
0
        public override void Run()
        {
            StatusLogger.UpdateMessage(UiStringKey.AddingEntry);

            //make sure we're not adding the entry if it was added before.
            //(this might occur in very rare cases where the user dismissis the save dialog
            //by rotating the screen while saving and then presses save again)
            if (_parentGroup.FindEntry(_entry.Uuid, false) == null)
            {
                _parentGroup.AddEntry(_entry, true);
            }


            // Commit to disk
            SaveDb save = new SaveDb(_ctx, _app, _app.CurrentDb, OnFinishToRun);

            save.SetStatusLogger(StatusLogger);
            save.Run();
        }
コード例 #12
0
ファイル: DeleteRunnable.cs プロジェクト: 77rusa/README
        public override void Run()
        {
            StatusLogger.UpdateMessage(StatusMessage);

            List <PwGroup> touchedGroups            = new List <PwGroup>();
            List <PwGroup> permanentlyDeletedGroups = new List <PwGroup>();

            Android.Util.Log.Debug("KP2A", "Calling PerformDelete..");
            PerformDelete(touchedGroups, permanentlyDeletedGroups);

            _onFinishToRun = new ActionOnFinish(ActiveActivity, (success, message, activity) =>
            {
                if (success)
                {
                    foreach (var g in touchedGroups)
                    {
                        App.DirtyGroups.Add(g);
                    }
                    foreach (var g in permanentlyDeletedGroups)
                    {
                        //remove groups from global lists if present there
                        App.DirtyGroups.Remove(g);
                        Db.GroupsById.Remove(g.Uuid);
                        Db.Elements.Remove(g);
                    }
                }
                else
                {
                    // Let's not bother recovering from a failure to save.  It is too much work.
                    App.Lock(false);
                }
            }, OnFinishToRun);

            // Commit database
            SaveDb save = new SaveDb(Ctx, App, Db, OnFinishToRun, false);

            save.ShowDatabaseIocInStatus = ShowDatabaseIocInStatus;

            save.SetStatusLogger(StatusLogger);
            save.Run();
        }
コード例 #13
0
ファイル: DeleteEntry.cs プロジェクト: pythe/wristpass
        public override void Run()
        {
            StatusLogger.UpdateMessage(UiStringKey.DeletingEntry);
            PwDatabase pd = Db.KpDatabase;

            PwGroup pgRecycleBin = pd.RootGroup.FindGroup(pd.RecycleBinUuid, true);

            bool bUpdateGroupList = false;
            DateTime dtNow = DateTime.Now;
            PwEntry pe = _entry;
            PwGroup pgParent = pe.ParentGroup;
            if(pgParent != null)
            {
                pgParent.Entries.Remove(pe);
                //TODO check if RecycleBin is deleted
                //TODO no recycle bin in KDB

                if ((DeletePermanently) || (!CanRecycle))
                {
                    PwDeletedObject pdo = new PwDeletedObject(pe.Uuid, dtNow);
                    pd.DeletedObjects.Add(pdo);

                    _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.
                                App.LockDatabase(false);
                            }
                        }, OnFinishToRun);
                }
                else // Recycle
                {
                    EnsureRecycleBinExists(ref pgRecycleBin, ref bUpdateGroupList);

                    pgRecycleBin.AddEntry(pe, true, true);
                    pe.Touch(false);

                    _onFinishToRun = new ActionOnFinish( (success, message) =>
                                                 {
                        if ( success ) {
                            // Mark previous parent dirty
                            Db.Dirty.Add(pgParent);
                            // Mark new parent dirty
                            Db.Dirty.Add(pgRecycleBin);
                            // mark root dirty if recycle bin was created
                            if (bUpdateGroupList)
                                Db.Dirty.Add(Db.Root);
                        } else {
                            // Let's not bother recovering from a failure to save a deleted entry.  It is too much work.
                            App.LockDatabase(false);
                        }

                    }, OnFinishToRun);
                }
            }

            // Commit database
            SaveDb save = new SaveDb(Ctx, App, OnFinishToRun, false);
            save.SetStatusLogger(StatusLogger);
            save.Run();
        }
コード例 #14
0
ファイル: AddGroup.cs プロジェクト: pythe/wristpass
        public override void Run()
        {
            StatusLogger.UpdateMessage(UiStringKey.AddingGroup);
            // Generate new group
            Group = new PwGroup(true, true, _name, (PwIcon)_iconId);
            Parent.AddGroup(Group, true);

            // Commit to disk
            SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun, DontSave);
            save.SetStatusLogger(StatusLogger);
            save.Run();
        }
コード例 #15
0
        public override void Run()
        {
            try
            {
                IOConnectionInfo ioc = _app.GetDb().Ioc;
                IFileStorage fileStorage = _app.GetFileStorage(ioc);
                if (!(fileStorage is CachingFileStorage))
                {
                    throw new Exception("Cannot sync a non-cached database!");
                }
                StatusLogger.UpdateMessage(UiStringKey.SynchronizingCachedDatabase);
                CachingFileStorage cachingFileStorage = (CachingFileStorage) fileStorage;

                //download file from remote location and calculate hash:
                StatusLogger.UpdateSubMessage(_app.GetResourceString(UiStringKey.DownloadingRemoteFile));
                string hash;

                MemoryStream remoteData;
                try
                {
                    remoteData = cachingFileStorage.GetRemoteDataAndHash(ioc, out hash);
                }
                catch (FileNotFoundException)
                {
                    StatusLogger.UpdateSubMessage(_app.GetResourceString(UiStringKey.RestoringRemoteFile));
                    cachingFileStorage.UpdateRemoteFile(ioc, _app.GetBooleanPreference(PreferenceKey.UseFileTransactions));
                    Finish(true, _app.GetResourceString(UiStringKey.SynchronizedDatabaseSuccessfully));
                    return;
                }

                //check if remote file was modified:
                if (cachingFileStorage.GetBaseVersionHash(ioc) != hash)
                {
                    //remote file is modified
                    if (cachingFileStorage.HasLocalChanges(ioc))
                    {
                        //conflict! need to merge
                        _saveDb = new SaveDb(_context, _app, new ActionOnFinish((success, result) =>
                            {
                                if (!success)
                                {
                                    Finish(false, result);
                                }
                                else
                                {
                                    Finish(true, _app.GetResourceString(UiStringKey.SynchronizedDatabaseSuccessfully));
                                }
                                _saveDb = null;
                            }), false, remoteData);
                        _saveDb.Run();

                        _app.GetDb().MarkAllGroupsAsDirty();
                    }
                    else
                    {
                        //only the remote file was modified -> reload database.
                        //note: it's best to lock the database and do a complete reload here (also better for UI consistency in case something goes wrong etc.)
                        _app.TriggerReload(_context);
                        Finish(true);
                    }
                }
                else
                {
                    //remote file is unmodified
                    if (cachingFileStorage.HasLocalChanges(ioc))
                    {
                        //but we have local changes -> upload:
                        StatusLogger.UpdateSubMessage(_app.GetResourceString(UiStringKey.UploadingFile));
                        cachingFileStorage.UpdateRemoteFile(ioc, _app.GetBooleanPreference(PreferenceKey.UseFileTransactions));
                        StatusLogger.UpdateSubMessage("");
                        Finish(true, _app.GetResourceString(UiStringKey.SynchronizedDatabaseSuccessfully));
                    }
                    else
                    {
                        //files are in sync: just set the result
                        Finish(true, _app.GetResourceString(UiStringKey.FilesInSync));
                    }
                }
            }
            catch (Exception e)
            {
                Finish(false, e.Message);
            }
        }
コード例 #16
0
        public override void Run()
        {
            try
            {
                IOConnectionInfo ioc         = _app.GetDb().Ioc;
                IFileStorage     fileStorage = _app.GetFileStorage(ioc);
                if (!(fileStorage is CachingFileStorage))
                {
                    throw new Exception("Cannot sync a non-cached database!");
                }
                StatusLogger.UpdateMessage(UiStringKey.SynchronizingCachedDatabase);
                CachingFileStorage cachingFileStorage = (CachingFileStorage)fileStorage;

                //download file from remote location and calculate hash:
                StatusLogger.UpdateSubMessage(_app.GetResourceString(UiStringKey.DownloadingRemoteFile));
                string hash;

                MemoryStream remoteData;
                try
                {
                    remoteData = cachingFileStorage.GetRemoteDataAndHash(ioc, out hash);
                }
                catch (FileNotFoundException)
                {
                    StatusLogger.UpdateSubMessage(_app.GetResourceString(UiStringKey.RestoringRemoteFile));
                    cachingFileStorage.UpdateRemoteFile(ioc, _app.GetBooleanPreference(PreferenceKey.UseFileTransactions));
                    Finish(true, _app.GetResourceString(UiStringKey.SynchronizedDatabaseSuccessfully));
                    return;
                }

                //check if remote file was modified:
                if (cachingFileStorage.GetBaseVersionHash(ioc) != hash)
                {
                    //remote file is modified
                    if (cachingFileStorage.HasLocalChanges(ioc))
                    {
                        //conflict! need to merge
                        _saveDb = new SaveDb(_context, _app, new ActionOnFinish((success, result) =>
                        {
                            if (!success)
                            {
                                Finish(false, result);
                            }
                            else
                            {
                                Finish(true, _app.GetResourceString(UiStringKey.SynchronizedDatabaseSuccessfully));
                            }
                            _saveDb = null;
                        }), false, remoteData);
                        _saveDb.Run();

                        _app.GetDb().MarkAllGroupsAsDirty();
                    }
                    else
                    {
                        //only the remote file was modified -> reload database.
                        //note: it's best to lock the database and do a complete reload here (also better for UI consistency in case something goes wrong etc.)
                        _app.TriggerReload(_context);
                        Finish(true);
                    }
                }
                else
                {
                    //remote file is unmodified
                    if (cachingFileStorage.HasLocalChanges(ioc))
                    {
                        //but we have local changes -> upload:
                        StatusLogger.UpdateSubMessage(_app.GetResourceString(UiStringKey.UploadingFile));
                        cachingFileStorage.UpdateRemoteFile(ioc, _app.GetBooleanPreference(PreferenceKey.UseFileTransactions));
                        StatusLogger.UpdateSubMessage("");
                        Finish(true, _app.GetResourceString(UiStringKey.SynchronizedDatabaseSuccessfully));
                    }
                    else
                    {
                        //files are in sync: just set the result
                        Finish(true, _app.GetResourceString(UiStringKey.FilesInSync));
                    }
                }
            }
            catch (Exception e)
            {
                Finish(false, e.Message);
            }
        }
コード例 #17
0
ファイル: CreateDB.cs プロジェクト: pythe/wristpass
        public override void Run()
        {
            StatusLogger.UpdateMessage(UiStringKey.progress_create);
            Database db = _app.CreateNewDatabase();

            db.KpDatabase = new KeePassLib.PwDatabase();

            if (_key == null)
            {
                _key = new CompositeKey(); //use a temporary key which should be changed after creation
            }

            db.KpDatabase.New(_ioc, _key);

            db.KpDatabase.KeyEncryptionRounds = DefaultEncryptionRounds;
            db.KpDatabase.Name = "Keepass2Android Password Database";
            //re-set the name of the root group because the PwDatabase uses UrlUtil which is not appropriate for all file storages:
            db.KpDatabase.RootGroup.Name = _app.GetFileStorage(_ioc).GetFilenameWithoutPathAndExt(_ioc);

            // Set Database state
            db.Root = db.KpDatabase.RootGroup;
            db.Loaded = true;
            db.SearchHelper = new SearchDbHelper(_app);

            // Add a couple default groups
            AddGroup internet = AddGroup.GetInstance(_ctx, _app, "Internet", 1, db.KpDatabase.RootGroup, null, true);
            internet.Run();
            AddGroup email = AddGroup.GetInstance(_ctx, _app, "eMail", 19, db.KpDatabase.RootGroup, null, true);
            email.Run();

            // Commit changes
            SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun, _dontSave);
            save.SetStatusLogger(StatusLogger);
            _onFinishToRun = null;
            save.Run();
        }