X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/6cb61a05b6157236bbea7b351cfc741eb6853605..b537dd42c1da03890c832e94a4f47369ca3d99af:/mac/macdlg.c?ds=sidebyside diff --git a/mac/macdlg.c b/mac/macdlg.c index a7c3c3f5..bf7c1e9d 100644 --- a/mac/macdlg.c +++ b/mac/macdlg.c @@ -1,4 +1,4 @@ -/* $Id: macdlg.c,v 1.1 2002/12/31 01:40:14 ben Exp $ */ +/* $Id: macdlg.c,v 1.4 2003/01/18 20:09:21 ben Exp $ */ /* * Copyright (c) 2002 Ben Harris * All rights reserved. @@ -31,6 +31,8 @@ #include #include +#include +#include #include #include @@ -38,6 +40,7 @@ #include "putty.h" #include "mac.h" #include "macresid.h" +#include "storage.h" void mac_newsession(void) { @@ -55,6 +58,71 @@ void mac_newsession(void) ShowWindow(s->settings_window); } +void mac_opensession(void) { + Session *s; + StandardFileReply sfr; + static const OSType sftypes[] = { 'Sess', 0, 0, 0 }; + void *sesshandle; + int i; + + s = smalloc(sizeof(*s)); + memset(s, 0, sizeof(*s)); + + StandardGetFile(NULL, 1, sftypes, &sfr); + if (!sfr.sfGood) goto fail; + + sesshandle = open_settings_r_fsp(&sfr.sfFile); + if (sesshandle == NULL) goto fail; + load_open_settings(sesshandle, TRUE, &s->cfg); + close_settings_r(sesshandle); + + /* + * Select protocol. This is farmed out into a table in a + * separate file to enable an ssh-free variant. + */ + s->back = NULL; + for (i = 0; backends[i].backend != NULL; i++) + if (backends[i].protocol == s->cfg.protocol) { + s->back = backends[i].backend; + break; + } + if (s->back == NULL) { + fatalbox("Unsupported protocol number found"); + } + mac_startsession(s); + return; + + fail: + sfree(s); + return; +} + +void mac_savesession(void) +{ + + /* Don't remember which file a session goes with yet, so... */ + mac_savesessionas(); +} + +void mac_savesessionas(void) +{ + Session *s = (Session *)GetWRefCon(FrontWindow()); + StandardFileReply sfr; + void *sesshandle; + + StandardPutFile("\pSave session as:", "\puntitled", &sfr); + if (!sfr.sfGood) return; + + if (!sfr.sfReplacing) { + FSpCreateResFile(&sfr.sfFile, PUTTY_CREATOR, SESS_TYPE, sfr.sfScript); + if (ResError() != noErr) return; /* XXX report error */ + } + sesshandle = open_settings_w_fsp(&sfr.sfFile); + if (sesshandle == NULL) return; /* XXX report error */ + save_open_settings(sesshandle, TRUE, &s->cfg); + close_settings_w(sesshandle); +} + void mac_activatedlg(WindowPtr window, EventRecord *event) { DialogItemType itemtype; @@ -74,7 +142,7 @@ void mac_clickdlg(WindowPtr window, EventRecord *event) short item; Session *s = (Session *)GetWRefCon(window); - if (DialogSelect(event, &(DialogPtr)window, &item)) + if (DialogSelect(event, &window, &item)) switch (item) { case wiSettingsOpen: CloseWindow(window);