X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/f5d2d791ca424c60b2bdfb1be346a17cc77e4276..1d4cb74b26f92ddb461550c03196a7bb5943f461:/mac/macstore.c diff --git a/mac/macstore.c b/mac/macstore.c index 9d3f25c6..66e82014 100644 --- a/mac/macstore.c +++ b/mac/macstore.c @@ -1,4 +1,4 @@ -/* $Id: macstore.c,v 1.8 2003/01/14 19:09:24 ben Exp $ */ +/* $Id: macstore.c,v 1.10 2003/01/18 16:10:21 ben Exp $ */ /* * macstore.c: Macintosh-specific impementation of the interface @@ -16,8 +16,10 @@ #include "putty.h" #include "storage.h" #include "mac.h" +#include "macresid.h" #define PUTTY_CREATOR FOUR_CHAR_CODE('pTTY') +#define INTERNAL_CREATOR FOUR_CHAR_CODE('pTTI') #define SESS_TYPE FOUR_CHAR_CODE('Sess') #define SEED_TYPE FOUR_CHAR_CODE('Seed') @@ -95,6 +97,25 @@ OSErr FSpGetDirID(FSSpec *f, long *idp, Boolean makeit) { return error; } +/* Copy a resource into the current resource file */ +static OSErr copy_resource(ResType restype, short resid) +{ + Handle h; + Str255 resname; + + fprintf(stderr, "getting resource %x, id %d\n", restype, resid); + h = GetResource(restype, resid); + if (h != NULL) { + GetResInfo(h, &resid, &restype, resname); + DetachResource(h); + AddResource(h, restype, resid, resname); + if (ResError() == noErr) + WriteResource(h); + } + fprintf(stderr, "ResError() == %d\n", ResError()); + return ResError(); +} + struct write_settings { int fd; FSSpec tmpfile; @@ -137,6 +158,10 @@ void *open_settings_w(char const *sessionname) { ws->fd = FSpOpenResFile(&ws->tmpfile, fsWrPerm); if (ws->fd == -1) {error = ResError(); goto out;} + /* Set up standard resources. Doesn't matter if these fail. */ + copy_resource('STR ', -16396); + copy_resource('TMPL', TMPL_Int); + return ws; out: @@ -390,12 +415,16 @@ void read_random_seed(noise_consumer_t consumer) FSClose(refnum); } +/* + * We don't bother with the usual FSpExchangeFiles dance here because + * it doesn't really matter if the old random seed gets lost. + */ void write_random_seed(void *data, int len) { - short puttyVRefNum, tmpVRefNum; - long puttyDirID, tmpDirID; + short puttyVRefNum; + long puttyDirID; OSErr error; - FSSpec dstfile, tmpfile; + FSSpec dstfile; short refnum; long count = len; @@ -404,36 +433,21 @@ void write_random_seed(void *data, int len) error = FSMakeFSSpec(puttyVRefNum, puttyDirID, "\pPuTTY Random Seed", &dstfile); - if (error != noErr && error != fnfErr) return; - - /* Create a temporary file to save to first. */ - error = FindFolder(puttyVRefNum, kTemporaryFolderType, kCreateFolder, - &tmpVRefNum, &tmpDirID); - if (error != noErr) return; - error = FSMakeFSSpec(tmpVRefNum, tmpDirID, "\pPuTTY Random Seed", - &tmpfile); - if (error != noErr && error != fnfErr) return; - if (error == noErr) { - error = FSpDelete(&tmpfile); - if (error != noErr) return; - } - error = FSpCreate(&tmpfile, PUTTY_CREATOR, SEED_TYPE, smRoman); - if (error != noErr) return; - - if (FSpOpenDF(&tmpfile, fsWrPerm, &refnum) != noErr) goto fail; - - if (FSWrite(refnum, &count, data) != noErr) goto fail2; - if (FSClose(refnum) != noErr) goto fail; - - if (FSpExchangeFiles(&tmpfile, &dstfile) != noErr) goto fail; - if (FSpDelete(&tmpfile) != noErr) return; + if (error == fnfErr) { + /* Set up standard resources */ + FSpCreateResFile(&dstfile, INTERNAL_CREATOR, SEED_TYPE, smRoman); + refnum = FSpOpenResFile(&dstfile, fsWrPerm); + if (ResError() == noErr) { + copy_resource('STR ', -16397); + CloseResFile(refnum); + } + } else if (error != noErr) return; + + if (FSpOpenDF(&dstfile, fsWrPerm, &refnum) != noErr) return; + FSWrite(refnum, &count, data); + FSClose(refnum); return; - - fail2: - FSClose(refnum); - fail: - FSpDelete(&tmpfile); } /*