sentient06
Member
Hello everyone,
I've been working on a couple of projects for new Classic Mac software. Yeah, exciting stuff. I've never tried my hands on this before, so I got a bunch of books, I got Inside Macintosh at hand, I've been through tutorials and started coding.
I am working on Mac OS 9.2.2 and CodeWarrior 5 (Pro 8, but it says 5, I don't know, it's confusing). I am planning on compiling for PowerPC and 68k in a fat bundle or maybe separate binaries.
I am still assessing the feasability of my project, but so far I got a SHA-1 implementation I've made in C, converted into a library that can be imported into a C++ project. I also got a small ZLib library at hand. My next challenge is to create, delete and assess the existence of files. Here is where my coding spree came to a halt, and I think I need a hand figuring this out.
My idea is simple: first I create a simple function that will check the existence of a file, and tell me whether it's a regular file or a directory, and if there's an error, report the error. Later, if all is working, I can nest the routine in an object or something.
I make the checks by using flags. I started with boolean flags, called exists, isDir, isFile, error, which I would then pass to my function. It didn't work at all. I've changed the type from booleans to unsigned chars to make the code simpler to work with the libraries from the Toolbox, and I kept getting errors of non-existent file/dir. So I thought maybe that's because the path is relative. So I've added 2 parameters for volume and parent directory, like so:
My function is there, it's called "CheckPathStatus". Here's the implementation.
Now, I created a folder in the same dir as the executable called "abc". And I keep getting an error in FSMakeFSSpec of value -43, which means the thing doesn't exist. When running on the debugger, I get a directory id (374 last time I saw) and a negative vRefNum to represent the hard drive with the value -32509.
Does that mean that the HD is unrecognised? What am I doing wrong here? Inside Macintosh only seems to suggest that vRefNum should be zero for the main HD, it doesn't say what happens if the HD isn't found.
Also, the directory does exist, and I'm assuming that my code to take the full path is to blame. But how can it be fixed?
Perhaps I'm using the wrong function?
Does anyone have experience with this? Is there a simpler way of doing this? Am I going insane?
Thanks in advance for any advice.
I've been working on a couple of projects for new Classic Mac software. Yeah, exciting stuff. I've never tried my hands on this before, so I got a bunch of books, I got Inside Macintosh at hand, I've been through tutorials and started coding.
I am working on Mac OS 9.2.2 and CodeWarrior 5 (Pro 8, but it says 5, I don't know, it's confusing). I am planning on compiling for PowerPC and 68k in a fat bundle or maybe separate binaries.
I am still assessing the feasability of my project, but so far I got a SHA-1 implementation I've made in C, converted into a library that can be imported into a C++ project. I also got a small ZLib library at hand. My next challenge is to create, delete and assess the existence of files. Here is where my coding spree came to a halt, and I think I need a hand figuring this out.
My idea is simple: first I create a simple function that will check the existence of a file, and tell me whether it's a regular file or a directory, and if there's an error, report the error. Later, if all is working, I can nest the routine in an object or something.
I make the checks by using flags. I started with boolean flags, called exists, isDir, isFile, error, which I would then pass to my function. It didn't work at all. I've changed the type from booleans to unsigned chars to make the code simpler to work with the libraries from the Toolbox, and I kept getting errors of non-existent file/dir. So I thought maybe that's because the path is relative. So I've added 2 parameters for volume and parent directory, like so:
C++:
// Variables for volume reference number and directory ID
short vRefNum = 0;
long dirID = 0;
// Handle relative paths by getting the current volume and directory
err = HGetVol(NULL, &vRefNum, &dirID);
if (err != noErr) {
printf("Error getting current volume/directory: %d\n", err);
return err;
}
// Call CheckPathStatus for a relative path (like "abc") using the current directory
err = CheckPathStatus(path, &exists, &isDir, &isFile, &error, vRefNum, dirID);
My function is there, it's called "CheckPathStatus". Here's the implementation.
C++:
OSErr CheckPathStatus(
const char* path,
unsigned char *exists,
unsigned char *isDir,
unsigned char *isFile,
unsigned char *error,
short vRefNum, // Volume reference number (for full path handling)
long dirID // Directory ID (for full path handling)
) {
FSSpec fileSpec;
CInfoPBRec catInfo;
OSErr err;
Str255 pPath; // Pascal string for the path
*exists = 0;
*isDir = 0;
*isFile = 0;
*error = 0;
// Convert C string to Pascal string, I can post this function if you want:
CtoPStr(path, pPath);
// Convert path to an FSSpec
err = FSMakeFSSpec(vRefNum, dirID, pPath, &fileSpec);
if (err != noErr) {
printf("Error in FSMakeFSSpec: %d\n", err);
*error = 1;
return err;
}
// Set up the CInfoPBRec to get info about the file
catInfo.hFileInfo.ioNamePtr = fileSpec.name;
catInfo.hFileInfo.ioVRefNum = fileSpec.vRefNum;
catInfo.hFileInfo.ioDirID = fileSpec.parID;
catInfo.hFileInfo.ioFDirIndex = 0;
// Get information about the file/directory
err = PBGetCatInfoSync(&catInfo);
if (err == noErr) {
*exists = 1;
if (catInfo.hFileInfo.ioFlAttrib & ioDirMask) {
*isDir = 1;
printf("Path is a directory.\n");
} else {
*isFile = 1;
printf("Path is a regular file.\n");
}
} else {
printf("Error in PBGetCatInfoSync: %d\n", err);
*error = 1;
}
return err;
}
Now, I created a folder in the same dir as the executable called "abc". And I keep getting an error in FSMakeFSSpec of value -43, which means the thing doesn't exist. When running on the debugger, I get a directory id (374 last time I saw) and a negative vRefNum to represent the hard drive with the value -32509.
Does that mean that the HD is unrecognised? What am I doing wrong here? Inside Macintosh only seems to suggest that vRefNum should be zero for the main HD, it doesn't say what happens if the HD isn't found.
Also, the directory does exist, and I'm assuming that my code to take the full path is to blame. But how can it be fixed?
Perhaps I'm using the wrong function?
Does anyone have experience with this? Is there a simpler way of doing this? Am I going insane?
Thanks in advance for any advice.
Last edited: