Resource fork data in Xcode?

kuroyume

Registered
I'm looking for a way to convert this code from CodeWarrior PPC to Xcode Universal Binary. I'm not doing Carbon or Cocoa. It is a C++ application SDK and creates a dylib. The resource data is NOT part of the build - it is data read by the application plugin being created - external, not ResEdit, not Rez, not NIB (tyvm!).

Code:
#ifndef _MACRES_H_
#define _MACRES_H_

// Includes
#include "MacMemory.h"
#include "Script.h"
#include "Files.h"
#include "Resources.h"

// CLASS: MacOS Resource support
class MacRes
{
	private:
		OSErr	error;
		short	refSrc;
		short	refDst;
		long	datasize;
		Handle	resHandle;
		FSSpec	fssSrc;
		FSSpec	fssDst;
		char	buffer[512];
	public:
		int		MyOpenResource(char* src, char* dst);
};

#endif	//_MACRES_H_
Code:
// Includes
#include "string.h"
#include "MacRes.h"

#define kFileCreator	'rtip'
#define kFileTypePICT	'PICT'

// METHODS: MacRes
// Open Resource Fork
//*---------------------------------------------------------------------------*
int MacRes::MyOpenResource(char* src, char* dst)
//*---------------------------------------------------------------------------*
{
	// Convert full paths using :-separators into FSSpec
	// - Source
	if (FSMakeFSSpec(0, 0, (unsigned char *)src, &fssSrc) != noErr) return 1;
	// - Destination
	error = FSMakeFSSpec(0, 0, (unsigned char *)dst, &fssDst);
	if ((error != noErr) && (error != fnfErr)) return 2;
	// Open resource fork of file (and make current)
	if ((refSrc = FSpOpenResFile(&fssSrc, fsRdPerm)) <= 0) return 3;
	// Get Handle of PICT resource
	if ((resHandle = Get1Resource(kFileTypePICT, 128)) == NULL) return 4;
	// Write data to file
	if (error == fnfErr)
	{
		if (FSpCreate(&fssDst, kFileCreator, kFileTypePICT, smSystemScript) != noErr) return 5;
	}
	if (FSpOpenDF(&fssDst, fsWrPerm, &refDst) != noErr) return 6;
	datasize = 512;
	memset(&buffer[0], 0, datasize);
	if (FSWrite(refDst, &datasize, &buffer[0]) != noErr) return 7;
	if ((datasize = GetHandleSize(resHandle)) < 1) return 8;
	HNoPurge(resHandle);
	HLock(resHandle);
	// - copy PICT data to temp file
	if (FSWrite(refDst, &datasize, *resHandle) != noErr) return 9;
	FSClose(refDst);
	HUnlock(resHandle);
	HPurge(resHandle);
	// Clean up
	ReleaseResource(resHandle);
	CloseResFile(refSrc);
	return 0;
}
 
Okay, I think that I have this sorted. Include the Carbon.framework and the header path to the required headers in the Developer folder and it works.

Currently, I'm using full paths converted from MacOSX paths: /Applications/Folder/Folder/File.ext

For FSMakeFSSpec(), this needs to be a full path using ':' separators. But because of the 255 character limit on the path, it would be better to somehow use a relative path. How?

Thank you very much,
Robert
 
Back
Top