From e2b2305b109894c5eeebc6783e5dd7f39acd80ba Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Fri, 19 Apr 2019 17:17:09 -0500 Subject: [PATCH] Improved clean-up code. This shouldn't ordinarily make any difference, but it may help to ensure things are correctly handled in some corner cases. --- diskbrowser.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/diskbrowser.c b/diskbrowser.c index 3648603..be4af9f 100644 --- a/diskbrowser.c +++ b/diskbrowser.c @@ -5,6 +5,7 @@ #pragma rtl #include +#include #include #include #include @@ -70,7 +71,7 @@ void InstallMenuItem(void) { /* .itemTitleRef = */ (Long)&menuTitle }; - tellFinderAddToExtrasOut dataOutRec; + tellFinderAddToExtrasOut dataOutRec = {0}; SendRequest(tellFinderAddToExtras, sendToName|stopAfterOne, (Long)NAME_OF_FINDER, @@ -84,12 +85,24 @@ void InstallMenuItem(void) { } } +void RemoveMenuItem(void) { + tellFinderRemoveFromExtrasOut dataOutRec = {0}; + + if (menuItemID == 0) + return; + + SendRequest(tellFinderRemoveFromExtras, sendToName|stopAfterOne, + (Long)NAME_OF_FINDER, + (Long)menuItemID, + (Ptr)&dataOutRec); + menuItemID = 0; +} + void DoGoAway(void) { CloseBrowserWindow(); - + RemoveMenuItem(); + AcceptRequests(NULL, myUserID, NULL); ResourceShutDown(); - - /* TODO remove menu item, other cleanup? */ } /* @@ -103,6 +116,10 @@ static pascal Word requestProc(Word reqCode, Long dataIn, void *dataOut) { InstallMenuItem(); break; + case finderSaysGoodbye: + RemoveMenuItem(); + break; + case finderSaysExtrasChosen: if ((dataIn & 0x0000FFFF) == menuItemID) { ShowBrowserWindow(); @@ -158,5 +175,10 @@ int main(void) { return 1; } + /* Check for List Manager, in case future Finder doesn't start it. */ + if (!ListStatus() || toolerror()) { + return 1; + } + AcceptRequests(diskbrowserRequestName, myUserID, &requestProc); }