diff --git a/config/gimx-config.cpp b/config/gimx-config.cpp index 358c792d..8b784a5f 100644 --- a/config/gimx-config.cpp +++ b/config/gimx-config.cpp @@ -38,6 +38,9 @@ #define _CN(STRING) locale->GetString(wxString(STRING.c_str(), wxConvUTF8)) +#define TO_STRING(WXSTRING) string(WXSTRING.mb_str(wxConvUTF8)) +#define TO_WXSTRING(STRING) wxString(STRING.c_str(), wxConvUTF8) + using namespace std; //(*IdInit(configFrame) @@ -563,13 +566,11 @@ void configFrame::readLabels() } wxString file; - wxString filepath; wxString filespec = wxT("*.xml"); for (bool cont = dir.GetFirst(&file, filespec, wxDIR_FILES); cont; cont = dir.GetNext(&file)) { - filepath = default_directory + file; - ConfigurationFile::GetLabels(string(filepath.mb_str(wxConvUTF8)), button_labels, axis_labels); + ConfigurationFile::GetLabels(TO_STRING(default_directory), TO_STRING(file), button_labels, axis_labels); } button_labels.sort(compare_nocase); @@ -1361,7 +1362,6 @@ configFrame::configFrame(wxString file,wxWindow* parent, wxWindowID id __attribu StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1); StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1); SetStatusBar(StatusBar1); - FileDialog1 = new wxFileDialog(this, _("Select file"), wxEmptyString, wxEmptyString, _("XML files (*.xml)|*.xml"), wxFD_DEFAULT_STYLE|wxFD_OPEN, wxDefaultPosition, wxDefaultSize, _T("wxFileDialog")); GridSizer1->Fit(this); GridSizer1->SetSizeHints(this); @@ -1450,6 +1450,7 @@ configFrame::configFrame(wxString file,wxWindow* parent, wxWindowID id __attribu Connect(ID_MENUITEM27,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&configFrame::OnMenuAutoBindControls); Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&configFrame::OnAbout); //*) + Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(configFrame::OnClose), NULL, this); GridPanelButton->SetSelectionMode(wxGrid::wxGridSelectRows); GridPanelAxis->SetSelectionMode(wxGrid::wxGridSelectRows); @@ -1507,7 +1508,7 @@ configFrame::configFrame(wxString file,wxWindow* parent, wxWindowID id __attribu } } - FileDialog1->SetDirectory(default_directory); + configFile.SetDirectory(TO_STRING(default_directory)); GridPanelButton->SetDefaultColSize(wxGRID_AUTOSIZE); GridPanelButton->SetRowLabelSize(20); @@ -1525,43 +1526,8 @@ configFrame::configFrame(wxString file,wxWindow* parent, wxWindowID id __attribu evcatch = EventCatcher::getInstance(); - /* Open the file given as argument */ - if(!file.IsEmpty()) - { - wxString wxfile = default_directory + file; - - if(::wxFileExists(wxfile)) - { - int ret = configFile.ReadConfigFile(string(wxfile.mb_str(wxConvUTF8))); - - if(ret < 0) - { - wxMessageBox(wxString(configFile.GetError().c_str(), wxConvUTF8), _("Error"), wxICON_ERROR); - } - else if(ret > 0) - { - wxMessageBox(wxString(configFile.GetInfo().c_str(), wxConvUTF8), _("Info"), wxICON_INFORMATION); - } - - MenuItemMultipleMiceAndKeyboards->Check(configFile.MultipleMK()); - if(MenuItemMultipleMiceAndKeyboards->IsChecked()) - { - MenuItemReplaceMouse->Enable(true); - MenuItemReplaceKeyboard->Enable(true); - } - else - { - MenuItemReplaceMouse->Enable(false); - MenuItemReplaceKeyboard->Enable(false); - } - load_current(); - MenuFile->Enable(idMenuSave, true); - FileDialog1->SetFilename(file); - } - else - { - wxMessageBox( _("Cannot open config file: ") + file, _("Error"), wxICON_ERROR); - } + if (!file.IsEmpty()) { + openConfiguration(default_directory, file); } readLabels(); @@ -1586,6 +1552,32 @@ configFrame::~configFrame() //*) } +void configFrame::checkSave() +{ + save_current(); + if (!configFile.GetFile().empty()) { + if (!(openedConfigFile == configFile)) { + int answer = wxMessageBox(_("Do you want to save your configuration?"), TO_WXSTRING(configFile.GetFile()), wxYES_NO); + if (answer == wxYES) { + wxCommandEvent e; + OnMenuSave(e); + } + } + } else if (!configFile.IsEmpty()) { + int answer = wxMessageBox(_("Do you want to save your configuration?"), wxEmptyString, wxYES_NO); + if (answer == wxYES) { + wxCommandEvent e; + OnMenuSaveAs(e); + } + } +} + +void configFrame::OnClose(wxCloseEvent& event) +{ + checkSave(); + event.Skip(); +} + void configFrame::OnQuit(wxCommandEvent& event __attribute__((unused))) { Close(); @@ -1611,8 +1603,13 @@ void configFrame::OnAbout(wxCommandEvent& event __attribute__((unused))) */ void configFrame::OnMenuItemNew(wxCommandEvent& event __attribute__((unused))) { - FileDialog1->SetFilename(wxEmptyString); + checkSave(); + + wxTopLevelWindow::SetTitle(wxT("Gimx-config")); configFile = ConfigurationFile(); + configFile.SetDirectory(TO_STRING(default_directory)); + configFile.SetFile(""); + openedConfigFile = ConfigurationFile(); currentController = 0; currentProfile = 0; @@ -2674,37 +2671,27 @@ void configFrame::refresh_gui() Refresh(); } -/* - * \brief Method called on File>Open click. - */ -void configFrame::OnMenuOpen(wxCommandEvent& event __attribute__((unused))) +void configFrame::openConfiguration(const wxString& directory, const wxString& file) { - int ret; - - if ( FileDialog1->ShowModal() != wxID_OK ) return; - - wxString FileName = FileDialog1->GetPath(); - if ( FileName.IsEmpty() ) return; + if (!::wxFileExists (directory + "/" + file)) { + wxMessageBox( _("Cannot open config file: ") + file, _("Error"), wxICON_ERROR); + return; + } - ret = configFile.ReadConfigFile(string(FileName.mb_str(wxConvUTF8))); + int ret = configFile.ReadConfigFile(TO_STRING(directory), TO_STRING(file)); - if(ret < 0) - { - wxMessageBox(wxString(configFile.GetError().c_str(), wxConvUTF8), _("Error"), wxICON_ERROR); - } - else if(ret > 0) - { - wxMessageBox(wxString(configFile.GetInfo().c_str(), wxConvUTF8), _("Info"), wxICON_INFORMATION); + if (ret < 0) { + wxMessageBox(TO_WXSTRING(configFile.GetError()), _("Error"), wxICON_ERROR); + return; + } else if (ret > 0) { + wxMessageBox(TO_WXSTRING(configFile.GetInfo()), _("Info"), wxICON_INFORMATION); } MenuItemMultipleMiceAndKeyboards->Check(configFile.MultipleMK()); - if(MenuItemMultipleMiceAndKeyboards->IsChecked()) - { + if (MenuItemMultipleMiceAndKeyboards->IsChecked()) { MenuItemReplaceMouse->Enable(true); MenuItemReplaceKeyboard->Enable(true); - } - else - { + } else { MenuItemReplaceMouse->Enable(false); MenuItemReplaceKeyboard->Enable(false); } @@ -2717,7 +2704,28 @@ void configFrame::OnMenuOpen(wxCommandEvent& event __attribute__((unused))) refresh_gui(); reset_buttons(); MenuFile->Enable(idMenuSave, true); + configFile.SetDirectory(TO_STRING(directory)); + configFile.SetFile(TO_STRING(file)); + wxTopLevelWindow::SetTitle(file + wxT(" - Gimx-config")); + openedConfigFile = configFile; +} + +/* + * \brief Method called on File>Open click. + */ +void configFrame::OnMenuOpen(wxCommandEvent& event __attribute__((unused))) +{ + wxFileDialog FileDialog(this, _("Select file"), TO_WXSTRING(configFile.GetDirectory()), wxEmptyString, + _("XML files (*.xml)|*.xml"), wxFD_DEFAULT_STYLE | wxFD_OPEN, wxDefaultPosition, wxDefaultSize, + _T("wxFileDialog")); + if ( FileDialog.ShowModal() == wxID_CANCEL) { + return; + } + + checkSave(); + + openConfiguration(FileDialog.GetDirectory(), FileDialog.GetFilename()); } /* @@ -2806,44 +2814,44 @@ void configFrame::OnMenuItemConfiguration(wxCommandEvent& event __attribute__((u refresh_gui(); } +bool configFrame::save(const wxString& directory, const wxString& file) +{ + save_current(); + reset_buttons(); + if (configFile.WriteConfigFile(TO_STRING(directory), TO_STRING(file)) < 0) { + wxMessageBox(_("Can't save ") + file, _("Error"), wxICON_ERROR); + return false; + } else { + openedConfigFile = configFile; + SetTitle(file + wxT(" - Gimx-config")); + Refresh(); + } + return true; +} + /* * \bried Method called on File>Save click. \ * It saves the current profile and writes the config file on the disk. */ void configFrame::OnMenuSave(wxCommandEvent& event __attribute__((unused))) { - wxString end; - save_current(); - if(configFile.WriteConfigFile() < 0) - { - wxMessageBox(_("Can't save ") + wxString(configFile.GetFilePath().c_str(), wxConvUTF8), _("Error"), wxICON_ERROR); - } - reset_buttons(); + save(configFile.GetDirectory(), configFile.GetFile()); } /* * \bried Method called on File>Save_As click. \ * It asks the user for a config location & name, and calls OnMenuSave. */ -void configFrame::OnMenuSaveAs(wxCommandEvent& event) +void configFrame::OnMenuSaveAs(wxCommandEvent& event __attribute__((unused))) { - wxFileDialog saveFileDialog(this, _("Save config file"), wxT(""), wxT(""), _("XML files (*.xml)|*.xml"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT); - - saveFileDialog.SetDirectory(FileDialog1->GetDirectory()); - saveFileDialog.SetFilename(FileDialog1->GetFilename()); - - if ( saveFileDialog.ShowModal() == wxID_CANCEL ) return; - - wxString FileName = saveFileDialog.GetPath(); + wxFileDialog saveFileDialog(this, _("Save config file"), TO_WXSTRING(configFile.GetDirectory()), + TO_WXSTRING(configFile.GetFile()), _("XML files (*.xml)|*.xml"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT); - if ( FileName.IsEmpty() ) return; - - configFile.SetFilePath(string(FileName.mb_str(wxConvUTF8))); - - OnMenuSave(event); + if ( saveFileDialog.ShowModal() == wxID_CANCEL) { + return; + } - FileDialog1->SetDirectory(saveFileDialog.GetDirectory()); - FileDialog1->SetFilename(saveFileDialog.GetFilename()); + save(saveFileDialog.GetDirectory(), saveFileDialog.GetFilename()); MenuFile->Enable(idMenuSave, true); } @@ -3799,7 +3807,7 @@ void configFrame::OnMenuMultipleMK(wxCommandEvent& event __attribute__((unused)) */ void configFrame::OnMenuAutoBindControls(wxCommandEvent& event __attribute__((unused))) { - if(configFile.GetFilePath().empty()) + if(configFile.GetFile().empty()) { wxMessageBox( _("No config opened!"), _("Error"), wxICON_ERROR); return; @@ -3812,7 +3820,7 @@ void configFrame::OnMenuAutoBindControls(wxCommandEvent& event __attribute__((un wxString FileName = FileDialog.GetPath(); if ( FileName.IsEmpty() ) return; - if(configFile.AutoBind(string(FileName.mb_str(wxConvUTF8))) < 0) + if(configFile.AutoBind(TO_STRING(FileDialog.GetDirectory()), TO_STRING(FileDialog.GetFilename())) < 0) { wxMessageBox(_("Can't auto-bind controls!"), _("Error"), wxICON_ERROR); } diff --git a/config/gimx-config.h b/config/gimx-config.h index 60914208..497b61de 100644 --- a/config/gimx-config.h +++ b/config/gimx-config.h @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -111,6 +110,7 @@ class configFrame: public wxFrame void OnButtonFFBTweaksDelete(wxCommandEvent& event); void OnAxisTabAxisIdSelect(wxCommandEvent& event); //*) + void OnClose(wxCloseEvent& event); void DeleteSelectedRows(wxGrid* grid); void DeleteLinkedRows(wxGrid* grid, int row); void replaceDevice(wxString wx_device_type); @@ -132,6 +132,9 @@ class configFrame: public wxFrame void LoadControllerType(); pair selectEvent(); void addJoystickCorrection(); + void openConfiguration(const wxString& directory, const wxString& file); + bool save(const wxString& directory, const wxString& file); + void checkSave(); //(*Identifiers(configFrame) static const long ID_STATICTEXT35; @@ -325,7 +328,6 @@ class configFrame: public wxFrame //*) //(*Declarations(configFrame) - wxFileDialog* FileDialog1; wxMenu* MenuType; wxButton* MouseOptionsAutoDetect; wxStaticText* StaticText1; @@ -524,6 +526,7 @@ class configFrame: public wxFrame EventCatcher* evcatch; ConfigurationFile configFile; + ConfigurationFile openedConfigFile; unsigned int currentController; unsigned int currentProfile; diff --git a/config/wxsmith/configframe.wxs b/config/wxsmith/configframe.wxs index ee2bbfe3..7d2c693d 100644 --- a/config/wxsmith/configframe.wxs +++ b/config/wxsmith/configframe.wxs @@ -2111,10 +2111,5 @@ -1 wxSB_NORMAL - - Select file - XML files (*.xml)|*.xml - - diff --git a/fpsconfig/gimx-fpsconfig.cpp b/fpsconfig/gimx-fpsconfig.cpp index dc0236b6..d75d1d78 100644 --- a/fpsconfig/gimx-fpsconfig.cpp +++ b/fpsconfig/gimx-fpsconfig.cpp @@ -41,6 +41,9 @@ #define _CN(STRING) locale->GetString(wxString(STRING.c_str(), wxConvUTF8)) +#define TO_STRING(WXSTRING) string(WXSTRING.mb_str(wxConvUTF8)) +#define TO_WXSTRING(STRING) wxString(STRING.c_str(), wxConvUTF8) + using namespace std; /* @@ -412,7 +415,6 @@ fpsconfigFrame::fpsconfigFrame(wxString file,wxWindow* parent,wxWindowID id __at StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1); StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1); SetStatusBar(StatusBar1); - FileDialog1 = new wxFileDialog(this, _("Select file"), wxEmptyString, wxEmptyString, wxFileSelectorDefaultWildcardStr, wxFD_DEFAULT_STYLE, wxDefaultPosition, wxDefaultSize, _T("wxFileDialog")); Connect(ID_SPINCTRL8,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)&fpsconfigFrame::OnSpinCtrlChange); Connect(ID_SPINCTRL7,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)&fpsconfigFrame::OnSpinCtrlChange); @@ -471,6 +473,7 @@ fpsconfigFrame::fpsconfigFrame(wxString file,wxWindow* parent,wxWindowID id __at Connect(ID_MENUITEM9,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&fpsconfigFrame::OnMenuItemWindowEventsSelected); Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&fpsconfigFrame::OnAbout); //*) + Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(fpsconfigFrame::OnClose), NULL, this); wxMemoryInputStream istream(background_png, sizeof background_png); wxImage background_img(istream, wxBITMAP_TYPE_PNG); @@ -537,7 +540,7 @@ fpsconfigFrame::fpsconfigFrame(wxString file,wxWindow* parent,wxWindowID id __at } } - FileDialog1->SetDirectory(default_directory); + configFile.SetDirectory(TO_STRING(default_directory)); current_dpi = 0; @@ -548,24 +551,13 @@ fpsconfigFrame::fpsconfigFrame(wxString file,wxWindow* parent,wxWindowID id __at evcatch = EventCatcher::getInstance(); - /* Open the file given as argument. */ - if(!file.IsEmpty()) - { - wxString wxfile = default_directory + file; + save_current(emptyConfigFile); - if(::wxFileExists(wxfile)) - { - configFile.ReadConfigFile(string(wxfile.mb_str(wxConvUTF8))); - LoadConfig(); - FileDialog1->SetFilename(file); - } - else - { - wxMessageBox( _("Cannot open config file: ") + file, _("Error"), wxICON_ERROR); - } + if (!file.IsEmpty()) { + openConfiguration(default_directory, file); } - wxToolTip::SetDelay(0); + wxToolTip::SetDelay(0); readLabels(); @@ -578,6 +570,34 @@ fpsconfigFrame::~fpsconfigFrame() //(*Destroy(fpsconfigFrame) //*) Panel1->RemoveEventHandler(ToolBarBackground); + delete ToolBarBackground; +} + +void fpsconfigFrame::checkSave() +{ + save_current(configFile); + + if (!configFile.GetFile().empty()) { + if (!(openedConfigFile == configFile)) { + int answer = wxMessageBox(_("Do you want to save your configuration?"), TO_WXSTRING(configFile.GetFile()), wxYES_NO); + if (answer == wxYES) { + wxCommandEvent e; + OnMenuSave(e); + } + } + } else if (!(configFile == emptyConfigFile)) { + int answer = wxMessageBox(_("Do you want to save your configuration?"), wxEmptyString, wxYES_NO); + if (answer == wxYES) { + wxCommandEvent e; + OnMenuSaveAs(e); + } + } +} + +void fpsconfigFrame::OnClose(wxCloseEvent& event) +{ + checkSave(); + event.Skip(); } void fpsconfigFrame::OnQuit(wxCommandEvent& event __attribute__((unused))) @@ -1019,7 +1039,15 @@ void fpsconfigFrame::OnButtonClick(wxCommandEvent& event) void fpsconfigFrame::OnMenuNew(wxCommandEvent& event __attribute__((unused))) { - FileDialog1->SetFilename(wxEmptyString); + checkSave(); + + wxTopLevelWindow::SetTitle(wxT("Gimx-fpsconfig")); + configFile = ConfigurationFile(); + configFile.SetDirectory(TO_STRING(default_directory)); + configFile.SetFile(""); + openedConfigFile = ConfigurationFile(); + openedConfigFile.SetDirectory(TO_STRING(default_directory)); + openedConfigFile.SetFile(""); defaultMouseName = ""; defaultMouseId = "0"; @@ -1072,37 +1100,42 @@ void fpsconfigFrame::OnMenuNew(wxCommandEvent& event __attribute__((unused))) TextCtrlFilterADS->SetValue(wxT("0.00")); SpinCtrlDPI->Enable(true); + SpinCtrlDPI->SetValue(0); + current_dpi = 0; SpinCtrlDPI->SetToolTip(_("Enter your mouse DPI value.")); - configFile = ConfigurationFile(); - MenuItemSave->Enable(false); } -void fpsconfigFrame::OnMenuSaveAs(wxCommandEvent& event) +void fpsconfigFrame::OnMenuSaveAs(wxCommandEvent& event __attribute__((unused))) { - wxFileDialog saveFileDialog(this, _("Save config file"), wxT(""), wxT(""), _("XML files (*.xml)|*.xml"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT); - - saveFileDialog.SetDirectory(FileDialog1->GetDirectory()); - saveFileDialog.SetFilename(FileDialog1->GetFilename()); - - if ( saveFileDialog.ShowModal() == wxID_CANCEL ) return; - - wxString FileName = saveFileDialog.GetPath(); - - if ( FileName.IsEmpty() ) return; - - configFile.SetFilePath(string(FileName.mb_str(wxConvUTF8))); + wxFileDialog saveFileDialog(this, _("Save config file"), TO_WXSTRING(configFile.GetDirectory()), + TO_WXSTRING(configFile.GetFile()), _("XML files (*.xml)|*.xml"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT); - OnMenuSave(event); + if ( saveFileDialog.ShowModal() == wxID_CANCEL) { + return; + } - FileDialog1->SetDirectory(saveFileDialog.GetDirectory()); - FileDialog1->SetFilename(saveFileDialog.GetFilename()); + save(saveFileDialog.GetDirectory(), saveFileDialog.GetFilename()); MenuItemSave->Enable(true); } -void fpsconfigFrame::OnMenuSave(wxCommandEvent& event __attribute__((unused))) +bool fpsconfigFrame::save(const wxString& directory, const wxString& file) +{ + save_current(configFile); + if (configFile.WriteConfigFile(TO_STRING(directory), TO_STRING(file)) < 0) { + wxMessageBox(_("Can't save_current ") + file, _("Error"), wxICON_ERROR); + return false; + } else { + openedConfigFile = configFile; + SetTitle(file + wxT(" - Gimx-fpsconfig")); + Refresh(); + } + return true; +} + +void fpsconfigFrame::save_current(ConfigurationFile& config) { std::list* ButtonMappers; std::list* AxisMappers; @@ -1125,12 +1158,12 @@ void fpsconfigFrame::OnMenuSave(wxCommandEvent& event __attribute__((unused))) /* * Save DPI value. */ - configFile.GetController(0)->SetMouseDPI(current_dpi); + config.GetController(0)->SetMouseDPI(current_dpi); /* * Save Hip Fire config. */ //Save ButtonMappers - ButtonMappers = configFile.GetController(0)->GetProfile(0)->GetButtonMapperList(); + ButtonMappers = config.GetController(0)->GetProfile(0)->GetButtonMapperList(); for(int i=bi_select; iGetType().empty()) @@ -1151,7 +1184,7 @@ void fpsconfigFrame::OnMenuSave(wxCommandEvent& event __attribute__((unused))) } } //Save AxisMappers - AxisMappers = configFile.GetController(0)->GetProfile(0)->GetAxisMapperList(); + AxisMappers = config.GetController(0)->GetProfile(0)->GetAxisMapperList(); for(int i=ai_ls_up; iGetType().empty()) @@ -1181,7 +1214,7 @@ void fpsconfigFrame::OnMenuSave(wxCommandEvent& event __attribute__((unused))) it->GetEvent()->SetExponent(string(TextCtrlAccelerationHipFire->GetValue().mb_str(wxConvUTF8))); it->GetEvent()->SetShape(reverseTranslate(string(ChoiceDeadZoneShapeHipFire->GetStringSelection().mb_str(wxConvUTF8)))); - std::list* mouseOptions = configFile.GetController(0)->GetProfile(0)->GetMouseOptionsList(); + std::list* mouseOptions = config.GetController(0)->GetProfile(0)->GetMouseOptionsList(); std::list::iterator it2; for(it2 = mouseOptions->begin(); it2!=mouseOptions->end(); ++it2) { @@ -1209,7 +1242,7 @@ void fpsconfigFrame::OnMenuSave(wxCommandEvent& event __attribute__((unused))) string(TextCtrlAccelerationHipFire->GetValue().mb_str(wxConvUTF8)), reverseTranslate(string(ChoiceDeadZoneShapeHipFire->GetStringSelection().mb_str(wxConvUTF8))), "Aiming - x axis")); - std::list* mouseOptions = configFile.GetController(0)->GetProfile(0)->GetMouseOptionsList(); + std::list* mouseOptions = config.GetController(0)->GetProfile(0)->GetMouseOptionsList(); std::list::iterator it2; for(it2 = mouseOptions->begin(); it2!=mouseOptions->end(); ++it2) { @@ -1260,19 +1293,19 @@ void fpsconfigFrame::OnMenuSave(wxCommandEvent& event __attribute__((unused))) * Save ADS config. */ //Save Trigger - if(configFile.GetController(0)->GetProfile(1)->GetTrigger()->GetDevice()->GetType() != "mouse" - || configFile.GetController(0)->GetProfile(1)->GetTrigger()->GetEvent()->GetId() != "BUTTON_RIGHT" - || configFile.GetController(0)->GetProfile(1)->GetTrigger()->GetSwitchBack() != "yes") + if(config.GetController(0)->GetProfile(1)->GetTrigger()->GetDevice()->GetType() != "mouse" + || config.GetController(0)->GetProfile(1)->GetTrigger()->GetEvent()->GetId() != "BUTTON_RIGHT" + || config.GetController(0)->GetProfile(1)->GetTrigger()->GetSwitchBack() != "yes") { - configFile.GetController(0)->GetProfile(1)->GetTrigger()->GetDevice()->SetType("mouse"); - configFile.GetController(0)->GetProfile(1)->GetTrigger()->GetDevice()->SetName(defaultMouseName); - configFile.GetController(0)->GetProfile(1)->GetTrigger()->GetDevice()->SetId(defaultMouseId); - configFile.GetController(0)->GetProfile(1)->GetTrigger()->GetEvent()->SetId("BUTTON_RIGHT"); - configFile.GetController(0)->GetProfile(1)->GetTrigger()->SetSwitchBack("yes"); - configFile.GetController(0)->GetProfile(1)->GetTrigger()->SetDelay(0); + config.GetController(0)->GetProfile(1)->GetTrigger()->GetDevice()->SetType("mouse"); + config.GetController(0)->GetProfile(1)->GetTrigger()->GetDevice()->SetName(defaultMouseName); + config.GetController(0)->GetProfile(1)->GetTrigger()->GetDevice()->SetId(defaultMouseId); + config.GetController(0)->GetProfile(1)->GetTrigger()->GetEvent()->SetId("BUTTON_RIGHT"); + config.GetController(0)->GetProfile(1)->GetTrigger()->SetSwitchBack("yes"); + config.GetController(0)->GetProfile(1)->GetTrigger()->SetDelay(0); } //Save ButtonMappers - ButtonMappers = configFile.GetController(0)->GetProfile(1)->GetButtonMapperList(); + ButtonMappers = config.GetController(0)->GetProfile(1)->GetButtonMapperList(); for(int i=bi_select; iGetType().empty()) @@ -1293,7 +1326,7 @@ void fpsconfigFrame::OnMenuSave(wxCommandEvent& event __attribute__((unused))) } } //Save AxisMappers - AxisMappers = configFile.GetController(0)->GetProfile(1)->GetAxisMapperList(); + AxisMappers = config.GetController(0)->GetProfile(1)->GetAxisMapperList(); for(int i=ai_ls_up; iGetType().empty()) @@ -1323,7 +1356,7 @@ void fpsconfigFrame::OnMenuSave(wxCommandEvent& event __attribute__((unused))) it->GetEvent()->SetExponent(string(TextCtrlAccelerationADS->GetValue().mb_str(wxConvUTF8))); it->GetEvent()->SetShape(reverseTranslate(string(ChoiceDeadZoneShapeADS->GetStringSelection().mb_str(wxConvUTF8)))); - std::list* mouseOptions = configFile.GetController(0)->GetProfile(1)->GetMouseOptionsList(); + std::list* mouseOptions = config.GetController(0)->GetProfile(1)->GetMouseOptionsList(); std::list::iterator it2; for(it2 = mouseOptions->begin(); it2!=mouseOptions->end(); ++it2) { @@ -1350,7 +1383,7 @@ void fpsconfigFrame::OnMenuSave(wxCommandEvent& event __attribute__((unused))) sDzADS, string(TextCtrlSensitivityADS->GetValue().mb_str(wxConvUTF8)), string(TextCtrlAccelerationADS->GetValue().mb_str(wxConvUTF8)), reverseTranslate(string(ChoiceDeadZoneShapeADS->GetStringSelection().mb_str(wxConvUTF8))), "Aiming - x axis")); - std::list* mouseOptions = configFile.GetController(0)->GetProfile(1)->GetMouseOptionsList(); + std::list* mouseOptions = config.GetController(0)->GetProfile(1)->GetMouseOptionsList(); std::list::iterator it2; for(it2 = mouseOptions->begin(); it2!=mouseOptions->end(); ++it2) { @@ -1407,11 +1440,11 @@ void fpsconfigFrame::OnMenuSave(wxCommandEvent& event __attribute__((unused))) { old_axes[i] = axes[i]; } +} - if(configFile.WriteConfigFile() < 0) - { - wxMessageBox(_("Can't save ") + wxString(configFile.GetFilePath().c_str(), wxConvUTF8), _("Error"), wxICON_ERROR); - } +void fpsconfigFrame::OnMenuSave(wxCommandEvent& event __attribute__((unused))) +{ + save(configFile.GetDirectory(), configFile.GetFile()); } void fpsconfigFrame::LoadConfig() @@ -1802,18 +1835,41 @@ void fpsconfigFrame::LoadConfig() MenuItemSave->Enable(true); } -void fpsconfigFrame::OnMenuOpen(wxCommandEvent& event __attribute__((unused))) +void fpsconfigFrame::openConfiguration(const wxString& directory, const wxString& file) { - FileDialog1->SetDirectory(default_directory); - - if ( FileDialog1->ShowModal() != wxID_OK ) return; + if (!::wxFileExists (directory + "/" + file)) { + wxMessageBox( _("Cannot open config file: ") + file, _("Error"), wxICON_ERROR); + return; + } - wxString FileName = FileDialog1->GetPath(); - if ( FileName.IsEmpty() ) return; + int ret = configFile.ReadConfigFile(TO_STRING(directory), TO_STRING(file)); - configFile.ReadConfigFile(string(FileName.mb_str(wxConvUTF8))); + if (ret < 0) { + wxMessageBox(TO_WXSTRING(configFile.GetError()), _("Error"), wxICON_ERROR); + return; + } else if (ret > 0) { + wxMessageBox(TO_WXSTRING(configFile.GetInfo()), _("Info"), wxICON_INFORMATION); + } LoadConfig(); + + wxTopLevelWindow::SetTitle(file + wxT(" - Gimx-fpsconfig")); + openedConfigFile = configFile; +} + +void fpsconfigFrame::OnMenuOpen(wxCommandEvent& event __attribute__((unused))) +{ + wxFileDialog FileDialog(this, _("Select file"), TO_WXSTRING(configFile.GetDirectory()), wxEmptyString, + _("XML files (*.xml)|*.xml"), wxFD_DEFAULT_STYLE | wxFD_OPEN, wxDefaultPosition, wxDefaultSize, + _T("wxFileDialog")); + + if ( FileDialog.ShowModal() == wxID_CANCEL) { + return; + } + + checkSave(); + + openConfiguration(FileDialog.GetDirectory(), FileDialog.GetFilename()); } void fpsconfigFrame::OnTextCtrlText(wxCommandEvent& event) @@ -2046,7 +2102,7 @@ void fpsconfigFrame::OnButtonConvertSensitivityClick(wxCommandEvent& event __att void fpsconfigFrame::OnMenuAutoBindControls(wxCommandEvent& event __attribute__((unused))) { - if(configFile.GetFilePath().empty()) + if(configFile.GetFile().empty()) { wxMessageBox( _("No config opened!"), _("Error"), wxICON_ERROR); return; @@ -2059,7 +2115,7 @@ void fpsconfigFrame::OnMenuAutoBindControls(wxCommandEvent& event __attribute__( wxString FileName = FileDialog.GetPath(); if ( FileName.IsEmpty() ) return; - if(configFile.AutoBind(string(FileName.mb_str(wxConvUTF8))) < 0) + if(configFile.AutoBind(TO_STRING(FileDialog.GetDirectory()), TO_STRING(FileDialog.GetFilename())) < 0) { wxMessageBox(_("Can't auto-bind controls!"), _("Error"), wxICON_ERROR); } @@ -2096,13 +2152,11 @@ void fpsconfigFrame::readLabels() } wxString file; - wxString filepath; wxString filespec = wxT("*.xml"); for (bool cont = dir.GetFirst(&file, filespec, wxDIR_FILES); cont; cont = dir.GetNext(&file)) { - filepath = default_directory + file; - ConfigurationFile::GetLabels(string(filepath.mb_str(wxConvUTF8)), blabels, alabels); + ConfigurationFile::GetLabels(TO_STRING(default_directory), TO_STRING(file), blabels, alabels); } blabels.sort(compare_nocase); diff --git a/fpsconfig/gimx-fpsconfig.h b/fpsconfig/gimx-fpsconfig.h index c0902033..4f5728c1 100644 --- a/fpsconfig/gimx-fpsconfig.h +++ b/fpsconfig/gimx-fpsconfig.h @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -84,6 +83,7 @@ class fpsconfigFrame: public wxFrame void OnMenuOpenConfigDirectory(wxCommandEvent& event); void OnMenuItemWindowEventsSelected(wxCommandEvent& event); //*) + void OnClose(wxCloseEvent& event); e_button_index getButtonIndex(wxButton* button); e_axis_index getAxisIndex(wxButton* button); @@ -100,6 +100,11 @@ class fpsconfigFrame: public wxFrame void updateTextCtrlValue(wxTextCtrl* text, int step, double* value); void updateSpinCtrl(wxSpinCtrl * spin, wxTextCtrl* text, int step, int min, int max, double * value); + void save_current(ConfigurationFile& config); + bool save(const wxString& directory, const wxString& file); + void openConfiguration(const wxString& directory, const wxString& file); + void checkSave(); + //(*Identifiers(fpsconfigFrame) static const long ID_SPINCTRL8; static const long ID_SPINCTRL7; @@ -209,7 +214,6 @@ class fpsconfigFrame: public wxFrame wxMenuItem* MenuItemNew; wxStaticText* StaticText8; wxSpinCtrl* SpinCtrlSensitivityADS; - wxFileDialog* FileDialog1; wxStaticText* StaticTextDZ; wxButton* l3; wxSpinCtrl* SpinCtrlXyRatioHipFire; @@ -244,6 +248,8 @@ class fpsconfigFrame: public wxFrame EventCatcher* evcatch; ConfigurationFile configFile; + ConfigurationFile openedConfigFile; + ConfigurationFile emptyConfigFile; ControlMapper buttons[BI_MAX]; ControlMapper old_buttons[BI_MAX]; diff --git a/fpsconfig/wxsmith/fpsconfigframe.wxs b/fpsconfig/wxsmith/fpsconfigframe.wxs index b8e9203f..ef1e8634 100644 --- a/fpsconfig/wxsmith/fpsconfigframe.wxs +++ b/fpsconfig/wxsmith/fpsconfigframe.wxs @@ -478,8 +478,5 @@ -1 wxSB_NORMAL - - Select file - diff --git a/launcher/gimx-launcher.cpp b/launcher/gimx-launcher.cpp index 1e40ae53..9fb049cf 100644 --- a/launcher/gimx-launcher.cpp +++ b/launcher/gimx-launcher.cpp @@ -92,6 +92,9 @@ using namespace std; #define CONSOLETUNER_VID 0x2508 +#define TO_STRING(WXSTRING) string(WXSTRING.mb_str(wxConvUTF8)) +#define TO_WXSTRING(STRING) wxString(STRING.c_str(), wxConvUTF8) + //(*IdInit(launcherFrame) const long launcherFrame::ID_STATICTEXT4 = wxNewId(); const long launcherFrame::ID_CHOICE1 = wxNewId(); @@ -1741,11 +1744,8 @@ void launcherFrame::OnButtonCheckClick1(wxCommandEvent& event __attribute__((unu return; } - string file = string(gimxConfigDir.mb_str(wxConvUTF8)); - file.append(InputChoice->GetStringSelection().mb_str(wxConvUTF8)); - ConfigurationFile configFile; - int ret = configFile.ReadConfigFile(file); + int ret = configFile.ReadConfigFile(TO_STRING(gimxConfigDir), TO_STRING(InputChoice->GetStringSelection())); if(ret < 0) { @@ -2137,7 +2137,7 @@ void launcherFrame::OnMenuGetConfigs(wxCommandEvent& event __attribute__((unused void launcherFrame::autoBindControls(wxArrayString configs) { - string dir = string(gimxConfigDir.mb_str(wxConvUTF8)); + string dir = TO_STRING(gimxConfigDir); wxString mod_config; @@ -2156,7 +2156,7 @@ void launcherFrame::autoBindControls(wxArrayString configs) ConfigurationFile configFile; mod_config = configs[j]; - int ret = configFile.ReadConfigFile(dir + string(mod_config.mb_str(wxConvUTF8))); + int ret = configFile.ReadConfigFile(dir, TO_STRING(mod_config)); if(ret < 0) { @@ -2164,14 +2164,14 @@ void launcherFrame::autoBindControls(wxArrayString configs) return; } - if(configFile.AutoBind(dir + string(dialog.GetStringSelection().mb_str(wxConvUTF8))) < 0) + if(configFile.AutoBind(dir, TO_STRING(dialog.GetStringSelection())) < 0) { wxMessageBox(_("Can't auto-bind controls for config: ") + mod_config, _("Error"), wxICON_ERROR); } else { - configFile.ConvertSensitivity(dir + string(dialog.GetStringSelection().mb_str(wxConvUTF8))); - if(configFile.WriteConfigFile() < 0) + configFile.ConvertSensitivity(dir, TO_STRING(dialog.GetStringSelection())); + if(configFile.WriteConfigFile(dir, TO_STRING(mod_config)) < 0) { wxMessageBox(_("Can't write config: ") + mod_config, _("Error"), wxICON_ERROR); } diff --git a/shared/gimxconfigeditor/include/ConfigurationFile.h b/shared/gimxconfigeditor/include/ConfigurationFile.h index 4c7afbcd..74478a15 100644 --- a/shared/gimxconfigeditor/include/ConfigurationFile.h +++ b/shared/gimxconfigeditor/include/ConfigurationFile.h @@ -20,24 +20,28 @@ class ConfigurationFile ConfigurationFile(); virtual ~ConfigurationFile(); ConfigurationFile& operator=(const ConfigurationFile& other); - int ReadConfigFile(string filePath); + int ReadConfigFile(const string& directory, const string& file); bool MultipleMK() { return m_multipleMK; } void SetCheckDevices(bool check) { m_checkDevices = check; } string GetError() { return m_Error; } string GetInfo() { return m_Info; } - int WriteConfigFile(); - string GetFilePath() { return m_FilePath; } - void SetFilePath(string val) { m_FilePath = val; } + int WriteConfigFile(const string& directory, const string& file); + string GetFile() const { return m_File; } + string GetDirectory() const { return m_Directory; } + void SetFile(const string& val) { m_File = val; } + void SetDirectory(const string& val) { m_Directory = val; } Controller* GetController(unsigned int i) { return m_Controllers+i; } void SetController(Controller val, unsigned int i) { m_Controllers[i] = val; } - int AutoBind(string refFilePath); - int ConvertSensitivity(string refFilePath); + int AutoBind(const string& directory, const string& file); + int ConvertSensitivity(const string& directory, const string& file); void GetLabels(list&, list&); - static void GetLabels(string, list&, list&); + static void GetLabels(const string& directory, const string& file, list& button_labels, list& axis_labels); bool IsEmpty(); + bool operator==(const ConfigurationFile &other) const; protected: private: - string m_FilePath; + string m_File; + string m_Directory; string m_Error; string m_Info; Controller m_Controllers[MAX_CONTROLLERS]; diff --git a/shared/gimxconfigeditor/include/Controller.h b/shared/gimxconfigeditor/include/Controller.h index e14ac8d8..5eec6e07 100644 --- a/shared/gimxconfigeditor/include/Controller.h +++ b/shared/gimxconfigeditor/include/Controller.h @@ -26,6 +26,7 @@ class Controller unsigned int GetMouseDPI() { return m_MouseDPI; } void SetMouseDPI(unsigned int val) { m_MouseDPI = val; } bool IsEmpty(); + bool operator==(const Controller &other) const; protected: private: e_controller_type m_ControllerType; diff --git a/shared/gimxconfigeditor/include/Profile.h b/shared/gimxconfigeditor/include/Profile.h index f234d4b6..41927afa 100644 --- a/shared/gimxconfigeditor/include/Profile.h +++ b/shared/gimxconfigeditor/include/Profile.h @@ -40,6 +40,7 @@ class Profile bool IsEmpty(); const std::string& getMacros() const { return m_Macros; } void setMacros(const std::string& macros) { m_Macros = macros; } + bool operator==(const Profile &other) const; protected: private: Trigger m_Trigger; diff --git a/shared/gimxconfigeditor/include/XmlWritter.h b/shared/gimxconfigeditor/include/XmlWritter.h index c99019d5..ae190ab9 100644 --- a/shared/gimxconfigeditor/include/XmlWritter.h +++ b/shared/gimxconfigeditor/include/XmlWritter.h @@ -14,7 +14,7 @@ class XmlWritter XmlWritter(); XmlWritter(ConfigurationFile* configFile); virtual ~XmlWritter(); - int WriteConfigFile(); + int WriteConfigFile(const string& directory, const string& file); protected: private: void CreateEventNode(xmlNodePtr parent_node, Event* event); diff --git a/shared/gimxconfigeditor/src/ConfigurationFile.cpp b/shared/gimxconfigeditor/src/ConfigurationFile.cpp index e433efb5..c7a9aa22 100644 --- a/shared/gimxconfigeditor/src/ConfigurationFile.cpp +++ b/shared/gimxconfigeditor/src/ConfigurationFile.cpp @@ -35,7 +35,7 @@ ConfigurationFile& ConfigurationFile::operator=(const ConfigurationFile& rhs) return *this; } -int ConfigurationFile::ReadConfigFile(string filePath) +int ConfigurationFile::ReadConfigFile(const string& directory, const string& file) { int ret; @@ -43,7 +43,8 @@ int ConfigurationFile::ReadConfigFile(string filePath) reader.SetCheckDevices(m_checkDevices); - ret = reader.ReadConfigFile(filePath); + string path = directory + "/" + file; + ret = reader.ReadConfigFile(path); if(ret < 0) { @@ -54,18 +55,29 @@ int ConfigurationFile::ReadConfigFile(string filePath) m_Info = reader.GetInfo(); } - m_multipleMK = reader.MultipleMK(); + if (ret >= 0) + { + m_multipleMK = reader.MultipleMK(); - m_FilePath = filePath; + m_Directory = directory; + m_File = file; + } return ret; } -int ConfigurationFile::WriteConfigFile() +int ConfigurationFile::WriteConfigFile(const string& directory, const string& file) { XmlWritter writer(this); - return writer.WriteConfigFile(); + int ret = writer.WriteConfigFile(directory, file); + + if (ret != -1) { + m_Directory = directory; + m_File = file; + } + + return ret; } list &split(const string &s, char delim, list &elems) @@ -154,11 +166,11 @@ static void AutoBindMappers(list* refMappers, list* modMappers) } } -int ConfigurationFile::AutoBind(string refFilePath) +int ConfigurationFile::AutoBind(const string& directory, const string& file) { ConfigurationFile refConfigFile; - int ret = refConfigFile.ReadConfigFile(refFilePath); + int ret = refConfigFile.ReadConfigFile(directory, file); if(ret >= 0) { @@ -184,11 +196,11 @@ int ConfigurationFile::AutoBind(string refFilePath) return ret; } -int ConfigurationFile::ConvertSensitivity(string refFilePath) +int ConfigurationFile::ConvertSensitivity(const string& directory, const string& file) { ConfigurationFile refConfigFile; - int ret = refConfigFile.ReadConfigFile(refFilePath); + int ret = refConfigFile.ReadConfigFile(directory, file); if(ret >= 0) { @@ -310,11 +322,11 @@ void ConfigurationFile::GetLabels(list& button_labels, list& axi } } -void ConfigurationFile::GetLabels(string file, list& button_labels, list& axis_labels) +void ConfigurationFile::GetLabels(const string& directory, const string& file, list& button_labels, list& axis_labels) { ConfigurationFile configFile; configFile.SetCheckDevices(false); - if(configFile.ReadConfigFile(file) >= 0) + if(configFile.ReadConfigFile(directory, file) >= 0) { configFile.GetLabels(button_labels, axis_labels); } @@ -331,3 +343,13 @@ bool ConfigurationFile::IsEmpty() } return true; } + +bool ConfigurationFile::operator==(const ConfigurationFile &other) const +{ + for (unsigned int i = 0; i < sizeof(m_Controllers) / sizeof(*m_Controllers); ++i) { + if (!(m_Controllers[i] == other.m_Controllers[i])) { + return false; + } + } + return true; +} diff --git a/shared/gimxconfigeditor/src/Controller.cpp b/shared/gimxconfigeditor/src/Controller.cpp index 528f8d41..d7ff1391 100644 --- a/shared/gimxconfigeditor/src/Controller.cpp +++ b/shared/gimxconfigeditor/src/Controller.cpp @@ -50,3 +50,14 @@ bool Controller::IsEmpty() } return true; } + +bool Controller::operator==(const Controller &other) const +{ + for (unsigned int i = 0; i < sizeof(m_Profile) / sizeof(*m_Profile); ++i) { + if (!(m_Profile[i] == other.m_Profile[i])) { + return false; + } + } + return m_ControllerType == other.m_ControllerType + && m_MouseDPI == other.m_MouseDPI; +} diff --git a/shared/gimxconfigeditor/src/Event.cpp b/shared/gimxconfigeditor/src/Event.cpp index 46578f93..4da3d8f6 100644 --- a/shared/gimxconfigeditor/src/Event.cpp +++ b/shared/gimxconfigeditor/src/Event.cpp @@ -73,5 +73,7 @@ bool Event::operator==(const Event &other) const && m_DeadZone == other.m_DeadZone && m_Multiplier == other.m_Multiplier && m_Exponent == other.m_Exponent - && m_Shape == other.m_Shape; + && (m_Shape == other.m_Shape + || (m_Shape == "Circle" && other.m_Shape == "") + || (m_Shape == "" && other.m_Shape == "Circle")); } diff --git a/shared/gimxconfigeditor/src/Profile.cpp b/shared/gimxconfigeditor/src/Profile.cpp index 4954d9b8..310efd6f 100644 --- a/shared/gimxconfigeditor/src/Profile.cpp +++ b/shared/gimxconfigeditor/src/Profile.cpp @@ -72,3 +72,15 @@ bool Profile::IsEmpty() } return true; } + +bool Profile::operator==(const Profile &other) const +{ + return m_Trigger == other.m_Trigger + && m_IntensityList == other.m_IntensityList + && m_MouseOptionsList == other.m_MouseOptionsList + && m_ButtonMappers == other.m_ButtonMappers + && m_AxisMappers == other.m_AxisMappers + && m_JoystickCorrectionsList == other.m_JoystickCorrectionsList + && m_ForceFeedback == other.m_ForceFeedback + && m_Macros == other.m_Macros; +} diff --git a/shared/gimxconfigeditor/src/XmlWritter.cpp b/shared/gimxconfigeditor/src/XmlWritter.cpp index df3a35bb..9e4de75f 100644 --- a/shared/gimxconfigeditor/src/XmlWritter.cpp +++ b/shared/gimxconfigeditor/src/XmlWritter.cpp @@ -338,7 +338,7 @@ void XmlWritter::CreateControllerNodes(xmlNodePtr parent_node) } } -int XmlWritter::WriteConfigFile() +int XmlWritter::WriteConfigFile(const string& directory, const string& file) { int ret; xmlDocPtr doc = NULL; /* document pointer */ @@ -358,11 +358,12 @@ int XmlWritter::WriteConfigFile() /* * Dumping document to stdio or file */ - ret = xmlSaveFormatFileEnc(m_ConfigurationFile->GetFilePath().c_str(), doc, "UTF-8", 1); + string path = directory + "/" + file; + ret = xmlSaveFormatFileEnc(path.c_str(), doc, "UTF-8", 1); #ifndef WIN32 if(ret != -1 - && chown(m_ConfigurationFile->GetFilePath().c_str(), getpwuid(getuid())->pw_uid, getpwuid(getuid())->pw_gid) < 0) + && chown(path.c_str(), getpwuid(getuid())->pw_uid, getpwuid(getuid())->pw_gid) < 0) { ret = -1; }