Add context help to a couple of message boxes. Unfortunately the ones
[sgt/putty] / windows / winpgen.c
index e80dbfe..d027fc7 100644 (file)
@@ -21,8 +21,6 @@
 
 #define DEFAULT_KEYSIZE 1024
 
-static int requested_help;
-
 static char *cmdline_keyfile = NULL;
 
 /*
@@ -198,11 +196,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 +210,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 +621,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 +631,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));
-       MessageBox(NULL, msg,
-                  "PuTTYgen Error", MB_OK | MB_ICONERROR);
+       char *msg = dupprintf("Couldn't load private key (%s)",
+                             key_type_to_str(type));
+       message_box(msg, "PuTTYgen Error", MB_OK | MB_ICONERROR,
+                   HELPCTXID(errors_cantloadkey));
+       sfree(msg);
        return;
     }
 
@@ -682,17 +672,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 +694,10 @@ 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);
+       message_box(msg, "PuTTYgen Error", MB_OK | MB_ICONERROR,
+                   HELPCTXID(errors_cantloadkey));
+       sfree(msg);
     } else if (ret == 1) {
        /*
         * Now update the key controls with all the
@@ -1279,14 +1271,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 +1332,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);
@@ -1424,6 +1416,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
 
     InitCommonControls();
     hinst = inst;
+    hwnd = NULL;
 
     /*
      * See if we can find our Help file.
@@ -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);