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

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

References BasicUI::Get(), PlatformCompatibility::GetExecutablePath(), 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 205 of file AudacityApp.cpp.

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