MyUtils.c

/*
    File:       MySGStuff.c
    
    Contains:   Sequence grabber code.
 
    Written by: John Wang
 
    Copyright:  © 1994 by Apple Computer, Inc., all rights reserved.
 
    Change History (most recent first):
 
        <1>     04/04/94    JW      Created.
 
    To Do:
    
*/
 
#ifdef THINK_C
#define     applec
#endif
#include    "MyHeaders"
/*
#include    <Types.h>
#include    <Memory.h>
#include    <QuickDraw.h>
#include    <Palettes.h>
#include    <QDOffscreen.h>
#include    <Errors.h>
#include    <Fonts.h>
#include    <Dialogs.h>
#include    <Windows.h>
#include    <Menus.h>
#include    <Events.h>
#include    <Desk.h>
#include    <DiskInit.h>
#include    <OSUtils.h>
#include    <Resources.h>
#include    <ToolUtils.h>
#include    <AppleEvents.h>
#include    <EPPC.h>
#include    <GestaltEqu.h>
#include    <Processes.h>
#include    <Balloons.h>
#include    <Aliases.h>
#include    <MixedMode.h>
#include    <Scrap.h>
#include    <LowMem.h>
*/
#include    <Folders.h>
 
#include    "MyCaptureAppShell.h"
#include    "MySGStuff.h"
#include    "MyUtils.h"
 
/* ------------------------------------------------------------------------- */
 
//  Show Alert.  Then, return true is err != noErr.
void ReportWarning(Str255 procStr, long err)
{
    Str255  myStr;
    
    NumToString(err, myStr);
    ParamText("\pWarning!", procStr, err ? myStr : nil, nil);
    Alert(kALERT_ERROR, nil);
}
 
void ReportFatal(Str255 procStr, long err)
{
    Str255  myStr;
    
    NumToString(err, myStr);
    ParamText("\pFatal Error!", procStr, err ? myStr : nil, nil);
    Alert(kALERT_ERROR, nil);
    ExitToShell();
}
 
void GetGlobalWindow(WindowPtr theWindow, Rect *windowRect)
{
    //  Get the windowRect in global coordinates.
    *windowRect = theWindow->portRect;
    LocalToGlobal(&topLeft(*windowRect));
    LocalToGlobal(&botRight(*windowRect));
}
 
/* ------------------------------------------------------------------------- */
 
//  readPreferencesFile will return refnum = -1 if not found.
short readPreferencesFile()
{
    short           myVRefNum;
    long            myDirID;
    StringHandle    prefsName;
    short           myRefNum;
    
    if (FindFolder(kOnSystemDisk, kPreferencesFolderType, true, &myVRefNum, &myDirID))
        return(-1);
    
    prefsName = GetString(STR_PREFSNAME);
    myRefNum = HOpenResFile(myVRefNum, myDirID, (unsigned char *) *prefsName, fsRdPerm);
    ReleaseResource((Handle) prefsName);
    
    return(myRefNum);
}
 
//  writePreferencesFile returns -1 if preferences file can't be opened.
short writePreferencesFile()
{
    short           myVRefNum;
    long            myDirID;
    StringHandle    prefsName;
    short           myRefNum;
    
    if (FindFolder(kOnSystemDisk, kPreferencesFolderType, true, &myVRefNum, &myDirID))
        return(-1);
    
    prefsName = GetString(STR_PREFSNAME);
    HDelete(myVRefNum, myDirID, (unsigned char *) *prefsName);
    HCreateResFile(myVRefNum, myDirID, (unsigned char *) *prefsName);
    myRefNum = HOpenResFile(myVRefNum, myDirID, (unsigned char *) *prefsName, fsRdWrPerm);
    ReleaseResource((Handle) prefsName);
    
    return(myRefNum);
}
 
void closePreferencesFile(short myRefNum)
{
    UpdateResFile(myRefNum);
    CloseResFile(myRefNum);
}