From 6be698833d29007a977da15aa97b9edcf155a3f9 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Wed, 19 Apr 2017 21:10:23 -0500 Subject: [PATCH] Detect if AFPBridge and Marinetti are installed, and give an error/warning if not. We indicate that AFPBridge is installed by creating a message in the message center (which also includes its version, in case we want to distinguish between different versions in the future). --- afpbridge.c | 27 ++++++++++++++++++++++----- afpcdev.c | 32 ++++++++++++++++++++++++++++++++ afpcdev.rez | 19 +++++++++++++++++++ 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/afpbridge.c b/afpbridge.c index 56c656d..007aa76 100644 --- a/afpbridge.c +++ b/afpbridge.c @@ -7,17 +7,25 @@ #include #include #include +#include #include "installcmds.h" #include "aspinterface.h" #include "asmglue.h" const char bootInfoString[] = "AFPBridge v1.0b1"; +LongWord version = 0x01006001; /* in rVersion format */ + +const char versionMessageString[] = "\pSTH~AFPBridge~Version~"; + +typedef struct VersionMessageRec { + Word blockLen; + char nameString[23]; + LongWord dataBlock; +} VersionMessageRec; extern Word *unloadFlagPtr; extern void resetRoutine(void); -FSTInfoRecGS fstInfoRec; - void pollTask(void); void notificationProc(void); @@ -40,9 +48,7 @@ static struct NotificationProcRec { void (*proc)(void); } notificationProcRec; -NotifyProcRecGS addNotifyProcRec; - -LongWord *SoftResetPtr = (LongWord *)0xE11010; +#define SoftResetPtr ((LongWord *)0xE11010) extern LongWord oldSoftReset; #define JML 0x5C @@ -54,6 +60,9 @@ void setUnloadFlag(void) { int main(void) { unsigned int i; + FSTInfoRecGS fstInfoRec; + NotifyProcRecGS addNotifyProcRec; + VersionMessageRec versionMessageRec; /* * Check for presence of AppleShare FST. We error out and unload @@ -79,6 +88,14 @@ int main(void) { if (toolerror() && toolerror() != terrINITNOTFOUND) goto error; + versionMessageRec.blockLen = sizeof(versionMessageRec); + memcpy(versionMessageRec.nameString, versionMessageString, + sizeof(versionMessageRec.nameString)); + versionMessageRec.dataBlock = version; + MessageByName(TRUE, (Pointer)&versionMessageRec); + if (toolerror()) + goto error; + ShowBootInfo(bootInfoString, NULL); /* diff --git a/afpcdev.c b/afpcdev.c index 643ec21..c646857 100644 --- a/afpcdev.c +++ b/afpcdev.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "afpoptions.h" #include "afpurlparser.h" #include "strncasecmp.h" @@ -56,6 +57,8 @@ #define aliasFileError 3003 #define tempFileNameError 3004 #define saveAliasError 3005 +#define noAFPBridgeError 3006 +#define noAFPBridgeWarning 3007 #define EM_filetype 0xE2 #define EM_auxtype 0xFFFF @@ -320,6 +323,25 @@ void ConnectOrSave(AFPURLParts* urlParts, GSString255Ptr file, Boolean connect) } } +Boolean checkVersions(void) +{ + static struct { + Word blockLen; + char nameString[23]; + } messageRec = { sizeof(messageRec), "\pSTH~AFPBridge~Version~" }; + + /* Check if AFPBridge is active (any version is OK) */ + MessageByName(FALSE, (Pointer)&messageRec); + if (toolerror()) + return FALSE; + + /* Check for Marinetti (AFPBridge will keep it active if installed) */ + if (!TCPIPStatus() || toolerror()) + return FALSE; + + return TRUE; +} + void DoConnect(void) { Word i; @@ -333,6 +355,11 @@ void DoConnect(void) if (urlParts.protocol == proto_invalid) goto fixcaret; + if (urlParts.protocol == proto_TCP && !checkVersions()) { + AlertWindow(awResource+awButtonLayout, NULL, noAFPBridgeError); + goto fixcaret; + } + /* Generate the path name for the temp file in same dir as the CDev */ getRefInfoRec.pCount = 3; getRefInfoRec.refNum = GetOpenFileRefNum(0); /* current resource file */ @@ -378,6 +405,11 @@ void DoSave(void) if (urlParts.protocol == proto_invalid) return; + if (urlParts.protocol == proto_TCP && !checkVersions()) { + if (AlertWindow(awResource+awButtonLayout, NULL, noAFPBridgeWarning)==0) + return; + } + /* Load Standard File toolset if necessary */ if (!SFStatus() || toolerror()) { if (toolerror()) diff --git a/afpcdev.rez b/afpcdev.rez index a8bafb3..4733752 100644 --- a/afpcdev.rez +++ b/afpcdev.rez @@ -301,6 +301,8 @@ resource rPString(saveFilePrompt) { "Save server alias as:" }; #define aliasFileError 3003 #define tempFileNameError 3004 #define saveAliasError 3005 +#define noAFPBridgeError 3006 +#define noAFPBridgeWarning 3007 #define protoInvalidError 4000 #define noServerOrVolumeNameError 4001 @@ -418,3 +420,20 @@ resource rAlertString (saveAliasError) { "There was an error while attempting to save the alias file." ":^#0\$00" }; + +resource rAlertString (noAFPBridgeError) { + "62:" + "To connect to AFP servers over TCP, AFPBridge and Marinetti " + "must be installed and enabled. Please install them and then " + "restart your system." + ":^#0\$00" +}; + +resource rAlertString (noAFPBridgeWarning) { + "74:" + "To connect to AFP servers over TCP, AFPBridge and Marinetti " + "must be installed and enabled. You can continue to save an " + "alias now, but to connect to the server you will need to " + "install them and then restart your system." + ":#1:^#6\$00" +};