Audacity 3.2.0
Functions
anonymous_namespace{AudacityApp.cpp} Namespace Reference

Custom events. More...

Functions

void PopulatePreferences ()
 
void InitCrashreports ()
 

Detailed Description

Custom events.

Function Documentation

◆ InitCrashreports()

void anonymous_namespace{AudacityApp.cpp}::InitCrashreports ( )

Definition at line 430 of file AudacityApp.cpp.

431{
432#if defined(USE_BREAKPAD) || defined(USE_CRASHPAD)
433 wxFileName databasePath;
434 databasePath.SetPath(FileNames::StateDir());
435 databasePath.AppendDir("crashreports");
436 databasePath.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
437
438 if(databasePath.DirExists())
439 {
440 const auto sentryRelease = wxString::Format(
441 "audacity@%d.%d.%d", AUDACITY_VERSION, AUDACITY_RELEASE, AUDACITY_REVISION);
442#if defined(USE_BREAKPAD)
443 BreakpadConfigurer configurer;
444 configurer.SetDatabasePathUTF8(databasePath.GetPath().ToUTF8().data())
445 .SetSenderPathUTF8(wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath().ToUTF8().data())
446 #if defined(CRASH_REPORT_URL)
447 .SetReportURL(CRASH_REPORT_URL)
448 #endif
450 { "version", wxString(AUDACITY_VERSION_STRING).ToUTF8().data() },
451 { "sentry[release]", sentryRelease.ToUTF8().data() }
452 })
453 .Start();
454#elif defined(USE_CRASHPAD)
455 try
456 {
457 const auto executableDir = wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath();
458 const wxFileName crashpadHandlerPath(executableDir, CRASHPAD_HANDLER_NAME);
459 const wxFileName crashreporterPath(executableDir, CRASHREPORTER_NAME);
460 const wxFileName metricsDir = databasePath;
461 std::vector<std::string> arguments = {
462 wxString::Format("--crashreporter-path=%s", crashreporterPath.GetFullPath()).ToUTF8().data(),
463#if defined(CRASH_REPORT_URL)
464 wxString::Format(
465 "--crashreporter-argument=-u=%s",
466 CRASH_REPORT_URL).ToUTF8().data(),
467 wxString::Format(
468 "--crashreporter-argument=-a=version=\"%s\",sentry[release]=\"%s\"",
469 AUDACITY_VERSION_STRING,
470 sentryRelease).ToUTF8().data()
471#endif
472 };
473 CrashpadConfigurer configurer;
474 configurer.SetHandlerPathUTF8(crashpadHandlerPath.GetFullPath().ToUTF8().data())
475 .SetDatabasePathUTF8(databasePath.GetFullPath().ToUTF8().data())
476 .SetMetricsDirUTF8(metricsDir.GetFullPath().ToUTF8().data())
477 .SetArguments(arguments)
478 .Start();
479 }
480 catch (std::exception& e)
481 {
482 wxLogError("Crashpad init error: %s", e.what());
483 }
484 }
485#endif
486#elif !defined(_DEBUG)// Do not capture crashes in debug builds
487#if defined(HAS_CRASH_REPORT)
488#if defined(wxUSE_ON_FATAL_EXCEPTION) && wxUSE_ON_FATAL_EXCEPTION
489 wxHandleFatalExceptions();
490#endif
491#endif
492#endif
493}
This class is used to configure Breakpad's handler before start.
BreakpadConfigurer & SetSenderPathUTF8(const std::string &pathUTF8)
Sets a path to a directory where crash reporter sending program is located.
BreakpadConfigurer & SetParameters(const std::map< std::string, std::string > &parameters)
Sets an additional parameters that should be sent to a crash reporting server (ASCII encoded)
BreakpadConfigurer & SetDatabasePathUTF8(const std::string &pathUTF8)
Sets the directory where crashreports will be stored (should have rw permission)
BreakpadConfigurer & SetReportURL(const std::string &reportURL)
Sets report URL to the crash reporting server (URL-Encoded, optional)
CrashpadConfigurer & SetMetricsDirUTF8(const std::string &metricsDir)
CrashpadConfigurer & SetDatabasePathUTF8(const std::string &database)
CrashpadConfigurer & SetHandlerPathUTF8(const std::string &handlerPath)
CrashpadConfigurer & SetArguments(const std::vector< std::string > &arguments)
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:201
FILES_API FilePath StateDir()
Audacity user state directory.
std::string ToUTF8(const std::wstring &wstr)

References BasicUI::Get(), CrashpadConfigurer::SetArguments(), CrashpadConfigurer::SetDatabasePathUTF8(), BreakpadConfigurer::SetDatabasePathUTF8(), CrashpadConfigurer::SetHandlerPathUTF8(), CrashpadConfigurer::SetMetricsDirUTF8(), BreakpadConfigurer::SetParameters(), BreakpadConfigurer::SetReportURL(), BreakpadConfigurer::SetSenderPathUTF8(), CrashpadConfigurer::Start(), FileNames::StateDir(), and audacity::ToUTF8().

Referenced by AudacityApp::Initialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PopulatePreferences()

void anonymous_namespace{AudacityApp.cpp}::PopulatePreferences ( )

Definition at line 201 of file AudacityApp.cpp.

202{
203 bool resetPrefs = false;
204 wxString langCode = gPrefs->Read(wxT("/Locale/Language"), wxEmptyString);
205 bool writeLang = false;
206
207 const wxFileName fn(
209 wxT("FirstTime.ini"));
210 if (fn.FileExists()) // it will exist if the (win) installer put it there
211 {
212 const wxString fullPath{fn.GetFullPath()};
213
214 auto pIni =
215 AudacityFileConfig::Create({}, {}, fullPath, {},
216 wxCONFIG_USE_LOCAL_FILE);
217 auto &ini = *pIni;
218
219 wxString lang;
220 if (ini.Read(wxT("/FromInno/Language"), &lang) && !lang.empty())
221 {
222 // Only change "langCode" if the language was actually specified in the ini file.
223 langCode = lang;
224 writeLang = true;
225
226 // Inno Setup doesn't allow special characters in the Name values, so "0" is used
227 // to represent the "@" character.
228 langCode.Replace(wxT("0"), wxT("@"));
229 }
230
231 ini.Read(wxT("/FromInno/ResetPrefs"), &resetPrefs, false);
232
233 bool gone = wxRemoveFile(fullPath); // remove FirstTime.ini
234 if (!gone)
235 {
237 XO("Failed to remove %s").Format(fullPath),
238 XO("Failed!"));
239 }
240 }
241
242 // Use the system default language if one wasn't specified or if the user selected System.
243 if (langCode.empty())
244 langCode =
246
247 langCode = GUISettings::SetLang( langCode );
248
249 // User requested that the preferences be completely reset
250 if (resetPrefs)
251 {
253 writeLang = true;
254 }
255
256 // Save the specified language
257 if (writeLang)
258 {
259 gPrefs->Write(wxT("/Locale/Language"), langCode);
260 }
261
262 // In AUdacity 2.1.0 support for the legacy 1.2.x preferences (depreciated since Audacity
263 // 1.3.1) is dropped. As a result we can drop the import flag
264 // first time this version of Audacity is run we try to migrate
265 // old preferences.
266 bool newPrefsInitialized = false;
267 gPrefs->Read(wxT("/NewPrefsInitialized"), &newPrefsInitialized, false);
268 if (newPrefsInitialized) {
269 gPrefs->DeleteEntry(wxT("/NewPrefsInitialized"));
270 }
271
272 // record the Prefs version for future checking (this has not been used for a very
273 // long time).
274 gPrefs->Write(wxT("/PrefsVersion"), wxString(wxT(AUDACITY_PREFS_VERSION_STRING)));
275
276 // Check if some prefs updates need to happen based on audacity version.
277 // Unfortunately we can't use the PrefsVersion prefs key because that resets things.
278 // In the future we may want to integrate that better.
279 // these are done on a case-by-case basis for now so they must be backwards compatible
280 // (meaning the changes won't mess audacity up if the user goes back to an earlier version)
281 int vMajor = gPrefs->Read(wxT("/Version/Major"), (long) 0);
282 int vMinor = gPrefs->Read(wxT("/Version/Minor"), (long) 0);
283 int vMicro = gPrefs->Read(wxT("/Version/Micro"), (long) 0);
284
285 SetPreferencesVersion(vMajor, vMinor, vMicro); // make a note of these initial values
286 // for use by ToolManager::ReadConfig()
287
288 // These integer version keys were introduced april 4 2011 for 1.3.13
289 // The device toolbar needs to be enabled due to removal of source selection features in
290 // the mixer toolbar.
291 if ((vMajor < 1) ||
292 (vMajor == 1 && vMinor < 3) ||
293 (vMajor == 1 && vMinor == 3 && vMicro < 13)) {
294
295
296 // Do a full reset of the Device Toolbar to get it on the screen.
297 if (gPrefs->Exists(wxT("/GUI/ToolBars/Device")))
298 gPrefs->DeleteGroup(wxT("/GUI/ToolBars/Device"));
299
300 // We keep the mixer toolbar prefs (shown/not shown)
301 // the width of the mixer toolbar may have shrunk, the prefs will keep the larger value
302 // if the user had a device that had more than one source.
303 if (gPrefs->Exists(wxT("/GUI/ToolBars/Mixer"))) {
304 // Use the default width
305 gPrefs->Write(wxT("/GUI/ToolBars/Mixer/W"), -1);
306 }
307 }
308
309 // In 2.1.0, the Meter toolbar was split and lengthened, but strange arrangements happen
310 // if upgrading due to the extra length. So, if a user is upgrading, use the pre-2.1.0
311 // lengths, but still use the NEW split versions.
312 if (gPrefs->Exists(wxT("/GUI/ToolBars/Meter")) &&
313 !gPrefs->Exists(wxT("/GUI/ToolBars/CombinedMeter"))) {
314
315 // Read in all of the existing values
316 long dock, order, show, x, y, w, h;
317 gPrefs->Read(wxT("/GUI/ToolBars/Meter/Dock"), &dock, -1L);
318 gPrefs->Read(wxT("/GUI/ToolBars/Meter/Order"), &order, -1L);
319 gPrefs->Read(wxT("/GUI/ToolBars/Meter/Show"), &show, -1L);
320 gPrefs->Read(wxT("/GUI/ToolBars/Meter/X"), &x, -1L);
321 gPrefs->Read(wxT("/GUI/ToolBars/Meter/Y"), &y, -1L);
322 gPrefs->Read(wxT("/GUI/ToolBars/Meter/W"), &w, -1L);
323 gPrefs->Read(wxT("/GUI/ToolBars/Meter/H"), &h, -1L);
324
325 // "Order" must be adjusted since we're inserting two NEW toolbars
326 if (dock > 0) {
327
328 const auto toolbarsGroup = gPrefs->BeginGroup("/GUI/ToolBars");
329 for(const auto& group : gPrefs->GetChildGroups())
330 {
331 long orderValue;
332 const auto orderKey = group + wxT("/Order");
333 if(gPrefs->Read(orderKey, &orderValue) && orderValue >= order)
334 gPrefs->Write(orderKey, orderValue + 2);
335 }
336 // And override the height
337 h = 27;
338 }
339
340 // Write the split meter bar values
341 gPrefs->Write(wxT("/GUI/ToolBars/RecordMeter/Dock"), dock);
342 gPrefs->Write(wxT("/GUI/ToolBars/RecordMeter/Order"), order);
343 gPrefs->Write(wxT("/GUI/ToolBars/RecordMeter/Show"), show);
344 gPrefs->Write(wxT("/GUI/ToolBars/RecordMeter/X"), -1);
345 gPrefs->Write(wxT("/GUI/ToolBars/RecordMeter/Y"), -1);
346 gPrefs->Write(wxT("/GUI/ToolBars/RecordMeter/W"), w);
347 gPrefs->Write(wxT("/GUI/ToolBars/RecordMeter/H"), h);
348 gPrefs->Write(wxT("/GUI/ToolBars/PlayMeter/Dock"), dock);
349 gPrefs->Write(wxT("/GUI/ToolBars/PlayMeter/Order"), order + 1);
350 gPrefs->Write(wxT("/GUI/ToolBars/PlayMeter/Show"), show);
351 gPrefs->Write(wxT("/GUI/ToolBars/PlayMeter/X"), -1);
352 gPrefs->Write(wxT("/GUI/ToolBars/PlayMeter/Y"), -1);
353 gPrefs->Write(wxT("/GUI/ToolBars/PlayMeter/W"), w);
354 gPrefs->Write(wxT("/GUI/ToolBars/PlayMeter/H"), h);
355
356 // And hide the old combined meter bar
357 gPrefs->Write(wxT("/GUI/ToolBars/Meter/Dock"), -1);
358 }
359
360 // Upgrading pre 2.2.0 configs we assume extended set of defaults.
361 if ((0<vMajor && vMajor < 2) ||
362 (vMajor == 2 && vMinor < 2))
363 {
364 gPrefs->Write(wxT("/GUI/Shortcuts/FullDefaults"),1);
365 }
366
367 // Upgrading pre 2.4.0 configs, the selection toolbar is now split.
368 if ((0<vMajor && vMajor < 2) ||
369 (vMajor == 2 && vMinor < 4))
370 {
371 gPrefs->Write(wxT("/GUI/Toolbars/Selection/W"),"");
372 gPrefs->Write(wxT("/GUI/Toolbars/SpectralSelection/W"),"");
373 gPrefs->Write(wxT("/GUI/Toolbars/Time/X"),-1);
374 gPrefs->Write(wxT("/GUI/Toolbars/Time/Y"),-1);
375 gPrefs->Write(wxT("/GUI/Toolbars/Time/H"),55);
376 gPrefs->Write(wxT("/GUI/Toolbars/Time/W"),251);
377 gPrefs->Write(wxT("/GUI/Toolbars/Time/DockV2"),2);
378 gPrefs->Write(wxT("/GUI/Toolbars/Time/Dock"),2);
379 gPrefs->Write(wxT("/GUI/Toolbars/Time/Path"),"0,1");
380 gPrefs->Write(wxT("/GUI/Toolbars/Time/Show"),1);
381 }
382
383 if (std::pair{ vMajor, vMinor } < std::pair{ 3, 1 } ) {
384 // Reset the control toolbar
385 gPrefs->Write(wxT("/GUI/Toolbars/Control/W"), -1);
386 }
387
388 if(std::pair{vMajor, vMinor} < std::pair{3, 2})
389 {
390 if(gPrefs->Exists(wxT("/GUI/ToolBars")))
391 gPrefs->DeleteGroup(wxT("/GUI/ToolBars"));
392 if(gPrefs->Exists(wxT("Window")))
393 gPrefs->DeleteGroup(wxT("Window"));
394 if(gPrefs->Exists("/GUI/ShowSplashScreen"))
395 gPrefs->DeleteEntry("/GUI/ShowSplashScreen");
396 if(gPrefs->Exists("/GUI/Help"))
397 gPrefs->DeleteEntry("/GUI/Help");
398 }
399
400 if(std::tuple{ vMajor, vMinor, vMicro } < std::tuple{ 3, 2, 3 })
401 {
402 // Reset Share Audio width if it was populated before 3.2.3
403 if(gPrefs->Exists("/GUI/ToolBars/Share Audio/W"))
404 gPrefs->DeleteEntry("/GUI/ToolBars/Share Audio/W");
405 }
406
407 // We need to reset the toolbar layout and force the splash screen for 3.4
408 if (std::pair { vMajor, vMinor } < std::pair { 3, 4 })
409 {
410 if (gPrefs->Exists(wxT("/GUI/ToolBars")))
411 gPrefs->DeleteGroup(wxT("/GUI/ToolBars"));
412 if (gPrefs->Exists("/GUI/ShowSplashScreen"))
413 gPrefs->DeleteEntry("/GUI/ShowSplashScreen");
414 }
415
416 if (std::pair { vMajor, vMinor } < std::pair { 3, 5 })
417 {
418 if (gPrefs->Exists("/GUI/ShowSplashScreen"))
419 gPrefs->DeleteEntry("/GUI/ShowSplashScreen");
420 }
421
422 // write out the version numbers to the prefs file for future checking
423 gPrefs->Write(wxT("/Version/Major"), AUDACITY_VERSION);
424 gPrefs->Write(wxT("/Version/Minor"), AUDACITY_RELEASE);
425 gPrefs->Write(wxT("/Version/Micro"), AUDACITY_REVISION);
426
427 gPrefs->Flush();
428}
wxT("CloseDown"))
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
XO("Cut/Copy/Paste")
void SetPreferencesVersion(int vMajor, int vMinor, int vMicro)
Definition: Prefs.cpp:246
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
void ResetPreferences()
Call this to reset preferences to an (almost)-"new" default state.
Definition: Prefs.cpp:253
#define AUDACITY_PREFS_VERSION_STRING
Definition: Prefs.h:39
static const auto fn
static std::unique_ptr< AudacityFileConfig > Create(const wxString &appName={}, const wxString &vendorName={}, const wxString &localFilename={}, const wxString &globalFilename={}, long style=wxCONFIG_USE_LOCAL_FILE|wxCONFIG_USE_GLOBAL_FILE, const wxMBConv &conv=wxConvAuto())
Require a call to this factory, to guarantee proper two-phase initialization.
Abstract base class used in importing a file.
virtual bool Flush() noexcept=0
virtual bool Exists(const wxString &key) const
Returns true if group or entry exists.
GroupScope BeginGroup(const wxString &prefix)
Appends a prefix to the current group or sets a new absolute path. Group that was set as current befo...
bool DeleteGroup(const wxString &key)
Deletes specified group if exists.
virtual bool Write(const wxString &key, bool value)=0
bool DeleteEntry(const wxString &key)
Deletes specified entry if exists.
virtual bool Read(const wxString &key, bool *value) const =0
virtual wxArrayString GetChildGroups() const =0
Returns all child groups within the current group.
FILES_API FilePath ResourcesDir()
FILES_API const FilePaths & AudacityPathList()
A list of directories that should be searched for Audacity files (plug-ins, help files,...
AUDACITY_DLL_API wxString SetLang(const wxString &lang)
Definition: GUISettings.cpp:19
wxString GetSystemLanguageCode(const FilePaths &pathList)
Definition: Languages.cpp:83

References AUDACITY_PREFS_VERSION_STRING, AudacityMessageBox(), FileNames::AudacityPathList(), audacity::BasicSettings::BeginGroup(), AudacityFileConfig::Create(), audacity::BasicSettings::DeleteEntry(), audacity::BasicSettings::DeleteGroup(), audacity::BasicSettings::Exists(), audacity::BasicSettings::Flush(), fn, audacity::BasicSettings::GetChildGroups(), Languages::GetSystemLanguageCode(), gPrefs, audacity::BasicSettings::Read(), ResetPreferences(), FileNames::ResourcesDir(), GUISettings::SetLang(), SetPreferencesVersion(), audacity::BasicSettings::Write(), wxT(), and XO().

Referenced by AudacityApp::OnInit().

Here is the call graph for this function:
Here is the caller graph for this function: