[futurebasic] Re: [FB] Folder Visability

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

From: Robert Purves <robert.purves@...>
Date: Mon, 5 Sep 2005 21:15:38 +1200
On 5/09/2005, at 9:57 AM, Joe Smith wrote:


> How do you determine and change a folder's visability ??  I checked  
> the
> examples in the USR ScanFolder and see reference to the _fvisable  
> but don't
> know quite how to change the folder.  Any help would be appreciated.
>

Use FSpIsObjectInvisible and FSpHideShowObject from the demo below.  
They work for directories as well as files.

Robert P.


'---------------------
#define FSCatalogInfoBitmap as UInt32
#define FSVolumeRefNum      as SInt16

begin record UTCDateTime
dim as UInt16   highSeconds
dim as UInt32   lowSeconds
dim as UInt16   fraction
end record

begin record HFSUniStr255
   dim as UInt16   length // number of unicode characters
   dim as UniChar  unicode[254] // unicode characters
end record

begin record FSCatalogInfo
dim as UInt16          nodeFlags
dim as FSVolumeRefNum  volume
dim as UInt32          parentDirID, nodeID
dim as UInt8           sharingFlags, userPrivileges, reserved1,  
reserved2
dim as UTCDateTime     createDate, contentModDate, attributeModDate,  
accessDate, backupDate
dim as UInt32          permissions[3] // OS X
dim as FInfo           finderInfo
dim as UInt8           extFinderInfo[15]
dim as UInt64          dataLogicalSize, dataPhysicalSize,  
rsrcLogicalSize, rsrcPhysicalSize // files only
dim as UInt32          valence // folders only
dim as TextEncoding    textEncodingHint
end record

toolbox fn FSSetCatalogInfo( const FSRef *ref, ¬
     FSCatalogInfoBitmap whichInfo, ¬
     const FSCatalogInfo *catalogInfo) = OSErr

toolbox fn FSGetCatalogInfo( const FSRef *ref, ¬
     FSCatalogInfoBitmap whichInfo,¬
     FSCatalogInfo *catalogInfo, ¬
     HFSUniStr255 *outName, ¬
     FSSpec *FSSpec, ¬
     FSRef *parentRef ) = OSErr

_kFSCatInfoFinderInfo = 0x00000800
_kIsInvisible = 0x4000



/*
Return _zTrue if the file or folder referenced by f
is either invisible or nonexistent, else return false.
Note that this examines only FSCatalogInfo.FInfo.fdFlags;
other cloaks of invisibility, such as .name, are not detected.
*/

local mode
local fn FSpIsObjectInvisible( f as ^FSSpec )
'~'1
dim as FSRef             ref
dim as FSCatalogInfo     info
dim as OSStatus          err
dim as Boolean           invisible

invisible = _zTrue
if ( f == 0 ) then exit fn
err = fn FSpMakeFSRef( #f, @ref )
if ( err == _noErr ) then err = fn FSGetCatalogInfo( ref,  
_kFSCatInfoFinderInfo, @info, #0, #0, #0 )
if ( err == _noErr ) then invisible = ( (_kIsInvisible and  
info.finderInfo.fdFlags) != 0 )
end fn = invisible


/*
Hide or show the file or folder referenced by f.
If the 'hide' parameter is non-zero, the object will be hidden,
otherwise it will be revealed. The object is updated only if
its visibility needs to be changed.
Returns an OSErr (_noErr, _paramErr, _fnfErr, _nsvErr...)
*/

local mode
local fn FSpHideShowObject( hide as Boolean, f as ^FSSpec )
'~'1
dim as FSRef             ref
dim as FSCatalogInfo     info
dim as OSErr             err
dim as Boolean           needChange

if ( f == 0 ) then err = _paramErr : exit fn
err = fn FSpMakeFSRef( #f, @ref )
if ( err ) then exit fn
err = fn FSGetCatalogInfo( ref, _kFSCatInfoFinderInfo, @info, #0, #0,  
#0 )
if ( err ) then exit fn
long if ( hide ) // make invisible
needChange = ( (info.finderInfo.fdFlags and _kIsInvisible) == 0 )
info.finderInfo.fdFlags = info.finderInfo.fdFlags or _kIsInvisible
xelse // make visible
needChange = ( (info.finderInfo.fdFlags and _kIsInvisible) != 0 )
info.finderInfo.fdFlags = info.finderInfo.fdFlags and not 
( _kIsInvisible )
end if
if ( needChange ) then err = fn FSSetCatalogInfo( ref,  
_kFSCatInfoFinderInfo, info )
end fn = err


// demo main program
dim as FSSpec   f
dim as long   @ dirID
dim as OSErr    err

// as demo, make folder in app's folder
err = fn FSMakeFSSpec( system( _aplVRefNum ), system( _aplParID ),  
"test folderol", @f )
err = fn FSpDirCreate( f, _smSystemScript, @dirID )
print fn FSpIsObjectInvisible( f ) // 0 == _false
err = fn FSpHideShowObject( _zTrue, f )
print fn FSpIsObjectInvisible( f ) // -1 == _zTrue
err = fn FSpDelete( f )
do
HandleEvents
until 0
'---------------------