MCPcopy Create free account
hub / github.com/TypesettingTools/Aegisub / AutoSave

Method AutoSave

src/subs_controller.cpp:255–292  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

253}
254
255void SubsController::AutoSave() {
256 if (commit_id == autosaved_commit_id)
257 return;
258
259 auto directory = context->path->Decode(OPT_GET("Path/Auto/Save")->GetString());
260 if (directory.empty())
261 directory = filename.parent_path();
262
263 auto name = filename.filename();
264 if (name.empty())
265 name = "Untitled";
266
267 autosaved_commit_id = commit_id;
268 auto frame = context->frame;
269 auto subs_copy = new AssFile(*context->ass);
270 autosave_queue->Async([subs_copy, name, directory, frame] {
271 wxString msg;
272 std::unique_ptr<AssFile> subs(subs_copy);
273
274 try {
275 agi::fs::CreateDirectory(directory);
276 auto path = directory / agi::format("%s.%s.AUTOSAVE.ass", name.string(),
277 agi::util::strftime("%Y-%m-%d-%H-%M-%S"));
278 SubtitleFormat::GetWriter(path)->WriteFile(subs.get(), path, 0);
279 msg = fmt_tl("File backup saved as \"%s\".", path);
280 }
281 catch (const agi::Exception& err) {
282 msg = to_wx("Exception when attempting to autosave file: " + err.GetMessage());
283 }
284 catch (...) {
285 msg = "Unhandled exception when attempting to autosave file.";
286 }
287
288 agi::dispatch::Main().Async([frame, msg] {
289 frame->StatusTimeout(msg);
290 });
291 });
292}
293
294bool SubsController::CanSave() const {
295 try {

Callers

nothing calls this directly

Calls 9

strftimeFunction · 0.85
DecodeMethod · 0.80
AsyncMethod · 0.80
stringMethod · 0.80
StatusTimeoutMethod · 0.80
formatFunction · 0.70
to_wxFunction · 0.70
WriteFileMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected