Simplify the backup names when using an older file format.

Currently if we have a 2.3 file and we open it with a more recent version
we get:

original file: file.lyx
backup file:   file-lyxformat-544.lyx~

After this commit the backup file becomes

file-lyx23.lyx~

If the file is from a development version then we get the same result as before.
This commit is contained in:
José Matos 2018-05-09 08:53:28 +01:00
parent bde1834f7e
commit 37c9480656

View File

@ -1329,14 +1329,37 @@ Buffer::ReadStatus Buffer::convertLyXFormat(FileName const & fn,
FileName Buffer::getBackupName() const {
map<int, string> const file_formats = {
{544, "23"},
{508, "22"},
{474, "21"},
{413, "20"},
{345, "16"},
{276, "15"},
{245, "14"},
{221, "13"},
{220, "12"},
{218, "1163"},
{217, "116"},
{216, "115"},
{215, "11"},
{210, "010"},
{200, "006"}
};
FileName const & fn = fileName();
string const fname = fn.onlyFileNameWithoutExt();
string const fext = fn.extension() + "~";
string const fpath = lyxrc.backupdir_path.empty() ?
fn.onlyPath().absFileName() :
lyxrc.backupdir_path;
string const fform = convert<string>(d->file_format);
string const backname = fname + "-lyxformat-" + fform;
string backup_suffix;
// If file format is from a stable series use version instead of file format
auto const it = file_formats.find(d->file_format);
if (it != file_formats.end())
backup_suffix = "-lyx" + it->second;
else
backup_suffix = "-lyxformat-" + convert<string>(d->file_format);
string const backname = fname + backup_suffix;
FileName backup(addName(fpath, addExtension(backname, fext)));
// limit recursion, just in case