/* Panic button to display fatal errors. Completely self contained, can't rely on carbon.cc being available */ static void carbonFatalDialog(const char *error, const char *exposition) { DialogRef alertDialog; CFStringRef cfError; CFStringRef cfExposition; DialogItemIndex index; AlertStdCFStringAlertParamRec alertParam = {0}; // Init libraries InitCursor(); // Assemble dialog cfError = CFStringCreateWithCString(NULL, error, kCFStringEncodingASCII); if(exposition != NULL) { cfExposition = CFStringCreateWithCString(NULL, exposition, kCFStringEncodingASCII); } else { cfExposition = NULL; } alertParam.version = kStdCFStringAlertVersionOne; alertParam.defaultText = CFSTR("Quit"); alertParam.position = kWindowDefaultPosition; alertParam.defaultButton = kAlertStdAlertOKButton; // Display Dialog CreateStandardAlert( kAlertStopAlert, cfError, cfExposition, /* can be NULL */ &alertParam, /* can be NULL */ &alertDialog); RunStandardAlert(alertDialog, NULL, &index); // Cleanup CFRelease(cfError); if(cfExposition != NULL) { CFRelease(cfExposition); } }
static void DisplayError(OSStatus err) // Displays a trivial error dialog if err represents an error. { if ( (err != noErr) && (err != userCanceledErr) ) { AlertStdCFStringAlertParamRec params; DialogRef dlg; DialogItemIndex junkItem; params.version = kStdCFStringAlertVersionOne; params.movable = true; params.helpButton = false; params.defaultText = (CFStringRef) kAlertDefaultOKText; params.cancelText = NULL; params.otherText = NULL; params.defaultButton = kAlertStdAlertOKButton; params.cancelButton = 0; params.position = kWindowCenterMainScreen; params.flags = 0; err = CreateStandardAlert( kAlertStopAlert, CFSTR("LoginItemsAE got an error."), CFStringCreateWithFormat(NULL, NULL, CFSTR("%ld"), err), ¶ms, &dlg ); if (err == noErr) { err = RunStandardAlert(dlg, NULL, &junkItem); } assert(err == noErr); } }
void __create_message (HWND hwnd, SQLPOINTER dsn, SQLPOINTER text, SQLCHAR waMode, AlertType id) { CFStringRef msg, msg1; DialogRef dlg; SInt16 out; char buf[1024]; if (hwnd == NULL) return; if (waMode == 'A') { if (dsn) { STRCPY(buf, "DSN: "); STRCAT(buf, dsn); msg = CFStringCreateWithBytes (NULL, (unsigned char*)buf, STRLEN(buf), kCFStringEncodingUTF8, false); msg1 = CFStringCreateWithBytes (NULL, (unsigned char*)text, STRLEN(text), kCFStringEncodingUTF8, false); } else { STRCPY(buf, ""); msg = CFStringCreateWithBytes (NULL, (unsigned char*)text, STRLEN(text), kCFStringEncodingUTF8, false); msg1 = CFStringCreateWithBytes (NULL, (unsigned char*)buf, STRLEN(buf), kCFStringEncodingUTF8, false); } } else { if (dsn) { WCSCPY(buf, L"DSN: "); WCSCAT(buf, dsn); msg = convert_wchar_to_CFString((wchar_t*)buf); msg1 = convert_wchar_to_CFString((wchar_t*)text); } else { WCSCPY(buf, L""); msg = convert_wchar_to_CFString((wchar_t*)text); msg1 = convert_wchar_to_CFString((wchar_t*)buf); } } CreateStandardAlert (id, msg, msg1, NULL, &dlg); RunStandardAlert (dlg, NULL, &out); CFRelease(msg); CFRelease(msg1); return; }
static int do_msgbox(const char *str, AlertType alert_type, AlertStdCFStringAlertParamRec *param, DialogItemIndex *idx, const char *desc) { const char *_title = desc ? desc : "Setup"; int retval = 0; DialogItemIndex val = 0; CFStringRef title = CFStringCreateWithBytes(NULL, BAD_CAST _title, strlen(_title), kCFStringEncodingUTF8, 0); CFStringRef msg = CFStringCreateWithBytes(NULL, BAD_CAST str, strlen(str), kCFStringEncodingUTF8, 0); if ((msg != NULL) && (title != NULL)) { DialogRef dlg = NULL; if (CreateStandardAlert(alert_type, title, msg, param, &dlg) == noErr) { RunStandardAlert(dlg, NULL, (idx) ? idx : &val); retval = 1; } /* if */ } /* if */ if (msg != NULL) CFRelease(msg); if (title != NULL) CFRelease(title); return(retval); } /* do_msgbox */
void AppearanceAlert (AlertType type, int stringID1, int stringID2) { OSStatus err; DialogRef dialog; DialogItemIndex outItemHit; CFStringRef key1, key2, mes1, mes2; char label1[32], label2[32]; sprintf(label1, "AlertMes_%02d", stringID1); sprintf(label2, "AlertMes_%02d", stringID2); key1 = CFStringCreateWithCString(kCFAllocatorDefault, label1, CFStringGetSystemEncoding()); key2 = CFStringCreateWithCString(kCFAllocatorDefault, label2, CFStringGetSystemEncoding()); if (key1) mes1 = CFCopyLocalizedString(key1, "mes1"); else mes1 = NULL; if (key2) mes2 = CFCopyLocalizedString(key2, "mes2"); else mes2 = NULL; PlayAlertSound(); err = CreateStandardAlert(type, mes1, mes2, NULL, &dialog); err = RunStandardAlert(dialog, NULL, &outItemHit); if (key1) CFRelease(key1); if (key2) CFRelease(key2); if (mes1) CFRelease(mes1); if (mes2) CFRelease(mes2); }
void create_error_Internal (HWND hwnd, SQLPOINTER dsn, SQLPOINTER text, SQLPOINTER errmsg, SQLCHAR waMode) { CFStringRef msg, msg1; DialogRef dlg; SInt16 out; if (hwnd == NULL) return; if (waMode == 'A') { msg = CFStringCreateWithBytes (NULL, (unsigned char*)text, STRLEN(text), kCFStringEncodingUTF8, false); msg1 = CFStringCreateWithBytes (NULL, (unsigned char*)errmsg, STRLEN(errmsg), kCFStringEncodingUTF8, false); } else { msg = convert_wchar_to_CFString((wchar_t*)text); msg1 = convert_wchar_to_CFString((wchar_t*)errmsg); } CreateStandardAlert (kAlertStopAlert, msg, msg1, NULL, &dlg); RunStandardAlert (dlg, NULL, &out); CFRelease(msg); CFRelease(msg1); return; }
OSStatus DisplayAlert(CFStringRef error, CFStringRef explanation, OSStatus status) { DialogRef dialog; if (status == 0) CreateStandardAlert(kAlertStopAlert, error, explanation, NULL, &dialog); else { CFStringRef exp; if (status > 0) { char s[8]; CFStringRef stat = UTCreateStringForOSType(status); CFStringGetCString(stat, s, sizeof(s), kCFStringEncodingMacRoman); CFRelease(stat); exp = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%s: '%s' (0x%x)"), CFStringGetCStringPtr(explanation, kCFStringEncodingMacRoman), s, status); } else { exp = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%s: %d (0x%x)"), CFStringGetCStringPtr(explanation, kCFStringEncodingMacRoman), status, status); } CreateStandardAlert(kAlertStopAlert, error, exp, NULL, &dialog); } SetWindowTitleWithCFString(GetDialogWindow(dialog), CFSTR("Accordion")); RunStandardAlert(dialog, NULL, NULL); return noErr; }
void MsgBox(const char *err) { #if defined(__APPLE__) && !defined(__IOS__) DialogRef alertDialog; CFStringRef sr = //CFStringCreateWithCharacters(NULL, err, strlen(err)); CFStringCreateWithCString(kCFAllocatorDefault, err, ::GetApplicationTextEncoding()); CreateStandardAlert(kAlertStopAlert, CFSTR("Error:"), sr, NULL, &alertDialog); RunStandardAlert (alertDialog, NULL, NULL); #endif }
/***************************************************** * * main (argc, argv) * * Purpose: main program entry point * * Notes: You might want to change this to something more verbose * * Inputs: argc - the number of elements in the argv array * argv - an array of pointers to the parameters to this application * * Returns: int - error code (0 == no error) */ int main(int argc, char* argv[]) { OSStatus status; // Can we run this particular demo application? long response; status = Gestalt(gestaltSystemVersion, &response); Boolean ok = ((noErr == status) && (response >= 0x00001030)); if (!ok) { DialogRef theAlert; CreateStandardAlert(kAlertStopAlert, CFSTR("Mac OS X 10.3 (minimum) is required for this application"), NULL, NULL, &theAlert); RunStandardAlert(theAlert, NULL, NULL); ExitToShell(); } // Create a Nib reference passing the name of the nib file (without the .nib extension) // CreateNibReference only searches into the application bundle. status = CreateNibReference(CFSTR("main"), &gIBNibRef); require_noerr(status, CantGetNibRef); // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar // object. This name is set in InterfaceBuilder when the nib is created. status = SetMenuBarFromNib(gIBNibRef, CFSTR("MenuBar")); require_noerr(status, CantSetMenuBar); // Adding a Font menu MenuRef fontMenu = GetMenuRef(3); require(fontMenu != NULL, CantSetMenuBar); status = CreateStandardFontMenu(fontMenu, 0, 0, 0, NULL); require_noerr(status, CantSetMenuBar); // Enabling Preferences menu item EnableMenuCommand(NULL, kHICommandPreferences); // Let's react to User's commands. Install_AppleEventHandlers(); EventTypeSpec eventTypeCP = {kEventClassCommand, kEventCommandProcess}; InstallEventHandler(GetApplicationEventTarget(), Handle_CommandProcess, 1, &eventTypeCP, NULL, NULL); EventTypeSpec eventTypeCUS = {kEventClassCommand, kEventCommandUpdateStatus}; InstallEventHandler(GetApplicationEventTarget(), Handle_CommandUpdateStatus, 1, &eventTypeCUS, NULL, NULL); EventTypeSpec eventTypeAA = {kEventClassApplication, kEventAppActivated}; InstallEventHandler(GetApplicationEventTarget(), Handle_AppActivated, 1, &eventTypeAA, NULL, NULL); // Call the event loop RunApplicationEventLoop(); CantSetMenuBar: CantGetNibRef: return status; } // main
// display error messages void Error(const char *es) { short i; char mes[200]; sprintf(mes,"%s\n(error code: %d)",es,BASS_ErrorGetCode()); CFStringRef ces=CFStringCreateWithCString(0,mes,0); DialogRef alert; CreateStandardAlert(0,CFSTR("Error"),ces,NULL,&alert); RunStandardAlert(alert,NULL,&i); CFRelease(ces); }
void MsgBox(const char *err) { #if defined(__APPLE__) && !defined(__IOS__) // FIXME: this code should never be run when running from command line DialogRef alertDialog; CFStringRef sr = //CFStringCreateWithCharacters(nullptr, err, strlen(err)); CFStringCreateWithCString(kCFAllocatorDefault, err, ::GetApplicationTextEncoding()); CreateStandardAlert(kAlertStopAlert, CFSTR("Error:"), sr, nullptr, &alertDialog); RunStandardAlert (alertDialog, nullptr, nullptr); #else (void)err; #endif }
void ResumeErrorDialogProc(void) { DialogRef ret; AlertStdCFStringAlertParamRec param; DialogItemIndex hit; GetStandardAlertDefaultParams(¶m, kStdCFStringAlertVersionOne); param.movable = true; CreateStandardAlert(kAlertStopAlert, CFCopyLocalizedString(CFSTR("Couldn't restart"), "Resume Error Message"), CFCopyLocalizedString(CFSTR("An error occured when reading the np2.sav file. Neko Project IIx couldn't restart."), "Resume Error Description"), ¶m, &ret); SysBeep(0); RunStandardAlert(ret, NULL, &hit); }
// --------------------------------------------------------------------------- // Constructeur // ------------ bStdAlert::bStdAlert(int kind, int def_btn, bool has_cancel, const char* error_string, const char* explanation_string, bool silent, UInt32 delay){ _res=false; if(silent){ fprintf(stderr,"ALERT : %s\n",error_string); fprintf(stderr,"%s\n",explanation_string); _res=true; return; } AlertStdCFStringAlertParamRec prm; (void)GetStandardAlertDefaultParams(&prm,kStdCFStringAlertVersionOne); prm.defaultButton=def_btn; if(def_btn==kAlertStdAlertOKButton){ prm.cancelButton=kAlertStdAlertCancelButton; } else if(def_btn==kAlertStdAlertCancelButton){ prm.cancelButton=kAlertStdAlertOKButton; } char msg[__MESSAGE_STRING_LENGTH_MAX__]; message_string(kMsgOk,msg,1); prm.defaultText=CFStringCreateWithCString(kCFAllocatorDefault,msg,kCFStringEncodingMacRoman); if(has_cancel){ message_string(kMsgCancel,msg,1); prm.cancelText=CFStringCreateWithCString(kCFAllocatorDefault,msg,kCFStringEncodingMacRoman); } CFStringRef err=CFStringCreateWithCString(kCFAllocatorDefault,error_string,kCFStringEncodingMacRoman); CFStringRef exp=CFStringCreateWithCString(kCFAllocatorDefault,explanation_string,kCFStringEncodingMacRoman); DialogRef alrt; (void)CreateStandardAlert(kind,err,exp,&prm,&alrt); SetDialogTimeout(alrt,def_btn,delay); (void)RunStandardAlert(alrt,NULL,&_hit); _res=(_hit==def_btn); CFRelease(err); CFRelease(exp); }
static SInt16 ShowAlert( int type, CFStringRef message, CFStringRef OK, CFStringRef cancel = NULL ) { struct AlertStdCFStringAlertParamRec params = {kStdCFStringAlertVersionOne, true, false, OK, cancel, NULL, kAlertStdAlertOKButton, kAlertStdAlertCancelButton, kWindowAlertPositionParentWindowScreen, NULL}; DialogRef dialog; SInt16 result; OSErr err; CreateStandardAlert(type, message, NULL, ¶ms, &dialog); err = AutoSizeDialog(dialog); ASSERT(err == noErr); RunStandardAlert(dialog, NULL, &result); return result; }
static SInt16 showCautionAlert(CFStringRef title, CFStringRef string, CFStringRef button) { DialogRef ret; AlertStdCFStringAlertParamRec param; DialogItemIndex hit; GetStandardAlertDefaultParams(¶m, kStdCFStringAlertVersionOne); param.movable = true; param.cancelButton = kAlertStdAlertCancelButton; param.cancelText = param.defaultText; if (button) param.defaultText = button; CreateStandardAlert(kAlertCautionAlert, title, string, ¶m, &ret); SysBeep(0); RunStandardAlert(ret, NULL, &hit); return(hit); }
//------------------------------------------------------------------------------ void ofCreateAlertDialog(string errorMessage){ #ifdef TARGET_WIN32 // we need to convert error message to a wide char message. // first, figure out the length and allocate a wchar_t at that length + 1 (the +1 is for a terminating character) int length = strlen(errorMessage.c_str()); wchar_t * widearray = new wchar_t[length+1]; memset(widearray, 0, sizeof(wchar_t)*(length+1)); // then, call mbstowcs: // http://www.cplusplus.com/reference/clibrary/cstdlib/mbstowcs/ mbstowcs(widearray, errorMessage.c_str(), length); // launch the alert: MessageBox(NULL, widearray, L"alert", MB_OK); // clear the allocated memory: delete widearray; #endif #ifdef TARGET_OSX CFStringRef msgStrRef = CFStringCreateWithCString(NULL, errorMessage.c_str(), kCFStringEncodingASCII); DialogRef theItem; DialogItemIndex itemIndex; CreateStandardAlert(kAlertNoteAlert, msgStrRef, NULL, NULL, &theItem); RunStandardAlert(theItem, NULL, &itemIndex); #endif #if defined( TARGET_LINUX ) && defined (OF_USING_GTK) initGTK(); GtkWidget* dialog = gtk_message_dialog_new (NULL, (GtkDialogFlags) 0, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, errorMessage.c_str()); gtk_dialog_run (GTK_DIALOG (dialog)); startGTK(dialog); #endif #ifdef TARGET_ANDROID ofxAndroidAlertBox(errorMessage); #endif }
//--------------------------------------------------------------------------------------------- int main() { static const EventTypeSpec sApplicationEvents[] = {{ kEventClassCommand, kEventCommandProcess }}; OSErr err; if (!SystemVersionRequired(0x1020)) { DialogRef theAlert; CreateStandardAlert(kAlertStopAlert, CFSTR("Need 10.2 or later!"), NULL, NULL, &theAlert); RunStandardAlert(theAlert, NULL, NULL); return 0; } ProcessSerialNumber psn = {0, kCurrentProcess}; err = GetProcessBundleLocation(&psn, &gApplicationBundleFSRef); err = CreateNibReference(CFSTR("CarbonSketch"), &gOurNibRef ); require_noerr( err, CantGetNibRef ); err = SetMenuBarFromNib( gOurNibRef, CFSTR("MenuBar") ); require_noerr( err, SetMenuBarFromNib_FAILED ); AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, DoOpenApp, 0, false); AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, DoOpenDocuments, 0, false); // AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, DoPrintDocuments, 0, false); InstallApplicationEventHandler( NewEventHandlerUPP(AppEventHandlerProc), GetEventTypeCount(sApplicationEvents), sApplicationEvents, 0, NULL ); RunApplicationEventLoop(); SetMenuBarFromNib_FAILED: DisposeNibReference(gOurNibRef); CantGetNibRef: return err; }
void InformUserOfCrash( const CString &sPath ) { CFStringRef error; error = CFStringCreateWithCString(kCFAllocatorDefault, "StepMania has crashed. Debug " "information has been output to\n\n " + sPath + "\n\nPlease report a bug at:" "\n\nhttp://sourceforge.net/tracker/" "?func=add&group_id=37892&atid=421366", kCFStringEncodingASCII); CFStringRef OK = CFSTR("Open crashinfo"); CFStringRef Cancel = CFSTR("Cancel"); struct AlertStdCFStringAlertParamRec params = {kStdCFStringAlertVersionOne, true, false, OK, Cancel, NULL, kAlertStdAlertOKButton, kAlertStdAlertCancelButton, kWindowAlertPositionParentWindowScreen, NULL}; DialogRef dialog; SInt16 button; CreateStandardAlert(kAlertStopAlert, error, NULL, ¶ms, &dialog); AutoSizeDialog(dialog); RunStandardAlert(dialog, NULL, &button); switch (button) { case kAlertStdAlertOKButton: // This is lazy, and easy, and it seems to work. if (system(NULL)) system("/usr/bin/open '" + sPath + "'"); else SysBeep(30); break; } CFRelease(OK); CFRelease(Cancel); CFRelease(error); }
int x_show_alert(int is_fatal, const char *str) { DialogRef alert; DialogItemIndex out_item_hit; CFStringRef cfstrref; CFStringRef okstrref; AlertStdCFStringAlertParamRec alert_param; OSStatus osstat; if (!str || !*str) return 0; /* The dialog eats all events--including key-up events */ /* Call adb_all_keys_up() to prevent annoying key-repeat problems */ /* for instance, a key-down causes a dialog to appear--and the */ /* eats the key-up event...then as soon as the dialog goes, adb.c */ /* auto-repeat will repeat the key, and the dialog re-appears...*/ adb_all_keys_up(); cfstrref = CFStringCreateWithCString(NULL, str, kCFStringEncodingMacRoman); osstat = GetStandardAlertDefaultParams(&alert_param, kStdCFStringAlertVersionOne); okstrref = CFSTR("Click OK to continue"); if(is_fatal) { okstrref = CFSTR("Click OK to exit GSplus"); } CreateStandardAlert(kAlertStopAlert, cfstrref, okstrref, &alert_param, &alert); out_item_hit = -1; RunStandardAlert(alert, NULL, &out_item_hit); CFRelease(cfstrref); return (out_item_hit >= 3); }
int wxMessageDialog::ShowModal() { int resultbutton = wxID_CANCEL ; short result ; const long style = GetMessageDialogStyle(); wxASSERT_MSG( ( style & 0x3F ) != wxYES , wxT("this style is not supported on mac") ) ; AlertType alertType = kAlertPlainAlert ; if (style & wxICON_EXCLAMATION) alertType = kAlertNoteAlert ; else if (style & wxICON_HAND) alertType = kAlertStopAlert ; else if (style & wxICON_INFORMATION) alertType = kAlertNoteAlert ; else if (style & wxICON_QUESTION) alertType = kAlertCautionAlert ; #if TARGET_CARBON if ( UMAGetSystemVersion() >= 0x1000 ) { AlertStdCFStringAlertParamRec param ; wxMacCFStringHolder cfNoString(_("No") , m_font.GetEncoding()) ; wxMacCFStringHolder cfYesString( _("Yes") , m_font.GetEncoding()) ; wxMacCFStringHolder cfTitle(m_caption , m_font.GetEncoding()); wxMacCFStringHolder cfText(m_message , m_font.GetEncoding()); param.movable = true; param.flags = 0 ; bool skipDialog = false ; if (style & wxYES_NO) { if (style & wxCANCEL) { param.defaultText = cfYesString ; param.cancelText = (CFStringRef) kAlertDefaultCancelText; param.otherText = cfNoString ; param.helpButton = false ; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = kAlertStdAlertCancelButton; } else { param.defaultText = cfYesString ; param.cancelText = NULL; param.otherText = cfNoString ; param.helpButton = false ; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } } // the msw implementation even shows an ok button if it is not specified, we'll do the same else { if (style & wxCANCEL) { // thats a cancel missing param.defaultText = (CFStringRef) kAlertDefaultOKText ; param.cancelText = (CFStringRef) kAlertDefaultCancelText ; param.otherText = NULL; param.helpButton = false ; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } else { param.defaultText = (CFStringRef) kAlertDefaultOKText ; param.cancelText = NULL; param.otherText = NULL; param.helpButton = false ; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } } /* else { skipDialog = true ; } */ param.position = kWindowDefaultPosition; if ( !skipDialog ) { DialogRef alertRef ; CreateStandardAlert( alertType , cfTitle , cfText , ¶m , &alertRef ) ; RunStandardAlert( alertRef , NULL , &result ) ; } if ( skipDialog ) return wxID_CANCEL ; } else #endif { AlertStdAlertParamRec param; Str255 yesPString ; Str255 noPString ; Str255 pascalTitle ; Str255 pascalText ; wxMacStringToPascal( m_caption , pascalTitle ) ; wxMacStringToPascal( _("Yes") , yesPString ) ; wxMacStringToPascal( _("No") , noPString ) ; wxMacStringToPascal( m_message , pascalText ) ; param.movable = true; param.filterProc = NULL ; if (style & wxYES_NO) { if (style & wxCANCEL) { param.defaultText = yesPString ; param.cancelText = (StringPtr) kAlertDefaultCancelText; param.otherText = noPString ; param.helpButton = false ; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = kAlertStdAlertCancelButton; } else { param.defaultText = yesPString ; param.cancelText = NULL; param.otherText = noPString ; param.helpButton = false ; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } } else if (style & wxOK) { if (style & wxCANCEL) { param.defaultText = (StringPtr) kAlertDefaultOKText ; param.cancelText = (StringPtr) kAlertDefaultCancelText ; param.otherText = NULL; param.helpButton = false ; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } else { param.defaultText = (StringPtr) kAlertDefaultOKText ; param.cancelText = NULL; param.otherText = NULL; param.helpButton = false ; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } } else { return resultbutton ; } param.position = 0; StandardAlert( alertType, pascalTitle, pascalText, ¶m, &result ); } if (style & wxOK) { if (style & wxCANCEL) { //TODO add Cancelbutton switch( result ) { case 1 : resultbutton = wxID_OK ; break ; case 2 : break ; case 3 : break ; } } else { switch( result ) { case 1 : resultbutton = wxID_OK ; break ; case 2 : break ; case 3 : break ; } } } else if (style & wxYES_NO) { if (style & wxCANCEL) { switch( result ) { case 1 : resultbutton = wxID_YES ; break ; case 2 : resultbutton = wxID_CANCEL ; break ; case 3 : resultbutton = wxID_NO ; break ; } } else { switch( result ) { case 1 : resultbutton = wxID_YES ; break ; case 2 : break ; case 3 : resultbutton = wxID_NO ; break ; } } } return resultbutton ; }
int main(int argc, char **argv) { // We assume that all the logs we're looking for reside on the current drive gDirUtilp->initAppDirs("SecondLife"); LLError::initForApplication( gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "")); // Rename current log file to ".old" std::string old_log_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "updater.log.old"); std::string log_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "updater.log"); LLFile::rename(log_file.c_str(), old_log_file.c_str()); // Set the log file to updater.log LLError::logToFile(log_file); ///////////////////////////////////////// // // Process command line arguments // gUpdateURL = NULL; gProductName = NULL; gBundleID = NULL; gDmgFile = NULL; gMarkerPath = NULL; parse_args(argc, argv); if ((gUpdateURL == NULL) && (gDmgFile == NULL)) { llinfos << "Usage: mac_updater -url <url> | -dmg <dmg file> [-name <product_name>] [-program <program_name>]" << llendl; exit(1); } else { llinfos << "Update url is: " << gUpdateURL << llendl; if (gProductName) { llinfos << "Product name is: " << gProductName << llendl; } else { gProductName = "Second Life"; } if (gBundleID) { llinfos << "Bundle ID is: " << gBundleID << llendl; } else { gBundleID = "com.secondlife.indra.viewer"; } } llinfos << "Starting " << gProductName << " Updater" << llendl; // Real UI... OSStatus err; IBNibRef nib = NULL; err = CreateNibReference(CFSTR("AutoUpdater"), &nib); char windowTitle[MAX_PATH]; /* Flawfinder: ignore */ snprintf(windowTitle, sizeof(windowTitle), "%s Updater", gProductName); CFStringRef windowTitleRef = NULL; windowTitleRef = CFStringCreateWithCString(NULL, windowTitle, kCFStringEncodingUTF8); if(err == noErr) { err = CreateWindowFromNib(nib, CFSTR("Updater"), &gWindow); } if (err == noErr) { err = SetWindowTitleWithCFString(gWindow, windowTitleRef); } CFRelease(windowTitleRef); if(err == noErr) { // Set up an event handler for the window. EventTypeSpec handlerEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassCustom, kEventCustomProgress }, { kEventClassCustom, kEventCustomDone } }; InstallStandardEventHandler(GetWindowEventTarget(gWindow)); InstallWindowEventHandler( gWindow, NewEventHandlerUPP(dialogHandler), GetEventTypeCount (handlerEvents), handlerEvents, 0, &gEventHandler); } if(err == noErr) { ShowWindow(gWindow); SelectWindow(gWindow); } if(err == noErr) { pthread_create(&updatethread, NULL, &updatethreadproc, NULL); } if(err == noErr) { RunAppModalLoopForWindow(gWindow); } void *threadresult; pthread_join(updatethread, &threadresult); if(!gCancelled && (gFailure != noErr)) { // Something went wrong. Since we always just tell the user to download a new version, we don't really care what. AlertStdCFStringAlertParamRec params; SInt16 retval_mac = 1; DialogRef alert = NULL; OSStatus err; params.version = kStdCFStringAlertVersionOne; params.movable = false; params.helpButton = false; params.defaultText = (CFStringRef)kAlertDefaultOKText; params.cancelText = 0; params.otherText = 0; params.defaultButton = 1; params.cancelButton = 0; params.position = kWindowDefaultPosition; params.flags = 0; err = CreateStandardAlert( kAlertStopAlert, CFSTR("Error"), CFSTR("An error occurred while updating Second Life. Please download the latest version from www.secondlife.com."), ¶ms, &alert); if(err == noErr) { err = RunStandardAlert( alert, NULL, &retval_mac); } if(gMarkerPath != 0) { // Create a install fail marker that can be used by the viewer to // detect install problems. std::ofstream stream(gMarkerPath); if(stream) stream << -1; } exit(-1); } else { exit(0); } if(gWindow != NULL) { DisposeWindow(gWindow); } if(nib != NULL) { DisposeNibReference(nib); } return 0; }
int wxMessageDialog::ShowModal() { int resultbutton = wxID_CANCEL; const long style = GetMessageDialogStyle(); wxASSERT_MSG( (style & 0x3F) != wxYES, wxT("this style is not supported on Mac") ); AlertType alertType = kAlertPlainAlert; if (style & wxICON_EXCLAMATION) alertType = kAlertCautionAlert; else if (style & wxICON_HAND) alertType = kAlertStopAlert; else if (style & wxICON_INFORMATION) alertType = kAlertNoteAlert; else if (style & wxICON_QUESTION) alertType = kAlertNoteAlert; #if TARGET_API_MAC_OSX if ( !wxIsMainThread() ) { CFStringRef defaultButtonTitle = NULL; CFStringRef alternateButtonTitle = NULL; CFStringRef otherButtonTitle = NULL; wxMacCFStringHolder cfTitle( m_caption, m_font.GetEncoding() ); wxMacCFStringHolder cfText( m_message, m_font.GetEncoding() ); wxMacCFStringHolder cfNoString( _("No"), m_font.GetEncoding() ); wxMacCFStringHolder cfYesString( _("Yes"), m_font.GetEncoding() ); wxMacCFStringHolder cfOKString( _("OK") , m_font.GetEncoding()) ; wxMacCFStringHolder cfCancelString( _("Cancel"), m_font.GetEncoding() ); int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ }; if (style & wxYES_NO) { if ( style & wxNO_DEFAULT ) { defaultButtonTitle = cfNoString; alternateButtonTitle = cfYesString; buttonId[0] = wxID_NO; buttonId[1] = wxID_YES; } else { defaultButtonTitle = cfYesString; alternateButtonTitle = cfNoString; buttonId[0] = wxID_YES; buttonId[1] = wxID_NO; } if (style & wxCANCEL) { otherButtonTitle = cfCancelString; buttonId[2] = wxID_CANCEL; } } else { // the MSW implementation even shows an OK button if it is not specified, we'll do the same buttonId[0] = wxID_OK; // using null as default title does not work on earlier systems defaultButtonTitle = cfOKString; if (style & wxCANCEL) { alternateButtonTitle = cfCancelString; buttonId[1] = wxID_CANCEL; } } CFOptionFlags exitButton; OSStatus err = CFUserNotificationDisplayAlert( 0, alertType, NULL, NULL, NULL, cfTitle, cfText, defaultButtonTitle, alternateButtonTitle, otherButtonTitle, &exitButton ); if (err == noErr) resultbutton = buttonId[exitButton]; } else #endif { short result; AlertStdCFStringAlertParamRec param; wxMacCFStringHolder cfNoString( _("No"), m_font.GetEncoding() ); wxMacCFStringHolder cfYesString( _("Yes"), m_font.GetEncoding() ); wxMacCFStringHolder cfTitle( m_caption, m_font.GetEncoding() ); wxMacCFStringHolder cfText( m_message, m_font.GetEncoding() ); param.movable = true; param.flags = 0; param.version = kStdCFStringAlertVersionOne; bool skipDialog = false; if (style & wxYES_NO) { if (style & wxCANCEL) { param.defaultText = cfYesString; param.cancelText = (CFStringRef) kAlertDefaultCancelText; param.otherText = cfNoString; param.helpButton = false; param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; param.cancelButton = kAlertStdAlertCancelButton; } else { param.defaultText = cfYesString; param.cancelText = NULL; param.otherText = cfNoString; param.helpButton = false; param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; param.cancelButton = 0; } } // the MSW implementation even shows an OK button if it is not specified, we'll do the same else { if (style & wxCANCEL) { // that's a cancel missing param.defaultText = (CFStringRef) kAlertDefaultOKText; param.cancelText = (CFStringRef) kAlertDefaultCancelText; param.otherText = NULL; param.helpButton = false; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } else { param.defaultText = (CFStringRef) kAlertDefaultOKText; param.cancelText = NULL; param.otherText = NULL; param.helpButton = false; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } } param.position = kWindowDefaultPosition; if ( !skipDialog ) { DialogRef alertRef; CreateStandardAlert( alertType, cfTitle, cfText, ¶m, &alertRef ); RunStandardAlert( alertRef, NULL, &result ); } else { return wxID_CANCEL; } if (style & wxOK) { switch ( result ) { case 1: resultbutton = wxID_OK; break; case 2: // TODO: add Cancel button // if (style & wxCANCEL) // resultbutton = wxID_CANCEL; break; case 3: default: break; } } else if (style & wxYES_NO) { switch ( result ) { case 1: resultbutton = wxID_YES; break; case 2: if (!(style & wxCANCEL)) resultbutton = wxID_CANCEL; break; case 3: resultbutton = wxID_NO; break; default: break; } } } return resultbutton; }
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; }
int x_show_alert(int is_fatal, const char *str) { DialogRef alert; DialogItemIndex out_item_hit; CFStringRef cfstrref, cfstrref2; CFStringRef okstrref; AlertStdCFStringAlertParamRec alert_param; OSStatus osstat; char *bufptr, *buf2ptr; int sum, len; int i; /* The dialog eats all events--including key-up events */ /* Call adb_all_keys_up() to prevent annoying key-repeat problems */ /* for instance, a key-down causes a dialog to appear--and the */ /* eats the key-up event...then as soon as the dialog goes, adb.c */ /* auto-repeat will repeat the key, and the dialog re-appears...*/ adb_all_keys_up(); sum = 20; for(i = 0; i < g_fatal_log; i++) { sum += strlen(g_fatal_log_strs[i]); } bufptr = (char*)malloc(sum); buf2ptr = bufptr; for(i = 0; i < g_fatal_log; i++) { len = strlen(g_fatal_log_strs[i]); len = MIN(len, sum); len = MAX(len, 0); memcpy(bufptr, g_fatal_log_strs[i], MIN(len, sum)); bufptr += len; bufptr[0] = 0; sum = sum - len; } cfstrref = CFStringCreateWithCString(NULL, buf2ptr, kCFStringEncodingMacRoman); printf("buf2ptr: :%s:\n", buf2ptr); osstat = GetStandardAlertDefaultParams(&alert_param, kStdCFStringAlertVersionOne); if(str) { // Provide an extra option--create a file cfstrref2 = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("Create ~/Library/KEGS/%s"), str); alert_param.otherText = cfstrref2; } okstrref = CFSTR("Click OK to continue"); if(is_fatal) { okstrref = CFSTR("Clock OK to exit KEGS"); } CreateStandardAlert(kAlertStopAlert, cfstrref, okstrref, &alert_param, &alert); out_item_hit = -1; RunStandardAlert(alert, NULL, &out_item_hit); printf("out_item_hit: %d\n", out_item_hit); free(buf2ptr); clear_fatal_logs(); /* free the fatal_log string memory */ return (out_item_hit >= 3); }
/***************************************************** * * DisplaySimpleWindow ( void ) * * Purpose: Called to create a new window in response to a kHICommandNew event. Here we create a window, set up the MyMPTaskInfo structure, * and create an MP thread to monitor our specified directories. * */ static void DisplaySimpleWindow( void ) { OSStatus err; OSStatus err1; WindowRef window; ControlRef control; MPTaskID mpTaskID; MyMPTaskInfo *mpTaskInfo; FSRef fsRef; char path[MAXPATHLEN]; DialogRef alertDialog; static EventHandlerUPP mpWindowEventHandlerUPP; SInt32 i = -1; const EventTypeSpec windowEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassMP, kEventKQueue }, { kEventClassWindow, kEventWindowClose } }; err = CreateWindowFromNib( g.mainNib, CFSTR("MainWindow"), &window ); if ( (err != noErr) || (window == NULL) ) goto Bail; if ( mpWindowEventHandlerUPP == NULL ) mpWindowEventHandlerUPP = NewEventHandlerUPP( MPWindowEventHandlerProc ); // MPWindowEventHandlerProc handles events for this window err = InstallWindowEventHandler( window, mpWindowEventHandlerUPP, GetEventTypeCount(windowEvents), windowEvents, window, NULL ); // Display the directories we are going to watch in the static text fields. In this sample we hard code the values to a few specific locations err = FSFindFolder( kUserDomain, kDesktopFolderType, kDontCreateFolder, &fsRef ); // Watch the Desktop folder err1 = FSRefMakePath( &fsRef, (UInt8 *)path, MAXPATHLEN ); if ( (err == noErr) && (err1 == noErr) ) SetControlCString( window, 'STxt', ++i, path ); err = FSFindFolder( kUserDomain, kDocumentsFolderType, kDontCreateFolder, &fsRef ); // Watch the Documents folder err1 = FSRefMakePath( &fsRef, (UInt8 *)path, MAXPATHLEN ); if ( (err == noErr) && (err1 == noErr) ) SetControlCString( window, 'STxt', ++i, path ); err = FSFindFolder( kUserDomain, kCurrentUserFolderType, kDontCreateFolder, &fsRef ); // Watch the Users folder err1 = FSRefMakePath( &fsRef, (UInt8 *)path, MAXPATHLEN ); if ( (err == noErr) && (err1 == noErr) ) SetControlCString( window, 'STxt', ++i, path ); mpTaskInfo = (MyMPTaskInfo*) NewPtrClear( sizeof(MyMPTaskInfo) ); SetWRefCon( window, (long) mpTaskInfo ); for ( mpTaskInfo->count = 0 ; mpTaskInfo->count < kMaxFoldersToWatch ; mpTaskInfo->count++ ) { GetControlCString( window, 'STxt', mpTaskInfo->count, mpTaskInfo->path[mpTaskInfo->count] ); // This code pretty much just reads back the strings we set above if ( mpTaskInfo->path[mpTaskInfo->count][0] == '\0' ) break; // We initialize a number of values which are not be safe to retrieve from an MP thread. GetControlBySigAndID( window, 'Date', mpTaskInfo->count, &mpTaskInfo->mpControlInfo[mpTaskInfo->count].dateControl ); GetControlBySigAndID( window, 'STxt', mpTaskInfo->count, &control ); mpTaskInfo->mpControlInfo[mpTaskInfo->count].eventTarget = GetControlEventTarget( control ); } if ( mpTaskInfo->count < 1 ) { DisposePtr( (Ptr) mpTaskInfo ); goto Bail; } // Create our MP thread and pass in mpTaskInfo. MyMPTask is responsible for watching the passed in directories, and posting notifications of changes. err = MPCreateTask( MyMPTask, (void *) mpTaskInfo, 0, NULL, 0, 0, kNilOptions, &mpTaskID ); if ( err != noErr ) // Alert if an error occured { CreateStandardAlert( kAlertStopAlert, CFSTR("MPCreateTask returned an error! Will not create window."), NULL, NULL, &alertDialog ); RunStandardAlert( alertDialog, NULL, NULL ); goto Bail; } ShowWindow( window ); Bail: return; }
/***************************************************** * * Do_Preferences(void) * * Purpose: routine to display dialog to set our applications preferences * * Inputs: none * * Returns: none */ static void Do_Preferences(void) { DialogRef theAlert; CreateStandardAlert(kAlertStopAlert, CFSTR("No Preferences yet!"), NULL, NULL, &theAlert); RunStandardAlert(theAlert, NULL, NULL); } // Do_Preferences
void display_mac_alert(char *message, int error) { window *wind; d_event event; int fullscreen; bool osX = FALSE; uint response; int16_t itemHit; // Handle Descent's windows properly if ((wind = window_get_front())) WINDOW_SEND_EVENT(wind, EVENT_WINDOW_DEACTIVATED); if (grd_curscreen && (fullscreen = gr_check_fullscreen())) gr_toggle_fullscreen(); osX = ( Gestalt(gestaltSystemVersion, (long *) &response) == noErr) && (response >= 0x01000 ); ShowCursor(); if (osX) { #ifdef TARGET_API_MAC_CARBON DialogRef alert; CFStringRef error_text = CFSTR("Sorry, a critical error has occurred."); CFStringRef text = NULL; text = CFStringCreateWithCString(CFAllocatorGetDefault(), message, kCFStringEncodingMacRoman); if (!text) { if (wind) WINDOW_SEND_EVENT(wind, EVENT_WINDOW_ACTIVATED); return; } if (CreateStandardAlert(error ? kAlertStopAlert : kAlertNoteAlert, error ? error_text : text, error ? text : NULL, 0, &alert) != noErr) { CFRelease(text); if (wind) WINDOW_SEND_EVENT(wind, EVENT_WINDOW_ACTIVATED); return; } RunStandardAlert(alert, 0, &itemHit); CFRelease(text); #endif } else { // This #if guard removes both compiler warnings // and complications if we didn't link the (older) Mac OS X SDK that actually supports the following. #if !defined(MAC_OS_X_VERSION_MAX_ALLOWED) || (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4) Str255 error_text = "\pSorry, a critical error has occurred."; Str255 text; CopyCStringToPascal(message, text); StandardAlert(error ? kAlertStopAlert : kAlertNoteAlert, error ? error_text : text, error ? text : NULL, 0, &itemHit); #endif } if ((wind = window_get_front())) WINDOW_SEND_EVENT(wind, EVENT_WINDOW_ACTIVATED); if (grd_curscreen && !error && fullscreen) gr_toggle_fullscreen(); }
int wxMessageDialog::ShowModal() { WX_HOOK_MODAL_DIALOG(); int resultbutton = wxID_CANCEL; const long style = GetMessageDialogStyle(); wxASSERT_MSG( (style & 0x3F) != wxYES, "this style is not supported on Mac" ); AlertType alertType = kAlertPlainAlert; switch ( GetEffectiveIcon() ) { case wxICON_ERROR: alertType = kAlertStopAlert; break; case wxICON_WARNING: alertType = kAlertCautionAlert; break; case wxICON_QUESTION: case wxICON_INFORMATION: alertType = kAlertNoteAlert; break; } // (the standard alert has two slots [title, text] // for the three wxStrings [caption, message, extended message]) // // if the extended text is empty we use the caption and // the message (for backwards compatibility) // // if the extended text is not empty we ignore the caption // and use the message and the extended message wxString msgtitle,msgtext; if(m_extendedMessage.IsEmpty()) { if ( m_caption.IsEmpty() ) msgtitle = m_message; else { msgtitle = m_caption; msgtext = m_message; } } else { msgtitle = m_message; msgtext = m_extendedMessage; } if ( !wxIsMainThread() ) { CFStringRef defaultButtonTitle = NULL; CFStringRef alternateButtonTitle = NULL; CFStringRef otherButtonTitle = NULL; wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() ); wxCFStringRef cfText( msgtext, GetFont().GetEncoding() ); wxCFStringRef cfNoString( GetNoLabel().c_str(), GetFont().GetEncoding() ); wxCFStringRef cfYesString( GetYesLabel().c_str(), GetFont().GetEncoding() ); wxCFStringRef cfOKString( GetOKLabel().c_str() , GetFont().GetEncoding()) ; wxCFStringRef cfCancelString( GetCancelLabel().c_str(), GetFont().GetEncoding() ); int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ }; if (style & wxYES_NO) { if ( style & wxNO_DEFAULT ) { defaultButtonTitle = cfNoString; alternateButtonTitle = cfYesString; buttonId[0] = wxID_NO; buttonId[1] = wxID_YES; } else { defaultButtonTitle = cfYesString; alternateButtonTitle = cfNoString; buttonId[0] = wxID_YES; buttonId[1] = wxID_NO; } if (style & wxCANCEL) { otherButtonTitle = cfCancelString; buttonId[2] = wxID_CANCEL; } } else { // the MSW implementation even shows an OK button if it is not specified, we'll do the same buttonId[0] = wxID_OK; // using null as default title does not work on earlier systems defaultButtonTitle = cfOKString; if (style & wxCANCEL) { alternateButtonTitle = cfCancelString; buttonId[1] = wxID_CANCEL; } } CFOptionFlags exitButton; OSStatus err = CFUserNotificationDisplayAlert( 0, alertType, NULL, NULL, NULL, cfTitle, cfText, defaultButtonTitle, alternateButtonTitle, otherButtonTitle, &exitButton ); if (err == noErr) resultbutton = buttonId[exitButton]; } else { short result; AlertStdCFStringAlertParamRec param; wxCFStringRef cfNoString( GetNoLabel().c_str(), GetFont().GetEncoding() ); wxCFStringRef cfYesString( GetYesLabel().c_str(), GetFont().GetEncoding() ); wxCFStringRef cfOKString( GetOKLabel().c_str(), GetFont().GetEncoding() ); wxCFStringRef cfCancelString( GetCancelLabel().c_str(), GetFont().GetEncoding() ); wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() ); wxCFStringRef cfText = msgtext.IsEmpty() ? wxCFStringRef() : wxCFStringRef( msgtext, GetFont().GetEncoding() ); param.movable = true; param.flags = 0; param.version = kStdCFStringAlertVersionOne; bool skipDialog = false; if (style & wxYES_NO) { if (style & wxCANCEL) { param.defaultText = cfYesString; param.cancelText = cfCancelString; param.otherText = cfNoString; param.helpButton = false; param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; param.cancelButton = kAlertStdAlertCancelButton; } else { param.defaultText = cfYesString; param.cancelText = NULL; param.otherText = cfNoString; param.helpButton = false; param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; param.cancelButton = 0; } } // the MSW implementation even shows an OK button if it is not specified, we'll do the same else { if (style & wxCANCEL) { // that's a cancel missing param.defaultText = cfOKString; param.cancelText = cfCancelString; param.otherText = NULL; param.helpButton = false; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } else { param.defaultText = cfOKString; param.cancelText = NULL; param.otherText = NULL; param.helpButton = false; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } } param.position = kWindowDefaultPosition; if ( !skipDialog ) { DialogRef alertRef; CreateStandardAlert( alertType, cfTitle, cfText, ¶m, &alertRef ); wxDialog::OSXBeginModalDialog(); RunStandardAlert( alertRef, NULL, &result ); wxDialog::OSXEndModalDialog(); } else { return wxID_CANCEL; } if (style & wxOK) { switch ( result ) { case 1: resultbutton = wxID_OK; break; case 2: // TODO: add Cancel button // if (style & wxCANCEL) // resultbutton = wxID_CANCEL; break; case 3: default: break; } } else if (style & wxYES_NO) { switch ( result ) { case 1: resultbutton = wxID_YES; break; case 2: if (!(style & wxCANCEL)) resultbutton = wxID_CANCEL; break; case 3: resultbutton = wxID_NO; break; default: break; } } } SetReturnCode(resultbutton); return resultbutton; }
int main(int argc, char **argv) { // We assume that all the logs we're looking for reside on the current drive gDirUtilp->initAppDirs("SecondLife"); ///////////////////////////////////////// // // Process command line arguments // gUpdateURL = NULL; gProductName = NULL; parse_args(argc, argv); if (!gUpdateURL) { llinfos << "Usage: mac_updater -url <url> [-name <product_name>] [-program <program_name>]" << llendl; exit(1); } else { llinfos << "Update url is: " << gUpdateURL << llendl; if (gProductName) { llinfos << "Product name is: " << gProductName << llendl; } else { gProductName = "Second Life"; } } llinfos << "Starting " << gProductName << " Updater" << llendl; // Real UI... OSStatus err; IBNibRef nib = NULL; err = CreateNibReference(CFSTR("AutoUpdater"), &nib); char windowTitle[MAX_PATH]; /* Flawfinder: ignore */ snprintf(windowTitle, sizeof(windowTitle), "%s Updater", gProductName); CFStringRef windowTitleRef = NULL; windowTitleRef = CFStringCreateWithCString(NULL, windowTitle, kCFStringEncodingUTF8); if(err == noErr) { err = CreateWindowFromNib(nib, CFSTR("Updater"), &gWindow); } if (err == noErr) { err = SetWindowTitleWithCFString(gWindow, windowTitleRef); } CFRelease(windowTitleRef); if(err == noErr) { // Set up an event handler for the window. EventTypeSpec handlerEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassCustom, kEventCustomProgress }, { kEventClassCustom, kEventCustomDone } }; InstallStandardEventHandler(GetWindowEventTarget(gWindow)); InstallWindowEventHandler( gWindow, NewEventHandlerUPP(dialogHandler), GetEventTypeCount (handlerEvents), handlerEvents, 0, &gEventHandler); } if(err == noErr) { ShowWindow(gWindow); } if(err == noErr) { pthread_create(&updatethread, NULL, &updatethreadproc, NULL); } if(err == noErr) { RunAppModalLoopForWindow(gWindow); } void *threadresult; pthread_join(updatethread, &threadresult); if(!gCancelled && (gFailure != noErr)) { // Something went wrong. Since we always just tell the user to download a new version, we don't really care what. AlertStdCFStringAlertParamRec params; SInt16 retval_mac = 1; DialogRef alert = NULL; OSStatus err; params.version = kStdCFStringAlertVersionOne; params.movable = false; params.helpButton = false; params.defaultText = (CFStringRef)kAlertDefaultOKText; params.cancelText = 0; params.otherText = 0; params.defaultButton = 1; params.cancelButton = 0; params.position = kWindowDefaultPosition; params.flags = 0; err = CreateStandardAlert( kAlertStopAlert, CFSTR("Error"), CFSTR("An error occurred while updating Second Life. Please download the latest version from www.secondlife.com."), ¶ms, &alert); if(err == noErr) { err = RunStandardAlert( alert, NULL, &retval_mac); } } // Don't dispose of things, just exit. This keeps the update thread from potentially getting hosed. exit(0); if(gWindow != NULL) { DisposeWindow(gWindow); } if(nib != NULL) { DisposeNibReference(nib); } return 0; }