X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/58c840dcc1810bfc5a7334fe29058d2b2c97cdaf..61f62bb301d0b6d49d1fea71513eb051a901e1b1:/windows/window.c diff --git a/windows/window.c b/windows/window.c index f654d2ad..033cfa5d 100644 --- a/windows/window.c +++ b/windows/window.c @@ -219,12 +219,7 @@ static void start_backend(void) * Select protocol. This is farmed out into a table in a * separate file to enable an ssh-free variant. */ - back = NULL; - for (i = 0; backends[i].backend != NULL; i++) - if (backends[i].protocol == cfg.protocol) { - back = backends[i].backend; - break; - } + back = backend_from_proto(cfg.protocol); if (back == NULL) { char *str = dupprintf("%s Internal Error", appname); MessageBox(NULL, "Unsupported protocol number found", @@ -361,17 +356,18 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { char *p; int got_host = 0; + /* By default, we bring up the config dialog, rather than launching + * a session. This gets set to TRUE if something happens to change + * that (e.g., a hostname is specified on the command-line). */ + int allow_launch = FALSE; default_protocol = be_default_protocol; /* Find the appropriate default port. */ { - int i; + Backend *b = backend_from_proto(default_protocol); default_port = 0; /* illegal */ - for (i = 0; backends[i].backend != NULL; i++) - if (backends[i].protocol == default_protocol) { - default_port = backends[i].backend->default_port; - break; - } + if (b) + default_port = b->default_port; } cfg.logtype = LGTYP_NONE; @@ -397,7 +393,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) if (!cfg_launchable(&cfg) && !do_config()) { cleanup_exit(0); } - loaded_session = TRUE; /* allow it to be launched directly */ + allow_launch = TRUE; /* allow it to be launched directly */ } else if (*p == '&') { /* * An initial & means we've been given a command line @@ -413,10 +409,10 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) cfg = *cp; UnmapViewOfFile(cp); CloseHandle(filemap); - loaded_session = TRUE; } else if (!do_config()) { cleanup_exit(0); } + allow_launch = TRUE; } else { /* * Otherwise, break up the command line and deal with @@ -541,8 +537,10 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) cmdline_run_saved(&cfg); - if ((!loaded_session || !cfg_launchable(&cfg)) && - !do_config()) { + if (loaded_session || got_host) + allow_launch = TRUE; + + if ((!allow_launch || !cfg_launchable(&cfg)) && !do_config()) { cleanup_exit(0); } @@ -599,15 +597,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) } } - /* Check for invalid Port number (i.e. zero) */ - if (cfg.port == 0) { - char *str = dupprintf("%s Internal Error", appname); - MessageBox(NULL, "Invalid Port Number", - str, MB_OK | MB_ICONEXCLAMATION); - sfree(str); - cleanup_exit(1); - } - if (!prev) { wndclass.style = 0; wndclass.lpfnWndProc = WndProc;