diff --git a/macos/error.h b/macos/error.h index d7ef665..54c3b2c 100644 --- a/macos/error.h +++ b/macos/error.h @@ -26,7 +26,13 @@ typedef enum ErrorCode { // Could not create alias. kErrAlias, // 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; // ExitAssert shows an assertion error and quits the program. Either the file or diff --git a/macos/project.c b/macos/project.c index 6a5a362..8a55487 100644 --- a/macos/project.c +++ b/macos/project.c @@ -291,10 +291,12 @@ static Boolean ProjectRead(ProjectHandle project) long count, size; ErrorCode err; OSErr osErr; - int nchunks, i; + int nchunks, i, pathLength; UInt32 headerCRC, gotCRC; - Handle chunkData; + Handle alias, path; ProjectChunkStatus chunkStatus; + FSSpec folderSpec; + Boolean wasChanged; chunks = NULL; err = kErrNone; @@ -348,25 +350,52 @@ static Boolean ProjectRead(ProjectHandle project) } for (i = 0; i < 2; i++) { - chunkStatus = - ProjectReadChunk(project, nchunks, chunks, kProjectAliasChunks[i], - &chunkData, &size); - if (chunkStatus == kChunkError) { + chunkStatus = ProjectReadChunk(project, nchunks, chunks, + kProjectAliasChunks[i], &alias, &size); + switch (chunkStatus) { + case kChunkError: goto errorSilent; - } - if (chunkStatus == kChunkFound) { - (*project)->dirs[i].alias = (AliasHandle)chunkData; - // FIXME: Resolve the alias. - continue; - } - chunkStatus = ProjectReadChunk( - project, nchunks, chunks, kProjectPathChunks[i], &chunkData, &size); - if (chunkStatus == kChunkError) { - goto errorSilent; - } - if (chunkStatus == kChunkFound) { - (*project)->dirs[i].pathLength = size; - (*project)->dirs[i].path = chunkData; + case kChunkFound: + (*project)->dirs[i].alias = (AliasHandle)alias; + osErr = ResolveAlias(NULL, (AliasHandle)alias, &folderSpec, + &wasChanged); + err = (ErrorCode)(kErrLocalNotFound + i); + switch (osErr) { + case noErr: + osErr = GetDirPath(&folderSpec, &pathLength, &path); + if (osErr != 0) { + ShowError(err, kErrNone, osErr, NULL); + } else { + (*project)->dirs[i].pathLength = pathLength; + (*project)->dirs[i].path = path; + } + 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)); 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) diff --git a/macos/resources.r b/macos/resources.r index fc2da32..963c25a 100644 --- a/macos/resources.r +++ b/macos/resources.r @@ -154,6 +154,9 @@ resource 'STR#' (rSTRS_Errors) {{ "Could not query volume parameters.", "Could not create alias.", "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) {