Ben Rudiak-Gould points out that we should be using WM_APP as the base for
[u/mdw/putty] / windows / winpgen.c
index dae9f93..d767b23 100644 (file)
 #define ICON_BIG        1
 #endif
 
-#define WM_DONEKEY (WM_XUSER + 1)
+#define WM_DONEKEY (WM_APP + 1)
 
 #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);
 }
 
 /*
@@ -436,7 +425,7 @@ void old_keyfile_warning(void)
 {
     static const char mbtitle[] = "PuTTY Key File Warning";
     static const char message[] =
-       "You are loading an SSH 2 private key which has an\n"
+       "You are loading an SSH-2 private key which has an\n"
        "old version of the file format. This means your key\n"
        "file is not fully tamperproof. Future versions of\n"
        "PuTTY may stop supporting this private key format,\n"
@@ -644,8 +633,8 @@ 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));
-       MessageBox(NULL, msg,
-                  "PuTTYgen Error", MB_OK | MB_ICONERROR);
+       message_box(msg, "PuTTYgen Error", MB_OK | MB_ICONERROR,
+                   HELPCTXID(errors_cantloadkey));
        sfree(msg);
        return;
     }
@@ -673,7 +662,7 @@ void load_key_file(HWND hwnd, struct MainDlgState *state,
            dlgret = DialogBoxParam(hinst,
                                    MAKEINTRESOURCE(210),
                                    NULL, PassphraseProc,
-                                   (LPARAM) & pps);
+                                   (LPARAM) &pps);
            if (!dlgret) {
                ret = -2;
                break;
@@ -706,7 +695,8 @@ void load_key_file(HWND hwnd, struct MainDlgState *state,
        sfree(comment);
     if (ret == 0) {
        char *msg = dupprintf("Couldn't load private key (%s)", errmsg);
-       MessageBox(NULL, msg, "PuTTYgen Error", MB_OK | MB_ICONERROR);
+       message_box(msg, "PuTTYgen Error", MB_OK | MB_ICONERROR,
+                   HELPCTXID(errors_cantloadkey));
        sfree(msg);
     } else if (ret == 1) {
        /*
@@ -811,8 +801,9 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
     switch (msg) {
       case WM_INITDIALOG:
         if (help_path)
-            SetWindowLong(hwnd, GWL_EXSTYLE,
-                          GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_CONTEXTHELP);
+            SetWindowLongPtr(hwnd, GWL_EXSTYLE,
+                            GetWindowLongPtr(hwnd, GWL_EXSTYLE) |
+                            WS_EX_CONTEXTHELP);
         else {
             /*
              * If we add a Help button, this is where we destroy it
@@ -828,7 +819,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
        state->collecting_entropy = FALSE;
        state->entropy = NULL;
        state->key_exists = FALSE;
-       SetWindowLong(hwnd, GWL_USERDATA, (LONG) state);
+       SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) state);
        {
            HMENU menu, menu1;
 
@@ -846,9 +837,9 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
            menu1 = CreateMenu();
            AppendMenu(menu1, MF_ENABLED, IDC_GENERATE, "&Generate key pair");
            AppendMenu(menu1, MF_SEPARATOR, 0, 0);
-           AppendMenu(menu1, MF_ENABLED, IDC_KEYSSH1, "SSH&1 key (RSA)");
-           AppendMenu(menu1, MF_ENABLED, IDC_KEYSSH2RSA, "SSH2 &RSA key");
-           AppendMenu(menu1, MF_ENABLED, IDC_KEYSSH2DSA, "SSH2 &DSA key");
+           AppendMenu(menu1, MF_ENABLED, IDC_KEYSSH1, "SSH-&1 key (RSA)");
+           AppendMenu(menu1, MF_ENABLED, IDC_KEYSSH2RSA, "SSH-2 &RSA key");
+           AppendMenu(menu1, MF_ENABLED, IDC_KEYSSH2DSA, "SSH-2 &DSA key");
            AppendMenu(menu, MF_POPUP | MF_ENABLED, (UINT) menu1, "&Key");
            state->keymenu = menu1;
 
@@ -925,9 +916,9 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
            endbox(&cp);
            beginbox(&cp, "Parameters", IDC_BOX_PARAMS);
            radioline(&cp, "Type of key to generate:", IDC_TYPESTATIC, 3,
-                     "SSH&1 (RSA)", IDC_KEYSSH1,
-                     "SSH2 &RSA", IDC_KEYSSH2RSA,
-                     "SSH2 &DSA", IDC_KEYSSH2DSA, NULL);
+                     "SSH-&1 (RSA)", IDC_KEYSSH1,
+                     "SSH-2 &RSA", IDC_KEYSSH2RSA,
+                     "SSH-2 &DSA", IDC_KEYSSH2DSA, NULL);
            staticedit(&cp, "Number of &bits in a generated key:",
                       IDC_BITSSTATIC, IDC_BITS, 20);
            endbox(&cp);
@@ -953,7 +944,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
 
        return 1;
       case WM_MOUSEMOVE:
-       state = (struct MainDlgState *) GetWindowLong(hwnd, GWL_USERDATA);
+       state = (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
        if (state->collecting_entropy &&
            state->entropy && state->entropy_got < state->entropy_required) {
            state->entropy[state->entropy_got++] = lParam;
@@ -1004,7 +995,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
          case IDC_KEYSSH2DSA:
            {
                state = (struct MainDlgState *)
-                   GetWindowLong(hwnd, GWL_USERDATA);
+                   GetWindowLongPtr(hwnd, GWLP_USERDATA);
                if (!IsDlgButtonChecked(hwnd, LOWORD(wParam)))
                    CheckRadioButton(hwnd, IDC_KEYSSH1, IDC_KEYSSH2DSA,
                                     LOWORD(wParam));
@@ -1018,7 +1009,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
          case IDC_COMMENTEDIT:
            if (HIWORD(wParam) == EN_CHANGE) {
                state = (struct MainDlgState *)
-                   GetWindowLong(hwnd, GWL_USERDATA);
+                   GetWindowLongPtr(hwnd, GWLP_USERDATA);
                if (state->key_exists) {
                    HWND editctl = GetDlgItem(hwnd, IDC_COMMENTEDIT);
                    int len = GetWindowTextLength(editctl);
@@ -1057,7 +1048,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
                 HIWORD(wParam) != BN_DOUBLECLICKED)
                break;
            state =
-               (struct MainDlgState *) GetWindowLong(hwnd, GWL_USERDATA);
+               (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
            if (!state->generation_thread_exists) {
                BOOL ok;
                state->keysize = GetDlgItemInt(hwnd, IDC_BITS, &ok, FALSE);
@@ -1113,7 +1104,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
            if (HIWORD(wParam) != BN_CLICKED)
                break;
            state =
-               (struct MainDlgState *) GetWindowLong(hwnd, GWL_USERDATA);
+               (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
            if (state->key_exists) {
                char filename[FILENAME_MAX];
                char passphrase[PASSPHRASE_MAXLEN];
@@ -1135,7 +1126,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
                 if (type != realtype &&
                     import_target_type(type) != realtype) {
                     char msg[256];
-                    sprintf(msg, "Cannot export an SSH%d key in an SSH%d"
+                    sprintf(msg, "Cannot export an SSH-%d key in an SSH-%d"
                             " format", (state->ssh2 ? 2 : 1),
                             (state->ssh2 ? 1 : 2));
                    MessageBox(hwnd, msg,
@@ -1208,7 +1199,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
            if (HIWORD(wParam) != BN_CLICKED)
                break;
            state =
-               (struct MainDlgState *) GetWindowLong(hwnd, GWL_USERDATA);
+               (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
            if (state->key_exists) {
                char filename[FILENAME_MAX];
                if (prompt_keyfile(hwnd, "Save public key as:",
@@ -1243,7 +1234,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
            if (HIWORD(wParam) != BN_CLICKED)
                break;
            state =
-               (struct MainDlgState *) GetWindowLong(hwnd, GWL_USERDATA);
+               (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
            if (!state->generation_thread_exists) {
                char filename[FILENAME_MAX];
                if (prompt_keyfile(hwnd, "Load private key:",
@@ -1255,7 +1246,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
        }
        return 0;
       case WM_DONEKEY:
-       state = (struct MainDlgState *) GetWindowLong(hwnd, GWL_USERDATA);
+       state = (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
        state->generation_thread_exists = FALSE;
        state->key_exists = TRUE;
        SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0,
@@ -1395,7 +1386,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
         }
         break;
       case WM_CLOSE:
-       state = (struct MainDlgState *) GetWindowLong(hwnd, GWL_USERDATA);
+       state = (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
        sfree(state);
         if (requested_help) {
             WinHelp(hwnd, help_path, HELP_QUIT, 0);
@@ -1414,18 +1405,9 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
     int argc;
     char **argv;
 
-    split_into_argv(cmdline, &argc, &argv, NULL);
-
-    if (argc > 0) {
-       /*
-        * Assume the first argument to be a private key file, and
-        * attempt to load it.
-        */
-       cmdline_keyfile = argv[0];
-    }
-
     InitCommonControls();
     hinst = inst;
+    hwnd = NULL;
 
     /*
      * See if we can find our Help file.
@@ -1447,6 +1429,21 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
             help_path = NULL;
     }
 
+    split_into_argv(cmdline, &argc, &argv, NULL);
+
+    if (argc > 0) {
+       if (!strcmp(argv[0], "-pgpfp")) {
+           pgp_fingerprints();
+           exit(1);
+       } else {
+           /*
+            * Assume the first argument to be a private key file, and
+            * attempt to load it.
+            */
+           cmdline_keyfile = argv[0];
+       }
+    }
+
     random_ref();
     return DialogBox(hinst, MAKEINTRESOURCE(201), NULL,
                     MainDlgProc) != IDOK;