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(); }
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(); }