summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Kleshchev <andreykproductengine@lindenlab.com>2024-05-15 20:57:28 +0300
committerAndrey Kleshchev <117672381+akleshchev@users.noreply.github.com>2024-05-15 23:36:29 +0300
commit43603fedba457545379c07a4a96ee1ba99e19b8c (patch)
treef91b3eef5763bd978276dbeed7a83194fe0abca5
parenta266a4356f1dfb60514abf81a7f27e9f49156086 (diff)
jira-archive-internal#67837 Windows' bulk export of snapshots and textures
Properly sanitize names Better duplicate avoidance
-rw-r--r--indra/newview/llpreviewtexture.cpp71
-rw-r--r--indra/newview/llpreviewtexture.h1
2 files changed, 45 insertions, 27 deletions
diff --git a/indra/newview/llpreviewtexture.cpp b/indra/newview/llpreviewtexture.cpp
index 28428112a1..91b8f0496e 100644
--- a/indra/newview/llpreviewtexture.cpp
+++ b/indra/newview/llpreviewtexture.cpp
@@ -67,6 +67,7 @@ const F32 PREVIEW_TEXTURE_MIN_ASPECT = 0.005f;
LLPreviewTexture::LLPreviewTexture(const LLSD& key)
: LLPreview(key),
mLoadingFullImage( false ),
+ mSavingMultiple(false),
mShowKeepDiscard(false),
mCopyToInv(false),
mIsCopyable(false),
@@ -310,9 +311,12 @@ void LLPreviewTexture::saveTextureToFile(const std::vector<std::string>& filenam
// remember the user-approved/edited file name.
mSaveFileName = filenames[0];
+ mSavingMultiple = false;
mLoadingFullImage = true;
getWindow()->incBusyCount();
+ LL_DEBUGS("FileSaveAs") << "Scheduling saving file to " << mSaveFileName << LL_ENDL;
+
mImage->forceToSaveRawImage(0);//re-fetch the raw image if the old one is removed.
mImage->setLoadedCallback(LLPreviewTexture::onFileLoadedForSave,
0, true, false, new LLUUID(mItemUUID), &mCallbackTextureList);
@@ -322,35 +326,16 @@ void LLPreviewTexture::saveTextureToFile(const std::vector<std::string>& filenam
void LLPreviewTexture::saveMultipleToFile(const std::string& file_name)
{
std::string texture_location(gSavedSettings.getString("TextureSaveLocation"));
- std::string texture_name = file_name.empty() ? getItem()->getName() : file_name;
-
- std::string filepath;
- S32 i = 0;
- S32 err = 0;
- std::string extension(".png");
- do
- {
- filepath = texture_location;
- filepath += gDirUtilp->getDirDelimiter();
- filepath += texture_name;
-
- if (i != 0)
- {
- filepath += llformat("_%.3d", i);
- }
+ std::string texture_name = LLDir::getScrubbedFileName(file_name.empty() ? getItem()->getName() : file_name);
- filepath += extension;
+ mSaveFileName = texture_location + gDirUtilp->getDirDelimiter() + texture_name + ".png";
- llstat stat_info;
- err = LLFile::stat( filepath, &stat_info );
- i++;
- } while (-1 != err); // Search until the file is not found (i.e., stat() gives an error).
-
-
- mSaveFileName = filepath;
+ mSavingMultiple = true;
mLoadingFullImage = true;
getWindow()->incBusyCount();
+ LL_DEBUGS("FileSaveAs") << "Scheduling saving file to " << mSaveFileName << LL_ENDL;
+
mImage->forceToSaveRawImage(0);//re-fetch the raw image if the old one is removed.
mImage->setLoadedCallback(LLPreviewTexture::onFileLoadedForSave,
0, true, false, new LLUUID(mItemUUID), &mCallbackTextureList);
@@ -451,8 +436,39 @@ void LLPreviewTexture::onFileLoadedForSave(bool success,
if( self && final && success )
{
+ LL_DEBUGS("FileSaveAs") << "Saving file to " << self->mSaveFileName << LL_ENDL;
const U32 ext_length = 3;
std::string extension = self->mSaveFileName.substr( self->mSaveFileName.length() - ext_length);
+
+ std::string filepath;
+ if (self->mSavingMultiple)
+ {
+ std::string part_path = self->mSaveFileName.substr(0, self->mSaveFileName.length() - ext_length - 1);
+
+ S32 i = 0;
+ S32 err = 0;
+ do
+ {
+ filepath = part_path;
+
+ if (i != 0)
+ {
+ filepath += llformat("_%.3d", i);
+ }
+
+ filepath += ".";
+ filepath += extension;
+
+ llstat stat_info;
+ err = LLFile::stat(filepath, &stat_info);
+ i++;
+ } while (-1 != err); // Search until the file is not found (i.e., stat() gives an error).
+ }
+ else
+ {
+ filepath = self->mSaveFileName;
+ }
+
LLStringUtil::toLower(extension);
// We only support saving in PNG or TGA format
LLPointer<LLImageFormatted> image;
@@ -468,13 +484,13 @@ void LLPreviewTexture::onFileLoadedForSave(bool success,
if( image && !image->encode( src, 0 ) )
{
LLSD args;
- args["FILE"] = self->mSaveFileName;
+ args["FILE"] = filepath;
LLNotificationsUtil::add("CannotEncodeFile", args);
}
- else if( image && !image->save( self->mSaveFileName ) )
+ else if( image && !image->save(filepath) )
{
LLSD args;
- args["FILE"] = self->mSaveFileName;
+ args["FILE"] = filepath;
LLNotificationsUtil::add("CannotWriteFile", args);
}
else
@@ -482,6 +498,7 @@ void LLPreviewTexture::onFileLoadedForSave(bool success,
self->mSavedFileTimer.reset();
self->mSavedFileTimer.setTimerExpirySec( SECONDS_TO_SHOW_FILE_SAVED_MSG );
}
+ LL_DEBUGS("FileSaveAs") << "Done saving file to " << filepath << LL_ENDL;
self->mSaveFileName.clear();
}
diff --git a/indra/newview/llpreviewtexture.h b/indra/newview/llpreviewtexture.h
index fdc6dddb38..e8a0a43245 100644
--- a/indra/newview/llpreviewtexture.h
+++ b/indra/newview/llpreviewtexture.h
@@ -86,6 +86,7 @@ private:
S32 mImageOldBoostLevel;
std::string mSaveFileName;
LLFrameTimer mSavedFileTimer;
+ bool mSavingMultiple;
bool mLoadingFullImage;
bool mShowKeepDiscard;
bool mCopyToInv;