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