home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 June / MacFormat 25.iso / Shareware City / Developers / ICAppSourceKit1.0 / ICStandardFile.p < prev    next >
Encoding:
Text File  |  1994-11-18  |  3.0 KB  |  125 lines  |  [TEXT/PJMM]

  1. unit ICStandardFile;
  2.  
  3. interface
  4.  
  5.     function ICStandardGetFile (t: OSType; var fs: FSSpec; var fi: FInfo): OSErr;
  6.     function ICStandardPutFile (prompt, name: str255; var fs: FSSpec): OSErr;
  7.     function ICStandardGetFolder (var fs: FSSpec; var dirID: longInt): OSErr;
  8.  
  9. implementation
  10.  
  11.     uses
  12.         Finder, ICGlobals, ICMiscSubs, StandardGetFolder;
  13.  
  14.     function ICStandardGetFile (t: OSType; var fs: FSSpec; var fi: FInfo): OSErr;
  15.         var
  16.             tl: SFTypeList;
  17.             reply: SFReply;
  18.             valid: boolean;
  19.             info: FInfo;
  20.             types: integer;
  21.             err: OSErr;
  22.             junklong: longInt;
  23.             nreply: StandardFileReply;
  24.     begin
  25.         tl[0] := t;
  26.         if t = OSType(0) then begin
  27.             types := -1;
  28.         end
  29.         else if t = 'APPL' then begin
  30.             tl[1] := kApplicationAliasType;
  31.             types := 2;
  32.         end
  33.         else begin
  34.             types := 1;
  35.         end;
  36.         err := userCanceledErr;
  37.         if has_newStdFile then begin
  38.             StandardGetFile(nil, types, tl, nreply);
  39.             if nreply.sfGood then begin
  40.                 fs := nreply.sfFile;
  41.                 err := HGetFInfo(fs.vRefNum, fs.parID, fs.name, fi);
  42.             end;
  43.         end
  44.         else begin
  45.             SFGetFile(Point($00640064), '', nil, types, tl, nil, reply);
  46.             if reply.good then begin
  47.                 err := GetFInfo(reply.fName, reply.vRefNum, fi);
  48.                 if err = noErr then begin
  49.                     fs.name := reply.fName;
  50.                     err := GetWDinfo(reply.vRefNum, fs.vRefNum, fs.parID, junklong);
  51.                 end;
  52.             end;
  53.         end;
  54.         ICStandardGetFile := err;
  55.     end;
  56.  
  57.     function ICStandardPutFile (prompt, name: str255; var fs: FSSpec): OSErr;
  58.         var
  59.             reply: SFReply;
  60.             err: OSErr;
  61.             junklong: longInt;
  62.             nreply: StandardFileReply;
  63.     begin
  64.         err := userCanceledErr;
  65.         if has_newStdFile then begin
  66.             StandardPutFile(prompt, name, nreply);
  67.             if nreply.sfGood then begin
  68.                 fs := nreply.sfFile;
  69.                 err := noErr;
  70.             end;
  71.         end
  72.         else begin
  73.             SFPutFile(Point($00640064), prompt, name, nil, reply);
  74.             if reply.good then begin
  75.                 fs.name := reply.fName;
  76.                 err := GetWDinfo(reply.vRefNum, fs.vRefNum, fs.parID, junklong);
  77.             end;
  78.         end;
  79.         ICStandardPutFile := err;
  80.     end;
  81.  
  82.     function ButtonHook (item: integer; dlg: DialogPtr): integer;
  83.     begin
  84.         if item = 11 then begin
  85.             item := sfItemOpenButton;
  86.         end;
  87.         ButtonHook := item;
  88.     end;
  89.  
  90.     function ICStandardGetFolder (var fs: FSSpec; var dirID: longInt): OSErr;
  91.         var
  92.             err: OSErr;
  93.             typelist: SFTypeList;
  94.             cpb: CInfoPBRec;
  95.             reply: SFReply;
  96.             temp: FSSpec;
  97.             junklong: longInt;
  98.             nreply: StandardFileReply;
  99.     begin
  100.         err := userCanceledErr;
  101.         if has_newStdFile then begin
  102.             StandardGetFolder(Point($00640064), '', nreply);
  103.             if nreply.sfGood then begin
  104.                 fs := nreply.sfFile;
  105.                 err := noErr;
  106.             end;
  107.         end
  108.         else begin
  109.             typeList[0] := OSType(0); { numTypes=0 doesn't seem to stop files from being displayed }
  110.             SFPGetFile(Point($00640064), '', nil, 1, typeList, @ButtonHook, reply, 1500, nil);
  111.             if reply.good then begin
  112.                 err := GetWDinfo(reply.vRefNum, fs.vRefNum, fs.parID, junklong);
  113.             end; (* if *)
  114.         end;
  115.         if err = noErr then begin
  116.             err := FSpGetCatInfo(fs, -1, cpb);
  117.             if err = noErr then begin
  118.                 fs.parID := cpb.ioDrParID;
  119.                 dirID := cpb.ioDirID;
  120.             end; (* if *)
  121.         end;
  122.         ICStandardGetFolder := err;
  123.     end;
  124.  
  125. end.