MCPcopy Create free account
hub / github.com/clementgallet/libTAS / removeOldSaves

Method removeOldSaves

src/program/AutoSave.cpp:71–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71void AutoSave::removeOldSaves(Context* context, const std::string& moviename)
72{
73 /* Scanning the directory of savefiles. We can't pass a filter function as
74 * lambda because only non-capturing lambdas can be converted to function
75 * pointers. We must filter when iterating. */
76
77 /* We use a set to order files alphabetically */
78 std::set<std::filesystem::path> sorted_files;
79
80 for (auto &entry : std::filesystem::directory_iterator(context->config.tempmoviedir))
81 sorted_files.insert(entry.path());
82
83 int matches = 0;
84 for (auto filename_it = sorted_files.rbegin(); filename_it != sorted_files.rend(); filename_it++) {
85 std::string tempfilename = filename_it->filename().string();
86 if ((tempfilename.size() == (moviename.size() + 20)) &&
87 (0 == tempfilename.compare(0, moviename.size(), moviename))) {
88 /* We found a matching autosave */
89 matches++;
90 if (matches > context->config.autosave_count) {
91 /* Removing the autosave */
92 std::cout << "Remove autosave movie " << *filename_it << std::endl;
93 std::filesystem::remove(*filename_it);
94 }
95 }
96 else {
97 /* Little optimisation. If we already had a match, then we won't
98 * have any more matches, so we can stop here */
99 if (matches > 0)
100 break;
101 }
102 }
103}

Callers

nothing calls this directly

Calls 5

removeFunction · 0.85
rbeginMethod · 0.80
rendMethod · 0.80
insertMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected