Implement resource file handling
This was previously implemented, but lost. The previous implementation was probably destroyed when testing this tool. GitOrigin-RevId: e1a41fc5290e57510c252c8404db86afa1913eba
This commit is contained in:
parent
6b7a783916
commit
4d82709bd4
63
file.c
63
file.c
|
@ -155,7 +155,7 @@ static Ptr gDestBuffer;
|
||||||
int sync_file(struct file_info *file, operation_mode mode, short srcVol,
|
int sync_file(struct file_info *file, operation_mode mode, short srcVol,
|
||||||
long srcDir, short destVol, long destDir, short tempVol,
|
long srcDir, short destVol, long destDir, short tempVol,
|
||||||
long tempDir) {
|
long tempDir) {
|
||||||
OSType creator = 'MPS ', fileType = 'TEXT';
|
OSType creator, fileType;
|
||||||
FSSpec src, dest, temp;
|
FSSpec src, dest, temp;
|
||||||
short srcRef = 0, destRef = 0;
|
short srcRef = 0, destRef = 0;
|
||||||
bool has_temp = false;
|
bool has_temp = false;
|
||||||
|
@ -196,14 +196,20 @@ int sync_file(struct file_info *file, operation_mode mode, short srcVol,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the source file for reading.
|
// Create the temporary file.
|
||||||
err = FSpOpenDF(&src, fsRdPerm, &srcRef);
|
switch (file->type) {
|
||||||
if (err != 0) {
|
case kTypeText:
|
||||||
print_errcode(err, "could not open file");
|
creator = 'MPS ';
|
||||||
goto error;
|
fileType = 'TEXT';
|
||||||
|
break;
|
||||||
|
case kTypeResource:
|
||||||
|
creator = 'RSED';
|
||||||
|
fileType = 'rsrc';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
print_err("invalid type");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and open the temporary file for writing.
|
|
||||||
err = FSpCreate(&temp, creator, fileType, smSystemScript);
|
err = FSpCreate(&temp, creator, fileType, smSystemScript);
|
||||||
if (err == dupFNErr) {
|
if (err == dupFNErr) {
|
||||||
err = FSpDelete(&temp);
|
err = FSpDelete(&temp);
|
||||||
|
@ -218,11 +224,6 @@ int sync_file(struct file_info *file, operation_mode mode, short srcVol,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
has_temp = true;
|
has_temp = true;
|
||||||
err = FSpOpenDF(&temp, fsRdWrPerm, &destRef);
|
|
||||||
if (err != 0) {
|
|
||||||
print_errcode(err, "could not open temp file");
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get buffers for conversion.
|
// Get buffers for conversion.
|
||||||
if (gSrcBuffer == NULL) {
|
if (gSrcBuffer == NULL) {
|
||||||
|
@ -240,16 +241,40 @@ int sync_file(struct file_info *file, operation_mode mode, short srcVol,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Open the source file for reading.
|
||||||
|
if (file->type == kTypeResource && mode == kModePush) {
|
||||||
|
err = FSpOpenRF(&src, fsRdPerm, &srcRef);
|
||||||
|
} else {
|
||||||
|
err = FSpOpenDF(&src, fsRdPerm, &srcRef);
|
||||||
|
}
|
||||||
|
if (err != 0) {
|
||||||
|
print_errcode(err, "could not open file");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (file->type == kTypeResource && mode == kModePull) {
|
||||||
|
err = FSpOpenRF(&temp, fsRdWrPerm, &destRef);
|
||||||
|
} else {
|
||||||
|
err = FSpOpenDF(&temp, fsRdWrPerm, &destRef);
|
||||||
|
}
|
||||||
|
if (err != 0) {
|
||||||
|
print_errcode(err, "could not open temp file");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
// Convert data.
|
// Convert data.
|
||||||
switch (mode) {
|
switch (file->type) {
|
||||||
case kModePush:
|
case kTypeText:
|
||||||
r = mac_to_unix(srcRef, destRef, gSrcBuffer, gDestBuffer);
|
if (mode == kModePush) {
|
||||||
|
r = mac_to_unix(srcRef, destRef, gSrcBuffer, gDestBuffer);
|
||||||
|
} else {
|
||||||
|
r = mac_from_unix(srcRef, destRef, gSrcBuffer, gDestBuffer);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case kModePull:
|
case kTypeResource:
|
||||||
r = mac_from_unix(srcRef, destRef, gSrcBuffer, gDestBuffer);
|
r = copy_data(srcRef, destRef, gSrcBuffer);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
print_err("invalid mode");
|
print_err("invalid type");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
|
|
Loading…
Reference in New Issue