/
AutoSaver.h
88 lines (61 loc) · 2.12 KB
/
AutoSaver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
#include <map>
#include "iregistry.h"
#include "imodule.h"
#include "imap.h"
#include <vector>
#include <sigc++/connection.h>
#include "os/fs.h"
#include "time/Timer.h"
/* greebo: The AutoMapSaver class lets itself being called in distinct intervals
* and saves the map files either to snapshots or to a single yyyy.autosave.map file.
*/
namespace map
{
class AutoMapSaver :
public RegisterableModule
{
// TRUE, if autosaving is enabled
bool _enabled;
// TRUE, if the autosaver generates snapshots
bool _snapshotsEnabled;
// The autosave interval stored in seconds
unsigned long _interval;
// The timer object that triggers the callback
std::unique_ptr<util::Timer> _timer;
std::size_t _changes;
std::vector<sigc::connection> _signalConnections;
public:
// Constructor
AutoMapSaver();
// RegisterableModule implementation
const std::string& getName() const override;
const StringSet& getDependencies() const override;
void initialiseModule(const IApplicationContext& ctx) override;
void shutdownModule() override;
~AutoMapSaver();
// Starts/stops the autosave "countdown"
void startTimer();
void stopTimer();
// Clears the _changes member variable that indicates how many changes have been made
void clearChanges();
private:
// Adds the elements to the according preference page
void constructPreferences();
void registryKeyChanged();
void onMapEvent(IMap::MapEvent ev);
// This performs is called to check if the map is valid/changed/should be saved
// and calls the save routines accordingly.
void checkSave();
// Saves a snapshot of the currently active map (only named maps)
void saveSnapshot();
// This gets called when the interval time is over
void onIntervalReached();
void collectExistingSnapshots(std::map<int, std::string>& existingSnapshots,
const fs::path& snapshotPath, const std::string& mapName);
void handleSnapshotSizeLimit(const std::map<int, std::string>& existingSnapshots,
const fs::path& snapshotPath, const std::string& mapName);
}; // class AutoMapSaver
// The accessor function for the static AutoSaver instance
AutoMapSaver& AutoSaver();
} // namespace map