This is the last part of what I need for the project, once this is working I'll post it up somewhere on the site and hopefully some guru's can suggest improvements to make it even better (but already it helps me a huge amount, very useful/efficient time-saving in user/password entry with the other components).
Code: Select all
:x*:]]change::
usernames := ""
GuiTag := "", GuiUsername := "", GuiPassword := "", GuiEmail := "", GuiFullname := ""
Loop, read, %PwdFile%
{
if (!RegExMatch(A_LoopReadLine, "^#") {
tmp := StrSplit(A_LoopReadLine, " ")
usernames .= tmp.2 . " [" . tmp.1 . "]`n"
}
}
; This simply uses the "SelectItem" function to display a RadioBox Gui to pick from the above list of usernames to then capture a line from the %PwdFile% to work with
selection := SelectItem(usernames, "Select User/Tag to be changed?", "Up/Down then Enter to select User/Tag to change.`nThe code in [xx] account tag to tie to password.")
if (selection != "") {
tmp := StrSplit(RegExReplace(selection, " +", " "), " ") ; use regex to replace multiple spaces with single spaces!
tmp_last := tmp.MaxIndex()
tag := tmp[tmp_last]
tag := RegExReplace(tag, "\[", "")
tag := RegExReplace(tag, "\]", "")
}
; GetPwdValue simply looks into the %PwdFile% and grabs a line that starts with %tag% (each line is simply a space-separated string of "<tag> <username> <password> <email> <fullname>" that GetPwdValue splits up)
user := GetPwdValue(tag, "Username")
pass := GetPwdValue(tag, "Password")
email := GetPwdValue(tag, "Email")
full := GetPwdValue(tag, "Fullname")
GuiTag := tag ; don't think I need to do this, just trying to pre-populate them to start with to see if this helps
GuiUsername := user
GuiPassword := pass
GuiEmail := email
GuiFullname := full
gui,3: new
gui,3: Default
gui,3: +LastFound ; +Label2
gui,3: add, text, xm12 ym5,Enter credentials to store in password file at:
gui,3: add, text, xm12 ym20,'%PwdFile%'.
gui,3: add, text, xm12 ym45,Tag, Username, Password are mandatory. ; groupbox w250 h147
gui,3: add, text, xm12 ym60,Email and Fullname are optional. ; groupbox w250 h147
gui,3: add, edit, xm80 ys ym85 vGuiTag, %tag%
gui,3: add, edit, xm80 yp+30 vGuiUsername, %user%
gui,3: add, edit, xm80 yp+30 vGuiPassword, %pass% ; 'password' option will obscure this field
gui,3: add, edit, xm80 yp+30 vGuiEmail, %email%
gui,3: add, edit, xm80 yp+30 vGuiFullname, %full%
gui,3: add, text, xm12 ym87 section, Tag:
gui,3: add, text, xm12 yp+30, Username:
gui,3: add, text, xm12 yp+30, Password:
gui,3: add, text, xm12 yp+30, (Email):
gui,3: add, text, xm12 yp+30, (Fullname):
gui,3: add, button, xm80 yp+35 default gDone3, OK ; Default means this will act on pressing Enter
gui,3: add, button, xp+50 gClose, Cancel
gui,3: show, x300 y200, Set Credentials
return ; return should be blank except inside a function... winexist()
Done3:
{
I want to populate the current values in the Gui fields as they are when I press OK. But this doesn't work, when I get to this point, none of GuiTag / Username / Password etc seem to contain the CURRENT values that are in those fields!
tag := GuiTag
user := GuiUsername
pass := GuiPassword
email := GuiEmail
full := GuiFullname
MsgBox, %tag%`n%user%`n%pass%
gui,2:submit,nohide
if (GuiTag = tag and GuiUsername = user and GuiPassword = pass and GuiEmail = email and GuiFullname = full) {
MsgBox, No values were changed., No changes were made, exiting...
gui,2:destroy
gui,3:destroy
return
}
IfInString, GuiTag, %A_Space%
{
MsgBox, Tag '%GuiTag%' is not permitted to have whitespace
gui,2:destroy
return
}
IfInString, GuiUsername, %A_Space%
{
MsgBox, Username '%GuiUsername%' is not permitted to have whitespace
gui,2:destroy
return
}
IfInString, GuiPassword, %A_Space%
{
MsgBox, Password '%GuiPassword%' is not permitted to have whitespace
gui,2:destroy
return
}
if (GuiTag != "" and GuiUsername != "" and GuiPassword != "") {
SetPWdTag(GuiTag, GuiUsername, GuiPassword, GuiEmail, GuiFullname)
}
else {
MsgBox, Mandatory values are required for Tag, Username, Password. As these were not entered, nothing will be updated in '%PwdFile%':`n`nTag: %GuiTag%`nUsername: %GuiUsername%`nPassword: %GuiPassword%`nEmail: %GuiEmail%`nFullname: %GuiFullname%
}
gui,2:destroy
gui,3:destroy
return
}
return
; Must match the gui title (and cannot use variales)
#IfWinActive Set Credentials ; Without this, ESC will be globally tied to this dialogue, locking out all other functionality
Esc::
Close:
{
gui,2:destroy
gui,3:destroy
return
}
#IfWinActive