aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llpreviewscript.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/llpreviewscript.cpp539
1 files changed, 317 insertions, 222 deletions
diff --git a/linden/indra/newview/llpreviewscript.cpp b/linden/indra/newview/llpreviewscript.cpp
index c13da9b..75371b2 100644
--- a/linden/indra/newview/llpreviewscript.cpp
+++ b/linden/indra/newview/llpreviewscript.cpp
@@ -30,6 +30,7 @@
30#include "llpreviewscript.h" 30#include "llpreviewscript.h"
31 31
32#include "llassetstorage.h" 32#include "llassetstorage.h"
33#include "llassetuploadresponders.h"
33#include "llbutton.h" 34#include "llbutton.h"
34#include "llcheckboxctrl.h" 35#include "llcheckboxctrl.h"
35#include "llcombobox.h" 36#include "llcombobox.h"
@@ -155,7 +156,7 @@ public:
155 LLScriptEdCore* getEditorCore() { return mEditorCore; } 156 LLScriptEdCore* getEditorCore() { return mEditorCore; }
156 static LLFloaterScriptSearch* getInstance() { return sInstance; } 157 static LLFloaterScriptSearch* getInstance() { return sInstance; }
157 158
158 void open(); 159 void open(); /*Flawfinder: ignore*/
159 160
160private: 161private:
161 162
@@ -187,6 +188,18 @@ LLFloaterScriptSearch::LLFloaterScriptSearch(std::string title, LLRect rect, LLS
187 sInstance = this; 188 sInstance = this;
188 189
189 childSetFocus("search_text", TRUE); 190 childSetFocus("search_text", TRUE);
191
192 // find floater in which script panel is embedded
193 LLView* viewp = (LLView*)editor_core;
194 while(viewp)
195 {
196 if (viewp->getWidgetType() == WIDGET_TYPE_FLOATER)
197 {
198 ((LLFloater*)viewp)->addDependentFloater(this);
199 break;
200 }
201 viewp = viewp->getParent();
202 }
190} 203}
191 204
192//static 205//static
@@ -208,7 +221,7 @@ void LLFloaterScriptSearch::show(LLScriptEdCore* editor_core)
208 new LLFloaterScriptSearch("Script Search",LLRect(left,top,left + SCRIPT_SEARCH_WIDTH,top - SCRIPT_SEARCH_HEIGHT),editor_core); 221 new LLFloaterScriptSearch("Script Search",LLRect(left,top,left + SCRIPT_SEARCH_WIDTH,top - SCRIPT_SEARCH_HEIGHT),editor_core);
209 } 222 }
210 223
211 sInstance->open(); 224 sInstance->open(); /*Flawfinder: ignore*/
212} 225}
213 226
214LLFloaterScriptSearch::~LLFloaterScriptSearch() 227LLFloaterScriptSearch::~LLFloaterScriptSearch()
@@ -255,9 +268,9 @@ void LLFloaterScriptSearch::handleBtnReplaceAll()
255 mEditorCore->mEditor->replaceTextAll(childGetText("search_text"), childGetText("replace_text"), caseChk->get()); 268 mEditorCore->mEditor->replaceTextAll(childGetText("search_text"), childGetText("replace_text"), caseChk->get());
256} 269}
257 270
258void LLFloaterScriptSearch::open() 271void LLFloaterScriptSearch::open() /*Flawfinder: ignore*/
259{ 272{
260 LLFloater::open(); 273 LLFloater::open(); /*Flawfinder: ignore*/
261 childSetFocus("search_text", TRUE); 274 childSetFocus("search_text", TRUE);
262} 275}
263/// --------------------------------------------------------------------------- 276/// ---------------------------------------------------------------------------
@@ -428,8 +441,8 @@ void LLScriptEdCore::draw()
428 S32 line = 0; 441 S32 line = 0;
429 S32 column = 0; 442 S32 column = 0;
430 mEditor->getCurrentLineAndColumn( &line, &column, FALSE ); // don't include wordwrap 443 mEditor->getCurrentLineAndColumn( &line, &column, FALSE ); // don't include wordwrap
431 char cursor_pos[STD_STRING_BUF_SIZE]; 444 char cursor_pos[STD_STRING_BUF_SIZE]; /*Flawfinder: ignore*/
432 sprintf( cursor_pos, "Line %d, Column %d", line, column ); 445 snprintf( cursor_pos, STD_STRING_BUF_SIZE, "Line %d, Column %d", line, column ); /*Flawfinder: ignore*/
433 childSetText("line_col", cursor_pos); 446 childSetText("line_col", cursor_pos);
434 } 447 }
435 else 448 else
@@ -851,6 +864,33 @@ LLPreviewLSL::LLPreviewLSL(const std::string& name, const LLRect& rect,
851 } 864 }
852} 865}
853 866
867// virtual
868void LLPreviewLSL::callbackLSLCompileSucceeded()
869{
870 llinfos << "LSL Bytecode saved" << llendl;
871 mScriptEd->mErrorList->addSimpleItem("Compile successful!");
872 mScriptEd->mErrorList->addSimpleItem("Save complete.");
873 closeIfNeeded();
874}
875
876// virtual
877void LLPreviewLSL::callbackLSLCompileFailed(const LLSD& compile_errors)
878{
879 llinfos << "Compile failed!" << llendl;
880
881 const LLFontGL* err_font = gResMgr->getRes(LLFONT_OCRA);
882 LLScrollListItem* item = NULL;
883 for(LLSD::array_const_iterator line = compile_errors.beginArray();
884 line < compile_errors.endArray();
885 line++)
886 {
887 item = new LLScrollListItem();
888 item->addColumn(line->asString(), err_font);
889 mScriptEd->mErrorList->addItem(item);
890 }
891 mScriptEd->selectFirstError();
892 closeIfNeeded();
893}
854 894
855void LLPreviewLSL::loadAsset() 895void LLPreviewLSL::loadAsset()
856{ 896{
@@ -912,10 +952,21 @@ BOOL LLPreviewLSL::canClose()
912 return mScriptEd->canClose(); 952 return mScriptEd->canClose();
913} 953}
914 954
955void LLPreviewLSL::closeIfNeeded()
956{
957 // Find our window and close it if requested.
958 getWindow()->decBusyCount();
959 mPendingUploads--;
960 if (mPendingUploads <= 0 && mCloseAfterSave)
961 {
962 close();
963 }
964}
965
915//override the llpreview open which attempts to load asset, load after xml ui made 966//override the llpreview open which attempts to load asset, load after xml ui made
916void LLPreviewLSL::open() 967void LLPreviewLSL::open() /*Flawfinder: ignore*/
917{ 968{
918 LLFloater::open(); 969 LLFloater::open(); /*Flawfinder: ignore*/
919} 970}
920 971
921// static 972// static
@@ -933,152 +984,152 @@ void LLPreviewLSL::onSave(void* userdata, BOOL close_after_save)
933 self->saveIfNeeded(); 984 self->saveIfNeeded();
934} 985}
935 986
936
937// Save needs to compile the text in the buffer. If the compile 987// Save needs to compile the text in the buffer. If the compile
938// succeeds, then save both assets out to the database. If the compile 988// succeeds, then save both assets out to the database. If the compile
939// fails, go ahead and save the text anyway so that the user doesn't 989// fails, go ahead and save the text anyway so that the user doesn't
940// get too fucked. 990// get too fucked.
941void LLPreviewLSL::saveIfNeeded() 991void LLPreviewLSL::saveIfNeeded()
942{ 992{
943 // llinfos << "LLPreviewLSL::save()" << llendl; 993 // llinfos << "LLPreviewLSL::saveIfNeeded()" << llendl;
944 if(!mScriptEd->mEditor->isPristine()) 994 if(mScriptEd->mEditor->isPristine())
945 { 995 {
946 mPendingUploads = 0; 996 return;
947 mScriptEd->mErrorList->deleteAllItems(); 997 }
948 mScriptEd->mEditor->makePristine();
949
950 // We need to update the asset information
951 LLTransactionID tid;
952 LLAssetID uuid;
953 tid.generate();
954 uuid = tid.makeAssetID(gAgent.getSecureSessionID());
955 char uuid_string[UUID_STR_LENGTH];
956 uuid.toString(uuid_string);
957 char filename[LL_MAX_PATH];
958 sprintf(filename, "%s.lsl", gDirUtilp->getExpandedFilename(LL_PATH_CACHE,uuid_string).c_str());
959 FILE* fp = LLFile::fopen(filename, "wb");
960 if(!fp)
961 {
962 llwarns << "Unable to write to " << filename << llendl;
963 LLScrollListItem* item = new LLScrollListItem();
964 item->addColumn("Error writing to local file. Is your hard drive full?", LLFontGL::sSansSerifSmall);
965 mScriptEd->mErrorList->addItem(item);
966 return;
967 }
968 998
969 LLString utf8text = mScriptEd->mEditor->getText(); 999 mPendingUploads = 0;
970 //fprintf(fp, "%s|%s\n", LLAssetType::lookup(LLAssetType::AT_LSL_TEXT), 1000 mScriptEd->mErrorList->deleteAllItems();
971 //uuid_string); 1001 mScriptEd->mEditor->makePristine();
972 //fprintf(fp,"{\n%s}\n", text.c_str());
973 fputs(utf8text.c_str(), fp);
974 fclose(fp);
975 fp = NULL;
976 1002
977 // also write it out to the vfs for upload 1003 // save off asset into file
978 LLVFile file(gVFS, uuid, LLAssetType::AT_LSL_TEXT, LLVFile::APPEND); 1004 LLTransactionID tid;
979 S32 size = utf8text.length() + 1; 1005 tid.generate();
1006 LLAssetID asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
1007 std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,asset_id.asString());
1008 std::string filename = llformat("%s.lsl", filepath.c_str());
980 1009
981 file.setMaxSize(size); 1010 FILE* fp = LLFile::fopen(filename.c_str(), "wb");
982 file.write((U8*)utf8text.c_str(), size); 1011 if(!fp)
1012 {
1013 llwarns << "Unable to write to " << filename << llendl;
1014 LLScrollListItem* item = new LLScrollListItem();
1015 item->addColumn("Error writing to local file. Is your hard drive full?", LLFontGL::sSansSerifSmall);
1016 mScriptEd->mErrorList->addItem(item);
1017 return;
1018 }
983 1019
984 LLInventoryItem *inv_item = getItem(); 1020 LLString utf8text = mScriptEd->mEditor->getText();
1021 fputs(utf8text.c_str(), fp);
1022 fclose(fp);
1023 fp = NULL;
985 1024
986 // save it out to database 1025 LLInventoryItem *inv_item = getItem();
987 if(gAssetStorage && inv_item) 1026 // save it out to asset server
1027 std::string url = gAgent.getRegion()->getCapability("UpdateScriptAgentInventory");
1028 if(inv_item)
1029 {
1030 getWindow()->incBusyCount();
1031 mPendingUploads++;
1032 if (!url.empty())
988 { 1033 {
989 getWindow()->incBusyCount(); 1034 uploadAssetViaCaps(url, filename, mItemUUID);
990 mPendingUploads++; 1035 }
991 LLScriptSaveInfo* info = NULL; 1036 else if (gAssetStorage)
1037 {
1038 uploadAssetLegacy(filename, mItemUUID, tid);
1039 }
1040 }
1041}
992 1042
993 LLLineEditor* descEditor = LLUICtrlFactory::getLineEditorByName(this, "desc"); 1043void LLPreviewLSL::uploadAssetViaCaps(const std::string& url,
1044 const std::string& filename,
1045 const LLUUID& item_id)
1046{
1047 llinfos << "Update Agent Inventory via capability" << llendl;
1048 LLSD body;
1049 body["item_id"] = item_id;
1050 LLHTTPClient::post(url, body, new LLUpdateAgentInventoryResponder(body, filename));
1051}
994 1052
995 info = new LLScriptSaveInfo(mItemUUID, 1053void LLPreviewLSL::uploadAssetLegacy(const std::string& filename,
996 descEditor->getText(), 1054 const LLUUID& item_id,
997 tid); 1055 const LLTransactionID& tid)
998 gAssetStorage->storeAssetData(tid, LLAssetType::AT_LSL_TEXT, &LLPreviewLSL::onSaveComplete, info); 1056{
999 } 1057 LLLineEditor* descEditor = LLUICtrlFactory::getLineEditorByName(this, "desc");
1058 LLScriptSaveInfo* info = new LLScriptSaveInfo(item_id,
1059 descEditor->getText(),
1060 tid);
1061 gAssetStorage->storeAssetData(filename.c_str(), tid,
1062 LLAssetType::AT_LSL_TEXT,
1063 &LLPreviewLSL::onSaveComplete,
1064 info);
1000 1065
1001 char dst_filename[LL_MAX_PATH]; 1066 LLAssetID asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
1002 sprintf(dst_filename, "%s.lso", gDirUtilp->getExpandedFilename(LL_PATH_CACHE,uuid_string).c_str()); 1067 std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,asset_id.asString());
1003 char err_filename[LL_MAX_PATH]; 1068 std::string dst_filename = llformat("%s.lso", filepath.c_str());
1004 sprintf(err_filename, "%s.out", gDirUtilp->getExpandedFilename(LL_PATH_CACHE,uuid_string).c_str()); 1069 std::string err_filename = llformat("%s.out", filepath.c_str());
1005 LLScrollListItem* item = NULL;
1006 const LLFontGL* err_font = gResMgr->getRes(LLFONT_OCRA);
1007 if(!lscript_compile(filename, dst_filename, err_filename, gAgent.isGodlike()))
1008 {
1009 llinfos << "Compile failed!" << llendl;
1010 //char command[256];
1011 //sprintf(command, "type %s\n", err_filename);
1012 //system(command);
1013 1070
1014 // load the error file into the error scrolllist 1071 LLScrollListItem* item = NULL;
1015 if(NULL != (fp = LLFile::fopen(err_filename, "r"))) 1072 const LLFontGL* err_font = gResMgr->getRes(LLFONT_OCRA);
1073 if(!lscript_compile(filename.c_str(),
1074 dst_filename.c_str(),
1075 err_filename.c_str(),
1076 gAgent.isGodlike()))
1077 {
1078 llinfos << "Compile failed!" << llendl;
1079 //char command[256];
1080 //sprintf(command, "type %s\n", err_filename);
1081 //system(command);
1082
1083 // load the error file into the error scrolllist
1084 FILE* fp = LLFile::fopen(err_filename.c_str(), "r");
1085 if(fp)
1086 {
1087 char buffer[MAX_STRING]; /*Flawfinder: ignore*/
1088 LLString line;
1089 while(!feof(fp))
1016 { 1090 {
1017 char buffer[MAX_STRING]; 1091 fgets(buffer, MAX_STRING, fp);
1018 LLString line; 1092 if(feof(fp))
1019 while(!feof(fp))
1020 { 1093 {
1021 1094 break;
1022 fgets(buffer, MAX_STRING, fp);
1023 if(feof(fp))
1024 {
1025 break;
1026 }
1027 else if(!buffer)
1028 {
1029 continue;
1030 }
1031 else
1032 {
1033 line.assign(buffer);
1034 LLString::stripNonprintable(line);
1035 item = new LLScrollListItem();
1036 item->addColumn(line, err_font);
1037 mScriptEd->mErrorList->addItem(item);
1038 }
1039 } 1095 }
1040 fclose(fp); 1096 else if(!buffer)
1041 mScriptEd->selectFirstError();
1042 }
1043 }
1044 else
1045 {
1046 llinfos << "Compile worked!" << llendl;
1047 if(gAssetStorage)
1048 {
1049 // move the compiled file into the vfs for transport
1050 FILE* fp = LLFile::fopen(dst_filename, "rb");
1051 LLVFile file(gVFS, uuid, LLAssetType::AT_LSL_BYTECODE, LLVFile::APPEND);
1052
1053 fseek(fp, 0, SEEK_END);
1054 S32 size = ftell(fp);
1055 fseek(fp, 0, SEEK_SET);
1056
1057 file.setMaxSize(size);
1058
1059 const S32 buf_size = 65536;
1060 U8 copy_buf[buf_size];
1061 while ((size = fread(copy_buf, 1, buf_size, fp)))
1062 { 1097 {
1063 file.write(copy_buf, size); 1098 continue;
1099 }
1100 else
1101 {
1102 line.assign(buffer);
1103 LLString::stripNonprintable(line);
1104 item = new LLScrollListItem();
1105 item->addColumn(line, err_font);
1106 mScriptEd->mErrorList->addItem(item);
1064 } 1107 }
1065 fclose(fp);
1066 fp = NULL;
1067 getWindow()->incBusyCount();
1068 mPendingUploads++;
1069 LLUUID* this_uuid = new LLUUID(mItemUUID);
1070 gAssetStorage->storeAssetData(tid,
1071 LLAssetType::AT_LSL_BYTECODE,
1072 &LLPreviewLSL::onSaveBytecodeComplete,
1073 (void**)this_uuid);
1074 } 1108 }
1109 fclose(fp);
1110 mScriptEd->selectFirstError();
1111 }
1112 }
1113 else
1114 {
1115 llinfos << "Compile worked!" << llendl;
1116 if(gAssetStorage)
1117 {
1118 getWindow()->incBusyCount();
1119 mPendingUploads++;
1120 LLUUID* this_uuid = new LLUUID(mItemUUID);
1121 gAssetStorage->storeAssetData(dst_filename.c_str(),
1122 tid,
1123 LLAssetType::AT_LSL_BYTECODE,
1124 &LLPreviewLSL::onSaveBytecodeComplete,
1125 (void**)this_uuid);
1075 } 1126 }
1076
1077 // get rid of any temp files left lying around
1078 LLFile::remove(filename);
1079 LLFile::remove(err_filename);
1080 LLFile::remove(dst_filename);
1081 } 1127 }
1128
1129 // get rid of any temp files left lying around
1130 LLFile::remove(filename.c_str());
1131 LLFile::remove(err_filename.c_str());
1132 LLFile::remove(dst_filename.c_str());
1082} 1133}
1083 1134
1084 1135
@@ -1184,7 +1235,7 @@ void LLPreviewLSL::onLoadComplete( LLVFS *vfs, const LLUUID& asset_uuid, LLAsset
1184 S32 file_length = file.getSize(); 1235 S32 file_length = file.getSize();
1185 1236
1186 char* buffer = new char[file_length+1]; 1237 char* buffer = new char[file_length+1];
1187 file.read((U8*)buffer, file_length); 1238 file.read((U8*)buffer, file_length); /*Flawfinder: ignore*/
1188 1239
1189 // put a EOS at the end 1240 // put a EOS at the end
1190 buffer[file_length] = 0; 1241 buffer[file_length] = 0;
@@ -1287,7 +1338,7 @@ LLLiveLSLEditor::LLLiveLSLEditor(const std::string& name,
1287 const std::string& title, 1338 const std::string& title,
1288 const LLUUID& object_id, 1339 const LLUUID& object_id,
1289 const LLUUID& item_id) : 1340 const LLUUID& item_id) :
1290 LLFloater(name, rect, title, TRUE, SCRIPT_MIN_WIDTH, SCRIPT_MIN_HEIGHT), 1341 LLPreview(name, rect, title, item_id, object_id, TRUE, SCRIPT_MIN_WIDTH, SCRIPT_MIN_HEIGHT),
1291 mObjectID(object_id), 1342 mObjectID(object_id),
1292 mItemID(item_id), 1343 mItemID(item_id),
1293 mScriptEd(NULL), 1344 mScriptEd(NULL),
@@ -1346,6 +1397,40 @@ LLLiveLSLEditor::~LLLiveLSLEditor()
1346 LLLiveLSLEditor::sInstances.removeData(mItemID ^ mObjectID); 1397 LLLiveLSLEditor::sInstances.removeData(mItemID ^ mObjectID);
1347} 1398}
1348 1399
1400// this is called via LLPreview::loadAsset() virtual method
1401void LLLiveLSLEditor::loadAsset()
1402{
1403 loadAsset(FALSE);
1404}
1405
1406// virtual
1407void LLLiveLSLEditor::callbackLSLCompileSucceeded(const LLUUID& task_id,
1408 const LLUUID& item_id,
1409 bool is_script_running)
1410{
1411 lldebugs << "LSL Bytecode saved" << llendl;
1412 mScriptEd->mErrorList->addSimpleItem("Compile successful!");
1413 mScriptEd->mErrorList->addSimpleItem("Save complete.");
1414 closeIfNeeded();
1415}
1416
1417// virtual
1418void LLLiveLSLEditor::callbackLSLCompileFailed(const LLSD& compile_errors)
1419{
1420 lldebugs << "Compile failed!" << llendl;
1421 const LLFontGL* err_font = gResMgr->getRes(LLFONT_OCRA);
1422 LLScrollListItem* item = NULL;
1423 for(LLSD::array_const_iterator line = compile_errors.beginArray();
1424 line < compile_errors.endArray();
1425 line++)
1426 {
1427 item = new LLScrollListItem();
1428 item->addColumn(line->asString(), err_font);
1429 mScriptEd->mErrorList->addItem(item);
1430 }
1431 mScriptEd->selectFirstError();
1432 closeIfNeeded();
1433}
1349 1434
1350void LLLiveLSLEditor::loadAsset(BOOL is_new) 1435void LLLiveLSLEditor::loadAsset(BOOL is_new)
1351{ 1436{
@@ -1377,6 +1462,7 @@ void LLLiveLSLEditor::loadAsset(BOOL is_new)
1377 mScriptEd->mEditor->setText("You are not allowed to view this script."); 1462 mScriptEd->mEditor->setText("You are not allowed to view this script.");
1378 mScriptEd->mEditor->makePristine(); 1463 mScriptEd->mEditor->makePristine();
1379 mScriptEd->mEditor->setEnabled(FALSE); 1464 mScriptEd->mEditor->setEnabled(FALSE);
1465 mAssetStatus = PREVIEW_ASSET_LOADED;
1380 } 1466 }
1381 else if(mItem.notNull()) 1467 else if(mItem.notNull())
1382 { 1468 {
@@ -1400,11 +1486,13 @@ void LLLiveLSLEditor::loadAsset(BOOL is_new)
1400 msg->addUUIDFast(_PREHASH_ItemID, mItemID); 1486 msg->addUUIDFast(_PREHASH_ItemID, mItemID);
1401 msg->sendReliable(object->getRegion()->getHost()); 1487 msg->sendReliable(object->getRegion()->getHost());
1402 mAskedForRunningInfo = TRUE; 1488 mAskedForRunningInfo = TRUE;
1489 mAssetStatus = PREVIEW_ASSET_LOADING;
1403 } 1490 }
1404 else 1491 else
1405 { 1492 {
1406 mScriptEd->mEditor->setText(""); 1493 mScriptEd->mEditor->setText("");
1407 mScriptEd->mEditor->makePristine(); 1494 mScriptEd->mEditor->makePristine();
1495 mAssetStatus = PREVIEW_ASSET_LOADED;
1408 } 1496 }
1409 1497
1410 if(item 1498 if(item
@@ -1448,6 +1536,7 @@ void LLLiveLSLEditor::loadAsset(BOOL is_new)
1448 LLSaleInfo::DEFAULT, 1536 LLSaleInfo::DEFAULT,
1449 LLInventoryItem::II_FLAGS_NONE, 1537 LLInventoryItem::II_FLAGS_NONE,
1450 time_corrected()); 1538 time_corrected());
1539 mAssetStatus = PREVIEW_ASSET_LOADED;
1451 } 1540 }
1452} 1541}
1453 1542
@@ -1463,10 +1552,11 @@ void LLLiveLSLEditor::onLoadComplete(LLVFS *vfs, const LLUUID& asset_id,
1463 1552
1464 if( LLLiveLSLEditor::sInstances.checkData(*xored_id) ) 1553 if( LLLiveLSLEditor::sInstances.checkData(*xored_id) )
1465 { 1554 {
1555 instance = LLLiveLSLEditor::sInstances[*xored_id];
1466 if( LL_ERR_NOERR == status ) 1556 if( LL_ERR_NOERR == status )
1467 { 1557 {
1468 instance = LLLiveLSLEditor::sInstances[*xored_id];
1469 instance->loadScriptText(vfs, asset_id, type); 1558 instance->loadScriptText(vfs, asset_id, type);
1559 instance->mAssetStatus = PREVIEW_ASSET_LOADED;
1470 } 1560 }
1471 else 1561 else
1472 { 1562 {
@@ -1488,6 +1578,7 @@ void LLLiveLSLEditor::onLoadComplete(LLVFS *vfs, const LLUUID& asset_id,
1488 { 1578 {
1489 LLNotifyBox::showXml("UnableToLoadScript"); 1579 LLNotifyBox::showXml("UnableToLoadScript");
1490 } 1580 }
1581 instance->mAssetStatus = PREVIEW_ASSET_ERROR;
1491 } 1582 }
1492 } 1583 }
1493 1584
@@ -1496,7 +1587,11 @@ void LLLiveLSLEditor::onLoadComplete(LLVFS *vfs, const LLUUID& asset_id,
1496 1587
1497void LLLiveLSLEditor::loadScriptText(const char* filename) 1588void LLLiveLSLEditor::loadScriptText(const char* filename)
1498{ 1589{
1499 FILE* file = LLFile::fopen(filename, "rb"); 1590 if(!filename)
1591 {
1592 llerrs << "Filename is Empty!" << llendl;
1593 }
1594 FILE* file = LLFile::fopen(filename, "rb"); /*Flawfinder: ignore*/
1500 if(file) 1595 if(file)
1501 { 1596 {
1502 // read in the whole file 1597 // read in the whole file
@@ -1522,7 +1617,7 @@ void LLLiveLSLEditor::loadScriptText(LLVFS *vfs, const LLUUID &uuid, LLAssetType
1522 LLVFile file(vfs, uuid, type); 1617 LLVFile file(vfs, uuid, type);
1523 S32 file_length = file.getSize(); 1618 S32 file_length = file.getSize();
1524 char *buffer = new char[file_length + 1]; 1619 char *buffer = new char[file_length + 1];
1525 file.read((U8*)buffer, file_length); 1620 file.read((U8*)buffer, file_length); /*Flawfinder: ignore*/
1526 1621
1527 if (file.getLastBytesRead() != file_length || 1622 if (file.getLastBytesRead() != file_length ||
1528 file_length <= 0) 1623 file_length <= 0)
@@ -1680,18 +1775,16 @@ void LLLiveLSLEditor::saveIfNeeded()
1680 // set up the save on the local machine. 1775 // set up the save on the local machine.
1681 mScriptEd->mEditor->makePristine(); 1776 mScriptEd->mEditor->makePristine();
1682 LLTransactionID tid; 1777 LLTransactionID tid;
1683 LLAssetID uuid;
1684 tid.generate(); 1778 tid.generate();
1685 uuid = tid.makeAssetID(gAgent.getSecureSessionID()); 1779 LLAssetID asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
1686 mItem->setAssetUUID(uuid); 1780 std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,asset_id.asString());
1781 std::string filename = llformat("%s.lsl", filepath.c_str());
1782
1783 mItem->setAssetUUID(asset_id);
1687 mItem->setTransactionID(tid); 1784 mItem->setTransactionID(tid);
1688 1785
1689 // write out the data, and store it in the asset database 1786 // write out the data, and store it in the asset database
1690 char uuid_string[UUID_STR_LENGTH]; 1787 FILE* fp = LLFile::fopen(filename.c_str(), "wb");
1691 uuid.toString(uuid_string);
1692 char filename[LL_MAX_PATH];
1693 sprintf(filename, "%s.lsl", gDirUtilp->getExpandedFilename(LL_PATH_CACHE,uuid_string).c_str());
1694 FILE* fp = LLFile::fopen(filename, "wb");
1695 if(!fp) 1788 if(!fp)
1696 { 1789 {
1697 llwarns << "Unable to write to " << filename << llendl; 1790 llwarns << "Unable to write to " << filename << llendl;
@@ -1703,65 +1796,71 @@ void LLLiveLSLEditor::saveIfNeeded()
1703 LLString utf8text = mScriptEd->mEditor->getText(); 1796 LLString utf8text = mScriptEd->mEditor->getText();
1704 fputs(utf8text.c_str(), fp); 1797 fputs(utf8text.c_str(), fp);
1705 fclose(fp); 1798 fclose(fp);
1706 1799 fp = NULL;
1707 LLCheckBoxCtrl* runningCheckbox = LLUICtrlFactory::getCheckBoxByName(this, "running");
1708 1800
1709 // save it out to database 1801 // save it out to asset server
1710 if(gAssetStorage) 1802 std::string url = gAgent.getRegion()->getCapability("UpdateScriptTaskInventory");
1803 getWindow()->incBusyCount();
1804 mPendingUploads++;
1805 BOOL is_running = LLUICtrlFactory::getCheckBoxByName(this, "running")->get();
1806 if (!url.empty())
1711 { 1807 {
1712 // write it out to the vfs for upload 1808 uploadAssetViaCaps(url, filename, mObjectID,
1713 LLVFile file(gVFS, uuid, LLAssetType::AT_LSL_TEXT, LLVFile::APPEND); 1809 mItemID, is_running);
1714 S32 size = utf8text.length() + 1;
1715
1716 file.setMaxSize(size);
1717 file.write((U8*)utf8text.c_str(), size);
1718
1719 getWindow()->incBusyCount();
1720 mPendingUploads++;
1721 LLLiveLSLSaveData* data = new LLLiveLSLSaveData(mObjectID,
1722 mItem,
1723 runningCheckbox->get());
1724 gAssetStorage->storeAssetData(tid, LLAssetType::AT_LSL_TEXT, &onSaveTextComplete, (void*)data, FALSE);
1725 } 1810 }
1726 1811 else if (gAssetStorage)
1727#if LL_WINDOWS
1728 // This major hack was inserted because sometimes compilation
1729 // would fail because it couldn't open this file... I decided
1730 // to make a loop until open was successful. This seems to be
1731 // a problem specific to ntfs.
1732 fp = NULL;
1733 const U32 MAX_TRIES = 20;
1734 U32 tries = MAX_TRIES;
1735 while((!fp) && --tries)
1736 { 1812 {
1737 ms_sleep(17); 1813 uploadAssetLegacy(filename, object, tid, is_running);
1738 fp = LLFile::fopen(filename, "r");
1739 if(!fp)
1740 {
1741 llwarns << "Trying to open the source file " << filename
1742 << " again" << llendl;
1743 }
1744 else
1745 {
1746 fclose(fp);
1747 }
1748 } 1814 }
1749 fp = NULL; 1815}
1750#endif 1816
1817void LLLiveLSLEditor::uploadAssetViaCaps(const std::string& url,
1818 const std::string& filename,
1819 const LLUUID& task_id,
1820 const LLUUID& item_id,
1821 BOOL is_running)
1822{
1823 llinfos << "Update Task Inventory via capability" << llendl;
1824 LLSD body;
1825 body["task_id"] = task_id;
1826 body["item_id"] = item_id;
1827 body["is_script_running"] = is_running;
1828 LLHTTPClient::post(url, body,
1829 new LLUpdateTaskInventoryResponder(body, filename));
1830}
1831
1832void LLLiveLSLEditor::uploadAssetLegacy(const std::string& filename,
1833 LLViewerObject* object,
1834 const LLTransactionID& tid,
1835 BOOL is_running)
1836{
1837 LLLiveLSLSaveData* data = new LLLiveLSLSaveData(mObjectID,
1838 mItem,
1839 is_running);
1840 gAssetStorage->storeAssetData(filename.c_str(), tid,
1841 LLAssetType::AT_LSL_TEXT,
1842 &onSaveTextComplete,
1843 (void*)data,
1844 FALSE);
1845
1846 LLAssetID asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
1847 std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,asset_id.asString());
1848 std::string dst_filename = llformat("%s.lso", filepath.c_str());
1849 std::string err_filename = llformat("%s.out", filepath.c_str());
1751 1850
1752 char dst_filename[LL_MAX_PATH];
1753 sprintf(dst_filename, "%s.lso", gDirUtilp->getExpandedFilename(LL_PATH_CACHE,uuid_string).c_str());
1754 char err_filename[LL_MAX_PATH];
1755 sprintf(err_filename, "%s.out", gDirUtilp->getExpandedFilename(LL_PATH_CACHE,uuid_string).c_str());
1756 LLScrollListItem* item = NULL; 1851 LLScrollListItem* item = NULL;
1757 const LLFontGL* err_font = gResMgr->getRes(LLFONT_OCRA); 1852 const LLFontGL* err_font = gResMgr->getRes(LLFONT_OCRA);
1758 if(!lscript_compile(filename, dst_filename, err_filename, gAgent.isGodlike())) 1853 FILE *fp;
1854 if(!lscript_compile(filename.c_str(),
1855 dst_filename.c_str(),
1856 err_filename.c_str(),
1857 gAgent.isGodlike()))
1759 { 1858 {
1760 // load the error file into the error scrolllist 1859 // load the error file into the error scrolllist
1761 llinfos << "Compile failed!" << llendl; 1860 llinfos << "Compile failed!" << llendl;
1762 if(NULL != (fp = LLFile::fopen(err_filename, "r"))) 1861 if(NULL != (fp = LLFile::fopen(err_filename.c_str(), "r")))
1763 { 1862 {
1764 char buffer[MAX_STRING]; 1863 char buffer[MAX_STRING]; /*Flawfinder: ignore*/
1765 LLString line; 1864 LLString line;
1766 while(!feof(fp)) 1865 while(!feof(fp))
1767 { 1866 {
@@ -1801,33 +1900,14 @@ void LLLiveLSLEditor::saveIfNeeded()
1801 { 1900 {
1802 llinfos << "LLLiveLSLEditor::saveAsset " 1901 llinfos << "LLLiveLSLEditor::saveAsset "
1803 << mItem->getAssetUUID() << llendl; 1902 << mItem->getAssetUUID() << llendl;
1804
1805 // move the compiled file into the vfs for transport
1806 FILE* fp = LLFile::fopen(dst_filename, "rb");
1807 LLVFile file(gVFS, uuid, LLAssetType::AT_LSL_BYTECODE, LLVFile::APPEND);
1808
1809 fseek(fp, 0, SEEK_END);
1810 S32 size = ftell(fp);
1811 fseek(fp, 0, SEEK_SET);
1812
1813 file.setMaxSize(size);
1814
1815 const S32 buf_size = 65536;
1816 U8 copy_buf[buf_size];
1817 while ((size = fread(copy_buf, 1, buf_size, fp)))
1818 {
1819 file.write(copy_buf, size);
1820 }
1821 fclose(fp);
1822 fp = NULL;
1823
1824 getWindow()->incBusyCount(); 1903 getWindow()->incBusyCount();
1825 mPendingUploads++; 1904 mPendingUploads++;
1826 LLLiveLSLSaveData* data = NULL; 1905 LLLiveLSLSaveData* data = NULL;
1827 data = new LLLiveLSLSaveData(mObjectID, 1906 data = new LLLiveLSLSaveData(mObjectID,
1828 mItem, 1907 mItem,
1829 runningCheckbox->get()); 1908 is_running);
1830 gAssetStorage->storeAssetData(tid, 1909 gAssetStorage->storeAssetData(dst_filename.c_str(),
1910 tid,
1831 LLAssetType::AT_LSL_BYTECODE, 1911 LLAssetType::AT_LSL_BYTECODE,
1832 &LLLiveLSLEditor::onSaveBytecodeComplete, 1912 &LLLiveLSLEditor::onSaveBytecodeComplete,
1833 (void*)data); 1913 (void*)data);
@@ -1836,11 +1916,12 @@ void LLLiveLSLEditor::saveIfNeeded()
1836 } 1916 }
1837 1917
1838 // get rid of any temp files left lying around 1918 // get rid of any temp files left lying around
1839 LLFile::remove(filename); 1919 LLFile::remove(filename.c_str());
1840 LLFile::remove(err_filename); 1920 LLFile::remove(err_filename.c_str());
1841 LLFile::remove(dst_filename); 1921 LLFile::remove(dst_filename.c_str());
1842 1922
1843 // If we successfully saved it, then we should be able to check/uncheck the running box! 1923 // If we successfully saved it, then we should be able to check/uncheck the running box!
1924 LLCheckBoxCtrl* runningCheckbox = LLUICtrlFactory::getCheckBoxByName(this, "running");
1844 runningCheckbox->setLabel(ENABLED_RUNNING_CHECKBOX_LABEL); 1925 runningCheckbox->setLabel(ENABLED_RUNNING_CHECKBOX_LABEL);
1845 runningCheckbox->setEnabled(TRUE); 1926 runningCheckbox->setEnabled(TRUE);
1846} 1927}
@@ -1916,13 +1997,10 @@ void LLLiveLSLEditor::onSaveBytecodeComplete(const LLUUID& asset_uuid, void* use
1916 args["[REASON]"] = std::string(LLAssetStorage::getErrorString(status)); 1997 args["[REASON]"] = std::string(LLAssetStorage::getErrorString(status));
1917 gViewerWindow->alertXml("CompileQueueSaveBytecode", args); 1998 gViewerWindow->alertXml("CompileQueueSaveBytecode", args);
1918 } 1999 }
1919 char uuid_string[UUID_STR_LENGTH]; 2000
1920 data->mItem->getAssetUUID().toString(uuid_string); 2001 std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,asset_uuid.asString());
1921 char dst_filename[LL_MAX_PATH]; 2002 std::string dst_filename = llformat("%s.lso", filepath.c_str());
1922 sprintf(dst_filename, "%s.lso", gDirUtilp->getExpandedFilename(LL_PATH_CACHE,uuid_string).c_str()); 2003 LLFile::remove(dst_filename.c_str());
1923 LLFile::remove(dst_filename);
1924 sprintf(dst_filename, "%s.lsl", gDirUtilp->getExpandedFilename(LL_PATH_CACHE,uuid_string).c_str());
1925 LLFile::remove(dst_filename);
1926 delete data; 2004 delete data;
1927} 2005}
1928 2006
@@ -1931,6 +2009,16 @@ BOOL LLLiveLSLEditor::canClose()
1931 return (mScriptEd->canClose()); 2009 return (mScriptEd->canClose());
1932} 2010}
1933 2011
2012void LLLiveLSLEditor::closeIfNeeded()
2013{
2014 getWindow()->decBusyCount();
2015 mPendingUploads--;
2016 if (mPendingUploads <= 0 && mCloseAfterSave)
2017 {
2018 close();
2019 }
2020}
2021
1934// static 2022// static
1935void LLLiveLSLEditor::onLoad(void* userdata) 2023void LLLiveLSLEditor::onLoad(void* userdata)
1936{ 2024{
@@ -1955,7 +2043,7 @@ LLLiveLSLEditor* LLLiveLSLEditor::show(const LLUUID& script_id, const LLUUID& ob
1955 { 2043 {
1956 // Move the existing view to the front 2044 // Move the existing view to the front
1957 instance = LLLiveLSLEditor::sInstances[xored_id]; 2045 instance = LLLiveLSLEditor::sInstances[xored_id];
1958 instance->open(); 2046 instance->open(); /*Flawfinder: ignore*/
1959 } 2047 }
1960 return instance; 2048 return instance;
1961} 2049}
@@ -1974,6 +2062,13 @@ void LLLiveLSLEditor::hide(const LLUUID& script_id, const LLUUID& object_id)
1974 delete instance; 2062 delete instance;
1975 } 2063 }
1976} 2064}
2065// static
2066LLLiveLSLEditor* LLLiveLSLEditor::find(const LLUUID& script_id, const LLUUID& object_id)
2067{
2068 LLUUID xored_id = script_id ^ object_id;
2069 return sInstances.getIfThere(xored_id);
2070}
2071
1977 2072
1978// static 2073// static
1979void LLLiveLSLEditor::processScriptRunningReply(LLMessageSystem* msg, void**) 2074void LLLiveLSLEditor::processScriptRunningReply(LLMessageSystem* msg, void**)