Пример #1
0
        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();
        }
        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();
                };
            }
        }
Пример #3
0
        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();
                }
            }
        }
Пример #4
0
        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");
        }