MCPcopy Create free account
hub / github.com/audacity/audacity / AssociateFileTypes

Method AssociateFileTypes

src/AudacityApp.cpp:2674–2825  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2672*/
2673#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) && !defined(__CYGWIN__)
2674void AudacityApp::AssociateFileTypes()
2675{
2676 // Check pref in case user has already decided against it.
2677 bool bWantAssociateFiles = true;
2678 if (gPrefs->Read(wxT("/WantAssociateFiles"), &bWantAssociateFiles) &&
2679 !bWantAssociateFiles)
2680 {
2681 // User has already decided against it
2682 return;
2683 }
2684
2685 wxRegKey associateFileTypes;
2686
2687 auto IsDefined = [&](const wxString &type)
2688 {
2689 associateFileTypes.SetName(wxString::Format(wxT("HKCR\\%s"), type));
2690 bool bKeyExists = associateFileTypes.Exists();
2691 if (!bKeyExists)
2692 {
2693 // Not at HKEY_CLASSES_ROOT. Try HKEY_CURRENT_USER.
2694 associateFileTypes.SetName(wxString::Format(wxT("HKCU\\Software\\Classes\\%s"), type));
2695 bKeyExists = associateFileTypes.Exists();
2696 }
2697 return bKeyExists;
2698 };
2699
2700 auto DefineType = [&](const wxString &type)
2701 {
2702 wxString root_key = wxT("HKCU\\Software\\Classes\\");
2703
2704 // Start with HKEY_CLASSES_CURRENT_USER.
2705 associateFileTypes.SetName(wxString::Format(wxT("%s%s"), root_key, type));
2706 if (!associateFileTypes.Create(true))
2707 {
2708 // Not at HKEY_CLASSES_CURRENT_USER. Try HKEY_CURRENT_ROOT.
2709 root_key = wxT("HKCR\\");
2710 associateFileTypes.SetName(wxString::Format(wxT("%s%s"), root_key, type));
2711 if (!associateFileTypes.Create(true))
2712 {
2713 // Actually, can't create keys. Empty root_key to flag failure.
2714 root_key.empty();
2715 }
2716 }
2717
2718 if (!root_key.empty())
2719 {
2720 associateFileTypes = wxT("Audacity.Project"); // Finally set value for the key
2721 }
2722
2723 return root_key;
2724 };
2725
2726 // Check for legacy and UP types
2727 if (IsDefined(wxT(".aup3")) && IsDefined(wxT(".aup")) && IsDefined(wxT("Audacity.Project")))
2728 {
2729 // Already defined, so bail
2730 return;
2731 }

Callers 1

InitPart2Method · 0.95

Calls 9

AudacityMessageBoxFunction · 0.85
ExistsMethod · 0.80
ReadMethod · 0.45
SetNameMethod · 0.45
CreateMethod · 0.45
emptyMethod · 0.45
WriteMethod · 0.45
FlushMethod · 0.45
FindMethod · 0.45

Tested by

no test coverage detected