TweetFollow Us on Twitter

HFS Transfer DA
Volume Number:4
Issue Number:10
Column Tag:Programmer's Workshop

HFS Transfer DA

By Clifford Story, Jacksonville, FL

Transfer DA

The Transfer DA is a small desk accessory that adds a Transfer menu to any application that supports desk accessories.

When Apple killed the Minifinder, my work habits were shattered. I tried Oasis, a Finder substitute, for a while but I didn’t like the way the working directory was changed by launching a program; that is, if I launched, say, Macwrite, and opened a file, the sfget dialog came up showing the directory that contained Macwrite, rather than the one I had been working in. I had to navigate through folders to return to my work files.

Transfer solves that problem. Now, I work on the desktop but when I want to switch from one application to another, I use Transfer. The working directory is unaffected, and I skip the Finder.

This DA illustrates some interesting programming techniques: it is a segmented DA; it does an HFS search of an entire hard disk; it uses the iaznotify hook; and it creates resources with TML Pascal (a subject which came up in the May Mac Tutor letters column).

How the DA Works

When the DA is launched for the first time, it starts at the root of the disk which contains the System folder, and does an HFS catalog of the entire disk. It finds each application on the disk, and stores the name and directory id in a special resource FILE called “Transfer data”, in the System folder. Henceforth, it uses this file to build the menu (the HFS catalog takes a little time - about 30 seconds on my 20 meg hard disk - so you wouldn’t want to go through it every time).

When an application is selected from the Transfer menu, the applications’s name and directory id are copied into the DA’s global data record, and the address of a special launch routine is installed in the “iaznotify” low-memory global. The transfer may be immediate or delayed; in the first case, the DA will call “ExitToShell”; in the second, it will wait for the application to quit normally.

When the application quits, the Mac will prepare to launch the next application (usually the Finder). As one of the last steps in this process, it will call “InitApplZone” to initialize the heap. This trap will, in turn, call the routine whose address is stored in “iaznotify” - the DA’s launch routine. This routine simply writes the name of the desired application to “curappname” (another low-memory global), and sets the directory to the proper directory. The Mac will then go ahead and launch the application. Sort of a cowbird launch, you might say!

DA Segmentation

This is a small DA, a bit over 6K. so why is it segmented? Am I just showing off?

Before “InitApplZone” calls the launch procedure, the Mac closes all resource files. That means that if the launch procedure is in a resource (e.g., the DRVR resource), it will be left in a free block. I don’t feel very secure when executing code in a free block! The solution is to detach the resource; the block will remain allocated until “InitApplZone” actually cleans up the heap - which happens after it calls the launch routine.

But if the launch routine is part of the DRVR resource, this means detaching the DRVR. If we do that, we’ll never know about menu selections, since the desk Manager needs a DRVR resource to pass DA events to. So the launch routine has to be in a separate segment.

The launch routine is in a PACK resource. The DRVR’s “open” routine loads and locks the PACK, and records its address. When it wants to call a routine from the PACK, it puts a routine selector into register D0 and jumps to the PACK. At the top of the PACK is a jump table that branches to the routine corresponding to the selector.

There are other ways to segment a DA; this is just the way I did this one.

Creating Resources with TML Pascal

Since it came up in the May letters column, let me say a few words on this topic. It’s really simple, once you know the (undocumented) trick. It’s all in the link control file.

For example, here is a link control file to create an LDEF:

 !fastlist
 /codetype LDEF 1001 ‘Fast List’ 32
 list
 pas$library
 macintfglue
 /end

The first line is the linker’s start point - the name of the

main routine. The second line defines the resource type. This will be an LDEF, resource id 1001, named “Fast List”, purgeable. The next three lines are the object files to link, in the order you want them to be linked. And the final line means just what it says.

The code itself should be compiled as a unit, and most resource types will require that the main routine appear at the very top of the resource.

The two resources in this program are linked a bit differently, the DRVR resource because the resource definition requires a DA header at the top, and the PACK resource because I want a jump table at the top. The fact that I left out the first line and got away with it suggests that it may not be necessary.

Using the DA

I have tested this DA with every application on my hard disk (at the time I wrote it). A number of applications require the delayed transfer; for example, any program that uses scratch files. I found only one that would not work at all. Can you guess? That’s right - Microsoft Word.

Transfer vs. Multifinder

I leave as an exercise for the reader the problem of making this DA work with the Multifinder. A more fruitful project might be converting the DA to an FKEY.

;***************************************
;
;types.asm
;--------
;
;(c) 1987, 1988 Attic Software
;
;record formats for Transfer
;
;***************************************

;***************************************
;wrecord
;***************************************

 WRthemenuequ    0; MenuHandle
 WRresfactorequ    4; integer
 WRsysdir equ    6; long
 WRpackaddr equ   10; Ptr
 WRlaunchpath  equ  14; long
 WRlaunchaddr  equ  18; long
 WRiazaddrequ   22; long
 WRtheevent equ   26
 ; EventRecord
 WRthenameequ   42; Str255
 WRtheblock equ  298; hfs block

;***************************************


(***************************************     
types.pas
--------
 
(c) 1987, 1988 Attic Software
 
Pascal declarations for Transfer
 
***************************************)

unit types;

(**************************************)

interface

(**************************************)

uses macintf, hfs;

(**************************************)

type
 
 logical= boolean;
 long   = longint;
 
 shortpointer    = ^integer;
 longpointer=  ^long;

(***************************************
 
Program constants consist of (1) DA message types (most of which are 
not used in Transfer); (2) low-memory globals; and (3) resource ids.
 
***************************************)

const
 
 accEvent = 64;
 accRun = 65;
 accCursor= 66;
 accMenu= 67;
 accUndo= 68;
 accCut = 70;
 accCopy= 71;
 accPaste = 72;
 accClear = 73;
 goodbyekiss=  -1;
 
 curappname =  $910;
 erik   = $4552494B;
 findername =  $2E0;
 iaznotify= $33C;
 sysmap = $A58;
 
 menunum= 1001;
 aboutitem= 1;
 builditem= 2;
 finderitem =  4;
 
 errordialog=  1001;
 aboutdialog=  1002;
 builddialog=  1003;
 delaydialog=  1004;
 
 packnum= 1001;
 stringnum= 1001;
 
 datastart= 1000;
 
(***************************************     
A “deskrecord” is simply an application’s name and directory.  We need 
to know both of these to transfer to that application.
An “marray” is an array of deskrecords, along with the array’s size.
Finally, a “wrecord” is the DA’s  global data.  The last three fields 
(“theEvent”, “thename” and the varient parameter block) are just scratch 
areas, used by various routines as local variables.  Putting them here 
keeps them off the stack.
 
***************************************)
 
type
 
 deskrecord =  record
 dirid  : long;
 name   : Str255;
 end;
 deskpointer=  ^deskrecord;
 deskhandle =  ^deskpointer;
 
 marray = record
 count  : integer;
 data   : array
 [0..1000] of deskhandle;
 end;
 arraypointer    = ^marray;
 arrayhandle=  ^arraypointer;
 
 wrecord= packed record
 theMenu: MenuHandle;resfactor:  integer;                sysdir
 : long;packaddr : Ptr;   
 launchpath :  long; launchaddr    : long;         
 iazaddr: long;  
 theEvent : EventRecord;
 thename: Str255;case integer of   1 : (infoblock
 : CInfoPBRec);
 2 :  (hblock
 : HParamBlockRec);
 3 :  (wdblock
 : WDPBRec);
 end;
 wpointer = ^wrecord;

(**************************************)

implementation

(**************************************)

end.

(**************************************)

;***************************************;
;drvrhead.asm
;------------
;
;(c) 1987, 1988 Attic Software
;
;header for DRVR segment of
;Transfer.
;
;***************************************

;***************************************
;includes
;***************************************

 includesysequ.d
 includetypes.asm

;***************************************
;imported routines
;***************************************

 xref open
 xref ctl

;***************************************
;exported routines
;***************************************

 xdef initglobals
 xdef setdir

;***************************************
;
;The canonical DA header.  This is a
;modified version of the DA header
;supplied with TML Pascal.
;
;***************************************

 dc.w $0400 ; flags 
 dc.w $0000 ; servicedc.w $ffff  ; mask
 dc.w $0000 ; menuID dc.w ornopen  ; open    dc.w  orndone     ; prime
 dc.w ornctl; Control
 dc.w orndone  ; Status
 dc.w ornclose ; close

;***************************************

 dc.w ‘(c) 1987, 1988 ‘
 dc.w ‘Attic Software’
 dc.w ‘All rights reserved’

;***************************************

ornopen 
 movem.lA0/A1,-(SP)
 move.l A1,-(SP) ; device
 move.l A0,-(SP) ; param  jsr open
 movem.l(SP)+,A0/A1
 move.l jiodone,-(SP)
 rts

ornctl  
 movem.lA0/A1,-(SP)
 move.l A1,-(SP) ; device
 move.l A0,-(SP) ; param  jsr ctl
 movem.l(SP)+,A0/A1
 move.l jiodone,-(SP)
 rts

ornclose
orndone
 move.l jiodone,-(SP)
 rts

;***************************************
;
;The routine loader moves a selector
;into D0, and the address of the
;PACK segment into A0.  It then
;jumps to the pack (the pack begins
;with a jump table).
;
;***************************************

initglobals
 move.w #0,D0
 bra.w  loader

setdir
 move.w #4,D0
 bra.w  loader

loader
 movea.l4(SP),A0 ; globals
 movea.lWRpackaddr(A0),A0
 jmp  (A0)

;***************************************


(***************************************
 
drvr.pas
--------
 
(c) 1987, 1988 Attic Software
 
Pascal routines for DRVR segment of Transfer
 
***************************************)

unit drvr;

(**************************************)

interface
 
(**************************************)

uses macintf, hfs, types;
 
(**************************************)

implementation
 
(**************************************)

procedure initglobals
 (globals : wpointer); external;
function setdir
 (dirid : long;
 globals : wpointer) : OSErr; external;
 
(***************************************
 
drawscreen
----------
 
This routine draws the “About” message in its rectangle.
 
***************************************)

procedure drawscreen(
 theWindow : WindowPtr;
 theitem : integer);
 
var
 theType: integer;
 theHandle: Handle;
 thebox : Rect;
 
begin
 
 SetPort(theWindow);
 
 GetFNum(‘monaco’, theType);
 TextFont(theType);
 TextSize(9);
 
 GetDItem(theWindow, theitem, theType,
 theHandle, thebox);
 
 theHandle := GetResource(‘INFO’,
 GetWRefCon(theWindow));
 HLock(theHandle);
 TextBox(theHandle^, GetHandleSize(theHandle),
 thebox, 0);
 HUnlock(theHandle);
 
end;
 
(***************************************
 
transalert
----------
 
 I want all the alerts to identify their source, so I made them dialogs, 
in titled windows, and wrote this routine to imitate “Alert”.
 
 This is not the best way to do it; for one thing, a titled window should 
be dragable.  Modal dialogs, therefore, should not have titles.  I should 
have simply added a distinctive icon to the item lists.
 
 Since this is the first use of the “resfactor” field of the global record, 
it’s as good a place as any to explain it.  This DA is given a formal 
resource id of 16, and all its owned resources are numbered accordingly. 
 The Font/DA Mover will change all these numbers when it installs the 
DA.  “resfactor”, which is computed in the “open” routine, below, is 
the correction factor that converts the hard-coded resource ids to the 
actual ids in use.
 
 Note that “resfactor” doesn’t convert the formal ids; it actually converts 
the constants defined in the “types.pas” unit, which are nice positive 
numbers, equal to the resource ids plus 16872.
 
 There’s a little bit of code to install the previous procedure if this 
is the “About” dialog.
 
***************************************)

procedure transalert
 (dialognum : integer;
 globals : wpointer);
 
var
 savedport: GrafPtr;
 theDialog: DialogPtr;
 therecord: DialogRecord;
 theType: integer;
 theHandle: Handle;
 thebox : Rect;
 choice : integer;
 
begin
 
 with globals^ do begin
 
 GetPort(savedport);
 
 theDialog := GetNewDialog(dialognum
 + resfactor, @therecord,
 pointer(-1));
 SetPort(theDialog);
 
 if dialognum = aboutdialog then
 begin
 GetDItem(theDialog, 2, theType,
 theHandle, thebox);
 SetDItem(theDialog, 2, theType,
 Handle(@drawscreen), thebox);
 SetWRefCon(theDialog, dialognum
 + resfactor);
 end;
 
 InitCursor;
 ShowWindow(theDialog);
 
 repeat
 ModalDialog(nil, choice);
 until choice = ok;
 
 CloseDialog(theDialog);
 SetPort(savedport);
 
 end;
 
end;
 
(***************************************
 
errordisplay
------------
 
 This routine displays error messages.  The texts of the messages are 
in a string list.
 
***************************************)

procedure errordisplay
 (appnum, sysnum, resnum : long;
 globals : wpointer);
 
var
 string1: Str255;
 string3: Str255;
 string4: Str255;
 
begin
 
 InitCursor;
 
 with globals^ do begin
 
 GetIndString(string1, resfactor
 + stringnum, resnum);
 if string1 = ‘’ then
 string1:= ‘An error has occurred!’;
 
 NumToString(appnum, string3);
 NumToString(sysnum, string4);
 ParamText(string1, ‘’,
 string3, string4);
 
 SysBeep(10);
 transalert(errordialog, globals);
 
 end;
 
end;
 
(***************************************
 
getapps
------
 
 Here it is - the only recursive routine I have ever been forced to use! 
 (Recursion is overrated; it is, in my opinion, better to avoid recursion, 
if you can do it in a natural fashion.  Loops are easier to read, and 
generally more efficient.)
 
 This routine is passed a directory id, the count of objects (files and 
folders) in that directory, and the volume reference number.  It indexes 
through the directory with “PBGetCatInfo”.
 
 If the object is another directory, it calls itself with that directory’s 
id and count.
 
 If the object is a file, and if the file is an application, it records 
its name and the directory id in the application array.
 
***************************************)
 
procedure getapps
 (thedir : long; thecount : integer;
 thevol : integer;
 theHandle : arrayhandle;
 globals : wpointer);
 
label
 100;
 
var
 index  : integer;
 anerror: integer;
 theDialog: DialogPtr;
 jndex  : integer;
 thelength: integer;
 thedesk: deskhandle;
 
begin
 
 with globals^ do begin
 
 for index := 1 to thecount do
 with infoblock do begin
 
 thename := ‘’;
 
 ioCompletion := nil;
 ioNamePtr := @thename;
 ioVRefNum := thevol;
 ioFDirIndex := index;
 ioDrDirID := thedir;
 
 anerror:= PBGetCatInfo(@infoblock,
 false);
 if anerror <> noErr then begin
 errordisplay(101, anerror,
 2, globals);
 goto 100;
 end;
 
 if BitAnd(ioFlAttrib, $10) = $10 then
 getapps(ioDrDirID, ioDrNmFls,
 thevol, theHandle, globals)
 else if ioFlFndrInfo.fdType
 = ‘APPL’ then begin
 
 jndex := theHandle^^.count+ 1;
 theHandle^^.count := jndex;
 SetHandleSize
 (Handle(theHandle),
 5 * (jndex + 1));
 
 HLock(Handle(theHandle));
 
 with theHandle^^ do
 while (IUCompString(thename,
 data[jndex - 1]^^.name) < 0)
 and (jndex > 1) do begin
 
 data[jndex]:= data[jndex - 1];
 jndex := jndex - 1;

 end;
 
 thelength:= 10 + length(thename);
 thelength:= 2 * (thelength div 2);
 theHandle^^.data[jndex]
 := deskhandle
 (NewHandle(thelength));
 with theHandle^^.data[jndex]^^
 do begin
 dirid := thedir;
 name := thename;
 end;
 
 HUnlock(Handle(theHandle));
 
 end;
 
100:  end;
 
 end;

end;
 
(***************************************
 
walktree
--------
 
 This routine catalogs all the applications on a given disk.
 
 It first puts up a dialog, telling the user what’s going on.
 
 It next calls “PBGetCatInfo” for the root directory (directory id = 
2), to get the number of objects in the root.  Then it calls “getapps” 
to walk the HFS tree recursively.
 
 The collected data is written to the current resource file (“Transfer 
Data”, in the System folder), and the dialog is dismissed.
 
***************************************)
 
procedure walktree
 (thevol : integer;
 theHandle : arrayhandle;
 globals : wpointer);
 
var
 savedport: GrafPtr;
 theDialog: DialogPtr;
 therecord: DialogRecord;
 index  : integer;
 anerror: integer;
 
begin
 
 with globals^ do begin
 
 GetPort(savedport);
 
 theDialog := GetNewDialog(resfactor
 + builddialog, @therecord,
 pointer(-1));
 SetPort(theDialog);
 ShowWindow(theDialog);
 DrawDialog(theDialog);
 
 with infoblock do begin
 ioCompletion := nil;
 ioNamePtr := nil;
 ioVRefNum := thevol;
 ioFDirIndex := 0;
 ioDrDirID := 2;
 end;
 anerror := PBGetCatInfo(@infoblock,
 false);
 if anerror <> noErr then
 errordisplay(102, anerror,
 2, globals)
 else
 getapps
 (2, infoblock.ioDrNmFls,
 thevol, theHandle, globals);
 end;
 
 HLock(Handle(theHandle));
 with theHandle^^ do
 for index := 1 to count do begin

 AddResource
 (Handle(data[index]), ‘.Trn’,
 datastart + index,
 data[index]^^.name);

 SetHandleSize
 (Handle(data[index]), 4);

 end;
 HUnlock(Handle(theHandle));
 
 CloseDialog(theDialog);
 SetPort(savedport);

end;
 
(***************************************
 
buildmenu
--------
 
 This routine assembles the necessary data, and builds the Transfer menu.
 
 It finds the volume reference number of the disk with the System folder, 
sets the directory to the System folder, and opens or creates the “Transfer 
Data” file in that directory.
 
 If this file lacks a header resource (whether because it was just created, 
or because it has been corrupted), then it must be rebuilt, with “walktree”.
 
 Then the menu is built.  The menu resource is loaded, and the fourth 
item set to the name of the current Finder.  The remainder of the menu 
is copied from the resource file.
 
***************************************)
 
procedure buildmenu(globals : wpointer);
 
label
 100;
 
var
 thepointer :  shortpointer;
 thevolume: integer;
 theres : integer;
 theHandle: arrayhandle;
 index  : integer;
 jndex  : integer;
 thedesk: Handle;
 theID  : integer;
 theType: ResType;
 anerror: integer;
 
begin
 
 with globals^ do begin
 
 thepointer := shortpointer(sysmap);
 anerror := GetVRefNum
 (thepointer^, thevolume);
 if anerror <> noErr then begin
 errordisplay(103, anerror,
 3, globals);
 goto 100;
 end;
 
 anerror := setdir(sysdir, globals);
 if anerror <> noErr then begin
 errordisplay(104, anerror,
 3, globals);
 goto 100;
 end;
 
 thename := ‘Transfer Data’;
 theres := OpenResFile(thename);
 if ResError = fnfErr then begin
 CreateResFile(thename);
 theres := OpenResFile(thename);
 end;
 if ResError <> noErr then begin
 errordisplay(105, ResError,
 3, globals);
 goto 100;
 end;
 
 theHandle
 := arrayhandle
 (Get1Resource(‘.Trn’,
 datastart));
 if theHandle = nil then begin
 theHandle := arrayhandle
 (NewHandle(6));
 theHandle^^.count := 0;
 theHandle^^.data[0]
 := deskhandle(NewHandle(16));
 AddResource(Handle(theHandle),
 ‘.Trn’, datastart, ‘’);
 walktree(thevolume,
 theHandle, globals);
 SetHandleSize
 (Handle(theHandle), 2);
 end;
 
 theMenu := GetMenu(resfactor
 + menunum);
 BlockMove(Ptr(findername),
 Ptr(@thename), 16);
 SetItem(theMenu, 4, thename);
 
 jndex := 1;
 for index := 1 to theHandle^^.count
 do begin
 thedesk := Get1Resource(‘.Trn’,
 datastart + index);
 if thedesk <> nil then begin
 AppendMenu(theMenu, ‘.Trn’);
 GetResInfo(thedesk, theID,
 theType, thename);
 SetItem(theMenu, jndex + 4,
 thename);
 jndex := jndex + 1;
 end;
 end;
 
 InsertMenu(theMenu, 0);
 DrawMenuBar;
 
 CloseResFile(theres);
 
100:

 end;
 
end;
 
(***************************************
 
systemvol
--------
 
 This routine is more or less straight out of Tech Note 77, pages 3 and 
4.  It returns a working directory reference number for the System folder, 
suitable for use in file system calls.
 
 Step one is to find the volume reference number of the volume that holds 
the System folder.  “sysmap” is the file reference number of the System 
file (an open file), so “GetVRefNum” will find the volume refence number 
of the System file and, of course, the System folder.
 
 Step two is to get the directory id, with a call to “PBHGetVInfo”.  
The directory id is returned in the “ioVFndrInfo[1]” field of the HParamBlockRec.
 
 Finally, “PBOpenWD” will return the System folder’s working directory 
reference number, which can be used as a volume reference number in file 
system calls.
 
***************************************)

function systemvol
 (globals : wpointer) : integer;
 
var
 thepointer :  shortpointer;
 thevolume: integer;
 anerror: integer;
 
begin
 
 with globals^ do begin
 
 thepointer := shortpointer(sysmap);
 anerror := GetVRefNum(thepointer^,
 thevolume);
 
 with hblock do begin
 ioNamePtr := nil;
 ioVRefNum := thevolume;
 ioVolIndex := 0;
 end;
 anerror := PBHGetVInfo(@hblock,
 false);
 
 with wdblock do begin
 ioWDDirID
 := hblock.ioVFndrInfo[1];
 ioNamePtr := nil;
 ioVRefNum := thevolume;
 ioWDProcID := erik;
 end;
 anerror := PBOpenWD(@wdblock,
 false);
 
 systemvol := wdblock.ioVRefNum;
 
 end;
 
end;
 
(***************************************
 
rebuildmenu
----------
 
 If the “Rebuild menu” item is chosen from the menu, or an application 
is chosen which can’t be found, Transfer will rebuild the menu from scratch. 
 It does this by deleting the “Transfer Data” file, and calling “buildmenu”.
 
***************************************)

procedure rebuildmenu
 (globals : wpointer);
 
var
 anerror: integer;
 
begin
 
 with globals^ do begin
 
 DeleteMenu(resfactor + menunum);
 ReleaseResource(Handle(theMenu));
 anerror := FSDelete
 (‘Transfer Data’,
 systemvol(globals));
 buildmenu(globals);
 
 end;
 
end;
 
(***************************************
 
dofinder
--------
 
 If the “Finder” item is chosen from the menu, then no transfer is desired, 
so restore the “iaznotify” hook to the value it held when Transfer was 
launched. (This isn’t quite right, since something besides Transfer may 
have changed it since then.  but I don’t see any way to correct for that...)
 
 If the option key is down, do nothing else.  Otherwise, do an immediate 
transfer by calling “ExitToShell”.
 
***************************************)

procedure dofinder(globals : wpointer);
 
var
 thepointer :  longpointer;
 
begin
 
 with globals^ do begin
 
 thepointer
 := longpointer(iaznotify);
 thepointer^ := iazaddr;
 
 if GetNextEvent(0, theEvent) then
 ;
 if BitAnd(theEvent.modifiers,
 optionKey) = 0 then
 ExitToShell;
 
 end;
 
end;
 
(***************************************
 
clickmenu
--------
 
 The first few menu choices are handled by routines above.
 
 If an application is chosen, we need to get (1) the application’s name, 
and (2) its directory.  The name is easy; it’s on the menu.  To get the 
directory, we have to go back to the “Transfer Data” file.
 
 Once we have the application’s directory, the next thing to do is to 
make sure it’s there.  Transferring to a non-existent application will 
cause a system bomb.
 
 If everything is ok, then if the option key is down, prepare to do a 
delayed transfer; otherwise, do an immediate transfer by calling “ExitToShell”.
 
***************************************)

procedure clickmenu
 (itemchoice : integer;
 globals : wpointer);
 
label
 100;
 
var
 theres : integer;
 thedesk: deskhandle;
 theinfo: FInfo;
 thepointer :  longpointer;
 anerror: integer;
 
begin
 
 with globals^ do begin
 
 case itemchoice of
 aboutitem:
 transalert(aboutdialog,
 globals);
 builditem:
 rebuildmenu(globals);
 finderitem :
 dofinder(globals);
 otherwise

 thepointer := longpointer
 (iaznotify);
 thepointer^ := launchaddr;

 anerror := setdir(sysdir,
 globals);
 if anerror <> noErr then begin
 errordisplay(106, anerror,
 3, globals);
 goto 100;
 end;
 
 theres := OpenResFile
 (‘Transfer Data’);
 if ResError <> noErr then begin
 rebuildmenu(globals);
 goto 100;
 end;
 
 GetItem(theMenu,
 itemchoice, thename);
 thedesk := deskhandle
 (Get1NamedResource(‘.Trn’,
 thename));
 DetachResource(Handle(thedesk));
 CloseResFile(theres);
 
 if thedesk = nil then begin
 rebuildmenu(globals);
 goto 100;
 end;
 
 anerror := setdir
 (thedesk^^.dirid, globals);
 if anerror <> noErr then begin
 rebuildmenu(globals);
 goto 100;
 end;
 
 anerror := GetFInfo(thename,
 0, theinfo);
 if anerror <> noErr then begin
 rebuildmenu(globals);
 goto 100;
 end;
 
 launchpath := thedesk^^.dirid;
 
 if GetNextEvent(0, theEvent) then
 ;
 if BitAnd(theEvent.modifiers,
 optionKey) = 0 then
 ExitToShell
 else begin
 ParamText(thename,
 ‘’, ‘’, ‘’);
 transalert(delaydialog,
 globals);
 end;
 
 end;
 
100:  HiliteMenu(0);
 
 end;
 
end;
 
(***************************************
 
open
----
 
 This is the canonical DA open routine.  If the DA has already been opened, 
device.dCtlMenu will be nonzero; do nothing.  Otherwise, Allocate the 
globals, and fill in a few fields.  Of particular interest is the calculation 
of “resfactor” by the magic formula $BFE0 - 32 * dCtlRefNum - 1000.  
This, assuming I have given the DA the formal resource id of 16, allows 
be to refer to owned resources by ids from 1000 to 1031, adding resfactor 
to convert to the actual values.
 
 Next, load and detach the PACK segment.  And lock it; it’s created locked 
but why take chances?
 
 Finally, call “initglobals” to fill in the rest of the fields, and “buildmenu” 
to set up the menu.
 
***************************************)
 
procedure open(var device : DCtlEntry;
 var block : ParamBlockRec);
 
var
 globals: wpointer;
 packhandle :  Handle;
 
begin
 
 if device.dCtlMenu = 0 then begin
 
 globals := wpointer
 (NewPtr(sizeof(wrecord)));
 if globals <> nil then
 with globals^ do begin
 
 with device do begin
 resfactor := $BFE0
 - 32 * dCtlRefNum - 1000;
 dCtlMenu := resfactor
 + menunum;
 dctlwindow := nil;
 dCtlStorage
 := Handle(globals);
 end;
 
 packhandle := GetResource
 (‘PACK’, resfactor + packnum);
 DetachResource(packhandle);
 HLock(packhandle);
 packaddr := packhandle^;
 
 initglobals(globals);
 buildmenu(globals);
 
 end;
 
 end;
 
end;
 
(***************************************
 
ctl
--
 
 The canonical Control routine.  The only events we’re interested in 
are menu clicks; if we get one, call “clickmenu”.
 
***************************************)
 
procedure ctl(var device : DCtlEntry;
 var block : ParamBlockRec);

var
 globals: wpointer;
 
begin
 
 if (device.dCtlMenu <> 0)
 and (block.csCode = accMenu)
 then begin
 globals := wpointer
 (device.dCtlStorage);
 clickmenu
 (block.csParam[1], globals);
 end;
 
end;
 
(**************************************)
 
 end.
 
(**************************************)


/codetype DRVR 16 ‘Transfer HD’ 16
drvrhead
drvr
pas$library
macintfglue
/end


;***************************************
;
;packhead.asm
;------------
;
;(c) 1987, 1988 Attic Software
;
;header and assembly routines for
;PACK segment of Transfer.
;
;***************************************

;***************************************
;exported routines
;***************************************

 xdef setglobal
 xdef getglobal
 xdef runiaz

;***************************************
;
;The jump table begins with a jump
;into the body of the table, indexed
;by D0 (the routine selector).  Then
;it branches to the appropriate
;routine.
;
;***************************************
 
 xref initglobals
 xref setdir

 jmp  2(PC,D0.w)
 bra.w  initglobals
 bra.w  setdir

;***************************************
;
;The global access routines provide
;a way to save the address of the
;global record, which would
;otherwise be lost.  This is done by
;writing the address into a four-
;byte constant in the PACK segment.
;
;Note:  writing to code segments is
;frowned upon in some circles.  This
;objection has a legitimate basis:
;self-modifying code is a horror.
;It makes debugging difficult, and
;maintenance impossible.  (5 points:
;where in “Inside Mac” are you
;instructed to write self-modifying
;code?)  In this instance, I an not
;modifying code; I am modifying
;data, and there’s nothing wrong
;with that.
;
;procedure setglobal(value : long);
;function getglobal : long;
;
;***************************************

 module ‘access’

setglobal
 movea.l(SP)+,A0
 lea  dummy,A1
 move.l (SP)+,(A1)
 jmp  (A0)

getglobal
 movea.l(SP)+,A0
 move.l dummy,(SP)
 jmp  (A0)

dummy
 dc.w ‘xxxx’

;***************************************
;
;procedure runiaz(iazaddr : long)
;
;The runiaz routine zeros the
;“iaznotify” hook, and calls the
;routine that preceded Transfer’s
;routine, if any.
;
;***************************************

 module ‘runiaz’

runiaz
 clr.l  $33C
 movea.l4(SP),A0
 move.l (SP)+,(SP)

 cmpa.l #0,A0
 beq.w  L0001
 move.l A0,-(SP)

L0001
 rts

;***************************************


(***************************************
 
pack.pas
--------

(c) 1987, 1988 Attic Software
 
Pascal routines for PACK segment of Transfer
 
***************************************)

unit pack;

(**************************************)

interface
 
(**************************************)

uses macintf, hfs, types;
 
(**************************************)

implementation
 
(**************************************)

procedure setglobal
 (value : long); external;
function getglobal : long; external;
procedure runiaz
 (iazaddr : long); external;
 
(***************************************
 
systemdir
--------
 
 This routine is more or less straight out of Tech Note 67.  It returns 
a directory id for the System folder, suitable for use in “SetVol” calls.
 
 Step one is to find the volume reference number of the volume that holds 
the System folder.  “sysmap” is the file reference number of the System 
file (an open file), so “GetVRefNum” will find the volume refence number 
of the System file and, of course, the System folder.  (The Tech Note 
skips this step; it searches the boot drive for a System folder, and 
may not find one.)
 
 Step two is to get the directory id, with a call to “PBHGetVInfo”.  
The directory id is returned in the “ioVFndrInfo[1]” field of the HParamBlockRec.
 
***************************************)

function systemdir
 (globals : wpointer) : long;
 
var
 thepointer :  shortpointer;
 thevolume: integer;
 anerror: integer;
 
begin
 
 with globals^ do begin
 
 thepointer := shortpointer(sysmap);
 anerror := GetVRefNum(thepointer^,
 thevolume);
 
 with hblock do begin
 ioNamePtr := nil;
 ioVRefNum := thevolume;
 ioVolIndex := 0;
 end;
 anerror := PBHGetVInfo(@hblock,
 false);
 
 systemdir := hblock.ioVFndrInfo[1];
 
 end;
 
end;

(***************************************
 
setdir
------
 
 This is just a shell around “PBHSetVol”.
 
***************************************)

function setdir
 (dirid : long;
 globals : wpointer) : OSErr;
 
begin
 
 with globals^ do begin
 
 with wdblock do begin
 ioCompletion := nil;
 ioNamePtr := nil;
 ioVRefNum := 0;
 ioWDDirID := dirid;
 end;
 
 setdir := PBHSetVol(@wdblock,
 false);
 
 end;
 
end;
 
(***************************************
 
postlaunch
----------
 
 This is the routine that performs the actual launch.  It is called by 
“InitApplZone” throught the “iaznotify” hook.
 
 First, recover the global record with a call to “getglobal”.  This routine 
is called after all the resources have been released; the DRVR segment 
is no longer around, and even if it was, “postlaunch” isn’t called by 
it, so we can’t find the globals in the usual way.  “getglobal” will 
return a long word stored right in the PACK segment, which has been previously 
set to a pointer to the globals.
 
 Next, “postlaunch” will call any routines that were already installed 
in “iaznotify” when “postlaunch” was installed there, via the “runiaz” 
routine.
 
 Then it calls “setdir” to set the volume to the folder containing the 
chosen application, and copies the applications’s name to “curappname”. 
 The system will now be fooled into launching that application instead 
of the Finder.
 
***************************************)

procedure postlaunch;
 
var
 globals: wpointer;
 anerror: integer;
 
begin
 
 globals := wpointer(getglobal);
 with globals^ do begin
 runiaz(iazaddr);
 anerror := setdir(launchpath,globals);
 if anerror = noErr then
 BlockMove(@thename, Ptr(curappname), 32);
 end;
 
end;
 
(***************************************
 
initglobals
----------
 
 Initialize global data.  Note that we preserve the value at “iaznotify”; 
if the current application has installed a routine there, we will want 
to run it before we run ours.
 
 Also, we don’t want to confuse the new application with the old applications’s 
data files, so we clear the finder files.
 
***************************************)

procedure initglobals
 (globals : wpointer);
 
var
 thepointer :  longpointer;
 message: integer;
 count  : integer;
 index  : integer;
 
begin
 
 setglobal(long(globals));
 
 with globals^ do begin
 
 sysdir := systemdir(globals);
 
 thepointer
 := longpointer(iaznotify);
 iazaddr := thepointer^;
 
 launchaddr
 := BitAnd(long(@postlaunch),
 $FFFFFF);
 
 end;
 
 CountAppFiles(message, count);
 for index := 1 to count do
 ClrAppFiles(index);
 
end;
 
(**************************************)
 
end.
 
(**************************************)


/codetype PACK -15871 ‘Transfer HD’ 16
packhead
pack
pas$library
macintfglue
/end


*****************************************
*rsrc.r
*
*(c) 1987, 1988 Attic Software
*
*resources for Transfer DA
*
****************************************

Transfer 3.2 HD
DFILDMOV

include drvr
include pack

*****************************************
*
*Menu resource
*
****************************************

type MENU
 ,-15871 (4)
Transfer
 About Transfer...
 Rebuild menu
 (-
 Finder

*****************************************
*
*Error messages
*
****************************************

Type STR#
 ,-15871 (32)
 4
I’m unable to load the Transfer DA.
Error building the menu list.
Error opening the “Transfer Data” file.
Error restoring the volume.

*****************************************
*
*About information
*
****************************************

Type INFO=GNRL
 Trans,-15870 (32)
.S
Transfer 3.2 HD adds a Transfer menu ++
to any application that ++
supports desk accessories.  It is ++
intended for use with your ++
hard disk, and 
.S
expects that you are using ++
HFS.\0D\0DTransfer 3.2 HD was ++
written by Clifford Story of ++
Attic Software.\0D\0D
.S
                    Attic Software\0D++
                    P.O. Box 24695\0D++
                    Jacksonville, ++
Florida   32241

*****************************************
*
*Item lists
*
****************************************

Type DITL
     Error,-15871 (32)
2
*   1
BtnItem Enabled
116 83 136 173
OK

*   2
statText Disabled
10 10 106 246
^0^1\0D\0DTransfer HD error ^2,++
\0DSystem error ^3.

     About,-15870 (32)
2
*   1
BtnItem Enabled
252 201 272 291
OK

*   2
userItem Enabled
10 10 242 482

     Build,-15869 (32)
1
*   1
statText Disabled
10 10 90 246
Transfer is building the menu list.  ++
This will take 30 seconds ++
or so but the list will be preserved ++
and won’t have to be ++
re-built unless you re-arrange your ++
disk.

     Delay,-15868 (32)
2
*   1
BtnItem Enabled
68 83 88 173
OK

*   2
statText Disabled
10 10 58 246
“^0” will be launched when you quit ++
this application.

*****************************************
*
*Dialogs
*
****************************************

Type DLOG
 Error,-15871 (32)
Transfer HD
64 128 210 384
invisible nogoaway
0
0
-15871

 About,-15870 (32)
Transfer 3.2 HD, © 1987, 1988 ++
Attic Software
50 10 332 502
invisible nogoaway
0
0
-15870

 Build,-15869 (32)
Transfer HD
64 128 164 384
invisible nogoaway
0
0
-15869

 Delay,-15868 (32)
Transfer HD
64 128 162 384
invisible nogoaway
0
0
-15868

****************************************
 
AAPL
$119.00
Apple Inc.
+1.40
MSFT
$47.75
Microsoft Corpora
+0.28
GOOG
$540.37
Google Inc.
-0.71

MacTech Search:
Community Search:

Software Updates via MacUpdate

HoudahSpot 3.9.6 - Advanced file search...
HoudahSpot is a powerful file search tool built upon MacOS X Spotlight. Spotlight unleashed Create detailed queries to locate the exact file you need Narrow down searches. Zero in on files Save... Read more
RapidWeaver 6.0.3 - Create template-base...
RapidWeaver is a next-generation Web design application to help you easily create professional-looking Web sites in minutes. No knowledge of complex code is required, RapidWeaver will take care of... Read more
iPhoto Library Manager 4.1.10 - Manage m...
iPhoto Library Manager lets you organize your photos into multiple iPhoto libraries. Separate your high school and college photos from your latest summer vacation pictures. Or keep some photo... Read more
iExplorer 3.5.1.9 - View and transfer al...
iExplorer is an iPhone browser for Mac lets you view the files on your iOS device. By using a drag and drop interface, you can quickly copy files and folders between your Mac and your iPhone or... Read more
MacUpdate Desktop 6.0.3 - Discover and i...
MacUpdate Desktop 6 brings seamless 1-click installs and version updates to your Mac. With a free MacUpdate account and MacUpdate Desktop 6, Mac users can now install almost any Mac app on macupdate.... Read more
SteerMouse 4.2.2 - Powerful third-party...
SteerMouse is an advanced driver for USB and Bluetooth mice. It also supports Apple Mighty Mouse very well. SteerMouse can assign various functions to buttons that Apple's software does not allow,... Read more
iMazing 1.1 - Complete iOS device manage...
iMazing (was DiskAid) is the ultimate iOS device manager with capabilities far beyond what iTunes offers. With iMazing and your iOS device (iPhone, iPad, or iPod), you can: Copy music to and from... Read more
PopChar X 7.0 - Floating window shows av...
PopChar X helps you get the most out of your font collection. With its crystal-clear interface, PopChar X provides a frustration-free way to access any font's special characters. Expanded... Read more
Carbon Copy Cloner 4.0.3 - Easy-to-use b...
Carbon Copy Cloner backups are better than ordinary backups. Suppose the unthinkable happens while you're under deadline to finish a project: your Mac is unresponsive and all you hear is an ominous,... Read more
ForeverSave 2.1.3 - Universal auto-save...
ForeverSave auto-saves all documents you're working on while simultaneously doing backup versioning in the background. Lost data can be quickly restored at any time. Losing data, caused by... Read more

Latest Forum Discussions

See All

Make Way for Fat Chicken, from the Maker...
Make Way for Fat Chicken, from the Makers of Scrap Squad Posted by Jessica Fisher on November 26th, 2014 [ permalink ] Relevant Games has announced they will be releasing their reverse tower defense game, | Read more »
Tripnary Review
Tripnary Review By Jennifer Allen on November 26th, 2014 Our Rating: :: TRAVEL BUCKET LISTiPhone App - Designed for the iPhone, compatible with the iPad Want to create a travel bucket list? Tripnary is a fun way to do exactly that... | Read more »
Ossian Studios’ RPG, The Shadow Sun, is...
Ossian Studios’ RPG, The Shadow Sun, is Now Available for $4.99 Posted by Jessica Fisher on November 26th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Mmmm, Tasty – Having the Angry Birds for...
The very first Angry Birds debuted on iOS back in 2009. When you sit back and tally up the number of Angry Birds games out there and the impact they’ve had on pop culture as a whole, you just need to ask yourself: “How would the birds taste... | Read more »
Rescue Quest Review
Rescue Quest Review By Jennifer Allen on November 26th, 2014 Our Rating: :: PATH BASED MATCH-3Universal App - Designed for iPhone and iPad Guide a wizard to safety by matching gems. Rescue Quest might not be an entirely original... | Read more »
You Can Play the Final Chapter of Lone W...
You Can Play the Final Chapter of Lone Wolf: Dawn Over V’taag Right Now Posted by Jessica Fisher on November 26th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Swords of Anima (Games)
Swords of Anima 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: A new tactical turn-based RPG experience. Command the Savior Rex Squad in an epic journey of courage and deception. Can you... | Read more »
Audio Defence: Zombie Arena
Audio Defence: Zombie Arena By Lee Hamlet on November 26th, 2014 Our Rating: :: DRAGS ITS FEETUniversal App - Designed for iPhone and iPad From the makers of Papa Sangre comes a defense game that forces players to listen carefully... | Read more »
Tales from the Borderland​s Will be Comi...
Tales from the Borderland​s Will be Coming to iOS by the End of the Year Posted by Jessica Fisher on November 26th, 2014 [ permalink ] Telltale Games has announced | Read more »
Sunburn! Review
Sunburn! Review By Campbell Bird on November 26th, 2014 Our Rating: :: DON'T DIE ALONEUniversal App - Designed for iPhone and iPad Platform through the depths of space to make sure your entire crew dies together in this satisfying... | Read more »

Price Scanner via MacPrices.net

2014 1.4GHz Mac mini on sale for $449, save $...
 B&H Photo has the new 1.4GHz Mac mini on sale for $449.99 including free shipping plus NY tax only. Their price is $50 off MSRP, and it’s the lowest price available for this new model. Adorama... Read more
Early Black Friday pricing on 27-inch 5K iMac...
 B&H Photo continues to offer Black Friday sale prices on the 27″ 3.5GHz 5K iMac, in stock today and on sale for $2299 including free shipping plus NY sales tax only. Their price is $200 off MSRP... Read more
Early Black Friday sale prices on iPad Air 2,...
 MacMall is discounting iPad Air 2s by up to $75 off MSRP as part of their Black Friday sale. Shipping is free: - 16GB iPad Air WiFi: $459 $40 off - 64GB iPad Air WiFi: $559 $40 off - 128GB iPad Air... Read more
Early Black Friday MacBook Air sale prices, $...
 MacMall has posted early Black Friday MacBook Air sale prices. Save $101 on all models for a limited time: - 11″ 1.4GHz/128GB MacBook Air: $798 - 11″ 1.4GHz/256GB MacBook Air: $998 - 13″ 1.4GHz/... Read more
Why iPhone 6 Tablet/Laptop Cannibalization Is...
247wallst.com blogger Douglas A. McIntyre noted last week that according to research posted on the Applovin blog site the iPhone 6 is outselling the iPhone 6 Plus by a wide margin . Hardly a surprise... Read more
Worldwide Tablet Growth Expected to Slow to 7...
The global tablet market is expected to record massive deceleration in 2014 with year-over-year growth slowing to 7.2%, down from 52.5% in 2013, according to a new forecast from International Data... Read more
Touchscreen Glove Company Announces New Produ...
Surrey, United Kingdom based TouchAbility specializes in design and manufacture of a wide variety of products compatible with touchscreen devices including smartphones, tablets and computers. Their... Read more
OtterBox Alpha Glass Screen Protectors for iP...
To complement the bigger, sharper displays on the latest Apple devices, OtterBox has introduced Alpha Glass screen protectors to the iPhone 6 and iPhone 6 Plus. The fortified glass screen protectors... Read more
Early Black Friday Mac Pro sale, 6-Core 3.5GH...
 B&H Photo has the 6-Core 3.5GHz Mac Pro on sale today for $3499 including free shipping plus NY sales tax. Their price is $500 off MSRP, and it’s the lowest price available for this model from... Read more
Early Black Friday sale price: 15-inch 2.2GHz...
 B&H Photo has the 2014 15″ 2.2GHz Retina MacBook Pro on sale today for $1699.99. Shipping is free, and B&H charges NY sales tax only. Their price is $300 off MSRP, equalling Best Buy’s price... Read more

Jobs Board

*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.