-/* $Id: macdlg.c,v 1.2 2003/01/01 11:45:43 ben Exp $ */
+/* $Id: macdlg.c,v 1.5 2003/01/18 20:52:59 ben Exp $ */
/*
* Copyright (c) 2002 Ben Harris
* All rights reserved.
#include <MacTypes.h>
#include <Dialogs.h>
+#include <Resources.h>
+#include <StandardFile.h>
#include <Windows.h>
+#include <assert.h>
#include <string.h>
#include "putty.h"
#include "mac.h"
#include "macresid.h"
+#include "storage.h"
void mac_newsession(void)
{
memset(s, 0, sizeof(*s));
do_defaults(NULL, &s->cfg);
s->back = &loop_backend;
+ s->hasfile = FALSE;
s->settings_window = GetNewDialog(wSettings, NULL, (WindowPtr)-1);
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);
+ if (sfr.sfFlags & kIsStationery)
+ s->hasfile = FALSE;
+ else {
+ s->hasfile = TRUE;
+ s->savefile = sfr.sfFile;
+ }
+
+ /*
+ * 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)
+{
+ Session *s = (Session *)GetWRefCon(FrontWindow());
+ void *sesshandle;
+
+ assert(s->hasfile);
+ sesshandle = open_settings_w_fsp(&s->savefile);
+ if (sesshandle == NULL) return; /* XXX report error */
+ save_open_settings(sesshandle, TRUE, &s->cfg);
+ close_settings_w(sesshandle);
+}
+
+void mac_savesessionas(void)
+{
+ Session *s = (Session *)GetWRefCon(FrontWindow());
+ StandardFileReply sfr;
+ void *sesshandle;
+
+ StandardPutFile("\pSave session as:",
+ s->hasfile ? s->savefile.name : "\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);
+ s->hasfile = TRUE;
+ s->savefile = sfr.sfFile;
+}
+
void mac_activatedlg(WindowPtr window, EventRecord *event)
{
DialogItemType itemtype;