|
From: <and...@us...> - 2009-09-16 19:48:57
|
Revision: 1827
http://frontierkernel.svn.sourceforge.net/frontierkernel/?rev=1827&view=rev
Author: andreradke
Date: 2009-09-16 19:48:48 +0000 (Wed, 16 Sep 2009)
Log Message:
-----------
On Mac only, switch tyfilespec from using a CStringRef to a HFSUniStr255 for the name field in order to simplify memory management. See definition of tyfilespec in shelltypes.h for details.
Modified Paths:
--------------
Frontier/trunk/Common/headers/file.h
Frontier/trunk/Common/headers/shelltypes.h
Frontier/trunk/Common/headers/versions.h
Frontier/trunk/Common/source/about.c
Frontier/trunk/Common/source/claycallbacks.c
Frontier/trunk/Common/source/dbverbs.c
Frontier/trunk/Common/source/file.c
Frontier/trunk/Common/source/filedialog.c
Frontier/trunk/Common/source/fileloop.c
Frontier/trunk/Common/source/fileops.c
Frontier/trunk/Common/source/filepath.c
Frontier/trunk/Common/source/fileverbs.c
Frontier/trunk/Common/source/icon.c
Frontier/trunk/Common/source/langdll.c
Frontier/trunk/Common/source/langevaluate.c
Frontier/trunk/Common/source/langhtml.c
Frontier/trunk/Common/source/langipc.c
Frontier/trunk/Common/source/langpack.c
Frontier/trunk/Common/source/langsqlite.c
Frontier/trunk/Common/source/langsystypes.c
Frontier/trunk/Common/source/launch.c
Frontier/trunk/Common/source/menuverbs.c
Frontier/trunk/Common/source/opverbs.c
Frontier/trunk/Common/source/player.c
Frontier/trunk/Common/source/resources.c
Frontier/trunk/Common/source/shellfile.c
Frontier/trunk/Common/source/shellsysverbs.c
Frontier/trunk/Common/source/shellverbs.c
Frontier/trunk/Common/source/shellwindow.c
Frontier/trunk/Common/source/shellwindowverbs.c
Frontier/trunk/Common/source/tableexternal.c
Frontier/trunk/Common/source/wpverbs.c
Frontier/trunk/build_Xcode/Frontier.xcodeproj/project.pbxproj
Modified: Frontier/trunk/Common/headers/file.h
===================================================================
--- Frontier/trunk/Common/headers/file.h 2009-08-30 19:58:42 UTC (rev 1826)
+++ Frontier/trunk/Common/headers/file.h 2009-09-16 19:48:48 UTC (rev 1827)
@@ -252,8 +252,6 @@
extern boolean folderfrompath (bigstring, bigstring);
-extern boolean getfileparentfolder (const ptrfilespec , ptrfilespec );
-
extern boolean deletefile ( const ptrfilespec );
extern boolean renamefile (const ptrfilespec , bigstring);
@@ -424,16 +422,6 @@
#ifdef MACVERSION
- extern boolean CFStringRefToHFSUniStr255 ( CFStringRef, HFSUniStr255 * ); // 2006-06-07 creedon
-
- extern boolean CFStringRefToStr255 ( CFStringRef, StringPtr ); // 2006-06-07 creedon
-
- extern boolean FSRefGetNameStr255 ( const FSRef *, Str255 ); // 2006-06-07 creedon
-
- extern boolean HFSUniStr255ToStr255 ( ConstHFSUniStr255Param, StringPtr ); // 2006-06-07 creedon
-
- extern boolean bigstringToHFSUniStr255 ( const bigstring, HFSUniStr255 * ); // 2006-06-07 creedon
-
extern void filegetinfofrompb ( FSRefParam *, tyfileinfo * );
extern void filegetinfofrompbcipbr ( CInfoPBRec *, tyfileinfo * );
@@ -442,30 +430,6 @@
extern boolean getmacfileinfocipbr ( const FSSpecPtr, CInfoPBRec * );
-/* 2006-08-11 creedon: cribbed from MoreFilesX.c and modded to work with Str255 */
-
-OSErr
-HFSNameGetUnicodeName255 (
- ConstStr255Param hfsName,
- TextEncoding textEncodingHint,
- HFSUniStr255 *unicodeName);
-
-/*
- The HFSNameGetUnicodeName function converts a Pascal Str255 string to an
- Unicode HFSUniStr255 string using the same routines as the File Manager.
-
- hfsName --> The Pascal string to convert.
- textEncodingHint --> The text encoding hint used for the conversion.
- You can pass kTextEncodingUnknown to use the
- "default" textEncodingHint.
- unicodeName <-- The Unicode string.
-
- __________
-
- Also see: HFSNameGetUnicodeName in MoreFilesX.c
-
-*/
-
#endif
@@ -502,16 +466,50 @@
#pragma mark === fileops.c ===
-extern boolean extendfilespec ( const ptrfilespec, ptrfilespec ); // 2006-06-23 creedon
+extern void clearfilespec(ptrfilespec); // 2009-09-05 aradke
-extern boolean getfilespecparent ( ptrfilespec ); // 2006-06-17 creedon
-
extern boolean setfilelabelindex (const ptrfilespec , short, boolean); // 2006-04-23 creedon */
-extern short getfilelabelindex (const ptrfilespec , short *); // 2006-04-23 creedon */
+extern short getfilelabelindex (const ptrfilespec , short *); // 2006-04-23 creedon */
#ifdef MACVERSION
+ extern boolean macfilespecisvalid(const ptrfilespec fs); // 2009-09-05 aradke
+
+ extern boolean macfilespecisresolvable(const ptrfilespec fs); // 2009-09-13 aradke
+
+ extern OSErr macgetfsref(const ptrfilespec fs, FSRef* fsref); // 2009-09-05 aradke
+
+ extern OSErr macgetfsspec(const ptrfilespec fs, FSSpec *fss); // 2009-09-06 aradke
+
+ extern OSErr macgetfilespecparent(const ptrfilespec fs, ptrfilespec fsparent); // 2009-09-05 aradke
+
+ extern OSErr macgetfilespecchild(const ptrfilespec fs, tyfsnameptr name, ptrfilespec fschild); // 2009-09-13 aradke
+
+ extern OSErr macgetfilespecchildfrombigstring(const ptrfilespec fs, bigstring bsname, ptrfilespec fschild); // 2009-09-13 aradke
+
+ extern OSErr macmakefilespec(const FSRef *fsref, ptrfilespec fs); // 2009-09-06 aradke
+
+ extern boolean macgetfsrefname(const FSRef *fsref, tyfsnameptr fsname); // 2009-09-05 aradke
+
+ extern boolean macgetfsrefnameasbigstring(const FSRef *fsref, bigstring bs); // 2009-09-05 aradke
+
+ extern void macgetfilespecname(const ptrfilespec fs, tyfsnameptr fsname); // 2009-09-05 aradke
+
+ extern void macgetfilespecnameasbigstring(const ptrfilespec fs, bigstring bs); // 2009-09-05 aradke
+
+ extern void clearfsname(tyfsnameptr fsname); // 2009-09-05 aradke
+
+ extern void copyfsname(const tyfsnameptr fssource, tyfsnameptr fsdest); // 2009-09-05 aradke
+
+ unsigned short fsnamelength(const tyfsnameptr fsname); // 2009-09-05 aradke
+
+ extern void bigstringtofsname(const bigstring bs, tyfsnameptr fsname); // 2009-09-05 aradke
+
+ extern void fsnametobigstring(const tyfsnameptr fsname, bigstring bs); // 2009-09-05 aradke
+
+ extern boolean CFStringRefToStr255 (CFStringRef input, StringPtr output); // 2006-08-08 creedon
+
extern OSStatus GetApplicationIconRef ( const ProcessSerialNumber * , const FSSpec* , IconRef * ); // 2006-06-04 creedon
extern OSStatus LSIsApplication( const FSRef *, Boolean *, Boolean * ); // 2006-05-25
@@ -521,7 +519,7 @@
#pragma mark === filepath.c ===
- extern boolean directorytopath ( const ptrfilespec, bigstring);
+extern boolean directorytopath ( const ptrfilespec, bigstring);
extern boolean volumerefnumtopath (short, bigstring);
@@ -543,7 +541,13 @@
extern void initfsdefault (void); /* 2005-07-18 creedon */
-
+#ifdef MACVERSION
+
+ extern OSStatus pathtofsref (bigstring, FSRef *);
+
+#endif // MACVERSION
+
+
#pragma mark === fileverbs.c ===
//extern filecheckdefaultpath (bigstring);
Modified: Frontier/trunk/Common/headers/shelltypes.h
===================================================================
--- Frontier/trunk/Common/headers/shelltypes.h 2009-08-30 19:58:42 UTC (rev 1826)
+++ Frontier/trunk/Common/headers/shelltypes.h 2009-09-16 19:48:48 UTC (rev 1827)
@@ -163,15 +163,39 @@
#ifdef MACVERSION
- typedef struct ExtFSRef {
+ /*
+ 2009-09-03 aradke: FSSpec was deprecated on Mac OS X and FSRef is its replacement.
+ FSSpec could represent a non-existant file as long as its parent directory existed, but FSRef can not.
+ Therefore, we have to extend FSRef with a string to hold the name of the non-existant file.
+ The FSRef field usually points to the parent folder instead of to the file itself (even if the file exists).
+ However, volumes have no parent folder so the FSRef field points to the volume itself in that case.
+
+ We chose a fixed-size Unicode string for the name field to simplify memory management.
+ If we used a CFStringRef we would have to keep track of copying and releasing in lots of places.
- FSRef fsref;
- CFStringRef path;
+ Reference: Apple Technical Note TN2078 -- Migrating to FSRefs & long Unicode names from FSSpecs
+ http://developer.apple.com/legacy/mac/library/technotes/tn2002/tn2078.html
+ */
+
+ typedef struct tyfilespecflags {
+
+ //boolean flvalid; // true: ref and name have been set -- false: empty filespec
+ boolean flvolume; // true: ref points to volume -- false: ref points to parent of file/folder
- } ExtFSRef, *ExtFSRefPtr, **ExtFSRefHandle;
+ } tyfilespecflags;
+
+ typedef struct HFSUniStr255 tyfsname, *tyfsnameptr;
+
+ typedef struct tyfilespec {
+
+ tyfilespecflags flags;
+ FSRef ref;
+ tyfsname name;
- typedef ExtFSRef tyfilespec, *ptrfilespec, **hdlfilespec;
+ } tyfilespec;
+ typedef tyfilespec *ptrfilespec, **hdlfilespec;
+
#endif // MACVERSION
Modified: Frontier/trunk/Common/headers/versions.h
===================================================================
--- Frontier/trunk/Common/headers/versions.h 2009-08-30 19:58:42 UTC (rev 1826)
+++ Frontier/trunk/Common/headers/versions.h 2009-09-16 19:48:48 UTC (rev 1827)
@@ -43,7 +43,7 @@
/* common strings for all targets */
#define APP_COPYRIGHT_FROM "2004"
-#define APP_COPYRIGHT_TILL "2007"
+#define APP_COPYRIGHT_TILL "2009"
/* target-specific strings and version info */
@@ -69,10 +69,10 @@
#define APP_SUBMINOR_VERSION_BCD 0x10 /* sub and minor version in BCD notation */
#define APP_STAGE_CODE 0x40 /* dev = 0x20, alpha = 0x40, beta = 0x60, final = 0x80 */
- #define APP_REVISION_LEVEL 15 /* for non-final releases only */
- #define APP_BUILD_NUMBER 15 /* increment by one for every release, final or not */
+ #define APP_REVISION_LEVEL 16 /* for non-final releases only */
+ #define APP_BUILD_NUMBER 16 /* increment by one for every release, final or not */
- #define APP_VERSION_STRING "10.1a15"
+ #define APP_VERSION_STRING "10.1a16"
#else
@@ -95,10 +95,10 @@
#define APP_SUBMINOR_VERSION_BCD 0x10 /* sub and minor version in BCD notation */
#define APP_STAGE_CODE 0x40 /* dev = 0x20, alpha = 0x40, beta = 0x60, final = 0x80 */
- #define APP_REVISION_LEVEL 15 /* for non-final releases only */
- #define APP_BUILD_NUMBER 15 /* increment by one for every release, final or not */
+ #define APP_REVISION_LEVEL 16 /* for non-final releases only */
+ #define APP_BUILD_NUMBER 16 /* increment by one for every release, final or not */
- #define APP_VERSION_STRING "10.1a15"
+ #define APP_VERSION_STRING "10.1a16"
#endif
#else
@@ -121,10 +121,10 @@
#define APP_SUBMINOR_VERSION_BCD 0x10 /* sub and minor version in BCD notation */
#define APP_STAGE_CODE 0x40 /* dev = 0x20, alpha = 0x40, beta = 0x60, final = 0x80 */
- #define APP_REVISION_LEVEL 15 /* for non-final releases only */
- #define APP_BUILD_NUMBER 15 /* increment by one for every release, final or not */
+ #define APP_REVISION_LEVEL 16 /* for non-final releases only */
+ #define APP_BUILD_NUMBER 16 /* increment by one for every release, final or not */
- #define APP_VERSION_STRING "10.1a15"
+ #define APP_VERSION_STRING "10.1a16"
#endif
@@ -134,60 +134,3 @@
#define APPNAME_SHORT APPNAME /* 2006-02-04 aradke */
#define APPNAME_TM APPNAME /* 2005-01-12 aradke: app names no longer include trademark character */
-
-
-
-
-/* 2006-02-07 aradke: old version switched off */
-
-#if 0
-
-/* Radio version information */
-
-#define radio_major_version 10
-#define radio_major_version_bcd 0x10 /* major version in BCD notation */
-
-#define radio_sub_version 1
-#define radio_minor_version 0
-#define radio_subminor_version_bcd 0x10 /* sub and minor version in BCD notation */
-
-#define radio_stage_code 0x40 /* dev = 0x20, alpha = 0x40, beta = 0x60, final = 0x80 */
-#define radio_revision_level 5 /* for non-final releases only */
-#define radio_build_number 5 /* increment by one for every release, final or not */
-
-#define radio_version_string "10.1a5"
-
-
-/* Frontier version information */
-
-#define frontier_major_version 10
-#define frontier_major_version_bcd 0x10 /* major version in BCD notation */
-
-#define frontier_sub_version 1
-#define frontier_minor_version 0
-#define frontier_subminor_version_bcd 0x10 /* sub and minor version in BCD notation */
-
-#define frontier_stage_code 0x40 /* dev = 0x20, alpha = 0x40, beta = 0x60, final = 0x80 */
-#define frontier_revision_level 5 /* for non-final releases only */
-#define frontier_build_number 5 /* increment by one for every release, final or not */
-
-#define frontier_version_string "10.1a5"
-
-
-/* OPML Editor version information */
-
-#define opml_major_version 10
-#define opml_major_version_bcd 0x10 /* major version in BCD notation */
-
-#define opml_sub_version 1
-#define opml_minor_version 0
-#define opml_subminor_version_bcd 0x10 /* sub and minor version in BCD notation */
-
-#define opml_stage_code 0x40 /* dev = 0x20, alpha = 0x40, beta = 0x60, final = 0x80 */
-#define opml_revision_level 5 /* for non-final releases only */
-#define opml_build_number 5 /* increment by one for every release, final or not */
-
-#define opml_version_string "10.1a5"
-
-#endif /* 2006-02-06 aradke: switched off, see below */
-
Modified: Frontier/trunk/Common/source/about.c
===================================================================
--- Frontier/trunk/Common/source/about.c 2009-08-30 19:58:42 UTC (rev 1826)
+++ Frontier/trunk/Common/source/about.c 2009-09-16 19:48:48 UTC (rev 1827)
@@ -288,9 +288,7 @@
getapplicationfilespec (nil, &programfspec);
- ( void ) extendfilespec ( &programfspec, &programfspec );
-
- err = FSRefMakeFSSpec ( &programfspec.fsref, &fs );
+ err = macgetfsspec (&programfspec, &fs);
if (GetIconRefFromFile (&fs, &iconref, &label) == noErr) {
Modified: Frontier/trunk/Common/source/claycallbacks.c
===================================================================
--- Frontier/trunk/Common/source/claycallbacks.c 2009-08-30 19:58:42 UTC (rev 1826)
+++ Frontier/trunk/Common/source/claycallbacks.c 2009-09-16 19:48:48 UTC (rev 1827)
@@ -830,58 +830,7 @@
return (true);
} /*expanddiskvisit*/
-#endif
-#if 0
-
-static boolean xxxclayinitializeoutline (void) {
-
-
- #if filebrowser
- tyexpandinfo expandinfo;
- expandinfo.hparent = nil; /*special case, see browserfindinsertionpoint*/
-
- expandinfo.ctlevels = 1;
-
- expandinfo.flsettmpbits = false;
-
- return (diskloop (&expanddiskvisit, (long) &expandinfo));
- #endif
-
- #if odbbrowser
- tybrowserspec fsroot;
- tybrowserinfo browserinfo;
- tyexpandinfo expandinfo;
- expandinfo.hparent = nil; /*special case, see browserfindinsertionpoint*/
-
- expandinfo.ctlevels = 1;
-
- expandinfo.flsettmpbits = false;
-
- fsroot.vRefNum = databasedata;
-
- /*
- fsroot.parID = roottable;
-
- setemptystring (fsroot.name);
- */
-
- fsroot.parID = nil;
-
- copystring (nameroottable, fsroot.name);
-
- claygetfileinfo (&fsroot, &browserinfo);
-
- return (clayfolderloop (&fsroot, false, browserexpandvisit, (long) &expandinfo));
-
- #endif
- } /*clayinitializeoutline*/
-
-#endif
-
-
-#if filebrowser
-
static void pushadjective (bigstring adjective, bigstring bs) {
bigstring adj;
Modified: Frontier/trunk/Common/source/dbverbs.c
===================================================================
--- Frontier/trunk/Common/source/dbverbs.c 2009-08-30 19:58:42 UTC (rev 1826)
+++ Frontier/trunk/Common/source/dbverbs.c 2009-09-16 19:48:48 UTC (rev 1827)
@@ -478,8 +478,6 @@
if (!getfilespecvalue (hparam1, pnum, ptrfs))
return (false);
- ( void ) extendfilespec ( ptrfs, ptrfs );
-
for (hodb = hodblist; hodb != nil; hodb = (**hodb).hnext) {
if ( equalfilespecs ( &( **hodb ).fs, ptrfs ) ) {
@@ -641,8 +639,6 @@
if (!getbooleanvalue (hparam1, 2, &odbrec.flreadonly))
return (false);
-
- ( void ) extendfilespec ( &odbrec.fs, &odbrec.fs );
w = shellfindfilewindow ( &odbrec.fs );
Modified: Frontier/trunk/Common/source/file.c
===================================================================
--- Frontier/trunk/Common/source/file.c 2009-08-30 19:58:42 UTC (rev 1826)
+++ Frontier/trunk/Common/source/file.c 2009-09-16 19:48:48 UTC (rev 1827)
@@ -55,6 +55,8 @@
boolean equalfilespecs ( const ptrfilespec fs1, const ptrfilespec fs2 ) {
//
+ // 2009-09-03 aradke: converted FSRef name field from CFStringRef to HFSUniStr255
+ //
// 2006-06-18 creedon: for Mac, FSRef-ized
//
// 5.0a25 dmb: until we set the volumeID to zero for all Win fsspecs, we must not compare them here
@@ -62,22 +64,25 @@
#ifdef MACVERSION
- if ( FSCompareFSRefs ( &( *fs1 ).fsref, &( *fs2 ).fsref ) != noErr )
- return ( false );
+ CFStringRef cfname1, cfname2;
+ boolean flequal;
+
+ if (fs1->flags.flvolume != fs2->flags.flvolume)
+ return (false);
+
+ if (FSCompareFSRefs (&fs1->ref, &fs2->ref) != noErr)
+ return (false);
- // seems like the checking could be improved for paths, what if one is NULL and the other is not?
-
- if ( ( ( *fs1 ).path != NULL ) && ( ( *fs2 ).path != NULL ) )
- if ( CFStringCompare ( ( *fs1 ).path, ( *fs2 ).path, 0 ) != kCFCompareEqualTo )
- return ( false );
-
- bigstring bs1, bs2;
+ cfname1 = CFStringCreateWithCharacters (kCFAllocatorDefault, fs1->name.unicode, fs1->name.length);
+ cfname2 = CFStringCreateWithCharacters (kCFAllocatorDefault, fs2->name.unicode, fs2->name.length);
+
+ flequal = ( CFStringCompare (cfname1, cfname2, 0) == kCFCompareEqualTo );
- getfsfile ( fs1, bs1 );
- getfsfile ( fs2, bs2 );
+ CFRelease (cfname1);
+ CFRelease (cfname2);
+
+ return (flequal);
- return ( equalstrings ( bs1, bs2 ) );
-
#endif
#ifdef WIN95VERSION
@@ -484,7 +489,7 @@
FSCatalogInfo catalogInfo;
OSErr err;
- err = FSGetCatalogInfo ( &( *fs ).fsref, kFSCatInfoVolume, &catalogInfo, NULL, NULL, NULL );
+ err = FSGetCatalogInfo ( &fs->ref, kFSCatInfoVolume, &catalogInfo, NULL, NULL, NULL );
(*pb).volumeParam.ioVRefNum = catalogInfo.volume;
@@ -524,29 +529,25 @@
static boolean filecreateandopen ( ptrfilespec fs, OSType creator, OSType filetype, hdlfilenum *fnum) {
-
+
//
+ // 2009-09-03 aradke: converted tyfilespec.name field from CFStringRef to HFSUniStr255
+ //
// 2006-09-15 creedon: for Mac, FSRef-ized
//
#ifdef MACVERSION
- HFSUniStr255 name;
+ FSRef fsref;
OSErr err;
setfserrorparam ( fs );
- CFStringRefToHFSUniStr255 ( ( *fs ).path, &name );
+ err = FSCreateFileUnicode ( &( *fs ).ref, (*fs).name.length, (*fs).name.unicode, kFSCatInfoNone, NULL, &fsref, NULL );
- err = FSCreateFileUnicode ( &( *fs ).fsref, name.length, name.unicode, kFSCatInfoNone, NULL, &( *fs ).fsref, NULL );
-
if ( oserror ( err ) )
return (false);
- CFRelease ( ( *fs ).path );
-
- ( *fs ).path = NULL; // clear out path
-
HFSUniStr255 dataforkname;
err = FSGetDataForkName ( &dataforkname );
@@ -554,11 +555,11 @@
if ( oserror ( err ) )
return ( false );
- err = FSOpenFork ( &( *fs ).fsref, dataforkname.length, dataforkname.unicode, fsRdWrPerm, fnum );
+ err = FSOpenFork ( &fsref, dataforkname.length, dataforkname.unicode, fsRdWrPerm, fnum );
if ( oserror ( err ) ) {
- FSClose (*fnum);
+ FSCloseFork (*fnum); // FIXME: is *fnum actually valid if FSOpenFork failed?
deletefile (fs);
@@ -566,7 +567,7 @@
}
- FSSetNameLocked ( &( *fs ).fsref );
+ FSSetNameLocked ( &fsref );
return (true);
@@ -603,15 +604,12 @@
//
boolean flfolder;
- tyfilespec fst;
- ( void ) extendfilespec ( fs, &fst );
+ if ( fileexists ( fs, &flfolder ) ) { // file exists, delete it
- if ( fileexists ( &fst, &flfolder ) ) { // file exists, delete it
-
//WriteToConsole("We're deleting a file that already exists. No idea why.");
- if ( ! deletefile ( &fst ) )
+ if ( ! deletefile ( fs ) )
return ( false );
}
@@ -633,7 +631,7 @@
#ifdef MACVERSION
- OSErr err;
+ FSRef fsref;
short perm;
setfserrorparam ( fs ); // in case error message takes a filename parameter
@@ -645,21 +643,20 @@
HFSUniStr255 dataforkname;
- err = FSGetDataForkName ( &dataforkname );
+ if ( oserror ( FSGetDataForkName ( &dataforkname ) ) )
+ return ( false );
- if ( oserror ( err ) )
+ if ( oserror ( macgetfsref ( fs, &fsref ) ) )
return ( false );
- err = FSOpenFork ( &( *fs ).fsref, dataforkname.length, dataforkname.unicode, perm, fnum );
-
- if ( oserror ( err ) ) {
+ if ( oserror ( FSOpenFork ( &fsref, dataforkname.length, dataforkname.unicode, perm, fnum ) ) ) {
*fnum = 0;
return (false);
}
- FSSetNameLocked ( &( *fs ).fsref );
+ FSSetNameLocked ( &fsref );
return (true);
@@ -768,16 +765,17 @@
#ifdef MACVERSION
- OSErr err;
+ FSRef fsref;
setfserrorparam ( fs ); // in case error message takes a filename parameter
+
+ if ( oserror ( macgetfsref ( fs, &fsref ) ) )
+ return ( false );
- FSClearNameLocked ( &( *fs ).fsref );
+ FSClearNameLocked ( &fsref );
+
+ return ( ! oserror ( FSDeleteObject ( &fsref ) ) );
- err = FSDeleteObject ( &( *fs ).fsref );
-
- return ( ! oserror ( err ) );
-
#endif
#ifdef WIN95VERSION
@@ -824,6 +822,8 @@
//
// can't call filegetinfo because it has an error message if the file isn't found.
//
+ // 2009-09-03 aradke: converted tyfilespec.name field from CFStringRef to HFSUniStr255
+ //
// 2006-06-19 creedon: Mac OS X bundles/packages are not considered folders
//
// for Mac, FSRef-ized
@@ -838,24 +838,25 @@
#ifdef MACVERSION
FSCatalogInfo catalogInfo;
+ FSRef fsref;
*flfolder = false;
- if ( ( *fs ).path != NULL )
- return ( false );
+ if (macgetfsref(fs, &fsref) != noErr)
+ return (false);
- if ( FSGetCatalogInfo ( &( *fs ).fsref, kFSCatInfoNodeFlags, &catalogInfo, NULL, NULL, NULL ) != noErr )
- return ( false );
+ if (FSGetCatalogInfo(&fsref, kFSCatInfoNodeFlags, &catalogInfo, NULL, NULL, NULL) != noErr)
+ return (false);
- *flfolder = ( ( catalogInfo.nodeFlags & kFSNodeIsDirectoryMask ) != 0 );
+ *flfolder = ((catalogInfo.nodeFlags & kFSNodeIsDirectoryMask) != 0);
/* Mac OS X bundles/packages are not considered folders */ {
boolean flisapplication, flisbundle;
- LSIsApplication ( &( *fs ).fsref, &flisapplication, &flisbundle );
+ LSIsApplication (&fsref, &flisapplication, &flisbundle);
- if ( flisapplication || flisbundle )
+ if (flisapplication || flisbundle)
*flfolder = false;
}
@@ -901,215 +902,3 @@
} // fileexists
-
-#ifdef MACVERSION
-
- static OSErr FSRefGetName ( const FSRef *fsr, CFStringRef *name ) {
-
- //
- // the caller must dispose of the CFString
- //
- // 2007-08-01 creedon: changed variable fsRef to fsr to reduce
- // confusion with FSRef definition
- //
- // 2006-07-06 creedon: created
- //
-
- HFSUniStr255 hname;
- OSErr err = FSGetCatalogInfo ( fsr, kFSCatInfoNone, NULL, &hname,
- NULL, NULL );
-
- if ( err == noErr )
- *name = CFStringCreateWithCharacters ( kCFAllocatorDefault,
- hname.unicode, hname.length );
-
- return ( err );
-
- } // FSRefGetName
-
-
- boolean CFStringRefToStr255 ( CFStringRef input, StringPtr output ) {
-
- //
- // 2006-08-08 creedon: created, cribbed from < http://developer.apple.com/carbon/tipsandtricks.html#CFStringFromUnicode >
- //
-
- CFIndex usedBufLen;
-
- CFStringGetBytes ( input, CFRangeMake ( 0, MIN ( CFStringGetLength ( input ), 255 ) ),
- kCFStringEncodingMacRoman, '^', false, &( output [ 1 ] ), 255, &usedBufLen );
-
- output [ 0 ] = usedBufLen;
-
- if ( output [ 0 ] == 0 )
- return ( false );
-
- return ( true );
-
- } // CFStringRefToStr255
-
-
- boolean HFSUniStr255ToStr255 ( ConstHFSUniStr255Param input, StringPtr output ) {
-
- //
- // 2006-07-06 creedon; created
- //
-
- CFStringRef csr;
-
- csr = CFStringCreateWithCharacters ( kCFAllocatorDefault, input -> unicode, input -> length );
-
- CFStringRefToStr255 ( csr, output );
-
- CFRelease ( csr );
-
- return ( true );
-
- } // HFSUniStr255ToStr255
-
-
- boolean FSRefGetNameStr255 ( const FSRef *fsRef, Str255 bsname ) {
-
- //
- // 2006-07-06 creedon; created
- //
-
- CFStringRef csr;
- OSErr err = FSRefGetName ( fsRef, &csr );
-
- if ( err != noErr )
- return ( false );
-
- if ( csr == NULL )
- return ( false );
-
- if ( ! CFStringGetPascalString ( csr, bsname, 256, kCFStringEncodingMacRoman ) )
- return ( false );
-
- CFRelease ( csr );
-
- return ( true );
-
- } // FSRefGetNameStr255
-
-
- boolean bigstringToHFSUniStr255 ( const bigstring bs, HFSUniStr255 *output ) {
-
- //
- // 2006-07-06 creedon; created
- //
-
- CFStringRef csr = CFStringCreateWithPascalString ( kCFAllocatorDefault, bs, kCFStringEncodingMacRoman );
-
- ( *output ).length = CFStringGetLength ( csr );
-
- CFStringGetCharacters ( csr, CFRangeMake ( 0, ( *output ).length ), ( *output ).unicode );
-
- CFRelease ( csr );
-
- return ( true );
-
- } // bigstringToHFSUniStr255
-
-
- boolean CFStringRefToHFSUniStr255 ( CFStringRef input, HFSUniStr255 *output ) {
-
- //
- // 2006-08-11 creedon: created, cribbed from < http://developer.apple.com/carbon/tipsandtricks.html#CFStringFromUnicode >
- //
-
- ( *output ).length = CFStringGetBytes ( input, CFRangeMake ( 0, MIN ( CFStringGetLength ( input ), 255 ) ),
- kCFStringEncodingUnicode, 0, false, ( UInt8 * ) ( *output ).unicode, 255, NULL );
-
- if ( ( *output ).length == 0 )
- return ( false );
-
- return ( true );
-
- } // CFStringRefToHFSUniStr255
-
-
-/* 2006-08-11 creedon: cribbed from MoreFilesX.c and modded to work with Str255 */
-
-/* macro for casting away const when you really have to */
-#define CONST_CAST(type, const_var) (*(type*)((void *)&(const_var)))
-
-OSErr
-HFSNameGetUnicodeName255 (
- ConstStr255Param hfsName,
- TextEncoding textEncodingHint,
- HFSUniStr255 *unicodeName)
-{
- ByteCount unicodeByteLength;
- OSStatus result;
- UnicodeMapping uMapping;
- TextToUnicodeInfo tuInfo;
- ByteCount pascalCharsRead;
-
- /* check parameters */
- require_action(NULL != unicodeName, BadParameter, result = paramErr);
-
- /* make sure output is valid in case we get errors or there's nothing to convert */
- unicodeName->length = 0;
-
- if ( 0 == StrLength(CONST_CAST(StringPtr, hfsName)) )
- {
- result = noErr;
- }
- else
- {
- /* if textEncodingHint is kTextEncodingUnknown, get a "default" textEncodingHint */
- if ( kTextEncodingUnknown == textEncodingHint )
- {
- ScriptCode script;
- RegionCode region;
-
- script = GetScriptManagerVariable(smSysScript);
- region = GetScriptManagerVariable(smRegionCode);
- result = UpgradeScriptInfoToTextEncoding(script, kTextLanguageDontCare, region,
- NULL, &textEncodingHint);
- if ( paramErr == result )
- {
- /* ok, ignore the region and try again */
- result = UpgradeScriptInfoToTextEncoding(script, kTextLanguageDontCare,
- kTextRegionDontCare, NULL, &textEncodingHint);
- }
- if ( noErr != result )
- {
- /* ok... try something */
- textEncodingHint = kTextEncodingMacRoman;
- }
- }
-
- uMapping.unicodeEncoding = CreateTextEncoding(kTextEncodingUnicodeDefault,
- kUnicodeCanonicalDecompVariant, kUnicode16BitFormat);
- uMapping.otherEncoding = GetTextEncodingBase(textEncodingHint);
- uMapping.mappingVersion = kUnicodeUseHFSPlusMapping;
-
- result = CreateTextToUnicodeInfo(&uMapping, &tuInfo);
- require_noerr(result, CreateTextToUnicodeInfo);
-
- result = ConvertFromTextToUnicode(tuInfo, hfsName[0], &hfsName[1],
- 0, /* no control flag bits */
- 0, NULL, 0, NULL, /* offsetCounts & offsetArrays */
- sizeof(unicodeName->unicode), /* output buffer size in bytes */
- &pascalCharsRead, &unicodeByteLength, unicodeName->unicode);
- require_noerr(result, ConvertFromTextToUnicode);
-
- /* convert from byte count to char count */
- unicodeName->length = unicodeByteLength / sizeof(UniChar);
-
-ConvertFromTextToUnicode:
-
- /* verify the result in debug builds -- there's really not anything you can do if it fails */
- verify_noerr(DisposeTextToUnicodeInfo(&tuInfo));
- }
-
-CreateTextToUnicodeInfo:
-BadParameter:
-
- return ( result );
-}
-
- #endif
-
Modified: Frontier/trunk/Common/source/filedialog.c
===================================================================
--- Frontier/trunk/Common/source/filedialog.c 2009-08-30 19:58:42 UTC (rev 1826)
+++ Frontier/trunk/Common/source/filedialog.c 2009-09-16 19:48:48 UTC (rev 1827)
@@ -535,9 +535,10 @@
//
tysfdata sfdata;
- FSSpec *fs = &sfdata.sfreply.sfFile, fspect;
+ FSSpec *fs = &sfdata.sfreply.sfFile;
+ FSSpec fspect;
OSErr err = noErr;
- OSType filetype = NULL;
+ OSType filetype = 0;
clearbytes ( &fspect, sizeof ( fspect ) );
@@ -547,23 +548,9 @@
clearbytes (&sfdata, sizeof (sfdata));
if ( sfverb == sfputfileverb ) {
-
- extendfilespec ( fspec, fspec );
-
- if ( ( *fspec ).path == NULL )
- FSGetCatalogInfo ( &( *fspec ).fsref, kFSCatInfoNone, NULL, NULL, &fspect, NULL );
- else {
- FSCatalogInfo catalogInfo;
-
- FSGetCatalogInfo ( &( *fspec ).fsref, kFSCatInfoVolume | kFSCatInfoNodeID, &catalogInfo, NULL, NULL,
- NULL );
-
- fspect.vRefNum = catalogInfo.volume;
- fspect.parID = catalogInfo.nodeID;
-
- CFStringRefToStr255 ( ( *fspec ).path, fspect.name );
-
- }
+
+ if (oserror (macgetfsspec (fspec, &fspect)))
+ return (false);
}
if ( filetypes != NULL )
@@ -597,7 +584,7 @@
case sfputfileverb:
if(gCanUseNavServ) {
- err = TimsPutFile ( bsprompt, ( *fs ).name, &sfdata.sfreply, filetype );
+ err = TimsPutFile (bsprompt, ( *fs ).name, &sfdata.sfreply, filetype);
}
break;
@@ -626,31 +613,32 @@
if (userCanceledErr == err)
return false;
- if(oserror(err))
+ if (oserror(err))
return false;
- if ( sfdata.sfreply.sfGood ) { // canonize
+ if (sfdata.sfreply.sfGood) { // canonize
+ FSRef fsref;
bigstring bs;
- boolean fl = ( *fs ).parID == fsRtParID;
- HFSUniStr255 name;
- setemptystring ( bs );
+ setemptystring (bs);
- if ( fl )
- copystring ( ( *fs ).name, bs );
+ fspec->flags.flvolume = (fs->parID == fsRtParID);
+
+ if (fspec->flags.flvolume)
+ copystring (fs->name, bs);
- err = FSMakeFSRef ( ( *fs ).vRefNum, ( *fs ).parID, bs, &( *fspec ).fsref );
+ err = FSMakeFSRef (fs->vRefNum, fs->parID, bs, &fsref);
- if ( ! fl ) {
-
- err = HFSNameGetUnicodeName ( ( *fs ).name, kTextEncodingUnknown, &name );
-
- ( *fspec ).path = CFStringCreateWithCharacters ( kCFAllocatorDefault, name.unicode, name.length );
-
+ if (fspec->flags.flvolume) {
+ fspec->ref = fsref;
+ HFSNameGetUnicodeName (fs->name, kTextEncodingUnknown, &fspec->name);
}
+ else {
+ macmakefilespec (&fsref, fspec);
+ }
- return ( true );
+ return (true);
}
@@ -1025,7 +1013,7 @@
NavDialogOptions dialogOptions;
NavEventUPP eventProc = NewNavEventUPP ( NavEventProc );
- if ( filetype == NULL )
+ if ( filetype == 0 )
filetype = 'TEXT';
err = NavGetDefaultDialogOptions ( &dialogOptions );
@@ -1050,6 +1038,7 @@
if (err == noErr) {
outReply->sfReplacing = reply.replacing;
+
FSMakeFSSpec (documentFSSpec.vRefNum, documentFSSpec.parID, documentFSSpec.name, &(outReply->sfFile));
outReply->sfGood = true;
Modified: Frontier/trunk/Common/source/fileloop.c
===================================================================
--- Frontier/trunk/Common/source/fileloop.c 2009-08-30 19:58:42 UTC (rev 1826)
+++ Frontier/trunk/Common/source/fileloop.c 2009-09-16 19:48:48 UTC (rev 1827)
@@ -195,45 +195,6 @@
return (false);
} /*diskinitloop*/
-
- boolean diskloop (tyfileloopcallback diskcallback, long refcon) {
-
- /*
- dmb 9/21/93: filegetvolumeinfo takes a vRefNum, not a string.
- */
-
- HVolumeParam pb;
- short ix;
-
- clearbytes (&pb, sizeof (pb)); /*init all fields to zero*/
-
- ix = 1; /*start with file index 1*/
-
- while (true) {
-
- bigstring bsvolume;
- tyfileinfo info;
- OSErr errcode;
-
- pb.ioVolIndex = ix++;
-
- pb.ioNamePtr = bsvolume;
-
- errcode = PBHGetVInfoSync ((HParmBlkPtr) &pb);
-
- if (errcode == nsvErr) /*not an error, just ran out of volumes*/
- return (true);
-
- if (oserror (errcode))
- return (false);
-
- filegetvolumeinfo (pb.ioVRefNum, &info);
-
- if (!(*diskcallback) (bsvolume, &info, refcon))
- return (false);
- } /*while*/
- } /*diskloop*/
-
#endif // MACVERSION
@@ -296,6 +257,8 @@
#ifdef MACVERSION
#pragma unused(filefilter)
+
+ // FIXME: fileloops should really be rewritten using FSRefs instead of pre-carbon apis
//
// a conglomeration of filemanager incantations which sets up a UserLand
@@ -322,12 +285,10 @@
short ix;
hdllistrecord hlist;
FSSpec fs;
- tyfilespec fst2;
- ( void ) extendfilespec ( fst, &fst2 );
-
- FSRefMakeFSSpec ( &fst2.fsref, &fs ); // might need to do more checking here to handle path
-
+ if (oserror (macgetfsspec (fst, &fs) ) )
+ return (false);
+
clearbytes (&pb, sizeof (CInfoPBRec)); // init all fields to zero
setoserrorparam ((ptrstring) fs.name);
@@ -535,7 +496,8 @@
tyfileinfo info;
OSErr ec;
- FSRefMakeFSSpec ( &( *pfs ).fsref, &fs ); // might need to do more checking here to handle path
+ if (oserror (macgetfsspec (pfs, &fs) ) )
+ return (false);
setoserrorparam ((ptrstring) fs.name);
@@ -681,6 +643,7 @@
long dirid;
OSErr err;
FSSpec fsfile;
+ FSRef fsref;
if (!opgetlisthandle ((**h).hfilelist, (**h).ixdirectory++, nil, &hdata))
return (false);
@@ -699,9 +662,9 @@
*flfolder = true; /*3.0.2b1*/
- FSpMakeFSRef ( &fsfile, &( *fsfilet ).fsref );
+ FSpMakeFSRef ( &fsfile, &fsref );
- ( void ) getfilespecparent ( &( *fsfilet ) );
+ macmakefilespec ( &fsref, fsfilet );
return (true);
@@ -727,12 +690,12 @@
if ((err == noErr) || (err == fnfErr)) { // 3.0.4b1 dmb
- err = FSpMakeFSRef ( &fsfile, &( *fsfilet ).fsref );
+ err = FSpMakeFSRef ( &fsfile, &fsref );
+ macmakefilespec ( &fsref, fsfilet );
+
if ( *flfolder )
( void ) fileisfolder ( fsfilet, flfolder );
-
- ( void ) getfilespecparent ( &( *fsfilet ) );
return ( true );
@@ -749,13 +712,13 @@
copystring (bs, fsfile.name);
- FSpMakeFSRef ( &fsfile, &( *fsfilet ).fsref );
+ FSpMakeFSRef ( &fsfile, &fsref );
+ macmakefilespec ( &fsref, fsfilet );
+
if ( *flfolder )
( void ) fileisfolder ( fsfilet, flfolder );
- ( void ) getfilespecparent ( &( *fsfilet ) );
-
return ( true );
}
Modified: Frontier/trunk/Common/source/fileops.c
===================================================================
--- Frontier/trunk/Common/source/fileops.c 2009-08-30 19:58:42 UTC (rev 1826)
+++ Frontier/trunk/Common/source/fileops.c 2009-09-16 19:48:48 UTC (rev 1827)
@@ -140,19 +140,15 @@
bigstring bs;
- if ( ( *fs ).path != NULL )
- CFStringRefToStr255 ( ( *fs ).path, bs );
- else
- if ( FSRefValid ( &( *fs ).fsref ) )
- FSRefGetNameStr255 ( &( *fs ).fsref, bs );
+ macgetfilespecnameasbigstring(fs, bs);
+
+ setoserrorparam(bs);
- setoserrorparam ( bs );
-
#endif // MACVERSION
#ifdef WIN95VERSION
- setoserrorparam ((ptrstring) fsname (fs));
+ setoserrorparam((ptrstring) fsname(fs));
#endif
@@ -279,20 +275,28 @@
*/
OSErr err;
+ FSRef fsref;
setfserrorparam ( fs ); // in case error message takes a filename parameter
+
+ err = macgetfsref(fs, &fsref);
- clearbytes ( pb, sizeof ( *pb ) );
- clearbytes ( catinfo, sizeof ( *catinfo ) );
+ if (err == noErr) {
- ( *pb ).catInfo = catinfo;
+ clearbytes(pb, sizeof(*pb));
+ clearbytes(catinfo, sizeof(*catinfo));
+
+ pb->catInfo = catinfo;
+
+ pb->ref = &fsref;
+ pb->whichInfo = kFSCatInfoGettableInfo;
+
+ err = PBGetCatalogInfoSync(pb);
+
+ pb->ref = NULL; // fsref is a local about to disappear
+ }
- ( *pb ).ref = &( *fs ).fsref;
- ( *pb ).whichInfo = kFSCatInfoGettableInfo;
-
- err = PBGetCatalogInfoSync ( pb );
-
- return ( ! oserror ( err ) );
+ return (!oserror(err));
} /* getmacfileinfo */
@@ -306,14 +310,14 @@
clearbytes (pb, sizeof (*pb));
- (*pb).hFileInfo.ioNamePtr = (StringPtr) (*fs).name;
+ pb->hFileInfo.ioNamePtr = (StringPtr) (*fs).name;
- (*pb).hFileInfo.ioVRefNum = (*fs).vRefNum;
+ pb->hFileInfo.ioVRefNum = (*fs).vRefNum;
- (*pb).hFileInfo.ioDirID = (*fs).parID;
+ pb->hFileInfo.ioDirID = (*fs).parID;
return (!oserror (PBGetCatInfoSync (pb)));
- } /*getmacfileinfo*/
+ } /*getmacfileinfocipbr*/
static boolean setmacfileinfo ( const ptrfilespec fs, FSRefParam *pb ) {
@@ -322,16 +326,29 @@
2.1b2 dmb: new fsspec-based version
*/
- setfserrorparam ( fs ); /*in case error message takes a filename parameter*/
+ OSErr err;
+ FSRef fsref;
- ( *pb ).ref = &( *fs ).fsref;
- ( *pb ).whichInfo = kFSCatInfoSettableInfo;
+ setfserrorparam(fs); /*in case error message takes a filename parameter*/
+
+ err = macgetfsref(fs, &fsref);
+
+ if (err == noErr) {
+
+ pb->ref = &fsref;
+
+ pb->whichInfo = kFSCatInfoSettableInfo;
- return ( ! oserror ( PBSetCatalogInfoSync ( pb ) ) );
+ err = PBSetCatalogInfoSync(pb);
+
+ pb->ref = NULL; // fsref is a local about to disappear
+ }
+
+ return (!oserror(err));
} /* setmacfileinfo */
- static boolean touchparentfolder ( const ptrfilespec fs ) {
+ static boolean touchparentfolder(const ptrfilespec fs) {
//
// touch the file date of the parent folder of fs
@@ -339,12 +356,12 @@
// 2006-06-18 creedon: FSRef-ized
//
- tyfilespec fsfolder = { { { 0 } }, 0 };
+ tyfilespec fsfolder;
- if ( FSGetCatalogInfo ( &( *fs ).fsref, kFSCatInfoNone, NULL, NULL, NULL, &fsfolder.fsref ) != noErr )
+ if (macgetfilespecparent(fs, &fsfolder) != noErr)
return (false);
- setfilemodified ( &fsfolder, timenow ( ) );
+ setfilemodified(&fsfolder, timenow());
return (true);
@@ -898,7 +915,7 @@
#endif
-boolean filegetinfo ( const ptrfilespec fs, tyfileinfo *info ) {
+boolean filegetinfo (const ptrfilespec fs, tyfileinfo *info) {
//
// 2006-06-25 creedon: for Mac, FSRef-ized
@@ -907,31 +924,26 @@
//
#ifdef MACVERSION
-
- setfserrorparam ( fs ); // in case error message takes a filename parameter
-
- if ( ( *fs ).path != NULL )
- return ( ! oserror ( fnfErr ) );
-
- if ( ! FSRefValid ( &( *fs ).fsref ) )
- return ( false );
-
+
+ FSRef fsref;
FSCatalogInfo catinfo;
FSRefParam pb;
- OSErr err;
+
+ setfserrorparam(fs); // in case error message takes a filename parameter
- clearbytes ( &pb, sizeof ( pb ) );
+ if (oserror(macgetfsref(fs, &fsref)))
+ return (false);
+
+ clearbytes(&pb, sizeof(pb));
pb.catInfo = &catinfo;
- pb.ref = &( *fs ).fsref;
+ pb.ref = &fsref;
pb.whichInfo = kFSCatInfoGettableInfo;
- err = PBGetCatalogInfoSync ( &pb );
-
- if ( oserror ( err ) )
- return ( false );
+ if (oserror(PBGetCatalogInfoSync(&pb)))
+ return (false);
- filegetinfofrompb ( &pb, info );
+ filegetinfofrompb(&pb, info);
#endif // MACVERSION
@@ -1194,22 +1206,22 @@
#ifdef MACVERSION
+ FSRef fsref;
OSErr err;
- if ( flvisible ) {
+ if (oserror (macgetfsref (fs, &fsref)))
+ return (false);
- err = FSClearInvisible ( &( *fs ).fsref );
-
- if ( err != noErr )
- return ( true );
+ if (flvisible) {
+ err = FSClearInvisible (&fsref);
}
else {
- err = FSSetInvisible ( &( *fs ).fsref );
-
- if ( err != noErr )
- return ( true );
+ err = FSSetInvisible (&fsref);
}
+ if (oserror (err))
+ return (false);
+
touchparentfolder (fs);
#endif
@@ -1299,17 +1311,21 @@
// Mac OS X bundles/packages are not considered folders
+ FSRef fsref;
boolean flisapplication, flisbundle;
- LSIsApplication ( &( *fs ).fsref, &flisapplication, &flisbundle );
+ if (macgetfsref (fs, &fsref) == noErr) {
+
+ if (LSIsApplication (&fsref, &flisapplication, &flisbundle) == noErr) {
- if ( flisapplication || flisbundle ) {
-
- *flfolder = false;
-
- return ( true );
-
- }
+ if (flisapplication || flisbundle) {
+
+ *flfolder = false;
+
+ return (true);
+ }
+ }
+ }
#endif
#ifdef WIN95VERSION
@@ -1339,7 +1355,7 @@
*flfolder = info.flfolder;
- return ( true );
+ return (true);
} // fileisfolder
@@ -1351,23 +1367,23 @@
//
#ifdef MACVERSION
-
- bigstring bsname;
- getfsfile ( fs, bsname );
-
- if ( isemptystring ( bsname ) )
- return ( false );
+ FSCatalogInfo catalogInfo;
+ FSRef fsref;
- FSCatalogInfo catalogInfo;
- OSErr err;
+ if (!fs->flags.flvolume)
+ return (false);
+
+ if (macgetfsref (fs, &fsref) != noErr)
+ return (false);
+
+ clearbytes (&catalogInfo, longsizeof (catalogInfo));
+
+ if (FSGetCatalogInfo (&fsref, kFSCatInfoGettableInfo, &catalogInfo, NULL, NULL, NULL) != noErr)
+ return (false);
+
+ return (catalogInfo.parentDirID == fsRtParID);
- clearbytes ( &catalogInfo, longsizeof ( catalogInfo ) );
-
- err = FSGetCatalogInfo ( &( *fs ).fsref, kFSCatInfoGettableInfo, &catalogInfo, NULL, NULL, NULL ); // kFSCatInfoParentDirID
-
- return ( catalogInfo.parentDirID == fsRtParID );
-
#endif
#ifdef WIN95VERSION
@@ -1794,68 +1810,40 @@
#ifdef MACVERSION
-extern OSStatus LSIsApplication( const FSRef *inRef, Boolean *outIsApplication,
- Boolean *outIsBundled )
-{
- LSItemInfoRecord info;
- OSStatus err = LSCopyItemInfoForRef( inRef, kLSRequestBasicFlagsOnly,
- &info );
-
- if ( err == noErr )
- {
- *outIsApplication = ( kLSItemInfoIsApplication &info.flags ) != 0;
- *outIsBundled = ( kLSItemInfoIsPackage &info.flags ) != 0;
- }
- return( err );
-}
+ OSStatus LSIsApplication (const FSRef *inRef, Boolean *outIsApplication, Boolean *outIsBundled) {
- //
- // ConvertCStringToHFSUniStr is from HelloWorldTool.c of FSCopyObject with no changes, I didn't want to include
- // HelloWorldTool.c in this project because there is a whole bunch of code we don't need
- //
+ LSItemInfoRecord info;
+ OSStatus err;
- #define kCouldNotCreateCFString 4
- #define kCouldNotGetStringData 5
+ err = LSCopyItemInfoForRef (inRef, kLSRequestBasicFlagsOnly, &info);
- static OSErr ConvertCStringToHFSUniStr(const char* cStr, HFSUniStr255 *uniStr)
- {
- OSErr err = noErr;
- CFStringRef tmpStringRef = CFStringCreateWithCString( kCFAllocatorDefault, cStr, kCFStringEncodingMacRoman );
- if( tmpStringRef != NULL )
- {
- if( CFStringGetCString( tmpStringRef, (char*)uniStr->unicode, sizeof(uniStr->unicode), kCFStringEncodingUnicode ) )
- uniStr->length = CFStringGetLength( tmpStringRef );
- else
- err = kCouldNotGetStringData;
-
- CFRelease( tmpStringRef );
- }
- else
- err = kCouldNotCreateCFString;
-
- return err;
- }
+ if (err == noErr) {
+ *outIsApplication = (kLSItemInfoIsApplication & info.flags) != 0;
+ *outIsBundled = (kLSItemInfoIsPackage & info.flags) != 0;
+ }
+ return (err);
+ }/*LSIsApplication*/
+
#endif
+
boolean copyfile ( const ptrfilespec fsource, const ptrfilespec fdest, boolean fldata, boolean flresources ) {
//
// create a copy of the indicated file in the destination folder or volume, with the indicated name.
//
// 2006-06-18 creedon: for Mac, FSRef-ized
+ // combined the two definitions (Mac and Win) of this function into one, deleted old code, see
+ // revision 1329, use FSCopyObject code
//
- // combined the two definitions (Mac and Win) of this function into one deleted old code, see
- // revision 1329 use FSCopyObject code
- //
// 5.0.1 dmb: for Windows, if the file exists, overwrite it.
//
#ifdef MACVERSION
- bigstring bs;
boolean flsourcefolder;
- HFSUniStr255 name;
+ FSRef fsrefsource;
if ( ! fileisfolder ( fsource, &flsourcefolder ) )
return ( false );
@@ -1869,15 +1857,11 @@
return ( true );
}
-
- getfsfile ( fdest, bs );
- convertpstring ( bs );
-
- if ( oserror ( ConvertCStringToHFSUniStr ( bs , &name ) ) )
+ if ( oserror ( macgetfsref ( fsource, &fsrefsource ) ) )
return ( false );
- if ( oserror ( FSCopyObject ( &( *fsource ).fsref, &( *fdest ).fsref, 0, kFSCatInfoNone, kDupeActionReplace, &name,
+ if ( oserror ( FSCopyObject ( &fsrefsource, &fdest->ref, 0, kFSCatInfoNone, kDupeActionReplace, &fdest->name,
false, false, NULL, NULL, NULL, NULL ) ) )
return ( false );
@@ -1983,7 +1967,6 @@
getfsvolume ( &fs, ( long * ) vnum );
-
return (true);
} // pathtovolume
@@ -2015,8 +1998,8 @@
short ixlist;
OSType foldertype;
long attrs;
- OSErr err = errorNone;
bigstring bsfirst;
+ FSRef fsref;
if (!(gestalt (gestaltFindFolderAttr, &attrs) && (attrs & (1 << gestaltFindFolderPresent))))
return (false);
@@ -2038,29 +2021,32 @@
else {
firstword (bsfolder, chspace, bsfirst);
- if (findstringlist (bsfirst, specialfolderlistnumber, &ixlist))
+ if (findstringlist (bsfirst, specialfolderlistnumber, &ixlist))
{
foldertype = specialfolders [ixlist];
//temp items, we want to redirect to the users domain.
//if we don't do this then it is a read only directory at the root.
- if (ixlist == 11)
+ if (ixlist == 11) {
+
vnum = kUserDomain;
-
- }
- else
- err = dirNFErr;
+ }
+ }
+ else {
+
+ oserror ( dirNFErr );
+
+ return ( false );
+ }
}
- if ( err == noErr ) {
-
- err = FSFindFolder ( vnum, foldertype, flcreate, &( *fs ).fsref );
+ if ( oserror ( FSFindFolder ( vnum, foldertype, flcreate, &fsref ) ) )
+ return ( false );
- ( void ) getfilespecparent ( fs );
-
- }
+ if ( oserror ( macmakefilespec ( &fsref, fs ) ) )
+ return ( false );
- return ( ! oserror ( err ) );
+ return ( true );
#endif
@@ -2514,7 +2500,7 @@
//
long vnum;
- OptionBits flags = NULL;
+ OptionBits flags = 0;
pid_t dissenter;
getfsvolume ( fs, &vnum );
@@ -2580,6 +2566,7 @@
boolean getfilecomment (const ptrfilespec fs, bigstring bscomment) {
+ // 2009-09-06 aradke: FIXME: apparently, the proper way to get and set comments on OS X is to send Apple Events to the Finder (slow!?)
//
// 2006-06-25 creedon: minimally FSRef-ized
//
@@ -2591,17 +2578,18 @@
DTPBRec dt;
FSSpec fss;
- FSGetCatalogInfo ( &( *fs ).fsref, kFSCatInfoNone, NULL, NULL, &fss, NULL );
-
clearbytes (&dt, sizeof (dt));
setemptystring (bscomment); /*default return*/
- if ( ! surefile ( fs ) )
+ if (!surefile(fs))
return (false);
-
- if ( ! hasdesktopmanager ( fss.vRefNum ) )
+
+ if (oserror (macgetfsspec (fs, &fss)))
return (false);
+
+ if (!hasdesktopmanager (fss.vRefNum))
+ return (false);
dt.ioVRefNum = fss.vRefNum;
@@ -2639,12 +2627,13 @@
DTPBRec dt;
FSSpec fss;
- FSGetCatalogInfo ( &( *fs ).fsref, kFSCatInfoNone, NULL, NULL, &fss, NULL );
-
clearbytes (&dt, sizeof (dt));
if (!surefile (fs))
return (false);
+
+ if (oserror (macgetfsspec (fs, &fss)))
+ return (false);
if (!hasdesktopmanager (fss.vRefNum))
return (false);
@@ -2911,7 +2900,7 @@
#ifdef MACVERSION
- OSStatus status;
+ FSRef fsrefvolume;
bigstring bs, bsvolname;
short ix = 1;
@@ -2951,8 +2940,11 @@
}
- status = FSPathMakeRef ( bsvolname, &( *fs ).fsref, NULL );
+ if ( FSPathMakeRef ( bsvolname, &fsrefvolume, NULL ) != noErr )
+ return ( false );
+ return ( macmakefilespec ( &fsrefvolume, fs ) == noErr );
+
#endif
#ifdef WIN95VERSION
@@ -2976,18 +2968,21 @@
#ifdef MACVERSION
- boolean fileresolvealias ( ptrfilespec fs ) {
+ boolean fileresolvealias (ptrfilespec fs) {
//
// 2006-09-18 creedon: FSRef-ized
//
+ FSRef fsref;
boolean flfolder, flalias;
- setfserrorparam ( fs );
+ setfserrorparam (fs);
- return ( ! oserror ( FSResolveAliasFile ( &( *fs ).fsref, true, &flfolder, &flalias ) ) );
-
+ if (oserror (macgetfsref (fs, &fsref)))
+ return (false);
+
+ return (!oserror (FSResolveAliasFile ( &fsref, true, &flfolder, &flalias)));
} // fileresolvealias
#endif
@@ -3068,73 +3063,12 @@
} /*folderfrompath*/
-#ifdef MACVERSION
+boolean movefile (const ptrfilespec fs, const ptrfilespec fsto) {
- boolean getfileparentfolder ( const ptrfilespec fs, ptrfilespec fsparent ) {
-
- // 2009-08-30 aradke: handle null filespecs. don't fail silently if an error occurs.
- //
- // 2006-08-24 creedon: FSRef-ized
-
- HFSUniStr255 name;
- OSErr err;
-
- if ( !FSRefValid ( &(*fs).fsref ) ) {
-
- clearbytes ( fsparent, sizeof(tyfilespec) );
-
- return ( true );
- }
-
- err = FSGetCatalogInfo ( &( *fs ).fsref, kFSCatInfoNone, NULL, &name, NULL, &( *fsparent ).fsref );
-
- if ( oserror(err) )
- return ( false );
-
- if ( ( *fs ).path == NULL ) {
-
- err = FSGetCatalogInfo ( &( *fsparent ).fsref, kFSCatInfoNone, NULL, &name, NULL, &( *fsparent ).fsref );
-
- if ( oserror(err) )
- return ( false );
- }
-
- ( *fsparent ).path = CFStringCreateWithCharacters ( kCFAllocatorDefault, name.unicode, name.length );
-
- return ( true );
-
- } // getfileparentfolder
-
-
- #if 0
-
- boolean getdefaultpath (bigstring bs) {
-
- ParamBlockRec pb;
- OSErr errcode;
-
- setstringlength (bs, 0);
-
- clearbytes (&pb, sizeof (pb));
-
- errcode = PBGetVolSync (&pb);
-
- if (oserror (errcode))
- return (false);
-
- return (filegetpath (pb.fileParam.ioVRefNum, bs));
- } /*getdefaultpath*/
-
- #endif
-
-#endif
-
-boolean movefile ( const ptrfilespec fs, const ptrfilespec fsto ) {
-
#ifdef MACVERSION
//
- // moves a file or folder speied in fs to the fcifolder specified by fsto. make sure that the new path is really a folder.
+ // moves a file or folder specified in fs to the folder specified by fsto. make sure that the new path is really a folder.
//
// 2006-10-23 creedon: use fileisfolder function to determine if fs is folder
//
@@ -3143,22 +3077,23 @@
// 1991-08-02 dmb: corrected error message params
//
- boolean fl;
+ boolean flfolder;
+ FSRef src, dst;
- ( void ) fileisfolder ( fs, &fl );
+ (void) fileisfolder (fs, &flfolder);
- if ( fl ) {
-
- oserror ( errorParam ); // not the best error message, but...
-
- return ( false );
-
+ if (flfolder) {
+ oserror (errorParam); // not the best error message, but...
+ return (false);
}
- setfserrorparam ( fs );
+ setfserrorparam (fs);
- return ( ! oserror ( FSMoveObject ( &( *fs ).fsref, &( *fsto ).fsref, NULL ) ) );
+ if (oserror (macgetfsref (fs, &src)) || oserror (macgetfsref (fsto, &dst)))
+ return (false);
+ return (!oserror (FSMoveObject (&src, &dst, NULL)));
+
#endif
#ifdef WIN95VERSION
@@ -3277,18 +3212,22 @@
fixes bug when it's a path to a folder.
*/
+ FSRef fsref;
+ tyfsname name;
+
if (!surefile (fs)) /*file doesn't exist -- catch error*/
return (false);
+ if (oserror (macgetfsref (fs, &fsref)))
+ return (false);
+
filefrompath (bsnew, bsnew);
setoserrorparam (bsnew); /*only likely errors from here on relate to new name*/
-
- HFSUniStr255 name;
- bigstringToHFSUniStr255 ( bsnew, &name );
+ bigstringtofsname (bsnew, &name);
- if ( oserror ( FSRenameUnicode ( &fs -> fsref, name.length, name.unicode, kTextEncodingUnknown, NULL ) ) )
+ if (oserror (FSRenameUnicode (&fsref, name.length, name.unicode, kTextEncodingUnknown, NULL)))
return (false);
touchparentfolder (fs);
@@ -3333,20 +3272,25 @@
#ifdef MACVERSION
+ FSRef fsref;
FSCatalogInfo catinfo;
- OSErr err;
- clearbytes ( &catinfo, sizeof ( catinfo ) );
+ clearbytes (&catinfo, sizeof (catinfo));
- setfserrorparam ( fs ); // in case error message takes a filename parameter
+ setfserrorparam (fs); // in case error message takes a filename parameter
- err = FSGetCatalogInfo ( &( *fs ).fsref, kFSCatInfoNodeFlags, &catinfo, NULL, NULL, NULL );
+ if (oserror (macgetfsref (fs, &fsref)))
+ return (false);
+ if (oserror (FSGetCatalogInfo (&fsref, kFSCatInfoNodeFlags, &catinfo, NULL, NULL, NULL)))
+ return (false);
+
catinfo.nodeFlags |= kFSNodeLockedMask;
- err = FSSetCatalogInfo ( &( *fs ).fsref, kFSCatInfoNodeFlags, &catinfo );
+ if (oserror (FSSetCatalogInfo (&fsref, kFSCatInfoNodeFlags, &catinfo)))
+ return (false);
- return ( ! oserror ( err ) );
+ return (true);
#endif
@@ -3383,20 +3327,25 @@
#ifdef MACVERSION
+ FSRef fsref;
FSCatalogInfo catinfo;
- OSErr err;
- clearbytes ( &catinfo, sizeof ( catinfo ) );
+ clearbytes (&catinfo, sizeof (catinfo));
- setfserrorparam ( fs ); // in case error message takes a filename parameter
+ setfserrorparam (fs); // in case error message takes a filename parameter
- err = FSGetCatalogInfo ( &( *fs ).fsref, kFSCatInfoNodeFlags, &catinfo, NULL, NULL, NULL );
+ if (oserror (macgetfsref (fs, &fsref)))
+ return (false);
+
+ if (oserror (FSGetCatalogInfo (&fsref, kFSCatInfoNodeFlags, &catinfo, NULL, NULL, NULL)))
+ return (false);
catinfo.nodeFlags &= ~kFSNodeLockedMask;
- err = FSSetCatalogInfo ( &( *fs ).fsref, kFSCatInfoNodeFlags, &catinfo );
+ if (oserror (FSSetCatalogInfo (&fsref, kFSCatInfoNodeFlags, &catinfo)))
+ return (false);
- return ( ! oserror ( err ) );
+ return (true);
#endif
@@ -3434,18 +3383,14 @@
//
#ifdef MACVERSION
-
- HFSUniStr255 name;
- long dirid;
- setfserrorparam ( fs );
+ setfserrorparam (fs);
- if ( ! CFStringRefToHFSUniStr255 ( ( *fs ).path, &name ) )
- return ( false );
+ if (oserror (FSCreateDirectoryUnicode (&fs->ref, fs->name.length, fs->name.unicode, kFSCatInfoNone, NULL, NULL, NULL, NULL)))
+ return (false);
- return ( ! oserror ( FSCreateDirectoryUnicode ( &( *fs ).fsref, name.length, name.unicode, kFSCatInfoNone, NULL,
- NULL, NULL, &dirid ) ) );
-
+ return (true);
+
#endif
#ifdef WIN95VERSION
@@ -3465,30 +3410,20 @@
boolean newfile ( const ptrfilespec fs, OSType creator, OSType filetype ) {
//
+ // 2009-09-03 aradke: switched tyfilespec.name field from CFStringRef to HFSUniStr255
+ //
// 2007-08-01 creedon: if path is NULL oserror
- //
// set err to bdNamErr by default
//
// 2006-06-18 creedon: for Mac, FSRef-ized
//
#ifdef MACVERSION
-
- HFSUniStr255 name;
- OSErr err = bdNamErr;
- setfserrorparam ( fs );
+ setfserrorparam (fs);
+
+ return (!oserror (FSCreateFileUnicode (&fs->ref, fs->name.length, fs->name.unicode, kFSCatInfoNone, NULL, NULL, NULL)));
- if ( ( *fs ).path != NULL ) {
-
- CFStringRefToHFSUniStr255 ( ( *fs ).path, &name );
-
- err = FSCreateFileUnicode ( &( *fs ).fsref, name.length,
- name.unicode, kFSCatInfoNone, NULL, &( *fs ).fsref, NULL );
- }
-
- return ( ! oserror ( err ) );
-
#endif
#ifdef WIN95VERSION
@@ -3529,20 +3464,24 @@
//
tyfilespec fs;
+ FSRef fsref;
setoserrorparam (bspath); /*in case error message takes a filename parameter*/
- insertstring ( BIGSTRING ( "\x09" "/Volumes/" ), bspath );
+ insertstring (BIGSTRING ("\x09" "/Volumes/"), bspath);
- stringreplaceall ( ':', '/', bspath );
+ stringreplaceall (':', '/', bspath);
- convertpstring ( bspath );
+ convertpstring (bspath);
- if ( oserror ( FSPathMakeRef ( bspath, &fs.fsref, NULL ) ) )
- return ( false );
+ if (oserror (FSPathMakeRef (bspath, &fsref, NULL)))
+ return (false);
- return ( filespectopath ( &fs, bspath ) );
+ if (oserror (macmakefilespec (&fsref, &fs)))
+ return (false);
+ return (filespectopath (&fs, bspath));
+
} // getfullfilepath
@@ -3552,11 +3491,12 @@
// 2006-06-25 creedon: FSRef-ized
//
- OSErr err;
+ FSRef fsref;
- err = FSMakeFSRef (vnum, dirid, fname, &( *pfs ).fsref);
+ if (FSMakeFSRef (vnum, dirid, fname, &fsref) != noErr)
+ return (false);
- return ( ( err == noErr ) || ( err == fnfErr ) );
+ return (macmakefilespec (&fsref, pfs) == noErr);
} // filemakespec
@@ -3603,7 +3543,7 @@
} /*initfile*/
-boolean findapplication ( OSType creator, ptrfilespec fsapp ) {
+boolean findapplication (OSType creator, ptrfilespec fsapp) {
//
// 2007-06-12 creedon: for Mac, use getfilespecparent
@@ -3634,21 +3574,17 @@
//
#ifdef MACVERSION
+
+ FSRef fsref;
- OSStatus status;
+ if ((UInt32) LSFindApplicationForInfo == (UInt32) kUnresolvedCFragSymbolAddress)
+ return (false);
- if ( ( UInt32 ) LSFindApplicationForInfo == ( UInt32 ) kUnresolvedCFragSymbolAddress )
- return ( false );
-
- status = LSFindApplicationForInfo ( creator, NULL, NULL, &( *fsapp ).fsref, NULL);
+ if (LSFindApplicationForInfo (creator, NULL, NULL, &fsref, NULL) != noErr)
+ return (false);
- if ( status != noErr )
- return ( false );
-
- getfilespecparent ( fsapp );
+ return (macmakefilespec (&fsref, fsapp) == noErr);
- return ( true );
-
#endif // MACVERSION
#ifdef WIN95VERSION
@@ -3697,62 +3633,307 @@
} // findapplication
-boolean extendfilespec ( const ptrfilespec fsin, ptrfilespec fsout ) {
+void clearfilespec (ptrfilespec fs) {
- //
- // 2006-06-23 creedon: created
- //
+ /*
+ 2009-09-04 aradke: init to nil filespec
+ */
+
+ clearbytes (fs, sizeof (tyfilespec));
- #ifdef MACVERSION
+ } /*clearfilespec*/
+
+
+#ifdef MACVERSION
+
+ boolean macfilespecisvalid (const ptrfilespec fs) {
+
+ /*
+ 2009-09-06 aradke: check if fs data is valid (though file may not exist)
+ */
+
+ return (FSRefValid (&fs->ref) && (fsnamelength (&fs->name) > 0));
+
+ } /*macfilespecisvalid*/
- tyfilespec fst;
- clearbytes ( &fst, sizeof ( fst ) );
+ boolean macfilespecisresolvable (const ptrfilespec fs) {
+
+ FSRef fsref;
+
+ return (macgetfsref (fs, &fsref) == noErr);
+ } /*macfilespecisresolvable*/
- if ( ! FSRefValid ( &( *fsin ).fsref ) )
- return ( false );
+
+ OSErr macgetfsref (const ptrfilespec fs, FSRef* fsref) {
- if ( ( *fsin ).path == NULL )
- return ( false );
+ /*
+ 2009-09-05 aradke: obtain the actual FSRef corresponding to our extended filespec.
+ if the file does not exist, we return an error.
+ */
- HFSUniStr255 name;
+ if (!macfilespecisvalid (fs))
+ return (fnfErr);
+
+ if (fs->flags.flvolume) {
+
+ *fsref = fs->ref;
+
+ return (noErr);
+ }
+
+ return (FSMakeFSRefUnicode (&fs->ref, fs->name.length, fs->name.unicode, kTextEncodingUnknown, fsref));
+ } /*macgetfsref*/
+
+
+ OSErr macmakefilespec (const FSRef *fsrefptr, ptrfilespec fs) {
+
+ /*
+ 2009-09-06 aradke: obtain the filespec corresponding to the fsref.
+ */
+
+ FSRef fsref = *fsrefptr; // local copy in case fsrefptr points to fs->ref
+ FSCatalogInfo catalogInfo;
OSErr err;
- CFStringRefToHFSUniStr255 ( ( *fsin ).path, &name );
+ clearfilespec (fs);
- err = FSMakeFSRefUnicode ( &( *fsin ).fsref, name.length, name.unicode, kTextEncodingUnknown, &fst.fsref ); // kTextEncodingUnicodeDefault
+ clearbytes (&catalogInfo, longsizeof(catalogInfo));
+
+ err = FSGetCatalogInfo (&fsref, kFSCatInfoGettableInfo, &catalogInfo, NULL, NULL, NULL);
- if ( err != noErr )
- return ( false );
+ if (err != noErr)
+ return (err);
- *fsout = fst;
+ if (catalogInfo.parentDirID == fsRtParID) {
- #endif // MACVERSION
+ fs->flags.flvolume = true;
+
+ fs->ref = fsref;
+
+ return (FSGetCatalogInfo (&fsref, kFSCatInfoNone, NULL, &fs->name, NULL, NULL));
+ }
+
+ return (FSGetCatalogInfo (&fsref, kFSCatInfoNone, NULL, &fs->name, NULL, &fs->ref));
+ } /*macmakefilespec*/
- return ( true );
- } // extendfilespec
+ OSErr macgetfsspec (const ptrfilespec fs, FSSpec *fss) {
+
+ /*
+ 2009-09-06 aradke: get an old-style FSSpec corresponding to our filespec.
+ FSSpecs are seriously deprecated ...
[truncated message content] |