[futurebasic] Re: [FB] Change filename to Longer file name

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 2004 : Group Archive : Group : All Groups

From: "H. Gluender" <h@...>
Date: Sun, 12 Sep 2004 15:26:21 +0200
Robert Covington wrote:


From the handy Technote that Herbie referenced  <
http://developer.apple.com/technotes/tn2002/tn2078.html >  :

>>  How do I support FSRefs and long Unicode file names in open and save
>>  dialogs?
>>
>>  You have to use the new NavCreateXXX APIs introduced in Navigation
>>  Services 3.0. (Navigation Services) You also have to use these if you
>>  want to implement open and save dialogs as sheets (though they don't
>>  need to be sheets)

>  I guess this is path to start hiking down.
----------------------------------------------

Robert,

I'm glad you made it...

In my most recent app (April 04) I exclusively used FSref. I open
files, read and write to them, and even save files the latter however
not by use of NavServices. :-)

You shall find all the necessary TB-routines in Apple's Files and
NavServices headers.

Here are three code snippets that works for me:


READ from file:

  dc = FN FSGetDataForkName( @name )
err = FN FSOpenFork( #suRef, name.length, @name.unicode[0], _fsRdPerm, ¬
           @forkRefNum )
IF ( ( err ) OR ( forkRefNum == 0 ) ) THEN EXIT "xx"

err = FN FSReadFork( forkRefNum, _fsFromStart, 0, SizeOf( UInt16 ), ¬
           SizeOf( UInt32 ), @seconds, @actualCount )
  dc = FN FSCloseFork( forkRefNum )
forkRefNum = 0


CREATE file:

catInfoF.finderInfoF.fileType    = _"ABcd"
catInfoF.finderInfoF.fileCreator = _"FGhi"
catInfoF.textEncodingHint        = catInfoD.textEncodingHint
//here I take the hint from another file
err = FN FSCreateFileUnicode( @parRef, name.length, @name.unicode[0], ¬
           _kFSCatInfoTextEncoding_kFSCatInfoFinderInfo, ¬
           @catInfoF, @suRef, #_nil )
IF ( err ) THEN  EXIT "yy"


WRITE to file:

  dc = FN FSGetDataForkName( @name )
err = FN FSOpenFork( @suRef, name.length, @name.unicode[0], _fsWrPerm, ¬
           @forkRefNum )
LONG IF ( ( err == _noErr ) AND ( forkRefNum != 0 ) )
err = FN FSWriteFork( forkRefNum, _fsFromStart, 0, 0, ¬
           SizeOf( UTCDateTime ), @catInfoD.createDate, #_nil )
//IF ( err == _noErr ) THEN err = FN FSSetForkSize( forkRefNum,
_fsAtMark, 0, 0)
//IF ( err == _noErr ) THEN err = FN FSFlushFork( forkRefNum )
//no need anymore, FSCloseFork will do
  dc = FN FSCloseFork( forkRefNum )
forkRefNum = 0
END IF


HTH a bit.

Best
--


                   Herbie

          ------------------------

          <http://www.gluender.de>