1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 09:27:59 +00:00

Stop winutils.c from depending on the global HWND.

The GUI version of pgp_fingerprints() is now a differently named
function that takes a parent HWND as a parameter, and so does my
help-enabled wrapper around MessageBox.
This commit is contained in:
Simon Tatham 2020-02-02 10:00:42 +00:00
parent ad0c7c99f8
commit 46f60bb547
6 changed files with 34 additions and 27 deletions

View File

@ -872,7 +872,7 @@ int win_seat_verify_ssh_host_key(
char *text = dupprintf(wrongmsg, appname, keytype, fingerprint,
appname);
char *caption = dupprintf(mbtitle, appname);
mbret = message_box(text, caption,
mbret = message_box(hwnd, text, caption,
MB_ICONWARNING | MB_YESNOCANCEL | MB_DEFBUTTON3,
HELPCTXID(errors_hostkey_changed));
assert(mbret==IDYES || mbret==IDNO || mbret==IDCANCEL);
@ -887,7 +887,7 @@ int win_seat_verify_ssh_host_key(
int mbret;
char *text = dupprintf(absentmsg, keytype, fingerprint, appname);
char *caption = dupprintf(mbtitle, appname);
mbret = message_box(text, caption,
mbret = message_box(hwnd, text, caption,
MB_ICONWARNING | MB_YESNOCANCEL | MB_DEFBUTTON3,
HELPCTXID(errors_hostkey_absent));
assert(mbret==IDYES || mbret==IDNO || mbret==IDCANCEL);

View File

@ -648,7 +648,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
"Are you really sure you want to continue?",
appname);
s2 = dupprintf("%s Warning", appname);
if (message_box(s1, s2,
if (message_box(NULL, s1, s2,
MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2,
HELPCTXID(option_cleanup)) == IDYES) {
cleanup_all();
@ -657,7 +657,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
sfree(s2);
exit(0);
} else if (!strcmp(p, "-pgpfp")) {
pgp_fingerprints();
pgp_fingerprints_msgbox(NULL);
exit(1);
} else if (*p != '-') {
cmdline_error("unexpected argument \"%s\"", p);

View File

@ -657,7 +657,7 @@ void load_key_file(HWND hwnd, struct MainDlgState *state,
!import_possible(type)) {
char *msg = dupprintf("Couldn't load private key (%s)",
key_type_to_str(type));
message_box(msg, "PuTTYgen Error", MB_OK | MB_ICONERROR,
message_box(hwnd, msg, "PuTTYgen Error", MB_OK | MB_ICONERROR,
HELPCTXID(errors_cantloadkey));
sfree(msg);
return;
@ -720,7 +720,7 @@ void load_key_file(HWND hwnd, struct MainDlgState *state,
sfree(comment);
if (ret == 0) {
char *msg = dupprintf("Couldn't load private key (%s)", errmsg);
message_box(msg, "PuTTYgen Error", MB_OK | MB_ICONERROR,
message_box(hwnd, msg, "PuTTYgen Error", MB_OK | MB_ICONERROR,
HELPCTXID(errors_cantloadkey));
sfree(msg);
} else if (ret == 1) {
@ -1572,7 +1572,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
for (i = 0; i < argc; i++) {
if (!strcmp(argv[i], "-pgpfp")) {
pgp_fingerprints();
pgp_fingerprints_msgbox(NULL);
return 1;
} else if (!strcmp(argv[i], "-restrict-acl") ||
!strcmp(argv[i], "-restrict_acl") ||

View File

@ -415,7 +415,7 @@ static void win_add_keyfile(Filename *filename)
}
error:
message_box(err, APPNAME, MB_OK | MB_ICONERROR,
message_box(hwnd, err, APPNAME, MB_OK | MB_ICONERROR,
HELPCTXID(errors_cantloadkey));
done:
if (passphrase) {
@ -1271,7 +1271,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
split_into_argv(cmdline, &argc, &argv, &argstart);
for (i = 0; i < argc; i++) {
if (!strcmp(argv[i], "-pgpfp")) {
pgp_fingerprints();
pgp_fingerprints_msgbox(NULL);
return 1;
} else if (!strcmp(argv[i], "-restrict-acl") ||
!strcmp(argv[i], "-restrict_acl") ||

View File

@ -399,7 +399,9 @@ typedef struct filereq_tag filereq; /* cwd for file requester */
bool request_file(filereq *state, OPENFILENAME *of, bool preserve, bool save);
filereq *filereq_new(void);
void filereq_free(filereq *state);
int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid);
void pgp_fingerprints_msgbox(HWND owner);
int message_box(HWND owner, LPCTSTR text, LPCTSTR caption,
DWORD style, DWORD helpctxid);
char *GetDlgItemText_alloc(HWND hwnd, int id);
void split_into_argv(char *, int *, char ***, char ***);

View File

@ -91,6 +91,8 @@ void filereq_free(filereq *state)
* Message box with optional context help.
*/
static HWND message_box_owner;
/* Callback function to launch context help. */
static VOID CALLBACK message_box_help_callback(LPHELPINFO lpHelpInfo)
{
@ -107,10 +109,11 @@ static VOID CALLBACK message_box_help_callback(LPHELPINFO lpHelpInfo)
CHECK_CTX(pgp_fingerprints);
#undef CHECK_CTX
if (context)
launch_help(hwnd, context);
launch_help(message_box_owner, context);
}
int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid)
int message_box(HWND owner, LPCTSTR text, LPCTSTR caption,
DWORD style, DWORD helpctxid)
{
MSGBOXPARAMS mbox;
@ -121,7 +124,7 @@ int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid)
mbox.cbSize = sizeof(mbox);
/* Assumes the globals `hinst' and `hwnd' have sensible values. */
mbox.hInstance = hinst;
mbox.hwndOwner = hwnd;
mbox.hwndOwner = message_box_owner = owner;
mbox.lpfnMsgBoxCallback = &message_box_help_callback;
mbox.dwLanguageId = LANG_NEUTRAL;
mbox.lpszText = text;
@ -135,21 +138,23 @@ int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid)
/*
* Display the fingerprints of the PGP Master Keys to the user.
*/
void pgp_fingerprints(void)
void pgp_fingerprints_msgbox(HWND owner)
{
message_box("These are the fingerprints of the PuTTY PGP Master Keys. They can\n"
"be used to establish a trust path from this executable to another\n"
"one. See the manual for more information.\n"
"(Note: these fingerprints have nothing to do with SSH!)\n"
"\n"
"PuTTY Master Key as of " PGP_MASTER_KEY_YEAR
" (" PGP_MASTER_KEY_DETAILS "):\n"
" " PGP_MASTER_KEY_FP "\n\n"
"Previous Master Key (" PGP_PREV_MASTER_KEY_YEAR
", " PGP_PREV_MASTER_KEY_DETAILS "):\n"
" " PGP_PREV_MASTER_KEY_FP,
"PGP fingerprints", MB_ICONINFORMATION | MB_OK,
HELPCTXID(pgp_fingerprints));
message_box(
owner,
"These are the fingerprints of the PuTTY PGP Master Keys. They can\n"
"be used to establish a trust path from this executable to another\n"
"one. See the manual for more information.\n"
"(Note: these fingerprints have nothing to do with SSH!)\n"
"\n"
"PuTTY Master Key as of " PGP_MASTER_KEY_YEAR
" (" PGP_MASTER_KEY_DETAILS "):\n"
" " PGP_MASTER_KEY_FP "\n\n"
"Previous Master Key (" PGP_PREV_MASTER_KEY_YEAR
", " PGP_PREV_MASTER_KEY_DETAILS "):\n"
" " PGP_PREV_MASTER_KEY_FP,
"PGP fingerprints", MB_ICONINFORMATION | MB_OK,
HELPCTXID(pgp_fingerprints));
}
/*