int SaveGameIterator::CreateSaveGame(int index, bool mqs) { AutoTable tab("savegame"); const char *slotname = NULL; int qsave = 0; if (tab) { slotname = tab->QueryField(index); qsave = atoi(tab->QueryField(index, 1)); } if (mqs) { assert(qsave); PruneQuickSave(slotname); } if (int cansave = CanSave()) return cansave; //if index is not an existing savegame, we create a unique slotname for (size_t i = 0; i < save_slots.size(); ++i) { Holder<SaveGame> save = save_slots[i]; if (save->GetSaveID() == index) { DeleteSaveGame(save); break; } } char Path[_MAX_PATH]; GameControl *gc = core->GetGameControl(); if (!CreateSavePath(Path, index, slotname)) { displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN); if (gc) { gc->SetDisplayText(STR_CANTSAVE, 30); } return -1; } if (!DoSaveGame(Path)) { displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN); if (gc) { gc->SetDisplayText(STR_CANTSAVE, 30); } return -1; } // Save succesful / Quick-save succesful if (qsave) { displaymsg->DisplayConstantString(STR_QSAVESUCCEED, DMC_BG2XPGREEN); if (gc) { gc->SetDisplayText(STR_QSAVESUCCEED, 30); } } else { displaymsg->DisplayConstantString(STR_SAVESUCCEED, DMC_BG2XPGREEN); if (gc) { gc->SetDisplayText(STR_SAVESUCCEED, 30); } } return 0; }
void PropEditCtrlTxt::OnText(wxCommandEvent& event) { if (CanSave()) { WriteValue(); EditorFrame::Get()->NotifyChanged(CHANGED_PROPS); } }
int SaveGameIterator::CreateSaveGame(Holder<SaveGame> save, const char *slotname) { if (!slotname) { return -1; } if (int cansave = CanSave()) return cansave; GameControl *gc = core->GetGameControl(); int index; if (save) { index = save->GetSaveID(); DeleteSaveGame(save); save.release(); } else { //leave space for autosaves //probably the hardcoded slot names should be read by this object //in that case 7 == size of hardcoded slot names array (savegame.2da) index = 7; for (size_t i = 0; i < save_slots.size(); ++i) { Holder<SaveGame> save = save_slots[i]; if (save->GetSaveID() >= index) { index = save->GetSaveID() + 1; } } } char Path[_MAX_PATH]; if (!CreateSavePath(Path, index, slotname)) { displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN); if (gc) { gc->SetDisplayText(STR_CANTSAVE, 30); } return -1; } if (!DoSaveGame(Path)) { displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN); if (gc) { gc->SetDisplayText(STR_CANTSAVE, 30); } return -1; } // Save succesful displaymsg->DisplayConstantString(STR_SAVESUCCEED, DMC_BG2XPGREEN); if (gc) { gc->SetDisplayText(STR_SAVESUCCEED, 30); } return 0; }
void udCodeEditorPanel::OnKeyDown(wxKeyEvent& event) { switch( event.GetKeyCode() ) { case 's': case 'S': if( event.AltDown() && CanSave() ) { wxCommandEvent evt; OnSave( evt ); } else event.Skip(); break; default: event.Skip(); } }
void udCodeEditorPanel::OnUpdateSave(wxUpdateUIEvent& event) { event.Enable( CanSave() ); }
void SubsController::Load(agi::fs::path const& filename, std::string charset) { try { if (charset.empty()) charset = CharSetDetect::GetEncoding(filename); } catch (agi::UserCancelException const&) { return; } // Make sure that file isn't actually a timecode file if (charset != "binary") { try { TextFileReader testSubs(filename, charset); std::string cur = testSubs.ReadLineFromFile(); if (boost::starts_with(cur, "# timecode")) { context->videoController->LoadTimecodes(filename); return; } } catch (...) { // if trying to load the file as timecodes fails it's fairly // safe to assume that it is in fact not a timecode file } } const SubtitleFormat *reader = SubtitleFormat::GetReader(filename); try { AssFile temp; reader->ReadFile(&temp, filename, charset); bool found_style = false; bool found_dialogue = false; // Check if the file has at least one style and at least one dialogue line for (auto const& line : temp.Line) { AssEntryGroup type = line.Group(); if (type == AssEntryGroup::STYLE) found_style = true; if (type == AssEntryGroup::DIALOGUE) found_dialogue = true; if (found_style && found_dialogue) break; } // And if it doesn't add defaults for each if (!found_style) temp.InsertLine(new AssStyle); if (!found_dialogue) temp.InsertLine(new AssDialogue); context->ass->swap(temp); } catch (agi::UserCancelException const&) { return; } catch (agi::fs::FileNotFound const&) { wxMessageBox(filename.wstring() + " not found.", "Error", wxOK | wxICON_ERROR | wxCENTER, context->parent); config::mru->Remove("Subtitle", filename); return; } catch (agi::Exception const& err) { wxMessageBox(to_wx(err.GetChainedMessage()), "Error", wxOK | wxICON_ERROR | wxCENTER, context->parent); return; } catch (std::exception const& err) { wxMessageBox(to_wx(err.what()), "Error", wxOK | wxICON_ERROR | wxCENTER, context->parent); return; } catch (...) { wxMessageBox("Unknown error", "Error", wxOK | wxICON_ERROR | wxCENTER, context->parent); return; } SetFileName(filename); // Push the initial state of the file onto the undo stack undo_stack.clear(); redo_stack.clear(); autosaved_commit_id = saved_commit_id = commit_id + 1; context->ass->Commit("", AssFile::COMMIT_NEW); // Save backup of file if (CanSave() && OPT_GET("App/Auto/Backup")->GetBool()) { auto path_str = OPT_GET("Path/Auto/Backup")->GetString(); agi::fs::path path; if (path_str.empty()) path = filename.parent_path(); else path = config::path->Decode(path_str); agi::fs::CreateDirectory(path); agi::fs::Copy(filename, path/(filename.stem().string() + ".ORIGINAL" + filename.extension().string())); } FileOpen(filename); }
void SubsController::OnCommit(AssFileCommit c) { if (c.message.empty() && !undo_stack.empty()) return; static int next_commit_id = 1; commit_id = next_commit_id++; // Allow coalescing only if it's the last change and the file has not been // saved since the last change if (commit_id == *c.commit_id+1 && redo_stack.empty() && saved_commit_id+1 != commit_id && autosaved_commit_id+1 != commit_id) { // If only one line changed just modify it instead of copying the file if (c.single_line) { entryIter this_it = context->ass->Line.begin(), undo_it = undo_stack.back().file.Line.begin(); while (&*this_it != c.single_line) { ++this_it; ++undo_it; } undo_stack.back().file.Line.insert(undo_it, *c.single_line->Clone()); delete &*undo_it; } else undo_stack.back().file = *context->ass; *c.commit_id = commit_id; return; } redo_stack.clear(); undo_stack.emplace_back(*context->ass, c.message, commit_id); int depth = std::max<int>(OPT_GET("Limits/Undo Levels")->GetInt(), 2); while ((int)undo_stack.size() > depth) undo_stack.pop_front(); if (undo_stack.size() > 1 && OPT_GET("App/Auto/Save on Every Change")->GetBool() && !filename.empty() && CanSave()) Save(filename); *c.commit_id = commit_id; }