// static
void LLFloaterCompileQueue::onSaveBytecodeComplete(const LLUUID& asset_id, void* user_data, S32 status, LLExtStat ext_status) // StoreAssetData callback (fixed)
{
	llinfos << "LLFloaterCompileQueue::onSaveBytecodeComplete()" << llendl;
	LLCompileQueueData* data = (LLCompileQueueData*)user_data;
	LLFloaterCompileQueue* queue = LLFloaterReg::findTypedInstance<LLFloaterCompileQueue>("compile_queue", data->mQueueID);
	if(queue && (0 == status) && data)
	{
		queue->saveItemByItemID(data->mItemId);
		queue->removeItemByItemID(data->mItemId);
	}
	else
	{
		llwarns << "Unable to save bytecode for script." << llendl;
		LLSD args;
		args["REASON"] = std::string(LLAssetStorage::getErrorString(status));
		LLNotificationsUtil::add("CompileQueueSaveBytecode", args);
	}
	delete data;
	data = NULL;
}
// static
void LLFloaterCompileQueue::onSaveBytecodeComplete(const LLUUID& asset_id, void* user_data, S32 status, LLExtStat ext_status) // StoreAssetData callback (fixed)
{
	llinfos << "LLFloaterCompileQueue::onSaveBytecodeComplete()" << llendl;
	LLCompileQueueData* data = (LLCompileQueueData*)user_data;
	LLFloaterCompileQueue* queue = static_cast<LLFloaterCompileQueue*> 
				(LLFloaterScriptQueue::findInstance(data->mQueueID));
	if(queue && (0 == status) && data)
	{
		queue->saveItemByItemID(data->mItemId);
		queue->removeItemByItemID(data->mItemId);
	}
	else
	{
		llwarns << "Unable to save bytecode for script." << llendl;
		LLStringUtil::format_map_t args;
		args["[REASON]"] = std::string(LLAssetStorage::getErrorString(status));
		gViewerWindow->alertXml("CompileQueueSaveBytecode", args);
	}
	delete data;
	data = NULL;
}
//virtual 
void LLUpdateTaskInventoryResponder::uploadComplete(const LLSD& content)
{
	llinfos << "LLUpdateTaskInventoryResponder::result from capabilities" << llendl;
	LLUUID item_id = mPostData["item_id"];
	LLUUID task_id = mPostData["task_id"];

	dialog_refresh_all();
	
	switch(mAssetType)
	{
		case LLAssetType::AT_NOTECARD:
			{
				// Update the UI with the new asset.
				LLPreviewNotecard* nc;
				nc = (LLPreviewNotecard*)LLPreview::find(item_id);
				if(nc)
				{
					// *HACK: we have to delete the asset in the VFS so
					// that the viewer will redownload it. This is only
					// really necessary if the asset had to be modified by
					// the uploader, so this can be optimized away in some
					// cases. A better design is to have a new uuid if the
					// script actually changed the asset.
					if(nc->hasEmbeddedInventory())
					{
						gVFS->removeFile(
							content["new_asset"].asUUID(),
							LLAssetType::AT_NOTECARD);
					}

					nc->setAssetId(content["new_asset"].asUUID());
					nc->refreshFromInventory();
				}
			}
			break;
		case LLAssetType::AT_LSL_TEXT:
			{
				if(mQueueId.notNull())
				{
					LLFloaterCompileQueue* queue = 
						(LLFloaterCompileQueue*) LLFloaterScriptQueue::findInstance(mQueueId);
					if(NULL != queue)
					{
						queue->removeItemByItemID(item_id);
					}
				}
				else
				{
					LLLiveLSLEditor* preview = LLLiveLSLEditor::find(item_id, task_id);
					if (preview)
					{
						// Bytecode save completed
						if (content["compiled"])
						{
							preview->callbackLSLCompileSucceeded(
								task_id,
								item_id,
								mPostData["is_script_running"]);
						}
						else
						{
							preview->callbackLSLCompileFailed(content["errors"]);
						}
					}
				}
			}
			break;
	default:
		break;
	}
}
// This is the callback for when each script arrives
// static
void LLFloaterCompileQueue::scriptArrived(LLVFS *vfs, const LLUUID& asset_id,
										  LLAssetType::EType type,
										  void* user_data, S32 status, LLExtStat ext_status)
{
	llinfos << "LLFloaterCompileQueue::scriptArrived()" << llendl;
	LLScriptQueueData* data = (LLScriptQueueData*)user_data;
	if(!data) return;
	LLFloaterCompileQueue* queue = static_cast<LLFloaterCompileQueue*> 
				(LLFloaterScriptQueue::findInstance(data->mQueueID));
	std::string buffer;
	if(queue && (0 == status))
	{
		//llinfos << "ITEM NAME 3: " << data->mScriptName << llendl;

		// Dump this into a file on the local disk so we can compile it.
		std::string filename;
		LLVFile file(vfs, asset_id, type);
		std::string uuid_str;
		asset_id.toString(uuid_str);
		filename = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,uuid_str) + llformat(".%s",LLAssetType::lookup(type));
		
		const bool is_running = true;
		LLViewerObject* object = gObjectList.findObject(data->mTaskId);
		if (object)
		{
			std::string url = object->getRegion()->getCapability("UpdateScriptTask");
			if(!url.empty())
			{
				// Read script source in to buffer.
				U32 script_size = file.getSize();
				U8* script_data = new U8[script_size];
				file.read(script_data, script_size);

				queue->mUploadQueue->queue(filename, data->mTaskId, 
				data->mItemId, is_running, queue->mMono, queue->getID(),
				script_data, script_size, data->mScriptName);
			}
			else
			{
				// It's now in the file, now compile it.
				buffer = std::string("Downloaded, now compiling: ") + data->mScriptName; // *TODO: Translate

				// Write script to local file for compilation.
				LLFILE *fp = LLFile::fopen(filename, "wb");	 /*Flawfinder: ignore*/
				if (fp)
				{
					const S32 buf_size = 65536;
					U8 copy_buf[buf_size];
					
					while (file.read(copy_buf, buf_size)) 	 /*Flawfinder: ignore*/
					{
						if (fwrite(copy_buf, file.getLastBytesRead(), 1, fp) < 1)
						{
							// return a bad file error if we can't write the whole thing
							status = LL_ERR_CANNOT_OPEN_FILE;
						}
					}

					fclose(fp);
				}
				else
				{
					llwarns << "Unable to find object to compile" << llendl; // why an error? KL
				}

				// TODO: babbage: No compile if no cap.
				queue->compile(filename, data->mItemId);
					
				// Delete it after we're done compiling?
				LLFile::remove(filename);
			}
		}
	}
	else
	{
		LLViewerStats::getInstance()->incStat( LLViewerStats::ST_DOWNLOAD_FAILED );

		if( LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status )
		{
			LLChat chat(std::string("Script not found on server.")); // *TODO: Translate
			LLFloaterChat::addChat(chat);
			buffer = std::string("Problem downloading: ") + data->mScriptName; // *TODO: Translate
		}
		else if (LL_ERR_INSUFFICIENT_PERMISSIONS == status)
		{
			LLChat chat(std::string("Insufficient permissions to download a script.")); // *TODO: Translate
			LLFloaterChat::addChat(chat);
			buffer = std::string("Insufficient permissions for: ") + data->mScriptName; // *TODO: Translate
		}
		else
		{
			buffer = std::string("Unknown failure to download ") + data->mScriptName; // *TODO: Translate
		}

		llwarns << "Problem downloading script asset." << llendl;
		if(queue) queue->removeItemByItemID(data->mItemId);
	}
	if(queue && (buffer.size() > 0)) 
	{
		LLScrollListCtrl* list = queue->getChild<LLScrollListCtrl>("queue output");
		list->addCommentText(buffer);
	}
	delete data;
}
Beispiel #5
0
// This is the callback for when each script arrives
// static
void LLFloaterCompileQueue::scriptArrived(LLVFS *vfs, const LLUUID& asset_id,
										  LLAssetType::EType type,
										  void* user_data, S32 status, LLExtStat ext_status)
{
	LL_INFOS() << "LLFloaterCompileQueue::scriptArrived()" << LL_ENDL;
	LLScriptQueueData* data = (LLScriptQueueData*)user_data;
	if(!data) return;
	LLFloaterCompileQueue* queue = static_cast<LLFloaterCompileQueue*> (LLFloaterScriptQueue::findInstance(data->mQueueID));

	std::string buffer;
	if(queue && (0 == status))
	{
		//LL_INFOS() << "ITEM NAME 3: " << data->mScriptName << LL_ENDL;

		// Dump this into a file on the local disk so we can compile it.
		std::string filename;
		LLVFile file(vfs, asset_id, type);
		std::string uuid_str;
		asset_id.toString(uuid_str);
		filename = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,uuid_str) + llformat(".%s",LLAssetType::lookup(type));
		
		const bool is_running = true;
		LLViewerObject* object = gObjectList.findObject(data->mTaskId);
		if (object)
		{
			std::string url = object->getRegion()->getCapability("UpdateScriptTask");
			if(!url.empty())
			{
				// Read script source in to buffer.
				U32 script_size = file.getSize();
				char* script_data = new char[script_size];
				file.read((U8*)script_data, script_size);

				queue->mUploadQueue->queue(filename, data->mTaskId, 
				data->mItemId, is_running, queue->mMono, queue->getID(),
				script_data, script_size, data->mScriptName);
			}
			else
			{
				std::string text = LLTrans::getString("CompileQueueProblemUploading");
				LLChat chat(text);
				LLFloaterChat::addChat(chat);
				buffer = text + LLTrans::getString(":") + " " + data->mScriptName;
				LL_WARNS() << "Problem uploading script asset." << LL_ENDL;
				if(queue) queue->removeItemByItemID(data->mItemId);
			}
#if 0 //Client side compiling disabled.
			else
			{
				// It's now in the file, now compile it.
				buffer = LLTrans::getString("CompileQueueDownloadedCompiling") + (": ") + data->mScriptName;

				// Write script to local file for compilation.
				LLFILE *fp = LLFile::fopen(filename, "wb");	 /*Flawfinder: ignore*/
				if (fp)
				{
					const S32 buf_size = 65536;
					U8 copy_buf[buf_size];
					
					while (file.read(copy_buf, buf_size)) 	 /*Flawfinder: ignore*/
					{
						if (fwrite(copy_buf, file.getLastBytesRead(), 1, fp) < 1)
						{
							// return a bad file error if we can't write the whole thing
							status = LL_ERR_CANNOT_OPEN_FILE;
						}
					}

					fclose(fp);
				}
				else
				{
					LL_ERRS() << "Unable to find object to compile" << LL_ENDL;
				}

				// TODO: babbage: No compile if no cap.
				queue->compile(filename, data->mItemId);
					
				// Delete it after we're done compiling?
				LLFile::remove(filename);
			}
#endif
		}