short ModalMacros(NewMacroInfo *macrost) { DialogPtr dtemp; short dItem; short i; Rect dBox; Str255 temp; Handle MacString[10], rubbish; SetUpMovableModalMenus(); dtemp=GetNewMyDialog( MacroDLOG + 2, NULL, kInFront, (void *)ThirdCenterDialog); SetDialogDefaultItem(dtemp, 1); SetDialogCancelItem(dtemp, 2); SetDialogTracksCursor(dtemp, 1); HideDialogItem(dtemp, 25); // no save default in session macros dialog dialogPane = 0; // start with Command-[0-9] // RAB BetterTelnet 2.0b5 - fix cancel button so it works again oldMacros = macrost->handle; HandToHand(&oldMacros); oldMacroIndexes = *macrost; // now fix the strings for (i=0; i<10; i++) { GetIndString(temp, 7100, i + (10 * dialogPane) + 1); GetDialogItem(dtemp, i+3, &dItem, &rubbish, &dBox); if (!temp[0]) { HideDialogItem(dtemp, i+13); HideDialogItem(dtemp, i+3); } else { ShowDialogItem(dtemp, i+13); ShowDialogItem(dtemp, i+3); } SetDialogItemText(rubbish, temp); } for (i=0; i<10; i++) { getmacro(macrost, i, (char *) &temp, 256); /* BYU LSC */ c2pstr((char *)temp); /* BYU LSC */ GetDialogItem( dtemp, i+13, &dItem, &MacString[i], &dBox); SetDialogItemText( MacString[i], temp ); } TelInfo->macrosModeless = dtemp; dItem = 0; while ((dItem != 1) && (dItem != 2)) { movableModalDialog(0, &dItem); MacroDialog(macrost, dtemp, 0, dItem); } if (dItem == 2) CancelMacros(macrost, dtemp); else CloseMacros(macrost, dtemp); ResetMenus(); return dItem; }
/**************************************************************** HideDPopup() hides the given popup item and its label item. ****************************************************************/ void HideDPopup(DialogPtr theDialog, short item) { short i; for ( i = 0 ; i < sa_numPopUps ; i++ ) if ( (sa_popTable[i].dialogPtr == theDialog) && (sa_popTable[i].popupItemNum == item) ) break; if (i < sa_numPopUps) { HideDialogItem(theDialog, sa_popTable[i].popupItemNum); if (sa_popTable[i].titleItemNum) HideDialogItem(theDialog, sa_popTable[i].titleItemNum); } }
short PGFAlert(char *inCStr, short allowCancel) { #ifdef PGP_MACINTOSH DialogPtr pfAlert; GrafPtr savePort; short result=0, i; Str255 s; GetPort(&savePort); strcpy((char *)s, inCStr); c2pstr((char *)s); if((pfAlert = GetNewDialog(130,nil,(WindowPtr)-1L)) != NULL) { SetPort(pfAlert); ParamText((uchar *)s,"\p","\p","\p"); if(!allowCancel) HideDialogItem(pfAlert,2); SetDialogCancelItem(pfAlert, 2); SetDialogDefaultItem(pfAlert, 1); ShowWindow(pfAlert); SysBeep(30); ModalDialog(nil, &i); DisposeDialog(pfAlert); result = (i==1); }
void Macros( void) { DialogPtr dtemp; short dItem; short i; Rect dBox; Str255 temp; Handle MacString[10], rubbish; setLastCursor(theCursors[normcurs]); if (TelInfo->macrosModeless) { SelectWindow(TelInfo->macrosModeless); return; } dtemp=GetNewMyDialog( MacroDLOG, NULL, kInFront, (void *)ThirdCenterDialog); SetDialogDefaultItem(dtemp, 1); SetDialogCancelItem(dtemp, 2); SetDialogTracksCursor(dtemp, 1); dialogPane = 0; // start with Command-[0-9] // RAB BetterTelnet 2.0b5 - fix cancel button so it works again oldMacros = TelInfo->newMacros.handle; HandToHand(&oldMacros); oldMacroIndexes = TelInfo->newMacros; // now fix the strings for (i=0; i<10; i++) { GetIndString(temp, 7100, i + (10 * dialogPane) + 1); GetDialogItem(dtemp, i+3, &dItem, &rubbish, &dBox); if (!temp[0]) { HideDialogItem(dtemp, i+13); HideDialogItem(dtemp, i+3); } else { ShowDialogItem(dtemp, i+13); ShowDialogItem(dtemp, i+3); } SetDialogItemText(rubbish, temp); } for (i=0; i<10; i++) { getmacro(&TelInfo->newMacros, i, (char *) &temp, 256); /* BYU LSC */ c2pstr((char *)temp); /* BYU LSC */ GetDialogItem( dtemp, i+13, &dItem, &MacString[i], &dBox); SetDialogItemText( MacString[i], temp ); } TelInfo->macrosModeless = dtemp; }
static void RunDialogTheSystem6or7Way(DialogRef theDialog) { SInt16 itemHit; DialogItemType itemType; Handle itemHandle; Rect itemBox; BringToFront(GetDialogWindow(theDialog)); do { ModalDialog(MySystem6or7DialogFilter, &itemHit); switch (itemHit) { case 2: { // we enable or disable the user item depending on whether the box is checked or not GetDialogItem(theDialog, itemHit, &itemType, &itemHandle, &itemBox); SInt16 enable = GetControlValue((ControlHandle)itemHandle); SetControlValue((ControlHandle)itemHandle, 1 - enable); GetDialogItem(theDialog, 13, &itemType, &itemHandle, &itemBox); SetDialogItem(theDialog, 13, enable?userItem+itemDisable:userItem, itemHandle, &itemBox); HideDialogItem(theDialog, 13); ShowDialogItem(theDialog, 13); } break; case 3: case 4: case 5: case 6: case 7: { // one radio button was chosen, let's adjust them all (we could also remember the last one...) int i; for (i = 3; i <= 7; i++) { GetDialogItem(theDialog, i, &itemType, &itemHandle, &itemBox); SetControlValue((ControlHandle)itemHandle, (i == itemHit)?1:0); } } break; case 14: { // the indicator of the scroll bar was moved so let's display the value in the first edit box // this is System 6 or 7 style so the controls can only handle 16 bits value (hence a max of 32767) GetDialogItem(theDialog, itemHit, &itemType, &itemHandle, &itemBox); SInt16 newValue = GetControlValue((ControlHandle)itemHandle); Str255 theStr; NumToString(newValue, theStr); GetDialogItem(theDialog, 9, &itemType, &itemHandle, &itemBox); SetDialogItemText(itemHandle, theStr); SelectDialogItemText(theDialog, 9, 0, 32767); } break; } } while (!(itemHit == ok)); DisposeDialog(theDialog); }
void MySelectDialogItemText(DialogRef theDialog, short editTextitemNum, short strtSel, short endSel) { #if TARGET_API_MAC_CARBON // with the new MAC code, the edit text item with the focus was not showing the text // it acted like the text was invisible... like it had drawn it and didn't care to redraw it. // I don't know what is up with that, but Hiding and Showing the item seems to do the trick // even though InvalDialogItemRect didn't help if(!IsWindowVisible(GetDialogWindow(theDialog))) { // then this is being called when the window is being set up // and so we need to use our trick HideDialogItem(theDialog,editTextitemNum); ShowDialogItem(theDialog,editTextitemNum); } #endif SelectDialogItemText(theDialog,editTextitemNum,strtSel,endSel); }
// NB: As of 2.0fc1, theEvent can be NULL! It isn't used anywhere, so don't _let_ it be // used anywhere! void MacroDialog(NewMacroInfo *macrost, DialogPtr dtemp, EventRecord *theEvent, short dItem) { short i; Rect dBox; Str255 temp; Handle MacString[10], rubbish; switch (dItem) { case 27: // switch keyset (pane) - RAB BetterTelnet 2.0b5 for (i=0; i<10; i++) { GetDialogItem( dtemp, i+13, &dItem, &MacString[i], &dBox); GetDialogItemText( MacString[i], temp); p2cstr(temp); setmacro(macrost, i + (10 * dialogPane), (char *) &temp); } dialogPane = GetCntlVal(dtemp, 27) - 1; // now fix the strings for (i=0; i<10; i++) { GetIndString(temp, 7100, i + (10 * dialogPane) + 1); GetDialogItem(dtemp, i+3, &dItem, &rubbish, &dBox); if (!temp[0]) { HideDialogItem(dtemp, i+13); HideDialogItem(dtemp, i+3); } else { ShowDialogItem(dtemp, i+13); ShowDialogItem(dtemp, i+3); } SetDialogItemText(rubbish, temp); } for (i=0; i<10; i++) { getmacro(macrost, i + (10 * dialogPane), (char *) &temp, 256); c2pstr((char *)temp); GetDialogItem( dtemp, i+13, &dItem, &MacString[i], &dBox); SetDialogItemText( MacString[i], temp ); } break; case (MacroExport): // we _used_ to get all the macros out, but now only the current set of 10 for (i=0; i<10; i++) { GetDialogItem( dtemp, i+13, &dItem, &MacString[i], &dBox); GetDialogItemText( MacString[i], temp); p2cstr(temp); setmacro(macrost, i + (10 * dialogPane), (char *) &temp); // RAB BetterTelnet 2.0b5 (revised) } saveMacros(macrost, (FSSpec *) NULL); break; case 25: for (i=0; i<10; i++) { GetDialogItem( dtemp, i+13, &dItem, &MacString[i], &dBox); GetDialogItemText( MacString[i], temp); p2cstr(temp); setmacro(macrost, i + (10 * dialogPane), (char *) &temp); } SaveGlobalMacros(macrost); break; case (MacroImport): loadMacros(macrost, (FSSpec *) NULL); for (i=0; i<10; i++) { getmacro(macrost, i + (10 * dialogPane), (char *) &temp, 256); c2pstr((char *)temp); GetDialogItem( dtemp, i+13, &dItem, &MacString[i], &dBox); SetDialogItemText( MacString[i], temp ); } break; case 1: case 2: break; default: if (dItem >2 && dItem <13) { i=dItem-3; getmacro(macrost, i + (dialogPane * 10), (char *) &temp, 256); /* BYU LSC */ c2pstr((char *)temp); GetDialogItem( dtemp, i+13, &dItem, &MacString[i], &dBox); SetDialogItemText( MacString[i], temp ); /* BYU LSC - Revert the mother */ SelectDialogItemText( dtemp, i+13, 0, 32767); /* And select it... */ } break; } }
int main(int argc, char *argv[]) { Boolean Success; ProcessSerialNumber ourProcess, installerPSN; short itemHit; long brandID = 0; int i; pid_t installerPID = 0, coreClientPID = 0, waitPermissionsPID = 0; FSRef fileRef; OSStatus err, err_fsref; FILE *f; char s[256]; char *q; #ifdef SANDBOX uid_t saved_euid, saved_uid, b_m_uid; passwd *pw; int finalInstallAction; DialogRef theWin; #else // SANDBOX group *grp; #endif // SANDBOX appName[0] = "/Applications/BOINCManager.app"; appNameEscaped[0] = "/Applications/BOINCManager.app"; brandName[0] = "BOINC"; saverName[0] = "BOINCSaver"; saverNameEscaped[0] = "BOINCSaver"; receiptNameEscaped[0] = "/Library/Receipts/BOINC.pkg"; appName[1] = "/Applications/GridRepublic Desktop.app"; appNameEscaped[1] = "/Applications/GridRepublic\\ Desktop.app"; brandName[1] = "GridRepublic"; saverName[1] = "GridRepublic"; saverNameEscaped[1] = "GridRepublic"; receiptNameEscaped[1] = "/Library/Receipts/GridRepublic.pkg"; appName[2] = "/Applications/Progress Thru Processors Desktop.app"; appNameEscaped[2] = "/Applications/Progress\\ Thru\\ Processors\\ Desktop.app"; brandName[2] = "Progress Thru Processors"; saverName[2] = "Progress Thru Processors"; saverNameEscaped[2] = "Progress\\ Thru\\ Processors"; receiptNameEscaped[2] = "/Library/Receipts/Progress\\ Thru\\ Processors.pkg"; ::GetCurrentProcess (&ourProcess); // getlogin() gives unreliable results under OS 10.6.2, so use environment strncpy(loginName, getenv("USER"), sizeof(loginName)-1); err = Gestalt(gestaltSystemVersion, &OSVersion); if (err != noErr) return err; for (i=0; i<argc; i++) { if (strcmp(argv[i], "-part2") == 0) return DeleteReceipt(); } Initialize(); QuitBOINCManager('BNC!'); // Quit any old instance of BOINC manager sleep(2); // Core Client may still be running if it was started without Manager coreClientPID = FindProcessPID("boinc", 0); if (coreClientPID) kill(coreClientPID, SIGTERM); // boinc catches SIGTERM & exits gracefully err = FindProcess ('APPL', 'xins', &installerPSN); if (err == noErr) err = GetProcessPID(&installerPSN , &installerPID); brandID = GetBrandID(); if ((brandID < 0) || (brandID >= NUMBRANDS)) { // Safety check brandID = 0; } if (OSVersion < 0x1040) { ::SetFrontProcess(&ourProcess); // Remove everything we've installed // "\pSorry, this version of GridRepublic requires system 10.4.0 or higher." s[0] = sprintf(s+1, "Sorry, this version of %s requires system 10.4.0 or higher.", brandName[brandID]); StandardAlert (kAlertStopAlert, (StringPtr)s, NULL, NULL, &itemHit); // "rm -rf /Applications/GridRepublic\\ Desktop.app" sprintf(s, "rm -rf %s", appNameEscaped[brandID]); system (s); // "rm -rf /Library/Screen\\ Savers/GridRepublic.saver" sprintf(s, "rm -rf /Library/Screen\\ Savers/%s.saver", saverNameEscaped[brandID]); system (s); // "rm -rf /Library/Receipts/GridRepublic.pkg" sprintf(s, "rm -rf %s", receiptNameEscaped[brandID]); system (s); // We don't customize BOINC Data directory name for branding system ("rm -rf /Library/Application\\ Support/BOINC\\ Data"); err = kill(installerPID, SIGKILL); ExitToShell(); } sleep (2); // Install all_projects_list.xml file, but only if one doesn't // already exist, since a pre-existing one is probably newer. f = fopen("/Library/Application Support/BOINC Data/all_projects_list.xml", "r"); if (f) { fclose(f); // Already exists } else { system ("cp -fp Contents/Resources/all_projects_list.xml /Library/Application\\ Support/BOINC\\ Data/"); system ("chmod a-x /Library/Application\\ Support/BOINC\\ Data/all_projects_list.xml"); } Success = false; #ifdef SANDBOX CheckUserAndGroupConflicts(); for (i=0; i<5; ++i) { err = CreateBOINCUsersAndGroups(); if (err != noErr) { // print_to_log_file("CreateBOINCUsersAndGroups returned %d (repetition=%d)", err, i); continue; } // err = SetBOINCAppOwnersGroupsAndPermissions("/Applications/GridRepublic Desktop.app"); err = SetBOINCAppOwnersGroupsAndPermissions(appName[brandID]); if (err != noErr) { // print_to_log_file("SetBOINCAppOwnersGroupsAndPermissions returned %d (repetition=%d)", err, i); continue; } err = SetBOINCDataOwnersGroupsAndPermissions(); if (err != noErr) { // print_to_log_file("SetBOINCDataOwnersGroupsAndPermissions returned %d (repetition=%d)", err, i); continue; } err = check_security(appName[brandID], "/Library/Application Support/BOINC Data", true, false); if (err == noErr) break; // print_to_log_file("check_security returned %d (repetition=%d)", err, i); } #else // ! defined(SANDBOX) // The BOINC Manager and Core Client have the set-user-ID-on-execution // flag set, so their ownership is important and must match the // ownership of the BOINC Data directory. // Find an appropriate admin user to set as owner of installed files // First, try the user currently logged in grp = getgrnam("admin"); i = 0; while ((p = grp->gr_mem[i]) != NULL) { // Step through all users in group admin if (strcmp(p, loginName) == 0) { Success = true; // Logged in user is a member of group admin break; } ++i; } // If currently logged in user is not admin, use first non-root admin user if (!Success) { i = 0; while ((p = grp->gr_mem[i]) != NULL) { // Step through all users in group admin if (strcmp(p, "root") != 0) break; ++i; } } // Set owner of branded BOINCManager and contents, including core client // "chown -Rf username /Applications/GridRepublic\\ Desktop.app" sprintf(s, "chown -Rf %s %s", p, appNameEscaped[brandID]); system (s); // Set owner of BOINC Screen Saver // "chown -Rf username /Library/Screen\\ Savers/GridRepublic.saver" sprintf(s, "chown -Rf %s /Library/Screen\\ Savers/%s.saver", p, saverNameEscaped[brandID]); system (s); // We don't customize BOINC Data directory name for branding // "chown -Rf username /Library/Application\\ Support/BOINC\\ Data" sprintf(s, "chown -Rf %s /Library/Application\\ Support/BOINC\\ Data", p); system (s); // "chmod -R a+s /Applications/GridRepublic\\ Desktop.app" sprintf(s, "chmod -R a+s %s", appNameEscaped[brandID]); system (s); #endif // ! defined(SANDBOX) // Remove any branded versions of BOINC other than ours (i.e., old versions) for (i=0; i< NUMBRANDS; i++) { if (i == brandID) continue; // "rm -rf /Applications/GridRepublic\\ Desktop.app" sprintf(s, "rm -rf %s", appNameEscaped[i]); system (s); // "rm -rf /Library/Screen\\ Savers/GridRepublic.saver" sprintf(s, "rm -rf /Library/Screen\\ Savers/%s.saver", saverNameEscaped[i]); system (s); } if (brandID == 0) { // Installing generic BOINC system ("rm -f /Library/Application\\ Support/BOINC\\ Data/Branding"); } // err_fsref = FSPathMakeRef((StringPtr)"/Applications/GridRepublic Desktop.app", &fileRef, NULL); err_fsref = FSPathMakeRef((StringPtr)appName[brandID], &fileRef, NULL); if (err_fsref == noErr) err = LSRegisterFSRef(&fileRef, true); err = UpdateAllVisibleUsers(brandID); if (err != noErr) return err; #ifdef SANDBOX err = CheckLogoutRequirement(&finalInstallAction); if (finalInstallAction == launchWhenDone) { // Wait for BOINC's RPC socket address to become available to user boinc_master, in // case we are upgrading from a version which did not run as user boinc_master. saved_uid = getuid(); saved_euid = geteuid(); pw = getpwnam("boinc_master"); b_m_uid = pw->pw_uid; seteuid(b_m_uid); for (i=0; i<120; i++) { err = TestRPCBind(); if (err == noErr) break; sleep(1); } seteuid(saved_euid); ProcessSerialNumber ourPSN; ProcessInfoRec pInfo; FSRef ourFSRef, theFSRef; char thePath[MAXPATHLEN]; // Get the full path to this PostInstall application's bundle err = GetCurrentProcess (&ourPSN); if (err) return -1000; // Should never happen memset(&pInfo, 0, sizeof(pInfo)); pInfo.processInfoLength = sizeof( ProcessInfoRec ); err = GetProcessInformation(&ourPSN, &pInfo); if (err) return -1001; // Should never happen err = GetProcessBundleLocation(&ourPSN, &ourFSRef); if (err) return -1002; // Should never happen err = FSRefMakePath (&ourFSRef, (UInt8*)thePath, sizeof(thePath)); if (err) return -1003; // Should never happen q = strrchr(thePath, '/'); if (q == NULL) return -1004; // Should never happen *++q = '\0'; strlcat(thePath, "WaitPermissions.app", sizeof(thePath)); err = FSPathMakeRef((StringPtr)thePath, &theFSRef, NULL); // When we first create the boinc_master group and add the current user to the // new group, there is a delay before the new group membership is recognized. // If we launch the BOINC Manager too soon, it will fail with a -1037 permissions // error, so we wait until the current user can access the switcher application. // Apparently, in order to get the changed permissions / group membership, we must // launch a new process belonging to the user. It may also need to be in a new // process group or new session. Neither system() nor popen() works, even after // setting the uid and euid back to the logged in user, but LSOpenFSRef() does. // The WaitPermissions application loops until it can access the switcher // application. err = LSOpenFSRef(&theFSRef, NULL); waitPermissionsStartTime = time(NULL); for (i=0; i<15; i++) { // Show "Please wait..." alert after 15 seconds waitPermissionsPID = FindProcessPID("WaitPermissions", 0); if (waitPermissionsPID == 0) { return 0; } sleep(1); } CreateStandardAlert(kAlertNoteAlert, CFSTR("Finishing install. Please wait ..."), CFSTR("This may take a few more minutes."), NULL, &theWin); HideDialogItem(theWin, kStdOkItemIndex); RemoveDialogItems(theWin, kStdOkItemIndex, 1, false); RunStandardAlert(theWin, &myFilterProc, &itemHit); } #endif // SANDBOX return 0; }