home *** CD-ROM | disk | FTP | other *** search
- /*
- * init.c - initialization routines
- */
- #include "RevRdist.h"
- #include <string.h>
- #include <TransSkelProto.h>
- #include <TransDisplayProto.h>
-
- extern unsigned char ApplScratch[12] : 0xa78;
-
-
-
-
- /*
- *=========================================================================
- * getSet - make sure we have enough information to proceed
- * returns: 0 if all set
- * <> 0 if something missing
- * Quit may or may not be set
- *=========================================================================
- */
-
- OSErr
- getSet()
- {
- OSErr error;
- cnode_t *cn; /* ptr to fi->f_info */
- file_info_t *fi; /* temp ptr into File_list[] */
- StringHandle sh; /* temp string handle */
- Integer vol; /* volume reference temp */
- HParamBlockRec hpb; /* for GetVInfo, etc calls */
- Str255 s; /* string temp */
-
- fi = &File_list[FL_PREF];
- cn = &fi->f_info;
- if (fi->f_set)
- {
- /*
- * If prefs file from launch, fetch values from it.
- * The file had better be there.
- */
- if (fi->f_launch)
- {
- fi->f_launch = false; /* get only one shot */
- error = prefFFetch (fi);
- if (error)
- {
- sh = fi->f_path;
- HLock ((Handle) sh);
- panic (true, E_PREFS, *sh, nil);
- HUnlock ((Handle) sh);
- return error;
- }
- prefMerge (P_WORK, true);
- }
- }
- /*
- * Figure out where the server master folder is.
- * Its name (absolute path) is a preferences resource.
- * (If the name doesn't include a ':', add one to make sure it
- * is treated as an absolute path.)
- */
- sh = Prefs[P_WORK].p[PS_MASTF];
- if (!sh)
- {
- panic (true, E_NOSERVER, nil);
- return E_NOSERVER;
- }
- fi = &File_list[FL_MAST];
- cn = &fi->f_info;
- COPYPS (*sh, s);
- error = getInfoByPath (s, fi);
- if (error)
- {
- ClueID = error;
- if (error == fnfErr || error == nsvErr)
- panic (true, E_NOSERVER, s, nil);
- else
- panic (true, E_SYS, Clue0, (SP) "\pgetInfoByPath", nil);
- }
- /*
- * We must have both see files and see folders access to the master
- */
- if (cn->access & 0x03)
- {
- panic (true, E_NOACCESS, s, nil);
- error = nsvErr;
- }
- if (error || Quit)
- return error;
- ServerVol = fi->f_vol;
- ServerRoot = fi->f_info.dirID;
- /*
- * Set master folder as default volume
- */
- error = SetVol (s, ServerVol);
- /*
- * If we don't have a config file yet, locate it via preferences
- */
- fi = &File_list[FL_DIST];
- cn = &fi->f_info;
- if (! fi->f_set )
- {
- sh = Prefs[P_WORK].p[PS_DISTF];
- if (!sh)
- {
- panic (true, E_DISTF, "", nil);
- return fnfErr;
- }
- HLock ((Handle) sh);
- fi->f_vol = 0;
- error = getInfoByPath (*sh, fi);
- if (error)
- {
- panic (true, E_DISTF, *sh, nil);
- HUnlock ((Handle) sh);
- return error;
- }
- HUnlock ((Handle) sh);
- }
- /*
- * okay, now find the volume to update.
- * It is the volume containing the preferences file, if present,
- * else the volume containing a distribution file used to launch us,
- * else the volume with the the blessed folder.
- */
- if (File_list[FL_PREF].f_set)
- vol = File_list[FL_PREF].f_vol;
- else if (File_list[FL_DIST].f_launch)
- vol = File_list[FL_DIST].f_vol;
- else
- vol = BlessedWD;
- fi = &File_list[FL_ROOT];
- fi->f_ref = vol;
- fi->f_info.ctype = C_FOLDER;
- s[0] = 0;
- error = getInfoByPath (s, fi);
- if (error)
- {
- panic (true, E_NOVOL, nil);
- return E_NOVOL;
- }
- ClientVol = fi->f_vol;
- ClientRoot = ROOTDIRID;
- /*
- * Make sure that client is HFS volume
- */
- ZERO (hpb);
- s[0] = 0;
- hpb.volumeParam.ioNamePtr = s;
- hpb.volumeParam.ioVRefNum = ClientVol;
- PBHGetVInfo (&hpb, false);
- if (hpb.volumeParam.ioVSigWord == 0xD2D7)
- {
- panic (true, E_MFS, CurApName, s, nil);
- return E_MFS;
- }
- ClientSp = (unsigned long)(unsigned)hpb.volumeParam.ioVFrBlk
- * (unsigned)hpb.volumeParam.ioVAlBlkSiz;
- /*
- * Check if the client volume is writeable
- * If not, warn and set ListOnly
- */
- if (!(Flags & DB_LISTONLY) && (hpb.volumeParam.ioVAtrb & 0x8080))
- {
- warning (E_LISTONLY, s, nil);
- Flags |= DB_LISTONLY;
- }
- /*
- * Create/access junk folder.
- * If fails, just warn about it.
- */
- error = makeJunk ();
- return error;
- }
-
-
- /*
- *=========================================================================
- * initGlobals - set up the (too many) global variables
- * exit: Quit = false if initialization succeeded
- * Quit = true if application must quit immediately
- *=========================================================================
- */
- void
- initGlobals ()
- {
- OSErr error;
- Integer fcount, fmsg;
- file_info_t * fi; /* ptr into File_list[] */
- Handle h; /* temp handle */
- Integer i; /* temp index */
- long * lp; /* ptr into ApplScratch */
- StringHandle sh; /* temp string handle */
- SysEnvRec theWorld; /* environment info */
- WindowPtr w; /* working window pointer */
-
- HighValue[0] = 3;
- HighValue[1] = HighValue[2] = HighValue[3] = 255;
- Clue0 = (SP) "\pinitGlobals";
- Quit = false;
- Ap_refNum = CurResFile ();
- error = SysEnvirons (1, &theWorld);
- if (error)
- {
- Quit = true;
- return;
- }
- BlessedWD = theWorld.sysVRefNum;
- /*
- * Set processing flag bits
- * Check ApplScratch for our signature to see if
- * we are running automatically at boot time.
- */
- Flags = 0;
- h = Get1Resource (TYPE_LONG, FLAG_PARM);
- if (h)
- {
- Flags = **((long **)h);
- ReleaseResource (h);
- }
- lp = (long *)(ApplScratch + 8);
- if (lp[0] == CREATOR)
- {
- Flags |= DB_STARTUP;
- lp[0] = 0;
- }
- if (((Flags & DB_DIALOG) || Button ()) && (Flags & DB_LOCKED) == 0)
- setDebug ();
- if (Quit)
- return;
- ActivityWind = GetNewDWindow (RSRC_BASE+WIND_ACTIVITY, (WindowPtr) -1L);
- ErrorWind = GetNewDWindow (RSRC_BASE+WIND_ERRORS, (WindowPtr) -1L);
- SetDWindow (ActivityWind);
- /*
- * Make sure we are running under HFS
- */
- if (FSFCBLen < 0)
- {
- panic (true, E_HFS, CurApName, nil);
- return;
- }
- /*
- * Get junking renaming suffix
- */
- h = GetResource ('STR ', STR_JUNKSUF);
- if (!h || **h > sizeof (Junksuf) - 1 || **h < 2)
- {
- panic (true, E_BADJUNKF, nil);
- return;
- }
- COPYPS (*h, Junksuf);
- ReleaseResource (h);
- /*
- * Get name for anonymous documents
- */
- h = GetResource ('STR ', STR_UNTITLED);
- if (!h)
- {
- error = ResError ();
- goto sysdie;
- }
- Untitled = (StringHandle) h;
- /*
- * Allocate File_list and fill parts of it in, including
- * info about Application
- * info about any files passed as parameters
- */
- File_list = (file_info_t *) NewPtr (FL_MAX * sizeof (* File_list));
- if (!File_list)
- goto nomem;
- setmem ((char *)File_list, FL_MAX * sizeof (* File_list), 0);
-
- fi = &File_list[FL_APPL];
- fi->f_ref = CurResFile ();
- fi->f_info.ctype = C_FILE;
- if (error = getInfoByPath ((SP)"\p", fi))
- goto sysdie;
- fi->f_launch = true;
-
- CountAppFiles (&fmsg, &fcount);
- if (fmsg == 1 && fcount > 0)
- {
- panic (false, E_NOPRINT, nil);
- if (Quit)
- return;
- }
-
- Ap_file.fType = 0;
- for (i = 1; i <= fcount; i++)
- {
- int j;
-
- GetAppFiles (i, &Ap_file);
- switch (Ap_file.fType)
- {
- case TYPE_PREF: j = FL_PREF; break;
- case TYPE_CONT: j = FL_DIST; break;
- case 'INIT': j = -1; Flags |= DB_STARTUP; break;
- default: j = -1; break;
- }
- if (j >= 0)
- {
- fi = &File_list[j];
- fi->f_vol = Ap_file.vRefNum;
- error = getInfoByPath (Ap_file.fName, fi);
- if (error == 0)
- fi->f_launch = true;
- }
- ClrAppFiles (i);
- }
- /*
- * Initialize preferences from application
- */
- setmem ((char *)&Prefs[0], 2 * sizeof (prefs_t), 0);
- if (prefFetch (File_list[FL_APPL].f_ref) == 0)
- prefMerge (P_WORK, false);
- /*
- * If we haven't located a preferences file yet, try finding the one
- * given by the preferences string within the application.
- * It's not a problem if we cannot find the file.
- */
- fi = &File_list[FL_PREF];
- if (!fi->f_set)
- {
- sh = (StringHandle) GetResource ('STR ', STR_PREFS);
- if (!sh)
- {
- panic (true, E_SYS, Clue0,
- (SP)"\pGetResource", (SP)"\ppref file name");
- return;
- }
- HLock ((Handle) sh);
- fi->f_vol = 0;
- error = getInfoByPath (*sh, fi);
- if (error == 0)
- {
- error = prefFFetch (fi);
- if (error == 0)
- prefMerge (P_WORK, true);
- Prefs[P_WORK].p_modified = false;
- }
- if (error)
- {
- /*
- * If not startup, tell about no prefs and see if we
- * should continue.
- */
- if ((Flags & DB_STARTUP) == 0)
- panic (false, E_PREFS, *sh, nil);
- }
- HUnlock ((Handle) sh);
- ReleaseResource ((Handle) sh);
- if (Quit)
- return;
- }
-
- return;
-
- sysdie:
- ClueID = error;
- panic (true, E_SYS, Clue0, nil);
- Quit = true;
- return;
-
- nomem:
- SysBeep (5);
- Quit = true;
- return;
- }
-
-
- /*
- *=========================================================================
- * tidyUp () - do final cleanup before exiting
- *=========================================================================
- */
- void
- tidyUp ()
- {
- if (Deskrefnum != -1)
- CloseResFile (Deskrefnum);
- }
-