X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/d70f60ae52b946d174468a4dff49702daa93dc9a..ec8679e9b667dd6de9ef29e0d01085b219901e3b:/pageant.c diff --git a/pageant.c b/pageant.c index 7133c8d5..f8d7ad2d 100644 --- a/pageant.c +++ b/pageant.c @@ -127,7 +127,8 @@ void add_keyfile(char *filename) { int ret; int attempts; - needs_pass = rsakey_encrypted(filename); + /* FIXME: we can acquire comment here and use it in dialog */ + needs_pass = rsakey_encrypted(filename, NULL); attempts = 0; key = malloc(sizeof(*key)); do { @@ -420,6 +421,9 @@ static LRESULT CALLBACK WndProc (HWND hwnd, UINT message, POINT cursorpos; GetCursorPos(&cursorpos); PostMessage(hwnd, WM_SYSTRAY2, cursorpos.x, cursorpos.y); + } else if (lParam == WM_LBUTTONDBLCLK) { + /* Equivalent to IDM_VIEWKEYS. */ + PostMessage(hwnd, WM_COMMAND, IDM_VIEWKEYS, 0); } break; case WM_SYSTRAY2: @@ -444,6 +448,13 @@ static LRESULT CALLBACK WndProc (HWND hwnd, UINT message, keylist = CreateDialog (instance, MAKEINTRESOURCE(211), NULL, KeyListProc); ShowWindow (keylist, SW_SHOWNORMAL); + /* + * Sometimes the window comes up minimised / hidden + * for no obvious reason. Prevent this. + */ + SetForegroundWindow(keylist); + SetWindowPos (keylist, HWND_TOP, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); } break; } @@ -534,6 +545,15 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { WNDCLASS wndclass; MSG msg; + /* + * First bomb out totally if we are already running. + */ + if (FindWindow("Pageant", "Pageant")) { + MessageBox(NULL, "Pageant is already running", "Pageant Error", + MB_ICONERROR | MB_OK); + return 0; + } + instance = inst; if (!prev) { @@ -597,16 +617,28 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { /* * Process the command line and add RSA keys as listed on it. - * FIXME: we don't support spaces in filenames here. We should. */ { - char *p = cmdline; + char *p; + int inquotes = 0; + p = cmdline; while (*p) { while (*p && isspace(*p)) p++; if (*p && !isspace(*p)) { - char *q = p; - while (*p && !isspace(*p)) p++; - if (*p) *p++ = '\0'; + char *q = p, *pp = p; + while (*p && (inquotes || !isspace(*p))) + { + if (*p == '"') { + inquotes = !inquotes; + p++; + continue; + } + *pp++ = *p++; + } + if (*pp) { + if (*p) p++; + *pp++ = '\0'; + } add_keyfile(q); } }