-
-
Notifications
You must be signed in to change notification settings - Fork 973
Feature: Persistant rotation of numbered autosave after restart #9397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Note that this PR and PR #9395 have conflicts. |
|
||
std::string_view name = list.begin()->title; | ||
std::from_chars(name.data() + this->prefix.size(), name.data() + name.size(), this->number); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lot of code for in a ctor. Somehow that triggers me. But I do not have any argument for it :P So it might be bullocks. Opinions? :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the thing has to be initialized somewhere and where else should it be, if not in the constructor? And the code seems fairly specific to this one particular problem, so it's not like refactoring anything into separate functions would have much of an advantage.
static fios_getlist_callback_proc *proc = [](SaveLoadOperation fop, const std::string &file, const char *ext, char *title, const char *last) { | ||
if (strcasecmp(ext, ".sav") == 0 && StrStartsWith(file, _prefix)) return FIOS_TYPE_FILE; | ||
return FIOS_TYPE_INVALID; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestions to make it a bit more clear what _prefix
is doing and that it is static:
static std::optional<std::string> _autosave_path;
if (!_autosave_path) _autosave_path = FioFindDirectory(AUTOSAVE_DIR);
static std::string _prefix; ///< Static as the lambda needs access to it.
/* Callback for FiosFileScanner. */
static fios_getlist_callback_proc *proc = [](SaveLoadOperation fop, const std::string &file, const char *ext, char *title, const char *last) {
if (strcasecmp(ext, ".sav") == 0 && StrStartsWith(file, _prefix)) return FIOS_TYPE_FILE;
return FIOS_TYPE_INVALID;
};
/* Prefix to check in the callback. */
_prefix = *_autosave_path + this->prefix;
? Dunno :)
It was always starting from 0 on openttd restart. Now the most recent autosave number will be used as a base to generate the next filename.
Function names are not the best. |
Fixes #9396
Motivation / Problem
Autosave numbering always starts from 0 when OpenTTD is started.
Description
Retrieve the number of the most recent autosave and use it as a base for the next one.
Limitations
If more than one OpenTTD instance is running, and if they share the same
autosave
directory, they will still overwrite each other savegames.Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.