diff options
author | McCabe Maxsted | 2011-09-13 12:53:32 -0700 |
---|---|---|
committer | McCabe Maxsted | 2011-09-13 13:21:33 -0700 |
commit | 03d006a9d34200aac9672c2f765b76ad8e688429 (patch) | |
tree | 9f339d7a494d0c3587cf67e7d93ceab89a42f3a7 /linden/indra/newview/llpreviewscript.cpp | |
parent | Ported external script editor patch from Phoenix, added some cleanup, and mad... (diff) | |
download | meta-impy-03d006a9d34200aac9672c2f765b76ad8e688429.zip meta-impy-03d006a9d34200aac9672c2f765b76ad8e688429.tar.gz meta-impy-03d006a9d34200aac9672c2f765b76ad8e688429.tar.bz2 meta-impy-03d006a9d34200aac9672c2f765b76ad8e688429.tar.xz |
Fixed the script editor constantly searching for an update that doesn't exist (also some more cleanup)
Diffstat (limited to 'linden/indra/newview/llpreviewscript.cpp')
-rw-r--r-- | linden/indra/newview/llpreviewscript.cpp | 114 |
1 files changed, 73 insertions, 41 deletions
diff --git a/linden/indra/newview/llpreviewscript.cpp b/linden/indra/newview/llpreviewscript.cpp index a1c05c7..ca4dcb7 100644 --- a/linden/indra/newview/llpreviewscript.cpp +++ b/linden/indra/newview/llpreviewscript.cpp | |||
@@ -170,15 +170,22 @@ LLScriptEdCore::LLScriptEdCore( | |||
170 | mSampleText(sample), | 170 | mSampleText(sample), |
171 | mHelpURL(help_url), | 171 | mHelpURL(help_url), |
172 | mEditor( NULL ), | 172 | mEditor( NULL ), |
173 | mFunctions(NULL), | ||
174 | mErrorList(NULL), | ||
173 | mLoadCallback( load_callback ), | 175 | mLoadCallback( load_callback ), |
174 | mSaveCallback( save_callback ), | 176 | mSaveCallback( save_callback ), |
175 | mSearchReplaceCallback( search_replace_callback ), | 177 | mSearchReplaceCallback( search_replace_callback ), |
176 | mUserdata( userdata ), | 178 | mUserdata( userdata ), |
177 | mForceClose( FALSE ), | 179 | mForceClose( FALSE ), |
180 | mLiveHelpHandle(), | ||
181 | mLiveHelpTimer(), | ||
178 | mLastHelpToken(NULL), | 182 | mLastHelpToken(NULL), |
179 | mLiveHelpHistorySize(0), | 183 | mLiveHelpHistorySize(0), |
180 | mEnableSave(FALSE), | 184 | mEnableSave(FALSE), |
181 | mEnableXEd(FALSE), | 185 | mEnableXEd(FALSE), |
186 | mXstbuf(), | ||
187 | mXfname(""), | ||
188 | mAutosaveFilename(""), | ||
182 | mHasScriptData(FALSE), | 189 | mHasScriptData(FALSE), |
183 | // We need to check for a new file every five seconds, or autosave every 60. | 190 | // We need to check for a new file every five seconds, or autosave every 60. |
184 | // There's probably a better solution to both of the above. | 191 | // There's probably a better solution to both of the above. |
@@ -284,7 +291,11 @@ BOOL LLScriptEdCore::tick() | |||
284 | } | 291 | } |
285 | else | 292 | else |
286 | { | 293 | { |
287 | XedUpd(); | 294 | // This should really be passed as a parameter -- MC |
295 | if (!mXfname.empty()) | ||
296 | { | ||
297 | xedUpdateScript(); | ||
298 | } | ||
288 | } | 299 | } |
289 | return FALSE; | 300 | return FALSE; |
290 | } | 301 | } |
@@ -509,7 +520,7 @@ void LLScriptEdCore::xedLaunch() | |||
509 | fp = NULL; | 520 | fp = NULL; |
510 | llinfos << "XEditor: " << mXfname << llendl; | 521 | llinfos << "XEditor: " << mXfname << llendl; |
511 | //record the stat | 522 | //record the stat |
512 | stat(mXfname.c_str(), &mXstbuf); | 523 | LLFile::stat(mXfname.c_str(), &mXstbuf); |
513 | //launch | 524 | //launch |
514 | #if LL_WINDOWS | 525 | #if LL_WINDOWS |
515 | //just to get rid of the pesky black window | 526 | //just to get rid of the pesky black window |
@@ -561,43 +572,45 @@ void LLScriptEdCore::xedLaunch() | |||
561 | #endif | 572 | #endif |
562 | } | 573 | } |
563 | 574 | ||
564 | void LLScriptEdCore::XedUpd() | 575 | void LLScriptEdCore::xedUpdateScript() |
565 | { | 576 | { |
566 | struct stat stbuf; | 577 | llstat stbuf; |
567 | stat(this->mXfname.c_str() , &stbuf); | 578 | if (LLFile::stat(this->mXfname.c_str() , &stbuf) == 0) // info found |
568 | if (this->mXstbuf.st_mtime != stbuf.st_mtime) | ||
569 | { | 579 | { |
570 | this->mErrorList->addCommentText(std::string("Change Detected... Updating")); | 580 | if (this->mXstbuf.st_mtime != stbuf.st_mtime) |
571 | 581 | { | |
572 | this->mXstbuf = stbuf; | 582 | this->mErrorList->addCommentText(std::string("Change Detected... Updating")); |
573 | LLFILE* file = LLFile::fopen(this->mXfname, "rb"); /*Flawfinder: ignore*/ | 583 | |
574 | if(file) | 584 | this->mXstbuf = stbuf; |
575 | { | 585 | LLFILE* file = LLFile::fopen(this->mXfname, "rb"); /*Flawfinder: ignore*/ |
576 | // read in the whole file | 586 | if(file) |
577 | fseek(file, 0L, SEEK_END); | 587 | { |
578 | S64 file_length = ftell(file); | 588 | // read in the whole file |
579 | fseek(file, 0L, SEEK_SET); | 589 | fseek(file, 0L, SEEK_END); |
580 | char* buffer = new char[file_length+1]; | 590 | S64 file_length = ftell(file); |
581 | size_t nread = fread(buffer, 1, file_length, file); | 591 | fseek(file, 0L, SEEK_SET); |
582 | if (nread < (size_t) file_length) | 592 | char* buffer = new char[file_length+1]; |
593 | size_t nread = fread(buffer, 1, file_length, file); | ||
594 | if (nread < (size_t) file_length) | ||
595 | { | ||
596 | llwarns << "Short read" << llendl; | ||
597 | } | ||
598 | buffer[nread] = '\0'; | ||
599 | fclose(file); | ||
600 | std::string ttext = LLStringExplicit(buffer); | ||
601 | LLStringUtil::replaceTabsWithSpaces(ttext, 4); | ||
602 | mEditor->setText(ttext); | ||
603 | LLScriptEdCore::doSave( this, FALSE ); | ||
604 | //mEditor->makePristine(); | ||
605 | delete[] buffer; | ||
606 | buffer = NULL; | ||
607 | } | ||
608 | else | ||
583 | { | 609 | { |
584 | llwarns << "Short read" << llendl; | 610 | llwarns << "Error opening " << this->mXfname << llendl; |
585 | } | 611 | } |
586 | buffer[nread] = '\0'; | ||
587 | fclose(file); | ||
588 | std::string ttext = LLStringExplicit(buffer); | ||
589 | LLStringUtil::replaceTabsWithSpaces(ttext, 4); | ||
590 | mEditor->setText(ttext); | ||
591 | LLScriptEdCore::doSave( this, FALSE ); | ||
592 | //mEditor->makePristine(); | ||
593 | delete[] buffer; | ||
594 | buffer = NULL; | ||
595 | } | ||
596 | else | ||
597 | { | ||
598 | llwarns << "Error opening " << this->mXfname << llendl; | ||
599 | } | 612 | } |
600 | } | 613 | } |
601 | } | 614 | } |
602 | //end dim | 615 | //end dim |
603 | void LLScriptEdCore::autoSave() | 616 | void LLScriptEdCore::autoSave() |
@@ -725,6 +738,11 @@ bool LLScriptEdCore::handleSaveChangesDialog(const LLSD& notification, const LLS | |||
725 | break; | 738 | break; |
726 | 739 | ||
727 | case 1: // "No" | 740 | case 1: // "No" |
741 | if( !mAutosaveFilename.empty()) | ||
742 | { | ||
743 | llinfos << "remove autosave: " << mAutosaveFilename << llendl; | ||
744 | LLFile::remove(mAutosaveFilename.c_str()); | ||
745 | } | ||
728 | if( !mXfname.empty()) | 746 | if( !mXfname.empty()) |
729 | { | 747 | { |
730 | llinfos << "remove autosave: " << mXfname << llendl; | 748 | llinfos << "remove autosave: " << mXfname << llendl; |
@@ -1343,6 +1361,15 @@ LLPreviewLSL::LLPreviewLSL(const std::string& name, const LLRect& rect, | |||
1343 | } | 1361 | } |
1344 | } | 1362 | } |
1345 | 1363 | ||
1364 | LLPreviewLSL::~LLPreviewLSL() | ||
1365 | { | ||
1366 | if (mScriptEd && !(mScriptEd->mXfname.empty())) | ||
1367 | { | ||
1368 | llinfos << "remove autosave: " << mScriptEd->mXfname << llendl; | ||
1369 | LLFile::remove(mScriptEd->mXfname.c_str()); | ||
1370 | } | ||
1371 | } | ||
1372 | |||
1346 | // virtual | 1373 | // virtual |
1347 | void LLPreviewLSL::callbackLSLCompileSucceeded() | 1374 | void LLPreviewLSL::callbackLSLCompileSucceeded() |
1348 | { | 1375 | { |
@@ -1443,10 +1470,10 @@ void LLPreviewLSL::closeIfNeeded() | |||
1443 | mPendingUploads--; | 1470 | mPendingUploads--; |
1444 | if (mPendingUploads <= 0 && mCloseAfterSave) | 1471 | if (mPendingUploads <= 0 && mCloseAfterSave) |
1445 | { | 1472 | { |
1446 | if( !mScriptEd->mXfname.empty()) | 1473 | if (mScriptEd && !mScriptEd->mAutosaveFilename.empty()) |
1447 | { | 1474 | { |
1448 | llinfos << "remove autosave: " << mScriptEd->mXfname << llendl; | 1475 | llinfos << "remove autosave: " << mScriptEd->mAutosaveFilename << llendl; |
1449 | LLFile::remove(mScriptEd->mXfname.c_str()); | 1476 | LLFile::remove(mScriptEd->mAutosaveFilename.c_str()); |
1450 | } | 1477 | } |
1451 | close(); | 1478 | close(); |
1452 | } | 1479 | } |
@@ -1901,7 +1928,12 @@ LLLiveLSLEditor::LLLiveLSLEditor(const std::string& name, | |||
1901 | } | 1928 | } |
1902 | 1929 | ||
1903 | LLLiveLSLEditor::~LLLiveLSLEditor() | 1930 | LLLiveLSLEditor::~LLLiveLSLEditor() |
1904 | { | 1931 | { |
1932 | if (mScriptEd && (!(mScriptEd->mXfname.empty()))) | ||
1933 | { | ||
1934 | llinfos << "remove autosave: " << mScriptEd->mXfname << llendl; | ||
1935 | LLFile::remove(mScriptEd->mXfname.c_str()); | ||
1936 | } | ||
1905 | LLLiveLSLEditor::sInstances.removeData(mItemID ^ mObjectID); | 1937 | LLLiveLSLEditor::sInstances.removeData(mItemID ^ mObjectID); |
1906 | } | 1938 | } |
1907 | 1939 | ||
@@ -2616,10 +2648,10 @@ void LLLiveLSLEditor::closeIfNeeded() | |||
2616 | mPendingUploads--; | 2648 | mPendingUploads--; |
2617 | if (mPendingUploads <= 0 && mCloseAfterSave) | 2649 | if (mPendingUploads <= 0 && mCloseAfterSave) |
2618 | { | 2650 | { |
2619 | if( !mScriptEd->mXfname.empty()) | 2651 | if (mScriptEd && (!mScriptEd->mAutosaveFilename.empty())) |
2620 | { | 2652 | { |
2621 | llinfos << "remove autosave: " << mScriptEd->mXfname << llendl; | 2653 | llinfos << "remove autosave: " << mScriptEd->mAutosaveFilename << llendl; |
2622 | LLFile::remove(mScriptEd->mXfname.c_str()); | 2654 | LLFile::remove(mScriptEd->mAutosaveFilename.c_str()); |
2623 | } | 2655 | } |
2624 | close(); | 2656 | close(); |
2625 | } | 2657 | } |