From b97caa77d462a4c1fd220eb63ecc9c23750b88bf Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Wed, 10 Jul 2013 21:06:45 +0200 Subject: [PATCH] Add versioning support to AIFilePicker. When saving a file, if the suggested filename has the form PREFIX?000.EXT then the viewer checks if that file already exists and if so, increments the number until it finds a name that does not already exist (in the suggested directory). The '?' is replaced with an underscore. This allows to fast saving of the same data without overwriting previous data. --- indra/newview/statemachine/aifilepicker.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/indra/newview/statemachine/aifilepicker.cpp b/indra/newview/statemachine/aifilepicker.cpp index 3cc3ccbcd..735c1d7ec 100644 --- a/indra/newview/statemachine/aifilepicker.cpp +++ b/indra/newview/statemachine/aifilepicker.cpp @@ -39,6 +39,7 @@ #include "llpluginmessageclasses.h" #include "llsdserialize.h" #include "aifilepicker.h" +#include "lldir.h" #if LL_WINDOWS #include "llviewerwindow.h" #endif @@ -195,9 +196,26 @@ void AIFilePicker::open(ELoadFilter filter, std::string const& default_path, std void AIFilePicker::open(std::string const& filename, ESaveFilter filter, std::string const& default_path, std::string const& context) { - mFilename = filename; + mFilename = LLDir::getScrubbedFileName(filename); mContext = context; mFolder = AIFilePicker::get_folder(default_path, context); + // If the basename of filename ends on "?000", then check if a file with that name exists and if so, increment the number. + std::string basename = gDirUtilp->getBaseFileName(filename, true); + size_t len = basename.size(); + if (len >= 4 && basename.substr(len - 4) == "?000") + { + basename = LLDir::getScrubbedFileName(basename.substr(0, len - 4)); + std::string extension = gDirUtilp->getExtension(mFilename); + for (int n = 0;; ++n) + { + mFilename = llformat("%s_%03u.%s", basename.c_str(), n, extension.c_str()); + std::string fullpath = mFolder + gDirUtilp->getDirDelimiter() + mFilename; + if (n == 999 || !gDirUtilp->fileExists(fullpath)) + { + break; + } + } + } mOpenType = save; switch(filter) {