2022-04-10 08:22:58 +00:00
|
|
|
// Copyright 2022 Dietrich Epp.
|
|
|
|
// This file is part of SyncFiles. SyncFiles is licensed under the terms of the
|
|
|
|
// Mozilla Public License, version 2.0. See LICENSE.txt for details.
|
2022-11-16 23:19:05 +00:00
|
|
|
#include "macos/project.h"
|
2022-04-10 08:09:17 +00:00
|
|
|
|
2022-11-16 23:19:05 +00:00
|
|
|
#include "lib/crc32.h"
|
|
|
|
#include "macos/choose_directory.h"
|
|
|
|
#include "macos/error.h"
|
|
|
|
#include "macos/main.h"
|
|
|
|
#include "macos/path.h"
|
|
|
|
#include "macos/resources.h"
|
|
|
|
#include "macos/tempfile.h"
|
2022-04-10 08:09:17 +00:00
|
|
|
|
2022-11-16 23:32:52 +00:00
|
|
|
#include <Aliases.h>
|
2022-04-10 08:09:17 +00:00
|
|
|
#include <MacMemory.h>
|
|
|
|
#include <MacWindows.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
Project format:
|
|
|
|
|
|
|
|
Header:
|
|
|
|
byte[32] magic
|
|
|
|
uint32 version
|
2022-11-16 23:19:05 +00:00
|
|
|
uint32 header length
|
|
|
|
uint32 header crc32
|
2022-04-10 08:09:17 +00:00
|
|
|
uint32 chunk count
|
|
|
|
ckinfo[] chunk info
|
|
|
|
byte[] chunk data
|
|
|
|
|
|
|
|
Chunk info:
|
2022-11-16 23:19:05 +00:00
|
|
|
uint32 chunk ID
|
2022-04-10 08:09:17 +00:00
|
|
|
uint32 byte offset
|
|
|
|
uint32 byte length
|
2022-11-16 23:19:05 +00:00
|
|
|
uint32 chunk crc32
|
2022-04-10 08:09:17 +00:00
|
|
|
|
|
|
|
Chunks: (names zero-padded)
|
2022-11-16 23:19:05 +00:00
|
|
|
"LOCA" local directory alias
|
2023-05-06 18:03:13 +00:00
|
|
|
"LOCP" local directory path
|
2022-11-16 23:19:05 +00:00
|
|
|
"REMA" destination directory alias
|
2023-05-06 18:03:13 +00:00
|
|
|
"REMP" destination directory path
|
2022-04-10 08:09:17 +00:00
|
|
|
|
|
|
|
Chunks are aligned to 16 byte boundaries, and the file is padded to a 16 byte
|
|
|
|
boundary. This is just to make it easier to read hexdumps.
|
|
|
|
*/
|
|
|
|
|
2022-11-16 23:19:05 +00:00
|
|
|
#define kVersion 0x10000
|
|
|
|
|
2023-05-07 01:36:33 +00:00
|
|
|
#define kMaxChunkCount 32
|
2023-05-07 02:24:50 +00:00
|
|
|
#define kMaxChunkSize (4 * 1024)
|
2023-05-07 01:36:33 +00:00
|
|
|
|
2022-04-10 08:09:17 +00:00
|
|
|
// clang-format off
|
|
|
|
|
|
|
|
// Magic cookie that identifies project files.
|
2022-11-16 23:19:05 +00:00
|
|
|
static const unsigned char kMagic[32] = {
|
2022-04-10 08:09:17 +00:00
|
|
|
// Identify the file type.
|
2022-11-16 23:19:05 +00:00
|
|
|
'S', 'y', 'n', 'c', 'F', 'i', 'l', 'e', 's',
|
|
|
|
' ', 'P', 'r', 'o', 'j', 'e', 'c', 't',
|
2022-04-10 08:09:17 +00:00
|
|
|
// Detect newline conversions.
|
|
|
|
0, 10, 0, 13, 0, 13, 10, 0,
|
|
|
|
// Detect encoding conversions (infinity in Roman and UTF-8).
|
2022-11-16 23:19:05 +00:00
|
|
|
0xb0, 0, 0xe2, 0x88, 0x9e, 0, 0
|
2022-04-10 08:09:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
struct ProjectHeader {
|
|
|
|
UInt8 magic[32];
|
|
|
|
UInt32 version;
|
|
|
|
UInt32 size;
|
|
|
|
UInt32 crc32;
|
|
|
|
UInt32 chunkCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ProjectChunk {
|
2022-11-16 23:19:05 +00:00
|
|
|
UInt32 id;
|
2022-04-10 08:09:17 +00:00
|
|
|
UInt32 offset;
|
|
|
|
UInt32 size;
|
2022-11-16 23:19:05 +00:00
|
|
|
UInt32 crc32;
|
2022-04-10 08:09:17 +00:00
|
|
|
};
|
|
|
|
|
2023-05-07 02:24:50 +00:00
|
|
|
static const UInt32 kProjectAliasChunks[2] = {'LOCA', 'REMA'};
|
|
|
|
static const UInt32 kProjectPathChunks[2] = {'LOCP', 'REMP'};
|
|
|
|
|
2022-04-10 08:09:17 +00:00
|
|
|
// Dimensions of controls.
|
|
|
|
enum {
|
|
|
|
kVBorder = 10,
|
|
|
|
kHBorder = 10,
|
|
|
|
kDirVSize = 62,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kControlChooseDirLocal,
|
|
|
|
kControlChooseDirRemote,
|
|
|
|
};
|
|
|
|
|
|
|
|
// FIXME: this is redundant.
|
|
|
|
enum {
|
|
|
|
kDirLocal,
|
|
|
|
kDirRemote,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ProjectDir {
|
|
|
|
int pathLength;
|
|
|
|
Handle path;
|
|
|
|
AliasHandle alias;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A synchronization project.
|
|
|
|
struct Project {
|
|
|
|
int windowWidth;
|
|
|
|
int isActive;
|
|
|
|
|
2022-11-16 23:19:05 +00:00
|
|
|
// File reference to the project file, or fileRef == 0 otherwise.
|
2022-04-10 08:09:17 +00:00
|
|
|
short fileRef;
|
2022-11-16 23:19:05 +00:00
|
|
|
// Location of the project file, if vRefNum != 0. In a possible edge case,
|
|
|
|
// the fileSpec may be set even when fileRef is 0. This may happen if you
|
|
|
|
// save the project to a volume which does not support FSpExchangeFiles(),
|
|
|
|
// and the operation fails.
|
2022-04-10 08:09:17 +00:00
|
|
|
FSSpec fileSpec;
|
2022-11-16 23:19:05 +00:00
|
|
|
// Script code for the filename.
|
|
|
|
ScriptCode fileScript;
|
2022-04-10 08:09:17 +00:00
|
|
|
|
|
|
|
struct ProjectDir dirs[2];
|
|
|
|
};
|
|
|
|
|
2023-05-07 00:37:45 +00:00
|
|
|
// ProjectNewObject creates a new empty Project object.
|
|
|
|
static ProjectHandle ProjectNewObject(void)
|
2022-04-10 08:09:17 +00:00
|
|
|
{
|
|
|
|
ProjectHandle project;
|
|
|
|
|
|
|
|
project = (ProjectHandle)NewHandle(sizeof(struct Project));
|
|
|
|
if (project == NULL) {
|
2023-05-07 00:37:45 +00:00
|
|
|
ShowMemError();
|
|
|
|
return NULL;
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
2023-05-07 00:37:45 +00:00
|
|
|
memset(*project, 0, sizeof(struct Project));
|
|
|
|
return project;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProjectDelete deletes a Project object. It does not free any associated
|
|
|
|
// windows.
|
|
|
|
static void ProjectDelete(ProjectHandle project)
|
|
|
|
{
|
|
|
|
Handle h;
|
|
|
|
int i;
|
|
|
|
short fileRef;
|
|
|
|
|
|
|
|
fileRef = (*project)->fileRef;
|
|
|
|
if (fileRef != 0) {
|
|
|
|
FSClose(fileRef);
|
|
|
|
}
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
h = (*project)->dirs[i].path;
|
|
|
|
if (h != NULL) {
|
|
|
|
DisposeHandle(h);
|
|
|
|
}
|
|
|
|
h = (Handle)(*project)->dirs[i].alias;
|
|
|
|
if (h != NULL) {
|
|
|
|
DisposeHandle(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DisposeHandle((Handle)project);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProjectCreateWindow creates a window for a given Project object.
|
|
|
|
static void ProjectCreateWindow(ProjectHandle project)
|
|
|
|
{
|
|
|
|
WindowRef window;
|
|
|
|
ControlRef control;
|
|
|
|
int i, windowWidth, controlWidth;
|
|
|
|
|
2022-04-10 08:09:17 +00:00
|
|
|
window = GetNewCWindow(rWIND_Project, NULL, (WindowPtr)-1);
|
|
|
|
if (window == NULL) {
|
2023-05-06 23:41:40 +00:00
|
|
|
EXIT_INTERNAL();
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
|
|
|
windowWidth = window->portRect.right - window->portRect.left;
|
|
|
|
SetWRefCon(window, (long)project);
|
2023-05-07 00:37:45 +00:00
|
|
|
(*project)->windowWidth = windowWidth;
|
2022-04-10 08:09:17 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
control = GetNewControl(rCNTL_ChooseFolder, window);
|
|
|
|
if (control == NULL) {
|
2023-05-06 23:41:40 +00:00
|
|
|
EXIT_INTERNAL();
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
|
|
|
controlWidth =
|
|
|
|
(*control)->contrlRect.right - (*control)->contrlRect.left;
|
|
|
|
MoveControl(control, windowWidth - controlWidth - kHBorder,
|
|
|
|
kVBorder + kDirVSize * i + 22);
|
|
|
|
SetControlReference(control, kControlChooseDirLocal + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowWindow(window);
|
|
|
|
}
|
|
|
|
|
2023-05-07 00:37:45 +00:00
|
|
|
void ProjectNew(void)
|
|
|
|
{
|
|
|
|
ProjectHandle project;
|
|
|
|
|
|
|
|
project = ProjectNewObject();
|
|
|
|
if (project == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ProjectCreateWindow(project);
|
|
|
|
}
|
|
|
|
|
2023-05-07 01:36:33 +00:00
|
|
|
// ProjectReadError displays an error message encountered when trying to read a
|
|
|
|
// project.
|
|
|
|
static void ProjectReadError(ProjectHandle project, ErrorCode err, OSErr osErr)
|
|
|
|
{
|
|
|
|
StrFileName name;
|
|
|
|
|
|
|
|
memcpy(name, (*project)->fileSpec.name, sizeof(StrFileName));
|
|
|
|
ShowError(kErrCouldNotReadProject, err, osErr, name);
|
|
|
|
}
|
|
|
|
|
2023-05-07 02:24:50 +00:00
|
|
|
typedef enum ProjectChunkStatus {
|
|
|
|
kChunkNotFound,
|
|
|
|
kChunkFound,
|
|
|
|
kChunkError,
|
|
|
|
} ProjectChunkStatus;
|
|
|
|
|
|
|
|
static ProjectChunkStatus ProjectReadChunk(ProjectHandle project, int nchunks,
|
|
|
|
struct ProjectChunk **chunks,
|
|
|
|
UInt32 chunkID, Handle *dataPtr,
|
|
|
|
long *sizePtr)
|
|
|
|
{
|
|
|
|
struct ProjectChunk *chunk, *end;
|
|
|
|
UInt32 offset, size, crc32, gotCRC32;
|
|
|
|
long count;
|
|
|
|
Handle h;
|
|
|
|
OSErr osErr;
|
|
|
|
short fileRef;
|
|
|
|
|
|
|
|
chunk = *chunks;
|
|
|
|
end = chunk + nchunks;
|
|
|
|
for (; chunk < end; chunk++) {
|
|
|
|
if (chunk->id == chunkID) {
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return kChunkNotFound;
|
|
|
|
|
|
|
|
found:
|
|
|
|
offset = chunk->offset;
|
|
|
|
size = chunk->size;
|
|
|
|
crc32 = chunk->crc32;
|
|
|
|
if (size > kMaxChunkSize) {
|
|
|
|
ProjectReadError(project, kErrProjectLarge, 0);
|
|
|
|
return kChunkError;
|
|
|
|
}
|
|
|
|
h = NewHandle(size);
|
|
|
|
if (h == NULL) {
|
|
|
|
ProjectReadError(project, kErrOutOfMemory, MemError());
|
|
|
|
return kChunkError;
|
|
|
|
}
|
|
|
|
if (size > 0) {
|
|
|
|
fileRef = (*project)->fileRef;
|
|
|
|
osErr = SetFPos(fileRef, fsFromStart, offset);
|
|
|
|
if (osErr != 0) {
|
|
|
|
DisposeHandle(h);
|
|
|
|
ProjectReadError(project, kErrNone, osErr);
|
|
|
|
return kChunkError;
|
|
|
|
}
|
|
|
|
count = size;
|
|
|
|
osErr = FSRead(fileRef, &count, *h);
|
|
|
|
if (osErr != 0) {
|
|
|
|
DisposeHandle(h);
|
|
|
|
ProjectReadError(project, kErrNone, osErr);
|
|
|
|
return kChunkError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gotCRC32 = CRC32Update(0, *h, size);
|
|
|
|
if (crc32 != gotCRC32) {
|
|
|
|
DisposeHandle(h);
|
|
|
|
ProjectReadError(project, kErrProjectDamaged, 0);
|
|
|
|
return kChunkError;
|
|
|
|
}
|
|
|
|
*dataPtr = h;
|
|
|
|
*sizePtr = size;
|
|
|
|
return kChunkFound;
|
|
|
|
}
|
|
|
|
|
2023-05-07 01:36:33 +00:00
|
|
|
// ProjectRead reads the project from disk. Returns true on success.
|
|
|
|
static Boolean ProjectRead(ProjectHandle project)
|
|
|
|
{
|
|
|
|
struct ProjectHeader header;
|
|
|
|
struct ProjectChunk **chunks;
|
|
|
|
short fileRef;
|
|
|
|
long count, size;
|
|
|
|
ErrorCode err;
|
|
|
|
OSErr osErr;
|
2023-05-07 02:55:06 +00:00
|
|
|
int nchunks, i, pathLength;
|
2023-05-07 01:36:33 +00:00
|
|
|
UInt32 headerCRC, gotCRC;
|
2023-05-07 02:55:06 +00:00
|
|
|
Handle alias, path;
|
2023-05-07 02:24:50 +00:00
|
|
|
ProjectChunkStatus chunkStatus;
|
2023-05-07 02:55:06 +00:00
|
|
|
FSSpec folderSpec;
|
|
|
|
Boolean wasChanged;
|
2023-05-07 01:36:33 +00:00
|
|
|
|
|
|
|
chunks = NULL;
|
|
|
|
err = kErrNone;
|
|
|
|
osErr = 0;
|
|
|
|
|
|
|
|
fileRef = (*project)->fileRef;
|
|
|
|
osErr = SetFPos(fileRef, fsFromStart, 0);
|
|
|
|
if (osErr != 0) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
count = sizeof(header);
|
|
|
|
osErr = FSRead(fileRef, &count, &header);
|
|
|
|
if (osErr != 0) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (count < sizeof(header) ||
|
2023-05-07 02:24:50 +00:00
|
|
|
memcmp(header.magic, kMagic, sizeof(kMagic)) != 0) {
|
2023-05-07 01:36:33 +00:00
|
|
|
err = kErrProjectDamaged;
|
|
|
|
goto error;
|
|
|
|
}
|
2023-05-07 02:24:50 +00:00
|
|
|
if (header.chunkCount > kMaxChunkCount) {
|
|
|
|
err = kErrProjectLarge;
|
|
|
|
goto error;
|
|
|
|
}
|
2023-05-07 01:36:33 +00:00
|
|
|
headerCRC = header.crc32;
|
|
|
|
header.crc32 = 0;
|
|
|
|
gotCRC = CRC32Update(0, &header, sizeof(header));
|
|
|
|
nchunks = header.chunkCount;
|
|
|
|
if (nchunks > 0) {
|
|
|
|
size = sizeof(struct ProjectChunk) * nchunks;
|
|
|
|
chunks = (struct ProjectChunk **)NewHandle(size);
|
|
|
|
if (chunks == NULL) {
|
|
|
|
err = kErrOutOfMemory;
|
|
|
|
osErr = MemError();
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
count = size;
|
|
|
|
osErr = FSRead(fileRef, &count, *chunks);
|
|
|
|
if (osErr != 0) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (count < size) {
|
|
|
|
err = kErrProjectDamaged;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
gotCRC = CRC32Update(gotCRC, *chunks, size);
|
|
|
|
}
|
|
|
|
if (headerCRC != gotCRC) {
|
|
|
|
err = kErrProjectDamaged;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2023-05-07 02:24:50 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
2023-05-07 02:55:06 +00:00
|
|
|
chunkStatus = ProjectReadChunk(project, nchunks, chunks,
|
|
|
|
kProjectAliasChunks[i], &alias, &size);
|
|
|
|
switch (chunkStatus) {
|
|
|
|
case kChunkError:
|
2023-05-07 02:24:50 +00:00
|
|
|
goto errorSilent;
|
2023-05-07 02:55:06 +00:00
|
|
|
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;
|
2023-05-07 02:24:50 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-07 01:36:33 +00:00
|
|
|
|
|
|
|
if (chunks != NULL) {
|
|
|
|
DisposeHandle((Handle)chunks);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (chunks != NULL) {
|
|
|
|
DisposeHandle((Handle)chunks);
|
|
|
|
}
|
|
|
|
ProjectReadError(project, err, osErr);
|
|
|
|
return false;
|
2023-05-07 02:24:50 +00:00
|
|
|
|
|
|
|
errorSilent:
|
|
|
|
if (chunks != NULL) {
|
|
|
|
DisposeHandle((Handle)chunks);
|
|
|
|
}
|
|
|
|
return false;
|
2023-05-07 01:36:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectOpen(FSSpec *spec, ScriptCode script)
|
|
|
|
{
|
|
|
|
ProjectHandle project;
|
|
|
|
struct Project *projectp;
|
|
|
|
short fileRef;
|
|
|
|
OSErr err;
|
|
|
|
|
|
|
|
err = FSpOpenDF(spec, fsRdWrPerm, &fileRef);
|
|
|
|
if (err != noErr) {
|
|
|
|
ShowError(kErrCouldNotReadProject, kErrNone, err, spec->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
project = ProjectNewObject();
|
|
|
|
if (project == NULL) {
|
|
|
|
FSClose(fileRef);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
projectp = *project;
|
|
|
|
projectp->fileRef = fileRef;
|
|
|
|
memcpy(&projectp->fileSpec, spec, sizeof(FSSpec));
|
|
|
|
projectp->fileScript = script;
|
|
|
|
|
2023-05-07 02:55:06 +00:00
|
|
|
if (!ProjectRead(project)) {
|
|
|
|
// This will close the file.
|
|
|
|
ProjectDelete(project);
|
|
|
|
return;
|
|
|
|
}
|
2023-05-07 01:36:33 +00:00
|
|
|
|
2023-05-07 02:55:06 +00:00
|
|
|
ProjectCreateWindow(project);
|
2023-05-07 01:36:33 +00:00
|
|
|
}
|
|
|
|
|
2023-05-07 05:51:00 +00:00
|
|
|
static Boolean ProjectHasDirectory(ProjectHandle project, int which)
|
|
|
|
{
|
|
|
|
struct Project *projectp = *project;
|
|
|
|
return projectp->dirs[which].alias != NULL ||
|
|
|
|
projectp->dirs[which].path != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectAdjustMenus(ProjectHandle project, MenuHandle fileMenu,
|
|
|
|
MenuHandle projectMenu)
|
2022-04-10 08:09:17 +00:00
|
|
|
{
|
|
|
|
if (fileMenu != NULL) {
|
|
|
|
EnableItem(fileMenu, iFile_Close);
|
|
|
|
EnableItem(fileMenu, iFile_Save);
|
|
|
|
EnableItem(fileMenu, iFile_SaveAs);
|
|
|
|
EnableItem(fileMenu, iFile_Revert);
|
|
|
|
}
|
2023-05-07 05:51:00 +00:00
|
|
|
if (projectMenu != NULL) {
|
|
|
|
if (ProjectHasDirectory(project, kDirLocal) &&
|
|
|
|
ProjectHasDirectory(project, kDirRemote)) {
|
|
|
|
EnableItem(projectMenu, iProject_Upload);
|
|
|
|
EnableItem(projectMenu, iProject_Download);
|
|
|
|
} else {
|
|
|
|
DisableItem(projectMenu, iProject_Upload);
|
|
|
|
DisableItem(projectMenu, iProject_Download);
|
|
|
|
}
|
|
|
|
}
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ProjectClose(WindowRef window, ProjectHandle project)
|
|
|
|
{
|
|
|
|
KillControls(window);
|
|
|
|
DisposeWindow(window);
|
2023-05-07 00:37:45 +00:00
|
|
|
ProjectDelete(project);
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
|
|
|
|
2023-05-06 18:03:13 +00:00
|
|
|
#define kChunkCount 4
|
2022-04-10 08:09:17 +00:00
|
|
|
|
2022-11-16 23:30:59 +00:00
|
|
|
#define ALIGN(x) (((x) + 15) & ~(UInt32)15)
|
2022-04-10 08:09:17 +00:00
|
|
|
|
2022-11-16 23:19:05 +00:00
|
|
|
static OSErr ProjectWriteHeader(short refNum, int nchunks,
|
|
|
|
struct ProjectChunk *ckInfo)
|
2022-04-10 08:09:17 +00:00
|
|
|
{
|
2022-11-16 23:19:05 +00:00
|
|
|
Ptr ptr;
|
|
|
|
struct ProjectHeader *head;
|
|
|
|
UInt32 size;
|
|
|
|
long count;
|
|
|
|
OSErr err;
|
2022-04-10 08:09:17 +00:00
|
|
|
|
2022-11-16 23:19:05 +00:00
|
|
|
size = sizeof(struct ProjectHeader) + sizeof(struct ProjectChunk) * nchunks;
|
|
|
|
ptr = NewPtr(size);
|
|
|
|
if (ptr == NULL) {
|
2022-04-10 08:09:17 +00:00
|
|
|
return MemError();
|
|
|
|
}
|
2022-11-16 23:19:05 +00:00
|
|
|
head = (struct ProjectHeader *)ptr;
|
|
|
|
memcpy(head->magic, kMagic, sizeof(head->magic));
|
|
|
|
head->version = kVersion;
|
|
|
|
head->size = size;
|
|
|
|
head->crc32 = 0;
|
|
|
|
head->chunkCount = nchunks;
|
|
|
|
memcpy(ptr + sizeof(struct ProjectHeader), ckInfo,
|
|
|
|
nchunks * sizeof(struct ProjectChunk));
|
|
|
|
head->crc32 = CRC32Update(0, ptr, size);
|
|
|
|
|
|
|
|
count = size;
|
|
|
|
err = FSWrite(refNum, &count, ptr);
|
|
|
|
DisposePtr(ptr);
|
|
|
|
return err;
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 23:19:05 +00:00
|
|
|
static OSErr ProjectFlush(short refNum)
|
2022-04-10 08:09:17 +00:00
|
|
|
{
|
|
|
|
ParamBlockRec pb;
|
|
|
|
|
2022-11-16 23:19:05 +00:00
|
|
|
memset(&pb, 0, sizeof(pb));
|
|
|
|
pb.ioParam.ioRefNum = refNum;
|
|
|
|
return PBFlushFileSync(&pb);
|
|
|
|
}
|
2022-04-10 08:09:17 +00:00
|
|
|
|
2022-11-16 23:19:05 +00:00
|
|
|
// ProjectWriteContent writes the project data to the given file.
|
|
|
|
static OSErr ProjectWriteContent(ProjectHandle project, short refNum)
|
|
|
|
{
|
|
|
|
UInt32 pad[4];
|
|
|
|
OSErr err;
|
|
|
|
Handle ckData[kChunkCount];
|
|
|
|
struct ProjectChunk ckInfo[kChunkCount];
|
|
|
|
UInt32 off;
|
|
|
|
Size size;
|
|
|
|
Handle h;
|
|
|
|
int i, nchunks;
|
|
|
|
long count;
|
2022-04-10 08:09:17 +00:00
|
|
|
|
2022-11-16 23:19:05 +00:00
|
|
|
// Gather all chunks.
|
|
|
|
nchunks = 0;
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
h = (Handle)(*project)->dirs[i].alias;
|
|
|
|
if (h != NULL) {
|
|
|
|
ckData[nchunks] = h;
|
|
|
|
ckInfo[nchunks].id = kProjectAliasChunks[i];
|
|
|
|
nchunks++;
|
|
|
|
}
|
2023-05-06 18:03:13 +00:00
|
|
|
h = (*project)->dirs[i].path;
|
|
|
|
if (h != NULL) {
|
|
|
|
ckData[nchunks] = h;
|
|
|
|
ckInfo[nchunks].id = kProjectPathChunks[i];
|
|
|
|
nchunks++;
|
|
|
|
}
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 23:19:05 +00:00
|
|
|
// Calculate chunk offsets.
|
|
|
|
off = sizeof(struct ProjectHeader) + sizeof(struct ProjectChunk) * nchunks;
|
|
|
|
for (i = 0; i < nchunks; i++) {
|
|
|
|
size = GetHandleSize(ckData[i]);
|
|
|
|
ckInfo[i].offset = off;
|
|
|
|
ckInfo[i].size = size;
|
|
|
|
ckInfo[i].crc32 = CRC32Update(0, *ckData[i], size);
|
|
|
|
off = ALIGN(off + size);
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 23:19:05 +00:00
|
|
|
// Write file. Refer to IM: Files listing 1-9, page 1-24.
|
|
|
|
err = SetEOF(refNum, off);
|
2022-04-10 08:09:17 +00:00
|
|
|
if (err != noErr) {
|
2022-11-16 23:19:05 +00:00
|
|
|
return err;
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
2022-11-16 23:19:05 +00:00
|
|
|
err = ProjectWriteHeader(refNum, nchunks, ckInfo);
|
2022-04-10 08:09:17 +00:00
|
|
|
if (err != noErr) {
|
2022-11-16 23:19:05 +00:00
|
|
|
return err;
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
2022-11-16 23:19:05 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
pad[i] = 0;
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
2022-11-16 23:19:05 +00:00
|
|
|
for (i = 0; i < nchunks; i++) {
|
|
|
|
size = ckInfo[i].size;
|
|
|
|
count = size;
|
|
|
|
err = FSWrite(refNum, &count, *ckData[i]);
|
|
|
|
if (err != noErr) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
count = (-size) & 15;
|
|
|
|
if (count > 0) {
|
|
|
|
err = FSWrite(refNum, &count, pad);
|
|
|
|
if (err != noErr) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 23:19:05 +00:00
|
|
|
return noErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A SaveMode describes the exact type of save operation.
|
|
|
|
typedef enum {
|
|
|
|
// kSaveNew indicates that the file is new, it does not exist yet.
|
|
|
|
kSaveNew,
|
|
|
|
// kSaveReplace indicates that the file is being saved over an existing
|
|
|
|
// file.
|
|
|
|
kSaveReplace,
|
|
|
|
// kSaveUpdate indicates that the file is being updated in-place.
|
|
|
|
kSaveUpdate
|
|
|
|
} SaveMode;
|
|
|
|
|
|
|
|
// ProjectCloseFile closes any open files and sets the file ref to 0.
|
|
|
|
static void ProjectCloseFile(ProjectHandle project)
|
|
|
|
{
|
|
|
|
struct Project *projectp;
|
|
|
|
|
2022-04-10 08:09:17 +00:00
|
|
|
projectp = *project;
|
|
|
|
if (projectp->fileRef != 0) {
|
|
|
|
FSClose(projectp->fileRef);
|
|
|
|
}
|
2022-11-16 23:19:05 +00:00
|
|
|
}
|
2022-04-10 08:09:17 +00:00
|
|
|
|
2022-11-16 23:19:05 +00:00
|
|
|
// ProjectSetFile closes any open files and replaces them with the given file.
|
|
|
|
static void ProjectSetFile(ProjectHandle project, short fileRef, FSSpec *spec)
|
|
|
|
{
|
|
|
|
struct Project *projectp;
|
|
|
|
|
|
|
|
projectp = *project;
|
|
|
|
if (projectp->fileRef != 0) {
|
|
|
|
FSClose(projectp->fileRef);
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
2022-11-16 23:19:05 +00:00
|
|
|
projectp->fileRef = fileRef;
|
|
|
|
memcpy(&projectp->fileSpec, spec, sizeof(FSSpec));
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 23:19:05 +00:00
|
|
|
// ProjectWrite writes the project to a file.
|
|
|
|
static OSErr ProjectWrite(ProjectHandle project, FSSpec *spec,
|
|
|
|
ScriptCode script, SaveMode mode)
|
2022-04-10 08:09:17 +00:00
|
|
|
{
|
2022-11-16 23:19:05 +00:00
|
|
|
HParamBlockRec hb;
|
|
|
|
CMovePBRec cm;
|
2022-04-10 08:09:17 +00:00
|
|
|
FSSpec temp;
|
|
|
|
OSErr err;
|
2022-11-16 23:19:05 +00:00
|
|
|
short refNum;
|
2022-04-10 08:09:17 +00:00
|
|
|
|
2023-04-20 06:07:14 +00:00
|
|
|
// See IM: Files, p. 1-25, Listing 1-10 "Updating a File Safely".
|
|
|
|
|
2022-11-16 23:19:05 +00:00
|
|
|
err = MakeTempFile(spec->vRefNum, &temp);
|
2022-04-10 08:09:17 +00:00
|
|
|
if (err != noErr) {
|
2022-11-16 23:19:05 +00:00
|
|
|
return err;
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
2022-11-16 23:19:05 +00:00
|
|
|
err = FSpCreate(&temp, kCreator, kTypeProject, script);
|
2022-04-10 08:09:17 +00:00
|
|
|
if (err != noErr) {
|
2022-11-16 23:19:05 +00:00
|
|
|
return err;
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
2022-11-16 23:19:05 +00:00
|
|
|
err = FSpOpenDF(&temp, fsRdWrPerm, &refNum);
|
2022-04-10 08:09:17 +00:00
|
|
|
if (err != noErr) {
|
2022-11-16 23:19:05 +00:00
|
|
|
goto error1;
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
2022-11-16 23:19:05 +00:00
|
|
|
err = ProjectWriteContent(project, refNum);
|
2022-04-10 08:09:17 +00:00
|
|
|
if (err != noErr) {
|
2022-11-16 23:19:05 +00:00
|
|
|
goto error2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For ordinary "Save", swap the file contents.
|
|
|
|
if (mode == kSaveUpdate) {
|
|
|
|
err = FSpExchangeFiles(&temp, spec);
|
|
|
|
if (err == noErr) {
|
|
|
|
err = FlushVol(NULL, spec->vRefNum);
|
|
|
|
if (err != noErr) {
|
|
|
|
FSClose(refNum);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
ProjectSetFile(project, refNum, spec);
|
|
|
|
// FIXME: What error handling, here?
|
|
|
|
FSpDelete(&temp);
|
|
|
|
return noErr;
|
|
|
|
}
|
|
|
|
// paramErr: function not supported by volume.
|
|
|
|
if (err != paramErr) {
|
|
|
|
goto error2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectCloseFile(project);
|
|
|
|
if (mode != kSaveNew) {
|
|
|
|
// For replace or update, the file already exists.
|
|
|
|
err = FSpDelete(spec);
|
|
|
|
if (err != noErr && err != fnfErr) {
|
|
|
|
goto error2;
|
|
|
|
}
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
2022-11-16 23:19:05 +00:00
|
|
|
|
|
|
|
// Try move & rename.
|
|
|
|
memset(&hb, 0, sizeof(hb));
|
|
|
|
hb.copyParam.ioNamePtr = temp.name;
|
|
|
|
hb.copyParam.ioVRefNum = temp.vRefNum;
|
|
|
|
hb.copyParam.ioNewName = spec->name;
|
|
|
|
hb.copyParam.ioNewDirID = spec->parID;
|
|
|
|
hb.copyParam.ioDirID = temp.parID;
|
|
|
|
err = PBHMoveRenameSync(&hb);
|
|
|
|
if (err == noErr) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
// paramErr: function not supported by volume.
|
|
|
|
if (err != paramErr) {
|
|
|
|
goto error2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try move, then rename.
|
|
|
|
memset(&cm, 0, sizeof(cm));
|
|
|
|
cm.ioNamePtr = temp.name;
|
|
|
|
cm.ioVRefNum = temp.vRefNum;
|
|
|
|
cm.ioNewDirID = spec->parID;
|
|
|
|
cm.ioDirID = temp.parID;
|
|
|
|
err = PBCatMoveSync(&cm);
|
2022-04-10 08:09:17 +00:00
|
|
|
if (err != noErr) {
|
2022-11-16 23:19:05 +00:00
|
|
|
goto error2;
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
2022-11-16 23:19:05 +00:00
|
|
|
temp.parID = spec->parID;
|
|
|
|
err = FSpRename(&temp, spec->name);
|
2022-04-10 08:09:17 +00:00
|
|
|
if (err != noErr) {
|
2022-11-16 23:19:05 +00:00
|
|
|
goto error2;
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
2022-11-16 23:19:05 +00:00
|
|
|
done:
|
|
|
|
err = FlushVol(NULL, spec->vRefNum);
|
2022-04-10 08:09:17 +00:00
|
|
|
if (err != noErr) {
|
2022-11-16 23:19:05 +00:00
|
|
|
FSClose(refNum);
|
|
|
|
return err;
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
2022-11-16 23:19:05 +00:00
|
|
|
ProjectSetFile(project, refNum, spec);
|
|
|
|
return noErr;
|
|
|
|
|
|
|
|
error2:
|
|
|
|
FSClose(refNum);
|
|
|
|
error1:
|
2022-04-10 08:09:17 +00:00
|
|
|
FSpDelete(&temp);
|
2022-11-16 23:19:05 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A SaveCommand distinguishes between Save and Save As.
|
|
|
|
typedef enum { kSave, kSaveAs } SaveCommand;
|
|
|
|
|
|
|
|
// ProjectSave handles the Save and SaveAs menu commands.
|
|
|
|
static void ProjectSave(WindowRef window, ProjectHandle project,
|
|
|
|
SaveCommand cmd)
|
|
|
|
{
|
|
|
|
// See listing 1-12 in IM: Files.
|
|
|
|
Str255 name;
|
|
|
|
StandardFileReply reply;
|
|
|
|
OSErr err;
|
|
|
|
FSSpec spec;
|
|
|
|
ScriptCode script;
|
|
|
|
|
|
|
|
if (cmd == kSaveAs || (*project)->fileSpec.vRefNum == 0) {
|
|
|
|
GetWTitle(window, name);
|
2023-04-20 06:07:14 +00:00
|
|
|
// FIXME: Move string to resource.
|
2022-11-16 23:19:05 +00:00
|
|
|
StandardPutFile("\pSave project as:", name, &reply);
|
|
|
|
if (!reply.sfGood) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ProjectWrite(project, &reply.sfFile, reply.sfScript,
|
|
|
|
reply.sfReplacing ? kSaveReplace : kSaveNew);
|
|
|
|
if (err != noErr) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
SetWTitle(window, reply.sfFile.name);
|
|
|
|
} else {
|
|
|
|
memcpy(&spec, &(*project)->fileSpec, sizeof(FSSpec));
|
|
|
|
script = (*project)->fileScript;
|
|
|
|
err = ProjectWrite(project, &spec, script, kSaveUpdate);
|
|
|
|
if (err != noErr) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-10 08:09:17 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
2023-05-06 23:41:40 +00:00
|
|
|
ShowError(kErrCouldNotSaveProject, kErrNone, err, reply.sfFile.name);
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectCommand(WindowRef window, ProjectHandle project, int menuID,
|
|
|
|
int item)
|
|
|
|
{
|
|
|
|
switch (menuID) {
|
|
|
|
case rMENU_File:
|
|
|
|
switch (item) {
|
|
|
|
case iFile_Close:
|
|
|
|
ProjectClose(window, project);
|
|
|
|
break;
|
|
|
|
case iFile_Save:
|
2022-11-16 23:19:05 +00:00
|
|
|
ProjectSave(window, project, kSave);
|
2022-04-10 08:09:17 +00:00
|
|
|
break;
|
|
|
|
case iFile_SaveAs:
|
2022-11-16 23:19:05 +00:00
|
|
|
ProjectSave(window, project, kSaveAs);
|
2022-04-10 08:09:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectUpdate(WindowRef window, ProjectHandle project)
|
|
|
|
{
|
|
|
|
struct Project *projectp;
|
|
|
|
Rect rect;
|
|
|
|
Handle text;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
HLock((Handle)project);
|
|
|
|
|
|
|
|
projectp = *project;
|
|
|
|
rect = window->portRect;
|
|
|
|
EraseRect(&rect);
|
|
|
|
MoveTo(0, kVBorder + kDirVSize - 10);
|
|
|
|
LineTo(projectp->windowWidth, kVBorder + kDirVSize - 10);
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
MoveTo(kHBorder, kVBorder + kDirVSize * i + 12);
|
|
|
|
DrawString(i == 0 ? "\pLocal Folder" : "\pRemote Folder");
|
|
|
|
text = projectp->dirs[i].path;
|
|
|
|
if (text != NULL) {
|
|
|
|
HLock(text);
|
|
|
|
MoveTo(kHBorder, kVBorder + kDirVSize * i + 36);
|
|
|
|
DrawText(*text, 0, projectp->dirs[i].pathLength);
|
|
|
|
HUnlock(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UpdateControls(window, window->visRgn);
|
|
|
|
|
|
|
|
HUnlock((Handle)project);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectActivate(WindowRef window, ProjectHandle project, int isActive)
|
|
|
|
{
|
|
|
|
struct Project *projectp;
|
|
|
|
|
|
|
|
projectp = *project;
|
|
|
|
if (projectp->isActive != isActive) {
|
|
|
|
projectp->isActive = isActive;
|
|
|
|
InvalRect(&window->portRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-06 18:03:13 +00:00
|
|
|
// VolumeDoesSupportIDs returns true if the volume supports file IDs. If the
|
|
|
|
// volume does not support file IDs, then we fall back to using paths to refer
|
|
|
|
// to project directories. This applies to the Basilisk II "Unix" volume. If you
|
|
|
|
// try to resolve an alias to a file on the Basilisk II "Unix" volume, you may
|
|
|
|
// get a different file than intended, because the directory IDs are not stable.
|
|
|
|
static Boolean VolumeDoesSupportIDs(short vRefNum)
|
|
|
|
{
|
|
|
|
HParamBlockRec hb;
|
|
|
|
GetVolParmsInfoBuffer parms;
|
|
|
|
OSErr err;
|
|
|
|
|
|
|
|
memset(&hb, 0, sizeof(hb));
|
|
|
|
hb.ioParam.ioVRefNum = vRefNum;
|
|
|
|
hb.ioParam.ioBuffer = (Ptr)&parms;
|
|
|
|
hb.ioParam.ioReqCount = sizeof(parms);
|
|
|
|
err = PBHGetVolParms(&hb, false);
|
|
|
|
if (err != noErr) {
|
2023-05-06 23:41:40 +00:00
|
|
|
ShowError(kErrVolumeQuery, kErrNone, err, NULL);
|
|
|
|
return false;
|
2023-05-06 18:03:13 +00:00
|
|
|
}
|
|
|
|
return (parms.vMAttrib & (1ul << bHasFileIDs)) != 0;
|
|
|
|
}
|
|
|
|
|
2022-04-10 08:09:17 +00:00
|
|
|
static void ProjectChooseDir(WindowRef window, ProjectHandle project,
|
|
|
|
int whichDir)
|
|
|
|
{
|
|
|
|
struct Project *projectp;
|
|
|
|
struct ProjectDir *dirp;
|
|
|
|
FSSpec directory;
|
2022-11-16 23:32:52 +00:00
|
|
|
AliasHandle alias;
|
2022-04-10 08:09:17 +00:00
|
|
|
Handle path;
|
|
|
|
int pathLength;
|
|
|
|
OSErr err;
|
|
|
|
|
2022-11-16 23:32:52 +00:00
|
|
|
if (!ChooseDirectory(&directory)) {
|
|
|
|
return;
|
|
|
|
}
|
2023-05-06 18:03:13 +00:00
|
|
|
if (VolumeDoesSupportIDs(directory.vRefNum)) {
|
|
|
|
err = NewAlias(NULL, &directory, &alias);
|
|
|
|
if (err != noErr) {
|
2023-05-06 23:41:40 +00:00
|
|
|
ShowError(kErrAlias, kErrNone, err, NULL);
|
|
|
|
return;
|
2023-05-06 18:03:13 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
alias = NULL;
|
2022-11-16 23:32:52 +00:00
|
|
|
}
|
|
|
|
err = GetDirPath(&directory, &pathLength, &path);
|
|
|
|
if (err != noErr) {
|
2023-05-06 23:41:40 +00:00
|
|
|
ShowError(kErrDirPath, kErrNone, err, NULL);
|
|
|
|
if (alias != NULL) {
|
|
|
|
DisposeHandle((Handle)alias);
|
|
|
|
}
|
|
|
|
return;
|
2022-11-16 23:32:52 +00:00
|
|
|
}
|
2023-05-06 23:41:40 +00:00
|
|
|
|
2022-11-16 23:32:52 +00:00
|
|
|
projectp = *project;
|
|
|
|
dirp = &projectp->dirs[whichDir];
|
|
|
|
if (dirp->path != NULL) {
|
|
|
|
DisposeHandle(dirp->path);
|
|
|
|
}
|
|
|
|
dirp->pathLength = pathLength;
|
|
|
|
dirp->path = path;
|
|
|
|
if (dirp->alias != NULL) {
|
|
|
|
DisposeHandle((Handle)dirp->alias);
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
2022-11-16 23:32:52 +00:00
|
|
|
dirp->alias = alias;
|
|
|
|
InvalRect(&window->portRect);
|
2022-04-10 08:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectMouseDown(WindowRef window, ProjectHandle project,
|
|
|
|
EventRecord *event)
|
|
|
|
{
|
|
|
|
Point mouse;
|
|
|
|
GrafPtr savedPort;
|
|
|
|
ControlRef control;
|
|
|
|
ControlPartCode part;
|
|
|
|
long reference;
|
|
|
|
|
|
|
|
GetPort(&savedPort);
|
|
|
|
SetPort(window);
|
|
|
|
mouse = event->where;
|
|
|
|
GlobalToLocal(&mouse);
|
|
|
|
part = FindControl(mouse, window, &control);
|
|
|
|
switch (part) {
|
|
|
|
case kControlButtonPart:
|
|
|
|
reference = GetControlReference(control);
|
|
|
|
if (TrackControl(control, mouse, NULL) != 0) {
|
|
|
|
switch (reference) {
|
|
|
|
case kControlChooseDirLocal:
|
|
|
|
ProjectChooseDir(window, project, kDirLocal);
|
|
|
|
break;
|
|
|
|
case kControlChooseDirRemote:
|
|
|
|
ProjectChooseDir(window, project, kDirRemote);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SetPort(savedPort);
|
|
|
|
}
|