Permalink
Browse files

config editors can crash if locale 'en_GB' misses #469

  • Loading branch information...
matlo committed Sep 8, 2017
1 parent cad9b27 commit 11a643109ac07fae965c5d81e8b428de8cf29795
Showing with 60 additions and 30 deletions.
  1. +25 −9 config/gimx-config.cpp
  2. +1 −0 config/gimx-config.h
  3. +33 −21 fpsconfig/gimx-fpsconfig.cpp
  4. +1 −0 fpsconfig/gimx-fpsconfig.h
@@ -576,6 +576,13 @@ void configFrame::readLabels()
} }
} }
static bool ToDouble(const wxString & from, double * to, const wxString & decimalPoint)
{
wxString tmp = from;
tmp.Replace(wxT("."), decimalPoint);
return tmp.ToDouble(to);
}
/* /*
* \brief Constructor. * \brief Constructor.
* *
@@ -591,6 +598,9 @@ configFrame::configFrame(wxString file,wxWindow* parent, wxWindowID id __attribu
#endif #endif
locale->AddCatalog(wxT("gimx")); locale->AddCatalog(wxT("gimx"));
struct lconv * l = localeconv();
decimalPoint = wxString(l->decimal_point, wxConvUTF8);
//(*Initialize(configFrame) //(*Initialize(configFrame)
wxFlexGridSizer* FlexGridSizer30; wxFlexGridSizer* FlexGridSizer30;
wxFlexGridSizer* FlexGridSizer46; wxFlexGridSizer* FlexGridSizer46;
@@ -3478,8 +3488,6 @@ void configFrame::OnMenuSetMouseDPI(wxCommandEvent& event __attribute__((unused)
*/ */
void configFrame::OnTextCtrl(wxCommandEvent& event) void configFrame::OnTextCtrl(wxCommandEvent& event)
{ {
wxLocale eng(wxLANGUAGE_ENGLISH); // make sure to use '.' as decimal separator
wxString str; wxString str;
wxTextCtrl* text; wxTextCtrl* text;
double value; double value;
@@ -3489,14 +3497,22 @@ void configFrame::OnTextCtrl(wxCommandEvent& event)
long pos = text->GetInsertionPoint(); long pos = text->GetInsertionPoint();
str = text->GetValue(); str = text->GetValue();
if(str.IsEmpty() || str == wxT("-") || str == wxT(".") || str == wxT("-.")) if(str.Replace(wxT(","), wxT(".")))
{ {
return; text->SetValue(str);
} }
if(str.Replace(wxT(","), wxT("."))) if (decimalPoint != wxT(".")) // avoid infinite recursion
{ {
text->SetValue(str); if(str.Replace(decimalPoint, wxT(".")))
{
text->SetValue(str);
}
}
if(str.IsEmpty() || str == wxT("-") || str == wxT(".") || str == wxT("-."))
{
return;
} }
if(str.Freq('.') > 1) if(str.Freq('.') > 1)
@@ -3521,14 +3537,14 @@ void configFrame::OnTextCtrl(wxCommandEvent& event)
} }
else if(text == AxisTabSensitivity) else if(text == AxisTabSensitivity)
{ {
if(!str.ToDouble(&value)) if(!ToDouble(str, &value, decimalPoint))
{ {
text->SetValue(wxT("1.00")); text->SetValue(wxT("1.00"));
} }
} }
else if(text == AxisTabAcceleration) else if(text == AxisTabAcceleration)
{ {
if(!str.ToDouble(&value)) if(!ToDouble(str, &value, decimalPoint))
{ {
text->SetValue(wxT("1.00")); text->SetValue(wxT("1.00"));
} }
@@ -3554,7 +3570,7 @@ void configFrame::OnTextCtrl(wxCommandEvent& event)
} }
else if(text == MouseOptionsFilter) else if(text == MouseOptionsFilter)
{ {
if(!str.ToDouble(&value)) if(!ToDouble(str, &value, decimalPoint))
{ {
text->SetValue(wxT("0.00")); text->SetValue(wxT("0.00"));
} }
@@ -502,6 +502,7 @@ class configFrame: public wxFrame
//*) //*)
wxLocale* locale; wxLocale* locale;
wxString decimalPoint;
event_catcher* evcatch; event_catcher* evcatch;
ConfigurationFile configFile; ConfigurationFile configFile;
@@ -203,6 +203,13 @@ const char* axis_labels[AI_MAX] =
"rel_axis_0-" "rel_axis_0-"
}; };
static bool ToDouble(const wxString & from, double * to, const wxString & decimalPoint)
{
wxString tmp = from;
tmp.Replace(wxT("."), decimalPoint);
return tmp.ToDouble(to);
}
fpsconfigFrame::fpsconfigFrame(wxString file,wxWindow* parent,wxWindowID id __attribute__((unused))) fpsconfigFrame::fpsconfigFrame(wxString file,wxWindow* parent,wxWindowID id __attribute__((unused)))
{ {
unsigned int i; unsigned int i;
@@ -213,6 +220,9 @@ fpsconfigFrame::fpsconfigFrame(wxString file,wxWindow* parent,wxWindowID id __at
#endif #endif
locale->AddCatalog(wxT("gimx")); locale->AddCatalog(wxT("gimx"));
struct lconv * l = localeconv();
decimalPoint = wxString(l->decimal_point, wxConvUTF8);
//(*Initialize(fpsconfigFrame) //(*Initialize(fpsconfigFrame)
wxMenu* MenuFile; wxMenu* MenuFile;
wxMenu* MenuAdvanced; wxMenu* MenuAdvanced;
@@ -1071,8 +1081,6 @@ void fpsconfigFrame::OnMenuSaveAs(wxCommandEvent& event)
void fpsconfigFrame::OnMenuSave(wxCommandEvent& event __attribute__((unused))) void fpsconfigFrame::OnMenuSave(wxCommandEvent& event __attribute__((unused)))
{ {
wxLocale eng(wxLANGUAGE_ENGLISH); // make sure to use '.' as decimal separator
std::list<ControlMapper>* ButtonMappers; std::list<ControlMapper>* ButtonMappers;
std::list<ControlMapper>* AxisMappers; std::list<ControlMapper>* AxisMappers;
double mx, my; double mx, my;
@@ -1198,7 +1206,7 @@ void fpsconfigFrame::OnMenuSave(wxCommandEvent& event __attribute__((unused)))
} }
wsmx = TextCtrlSensitivityHipFire->GetValue(); wsmx = TextCtrlSensitivityHipFire->GetValue();
wsxyratio = TextCtrlXyRatioHipFire->GetValue(); wsxyratio = TextCtrlXyRatioHipFire->GetValue();
if(wsmx.ToDouble(&mx) && wsxyratio.ToDouble(&xyratio)) if(ToDouble(wsmx, &mx, decimalPoint) && ToDouble(wsxyratio, &xyratio, decimalPoint))
{ {
my = mx * values[4]; my = mx * values[4];
} }
@@ -1339,7 +1347,7 @@ void fpsconfigFrame::OnMenuSave(wxCommandEvent& event __attribute__((unused)))
} }
wsmx = TextCtrlSensitivityADS->GetValue(); wsmx = TextCtrlSensitivityADS->GetValue();
wsxyratio = TextCtrlXyRatioADS->GetValue(); wsxyratio = TextCtrlXyRatioADS->GetValue();
if(wsmx.ToDouble(&mx) && wsxyratio.ToDouble(&xyratio)) if(ToDouble(wsmx, &mx, decimalPoint) && ToDouble(wsxyratio, &xyratio, decimalPoint))
{ {
my = mx * values[5]; my = mx * values[5];
} }
@@ -1385,8 +1393,6 @@ void fpsconfigFrame::OnMenuSave(wxCommandEvent& event __attribute__((unused)))
void fpsconfigFrame::LoadConfig() void fpsconfigFrame::LoadConfig()
{ {
wxLocale eng(wxLANGUAGE_ENGLISH); // make sure to use '.' as decimal separator
std::list<ControlMapper>* ButtonMappers[2]; std::list<ControlMapper>* ButtonMappers[2];
std::list<ControlMapper>* AxisMappers[2]; std::list<ControlMapper>* AxisMappers[2];
std::list<MouseOptions>* mouseOptions; std::list<MouseOptions>* mouseOptions;
@@ -1596,7 +1602,7 @@ void fpsconfigFrame::LoadConfig()
wsf = wxString(it2->GetFilter().c_str(), wxConvUTF8); wsf = wxString(it2->GetFilter().c_str(), wxConvUTF8);
if(wsf.ToDouble(&f)) if(ToDouble(wsf, &f, decimalPoint))
{ {
TextCtrlFilterHipFire->SetValue(wsf); TextCtrlFilterHipFire->SetValue(wsf);
SpinCtrlFilterHipFire->SetValue(f*100); SpinCtrlFilterHipFire->SetValue(f*100);
@@ -1607,7 +1613,7 @@ void fpsconfigFrame::LoadConfig()
wsmx = wxString(it->GetEvent()->GetMultiplier().c_str(), wxConvUTF8); wsmx = wxString(it->GetEvent()->GetMultiplier().c_str(), wxConvUTF8);
if(wsmx.ToDouble(&mx)) if(ToDouble(wsmx, &mx, decimalPoint))
{ {
TextCtrlSensitivityHipFire->SetValue(wsmx); TextCtrlSensitivityHipFire->SetValue(wsmx);
SpinCtrlSensitivityHipFire->SetValue(mx*100); SpinCtrlSensitivityHipFire->SetValue(mx*100);
@@ -1623,7 +1629,7 @@ void fpsconfigFrame::LoadConfig()
wsexp = wxString(it->GetEvent()->GetExponent().c_str(), wxConvUTF8); wsexp = wxString(it->GetEvent()->GetExponent().c_str(), wxConvUTF8);
if(wsexp.ToDouble(&exp)) if(ToDouble(wsexp, &exp, decimalPoint))
{ {
TextCtrlAccelerationHipFire->SetValue(wxString(it->GetEvent()->GetExponent().c_str(), wxConvUTF8)); TextCtrlAccelerationHipFire->SetValue(wxString(it->GetEvent()->GetExponent().c_str(), wxConvUTF8));
SpinCtrlAccelerationHipFire->SetValue(exp*100); SpinCtrlAccelerationHipFire->SetValue(exp*100);
@@ -1633,7 +1639,7 @@ void fpsconfigFrame::LoadConfig()
{ {
wsmy = wxString(it->GetEvent()->GetMultiplier().c_str(), wxConvUTF8); wsmy = wxString(it->GetEvent()->GetMultiplier().c_str(), wxConvUTF8);
if(wsmy.ToDouble(&my) && mx && my) if(ToDouble(wsmy, &my, decimalPoint) && mx && my)
{ {
xyratio = my / mx; xyratio = my / mx;
wsxyratio = wxString::Format(wxT("%.02f"), xyratio); wsxyratio = wxString::Format(wxT("%.02f"), xyratio);
@@ -1715,7 +1721,7 @@ void fpsconfigFrame::LoadConfig()
wsf = wxString(it2->GetFilter().c_str(), wxConvUTF8); wsf = wxString(it2->GetFilter().c_str(), wxConvUTF8);
if(wsf.ToDouble(&f)) if(ToDouble(wsf, &f, decimalPoint))
{ {
TextCtrlFilterADS->SetValue(wsf); TextCtrlFilterADS->SetValue(wsf);
SpinCtrlFilterADS->SetValue(f*100); SpinCtrlFilterADS->SetValue(f*100);
@@ -1726,7 +1732,7 @@ void fpsconfigFrame::LoadConfig()
wsmx = wxString(it->GetEvent()->GetMultiplier().c_str(), wxConvUTF8); wsmx = wxString(it->GetEvent()->GetMultiplier().c_str(), wxConvUTF8);
if(wsmx.ToDouble(&mx)) if(ToDouble(wsmx, &mx, decimalPoint))
{ {
TextCtrlSensitivityADS->SetValue(wsmx); TextCtrlSensitivityADS->SetValue(wsmx);
SpinCtrlSensitivityADS->SetValue(mx*100); SpinCtrlSensitivityADS->SetValue(mx*100);
@@ -1742,7 +1748,7 @@ void fpsconfigFrame::LoadConfig()
wsexp = wxString(it->GetEvent()->GetExponent().c_str(), wxConvUTF8); wsexp = wxString(it->GetEvent()->GetExponent().c_str(), wxConvUTF8);
if(wsexp.ToDouble(&exp)) if(ToDouble(wsexp, &exp, decimalPoint))
{ {
TextCtrlAccelerationADS->SetValue(wxString(it->GetEvent()->GetExponent().c_str(), wxConvUTF8)); TextCtrlAccelerationADS->SetValue(wxString(it->GetEvent()->GetExponent().c_str(), wxConvUTF8));
SpinCtrlAccelerationADS->SetValue(exp*100); SpinCtrlAccelerationADS->SetValue(exp*100);
@@ -1752,7 +1758,7 @@ void fpsconfigFrame::LoadConfig()
{ {
wsmy = wxString(it->GetEvent()->GetMultiplier().c_str(), wxConvUTF8); wsmy = wxString(it->GetEvent()->GetMultiplier().c_str(), wxConvUTF8);
if(wsmy.ToDouble(&my) && mx && my) if(ToDouble(wsmy, &my, decimalPoint) && mx && my)
{ {
xyratio = my / mx; xyratio = my / mx;
wsxyratio = wxString::Format(wxT("%.02f"), xyratio); wsxyratio = wxString::Format(wxT("%.02f"), xyratio);
@@ -1789,8 +1795,6 @@ void fpsconfigFrame::OnMenuOpen(wxCommandEvent& event __attribute__((unused)))
void fpsconfigFrame::OnTextCtrlText(wxCommandEvent& event) void fpsconfigFrame::OnTextCtrlText(wxCommandEvent& event)
{ {
wxLocale eng(wxLANGUAGE_ENGLISH); // make sure to use '.' as decimal separator
wxString str; wxString str;
wxTextCtrl* text; wxTextCtrl* text;
double value; double value;
@@ -1800,22 +1804,30 @@ void fpsconfigFrame::OnTextCtrlText(wxCommandEvent& event)
long pos = text->GetInsertionPoint(); long pos = text->GetInsertionPoint();
str = text->GetValue(); str = text->GetValue();
if(str.IsEmpty() || str == wxT("-") || str == wxT(".") || str == wxT("-.")) if(str.Replace(wxT(","), wxT(".")))
{ {
return; text->SetValue(str);
} }
if(str.Replace(wxT(","), wxT("."))) if (decimalPoint != wxT(".")) // avoid infinite recursion
{ {
text->SetValue(str); if(str.Replace(decimalPoint, wxT(".")))
{
text->SetValue(str);
}
}
if(str.IsEmpty() || str == wxT("-") || str == wxT(".") || str == wxT("-."))
{
return;
} }
if(str.Freq('.') > 1) if(str.Freq('.') > 1)
{ {
str = wxT("invalid"); str = wxT("invalid");
} }
if(!str.ToDouble(&value)) if(!ToDouble(str, &value, decimalPoint))
{ {
if (text == TextCtrlFilterHipFire || text == TextCtrlFilterADS) if (text == TextCtrlFilterHipFire || text == TextCtrlFilterADS)
{ {
@@ -237,6 +237,7 @@ class fpsconfigFrame: public wxFrame
wxBackgroundBitmap* ToolBarBackground; wxBackgroundBitmap* ToolBarBackground;
wxLocale* locale; wxLocale* locale;
wxString decimalPoint;
event_catcher* evcatch; event_catcher* evcatch;
ConfigurationFile configFile; ConfigurationFile configFile;

0 comments on commit 11a6431

Please sign in to comment.