FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

PG PRO

Handle a separate preferences file


FB/PG and a Separate Preferences File
11/6/99 gbeckman@pggp.com

The examples below are intended to accomplish the following:

1) Allow a PG project to use an external file for saving PG related and other resources.

2) Stop a PG application from writing to and changing its own resources.

3) Stop the PG application modification date from changing every time the application runs.

4) Allow an application to be shared as in a Network Version and still allow clients to retain the benifits of PG managed window, etc.

The goal, in addition to the above, was to have the application create the preferences file on the fly, so that if it became corrupted the user could toss it and re-launch.

In developing this modified PG project, I suggest you consider the following.

1) Even though your application is going to create the Preferences File on the fly, but a blank on in your installer, or create a resource string that identifies its version. This way, you will never have a newer (or older) app trying to use window information that does not match the running application.

2) You rename Runtime.INCL in such a way that reminds you. This way, if you ever have to re-build the PG portion of the project, you will remember that you need a Runtime with the special changes made.

We are going to make changes in 4 areas:

your.GLBL
One of your INCLs
Runtime.INCL
your.MAIN


and if you already use your Help File for resources

HSF Util.FLTR
===============================================================
In your.GLBL:

Staz says, it is necessary to make real sure the preferences file is closed at the end of a run. He also says if your attempt to point the application to another set of resources failed, and you closed the file, you would be closing the app resource file which would be really bad.

I made the following global in my PGGP.GLBL file:
DIM gPrefFlag

===============================================================
In any.INCL file:

We need to set gResRef, a PG global, to a new file.

In the example below, my app was PGGP and the app. creator type is PGGP.
This routine needs to run once, before any windows are built by your application. I run it in:

By stealing major hunks of the HFS util.FLTR's LOCAL FN openHelpFile, I came up with the following:
LOCAL
DIM resRef
DIM prefName$,t$
DIM oldFldr,vRef
DIM oldResRefNum%

LOCAL FN yourPrefFile
oldResRefNum% = FN CURRESFILE 'this is the very first thing to do
  '---------------------------------------
  ' Create or open the application's own preferences
  ' file.
  '---------------------------------------
  
  prefName$="PGGP Preferences"  'you choose the name you like
  
  oldFldr = FOLDER("",0)
  vRef    = FOLDER("Preferences",SYSTEM(_sysVol))
  
=====> see if it is there already <==========
  resRef = USR OPENRFPERM(prefName$,vRef,_fsRdWrPerm)
  
  oldFldr = FOLDER("",oldFldr)    'put things back
  gPrefFlag=0                            ' set the flag
=====> if it is there we set gResRef and the Flag and get out <======
  LONG IF resRef > 0
    gResRef=resRef
    gPrefFlag%=resRef
    CALL USERESFILE(gResRef)
    EXIT FN
  END IF
  
======> If it is not there, we make one <==========
======> Set file type for Pref file...please don't use mine <=========
======> Creator type must be 4 letters...no more...no less <=======
  t$       = "PREFPGGP"  'PREF+your creator type
  DEF OPEN = t$
  
'======> Get Aimed toward the right place <========
  oldFldr = FOLDER("",0)
  vRef    = FOLDER("Preferences",SYSTEM(_sysVol))
'======> Create the data fork and its icon <======
  OPEN "R",#1,prefName$    
  CLOSE #1
  
'=====> Give it a resource fork <========
  CALL CREATERESFILE(prefName$)
  
  oldFldr = FOLDER("",oldFldr)
'=====> Put things back <=======
'=====> And try to open it again <===
  resRef = USR OPENRFPERM(prefName$,vRef,_fsRdWrPerm)
  LONG IF resRef > 0
    gPrefFlag%=resRef
    gResRef=resRef
    CALL USERESFILE(gResRef)  'don't know if this is necessary???
  END IF
 CALL USERESFILE(oldResRefNum%) 'this is the very last thing to do
END FN
What you should have, now is a file in the preferences folder called PGGP Preferences with a resource fork, ready to receive your resources.

===============================================================
In the Runtime.INCL:

In the finder, I renamed mine Runtime1.INCL and made this change in the Main:

Changed
INCLUDE "Runtime.INCL"
to
INCLUDE "Runtime1.INCL"
Open Runtime1.INCL and find:
LOCAL FN pGputWnd(resID,recordPtr&)
Make the following changes:

Add a ' to the following (I suggest Remarking it so you remember what you are doing here.)
      'CALL CHANGEDRESOURCE(resHndl&)
and add this line...
      FN pGreplaceRes(resHndl&,_"pG3w",resID,"")
and save.

What you just did was to make it possible for PG to start a new resource. Without the change, PG would look in the new preferences file and not find a _"pG3w" and give up on saving the window information there. (Staz said that.)

================================================================
In your.Main:

in
CASE _mainStart
add
LOCAL FN PGGPPrefFile
and in
CASE _mainShutDown
 
add
IF gPrefFlag<>0 then CALL CLOSERESFILE(gResRef)
=================================================================
HFS util.FLTR

If you are already using your help file as a repository for resources, Find:
LOCAL FN openHelpFile
 
Locate two instances of:
      gHelpResRef = resRef
      gResRef=resRef
 
and make them
      gHelpResRef = resRef
      'gResRef=resRef
 
What you did, was to stop using gHelpResRef to set gResRef, PGs resource key.

Use ResEdit, to clean out all extra resources from your help file. All you need is:

TOPk
and
STR#
If you throw those two away, you will kill your help file.

================================================================
After you have debugged and have things running cleanly, you can compile your app and open it with ResEdit. In the file menu, go to GetInfo For and click resources locked. Save, and you are ready to play around. (I know some use Resourcer, but I don't know the exact steps to accomplish the above.)
Please remember, 1) I am no resource expert and 2) this is fairly new stuff, at least to me. If you find problems, or see places that need to be tightened up, please feel free to comment.

Last, thanks to Staz for the help with this. He is flat sharp on resources.

George Beckman