Remove FSSpec and alias usage from libreg on Mac OS X. b=487966 r=bsmedberg

This commit is contained in:
Josh Aas 2009-04-22 14:08:47 -04:00
parent cf212a510b
commit f2f4f4bd88
4 changed files with 7 additions and 258 deletions

View File

@ -76,10 +76,6 @@
#include "NSReg.h"
#include "VerReg.h"
#if defined(XP_MACOSX)
#include <Carbon/Carbon.h>
#endif
/* -------- local defines ---------------
*/
#define MAXREGVERLEN 32 /* Version=12345.12345.12345.12345 */
@ -158,11 +154,6 @@ static REGERR vr_GetUninstallItemPath(char *regPackageName, char *regbuf, uint32
static REGERR vr_convertPackageName(char *regPackageName, char *convertedPackageName, uint32 convertedDataLength);
static REGERR vr_unmanglePackageName(char *mangledPackageName, char *regPackageName, uint32 regPackageLength);
#if defined(XP_MACOSX)
static void vr_MacAliasFromPath(const char * fileName, void ** alias, int32 * length);
static char * vr_PathFromMacAlias(const void * alias, uint32 aliasLength);
#endif
/* --------------------------------------------------------------------- */
static REGERR vr_Init(void)
@ -440,69 +431,7 @@ static REGERR vr_SetPathname(HREG reg, RKEY key, char *entry, char *dir)
static REGERR vr_GetPathname(HREG reg, RKEY key, char *entry, char *buf, uint32 sizebuf)
{
REGERR err;
REGINFO info;
info.size = sizeof(REGINFO);
#if !defined(XP_MACOSX)
err = NR_RegGetEntry( reg, key, entry, (void*)buf, &sizebuf );
return err;
#else
err = NR_RegGetEntryInfo( reg, key, entry, &info );
if (err != REGERR_OK)
return err;
if (info.entryType == REGTYPE_ENTRY_FILE ||
info.entryType == REGTYPE_ENTRY_STRING_UTF )
{
err = NR_RegGetEntry( reg, key, entry, (void*)buf, &sizebuf );
}
else if (info.entryType == REGTYPE_ENTRY_BYTES)
{
extern char * nr_PathFromMacAlias(const void * alias, uint32 aliasLength);
#define MAC_ALIAS_BUFFER_SIZE 4000
char stackBuf[MAC_ALIAS_BUFFER_SIZE];
uint32 stackBufSize = MAC_ALIAS_BUFFER_SIZE;
char * tempBuf;
err = NR_RegGetEntry( reg, key, entry, (void*)stackBuf, &stackBufSize );
if (err != REGERR_OK)
return err;
tempBuf = nr_PathFromMacAlias(stackBuf, stackBufSize);
if (tempBuf == NULL)
{
/* don't change error w/out changing vr_SetCurrentNav to match */
buf[0] = '\0';
err = REGERR_NOFILE;
}
else
{
if (XP_STRLEN(tempBuf) > sizebuf)
err = REGERR_BUFTOOSMALL;
else
XP_STRCPY(buf, tempBuf);
XP_FREE(tempBuf);
}
}
else
{
/* what did we put here?? */
err = REGERR_BADTYPE;
}
return err;
#endif
return NR_RegGetEntry( reg, key, entry, (void*)buf, &sizebuf );
}

View File

@ -65,10 +65,6 @@
#include <stdio.h>
#include <string.h>
#ifdef XP_MACOSX
#include <Carbon/Carbon.h>
#endif
#ifdef XP_UNIX
#include <limits.h>
#endif
@ -159,146 +155,6 @@ static int32 regStartCount = 0;
char *globalRegName = NULL;
static char *user_name = NULL;
#ifdef XP_MACOSX
void nr_MacAliasFromPath(const char * fileName, void ** alias, int32 * length);
char * nr_PathFromMacAlias(const void * alias, uint32 aliasLength);
static void copyCStringToPascal(Str255 dest, const char *src)
{
size_t copyLen = strlen(src);
if (copyLen > 255)
copyLen = 255;
BlockMoveData(src, &dest[1], copyLen);
dest[0] = copyLen;
}
static OSErr isFileInTrash(FSRef *fsRef, PRBool *inTrash)
{
OSErr err;
FSCatalogInfo catalogInfo;
if (fsRef == NULL || inTrash == NULL)
return paramErr;
*inTrash = PR_FALSE;
err = FSGetCatalogInfo(fsRef, kFSCatInfoVolume, &catalogInfo, NULL, NULL, NULL);
if (err == noErr)
{
FSRef trashFSRef, currFSRef, parentFSRef;
err = FSFindFolder(catalogInfo.volume, kTrashFolderType, false, &trashFSRef);
if (err == noErr)
{
for (currFSRef = *fsRef;
(FSGetCatalogInfo(&currFSRef, kFSCatInfoNodeID, NULL, NULL, NULL, &parentFSRef) == noErr &&
FSGetCatalogInfo(&parentFSRef, kFSCatInfoNone, NULL, NULL, NULL, NULL) == noErr);
currFSRef = parentFSRef)
{
if (FSCompareFSRefs(&parentFSRef, &trashFSRef) == noErr)
{
*inTrash = PR_TRUE;
break;
}
}
}
}
return err;
}
/* returns an alias as a malloc'd pointer.
* On failure, *alias is NULL
*/
void nr_MacAliasFromPath(const char * fileName, void ** alias, int32 * length)
{
OSErr err;
Str255 pascalName;
FSRef fsRef;
FSSpec fs;
AliasHandle macAlias;
*alias = NULL;
*length = 0;
err = FSPathMakeRef((const UInt8*)fileName, &fsRef, NULL);
if ( err != noErr )
return;
err = FSNewAlias(NULL, &fsRef, &macAlias);
if ( (err != noErr) || ( macAlias == NULL ))
return;
*length = GetHandleSize( (Handle) macAlias );
*alias = XP_ALLOC( *length );
if ( *alias == NULL )
{
DisposeHandle((Handle)macAlias);
return;
}
HLock( (Handle) macAlias );
XP_MEMCPY(*alias, *macAlias , *length);
HUnlock( (Handle) macAlias );
DisposeHandle( (Handle) macAlias);
return;
}
/* resolves an alias, and returns a full path to the Mac file
* If the alias changed, it would be nice to update our alias pointers
*/
char * nr_PathFromMacAlias(const void * alias, uint32 aliasLength)
{
OSErr err;
AliasHandle h = NULL;
Handle fullPath = NULL;
short fullPathLength;
char * cpath = NULL;
PRBool inTrash;
FSRef fsRef;
FSCatalogInfo catalogInfo;
UInt8 pathBuf[MAX_PATH];
FSSpec fs;
Boolean wasChanged; /* Change flag, it would be nice to change the alias on disk
if the file location changed */
XP_MEMSET( &fs, '\0', sizeof(FSSpec) );
/* Copy the alias to a handle and resolve it */
h = (AliasHandle) NewHandle(aliasLength);
if ( h == NULL)
goto fail;
HLock( (Handle) h);
XP_MEMCPY( *h, alias, aliasLength );
HUnlock( (Handle) h);
err = FSResolveAlias(NULL, h, &fsRef, &wasChanged);
if (err != noErr)
goto fail;
/* if the alias has changed and the file is now in the trash,
assume that user has deleted it and that we do not want to look at it */
if (wasChanged && (isFileInTrash(&fsRef, &inTrash) == noErr) && inTrash)
goto fail;
err = FSRefMakePath(&fsRef, pathBuf, sizeof(pathBuf));
if (err != noErr)
goto fail;
fullPathLength = XP_STRLEN(pathBuf);
cpath = (char*) XP_ALLOC(fullPathLength + 1);
if ( cpath == NULL)
goto fail;
XP_MEMCPY(cpath, pathBuf, fullPathLength + 1);
/* Drop through */
fail:
if (h != NULL)
DisposeHandle( (Handle) h);
if (fullPath != NULL)
DisposeHandle( fullPath);
return cpath;
}
#endif
/* --------------------------------------------------------------------
* Registry List management
* --------------------------------------------------------------------
@ -391,19 +247,11 @@ static REGERR nr_OpenFile(const char *path, FILEHANDLE *fh)
{
switch (errno)
{
#ifdef XP_MACOSX
case fnfErr:
#else
case ENOENT: /* file not found */
#endif
return REGERR_NOFILE;
#ifdef XP_MACOSX
case opWrErr:
#else
case EROFS: /* read-only file system */
case EACCES: /* file in use or read-only file*/
#endif
/* try read only */
(*fh) = vr_fileOpen(path, XP_FILE_READ_BIN);
if ( VALID_FILEHANDLE(*fh) )
@ -1944,7 +1792,7 @@ static REGERR nr_RegAddKey( REGFILE *reg, RKEY key, char *path, RKEY *newKey, XP
while ( err == REGERR_OK ) {
/* get next name on the path */
err = nr_NextName(p, namebuf, sizeof(namebuf), &p);
err = nr_NextName(p, namebuf, sizeof(namebuf), (const char**)&p);
if ( err == REGERR_OK ) {
/* look for name at next level down */
parent = desc.location;
@ -3079,28 +2927,7 @@ VR_INTERFACE(REGERR) NR_RegGetEntry( HREG hReg, RKEY key, char *name,
break;
case REGTYPE_ENTRY_FILE:
err = nr_ReadData( reg, &desc, *size, (char*)buffer );
#ifdef XP_MACOSX
if (err == 0)
{
tmpbuf = nr_PathFromMacAlias(buffer, *size);
if (tmpbuf == NULL)
{
buffer = NULL;
err = REGERR_NOFILE; /* must match nr_GetPathname() in VerReg.c */
}
else
{
needFree = TRUE;
if (XP_STRLEN(tmpbuf) < *size) /* leave room for \0 */
XP_STRCPY(buffer, tmpbuf);
else
err = REGERR_BUFTOOSMALL;
}
}
#endif
break;
case REGTYPE_ENTRY_BYTES:
@ -3242,14 +3069,7 @@ VR_INTERFACE(REGERR) NR_RegSetEntry( HREG hReg, RKEY key, char *name, uint16 typ
break;
case REGTYPE_ENTRY_FILE:
#ifdef XP_MACOSX
nr_MacAliasFromPath(buffer, (void **)&data, &datalen);
if (data)
needFree = TRUE;
#else
data = (char*)buffer;
#endif
break;

View File

@ -55,7 +55,7 @@
* --------------------------------------------------------------------
*/
#define MAGIC_NUMBER 0x76644441L
#define MAJOR_VERSION 1 /* major version for incompatible changes */
#define MAJOR_VERSION 2 /* major version for incompatible changes */
#define MINOR_VERSION 2 /* minor ver for new (compatible) features */
#define PATHDEL '/'
#define HDRRESERVE 128 /* number of bytes reserved for hdr */

View File

@ -270,7 +270,7 @@ extern void vr_findGlobalRegName()
{
FSCatalogInfo catalogInfo;
FileInfo fileInfo = { 'REGS', 'MOSS', 0, { 0, 0 }, 0 };
BlockMoveData(&fileInfo, &(catalogInfo.finderInfo), sizeof(FileInfo));
memmove(&(catalogInfo.finderInfo), &fileInfo, sizeof(FileInfo));
err = FSCreateFileUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXRegName), kOSXRegName,
kFSCatInfoFinderInfo, &catalogInfo, &regRef, NULL);
}
@ -279,7 +279,7 @@ extern void vr_findGlobalRegName()
UInt8 pathBuf[PATH_MAX];
err = FSRefMakePath(&regRef, pathBuf, sizeof(pathBuf));
if (err == noErr)
globalRegName = XP_STRDUP(pathBuf);
globalRegName = XP_STRDUP((const char*)pathBuf);
}
}
}
@ -310,7 +310,7 @@ extern char* vr_findVerRegName()
{
FSCatalogInfo catalogInfo;
FileInfo fileInfo = { 'REGS', 'MOSS', 0, { 0, 0 }, 0 };
BlockMoveData(&fileInfo, &(catalogInfo.finderInfo), sizeof(FileInfo));
memmove(&(catalogInfo.finderInfo), &fileInfo, sizeof(FileInfo));
err = FSCreateFileUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXVersRegName), kOSXVersRegName,
kFSCatInfoFinderInfo, &catalogInfo, &regRef, NULL);
}
@ -319,7 +319,7 @@ extern char* vr_findVerRegName()
UInt8 pathBuf[PATH_MAX];
err = FSRefMakePath(&regRef, pathBuf, sizeof(pathBuf));
if (err == noErr)
verRegName = XP_STRDUP(pathBuf);
verRegName = XP_STRDUP((const char*)pathBuf);
}
}
}