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.
This commit is contained in:
Aleric Inglewood
2013-07-10 21:06:45 +02:00
parent 4779f91d5d
commit b97caa77d4

View File

@@ -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)
{