| 203 | namespace { |
| 204 | |
| 205 | void PopulatePreferences() |
| 206 | { |
| 207 | bool resetPrefs = false; |
| 208 | wxString langCode = gPrefs->Read(wxT("/Locale/Language"), wxEmptyString); |
| 209 | bool writeLang = false; |
| 210 | |
| 211 | const wxFileName fn( |
| 212 | FileNames::ResourcesDir(), |
| 213 | wxT("FirstTime.ini")); |
| 214 | if (fn.FileExists()) // it will exist if the (win) installer put it there |
| 215 | { |
| 216 | const wxString fullPath{fn.GetFullPath()}; |
| 217 | |
| 218 | auto pIni = |
| 219 | AudacityFileConfig::Create({}, {}, fullPath, {}, |
| 220 | wxCONFIG_USE_LOCAL_FILE); |
| 221 | auto &ini = *pIni; |
| 222 | |
| 223 | wxString lang; |
| 224 | if (ini.Read(wxT("/FromInno/Language"), &lang) && !lang.empty()) |
| 225 | { |
| 226 | // Only change "langCode" if the language was actually specified in the ini file. |
| 227 | langCode = lang; |
| 228 | writeLang = true; |
| 229 | |
| 230 | // Inno Setup doesn't allow special characters in the Name values, so "0" is used |
| 231 | // to represent the "@" character. |
| 232 | langCode.Replace(wxT("0"), wxT("@")); |
| 233 | } |
| 234 | |
| 235 | ini.Read(wxT("/FromInno/ResetPrefs"), &resetPrefs, false); |
| 236 | |
| 237 | bool gone = wxRemoveFile(fullPath); // remove FirstTime.ini |
| 238 | if (!gone) |
| 239 | { |
| 240 | AudacityMessageBox( |
| 241 | XO("Failed to remove %s").Format(fullPath), |
| 242 | XO("Failed!")); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | // Use the system default language if one wasn't specified or if the user selected System. |
| 247 | if (langCode.empty()) |
| 248 | langCode = |
| 249 | Languages::GetSystemLanguageCode(FileNames::AudacityPathList()); |
| 250 | |
| 251 | langCode = GUISettings::SetLang( langCode ); |
| 252 | |
| 253 | // User requested that the preferences be completely reset |
| 254 | if (resetPrefs) |
| 255 | { |
| 256 | ResetPreferences(); |
| 257 | writeLang = true; |
| 258 | } |
| 259 | |
| 260 | // Save the specified language |
| 261 | if (writeLang) |
| 262 | { |
no test coverage detected