Implement some changes based on feedback from Kelvin:

- Add the window position resource first.  That way, if the style resource needs to grow, the window position resource will not need to be re-written.

- Do not dispose of a handle passed to the resource manager through AddResource.  The resource is owned by the resource manager after that.

- No need to make the resource as changed when adding a resource.  It is implied.

Also, rename the disk image from Distribution to md2teach.
This commit is contained in:
Jeremy Rand 2021-05-10 22:58:12 -04:00
parent f1fd4a7bd3
commit ff039e5ee0
3 changed files with 23 additions and 20 deletions

Binary file not shown.

View File

@ -177,13 +177,6 @@ static int writeResources(void)
return 1;
}
AddResource(styleHandle(), resChanged, rStyleBlock, STYLE_BLOCK_NUM);
if (toolerror()) {
fprintf(stderr, "%s: Unable to add style resource to file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror());
result = 1;
goto error;
}
windowPosHandle = NewHandle(sizeof(windowPos), userid(), attrNoPurge, NULL);
if (toolerror()) {
fprintf(stderr, "%s: Unable to allocate memory for window resource for file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror());
@ -193,13 +186,19 @@ static int writeResources(void)
HLock(windowPosHandle);
PtrToHand((Pointer)windowPos, windowPosHandle, sizeof(windowPos));
AddResource(windowPosHandle, resChanged, R_WINDOW_POSITION, WINDOW_POSITION_NUM);
AddResource(windowPosHandle, 0, R_WINDOW_POSITION, WINDOW_POSITION_NUM);
if (toolerror()) {
fprintf(stderr, "%s: Unable to add window position resource to file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror());
result = 1;
DisposeHandle(windowPosHandle);
goto error;
}
DisposeHandle(windowPosHandle);
AddResource(styleHandle(), 0, rStyleBlock, STYLE_BLOCK_NUM);
if (toolerror()) {
fprintf(stderr, "%s: Unable to add style resource to file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror());
result = 1;
}
error:
CloseResourceFile(writeResId);
@ -241,13 +240,12 @@ static int writeRez(void)
" hex string;\n"
"};\n"
"\n"
"resource rStyleBlock (%u) {\n"
"resource rWindowPosition (%u) {\n"
" $\"",
rStyleBlock, R_WINDOW_POSITION, STYLE_BLOCK_NUM
);
rStyleBlock, R_WINDOW_POSITION, WINDOW_POSITION_NUM);
ptr = stylePtr();
size = styleSize();
ptr = (uint8_t *)(&windowPos);
size = sizeof(windowPos);
for (i = 0; i < size; i++) {
if ((i > 0) &&
((i % 32) == 0)) {
@ -260,12 +258,13 @@ static int writeRez(void)
fprintf(rezFile, "\"\n"
"};\n"
"\n"
"resource rWindowPosition (%u) {\n"
"resource rStyleBlock (%u) {\n"
" $\"",
WINDOW_POSITION_NUM);
STYLE_BLOCK_NUM
);
ptr = (uint8_t *)(&windowPos);
size = sizeof(windowPos);
ptr = stylePtr();
size = styleSize();
for (i = 0; i < size; i++) {
if ((i > 0) &&
((i % 32) == 0)) {
@ -274,6 +273,7 @@ static int writeRez(void)
fprintf(rezFile, "%02x", (uint16_t)*ptr);
ptr++;
}
fprintf(rezFile, "\"\n"
"};\n"
"\n");

View File

@ -293,7 +293,9 @@ void closeStyle(void)
Handle styleHandle(void)
{
return formatHandle;
Handle result = formatHandle;
formatHandle = NULL;
return result;
}
uint8_t * stylePtr(void)
@ -309,5 +311,6 @@ uint32_t styleSize(void)
void styleShutdown(void)
{
DisposeHandle(formatHandle);
if (formatHandle != NULL)
DisposeHandle(formatHandle);
}