diff options
Diffstat (limited to 'indra/newview/llpreviewscript.cpp')
-rw-r--r--[-rwxr-xr-x] | indra/newview/llpreviewscript.cpp | 672 |
1 files changed, 147 insertions, 525 deletions
diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp index 67832c5994..5b1b356597 100755..100644 --- a/indra/newview/llpreviewscript.cpp +++ b/indra/newview/llpreviewscript.cpp @@ -29,7 +29,6 @@ #include "llpreviewscript.h" #include "llassetstorage.h" -#include "llassetuploadresponders.h" #include "llbutton.h" #include "llcheckboxctrl.h" #include "llcombobox.h" @@ -53,7 +52,6 @@ #include "llscrolllistcell.h" #include "llsdserialize.h" #include "llslider.h" -#include "lscript_rt_interface.h" #include "lltooldraganddrop.h" #include "llvfile.h" @@ -88,7 +86,7 @@ #include "llfloatergotoline.h" #include "llexperiencecache.h" #include "llfloaterexperienceprofile.h" -#include "llexperienceassociationresponder.h" +#include "llviewerassetupload.h" const std::string HELLO_LSL = "default\n" @@ -118,26 +116,6 @@ static bool have_script_upload_cap(LLUUID& object_id) return object && (! object->getRegion()->getCapability("UpdateScriptTask").empty()); } - -class ExperienceResponder : public LLHTTPClient::Responder -{ -public: - ExperienceResponder(const LLHandle<LLLiveLSLEditor>& parent):mParent(parent) - { - } - - LLHandle<LLLiveLSLEditor> mParent; - - /*virtual*/ void httpSuccess() - { - LLLiveLSLEditor* parent = mParent.get(); - if(!parent) - return; - - parent->setExperienceIds(getContent()["experience_ids"]); - } -}; - /// --------------------------------------------------------------------------- /// LLLiveLSLFile /// --------------------------------------------------------------------------- @@ -1346,7 +1324,7 @@ void LLLiveLSLEditor::buildExperienceList() position = ADD_TOP; } - const LLSD& experience = LLExperienceCache::get(id); + const LLSD& experience = LLExperienceCache::instance().get(id); if(experience.isUndefined()) { mExperiences->add(getString("loading"), id, position); @@ -1365,7 +1343,7 @@ void LLLiveLSLEditor::buildExperienceList() if(!foundAssociated ) { - const LLSD& experience = LLExperienceCache::get(associated); + const LLSD& experience = LLExperienceCache::instance().get(associated); if(experience.isDefined()) { std::string experience_name_string = experience[LLExperienceCache::NAME].asString(); @@ -1386,7 +1364,7 @@ void LLLiveLSLEditor::buildExperienceList() if(last.notNull()) { mExperiences->setEnabled(FALSE); - LLExperienceCache::get(last, boost::bind(&LLLiveLSLEditor::buildExperienceList, this)); + LLExperienceCache::instance().get(last, boost::bind(&LLLiveLSLEditor::buildExperienceList, this)); } else { @@ -1418,11 +1396,23 @@ void LLLiveLSLEditor::requestExperiences() std::string lookup_url=region->getCapability("GetCreatorExperiences"); if(!lookup_url.empty()) { - LLHTTPClient::get(lookup_url, new ExperienceResponder(getDerivedHandle<LLLiveLSLEditor>())); + LLCoreHttpUtil::HttpCoroutineAdapter::completionCallback_t success = + boost::bind(&LLLiveLSLEditor::receiveExperienceIds, _1, getDerivedHandle<LLLiveLSLEditor>()); + + LLCoreHttpUtil::HttpCoroutineAdapter::callbackHttpGet(lookup_url, success); } } } +/*static*/ +void LLLiveLSLEditor::receiveExperienceIds(LLSD result, LLHandle<LLLiveLSLEditor> hparent) +{ + LLLiveLSLEditor* parent = hparent.get(); + if (!parent) + return; + + parent->setExperienceIds(result["experience_ids"]); +} /// --------------------------------------------------------------------------- @@ -1573,7 +1563,7 @@ void LLPreviewLSL::loadAsset() if (gAgent.isGodlike() || (is_copyable && (is_modifiable || is_library))) { LLUUID* new_uuid = new LLUUID(mItemUUID); - gAssetStorage->getInvItemAsset(LLHost::invalid, + gAssetStorage->getInvItemAsset(LLHost(), gAgent.getID(), gAgent.getSessionID(), item->getPermissions().getOwner(), @@ -1643,234 +1633,61 @@ void LLPreviewLSL::onSave(void* userdata, BOOL close_after_save) self->saveIfNeeded(); } +/*static*/ +void LLPreviewLSL::finishedLSLUpload(LLUUID itemId, LLSD response) +{ + // Find our window and close it if requested. + LLPreviewLSL* preview = LLFloaterReg::findTypedInstance<LLPreviewLSL>("preview_script", LLSD(itemId)); + if (preview) + { + // Bytecode save completed + if (response["compiled"]) + { + preview->callbackLSLCompileSucceeded(); + } + else + { + preview->callbackLSLCompileFailed(response["errors"]); + } + } +} + // Save needs to compile the text in the buffer. If the compile // succeeds, then save both assets out to the database. If the compile // fails, go ahead and save the text anyway. void LLPreviewLSL::saveIfNeeded(bool sync /*= true*/) { - // LL_INFOS() << "LLPreviewLSL::saveIfNeeded()" << LL_ENDL; - if(!mScriptEd->hasChanged()) - { - return; - } - - mPendingUploads = 0; - mScriptEd->mErrorList->deleteAllItems(); - mScriptEd->mEditor->makePristine(); - - // save off asset into file - LLTransactionID tid; - tid.generate(); - LLAssetID asset_id = tid.makeAssetID(gAgent.getSecureSessionID()); - std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,asset_id.asString()); - std::string filename = filepath + ".lsl"; - - mScriptEd->writeToFile(filename); - - if (sync) - { - mScriptEd->sync(); - } - - const LLInventoryItem *inv_item = getItem(); - // save it out to asset server - std::string url = gAgent.getRegion()->getCapability("UpdateScriptAgent"); - if(inv_item) - { - getWindow()->incBusyCount(); - mPendingUploads++; - if (!url.empty()) - { - uploadAssetViaCaps(url, filename, mItemUUID); - } - else if (gAssetStorage) - { - uploadAssetLegacy(filename, mItemUUID, tid); - } - } -} - -void LLPreviewLSL::uploadAssetViaCaps(const std::string& url, - const std::string& filename, - const LLUUID& item_id) -{ - LL_INFOS() << "Update Agent Inventory via capability" << LL_ENDL; - LLSD body; - body["item_id"] = item_id; - body["target"] = "lsl2"; - LLHTTPClient::post(url, body, new LLUpdateAgentInventoryResponder(body, filename, LLAssetType::AT_LSL_TEXT)); -} - -void LLPreviewLSL::uploadAssetLegacy(const std::string& filename, - const LLUUID& item_id, - const LLTransactionID& tid) -{ - LLLineEditor* descEditor = getChild<LLLineEditor>("desc"); - LLScriptSaveInfo* info = new LLScriptSaveInfo(item_id, - descEditor->getText(), - tid); - gAssetStorage->storeAssetData(filename, tid, - LLAssetType::AT_LSL_TEXT, - &LLPreviewLSL::onSaveComplete, - info); - - LLAssetID asset_id = tid.makeAssetID(gAgent.getSecureSessionID()); - std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,asset_id.asString()); - std::string dst_filename = llformat("%s.lso", filepath.c_str()); - std::string err_filename = llformat("%s.out", filepath.c_str()); - - const BOOL compile_to_mono = FALSE; - if(!lscript_compile(filename.c_str(), - dst_filename.c_str(), - err_filename.c_str(), - compile_to_mono, - asset_id.asString().c_str(), - gAgent.isGodlike())) - { - LL_INFOS() << "Compile failed!" << LL_ENDL; - //char command[256]; - //sprintf(command, "type %s\n", err_filename.c_str()); - //system(command); - - // load the error file into the error scrolllist - LLFILE* fp = LLFile::fopen(err_filename, "r"); - if(fp) - { - char buffer[MAX_STRING]; /*Flawfinder: ignore*/ - std::string line; - while(!feof(fp)) - { - if (fgets(buffer, MAX_STRING, fp) == NULL) - { - buffer[0] = '\0'; - } - if(feof(fp)) - { - break; - } - else - { - line.assign(buffer); - LLStringUtil::stripNonprintable(line); + if (!mScriptEd->hasChanged()) + { + return; + } - LLSD row; - row["columns"][0]["value"] = line; - row["columns"][0]["font"] = "OCRA"; - mScriptEd->mErrorList->addElement(row); - } - } - fclose(fp); - mScriptEd->selectFirstError(); - } - } - else - { - LL_INFOS() << "Compile worked!" << LL_ENDL; - if(gAssetStorage) - { - getWindow()->incBusyCount(); - mPendingUploads++; - LLUUID* this_uuid = new LLUUID(mItemUUID); - gAssetStorage->storeAssetData(dst_filename, - tid, - LLAssetType::AT_LSL_BYTECODE, - &LLPreviewLSL::onSaveBytecodeComplete, - (void**)this_uuid); - } - } + mPendingUploads = 0; + mScriptEd->mErrorList->deleteAllItems(); + mScriptEd->mEditor->makePristine(); - // get rid of any temp files left lying around - LLFile::remove(filename); - LLFile::remove(err_filename); - LLFile::remove(dst_filename); -} + if (sync) + { + mScriptEd->sync(); + } + const LLInventoryItem *inv_item = getItem(); + // save it out to asset server + std::string url = gAgent.getRegion()->getCapability("UpdateScriptAgent"); + if(inv_item) + { + getWindow()->incBusyCount(); + mPendingUploads++; + if (!url.empty()) + { + std::string buffer(mScriptEd->mEditor->getText()); + LLBufferedAssetUploadInfo::invnUploadFinish_f proc = boost::bind(&LLPreviewLSL::finishedLSLUpload, _1, _4); -// static -void LLPreviewLSL::onSaveComplete(const LLUUID& asset_uuid, void* user_data, S32 status, LLExtStat ext_status) // StoreAssetData callback (fixed) -{ - LLScriptSaveInfo* info = reinterpret_cast<LLScriptSaveInfo*>(user_data); - if(0 == status) - { - if (info) - { - const LLViewerInventoryItem* item; - item = (const LLViewerInventoryItem*)gInventory.getItem(info->mItemUUID); - if(item) - { - LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item); - new_item->setAssetUUID(asset_uuid); - new_item->setTransactionID(info->mTransactionID); - new_item->updateServer(FALSE); - gInventory.updateItem(new_item); - gInventory.notifyObservers(); - } - else - { - LL_WARNS() << "Inventory item for script " << info->mItemUUID - << " is no longer in agent inventory." << LL_ENDL; - } + LLResourceUploadInfo::ptr_t uploadInfo(new LLScriptAssetUpload(mItemUUID, buffer, proc)); - // Find our window and close it if requested. - LLPreviewLSL* self = LLFloaterReg::findTypedInstance<LLPreviewLSL>("preview_script", info->mItemUUID); - if (self) - { - getWindow()->decBusyCount(); - self->mPendingUploads--; - if (self->mPendingUploads <= 0 - && self->mCloseAfterSave) - { - self->closeFloater(); - } - } - } - } - else - { - LL_WARNS() << "Problem saving script: " << status << LL_ENDL; - LLSD args; - args["REASON"] = std::string(LLAssetStorage::getErrorString(status)); - LLNotificationsUtil::add("SaveScriptFailReason", args); - } - delete info; -} - -// static -void LLPreviewLSL::onSaveBytecodeComplete(const LLUUID& asset_uuid, void* user_data, S32 status, LLExtStat ext_status) // StoreAssetData callback (fixed) -{ - LLUUID* instance_uuid = (LLUUID*)user_data; - LLPreviewLSL* self = NULL; - if(instance_uuid) - { - self = LLFloaterReg::findTypedInstance<LLPreviewLSL>("preview_script", *instance_uuid); - } - if (0 == status) - { - if (self) - { - LLSD row; - row["columns"][0]["value"] = "Compile successful!"; - row["columns"][0]["font"] = "SANSSERIF_SMALL"; - self->mScriptEd->mErrorList->addElement(row); - - // Find our window and close it if requested. - self->getWindow()->decBusyCount(); - self->mPendingUploads--; - if (self->mPendingUploads <= 0 - && self->mCloseAfterSave) - { - self->closeFloater(); - } - } - } - else - { - LL_WARNS() << "Problem saving LSL Bytecode (Preview)" << LL_ENDL; - LLSD args; - args["REASON"] = std::string(LLAssetStorage::getErrorString(status)); - LLNotificationsUtil::add("SaveBytecodeFailReason", args); - } - delete instance_uuid; + LLViewerAssetUpload::EnqueueInventoryUpload(url, uploadInfo); + } + } } // static @@ -1961,7 +1778,8 @@ LLLiveLSLEditor::LLLiveLSLEditor(const LLSD& key) : mCloseAfterSave(FALSE), mPendingUploads(0), mIsModifiable(FALSE), - mIsNew(false) + mIsNew(false), + mIsSaving(FALSE) { mFactoryMap["script ed panel"] = LLCallbackMap(LLLiveLSLEditor::createScriptEdPanel, this); } @@ -2002,6 +1820,8 @@ void LLLiveLSLEditor::callbackLSLCompileSucceeded(const LLUUID& task_id, LL_DEBUGS() << "LSL Bytecode saved" << LL_ENDL; mScriptEd->mErrorList->setCommentText(LLTrans::getString("CompileSuccessful")); mScriptEd->mErrorList->setCommentText(LLTrans::getString("SaveComplete")); + getChild<LLCheckBoxCtrl>("running")->set(is_script_running); + mIsSaving = FALSE; closeIfNeeded(); } @@ -2022,6 +1842,7 @@ void LLLiveLSLEditor::callbackLSLCompileFailed(const LLSD& compile_errors) mScriptEd->mErrorList->addElement(row); } mScriptEd->selectFirstError(); + mIsSaving = FALSE; closeIfNeeded(); } @@ -2037,8 +1858,9 @@ void LLLiveLSLEditor::loadAsset() if(item) { - ExperienceAssociationResponder::fetchAssociatedExperience(item->getParentUUID(), item->getUUID(), boost::bind(&LLLiveLSLEditor::setAssociatedExperience, getDerivedHandle<LLLiveLSLEditor>(), _1)); - + LLExperienceCache::instance().fetchAssociatedExperience(item->getParentUUID(), item->getUUID(), + boost::bind(&LLLiveLSLEditor::setAssociatedExperience, getDerivedHandle<LLLiveLSLEditor>(), _1)); + bool isGodlike = gAgent.isGodlike(); bool copyManipulate = gAgent.allowOperation(PERM_COPY, item->getPermissions(), GP_OBJECT_MANIPULATE); mIsModifiable = gAgent.allowOperation(PERM_MODIFY, item->getPermissions(), GP_OBJECT_MANIPULATE); @@ -2249,24 +2071,7 @@ void LLLiveLSLEditor::draw() if(object->permAnyOwner()) { runningCheckbox->setLabel(getString("script_running")); - runningCheckbox->setEnabled(TRUE); - - if(object->permAnyOwner()) - { - runningCheckbox->setLabel(getString("script_running")); - runningCheckbox->setEnabled(TRUE); - } - else - { - runningCheckbox->setLabel(getString("public_objects_can_not_run")); - runningCheckbox->setEnabled(FALSE); - // *FIX: Set it to false so that the ui is correct for - // a box that is released to public. It could be - // incorrect after a release/claim cycle, but will be - // correct after clicking on it. - runningCheckbox->set(FALSE); - mMonoCheckbox->set(FALSE); - } + runningCheckbox->setEnabled(!mIsSaving); } else { @@ -2278,9 +2083,7 @@ void LLLiveLSLEditor::draw() // incorrect after a release/claim cycle, but will be // correct after clicking on it. runningCheckbox->set(FALSE); - mMonoCheckbox->setEnabled(FALSE); - // object may have fallen out of range. - mHaveRunningInfo = FALSE; + mMonoCheckbox->set(FALSE); } } else if(!object) @@ -2289,6 +2092,7 @@ void LLLiveLSLEditor::draw() // Really ought to put in main window. setTitle(LLTrans::getString("ObjectOutOfRange")); runningCheckbox->setEnabled(FALSE); + mMonoCheckbox->setEnabled(FALSE); // object may have fallen out of range. mHaveRunningInfo = FALSE; } @@ -2323,6 +2127,33 @@ LLLiveLSLSaveData::LLLiveLSLSaveData(const LLUUID& id, mItem = new LLViewerInventoryItem(item); } + +/*static*/ +void LLLiveLSLEditor::finishLSLUpload(LLUUID itemId, LLUUID taskId, LLUUID newAssetId, LLSD response, bool isRunning) +{ + LLSD floater_key; + floater_key["taskid"] = taskId; + floater_key["itemid"] = itemId; + + LLLiveLSLEditor* preview = LLFloaterReg::findTypedInstance<LLLiveLSLEditor>("preview_scriptedit", floater_key); + if (preview) + { + preview->mItem->setAssetUUID(newAssetId); + + // Bytecode save completed + if (response["compiled"]) + { + preview->callbackLSLCompileSucceeded(taskId, itemId, isRunning); + } + else + { + preview->callbackLSLCompileFailed(response["errors"]); + } + } + +} + + // virtual void LLLiveLSLEditor::saveIfNeeded(bool sync /*= true*/) { @@ -2333,7 +2164,7 @@ void LLLiveLSLEditor::saveIfNeeded(bool sync /*= true*/) return; } - if(mItem.isNull() || !mItem->isFinished()) + if (mItem.isNull() || !mItem->isFinished()) { // $NOTE: While the error message may not be exactly correct, // it's pretty close. @@ -2341,260 +2172,51 @@ void LLLiveLSLEditor::saveIfNeeded(bool sync /*= true*/) return; } - // get the latest info about it. We used to be losing the script - // name on save, because the viewer object version of the item, - // and the editor version would get out of synch. Here's a good - // place to synch them back up. - LLInventoryItem* inv_item = dynamic_cast<LLInventoryItem*>(object->getInventoryObject(mItemUUID)); - if(inv_item) - { - mItem->copyItem(inv_item); - } - - // Don't need to save if we're pristine - if(!mScriptEd->hasChanged()) - { - return; - } - - mPendingUploads = 0; - - // save the script - mScriptEd->enableSave(FALSE); - mScriptEd->mEditor->makePristine(); - mScriptEd->mErrorList->deleteAllItems(); - - // set up the save on the local machine. - mScriptEd->mEditor->makePristine(); - LLTransactionID tid; - tid.generate(); - LLAssetID asset_id = tid.makeAssetID(gAgent.getSecureSessionID()); - std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,asset_id.asString()); - std::string filename = llformat("%s.lsl", filepath.c_str()); - - mItem->setAssetUUID(asset_id); - mItem->setTransactionID(tid); - - mScriptEd->writeToFile(filename); - - if (sync) - { - mScriptEd->sync(); - } - - // save it out to asset server - std::string url = object->getRegion()->getCapability("UpdateScriptTask"); - getWindow()->incBusyCount(); - mPendingUploads++; - BOOL is_running = getChild<LLCheckBoxCtrl>( "running")->get(); - if (!url.empty()) - { - uploadAssetViaCaps(url, filename, mObjectUUID, mItemUUID, is_running, mScriptEd->getAssociatedExperience()); - } - else if (gAssetStorage) - { - uploadAssetLegacy(filename, object, tid, is_running); - } -} - -void LLLiveLSLEditor::uploadAssetViaCaps(const std::string& url, - const std::string& filename, - const LLUUID& task_id, - const LLUUID& item_id, - BOOL is_running, - const LLUUID& experience_public_id ) -{ - LL_INFOS() << "Update Task Inventory via capability " << url << LL_ENDL; - LLSD body; - body["task_id"] = task_id; - body["item_id"] = item_id; - body["is_script_running"] = is_running; - body["target"] = monoChecked() ? "mono" : "lsl2"; - body["experience"] = experience_public_id; - LLHTTPClient::post(url, body, - new LLUpdateTaskInventoryResponder(body, filename, LLAssetType::AT_LSL_TEXT)); -} - -void LLLiveLSLEditor::uploadAssetLegacy(const std::string& filename, - LLViewerObject* object, - const LLTransactionID& tid, - BOOL is_running) -{ - LLLiveLSLSaveData* data = new LLLiveLSLSaveData(mObjectUUID, - mItem, - is_running); - gAssetStorage->storeAssetData(filename, tid, - LLAssetType::AT_LSL_TEXT, - &onSaveTextComplete, - (void*)data, - FALSE); - - LLAssetID asset_id = tid.makeAssetID(gAgent.getSecureSessionID()); - std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,asset_id.asString()); - std::string dst_filename = llformat("%s.lso", filepath.c_str()); - std::string err_filename = llformat("%s.out", filepath.c_str()); - - LLFILE *fp; - const BOOL compile_to_mono = FALSE; - if(!lscript_compile(filename.c_str(), - dst_filename.c_str(), - err_filename.c_str(), - compile_to_mono, - asset_id.asString().c_str(), - gAgent.isGodlike())) - { - // load the error file into the error scrolllist - LL_INFOS() << "Compile failed!" << LL_ENDL; - if(NULL != (fp = LLFile::fopen(err_filename, "r"))) - { - char buffer[MAX_STRING]; /*Flawfinder: ignore*/ - std::string line; - while(!feof(fp)) - { - - if (fgets(buffer, MAX_STRING, fp) == NULL) - { - buffer[0] = '\0'; - } - if(feof(fp)) - { - break; - } - else - { - line.assign(buffer); - LLStringUtil::stripNonprintable(line); - - LLSD row; - row["columns"][0]["value"] = line; - row["columns"][0]["font"] = "OCRA"; - mScriptEd->mErrorList->addElement(row); - } - } - fclose(fp); - mScriptEd->selectFirstError(); - // don't set the asset id, because we want to save the - // script, even though the compile failed. - //mItem->setAssetUUID(LLUUID::null); - object->saveScript(mItem, FALSE, false); - dialog_refresh_all(); - } - } - else - { - LL_INFOS() << "Compile worked!" << LL_ENDL; - mScriptEd->mErrorList->setCommentText(LLTrans::getString("CompileSuccessfulSaving")); - if(gAssetStorage) - { - LL_INFOS() << "LLLiveLSLEditor::saveAsset " - << mItem->getAssetUUID() << LL_ENDL; - getWindow()->incBusyCount(); - mPendingUploads++; - LLLiveLSLSaveData* data = NULL; - data = new LLLiveLSLSaveData(mObjectUUID, - mItem, - is_running); - gAssetStorage->storeAssetData(dst_filename, - tid, - LLAssetType::AT_LSL_BYTECODE, - &LLLiveLSLEditor::onSaveBytecodeComplete, - (void*)data); - dialog_refresh_all(); - } - } - - // get rid of any temp files left lying around - LLFile::remove(filename); - LLFile::remove(err_filename); - LLFile::remove(dst_filename); - - // If we successfully saved it, then we should be able to check/uncheck the running box! - LLCheckBoxCtrl* runningCheckbox = getChild<LLCheckBoxCtrl>( "running"); - runningCheckbox->setLabel(getString("script_running")); - runningCheckbox->setEnabled(TRUE); -} - -void LLLiveLSLEditor::onSaveTextComplete(const LLUUID& asset_uuid, void* user_data, S32 status, LLExtStat ext_status) // StoreAssetData callback (fixed) -{ - LLLiveLSLSaveData* data = (LLLiveLSLSaveData*)user_data; - - if (status) - { - LL_WARNS() << "Unable to save text for a script." << LL_ENDL; - LLSD args; - args["REASON"] = std::string(LLAssetStorage::getErrorString(status)); - LLNotificationsUtil::add("CompileQueueSaveText", args); - } - else - { - LLSD floater_key; - floater_key["taskid"] = data->mSaveObjectID; - floater_key["itemid"] = data->mItem->getUUID(); - LLLiveLSLEditor* self = LLFloaterReg::findTypedInstance<LLLiveLSLEditor>("preview_scriptedit", floater_key); - if (self) - { - self->getWindow()->decBusyCount(); - self->mPendingUploads--; - if (self->mPendingUploads <= 0 - && self->mCloseAfterSave) - { - self->closeFloater(); - } - } - } - delete data; - data = NULL; -} - - -void LLLiveLSLEditor::onSaveBytecodeComplete(const LLUUID& asset_uuid, void* user_data, S32 status, LLExtStat ext_status) // StoreAssetData callback (fixed) -{ - LLLiveLSLSaveData* data = (LLLiveLSLSaveData*)user_data; - if(!data) - return; - if(0 ==status) - { - LL_INFOS() << "LSL Bytecode saved" << LL_ENDL; - LLSD floater_key; - floater_key["taskid"] = data->mSaveObjectID; - floater_key["itemid"] = data->mItem->getUUID(); - LLLiveLSLEditor* self = LLFloaterReg::findTypedInstance<LLLiveLSLEditor>("preview_scriptedit", floater_key); - if (self) - { - // Tell the user that the compile worked. - self->mScriptEd->mErrorList->setCommentText(LLTrans::getString("SaveComplete")); - // close the window if this completes both uploads - self->getWindow()->decBusyCount(); - self->mPendingUploads--; - if (self->mPendingUploads <= 0 - && self->mCloseAfterSave) - { - self->closeFloater(); - } - } - LLViewerObject* object = gObjectList.findObject(data->mSaveObjectID); - if(object) - { - object->saveScript(data->mItem, data->mActive, false); - dialog_refresh_all(); - //LLToolDragAndDrop::dropScript(object, ids->first, - // LLAssetType::AT_LSL_TEXT, FALSE); - } - } - else - { - LL_INFOS() << "Problem saving LSL Bytecode (Live Editor)" << LL_ENDL; - LL_WARNS() << "Unable to save a compiled script." << LL_ENDL; - - LLSD args; - args["REASON"] = std::string(LLAssetStorage::getErrorString(status)); - LLNotificationsUtil::add("CompileQueueSaveBytecode", args); - } - - std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,asset_uuid.asString()); - std::string dst_filename = llformat("%s.lso", filepath.c_str()); - LLFile::remove(dst_filename); - delete data; + // get the latest info about it. We used to be losing the script + // name on save, because the viewer object version of the item, + // and the editor version would get out of synch. Here's a good + // place to synch them back up. + LLInventoryItem* inv_item = dynamic_cast<LLInventoryItem*>(object->getInventoryObject(mItemUUID)); + if (inv_item) + { + mItem->copyItem(inv_item); + } + + // Don't need to save if we're pristine + if(!mScriptEd->hasChanged()) + { + return; + } + + mPendingUploads = 0; + + // save the script + mScriptEd->enableSave(FALSE); + mScriptEd->mEditor->makePristine(); + mScriptEd->mErrorList->deleteAllItems(); + mScriptEd->mEditor->makePristine(); + + if (sync) + { + mScriptEd->sync(); + } + bool isRunning = getChild<LLCheckBoxCtrl>("running")->get(); + getWindow()->incBusyCount(); + mPendingUploads++; + + std::string url = object->getRegion()->getCapability("UpdateScriptTask"); + + if (!url.empty()) + { + std::string buffer(mScriptEd->mEditor->getText()); + LLBufferedAssetUploadInfo::taskUploadFinish_f proc = boost::bind(&LLLiveLSLEditor::finishLSLUpload, _1, _2, _3, _4, isRunning); + + LLResourceUploadInfo::ptr_t uploadInfo(new LLScriptAssetUpload(mObjectUUID, mItemUUID, + monoChecked() ? LLScriptAssetUpload::MONO : LLScriptAssetUpload::LSL2, + isRunning, mScriptEd->getAssociatedExperience(), buffer, proc)); + + LLViewerAssetUpload::EnqueueInventoryUpload(url, uploadInfo); + } } BOOL LLLiveLSLEditor::canClose() |