76 {
77#ifdef _DEBUG
78 wxSizerFlags::DisableConsistencyChecks();
79#endif
80
81
82 wxFileName fn(wxStandardPaths::Get().GetDocumentsDir() + wxFileName::GetPathSeparator() + "PSP-UFU" + wxFileName::GetPathSeparator() + "config.ini");
83 if (!fn.DirExists()) {
84 fn.Mkdir();
85 }
86
87 wxTextFile file(fn.GetFullPath());
88 auto data = propertiesData->GetGeneralPropertiesData();
89
90 if (!file.Create()) {
91 if (!file.Open()) return false;
92
93 wxString line;
94 for (line = file.GetFirstLine(); !file.Eof(); line = file.GetNextLine()) {
95 wxString tag = "";
96 wxString tagValue = "";
97 bool parseValue = false;
98 for (unsigned int i = 0; i < line.Len(); ++i) {
99 if (line[i] == '=') {
100 parseValue = true;
101 }
102 else {
103 if (parseValue)
104 tagValue += line[i];
105 else
106 tag += line[i];
107 }
108 }
109
110 if (tag == "lang") {
111 if (tagValue == "pt-br" || tagValue == "pt") {
112 data.language = wxLANGUAGE_PORTUGUESE_BRAZILIAN;
113 }
114 else if (tagValue == "en" || tagValue == "en-us" || tagValue == "en-uk") {
115 data.language = wxLANGUAGE_ENGLISH;
116 }
117 }
118 if (tag == "theme") {
119 if (tagValue == "light") {
120 data.theme = THEME_LIGHT;
121 }
122 else if (tagValue == "dark") {
123 data.theme = THEME_DARK;
124 }
125 }
126 if (tag == "plotlib") {
127 if (tagValue == "chartdir") {
128 data.plotLib = PlotLib::wxCHART_DIR;
129 }
130 else if (tagValue == "mathplot") {
131 data.plotLib = PlotLib::wxMATH_PLOT;
132 }
133 }
134
135
136
137
138
139
140
141
142 if (tag == "labelfont") {
143 data.labelFont = tagValue;
144 }
145 if (tag == "labelfontsize") {
146 long size = 10;
147 tagValue.ToLong(&size);
148 data.labelFontSize = static_cast<int>(size);
149 }
150 if (tag == "atpfile") {
151 data.atpPath = wxFileName(tagValue);
152 }
153 }
154 file.Close();
155 }
156 else {
157 if (!file.Open()) return false;
158
159
160 file.AddLine("lang=en");
161 file.AddLine("plotlib=chartdir");
162 file.AddLine("theme=light");
163 file.AddLine("labelfont=Arial");
164 file.AddLine("labelfontsize=10");
165 file.AddLine("atpfile=");
166
167
168 file.Write();
169 file.Close();
170
171 data.language = wxLANGUAGE_ENGLISH;
172 data.theme = THEME_LIGHT;
173 data.plotLib = PlotLib::wxCHART_DIR;
174
175 propertiesData->SetGeneralPropertiesData(data);
176 }
177
178
179 wxString atpFolder = wxStandardPaths::Get().GetDocumentsDir() + wxFileName::GetPathSeparator() + "PSP-UFU" + wxFileName::GetPathSeparator() + "atp";
180 if (!wxDir::Exists(atpFolder)) wxDir::Make(atpFolder);
181 data.atpWorkFolder = atpFolder;
182
183 propertiesData->SetGeneralPropertiesData(data);
184 return true;
185 }