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 441 of file AudacityApp.cpp.

442{
443#if defined(USE_BREAKPAD) || defined(USE_CRASHPAD)
444 wxFileName databasePath;
445 databasePath.SetPath(FileNames::StateDir());
446 databasePath.AppendDir("crashreports");
447 databasePath.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
448
449 if(databasePath.DirExists())
450 {
451 const auto sentryRelease = wxString::Format(
452 "audacity@%d.%d.%d", AUDACITY_VERSION, AUDACITY_RELEASE, AUDACITY_REVISION);
453#if defined(USE_BREAKPAD)
454 BreakpadConfigurer configurer;
455 configurer.SetDatabasePathUTF8(databasePath.GetPath().ToUTF8().data())
456 .SetSenderPathUTF8(wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath().ToUTF8().data())
457 #if defined(CRASH_REPORT_URL)
458 .SetReportURL(CRASH_REPORT_URL)
459 #endif
461 { "version", wxString(AUDACITY_VERSION_STRING).ToUTF8().data() },
462 { "sentry[release]", sentryRelease.ToUTF8().data() }
463 })
464 .Start();
465#elif defined(USE_CRASHPAD)
466 try
467 {
468 const auto executableDir = wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath();
469 const wxFileName crashpadHandlerPath(executableDir, CRASHPAD_HANDLER_NAME);
470 const wxFileName crashreporterPath(executableDir, CRASHREPORTER_NAME);
471 const wxFileName metricsDir = databasePath;
472 std::vector<std::string> arguments = {
473 wxString::Format("--crashreporter-path=%s", crashreporterPath.GetFullPath()).ToUTF8().data(),
474#if defined(CRASH_REPORT_URL)
475 wxString::Format(
476 "--crashreporter-argument=-u=%s",
477 CRASH_REPORT_URL).ToUTF8().data(),
478 wxString::Format(
479 "--crashreporter-argument=-a=version=\"%s\",sentry[release]=\"%s\"",
480 AUDACITY_VERSION_STRING,
481 sentryRelease).ToUTF8().data()
482#endif
483 };
484 CrashpadConfigurer configurer;
485 configurer.SetHandlerPathUTF8(crashpadHandlerPath.GetFullPath().ToUTF8().data())
486 .SetDatabasePathUTF8(databasePath.GetFullPath().ToUTF8().data())
487 .SetMetricsDirUTF8(metricsDir.GetFullPath().ToUTF8().data())
488 .SetArguments(arguments)
489 .Start();
490 }
491 catch (std::exception& e)
492 {
493 wxLogError("Crashpad init error: %s", e.what());
494 }
495 }
496#endif
497#elif !defined(_DEBUG)// Do not capture crashes in debug builds
498#if defined(HAS_CRASH_REPORT)
499#if defined(wxUSE_ON_FATAL_EXCEPTION) && wxUSE_ON_FATAL_EXCEPTION
500 wxHandleFatalExceptions();
501#endif
502#endif
503#endif
504}
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:202
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 204 of file AudacityApp.cpp.

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