Added migration for old logs

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-06-01 23:48:48 +03:00
parent 6c082403c4
commit 3a6657596b
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318

View File

@ -376,9 +376,18 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
// init the logger // init the logger
{ {
static const QString logBase = FS::PathCombine("logs", BuildConfig.LAUNCHER_NAME + "-%0.log"); static const QString baseLogFile = BuildConfig.LAUNCHER_NAME + "-%0.log";
FS::ensureFolderPathExists( static const QString logBase = FS::PathCombine("logs", baseLogFile);
"logs"); // this can fail, but there is no need to throw an error *yet*, since it also triggers the error message below! if (FS::ensureFolderPathExists("logs")) { // if this did not fail
for (auto i = 0; i <= 4; i++) {
auto oldName = baseLogFile.arg(i);
auto newName = logBase.arg(i);
if (QFile::exists(newName)) // in case there are already files in folder just to be safe add a suffix
newName += ".old";
QFile::rename(oldName, newName);
}
}
auto moveFile = [](const QString& oldName, const QString& newName) { auto moveFile = [](const QString& oldName, const QString& newName) {
QFile::remove(newName); QFile::remove(newName);
QFile::copy(oldName, newName); QFile::copy(oldName, newName);