commit 37c94806566fdd13bef1fe5bfeda64ceb839f6a3 Author: José Matos <jama...@lyx.org> Date: Wed May 9 08:53:28 2018 +0100
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. --- src/Buffer.cpp | 27 +++++++++++++++++++++++++-- 1 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 5a0bd74..83a82f8 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -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