From 03d006a9d34200aac9672c2f765b76ad8e688429 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Tue, 13 Sep 2011 12:53:32 -0700 Subject: Fixed the script editor constantly searching for an update that doesn't exist (also some more cleanup) --- linden/indra/newview/llpreviewscript.cpp | 114 ++++++++++++++++++++----------- linden/indra/newview/llpreviewscript.h | 11 ++- 2 files changed, 78 insertions(+), 47 deletions(-) (limited to 'linden') 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( mSampleText(sample), mHelpURL(help_url), mEditor( NULL ), + mFunctions(NULL), + mErrorList(NULL), mLoadCallback( load_callback ), mSaveCallback( save_callback ), mSearchReplaceCallback( search_replace_callback ), mUserdata( userdata ), mForceClose( FALSE ), + mLiveHelpHandle(), + mLiveHelpTimer(), mLastHelpToken(NULL), mLiveHelpHistorySize(0), mEnableSave(FALSE), mEnableXEd(FALSE), + mXstbuf(), + mXfname(""), + mAutosaveFilename(""), mHasScriptData(FALSE), // We need to check for a new file every five seconds, or autosave every 60. // There's probably a better solution to both of the above. @@ -284,7 +291,11 @@ BOOL LLScriptEdCore::tick() } else { - XedUpd(); + // This should really be passed as a parameter -- MC + if (!mXfname.empty()) + { + xedUpdateScript(); + } } return FALSE; } @@ -509,7 +520,7 @@ void LLScriptEdCore::xedLaunch() fp = NULL; llinfos << "XEditor: " << mXfname << llendl; //record the stat - stat(mXfname.c_str(), &mXstbuf); + LLFile::stat(mXfname.c_str(), &mXstbuf); //launch #if LL_WINDOWS //just to get rid of the pesky black window @@ -561,43 +572,45 @@ void LLScriptEdCore::xedLaunch() #endif } -void LLScriptEdCore::XedUpd() +void LLScriptEdCore::xedUpdateScript() { - struct stat stbuf; - stat(this->mXfname.c_str() , &stbuf); - if (this->mXstbuf.st_mtime != stbuf.st_mtime) + llstat stbuf; + if (LLFile::stat(this->mXfname.c_str() , &stbuf) == 0) // info found { - this->mErrorList->addCommentText(std::string("Change Detected... Updating")); - - this->mXstbuf = stbuf; - LLFILE* file = LLFile::fopen(this->mXfname, "rb"); /*Flawfinder: ignore*/ - if(file) - { - // read in the whole file - fseek(file, 0L, SEEK_END); - S64 file_length = ftell(file); - fseek(file, 0L, SEEK_SET); - char* buffer = new char[file_length+1]; - size_t nread = fread(buffer, 1, file_length, file); - if (nread < (size_t) file_length) + if (this->mXstbuf.st_mtime != stbuf.st_mtime) + { + this->mErrorList->addCommentText(std::string("Change Detected... Updating")); + + this->mXstbuf = stbuf; + LLFILE* file = LLFile::fopen(this->mXfname, "rb"); /*Flawfinder: ignore*/ + if(file) + { + // read in the whole file + fseek(file, 0L, SEEK_END); + S64 file_length = ftell(file); + fseek(file, 0L, SEEK_SET); + char* buffer = new char[file_length+1]; + size_t nread = fread(buffer, 1, file_length, file); + if (nread < (size_t) file_length) + { + llwarns << "Short read" << llendl; + } + buffer[nread] = '\0'; + fclose(file); + std::string ttext = LLStringExplicit(buffer); + LLStringUtil::replaceTabsWithSpaces(ttext, 4); + mEditor->setText(ttext); + LLScriptEdCore::doSave( this, FALSE ); + //mEditor->makePristine(); + delete[] buffer; + buffer = NULL; + } + else { - llwarns << "Short read" << llendl; + llwarns << "Error opening " << this->mXfname << llendl; } - buffer[nread] = '\0'; - fclose(file); - std::string ttext = LLStringExplicit(buffer); - LLStringUtil::replaceTabsWithSpaces(ttext, 4); - mEditor->setText(ttext); - LLScriptEdCore::doSave( this, FALSE ); - //mEditor->makePristine(); - delete[] buffer; - buffer = NULL; - } - else - { - llwarns << "Error opening " << this->mXfname << llendl; } - } + } } //end dim void LLScriptEdCore::autoSave() @@ -725,6 +738,11 @@ bool LLScriptEdCore::handleSaveChangesDialog(const LLSD& notification, const LLS break; case 1: // "No" + if( !mAutosaveFilename.empty()) + { + llinfos << "remove autosave: " << mAutosaveFilename << llendl; + LLFile::remove(mAutosaveFilename.c_str()); + } if( !mXfname.empty()) { llinfos << "remove autosave: " << mXfname << llendl; @@ -1343,6 +1361,15 @@ LLPreviewLSL::LLPreviewLSL(const std::string& name, const LLRect& rect, } } +LLPreviewLSL::~LLPreviewLSL() +{ + if (mScriptEd && !(mScriptEd->mXfname.empty())) + { + llinfos << "remove autosave: " << mScriptEd->mXfname << llendl; + LLFile::remove(mScriptEd->mXfname.c_str()); + } +} + // virtual void LLPreviewLSL::callbackLSLCompileSucceeded() { @@ -1443,10 +1470,10 @@ void LLPreviewLSL::closeIfNeeded() mPendingUploads--; if (mPendingUploads <= 0 && mCloseAfterSave) { - if( !mScriptEd->mXfname.empty()) + if (mScriptEd && !mScriptEd->mAutosaveFilename.empty()) { - llinfos << "remove autosave: " << mScriptEd->mXfname << llendl; - LLFile::remove(mScriptEd->mXfname.c_str()); + llinfos << "remove autosave: " << mScriptEd->mAutosaveFilename << llendl; + LLFile::remove(mScriptEd->mAutosaveFilename.c_str()); } close(); } @@ -1901,7 +1928,12 @@ LLLiveLSLEditor::LLLiveLSLEditor(const std::string& name, } LLLiveLSLEditor::~LLLiveLSLEditor() -{ +{ + if (mScriptEd && (!(mScriptEd->mXfname.empty()))) + { + llinfos << "remove autosave: " << mScriptEd->mXfname << llendl; + LLFile::remove(mScriptEd->mXfname.c_str()); + } LLLiveLSLEditor::sInstances.removeData(mItemID ^ mObjectID); } @@ -2616,10 +2648,10 @@ void LLLiveLSLEditor::closeIfNeeded() mPendingUploads--; if (mPendingUploads <= 0 && mCloseAfterSave) { - if( !mScriptEd->mXfname.empty()) + if (mScriptEd && (!mScriptEd->mAutosaveFilename.empty())) { - llinfos << "remove autosave: " << mScriptEd->mXfname << llendl; - LLFile::remove(mScriptEd->mXfname.c_str()); + llinfos << "remove autosave: " << mScriptEd->mAutosaveFilename << llendl; + LLFile::remove(mScriptEd->mAutosaveFilename.c_str()); } close(); } diff --git a/linden/indra/newview/llpreviewscript.h b/linden/indra/newview/llpreviewscript.h index 4de886e..cb9cdf4 100644 --- a/linden/indra/newview/llpreviewscript.h +++ b/linden/indra/newview/llpreviewscript.h @@ -128,7 +128,7 @@ public: void autoSave(); //dim external ed - void XedUpd(); + void xedUpdateScript(); void xedLaunch(); virtual BOOL handleKeyHere(KEY key, MASK mask); @@ -150,9 +150,8 @@ private: std::string mSampleText; std::string mAutosaveFilename; std::string mXfname; - struct stat mXstbuf; + llstat mXstbuf; std::string mHelpURL; - std::string mScriptTitle; LLTextEditor* mEditor; void (*mLoadCallback)(void* userdata); void (*mSaveCallback)(void* userdata, BOOL close_after_save); @@ -160,8 +159,7 @@ private: void* mUserdata; LLComboBox *mFunctions; BOOL mForceClose; - //LLPanel* mGuiPanel; - LLPanel* mCodePanel; + //LLPanel* mCodePanel; LLScrollListCtrl* mErrorList; LLDynamicArray mBridges; LLHandle mLiveHelpHandle; @@ -180,9 +178,10 @@ class LLPreviewLSL : public LLPreview public: LLPreviewLSL(const std::string& name, const LLRect& rect, const std::string& title, const LLUUID& item_uuid ); + ~LLPreviewLSL(); + virtual void callbackLSLCompileSucceeded(); virtual void callbackLSLCompileFailed(const LLSD& compile_errors); - /*virtual*/ void open(); /*Flawfinder: ignore*/ protected: -- cgit v1.1