1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-26 01:32:25 +00:00

Avoid launching a session from the Default Settings, even if they do

represent a launchable session, unless the user can be construed to
have really meant it. This means:
 - starting up PuTTY when the Default Settings are launchable still
   brings up the config box, and you have to hit Open to actually
   launch that session
 - double-clicking on Default Settings from the config box will load
   them but not launch them.
On the other hand:
 - explicitly loading the Default Settings on the command line using
   `-load' _does_ still launch them.

[originally from svn r7265]
This commit is contained in:
Simon Tatham 2007-02-10 17:02:41 +00:00
parent c4893477bd
commit 5d76e00dac
3 changed files with 16 additions and 7 deletions

View File

@ -383,7 +383,7 @@ struct sessionsaver_data {
*/ */
static int load_selected_session(struct sessionsaver_data *ssd, static int load_selected_session(struct sessionsaver_data *ssd,
char *savedsession, char *savedsession,
void *dlg, Config *cfg) void *dlg, Config *cfg, int *maybe_launch)
{ {
int i = dlg_listbox_index(ssd->listbox, dlg); int i = dlg_listbox_index(ssd->listbox, dlg);
int isdef; int isdef;
@ -397,8 +397,12 @@ static int load_selected_session(struct sessionsaver_data *ssd,
strncpy(savedsession, ssd->sesslist.sessions[i], strncpy(savedsession, ssd->sesslist.sessions[i],
SAVEDSESSION_LEN); SAVEDSESSION_LEN);
savedsession[SAVEDSESSION_LEN-1] = '\0'; savedsession[SAVEDSESSION_LEN-1] = '\0';
if (maybe_launch)
*maybe_launch = TRUE;
} else { } else {
savedsession[0] = '\0'; savedsession[0] = '\0';
if (maybe_launch)
*maybe_launch = FALSE;
} }
dlg_refresh(NULL, dlg); dlg_refresh(NULL, dlg);
/* Restore the selection, which might have been clobbered by /* Restore the selection, which might have been clobbered by
@ -464,6 +468,7 @@ static void sessionsaver_handler(union control *ctrl, void *dlg,
dlg_listbox_select(ssd->listbox, dlg, top); dlg_listbox_select(ssd->listbox, dlg, top);
} }
} else if (event == EVENT_ACTION) { } else if (event == EVENT_ACTION) {
int mbl = FALSE;
if (!ssd->midsession && if (!ssd->midsession &&
(ctrl == ssd->listbox || (ctrl == ssd->listbox ||
(ssd->loadbutton && ctrl == ssd->loadbutton))) { (ssd->loadbutton && ctrl == ssd->loadbutton))) {
@ -474,8 +479,8 @@ static void sessionsaver_handler(union control *ctrl, void *dlg,
* double-click on the list box _and_ that session * double-click on the list box _and_ that session
* contains a hostname. * contains a hostname.
*/ */
if (load_selected_session(ssd, savedsession, dlg, cfg) && if (load_selected_session(ssd, savedsession, dlg, cfg, &mbl) &&
(ctrl == ssd->listbox && cfg_launchable(cfg))) { (mbl && ctrl == ssd->listbox && cfg_launchable(cfg))) {
dlg_end(dlg, 1); /* it's all over, and succeeded */ dlg_end(dlg, 1); /* it's all over, and succeeded */
} }
} else if (ctrl == ssd->savebutton) { } else if (ctrl == ssd->savebutton) {
@ -533,12 +538,14 @@ static void sessionsaver_handler(union control *ctrl, void *dlg,
if (dlg_last_focused(ctrl, dlg) == ssd->listbox && if (dlg_last_focused(ctrl, dlg) == ssd->listbox &&
!cfg_launchable(cfg)) { !cfg_launchable(cfg)) {
Config cfg2; Config cfg2;
if (!load_selected_session(ssd, savedsession, dlg, &cfg2)) { int mbl = FALSE;
if (!load_selected_session(ssd, savedsession, dlg,
&cfg2, &mbl)) {
dlg_beep(dlg); dlg_beep(dlg);
return; return;
} }
/* If at this point we have a valid session, go! */ /* If at this point we have a valid session, go! */
if (*cfg2.host) { if (mbl && cfg_launchable(&cfg2)) {
*cfg = cfg2; /* structure copy */ *cfg = cfg2; /* structure copy */
cfg->remote_cmd_ptr = NULL; cfg->remote_cmd_ptr = NULL;
dlg_end(dlg, 1); dlg_end(dlg, 1);

View File

@ -3486,7 +3486,8 @@ int pt_main(int argc, char **argv)
cmdline_run_saved(&inst->cfg); cmdline_run_saved(&inst->cfg);
if (!cfg_launchable(&inst->cfg) && !cfgbox(&inst->cfg)) if ((!loaded_session || !cfg_launchable(&inst->cfg)) &&
!cfgbox(&inst->cfg))
exit(0); /* config box hit Cancel */ exit(0); /* config box hit Cancel */
} }

View File

@ -539,7 +539,8 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
cmdline_run_saved(&cfg); cmdline_run_saved(&cfg);
if (!cfg_launchable(&cfg) && !do_config()) { if ((!loaded_session || !cfg_launchable(&cfg)) &&
!do_config()) {
cleanup_exit(0); cleanup_exit(0);
} }