aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-01-31 19:03:33 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2023-01-31 19:03:33 +0100
commitd9818df8791730130adc5349e863b35de0e1c351 (patch)
treed95b67ac4a28273f8b9d5c7bde6ee00ce333f8a4
parentd0e8abf2c50286733fc7c7d03d3ad752555194a0 (diff)
Improve config version management
-rw-r--r--src/ochess.cpp53
1 files changed, 35 insertions, 18 deletions
diff --git a/src/ochess.cpp b/src/ochess.cpp
index bf3a2ce..5ef3522 100644
--- a/src/ochess.cpp
+++ b/src/ochess.cpp
@@ -7,14 +7,33 @@ bool MyApp::OnInit() {
// Check config version
CONFIG_OPEN(conf);
- wxString version=conf->Read("version",CONFIG_VERSION);
- conf->Write("version",version); // Setup config file version
- wxLogDebug("Starting ochess with configuration file version %s",version);
+ wxString version = conf->Read("version", CONFIG_VERSION);
+ conf->Write("version", version); // Setup config file version
+ wxLogDebug("Starting ochess with configuration file version %s", version);
CONFIG_CLOSE(conf);
// Advertise for configuration file version
- if(version != CONFIG_VERSION)
- SHOW_DIALOG_INFO("Configuration files version missmatch. Expected "+std::string(CONFIG_VERSION)+" but got "+version+".\nPlease remove the current configuration file as it may crash the application.");
+ if (version != CONFIG_VERSION) {
+ wxMessageDialog *dial = new wxMessageDialog(
+ NULL,
+ wxT("Configuration files version missmatch. Expected " +
+ std::string(CONFIG_VERSION) + " but got " + version +
+ ".\nExisting OChess configuration must be erased.\n" +
+ "Do you still want to proceed?"),
+ wxT("Information"), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
+
+ if (dial->ShowModal() != wxID_YES)
+ return false;
+ // First remove everything:
+ CONFIG_OPEN(conf2);
+ conf2->DeleteAll();
+ conf2->Write("version", CONFIG_VERSION);
+ CONFIG_CLOSE(conf2);
+ // Now Create new configuration:
+ CONFIG_OPEN(conf3);
+ conf3->Write("version", CONFIG_VERSION);
+ CONFIG_CLOSE(conf3);
+ }
// Main frame
MainWindow *frame = new MainWindow();
@@ -25,28 +44,26 @@ bool MyApp::OnInit() {
std::vector<TabInfos *> MyApp::ListTabInfos() {
std::vector<TabInfos *> tinfos;
- wxAuiNotebook *notebook=((MainWindow *)this->GetTopWindow())->notebook;
+ wxAuiNotebook *notebook = ((MainWindow *)this->GetTopWindow())->notebook;
for (int i = 0; i < notebook->GetPageCount(); i++) {
tinfos.push_back(dynamic_cast<TabInfos *>(notebook->GetPage(i)));
}
return (tinfos);
}
-Openings& MyApp::GetBook() { return Book; }
+Openings &MyApp::GetBook() { return Book; }
-void MyApp::NewGame(TabInfos *tabsrc,std::shared_ptr<Game> g){
- MainWindow *w=((MainWindow *)this->GetTopWindow());
- TabInfos *i=w->NewGame(g);
+void MyApp::NewGame(TabInfos *tabsrc, std::shared_ptr<Game> g) {
+ MainWindow *w = ((MainWindow *)this->GetTopWindow());
+ TabInfos *i = w->NewGame(g);
i->Link(tabsrc); // Link opened game to tabsrc
}
-void MyApp::NewGame(std::shared_ptr<Game> g){
- MainWindow *w=((MainWindow *)this->GetTopWindow());
+void MyApp::NewGame(std::shared_ptr<Game> g) {
+ MainWindow *w = ((MainWindow *)this->GetTopWindow());
w->NewGame(g);
}
-
-
wxIMPLEMENT_APP(MyApp);
void Abort(std::string msg) {
@@ -56,9 +73,9 @@ void Abort(std::string msg) {
wxLogFatalError(wxString(msg));
}
-long TabInfos::tab_count=0;
-void TabInfos::Link(TabInfos *tab){
- this->is_linked=true;
- this->linked_id=tab->id;
+long TabInfos::tab_count = 0;
+void TabInfos::Link(TabInfos *tab) {
+ this->is_linked = true;
+ this->linked_id = tab->id;
this->OnLink();
} \ No newline at end of file