| 253 | } |
| 254 | |
| 255 | void 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 | |
| 294 | bool SubsController::CanSave() const { |
| 295 | try { |