summaryrefslogtreecommitdiffstats
path: root/Project/main.cpp
diff options
context:
space:
mode:
authorThales Lima Oliveira <thaleslima.ufu@gmail.com>2017-08-11 18:49:13 -0300
committerThales Lima Oliveira <thaleslima.ufu@gmail.com>2017-08-11 18:49:13 -0300
commit1fcb990bd02da945ac0204caaed6a9aa1f6a7d5f (patch)
treebfd5888f0d90d1248260e77ebc46492dc6aab250 /Project/main.cpp
parente5f19af9a5829a307951785e850e53fc4fcfac90 (diff)
downloadPSP.git-1fcb990bd02da945ac0204caaed6a9aa1f6a7d5f.tar.gz
PSP.git-1fcb990bd02da945ac0204caaed6a9aa1f6a7d5f.tar.xz
PSP.git-1fcb990bd02da945ac0204caaed6a9aa1f6a7d5f.zip
General settings implemented
A lot of pt-br translation Some forms sizes fixes init file fully implemented
Diffstat (limited to 'Project/main.cpp')
-rw-r--r--Project/main.cpp88
1 files changed, 45 insertions, 43 deletions
diff --git a/Project/main.cpp b/Project/main.cpp
index c4c6e40..397cbfa 100644
--- a/Project/main.cpp
+++ b/Project/main.cpp
@@ -13,17 +13,53 @@ class MainApp : public wxApp
public:
MainApp() {}
virtual ~MainApp() {}
- void LoadInitFile(PropertiesData* propertiesData)
+ bool LoadInitFile(PropertiesData* propertiesData)
{
wxTextFile file("config.ini");
auto data = propertiesData->GetGeneralPropertiesData();
- if(!file.Open()) {
- // Create default init file.
- wxString defaultInitFile = "lang=en\ntheme=light\n";
+ if(!file.Create()) {
+ if(!file.Open()) return false;
+
+ wxString line;
+ for(line = file.GetFirstLine(); !file.Eof(); line = file.GetNextLine()) {
+ wxString tag = "";
+ wxString tagValue = "";
+ bool parseValue = false;
+ for(unsigned int i = 0; i < line.Len(); ++i) {
+ if(line[i] == '=') {
+ parseValue = true;
+ } else {
+ if(parseValue)
+ tagValue += line[i];
+ else
+ tag += line[i];
+ }
+ }
+ // Language
+ if(tag == "lang") {
+ if(tagValue == "pt-br" || tagValue == "pt") {
+ data.language = wxLANGUAGE_PORTUGUESE_BRAZILIAN;
+ } else if(tagValue == "en" || tagValue == "en-us" || tagValue == "en-uk") {
+ data.language = wxLANGUAGE_ENGLISH;
+ }
+ }
+ if(tag == "theme") {
+ if(tagValue == "light") {
+ data.theme = THEME_LIGHT;
+ } else if(tagValue == "dark") {
+ data.theme = THEME_DARK;
+ }
+ }
+ }
+ file.Close();
+ } else { // Create default init file.
+ if(!file.Open()) return false;
+
+ // Default parameters.
+ file.AddLine("lang=en");
+ file.AddLine("theme=light");
- file.Create();
- file.AddLine(defaultInitFile);
file.Write();
file.Close();
@@ -32,48 +68,13 @@ class MainApp : public wxApp
propertiesData->SetGeneralPropertiesData(data);
}
- wxString line;
- for(line = file.GetFirstLine(); !file.Eof(); line = file.GetNextLine()) {
- wxString tag = "";
- wxString tagValue = "";
- bool parseValue = false;
- for(unsigned int i = 0; i < line.Len(); ++i) {
- if(line[i] == '=') {
- parseValue = true;
- } else {
- if(parseValue)
- tagValue += line[i];
- else
- tag += line[i];
- }
- }
- // Language
- if(tag == "lang") {
- if(tagValue == "pt-br" || tagValue == "pt") {
- data.language = wxLANGUAGE_PORTUGUESE_BRAZILIAN;
- } else if(tagValue == "en" || tagValue == "en-us" || tagValue == "en-uk") {
- data.language = wxLANGUAGE_ENGLISH;
- }
- }
- if(tag == "theme") {
- if(tagValue == "light") {
- data.theme = THEME_LIGHT;
- } else if(tagValue == "dark") {
- data.theme = THEME_DARK;
- }
- }
- }
- file.Close();
-
propertiesData->SetGeneralPropertiesData(data);
+ return true;
}
void LoadCatalogs(wxLocale* locale, PropertiesData* propertiesData)
{
- LoadInitFile(propertiesData);
-
- // Load computer settings.
- locale->Init(locale->GetSystemLanguage(), wxLOCALE_DONT_LOAD_DEFAULT);
+ locale->Init(propertiesData->GetGeneralPropertiesData().language, wxLOCALE_DONT_LOAD_DEFAULT);
wxFileName fn(wxStandardPaths::Get().GetExecutablePath());
wxString langPath = fn.GetPath() + "\\..\\data\\lang";
@@ -89,6 +90,7 @@ class MainApp : public wxApp
wxImage::AddHandler(new wxJPEGHandler);
PropertiesData* propertiesData = new PropertiesData();
+ LoadInitFile(propertiesData);
wxLocale* locale = new wxLocale();
LoadCatalogs(locale, propertiesData);