summaryrefslogtreecommitdiff
path: root/indra/newview/llpreviewscript.cpp
diff options
context:
space:
mode:
authorMnikolenko Productengine <mnikolenko@productengine.com>2021-07-15 11:20:15 +0300
committerMnikolenko Productengine <mnikolenko@productengine.com>2021-07-15 11:21:21 +0300
commit881b12910fe44f479fca50cdee965f602bce3162 (patch)
tree272e8d3ca83c8fe33a55bb9b01a97efe8630ec27 /indra/newview/llpreviewscript.cpp
parent77aac9579170369a11f0884e16bd730f8cbb8bdb (diff)
parentbe6066eae218856f7fd74b98968a75e5062fa830 (diff)
Merge branch 'master' into DRTVWR-539
Diffstat (limited to 'indra/newview/llpreviewscript.cpp')
-rw-r--r--indra/newview/llpreviewscript.cpp52
1 files changed, 39 insertions, 13 deletions
diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp
index 4c539ded38..f13910cde5 100644
--- a/indra/newview/llpreviewscript.cpp
+++ b/indra/newview/llpreviewscript.cpp
@@ -636,14 +636,17 @@ bool LLScriptEdCore::writeToFile(const std::string& filename)
void LLScriptEdCore::sync()
{
- // Sync with external editor.
- std::string tmp_file = mContainer->getTmpFileName();
- llstat s;
- if (LLFile::stat(tmp_file, &s) == 0) // file exists
- {
- if (mLiveFile) mLiveFile->ignoreNextUpdate();
- writeToFile(tmp_file);
- }
+ // Sync with external editor.
+ if (mLiveFile)
+ {
+ std::string tmp_file = mLiveFile->filename();
+ llstat s;
+ if (LLFile::stat(tmp_file, &s) == 0) // file exists
+ {
+ mLiveFile->ignoreNextUpdate();
+ writeToFile(tmp_file);
+ }
+ }
}
bool LLScriptEdCore::hasChanged()
@@ -1027,9 +1030,25 @@ void LLScriptEdCore::openInExternalEditor()
{
delete mLiveFile; // deletes file
- // Save the script to a temporary file.
- std::string filename = mContainer->getTmpFileName();
- writeToFile(filename);
+ // Generate a suitable filename
+ std::string script_name = mScriptName;
+ std::string forbidden_chars = "<>:\"\\/|?*";
+ for (std::string::iterator c = forbidden_chars.begin(); c != forbidden_chars.end(); c++)
+ {
+ script_name.erase(std::remove(script_name.begin(), script_name.end(), *c), script_name.end());
+ }
+ std::string filename = mContainer->getTmpFileName(script_name);
+
+ // Save the script to a temporary file.
+ if (!writeToFile(filename))
+ {
+ // In case some characters from script name are forbidden
+ // and not accounted for, name is too long or some other issue,
+ // try file that doesn't include script name
+ script_name.clear();
+ filename = mContainer->getTmpFileName(script_name);
+ writeToFile(filename);
+ }
// Start watching file changes.
mLiveFile = new LLLiveLSLFile(filename, boost::bind(&LLScriptEdContainer::onExternalChange, mContainer, _1));
@@ -1419,7 +1438,7 @@ LLScriptEdContainer::LLScriptEdContainer(const LLSD& key) :
{
}
-std::string LLScriptEdContainer::getTmpFileName()
+std::string LLScriptEdContainer::getTmpFileName(const std::string& script_name)
{
// Take script inventory item id (within the object inventory)
// to consideration so that it's possible to edit multiple scripts
@@ -1431,7 +1450,14 @@ std::string LLScriptEdContainer::getTmpFileName()
LLMD5 script_id_hash((const U8 *)script_id.c_str());
script_id_hash.hex_digest(script_id_hash_str);
- return std::string(LLFile::tmpdir()) + "sl_script_" + script_id_hash_str + ".lsl";
+ if (script_name.empty())
+ {
+ return std::string(LLFile::tmpdir()) + "sl_script_" + script_id_hash_str + ".lsl";
+ }
+ else
+ {
+ return std::string(LLFile::tmpdir()) + "sl_script_" + script_name + "_" + script_id_hash_str + ".lsl";
+ }
}
bool LLScriptEdContainer::onExternalChange(const std::string& filename)