Fix text when creating resource forks in MacOS.

This commit is contained in:
2021-03-16 05:38:17 +00:00
parent c0c52aa887
commit 6dd972c781
2 changed files with 18 additions and 14 deletions

View File

@@ -121,28 +121,28 @@ void ResourceFork(const char* path)
log_write("Creating resource forks.\n"); log_write("Creating resource forks.\n");
memset(&finderInfo, 0, sizeof(FInfo)); memset(&finderInfo, 0, sizeof(FInfo));
rc = HCreate(refNum, dirId, "\pICON", ostUnknown, ftGenericDocumentPC); rc = HCreate(refNum, dirId, "\pICNS", ostUnknown, ftGenericDocumentPC);
if(!rc) if(!rc)
{ {
rRc = SaveResourceToNewFile(refNum, rRc = SaveResourceToNewFile(refNum,
dirId, dirId,
"\pICON", "\pICNS",
rtIcons, rtIcons,
-16455, -16455,
"\pIcon resource", "\pIcon resource",
(unsigned char*)IcnsResource, (unsigned char*)IcnsResource,
sizeof(IcnsResource)); sizeof(IcnsResource));
rc = HOpenDF(refNum, dirId, "\pICON", 0, &refFile); rc = HOpenDF(refNum, dirId, "\pICNS", 0, &refFile);
if(!rc) if(!rc)
{ {
memset(&fpb, 0, sizeof(HParamBlockRec)); memset(&fpb, 0, sizeof(HParamBlockRec));
count = strlen(rsrcText); count = strlen(icnsText);
wRc = FSWrite(refFile, &count, rsrcText); wRc = FSWrite(refFile, &count, icnsText);
cRc = FSClose(refFile); cRc = FSClose(refFile);
fpb.fileParam.ioVRefNum = refNum; fpb.fileParam.ioVRefNum = refNum;
fpb.fileParam.ioNamePtr = "\pICON"; fpb.fileParam.ioNamePtr = "\pICNS";
fpb.fileParam.ioDirID = dirId; fpb.fileParam.ioDirID = dirId;
fpb.fileParam.ioFlFndrInfo.fdType = ftGenericDocumentPC; fpb.fileParam.ioFlFndrInfo.fdType = ftGenericDocumentPC;
fpb.fileParam.ioFlFndrInfo.fdCreator = ostAaru; fpb.fileParam.ioFlFndrInfo.fdCreator = ostAaru;
@@ -151,8 +151,8 @@ void ResourceFork(const char* path)
rc = PBHSetFInfoSync(&fpb); rc = PBHSetFInfoSync(&fpb);
} }
} }
log_write("\tFile with three items in the resource fork: name = \"%s\", rc = %d, wRc = %d, cRc = %d, rRc = %d\n", log_write("\tFile with an icon in the resource fork: name = \"%s\", rc = %d, wRc = %d, cRc = %d, rRc = %d\n",
"ICON", "ICNS",
rc, rc,
wRc, wRc,
cRc, cRc,
@@ -175,8 +175,8 @@ void ResourceFork(const char* path)
{ {
memset(&fpb, 0, sizeof(HParamBlockRec)); memset(&fpb, 0, sizeof(HParamBlockRec));
count = strlen(rsrcText); count = strlen(pictText);
wRc = FSWrite(refFile, &count, rsrcText); wRc = FSWrite(refFile, &count, pictText);
cRc = FSClose(refFile); cRc = FSClose(refFile);
finderInfo.fdType = ftPICTFile; finderInfo.fdType = ftPICTFile;
finderInfo.fdCreator = ostAaru; finderInfo.fdCreator = ostAaru;
@@ -190,7 +190,7 @@ void ResourceFork(const char* path)
rc = PBHSetFInfoSync(&fpb); rc = PBHSetFInfoSync(&fpb);
} }
} }
log_write("\tFile with three items in the resource fork: name = \"%s\", rc = %d, wRc = %d, cRc = %d, rRc = %d\n", log_write("\tFile with a picture in the resource fork: name = \"%s\", rc = %d, wRc = %d, cRc = %d, rRc = %d\n",
"PICT", "PICT",
rc, rc,
wRc, wRc,
@@ -214,8 +214,8 @@ void ResourceFork(const char* path)
{ {
memset(&fpb, 0, sizeof(HParamBlockRec)); memset(&fpb, 0, sizeof(HParamBlockRec));
count = strlen(rsrcText); count = strlen(versText);
wRc = FSWrite(refFile, &count, rsrcText); wRc = FSWrite(refFile, &count, versText);
cRc = FSClose(refFile); cRc = FSClose(refFile);
fpb.fileParam.ioVRefNum = refNum; fpb.fileParam.ioVRefNum = refNum;
@@ -227,7 +227,8 @@ void ResourceFork(const char* path)
rc = PBHSetFInfoSync(&fpb); rc = PBHSetFInfoSync(&fpb);
} }
} }
log_write("\tFile with three items in the resource fork: name = \"%s\", rc = %d, wRc = %d, cRc = %d, rRc = %d\n", log_write("\tFile with an icon, a picture and a version in the resource fork: name = \"%s\", rc = %d, wRc = %d, "
"cRc = %d, rRc = %d\n",
"VERSION", "VERSION",
rc, rc,
wRc, wRc,

View File

@@ -34,6 +34,9 @@ static OSErr SaveResourceToNewFile(int16_t vRefNum,
unsigned char* buffer, unsigned char* buffer,
size_t length); size_t length);
const char* icnsText = "This file has a custom icon in the resource fork.\r";
const char* versText = "This file has a version in the resource fork.\r";
const char* pictText = "This file has a picture, in the resource fork.\r";
const char* rsrcText = "This file has a custom icon, a version, and a picture, in the resource fork.\r"; const char* rsrcText = "This file has a custom icon, a version, and a picture, in the resource fork.\r";
const unsigned char IcnsResource[5618] = { const unsigned char IcnsResource[5618] = {