Implement opening projects

This commit is contained in:
Dietrich Epp 2023-05-06 22:55:06 -04:00
parent 4a99288be2
commit c1862532b8
3 changed files with 65 additions and 24 deletions

View File

@ -26,7 +26,13 @@ typedef enum ErrorCode {
// Could not create alias. // Could not create alias.
kErrAlias, kErrAlias,
// Could not get directory path. // Could not get directory path.
kErrDirPath kErrDirPath,
// Local project directory not found.
kErrLocalNotFound,
// Remote project directory not found.
kErrRemoteNotFound,
// The volume is not mounted.
kErrNotMounted
} ErrorCode; } ErrorCode;
// ExitAssert shows an assertion error and quits the program. Either the file or // ExitAssert shows an assertion error and quits the program. Either the file or

View File

@ -291,10 +291,12 @@ static Boolean ProjectRead(ProjectHandle project)
long count, size; long count, size;
ErrorCode err; ErrorCode err;
OSErr osErr; OSErr osErr;
int nchunks, i; int nchunks, i, pathLength;
UInt32 headerCRC, gotCRC; UInt32 headerCRC, gotCRC;
Handle chunkData; Handle alias, path;
ProjectChunkStatus chunkStatus; ProjectChunkStatus chunkStatus;
FSSpec folderSpec;
Boolean wasChanged;
chunks = NULL; chunks = NULL;
err = kErrNone; err = kErrNone;
@ -348,25 +350,52 @@ static Boolean ProjectRead(ProjectHandle project)
} }
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
chunkStatus = chunkStatus = ProjectReadChunk(project, nchunks, chunks,
ProjectReadChunk(project, nchunks, chunks, kProjectAliasChunks[i], kProjectAliasChunks[i], &alias, &size);
&chunkData, &size); switch (chunkStatus) {
if (chunkStatus == kChunkError) { case kChunkError:
goto errorSilent; goto errorSilent;
} case kChunkFound:
if (chunkStatus == kChunkFound) { (*project)->dirs[i].alias = (AliasHandle)alias;
(*project)->dirs[i].alias = (AliasHandle)chunkData; osErr = ResolveAlias(NULL, (AliasHandle)alias, &folderSpec,
// FIXME: Resolve the alias. &wasChanged);
continue; err = (ErrorCode)(kErrLocalNotFound + i);
} switch (osErr) {
chunkStatus = ProjectReadChunk( case noErr:
project, nchunks, chunks, kProjectPathChunks[i], &chunkData, &size); osErr = GetDirPath(&folderSpec, &pathLength, &path);
if (chunkStatus == kChunkError) { if (osErr != 0) {
goto errorSilent; ShowError(err, kErrNone, osErr, NULL);
} } else {
if (chunkStatus == kChunkFound) { (*project)->dirs[i].pathLength = pathLength;
(*project)->dirs[i].pathLength = size; (*project)->dirs[i].path = path;
(*project)->dirs[i].path = chunkData; }
break;
case nsvErr:
ShowError(err, kErrNotMounted, 0, NULL);
break;
case fnfErr:
case dirNFErr:
ShowError(err, kErrNone, 0, NULL);
break;
default:
ShowError(err, kErrNone, osErr, NULL);
break;
}
break;
default:
chunkStatus = ProjectReadChunk(project, nchunks, chunks,
kProjectPathChunks[i], &path, &size);
switch (chunkStatus) {
case kChunkError:
goto errorSilent;
case kChunkFound:
(*project)->dirs[i].pathLength = size;
(*project)->dirs[i].path = path;
break;
default:
break;
}
break;
} }
} }
@ -411,10 +440,13 @@ void ProjectOpen(FSSpec *spec, ScriptCode script)
memcpy(&projectp->fileSpec, spec, sizeof(FSSpec)); memcpy(&projectp->fileSpec, spec, sizeof(FSSpec));
projectp->fileScript = script; projectp->fileScript = script;
ProjectRead(project); if (!ProjectRead(project)) {
// This will close the file.
ProjectDelete(project);
return;
}
ProjectDelete(project); ProjectCreateWindow(project);
// ProjectCreateWindow(project);
} }
void ProjectAdjustMenus(ProjectHandle project, MenuHandle fileMenu) void ProjectAdjustMenus(ProjectHandle project, MenuHandle fileMenu)

View File

@ -154,6 +154,9 @@ resource 'STR#' (rSTRS_Errors) {{
"Could not query volume parameters.", "Could not query volume parameters.",
"Could not create alias.", "Could not create alias.",
"Could not get directory path.", "Could not get directory path.",
"Local project directory not found.",
"Remote project directory not found.",
"The volume is not mounted.",
}}; }};
resource 'WIND' (rWIND_Project, preload, purgeable) { resource 'WIND' (rWIND_Project, preload, purgeable) {