X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/5d17ccfcfb6aaa0fe7b3fb1d90ffde20a1013cc1..95390bb866330af2a495a87db368886185bfd887:/windows/winpgen.c diff --git a/windows/winpgen.c b/windows/winpgen.c index e80dbfec..1e2075de 100644 --- a/windows/winpgen.c +++ b/windows/winpgen.c @@ -198,11 +198,6 @@ static int prompt_keyfile(HWND hwnd, char *dlgtitle, { OPENFILENAME of; memset(&of, 0, sizeof(of)); -#ifdef OPENFILENAME_SIZE_VERSION_400 - of.lStructSize = OPENFILENAME_SIZE_VERSION_400; -#else - of.lStructSize = sizeof(of); -#endif of.hwndOwner = hwnd; if (ppk) { of.lpstrFilter = "PuTTY Private Key Files (*.ppk)\0*.ppk\0" @@ -217,13 +212,9 @@ static int prompt_keyfile(HWND hwnd, char *dlgtitle, *filename = '\0'; of.nMaxFile = FILENAME_MAX; of.lpstrFileTitle = NULL; - of.lpstrInitialDir = NULL; of.lpstrTitle = dlgtitle; of.Flags = 0; - if (save) - return GetSaveFileName(&of); - else - return GetOpenFileName(&of); + return request_file(NULL, &of, FALSE, save); } /* @@ -632,6 +623,7 @@ void load_key_file(HWND hwnd, struct MainDlgState *state, int needs_pass; int type, realtype; int ret; + const char *errmsg = NULL; char *comment; struct PassphraseProcStruct pps; struct RSAKey newkey1; @@ -641,11 +633,11 @@ void load_key_file(HWND hwnd, struct MainDlgState *state, if (type != SSH_KEYTYPE_SSH1 && type != SSH_KEYTYPE_SSH2 && !import_possible(type)) { - char msg[256]; - sprintf(msg, "Couldn't load private key (%s)", - key_type_to_str(type)); + char *msg = dupprintf("Couldn't load private key (%s)", + key_type_to_str(type)); MessageBox(NULL, msg, "PuTTYgen Error", MB_OK | MB_ICONERROR); + sfree(msg); return; } @@ -682,17 +674,17 @@ void load_key_file(HWND hwnd, struct MainDlgState *state, if (type == SSH_KEYTYPE_SSH1) { if (realtype == type) ret = loadrsakey(&filename, &newkey1, - passphrase, NULL); + passphrase, &errmsg); else ret = import_ssh1(&filename, realtype, - &newkey1, passphrase); + &newkey1, passphrase, &errmsg); } else { if (realtype == type) newkey2 = ssh2_load_userkey(&filename, - passphrase, NULL); + passphrase, &errmsg); else newkey2 = import_ssh2(&filename, realtype, - passphrase); + passphrase, &errmsg); if (newkey2 == SSH2_WRONG_PASSPHRASE) ret = -1; else if (!newkey2) @@ -704,8 +696,9 @@ void load_key_file(HWND hwnd, struct MainDlgState *state, if (comment) sfree(comment); if (ret == 0) { - MessageBox(NULL, "Couldn't load private key.", - "PuTTYgen Error", MB_OK | MB_ICONERROR); + char *msg = dupprintf("Couldn't load private key (%s)", errmsg); + MessageBox(NULL, msg, "PuTTYgen Error", MB_OK | MB_ICONERROR); + sfree(msg); } else if (ret == 1) { /* * Now update the key controls with all the @@ -1279,14 +1272,12 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg, */ *state->commentptr = snewn(30, char); { - time_t t; - struct tm *tm; - time(&t); - tm = localtime(&t); + struct tm tm; + tm = ltime(); if (state->is_dsa) - strftime(*state->commentptr, 30, "dsa-key-%Y%m%d", tm); + strftime(*state->commentptr, 30, "dsa-key-%Y%m%d", &tm); else - strftime(*state->commentptr, 30, "rsa-key-%Y%m%d", tm); + strftime(*state->commentptr, 30, "rsa-key-%Y%m%d", &tm); } /* @@ -1342,50 +1333,52 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg, case WM_HELP: if (help_path) { int id = ((LPHELPINFO)lParam)->iCtrlId; - char *cmd = NULL; + char *topic = NULL; switch (id) { case IDC_GENERATING: case IDC_PROGRESS: case IDC_GENSTATIC: case IDC_GENERATE: - cmd = "JI(`',`puttygen.generate')"; break; + topic = "puttygen.generate"; break; case IDC_PKSTATIC: case IDC_KEYDISPLAY: - cmd = "JI(`',`puttygen.pastekey')"; break; + topic = "puttygen.pastekey"; break; case IDC_FPSTATIC: case IDC_FINGERPRINT: - cmd = "JI(`',`puttygen.fingerprint')"; break; + topic = "puttygen.fingerprint"; break; case IDC_COMMENTSTATIC: case IDC_COMMENTEDIT: - cmd = "JI(`',`puttygen.comment')"; break; + topic = "puttygen.comment"; break; case IDC_PASSPHRASE1STATIC: case IDC_PASSPHRASE1EDIT: case IDC_PASSPHRASE2STATIC: case IDC_PASSPHRASE2EDIT: - cmd = "JI(`',`puttygen.passphrase')"; break; + topic = "puttygen.passphrase"; break; case IDC_LOADSTATIC: case IDC_LOAD: - cmd = "JI(`',`puttygen.load')"; break; + topic = "puttygen.load"; break; case IDC_SAVESTATIC: case IDC_SAVE: - cmd = "JI(`',`puttygen.savepriv')"; break; + topic = "puttygen.savepriv"; break; case IDC_SAVEPUB: - cmd = "JI(`',`puttygen.savepub')"; break; + topic = "puttygen.savepub"; break; case IDC_TYPESTATIC: case IDC_KEYSSH1: case IDC_KEYSSH2RSA: case IDC_KEYSSH2DSA: - cmd = "JI(`',`puttygen.keytype')"; break; + topic = "puttygen.keytype"; break; case IDC_BITSSTATIC: case IDC_BITS: - cmd = "JI(`',`puttygen.bits')"; break; + topic = "puttygen.bits"; break; case IDC_IMPORT: case IDC_EXPORT_OPENSSH: case IDC_EXPORT_SSHCOM: - cmd = "JI(`',`puttygen.conversions')"; break; + topic = "puttygen.conversions"; break; } - if (cmd) { + if (topic) { + char *cmd = dupprintf("JI(`',`%s')", topic); WinHelp(hwnd, help_path, HELP_COMMAND, (DWORD)cmd); + sfree(cmd); requested_help = TRUE; } else { MessageBeep(0); @@ -1437,7 +1430,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) if (p && p >= r) r = p+1; q = strrchr(b, ':'); if (q && q >= r) r = q+1; - strcpy(r, "putty.hlp"); + strcpy(r, PUTTY_HELP_FILE); if ( (fp = fopen(b, "r")) != NULL) { help_path = dupstr(b); fclose(fp);