BOOL LLAsyncHostByName::startRequest( const LLString& domain_name, LLAsyncHostByNameCallback callback, void* userdata ) { if( isPendingRequest() ) { llwarns << "LLAsyncHostByName::startRequest() cancelled existing request." << llendl; cancelPendingRequest(); } mCallback = callback; mUserdata = userdata; memset(mOutputBuffer, 0, sizeof( mOutputBuffer ) ); mDomainName = domain_name; mRequestHandle = WSAAsyncGetHostByName( (HWND)gViewerWindow->getPlatformWindow(), LL_WM_HOST_RESOLVED, domain_name.c_str(), mOutputBuffer, sizeof( mOutputBuffer ) ); if( !mRequestHandle ) { llwarns << "LLAsyncHostByName::startRequest() failed: " << WSAGetLastError() << llendl; return FALSE; } return TRUE; }
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata) { LLString size = userdata.asString(); S32 width, height; sscanf(size.c_str(), "%d,%d", &width, &height); LLViewerWindow::movieSize(width, height); return true; }
// virtual void LLPanelDirPlaces::performQuery() { LLString name = childGetValue("name").asString(); if (name.length() < mMinSearchChars) { return; } LLString catstring = childGetValue("Category").asString(); // Because LLParcel::C_ANY is -1, must do special check S32 category = 0; if (catstring == "any") { category = LLParcel::C_ANY; } else { category = LLParcel::getCategoryFromString(catstring.c_str()); } U32 flags = 0x0; bool adult_enabled = gAgent.canAccessAdult(); bool mature_enabled = gAgent.canAccessMature(); if (gSavedSettings.getBOOL("ShowPGSims") || (!adult_enabled && !mature_enabled)) // if they can't have either of the others checked, force this one true { flags |= DFQ_INC_PG; } if( gSavedSettings.getBOOL("ShowMatureSims") && mature_enabled) { flags |= DFQ_INC_MATURE; } if( gSavedSettings.getBOOL("ShowAdultSims") && adult_enabled) { flags |= DFQ_INC_ADULT; } // Pack old query flag in case we are talking to an old server if ( ((flags & DFQ_INC_PG) == DFQ_INC_PG) && !((flags & DFQ_INC_MATURE) == DFQ_INC_MATURE) ) { flags |= DFQ_PG_PARCELS_ONLY; } if (0x0 == flags) { LLNotifyBox::showXml("NoContentToSearch"); return; } queryCore(name, category, flags); }
// static void LLFloaterFriends::requestFriendship(const LLUUID& target_id, const LLString& target_name) { // HACK: folder id stored as "message" LLUUID calling_card_folder_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_CALLINGCARD); std::string message = calling_card_folder_id.asString(); send_improved_im(target_id, target_name.c_str(), message.c_str(), IM_ONLINE, IM_FRIENDSHIP_OFFERED); }
// Reads a .tga file and creates an LLImageTGA with its data. bool LLImageTGA::loadFile( const LLString& path ) { S32 len = path.size(); if( len < 5 ) { return false; } LLString extension = path.substr( len - 4, 4 ); LLString::toLower(extension); if( ".tga" != extension ) { return false; } FILE* file = LLFile::fopen(path.c_str(), "rb"); /* Flawfinder: ignore */ if( !file ) { llwarns << "Couldn't open file " << path << llendl; return false; } S32 file_size = 0; if (!fseek(file, 0, SEEK_END)) { file_size = ftell(file); fseek(file, 0, SEEK_SET); } U8* buffer = allocateData(file_size); S32 bytes_read = fread(buffer, 1, file_size, file); if( bytes_read != file_size ) { deleteData(); llwarns << "Couldn't read file " << path << llendl; return false; } fclose( file ); if( !updateData() ) { llwarns << "Couldn't decode file " << path << llendl; deleteData(); return false; } return true; }
void LLSpinCtrl::updateEditor() { LLLocale locale(LLLocale::USER_LOCALE); // Don't display very small negative values as -0.000 F32 displayed_value = clamp_precision((F32)getValue().asReal(), mPrecision); // if( S32( displayed_value * pow( 10, mPrecision ) ) == 0 ) // { // displayed_value = 0.f; // } LLString format = llformat("%%.%df", mPrecision); LLString text = llformat(format.c_str(), displayed_value); mEditor->setText( text ); }
void LLSpinCtrl::onEditorCommit( LLUICtrl* caller, void *userdata ) { BOOL success = FALSE; LLSpinCtrl* self = (LLSpinCtrl*) userdata; llassert( caller == self->mEditor ); LLString text = self->mEditor->getText(); if( LLLineEditor::postvalidateFloat( text ) ) { LLLocale locale(LLLocale::USER_LOCALE); F32 val = (F32) atof(text.c_str()); if (val < self->mMinValue) val = self->mMinValue; if (val > self->mMaxValue) val = self->mMaxValue; if( self->mValidateCallback ) { F32 saved_val = self->mValue; self->mValue = val; if( self->mValidateCallback( self, self->mCallbackUserData ) ) { success = TRUE; self->onCommit(); } else { self->mValue = saved_val; } } else { self->mValue = val; self->onCommit(); success = TRUE; } } self->updateEditor(); if( !success ) { self->reportInvalidData(); } }
BOOL LLAsyncHostByName::startRequest( const LLString& domain_name, LLAsyncHostByNameCallback callback, void* userdata ) { struct hostent *response; U32 ip; BOOL result = FALSE; response = gethostbyname(domain_name.c_str()); if(response != NULL) { if(response->h_addrtype == AF_INET) { ip = ((struct in_addr*)response->h_addr_list[0])->s_addr; result = TRUE; (*callback)(result, domain_name, ip, userdata); } } return result; }
BOOL LLMediaImplGStreamer:: load ( const LLString& urlIn ) { llinfos << "Setting media URI: " << urlIn << llendl; if (!mPlaybin) { return FALSE; } // set URI g_object_set (G_OBJECT (mPlaybin), "uri", urlIn.c_str(), NULL); //g_object_set (G_OBJECT (mPlaybin), "uri", "file:///tmp/movie", NULL); // get playbin's bus - perhaps this can/should be done at init() GstBus *bus = llgst_pipeline_get_bus (GST_PIPELINE (mPlaybin)); if (!bus) { return FALSE; } llgst_bus_add_watch (bus, my_bus_callback, this); llgst_object_unref (bus); if (true) // dummy values { const int fixedsize = 2; mMediaRowbytes = mMediaDepthBytes * fixedsize; mMediaWidth = fixedsize; mMediaHeight = fixedsize; mTextureWidth = fixedsize; mTextureHeight = fixedsize; } BOOL rtn = LLMediaMovieBase::load(urlIn); llinfos << "load returns " << int(rtn) << llendl; return rtn; }
U32 LLControlGroup::loadFromFileLegacy(const LLString& filename, BOOL require_declaration, eControlType declare_as) { U32 item = 0; U32 validitems = 0; llifstream file; S32 version; file.open(filename.c_str()); /*Flawfinder: ignore*/ if (!file) { llinfos << "LLControlGroup::loadFromFile unable to open." << llendl; return 0; } // Check file version LLString name; file >> name; file >> version; if (name != "version" || version != CURRENT_VERSION) { llinfos << filename << " does not appear to be a version " << CURRENT_VERSION << " controls file" << llendl; return 0; } while (!file.eof()) { file >> name; if (name.empty()) { continue; } if (name.substr(0,2) == "//") { // This is a comment. char buffer[MAX_STRING]; /*Flawfinder: ignore*/ file.getline(buffer, MAX_STRING); continue; } BOOL declared = mNameTable.find(name) != mNameTable.end(); if (require_declaration && !declared) { // Declaration required, but this name not declared. // Complain about non-empty names. if (!name.empty()) { //read in to end of line char buffer[MAX_STRING]; /*Flawfinder: ignore*/ file.getline(buffer, MAX_STRING); llwarns << "LLControlGroup::loadFromFile() : Trying to set \"" << name << "\", setting doesn't exist." << llendl; } continue; } // Got an item. Load it up. item++; // If not declared, assume it's a string if (!declared) { switch(declare_as) { case TYPE_COL4: declareColor4(name, LLColor4::white, LLString::null, NO_PERSIST); break; case TYPE_COL4U: declareColor4U(name, LLColor4U::white, LLString::null, NO_PERSIST); break; case TYPE_STRING: default: declareString(name, LLString::null, LLString::null, NO_PERSIST); break; } } // Control name has been declared in code. LLControlBase *control = getControl(name); llassert(control); mLoadedSettings.insert(name); switch(control->mType) { case TYPE_F32: { F32 initial; file >> initial; control->set(initial); validitems++; } break; case TYPE_S32: { S32 initial; file >> initial; control->set(initial); validitems++; } break; case TYPE_U32: { U32 initial; file >> initial; control->set((LLSD::Integer) initial); validitems++; } break; case TYPE_BOOLEAN: { char boolstring[256]; /*Flawfinder: ignore*/ BOOL valid = FALSE; BOOL initial = FALSE; file >> boolstring; if (!strcmp("TRUE", boolstring)) { initial = TRUE; valid = TRUE; } else if (!strcmp("FALSE", boolstring)) { initial = FALSE; valid = TRUE; } if (valid) { control->set(initial); } else { llinfos << filename << "Item " << item << ": Invalid BOOL control " << name << ", " << boolstring << llendl; } validitems++; } break; case TYPE_STRING: { LLString string; file >> string; control->set(string); validitems++; } break; case TYPE_VEC3: { F32 x, y, z; file >> x >> y >> z; LLVector3 vector(x, y, z); control->set(vector.getValue()); validitems++; } break; case TYPE_VEC3D: { F64 x, y, z; file >> x >> y >> z; LLVector3d vector(x, y, z); control->set(vector.getValue()); validitems++; } break; case TYPE_RECT: { S32 left, bottom, width, height; file >> left >> bottom >> width >> height; LLRect rect; rect.setOriginAndSize(left, bottom, width, height); control->set(rect.getValue()); validitems++; } break; case TYPE_COL4U: { S32 red, green, blue, alpha; LLColor4U color; file >> red >> green >> blue >> alpha; color.setVec(red, green, blue, alpha); control->set(color.getValue()); validitems++; } break; case TYPE_COL4: { LLColor4 color; file >> color.mV[VRED] >> color.mV[VGREEN] >> color.mV[VBLUE] >> color.mV[VALPHA]; control->set(color.getValue()); validitems++; } break; case TYPE_COL3: { LLColor3 color; file >> color.mV[VRED] >> color.mV[VGREEN] >> color.mV[VBLUE]; control->set(color.getValue()); validitems++; } break; } } file.close(); return validitems; }
U32 LLControlGroup::saveToFile(const LLString& filename, BOOL nondefault_only) { const char ENDL = '\n'; llinfos << "Saving settings to file: " << filename << llendl; // place the objects in a temporary container that enforces a sort // order to ease manual editing of the file LLLinkedList< LLControlBase > controls; controls.setInsertBefore( &control_insert_before ); LLString name; for (ctrl_name_table_t::iterator iter = mNameTable.begin(); iter != mNameTable.end(); iter++) { name = iter->first; if (name.empty()) { CONTROL_ERRS << "Control with no name found!!!" << llendl; break; } LLControlBase* control = (LLControlBase *)iter->second; if (!control) { llwarns << "Tried to save invalid control: " << name << llendl; } if( control && control->mPersist ) { if (!(nondefault_only && (control->mIsDefault))) { controls.addDataSorted( control ); } else { // Debug spam // llinfos << "Skipping " << control->getName() << llendl; } } } llofstream file; file.open(filename.c_str()); /*Flawfinder: ignore*/ if (!file.is_open()) { // This is a warning because sometime we want to use settings files which can't be written... llwarns << "LLControlGroup::saveToFile unable to open file for writing" << llendl; return 0; } // Write file version file << "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n"; file << "<settings version = \"" << CURRENT_VERSION << "\">\n"; for( LLControlBase* control = controls.getFirstData(); control != NULL; control = controls.getNextData() ) { file << "\t<!--" << control->comment() << "-->" << ENDL; name = control->name(); switch (control->type()) { case TYPE_U32: { file << "\t<" << name << " value=\"" << (U32) control->get().asInteger() << "\"/>\n"; break; } case TYPE_S32: { file << "\t<" << name << " value=\"" << (S32) control->get().asInteger() << "\"/>\n"; break; } case TYPE_F32: { file << "\t<" << name << " value=\"" << (F32) control->get().asReal() << "\"/>\n"; break; } case TYPE_VEC3: { LLVector3 vector(control->get()); file << "\t<" << name << " value=\"" << vector.mV[VX] << " " << vector.mV[VY] << " " << vector.mV[VZ] << "\"/>\n"; break; } case TYPE_VEC3D: { LLVector3d vector(control->get()); file << "\t<" << name << " value=\"" << vector.mdV[VX] << " " << vector.mdV[VY] << " " << vector.mdV[VZ] << "\"/>\n"; break; } case TYPE_RECT: { LLRect rect(control->get()); file << "\t<" << name << " value=\"" << rect.mLeft << " " << rect.mBottom << " " << rect.getWidth() << " " << rect.getHeight() << "\"/>\n"; break; } case TYPE_COL4: { LLColor4 color(control->get()); file << "\t<" << name << " value=\"" << color.mV[VRED] << ", " << color.mV[VGREEN] << ", " << color.mV[VBLUE] << ", " << color.mV[VALPHA] << "\"/>\n"; break; } case TYPE_COL3: { LLColor3 color(control->get()); file << "\t<" << name << " value=\"" << color.mV[VRED] << ", " << color.mV[VGREEN] << ", " << color.mV[VBLUE] << "\"/>\n"; break; } case TYPE_BOOLEAN: { file << "\t<" << name << " value=\"" << (control->get().asBoolean() ? "TRUE" : "FALSE") << "\"/>\n"; break; } case TYPE_STRING: { file << "\t<" << name << " value=\"" << LLSDXMLFormatter::escapeString(control->get().asString()) << "\"/>\n"; break; } default: { CONTROL_ERRS << "LLControlGroup::saveToFile - unknown control type!" << llendl; break; } } // Debug spam // llinfos << name << " " << control->getValue().asString() << llendl; }// next file << "</settings>\n"; file.close(); return controls.getLength(); }
void upload_new_resource(const LLString& src_filename, std::string name, std::string desc, S32 compression_info, LLAssetType::EType destination_folder_type, LLInventoryType::EType inv_type, U32 next_owner_perm, const LLString& display_name, LLAssetStorage::LLStoreAssetCallback callback, void *userdata) { // Generate the temporary UUID. LLString filename = gDirUtilp->getTempFilename(); LLTransactionID tid; LLAssetID uuid; LLStringBase<char>::format_map_t args; LLString ext = src_filename.substr(src_filename.find_last_of('.')); LLAssetType::EType asset_type = LLAssetType::AT_NONE; char error_message[MAX_STRING]; /* Flawfinder: ignore */ error_message[0] = '\0'; LLString temp_str; BOOL error = FALSE; if (ext.empty()) { LLString::size_type offset = filename.find_last_of(gDirUtilp->getDirDelimiter()); if (offset != LLString::npos) offset++; LLString short_name = filename.substr(offset); // No extension snprintf(error_message, /* Flawfinder: ignore */ MAX_STRING, "No file extension for the file: '%s'\nPlease make sure the file has a correct file extension", short_name.c_str()); args["[FILE]"] = short_name; upload_error(error_message, "NofileExtension", filename, args); return; } else if( LLString::compareInsensitive(ext.c_str(),".bmp") == 0 ) { asset_type = LLAssetType::AT_TEXTURE; if (!LLViewerImageList::createUploadFile(src_filename, filename, IMG_CODEC_BMP )) { snprintf(error_message, MAX_STRING, "Problem with file %s:\n\n%s\n", /* Flawfinder: ignore */ src_filename.c_str(), LLImageBase::getLastError().c_str()); args["[FILE]"] = src_filename; args["[ERROR]"] = LLImageBase::getLastError(); upload_error(error_message, "ProblemWithFile", filename, args); return; } } else if( LLString::compareInsensitive(ext.c_str(),".tga") == 0 ) { asset_type = LLAssetType::AT_TEXTURE; if (!LLViewerImageList::createUploadFile(src_filename, filename, IMG_CODEC_TGA )) { snprintf(error_message, MAX_STRING, "Problem with file %s:\n\n%s\n", /* Flawfinder: ignore */ src_filename.c_str(), LLImageBase::getLastError().c_str()); args["[FILE]"] = src_filename; args["[ERROR]"] = LLImageBase::getLastError(); upload_error(error_message, "ProblemWithFile", filename, args); return; } } else if( LLString::compareInsensitive(ext.c_str(),".jpg") == 0 || LLString::compareInsensitive(ext.c_str(),".jpeg") == 0) { asset_type = LLAssetType::AT_TEXTURE; if (!LLViewerImageList::createUploadFile(src_filename, filename, IMG_CODEC_JPEG )) { snprintf(error_message, MAX_STRING, "Problem with file %s:\n\n%s\n", /* Flawfinder: ignore */ src_filename.c_str(), LLImageBase::getLastError().c_str()); args["[FILE]"] = src_filename; args["[ERROR]"] = LLImageBase::getLastError(); upload_error(error_message, "ProblemWithFile", filename, args); return; } } else if(LLString::compareInsensitive(ext.c_str(),".wav") == 0) { asset_type = LLAssetType::AT_SOUND; // tag it as audio S32 encode_result = 0; S32 bitrate = 128; if (compression_info) { bitrate = compression_info; } llinfos << "Attempting to encode wav as an ogg file at " << bitrate << "kbps" << llendl; encode_result = encode_vorbis_file_at(src_filename.c_str(), filename.c_str(), bitrate*1000); if (LLVORBISENC_NOERR != encode_result) { switch(encode_result) { case LLVORBISENC_DEST_OPEN_ERR: snprintf(error_message, MAX_STRING, "Couldn't open temporary compressed sound file for writing: %s\n", filename.c_str()); /* Flawfinder: ignore */ args["[FILE]"] = filename; upload_error(error_message, "CannotOpenTemporarySoundFile", filename, args); break; default: snprintf(error_message, MAX_STRING, "Unknown vorbis encode failure on: %s\n", src_filename.c_str()); /* Flawfinder: ignore */ args["[FILE]"] = src_filename; upload_error(error_message, "UnknownVorbisEncodeFailure", filename, args); break; } return; } } else if(LLString::compareInsensitive(ext.c_str(),".tmp") == 0) { // This is a generic .lin resource file asset_type = LLAssetType::AT_OBJECT; FILE* in = LLFile::fopen(src_filename.c_str(), "rb"); /* Flawfinder: ignore */ if (in) { // read in the file header char buf[16384]; /* Flawfinder: ignore */ S32 read; /* Flawfinder: ignore */ S32 version; if (fscanf(in, "LindenResource\nversion %d\n", &version)) { if (2 == version) { // *NOTE: This buffer size is hard coded into scanf() below. char label[MAX_STRING]; /* Flawfinder: ignore */ char value[MAX_STRING]; /* Flawfinder: ignore */ S32 tokens_read; while (fgets(buf, 1024, in)) { label[0] = '\0'; value[0] = '\0'; tokens_read = sscanf( /* Flawfinder: ignore */ buf, "%254s %254s\n", label, value); llinfos << "got: " << label << " = " << value << llendl; if (EOF == tokens_read) { fclose(in); snprintf(error_message, MAX_STRING, "corrupt resource file: %s", src_filename.c_str()); /* Flawfinder: ignore */ args["[FILE]"] = src_filename; upload_error(error_message, "CorruptResourceFile", filename, args); return; } if (2 == tokens_read) { if (! strcmp("type", label)) { asset_type = (LLAssetType::EType)(atoi(value)); } } else { if (! strcmp("_DATA_", label)) { // below is the data section break; } } // other values are currently discarded } } else { fclose(in); snprintf(error_message, MAX_STRING, "unknown linden resource file version in file: %s", src_filename.c_str()); /* Flawfinder: ignore */ args["[FILE]"] = src_filename; upload_error(error_message, "UnknownResourceFileVersion", filename, args); return; } } else { // this is an original binary formatted .lin file // start over at the beginning of the file fseek(in, 0, SEEK_SET); const S32 MAX_ASSET_DESCRIPTION_LENGTH = 256; const S32 MAX_ASSET_NAME_LENGTH = 64; S32 header_size = 34 + MAX_ASSET_DESCRIPTION_LENGTH + MAX_ASSET_NAME_LENGTH; S16 type_num; // read in and throw out most of the header except for the type fread(buf, header_size, 1, in); memcpy(&type_num, buf + 16, sizeof(S16)); /* Flawfinder: ignore */ asset_type = (LLAssetType::EType)type_num; } // copy the file's data segment into another file for uploading FILE* out = LLFile::fopen(filename.c_str(), "wb"); /* Flawfinder: ignore */ if (out) { while((read = fread(buf, 1, 16384, in))) /* Flawfinder: ignore */ { fwrite(buf, 1, read, out); /* Flawfinder: ignore */ } fclose(out); } else { fclose(in); snprintf(error_message, MAX_STRING, "Unable to create output file: %s", filename.c_str()); /* Flawfinder: ignore */ args["[FILE]"] = filename; upload_error(error_message, "UnableToCreateOutputFile", filename, args); return; } fclose(in); } else { llinfos << "Couldn't open .lin file " << src_filename << llendl; } } else if (LLString::compareInsensitive(ext.c_str(),".bvh") == 0) { snprintf(error_message, MAX_STRING, "We do not currently support bulk upload of animation files\n"); /* Flawfinder: ignore */ upload_error(error_message, "DoNotSupportBulkAnimationUpload", filename, args); return; } else { // Unknown extension snprintf(error_message, MAX_STRING, "Unknown file extension %s\nExpected .wav, .tga, .bmp, .jpg, .jpeg, or .bvh", ext.c_str()); /* Flawfinder: ignore */ error = TRUE;; } // gen a new transaction ID for this asset tid.generate(); if (!error) { uuid = tid.makeAssetID(gAgent.getSecureSessionID()); // copy this file into the vfs for upload S32 file_size; apr_file_t* fp = ll_apr_file_open(filename, LL_APR_RB, &file_size); if (fp) { LLVFile file(gVFS, uuid, asset_type, LLVFile::WRITE); file.setMaxSize(file_size); const S32 buf_size = 65536; U8 copy_buf[buf_size]; while ((file_size = ll_apr_file_read(fp, copy_buf, buf_size))) { file.write(copy_buf, file_size); } apr_file_close(fp); } else { snprintf(error_message, MAX_STRING, "Unable to access output file: %s", filename.c_str()); /* Flawfinder: ignore */ error = TRUE; } } if (!error) { LLString t_disp_name = display_name; if (t_disp_name.empty()) { t_disp_name = src_filename; } upload_new_resource(tid, asset_type, name, desc, compression_info, // tid destination_folder_type, inv_type, next_owner_perm, display_name, callback, userdata); } else { llwarns << error_message << llendl; LLStringBase<char>::format_map_t args; args["[ERROR_MESSAGE]"] = error_message; gViewerWindow->alertXml("ErrorMessage", args); if(LLFile::remove(filename.c_str()) == -1) { lldebugs << "unable to remove temp file" << llendl; } LLFilePicker::instance().reset(); } }
void *updatethreadproc(void*) { char tempDir[PATH_MAX] = ""; /* Flawfinder: ignore */ FSRef tempDirRef; char temp[PATH_MAX]; /* Flawfinder: ignore */ // *NOTE: This buffer length is used in a scanf() below. char deviceNode[1024] = ""; /* Flawfinder: ignore */ FILE *downloadFile = NULL; OSStatus err; ProcessSerialNumber psn; char target[PATH_MAX]; /* Flawfinder: ignore */ FSRef targetRef; FSRef targetParentRef; FSVolumeRefNum targetVol; FSRef trashFolderRef, tempFolderRef; Boolean replacingTarget = false; memset(&tempDirRef, 0, sizeof(tempDirRef)); memset(&targetRef, 0, sizeof(targetRef)); memset(&targetParentRef, 0, sizeof(targetParentRef)); try { // Attempt to get a reference to the Second Life application bundle containing this updater. // Any failures during this process will cause us to default to updating /Applications/Second Life.app { FSRef myBundle; err = GetCurrentProcess(&psn); if(err == noErr) { err = GetProcessBundleLocation(&psn, &myBundle); } if(err == noErr) { // Sanity check: Make sure the name of the item referenced by targetRef is "Second Life.app". FSRefMakePath(&myBundle, (UInt8*)target, sizeof(target)); llinfos << "Updater bundle location: " << target << llendl; } // Our bundle should be in Second Life.app/Contents/Resources/AutoUpdater.app // so we need to go up 3 levels to get the path to the main application bundle. if(err == noErr) { err = FSGetParentRef(&myBundle, &targetRef); } if(err == noErr) { err = FSGetParentRef(&targetRef, &targetRef); } if(err == noErr) { err = FSGetParentRef(&targetRef, &targetRef); } // And once more to get the parent of the target if(err == noErr) { err = FSGetParentRef(&targetRef, &targetParentRef); } if(err == noErr) { FSRefMakePath(&targetRef, (UInt8*)target, sizeof(target)); llinfos << "Path to target: " << target << llendl; } // Sanity check: make sure the target is a bundle with the right identifier if(err == noErr) { // Assume the worst... err = -1; if(isFSRefViewerBundle(&targetRef)) { // This is the bundle we're looking for. err = noErr; replacingTarget = true; } } // Make sure the target's parent directory is writable. if(err == noErr) { if(!isDirWritable(targetParentRef)) { // Parent directory isn't writable. llinfos << "Target parent directory not writable." << llendl; err = -1; replacingTarget = false; } } if(err != noErr) { Boolean isDirectory; llinfos << "Target search failed, defaulting to /Applications/" << gProductName << ".app." << llendl; // Set up the parent directory err = FSPathMakeRef((UInt8*)"/Applications", &targetParentRef, &isDirectory); if((err != noErr) || (!isDirectory)) { // We're so hosed. llinfos << "Applications directory not found, giving up." << llendl; throw 0; } snprintf(target, sizeof(target), "/Applications/%s.app", gProductName); memset(&targetRef, 0, sizeof(targetRef)); err = FSPathMakeRef((UInt8*)target, &targetRef, NULL); if(err == fnfErr) { // This is fine, just means we're not replacing anything. err = noErr; replacingTarget = false; } else { replacingTarget = true; } // Make sure the target's parent directory is writable. if(err == noErr) { if(!isDirWritable(targetParentRef)) { // Parent directory isn't writable. llinfos << "Target parent directory not writable." << llendl; err = -1; replacingTarget = false; } } } // If we haven't fixed all problems by this point, just bail. if(err != noErr) { llinfos << "Unable to pick a target, giving up." << llendl; throw 0; } } // Find the volID of the volume the target resides on { FSCatalogInfo info; err = FSGetCatalogInfo( &targetParentRef, kFSCatInfoVolume, &info, NULL, NULL, NULL); if(err != noErr) throw 0; targetVol = info.volume; } // Find the temporary items and trash folders on that volume. err = FSFindFolder( targetVol, kTrashFolderType, true, &trashFolderRef); if(err != noErr) throw 0; err = FSFindFolder( targetVol, kTemporaryFolderType, true, &tempFolderRef); if(err != noErr) throw 0; err = FSRefMakePath(&tempFolderRef, (UInt8*)temp, sizeof(temp)); if(err != noErr) throw 0; temp[0] = '\0'; strncat(temp, "/SecondLifeUpdate_XXXXXX", sizeof(temp) - 1); if(mkdtemp(temp) == NULL) { throw 0; } strcpy(tempDir, temp); /* Flawfinder: ignore */ llinfos << "tempDir is " << tempDir << llendl; err = FSPathMakeRef((UInt8*)tempDir, &tempDirRef, NULL); if(err != noErr) throw 0; chdir(tempDir); snprintf(temp, sizeof(temp), "SecondLife.dmg"); downloadFile = fopen(temp, "wb"); /* Flawfinder: ignore */ if(downloadFile == NULL) { throw 0; } { CURL *curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); // curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &curl_download_callback); curl_easy_setopt(curl, CURLOPT_FILE, downloadFile); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, &curl_progress_callback_func); curl_easy_setopt(curl, CURLOPT_URL, gUpdateURL); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); sendProgress(0, 1, CFSTR("Downloading...")); CURLcode result = curl_easy_perform(curl); curl_easy_cleanup(curl); if(gCancelled) { llinfos << "User cancel, bailing out."<< llendl; throw 0; } if(result != CURLE_OK) { llinfos << "Error " << result << " while downloading disk image."<< llendl; throw 0; } fclose(downloadFile); downloadFile = NULL; } sendProgress(0, 0, CFSTR("Mounting image...")); LLFile::mkdir("mnt", 0700); // NOTE: we could add -private at the end of this command line to keep the image from showing up in the Finder, // but if our cleanup fails, this makes it much harder for the user to unmount the image. LLString mountOutput; FILE* mounter = popen("hdiutil attach SecondLife.dmg -mountpoint mnt", "r"); /* Flawfinder: ignore */ if(mounter == NULL) { llinfos << "Failed to mount disk image, exiting."<< llendl; throw 0; } // We need to scan the output from hdiutil to find the device node it uses to attach the disk image. // If we don't have this information, we can't detach it later. while(mounter != NULL) { size_t len = fread(temp, 1, sizeof(temp)-1, mounter); temp[len] = 0; mountOutput.append(temp); if(len < sizeof(temp)-1) { // End of file or error. if(pclose(mounter) != 0) { llinfos << "Failed to mount disk image, exiting."<< llendl; throw 0; } mounter = NULL; } } if(!mountOutput.empty()) { const char *s = mountOutput.c_str(); char *prefix = "/dev/"; char *sub = strstr(s, prefix); if(sub != NULL) { sub += strlen(prefix); /* Flawfinder: ignore */ sscanf(sub, "%1023s", deviceNode); /* Flawfinder: ignore */ } } if(deviceNode[0] != 0) { llinfos << "Disk image attached on /dev/" << deviceNode << llendl; } else { llinfos << "Disk image device node not found!" << llendl; } // Get an FSRef to the new application on the disk image FSRef sourceRef; FSRef mountRef; snprintf(temp, sizeof(temp), "%s/mnt", tempDir); llinfos << "Disk image mount point is: " << temp << llendl; err = FSPathMakeRef((UInt8 *)temp, &mountRef, NULL); if(err != noErr) { llinfos << "Couldn't make FSRef to disk image mount point." << llendl; throw 0; } err = findAppBundleOnDiskImage(&mountRef, &sourceRef); if(err != noErr) { llinfos << "Couldn't find application bundle on mounted disk image." << llendl; throw 0; } FSRef asideRef; char aside[MAX_PATH]; /* Flawfinder: ignore */ // this will hold the name of the destination target HFSUniStr255 appNameUniStr; if(replacingTarget) { // Get the name of the target we're replacing err = FSGetCatalogInfo(&targetRef, 0, NULL, &appNameUniStr, NULL, NULL); if(err != noErr) throw 0; // Move aside old version (into work directory) err = FSMoveObject(&targetRef, &tempDirRef, &asideRef); if(err != noErr) throw 0; // Grab the path for later use. err = FSRefMakePath(&asideRef, (UInt8*)aside, sizeof(aside)); } else { // Construct the name of the target based on the product name char appName[MAX_PATH]; /* Flawfinder: ignore */ snprintf(appName, sizeof(appName), "%s.app", gProductName); utf8str_to_HFSUniStr255( &appNameUniStr, appName ); } sendProgress(0, 0, CFSTR("Copying files...")); llinfos << "Starting copy..." << llendl; // Copy the new version from the disk image to the target location. err = FSCopyObject( &sourceRef, &targetParentRef, 0, kFSCatInfoNone, kDupeActionStandard, &appNameUniStr, false, false, NULL, NULL, &targetRef, NULL); // Grab the path for later use. err = FSRefMakePath(&targetRef, (UInt8*)target, sizeof(target)); if(err != noErr) throw 0; llinfos << "Copy complete. Target = " << target << llendl; if(err != noErr) { // Something went wrong during the copy. Attempt to put the old version back and bail. (void)FSDeleteObjects(&targetRef); if(replacingTarget) { (void)FSMoveObject(&asideRef, &targetParentRef, NULL); } throw 0; } else { // The update has succeeded. Clear the cache directory. sendProgress(0, 0, CFSTR("Clearing cache...")); llinfos << "Clearing cache..." << llendl; char mask[LL_MAX_PATH]; /* Flawfinder: ignore */ snprintf(mask, LL_MAX_PATH, "%s*.*", gDirUtilp->getDirDelimiter().c_str()); gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE,""),mask); llinfos << "Clear complete." << llendl; } } catch(...) { if(!gCancelled) if(gFailure == noErr) gFailure = -1; } // Failures from here on out are all non-fatal and not reported. sendProgress(0, 3, CFSTR("Cleaning up...")); // Close disk image file if necessary if(downloadFile != NULL) { llinfos << "Closing download file." << llendl; fclose(downloadFile); downloadFile = NULL; } sendProgress(1, 3); // Unmount image if(deviceNode[0] != 0) { llinfos << "Detaching disk image." << llendl; snprintf(temp, sizeof(temp), "hdiutil detach '%s'", deviceNode); system(temp); /* Flawfinder: ignore */ } sendProgress(2, 3); // Move work directory to the trash if(tempDir[0] != 0) { // chdir("/"); // FSDeleteObjects(tempDirRef); llinfos << "Moving work directory to the trash." << llendl; err = FSMoveObject(&tempDirRef, &trashFolderRef, NULL); // snprintf(temp, sizeof(temp), "rm -rf '%s'", tempDir); // printf("%s\n", temp); // system(temp); } if(!gCancelled && !gFailure && (target[0] != 0)) { llinfos << "Touching application bundle." << llendl; snprintf(temp, sizeof(temp), "touch '%s'", target); system(temp); /* Flawfinder: ignore */ llinfos << "Launching updated application." << llendl; snprintf(temp, sizeof(temp), "open '%s'", target); system(temp); /* Flawfinder: ignore */ } sendDone(); return(NULL); }
LLCheckBoxCtrl::LLCheckBoxCtrl(const LLString& name, const LLRect& rect, const LLString& label, const LLFontGL* font, void (*commit_callback)(LLUICtrl* ctrl, void* userdata), void* callback_user_data, BOOL initial_value, BOOL use_radio_style, const LLString& control_which) : LLUICtrl(name, rect, TRUE, commit_callback, callback_user_data, FOLLOWS_LEFT | FOLLOWS_TOP), mTextEnabledColor( LLUI::sColorsGroup->getColor( "LabelTextColor" ) ), mTextDisabledColor( LLUI::sColorsGroup->getColor( "LabelDisabledColor" ) ), mRadioStyle( use_radio_style ), mInitialValue( initial_value ), mSetValue( initial_value ) { if (font) { mFont = font; } else { mFont = LLFontGL::sSansSerifSmall; } // must be big enough to hold all children setUseBoundingRect(TRUE); mKeyboardFocusOnClick = TRUE; // Label (add a little space to make sure text actually renders) const S32 FUDGE = 10; S32 text_width = mFont->getWidth( label ) + FUDGE; S32 text_height = llround(mFont->getLineHeight()); LLRect label_rect; label_rect.setOriginAndSize( LLCHECKBOXCTRL_HPAD + LLCHECKBOXCTRL_BTN_SIZE + LLCHECKBOXCTRL_SPACING, LLCHECKBOXCTRL_VPAD + 1, // padding to get better alignment text_width + LLCHECKBOXCTRL_HPAD, text_height ); mLabel = new LLTextBox( "CheckboxCtrl Label", label_rect, label.c_str(), mFont ); mLabel->setFollowsLeft(); mLabel->setFollowsBottom(); addChild(mLabel); // Button // Note: button cover the label by extending all the way to the right. LLRect btn_rect; btn_rect.setOriginAndSize( LLCHECKBOXCTRL_HPAD, LLCHECKBOXCTRL_VPAD, LLCHECKBOXCTRL_BTN_SIZE + LLCHECKBOXCTRL_SPACING + text_width + LLCHECKBOXCTRL_HPAD, llmax( text_height, LLCHECKBOXCTRL_BTN_SIZE ) + LLCHECKBOXCTRL_VPAD); LLString active_true_id, active_false_id; LLString inactive_true_id, inactive_false_id; if (mRadioStyle) { active_true_id = "UIImgRadioActiveSelectedUUID"; active_false_id = "UIImgRadioActiveUUID"; inactive_true_id = "UIImgRadioInactiveSelectedUUID"; inactive_false_id = "UIImgRadioInactiveUUID"; mButton = new LLButton( "Radio control button", btn_rect, active_false_id, active_true_id, control_which, &LLCheckBoxCtrl::onButtonPress, this, LLFontGL::sSansSerif ); mButton->setDisabledImages( inactive_false_id, inactive_true_id ); mButton->setHoverGlowStrength(0.35f); } else { active_false_id = "UIImgCheckboxActiveUUID"; active_true_id = "UIImgCheckboxActiveSelectedUUID"; inactive_true_id = "UIImgCheckboxInactiveSelectedUUID"; inactive_false_id = "UIImgCheckboxInactiveUUID"; mButton = new LLButton( "Checkbox control button", btn_rect, active_false_id, active_true_id, control_which, &LLCheckBoxCtrl::onButtonPress, this, LLFontGL::sSansSerif ); mButton->setDisabledImages( inactive_false_id, inactive_true_id ); mButton->setHoverGlowStrength(0.35f); } mButton->setIsToggle(TRUE); mButton->setToggleState( initial_value ); mButton->setFollowsLeft(); mButton->setFollowsBottom(); mButton->setCommitOnReturn(FALSE); addChild(mButton); }
LLSpinCtrl::LLSpinCtrl( const LLString& name, const LLRect& rect, const LLString& label, const LLFontGL* font, void (*commit_callback)(LLUICtrl*, void*), void* callback_user_data, F32 initial_value, F32 min_value, F32 max_value, F32 increment, const LLString& control_name, S32 label_width) : LLUICtrl(name, rect, TRUE, commit_callback, callback_user_data, FOLLOWS_LEFT | FOLLOWS_TOP ), mValue( initial_value ), mInitialValue( initial_value ), mMaxValue( max_value ), mMinValue( min_value ), mIncrement( increment ), mPrecision( 3 ), mLabelBox( NULL ), mTextEnabledColor( LLUI::sColorsGroup->getColor( "LabelTextColor" ) ), mTextDisabledColor( LLUI::sColorsGroup->getColor( "LabelDisabledColor" ) ), mbHasBeenSet( FALSE ) { S32 top = mRect.getHeight(); S32 bottom = top - 2 * SPINCTRL_BTN_HEIGHT; S32 centered_top = top; S32 centered_bottom = bottom; S32 btn_left = 0; // Label if( !label.empty() ) { LLRect label_rect( 0, centered_top, label_width, centered_bottom ); mLabelBox = new LLTextBox( "SpinCtrl Label", label_rect, label.c_str(), font ); addChild(mLabelBox); btn_left += label_rect.mRight + SPINCTRL_SPACING; } S32 btn_right = btn_left + SPINCTRL_BTN_WIDTH; // Spin buttons LLRect up_rect( btn_left, top, btn_right, top - SPINCTRL_BTN_HEIGHT ); LLString out_id = "UIImgBtnSpinUpOutUUID"; LLString in_id = "UIImgBtnSpinUpInUUID"; mUpBtn = new LLButton( "SpinCtrl Up", up_rect, out_id, in_id, "", &LLSpinCtrl::onUpBtn, this, LLFontGL::sSansSerif ); mUpBtn->setFollowsLeft(); mUpBtn->setFollowsBottom(); mUpBtn->setHeldDownCallback( &LLSpinCtrl::onUpBtn ); mUpBtn->setTabStop(FALSE); addChild(mUpBtn); LLRect down_rect( btn_left, top - SPINCTRL_BTN_HEIGHT, btn_right, bottom ); out_id = "UIImgBtnSpinDownOutUUID"; in_id = "UIImgBtnSpinDownInUUID"; mDownBtn = new LLButton( "SpinCtrl Down", down_rect, out_id, in_id, "", &LLSpinCtrl::onDownBtn, this, LLFontGL::sSansSerif ); mDownBtn->setFollowsLeft(); mDownBtn->setFollowsBottom(); mDownBtn->setHeldDownCallback( &LLSpinCtrl::onDownBtn ); mDownBtn->setTabStop(FALSE); addChild(mDownBtn); LLRect editor_rect( btn_right + 1, centered_top, mRect.getWidth(), centered_bottom ); mEditor = new LLLineEditor( "SpinCtrl Editor", editor_rect, "", font, MAX_STRING_LENGTH, &LLSpinCtrl::onEditorCommit, NULL, NULL, this, &LLLineEditor::prevalidateFloat ); mEditor->setFollowsLeft(); mEditor->setFollowsBottom(); mEditor->setFocusReceivedCallback( &LLSpinCtrl::onEditorGainFocus ); //RN: this seems to be a BAD IDEA, as it makes the editor behavior different when it has focus // than when it doesn't. Instead, if you always have to double click to select all the text, // it's easier to understand //mEditor->setSelectAllonFocusReceived(TRUE); mEditor->setIgnoreTab(TRUE); addChild(mEditor); updateEditor(); setSpanChildren( TRUE ); }
// blocking asset fetch which bypasses the VFS // this is a very limited function for use by the simstate loader and other one-offs S32 LLHTTPAssetStorage::getURLToFile(const LLUUID& uuid, LLAssetType::EType asset_type, const LLString &url, const char *filename, progress_callback callback, void *userdata) { // *NOTE: There is no guarantee that the uuid and the asset_type match // - not that it matters. - Doug lldebugs << "LLHTTPAssetStorage::getURLToFile() - " << url << llendl; FILE *fp = LLFile::fopen(filename, "wb"); /*Flawfinder: ignore*/ if (! fp) { llwarns << "Failed to open " << filename << " for writing" << llendl; return LL_ERR_ASSET_REQUEST_FAILED; } // make sure we use the normal curl setup, even though we don't really need a request object LLHTTPAssetRequest req(this, uuid, asset_type, RT_DOWNLOAD, url.c_str(), mCurlMultiHandle); req.mFP = fp; req.setupCurlHandle(); curl_easy_setopt(req.mCurlHandle, CURLOPT_FOLLOWLOCATION, TRUE); curl_easy_setopt(req.mCurlHandle, CURLOPT_WRITEFUNCTION, &curlFileDownCallback); curl_easy_setopt(req.mCurlHandle, CURLOPT_WRITEDATA, req.mCurlHandle); curl_multi_add_handle(mCurlMultiHandle, req.mCurlHandle); llinfos << "Requesting as file " << req.mURLBuffer << llendl; // braindead curl loop int queue_length; CURLMsg *curl_msg; LLTimer timeout; timeout.setTimerExpirySec(GET_URL_TO_FILE_TIMEOUT); bool success = false; S32 xfer_result = 0; do { curl_multi_perform(mCurlMultiHandle, &queue_length); curl_msg = curl_multi_info_read(mCurlMultiHandle, &queue_length); if (callback) { callback(userdata); } if ( curl_msg && (CURLMSG_DONE == curl_msg->msg) ) { success = true; } else if (timeout.hasExpired()) { llwarns << "Request for " << url << " has timed out." << llendl; success = false; xfer_result = LL_ERR_ASSET_REQUEST_FAILED; break; } } while (!success); if (success) { long curl_result = 0; curl_easy_getinfo(curl_msg->easy_handle, CURLINFO_HTTP_CODE, &curl_result); if (curl_result == HTTP_OK && curl_msg->data.result == CURLE_OK) { S32 size = ftell(req.mFP); if (size > 0) { // everything seems to be in order llinfos << "Success downloading " << req.mURLBuffer << " to file, size " << size << llendl; } else { llwarns << "Found " << req.mURLBuffer << " to be zero size" << llendl; xfer_result = LL_ERR_ASSET_REQUEST_FAILED; } } else { xfer_result = curl_result == HTTP_MISSING ? LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE : LL_ERR_ASSET_REQUEST_FAILED; llinfos << "Failure downloading " << req.mURLBuffer << " with result " << curl_easy_strerror(curl_msg->data.result) << ", http result " << curl_result << llendl; } } fclose(fp); if (xfer_result) { LLFile::remove(filename); } return xfer_result; }
bool LLPreviewNotecard::saveIfNeeded(LLInventoryItem* copyitem) { if(!gAssetStorage) { llwarns << "Not connected to an asset storage system." << llendl; return false; } LLViewerTextEditor* editor = LLViewerUICtrlFactory::getViewerTextEditorByName(this, "Notecard Editor"); if(!editor->isPristine()) { // We need to update the asset information LLTransactionID tid; LLAssetID asset_id; tid.generate(); asset_id = tid.makeAssetID(gAgent.getSecureSessionID()); LLVFile file(gVFS, asset_id, LLAssetType::AT_NOTECARD, LLVFile::APPEND); LLString buffer; if (!editor->exportBuffer(buffer)) { return false; } editor->makePristine(); S32 size = buffer.length() + 1; file.setMaxSize(size); file.write((U8*)buffer.c_str(), size); const LLInventoryItem* item = getItem(); // save it out to database if (item) { std::string agent_url = gAgent.getRegion()->getCapability("UpdateNotecardAgentInventory"); std::string task_url = gAgent.getRegion()->getCapability("UpdateNotecardTaskInventory"); if (mObjectUUID.isNull() && !agent_url.empty()) { // Saving into agent inventory mAssetStatus = PREVIEW_ASSET_LOADING; setEnabled(FALSE); LLSD body; body["item_id"] = mItemUUID; llinfos << "Saving notecard " << mItemUUID << " into agent inventory via " << agent_url << llendl; LLHTTPClient::post(agent_url, body, new LLUpdateAgentInventoryResponder(body, asset_id, LLAssetType::AT_NOTECARD)); } else if (!mObjectUUID.isNull() && !task_url.empty()) { // Saving into task inventory mAssetStatus = PREVIEW_ASSET_LOADING; setEnabled(FALSE); LLSD body; body["task_id"] = mObjectUUID; body["item_id"] = mItemUUID; llinfos << "Saving notecard " << mItemUUID << " into task " << mObjectUUID << " via " << task_url << llendl; LLHTTPClient::post(task_url, body, new LLUpdateTaskInventoryResponder(body, asset_id, LLAssetType::AT_NOTECARD)); } else if (gAssetStorage) { LLSaveNotecardInfo* info = new LLSaveNotecardInfo(this, mItemUUID, mObjectUUID, tid, copyitem); gAssetStorage->storeAssetData(tid, LLAssetType::AT_NOTECARD, &onSaveComplete, (void*)info, FALSE); } } } return true; }
OSStatus DisplayReleaseNotes(void) { OSStatus err; IBNibRef nib = NULL; WindowRef window = NULL; err = CreateNibReference(CFSTR("SecondLife"), &nib); if(err == noErr) { CreateWindowFromNib(nib, CFSTR("Release Notes"), &window); } if(err == noErr) { // Get the text view control HIViewRef textView; ControlID id; id.signature = 'text'; id.id = 0; LLString releaseNotesText; _read_file_into_string(releaseNotesText, "releasenotes.txt"); // Flawfinder: ignore err = HIViewFindByID(HIViewGetRoot(window), id, &textView); if(err == noErr) { // Convert from the encoding used in the release notes. CFStringRef str = CFStringCreateWithBytes( NULL, (const UInt8*)releaseNotesText.c_str(), releaseNotesText.size(), kCFStringEncodingWindowsLatin1, // This matches the way the Windows version displays the release notes. FALSE); if(str != NULL) { int size = CFStringGetLength(str); if(size > 0) { UniChar *chars = new UniChar[size + 1]; CFStringGetCharacters(str, CFRangeMake(0, size), chars); err = TXNSetData(HITextViewGetTXNObject(textView), kTXNUnicodeTextData, chars, size * sizeof(UniChar), kTXNStartOffset, kTXNStartOffset); delete[] chars; } CFRelease(str); } else { // Creating the string failed. Probably an encoding problem. Display SOMETHING... err = TXNSetData(HITextViewGetTXNObject(textView), kTXNTextData, releaseNotesText.c_str(), releaseNotesText.size(), kTXNStartOffset, kTXNStartOffset); } } // Set the selection to the beginning of the text and scroll it into view. if(err == noErr) { err = TXNSetSelection(HITextViewGetTXNObject(textView), kTXNStartOffset, kTXNStartOffset); } if(err == noErr) { // This function returns void. TXNShowSelection(HITextViewGetTXNObject(textView), false); } } if(err == noErr) { ShowWindow(window); } if(err == noErr) { // Set up an event handler for the window. EventHandlerRef handler = NULL; EventTypeSpec handlerEvents[] = { { kEventClassCommand, kEventCommandProcess } }; InstallWindowEventHandler( window, NewEventHandlerUPP(simpleDialogHandler), GetEventTypeCount (handlerEvents), handlerEvents, (void*)window, &handler); } if(err == noErr) { RunAppModalLoopForWindow(window); } if(window != NULL) { DisposeWindow(window); } if(nib != NULL) { DisposeNibReference(nib); } return(err); }