예제 #1
0
        private void StartAddEntry()
        {
            PwEntry defaultTemplate = new PwEntry(false, false);

            defaultTemplate.IconId = PwIcon.Key;
            defaultTemplate.Strings.Set(PwDefs.TitleField, new ProtectedString(false, GetString(Resource.String.DefaultTemplate)));
            List <PwEntry> templates = new List <PwEntry>()
            {
                defaultTemplate
            };

            if ((!PwUuid.Zero.Equals(App.Kp2a.CurrentDb.KpDatabase.EntryTemplatesGroup)) &&
                (App.Kp2a.CurrentDb.KpDatabase.RootGroup.FindGroup(App.Kp2a.CurrentDb.KpDatabase.EntryTemplatesGroup, true) != null))
            {
                templates.AddRange(
                    App.Kp2a.CurrentDb.GroupsById[App.Kp2a.CurrentDb.KpDatabase.EntryTemplatesGroup].Entries.OrderBy(
                        entr => entr.Strings.ReadSafe(PwDefs.TitleField)));
            }
            if (templates.Count > 1)
            {
                new AlertDialog.Builder(this)
                .SetAdapter(new TemplateListAdapter(this, Android.Resource.Layout.SelectDialogItem,
                                                    Android.Resource.Id.Text1, templates),
                            (o, args) => { EntryEditActivity.Launch(this, Group, templates[args.Which].Uuid, AppTask); })
                .Show();
            }
            else
            {
                EntryEditActivity.Launch(this, Group, PwUuid.Zero, AppTask);
            }
        }
예제 #2
0
 public override void AfterAddNewEntry(EntryEditActivity entryEditActivity, PwEntry newEntry)
 {
     EntryActivity.Launch(entryEditActivity, newEntry, -1,
                          new SelectEntryTask {
         ShowUserNotifications = this.ShowUserNotifications
     },
                          ActivityFlags.ForwardResult);
     //no need to call Finish here, that's done in EntryEditActivity ("closeOrShowError")
 }
예제 #3
0
        protected void SetupEditButtons()
        {
            View edit = FindViewById(Resource.Id.entry_edit);

            if (App.Kp2a.GetDb().CanWrite)
            {
                edit.Visibility = ViewStates.Visible;
                edit.Click     += (sender, e) =>
                {
                    EntryEditActivity.Launch(this, Entry, _appTask);
                };
            }
            else
            {
                edit.Visibility = ViewStates.Gone;
            }
        }
예제 #4
0
        void UpdateEntryFromUi(PwEntry entry)
        {
            Database          db  = App.Kp2a.GetDb();
            EntryEditActivity act = this;

            entry.Strings.Set(PwDefs.TitleField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectTitle,
                                                                     Util.GetEditText(act, Resource.Id.entry_title)));
            entry.Strings.Set(PwDefs.UserNameField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectUserName,
                                                                        Util.GetEditText(act, Resource.Id.entry_user_name)));

            String pass = Util.GetEditText(act, Resource.Id.entry_password);

            byte[] password = StrUtil.Utf8.GetBytes(pass);
            entry.Strings.Set(PwDefs.PasswordField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectPassword,
                                                                        password));
            MemUtil.ZeroByteArray(password);

            entry.Strings.Set(PwDefs.UrlField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectUrl,
                                                                   Util.GetEditText(act, Resource.Id.entry_url)));
            entry.Strings.Set(PwDefs.NotesField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectNotes,
                                                                     Util.GetEditText(act, Resource.Id.entry_comment)));

            // Validate expiry date
            DateTime newExpiry = new DateTime();

            if ((State.Entry.Expires) && (!DateTime.TryParse(Util.GetEditText(this, Resource.Id.entry_expires), out newExpiry)))
            {
                //ignore here
            }
            else
            {
                State.Entry.ExpiryTime = newExpiry;
            }

            // Delete all non standard strings
            var keys = entry.Strings.GetKeys();

            foreach (String key in keys)
            {
                if (PwDefs.IsStandardField(key) == false)
                {
                    entry.Strings.Remove(key);
                }
            }

            LinearLayout container = (LinearLayout)FindViewById(Resource.Id.advanced_container);

            for (int index = 0; index < container.ChildCount; index++)
            {
                View view = container.GetChildAt(index);

                TextView keyView = (TextView)view.FindViewById(Resource.Id.title);
                String   key     = keyView.Text;

                if (String.IsNullOrEmpty(key))
                {
                    continue;
                }

                TextView valueView = (TextView)view.FindViewById(Resource.Id.value);
                String   value     = valueView.Text;


                bool protect = ((CheckBox)view.FindViewById(Resource.Id.protection)).Checked;
                entry.Strings.Set(key, new ProtectedString(protect, value));
            }


            entry.OverrideUrl = Util.GetEditText(this, Resource.Id.entry_override_url);

            List <string> vNewTags = StrUtil.StringToTags(Util.GetEditText(this, Resource.Id.entry_tags));

            entry.Tags.Clear();
            foreach (string strTag in vNewTags)
            {
                entry.AddTag(strTag);
            }

            /*KPDesktop
             *
             *
             *      m_atConfig.Enabled = m_cbAutoTypeEnabled.Checked;
             *      m_atConfig.ObfuscationOptions = (m_cbAutoTypeObfuscation.Checked ?
             *                                       AutoTypeObfuscationOptions.UseClipboard :
             *                                       AutoTypeObfuscationOptions.None);
             *
             *      SaveDefaultSeq();
             *
             *      newEntry.AutoType = m_atConfig;
             */
        }
예제 #5
0
        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();
        }
예제 #6
0
 public virtual void AfterAddNewEntry(EntryEditActivity entryEditActivity, PwEntry newEntry)
 {
 }
예제 #7
0
파일: AppTask.cs 프로젝트: pythe/wristpass
 public override void AfterAddNewEntry(EntryEditActivity entryEditActivity, PwEntry newEntry)
 {
     EntryActivity.Launch(entryEditActivity, newEntry, -1,
         new SelectEntryTask { ShowUserNotifications = this.ShowUserNotifications},
         ActivityFlags.ForwardResult);
     //no need to call Finish here, that's done in EntryEditActivity ("closeOrShowError")
 }
예제 #8
0
파일: AppTask.cs 프로젝트: pythe/wristpass
 public virtual void AfterAddNewEntry(EntryEditActivity entryEditActivity, PwEntry newEntry)
 {
 }
예제 #9
0
 private void OnEdit(AutoExecItem item)
 {
     EntryEditActivity.Launch(this, item.Entry, new NullTask());
 }