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

424{
425#if defined(USE_BREAKPAD) || defined(USE_CRASHPAD)
426 wxFileName databasePath;
427 databasePath.SetPath(FileNames::StateDir());
428 databasePath.AppendDir("crashreports");
429 databasePath.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
430
431 if(databasePath.DirExists())
432 {
433 const auto sentryRelease = wxString::Format(
434 "audacity@%d.%d.%d", AUDACITY_VERSION, AUDACITY_RELEASE, AUDACITY_REVISION);
435#if defined(USE_BREAKPAD)
436 BreakpadConfigurer configurer;
437 configurer.SetDatabasePathUTF8(databasePath.GetPath().ToUTF8().data())
438 .SetSenderPathUTF8(wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath().ToUTF8().data())
439 #if defined(CRASH_REPORT_URL)
440 .SetReportURL(CRASH_REPORT_URL)
441 #endif
443 { "version", wxString(AUDACITY_VERSION_STRING).ToUTF8().data() },
444 { "sentry[release]", sentryRelease.ToUTF8().data() }
445 })
446 .Start();
447#elif defined(USE_CRASHPAD)
448 try
449 {
450 const auto executableDir = wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath();
451 const wxFileName crashpadHandlerPath(executableDir, CRASHPAD_HANDLER_NAME);
452 const wxFileName crashreporterPath(executableDir, CRASHREPORTER_NAME);
453 const wxFileName metricsDir = databasePath;
454 std::vector<std::string> arguments = {
455 wxString::Format("--crashreporter-path=%s", crashreporterPath.GetFullPath()).ToUTF8().data(),
456#if defined(CRASH_REPORT_URL)
457 wxString::Format(
458 "--crashreporter-argument=-u=%s",
459 CRASH_REPORT_URL).ToUTF8().data(),
460 wxString::Format(
461 "--crashreporter-argument=-a=version=\"%s\",sentry[release]=\"%s\"",
462 AUDACITY_VERSION_STRING,
463 sentryRelease).ToUTF8().data()
464#endif
465 };
466 CrashpadConfigurer configurer;
467 configurer.SetHandlerPathUTF8(crashpadHandlerPath.GetFullPath().ToUTF8().data())
468 .SetDatabasePathUTF8(databasePath.GetFullPath().ToUTF8().data())
469 .SetMetricsDirUTF8(metricsDir.GetFullPath().ToUTF8().data())
470 .SetArguments(arguments)
471 .Start();
472 }
473 catch (std::exception& e)
474 {
475 wxLogError("Crashpad init error: %s", e.what());
476 }
477 }
478#endif
479#elif !defined(_DEBUG)// Do not capture crashes in debug builds
480#if defined(HAS_CRASH_REPORT)
481#if defined(wxUSE_ON_FATAL_EXCEPTION) && wxUSE_ON_FATAL_EXCEPTION
482 wxHandleFatalExceptions();
483#endif
484#endif
485#endif
486}
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:196
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 200 of file AudacityApp.cpp.

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