mirror of
https://github.com/Blzut3/Wolf3D-Mac.git
synced 2024-11-28 15:50:19 +00:00
1 line
7.1 KiB
C
1 line
7.1 KiB
C
|
#include <Folders.h>
#include <Gestalt.h>
#include <Processes.h>
#include "Wolfdef.h"
#include <String.h>
#include "prefs.h"
typedef struct {
Byte fileName[34]; /* Enough space for filename */
OSType creator; /* Creator TYPE */
OSType fileType; /* File type */
OSType resType; /* Resource type */
short resID; /* Open resource file ID */
} PrefsInfo;
static PrefsInfo prefsInfo; /* My internal prefs record */
static Boolean prefsInited = FALSE; /* Is the struct valid? */
/**********************************
I miss the Apple IIgs where all you need to set the prefs directory
was to pass a filename of "@:Prefs file" and it will automatically place
the prefs file in either the proper Network folder or system prefs folder...
Instead I have to do this bullshit to scan the volumes to find the prefs
folder and volume...
If the file was not found, then create it.
return TRUE if the file was found and could not be created
**********************************/
static Boolean FindPrefsFile(short *prefVRefNum, long *prefDirID)
{
OSErr theErr;
long response;
CInfoPBRec infoPB;
if (!prefsInited) { /* Only look if the prefs structure is valid */
return FALSE; /* Exit NOW! */
}
/* First, try it the easy way... */
if ( !Gestalt(gestaltFindFolderAttr, &response) && /* Is the easy way available? */
( (1<<gestaltFindFolderPresent) & response)) {
/* Call the OS to do the dirty work */
theErr = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
prefVRefNum, prefDirID);
/* OK, try it the hard way... :( */
} else {
SysEnvRec theSysEnv;
StringPtr prefFolderName = "\pPreferences";
/* yeachh -- we have to do it all by hand! */
if (SysEnvirons(1, &theSysEnv)) { /* Is the system disk present? */
return FALSE; /* Forget it! */
}
*prefVRefNum = theSysEnv.sysVRefNum; /* Save off the boot volume ID */
/* check whether Preferences folder already exists */
infoPB.hFileInfo.ioCompletion = 0; /* Wait for completion */
infoPB.hFileInfo.ioNamePtr = prefFolderName; /* Get folder name */
infoPB.hFileInfo.ioVRefNum = *prefVRefNum; /* Pass the volume # */
infoPB.hFileInfo.ioFDirIndex = 0; /* Scan directories */
infoPB.hFileInfo.ioDirID = 0; /* Init dir id */
theErr = PBGetCatInfo(&infoPB, FALSE); /* Get the catalog info */
if (!theErr) {
*prefDirID = infoPB.hFileInfo.ioDirID; /* Return the folder id */
} else if (theErr == fnfErr) { /* Preferences doesn't already exist */
HParamBlockRec dirPB;
/* create "Preferences" folder */
dirPB.fileParam.ioCompletion = 0;
dirPB.fileParam.ioVRefNum = *prefVRefNum;
dirPB.fileParam.ioNamePtr = prefFolderName;
dirPB.fileParam.ioDirID = 0;
theErr = PBDirCreate(&dirPB, FALSE); /* Create the folder */
if (!theErr) {
*prefDirID = dirPB.fileParam.ioDirID; /* Save the ID */
}
}
}
/* if we make it here OK, create Preferences file if necessary */
if (!theErr) {
infoPB.hFileInfo.ioCompletion = 0;
infoPB.hFileInfo.ioNamePtr = prefsInfo.fileName;
infoPB.hFileInfo.ioVRefNum = *prefVRefNum;
infoPB.hFileInfo.ioFDirIndex = 0;
infoPB.hFileInfo.ioDirID = *prefDirID;
theErr = PBGetCatInfo(&infoPB, FALSE); /* Get the file info */
if (theErr == fnfErr) { /* Not present? */
theErr = HCreate(*prefVRefNum, *prefDirID, prefsInfo.fileName,
prefsInfo.creator, prefsInfo.fileType);
if (!theErr) {
HCreateResFile(*prefVRefNum, *prefDirID, prefsInfo.fileName);
theErr = ResError(); /* Was there an error? */
}
}
}
return (!theErr);
}
/**********************************
Init the record for the "Prefs" file
All this does is preset the prefsfile structure
for the filename of the prefs file.
**********************************/
void InitPrefsFile(OSType creator,Byte *PrefsName)
{
Word FLen;
FLen = strlen((char *)PrefsName); /* How long is the string? */
prefsInfo.fileName[0] = FLen; /* Make a PASCAL string */
BlockMove(PrefsName,&prefsInfo.fileName[1],FLen); /* Copy the bulk */
prefsInfo.creator
|