Do autosaves

This commit is contained in:
2025-03-02 12:03:52 -06:00
committed by Celtic Minstrel
parent 53de92c932
commit 5bc1643be7
7 changed files with 63 additions and 3 deletions

View File

@@ -35,6 +35,7 @@ std::vector<std::pair<fs::path, std::time_t>> sorted_file_mtimes(fs::path dir, s
bool load_party(fs::path file_to_load, cUniverse& univ);
bool save_party(cUniverse& univ, bool save_as = false);
bool save_party_force(cUniverse& univ, fs::path file);
void init_directories(const char* exec_path);

View File

@@ -444,9 +444,12 @@ bool load_party_v2(fs::path file_to_load, cUniverse& real_univ){
return true;
}
static bool save_party_const(const cUniverse& univ, bool save_as) {
static bool save_party_const(const cUniverse& univ, bool save_as, fs::path dest_file = "") {
// Make sure it has the proper file extension
fs::path dest_file = univ.file;
if(dest_file.empty()){
dest_file = univ.file;
}
if(dest_file.extension() != ".exg"){
dest_file += ".exg";
}
@@ -555,6 +558,10 @@ bool save_party(cUniverse& univ, bool save_as) {
return save_party_const(univ, save_as);
}
bool save_party_force(cUniverse& univ, fs::path file) {
return save_party_const(univ, false, file);
}
static bool compare_mtime(std::pair<fs::path, std::time_t> a, std::pair<fs::path, std::time_t> b) {
return std::difftime(a.second, b.second) > 0;
}