| 198 | } |
| 199 | |
| 200 | void SubsController::Save(agi::fs::path const& filename, const char *encoding) { |
| 201 | const SubtitleFormat *writer = SubtitleFormat::GetWriter(filename); |
| 202 | if (!writer) |
| 203 | throw agi::InvalidInputException("Unknown file type."); |
| 204 | |
| 205 | int old_autosaved_commit_id = autosaved_commit_id, old_saved_commit_id = saved_commit_id; |
| 206 | try { |
| 207 | autosaved_commit_id = saved_commit_id = commit_id; |
| 208 | |
| 209 | // Have to set this now for the sake of things that want to save paths |
| 210 | // relative to the script in the header |
| 211 | this->filename = filename; |
| 212 | context->path->SetToken("?script", filename.parent_path()); |
| 213 | |
| 214 | context->ass->CleanExtradata(); |
| 215 | writer->WriteFile(context->ass.get(), filename, 0, encoding); |
| 216 | FileSave(); |
| 217 | } |
| 218 | catch (...) { |
| 219 | autosaved_commit_id = old_autosaved_commit_id; |
| 220 | saved_commit_id = old_saved_commit_id; |
| 221 | throw; |
| 222 | } |
| 223 | |
| 224 | SetFileName(filename); |
| 225 | } |
| 226 | |
| 227 | void SubsController::Close() { |
| 228 | undo_stack.clear(); |