diff --git a/include/audacity/EffectInterface.h b/include/audacity/EffectInterface.h index 1352a7981..2f22945ea 100755 --- a/include/audacity/EffectInterface.h +++ b/include/audacity/EffectInterface.h @@ -98,6 +98,7 @@ public: }; class wxDialog; +class wxWindow; class EffectUIHostInterface; class EffectUIClientInterface; diff --git a/src/AudacityApp.cpp b/src/AudacityApp.cpp index c48a71e19..f950edaa0 100644 --- a/src/AudacityApp.cpp +++ b/src/AudacityApp.cpp @@ -36,7 +36,6 @@ It handles initialization and termination by subclassing wxApp. #include #include #include -#include #include #include #include @@ -989,8 +988,8 @@ wxString AudacityApp::SetLang( const wxString & lang ) } mLocale = std::make_unique(info->Language); - for(unsigned int i=0; iAddCatalogLookupPathPrefix(audacityPathList[i]); + for( const auto &path : FileNames::AudacityPathList() ) + mLocale->AddCatalogLookupPathPrefix( path ); // LL: Must add the wxWidgets catalog manually since the search // paths were not set up when mLocale was created. The @@ -1266,6 +1265,7 @@ bool AudacityApp::OnInit() // // Paths: set search path and temp dir path // + FilePaths audacityPathList; #ifdef __WXGTK__ /* Search path (for plug-ins, translations etc) is (in this order): @@ -1294,36 +1294,36 @@ bool AudacityApp::OnInit() wxString pathVar = wxGetenv(wxT("DARKAUDACITY_PATH")); #endif if (!pathVar.empty()) - AddMultiPathsToPathList(pathVar, audacityPathList); - AddUniquePathToPathList(::wxGetCwd(), audacityPathList); + FileNames::AddMultiPathsToPathList(pathVar, audacityPathList); + FileNames::AddUniquePathToPathList(::wxGetCwd(), audacityPathList); #ifdef AUDACITY_NAME - AddUniquePathToPathList(wxString::Format(wxT("%s/.%s-files"), + FileNames::AddUniquePathToPathList(wxString::Format(wxT("%s/.%s-files"), home, wxT(AUDACITY_NAME)), audacityPathList); - AddUniquePathToPathList(wxString::Format(wxT("%s/share/%s"), + FileNames::AddUniquePathToPathList(wxString::Format(wxT("%s/share/%s"), wxT(INSTALL_PREFIX), wxT(AUDACITY_NAME)), audacityPathList); - AddUniquePathToPathList(wxString::Format(wxT("%s/share/doc/%s"), + FileNames::AddUniquePathToPathList(wxString::Format(wxT("%s/share/doc/%s"), wxT(INSTALL_PREFIX), wxT(AUDACITY_NAME)), audacityPathList); #else //AUDACITY_NAME - AddUniquePathToPathList(wxString::Format(wxT("%s/.audacity-files"), + FileNames::AddUniquePathToPathList(wxString::Format(wxT("%s/.audacity-files"), home), audacityPathList); - AddUniquePathToPathList(wxString::Format(wxT("%s/share/audacity"), + FileNames::AddUniquePathToPathList(wxString::Format(wxT("%s/share/audacity"), wxT(INSTALL_PREFIX)), audacityPathList); - AddUniquePathToPathList(wxString::Format(wxT("%s/share/doc/audacity"), + FileNames::AddUniquePathToPathList(wxString::Format(wxT("%s/share/doc/audacity"), wxT(INSTALL_PREFIX)), audacityPathList); #endif //AUDACITY_NAME - AddUniquePathToPathList(wxString::Format(wxT("%s/share/locale"), + FileNames::AddUniquePathToPathList(wxString::Format(wxT("%s/share/locale"), wxT(INSTALL_PREFIX)), audacityPathList); - AddUniquePathToPathList(wxString::Format(wxT("./locale")), + FileNames::AddUniquePathToPathList(wxString::Format(wxT("./locale")), audacityPathList); #endif //__WXGTK__ @@ -1346,8 +1346,8 @@ bool AudacityApp::OnInit() #ifdef __WXMSW__ // On Windows, the path to the Audacity program is in argv[0] wxString progPath = wxPathOnly(argv[0]); - AddUniquePathToPathList(progPath, audacityPathList); - AddUniquePathToPathList(progPath + wxT("\\Languages"), audacityPathList); + FileNames::AddUniquePathToPathList(progPath, audacityPathList); + FileNames::AddUniquePathToPathList(progPath + wxT("\\Languages"), audacityPathList); // See bug #1271 for explanation of location tmpDirLoc = FileNames::MkDir(wxStandardPaths::Get().GetUserLocalDataDir()); @@ -1359,14 +1359,16 @@ bool AudacityApp::OnInit() // On Mac OS X, the path to the Audacity program is in argv[0] wxString progPath = wxPathOnly(argv[0]); - AddUniquePathToPathList(progPath, audacityPathList); + FileNames::AddUniquePathToPathList(progPath, audacityPathList); // If Audacity is a "bundle" package, then the root directory is // the great-great-grandparent of the directory containing the executable. - //AddUniquePathToPathList(progPath + wxT("/../../../"), audacityPathList); + //FileNames::AddUniquePathToPathList(progPath + wxT("/../../../"), audacityPathList); // These allow for searching the "bundle" - AddUniquePathToPathList(progPath + wxT("/../"), audacityPathList); - AddUniquePathToPathList(progPath + wxT("/../Resources"), audacityPathList); + FileNames::AddUniquePathToPathList( + progPath + wxT("/../"), audacityPathList); + FileNames::AddUniquePathToPathList( + progPath + wxT("/../Resources"), audacityPathList); // JKC Bug 1220: Using an actual temp directory for session data on Mac was // wrong because it would get cleared out on a reboot. @@ -1379,6 +1381,8 @@ bool AudacityApp::OnInit() // wxGetUserId() ) ); #endif //__WXMAC__ + FileNames::SetAudacityPathList( std::move( audacityPathList ) ); + // Define languanges for which we have translations, but that are not yet // supported by wxWidgets. // @@ -2021,54 +2025,6 @@ std::unique_ptr AudacityApp::ParseCommandLine() return{}; } -// static -void AudacityApp::AddUniquePathToPathList(const FilePath &pathArg, - FilePaths &pathList) -{ - wxFileName pathNorm = pathArg; - pathNorm.Normalize(); - const wxString newpath{ pathNorm.GetFullPath() }; - - for(unsigned int i=0; i // to inherit -#include // for wxDIR_FILES #include // member variable #if defined(EXPERIMENTAL_CRASH_REPORT) @@ -113,26 +112,6 @@ class AudacityApp final : public wxApp { void AssociateFileTypes(); #endif - /** \brief A list of directories that should be searched for Audacity files - * (plug-ins, help files, etc.). - * - * On Unix this will include the directory Audacity was installed into, - * plus the current user's .audacity-data/Plug-Ins directory. Additional - * directories can be specified using the AUDACITY_PATH environment - * variable. On Windows or Mac OS, this will include the directory - * which contains the Audacity program. */ - FilePaths audacityPathList; - - // Useful functions for working with search paths - static void AddUniquePathToPathList(const FilePath &path, - FilePaths &pathList); - static void AddMultiPathsToPathList(const wxString &multiPathString, - FilePaths &pathList); - static void FindFilesInPathList(const wxString & pattern, - const FilePaths & pathList, - FilePaths &results, - int flags = wxDIR_FILES); - bool GetWindowRectAlreadySaved()const {return mWindowRectAlreadySaved;} void SetWindowRectAlreadySaved(bool alreadySaved) {mWindowRectAlreadySaved = alreadySaved;} diff --git a/src/FileNames.cpp b/src/FileNames.cpp index 9b197a6a6..16cbe7725 100644 --- a/src/FileNames.cpp +++ b/src/FileNames.cpp @@ -519,3 +519,65 @@ bool FileNames::IsTempDirectoryNameOK( const FilePath & Name ) #endif return !(NameCanonical.StartsWith( BadPath )); } + +static FilePaths sAudacityPathList; + +const FilePaths &FileNames::AudacityPathList() +{ + return sAudacityPathList; +} + +void FileNames::SetAudacityPathList( FilePaths list ) +{ + sAudacityPathList = std::move( list ); +} + +// static +void FileNames::AddUniquePathToPathList(const FilePath &pathArg, + FilePaths &pathList) +{ + wxFileNameWrapper pathNorm { pathArg }; + pathNorm.Normalize(); + const wxString newpath{ pathNorm.GetFullPath() }; + + for(const auto &path : pathList) { + if (pathNorm == wxFileNameWrapper{ path }) + return; + } + + pathList.push_back(newpath); +} + +// static +void FileNames::AddMultiPathsToPathList(const wxString &multiPathStringArg, + FilePaths &pathList) +{ + wxString multiPathString(multiPathStringArg); + while (!multiPathString.empty()) { + wxString onePath = multiPathString.BeforeFirst(wxPATH_SEP[0]); + multiPathString = multiPathString.AfterFirst(wxPATH_SEP[0]); + AddUniquePathToPathList(onePath, pathList); + } +} + +#include + +// static +void FileNames::FindFilesInPathList(const wxString & pattern, + const FilePaths & pathList, + FilePaths & results, + int flags) +{ + wxLogNull nolog; + + if (pattern.empty()) { + return; + } + + wxFileNameWrapper ff; + + for(size_t i = 0; i < pathList.size(); i++) { + ff = pathList[i] + wxFILE_SEP_PATH + pattern; + wxDir::GetAllFiles(ff.GetPath(), &results, ff.GetFullName(), flags); + } +} diff --git a/src/FileNames.h b/src/FileNames.h index 16c7851cb..b1ae52024 100644 --- a/src/FileNames.h +++ b/src/FileNames.h @@ -13,6 +13,7 @@ #include "Audacity.h" +#include // for wxDIR_FILES #include // function return value #include "audacity/Types.h" @@ -40,6 +41,17 @@ public: static void SetDefaultTempDir( const FilePath &tempDir ); static bool IsTempDirectoryNameOK( const FilePath & Name ); + /** \brief A list of directories that should be searched for Audacity files + * (plug-ins, help files, etc.). + * + * On Unix this will include the directory Audacity was installed into, + * plus the current user's .audacity-data/Plug-Ins directory. Additional + * directories can be specified using the AUDACITY_PATH environment + * variable. On Windows or Mac OS, this will include the directory + * which contains the Audacity program. */ + static const FilePaths &AudacityPathList(); + static void SetAudacityPathList( FilePaths list ); + // originally an ExportMultiple method. Append suffix if newName appears in otherNames. static void MakeNameUnique( FilePaths &otherNames, wxFileName &newName); @@ -123,6 +135,16 @@ public: int flags, wxWindow *parent); + // Useful functions for working with search paths + static void AddUniquePathToPathList(const FilePath &path, + FilePaths &pathList); + static void AddMultiPathsToPathList(const wxString &multiPathString, + FilePaths &pathList); + static void FindFilesInPathList(const wxString & pattern, + const FilePaths & pathList, + FilePaths &results, + int flags = wxDIR_FILES); + private: // Private constructors: No one is ever going to instantiate it. // diff --git a/src/Languages.cpp b/src/Languages.cpp index becd2f273..0c70e9d34 100644 --- a/src/Languages.cpp +++ b/src/Languages.cpp @@ -32,6 +32,7 @@ #include "Audacity.h" #include "Languages.h" +#include "MemoryX.h" #include "audacity/Types.h" @@ -41,8 +42,6 @@ #include "FileNames.h" -#include "AudacityApp.h" - #include using LangHash = std::unordered_map; @@ -50,18 +49,18 @@ using LangHash = std::unordered_map; static bool TranslationExists(const FilePaths &audacityPathList, wxString code) { FilePaths results; - wxGetApp().FindFilesInPathList(wxString::Format(wxT("%s/audacity.mo"), + FileNames::FindFilesInPathList(wxString::Format(wxT("%s/audacity.mo"), code), audacityPathList, results); #if defined(__WXMAC__) - wxGetApp().FindFilesInPathList(wxString::Format(wxT("%s.lproj/audacity.mo"), + FileNames::FindFilesInPathList(wxString::Format(wxT("%s.lproj/audacity.mo"), code), audacityPathList, results); #endif - wxGetApp().FindFilesInPathList(wxString::Format(wxT("%s/LC_MESSAGES/audacity.mo"), + FileNames::FindFilesInPathList(wxString::Format(wxT("%s/LC_MESSAGES/audacity.mo"), code), audacityPathList, results); @@ -203,12 +202,13 @@ void GetLanguages(wxArrayString &langCodes, wxArrayString &langNames) localLanguageName[code] = name; } - auto audacityPathList = wxGetApp().audacityPathList; + auto audacityPathList = FileNames::AudacityPathList(); #if defined(__WXGTK__) - wxGetApp().AddUniquePathToPathList(wxString::Format(wxT("%s/share/locale"), - wxT(INSTALL_PREFIX)), - audacityPathList); + FileNames::AddUniquePathToPathList( + wxString::Format(wxT("%s/share/locale"), + wxT(INSTALL_PREFIX)), + audacityPathList); #endif // For each language in our list we look for a corresponding entry in diff --git a/src/ModuleManager.cpp b/src/ModuleManager.cpp index e21a03caf..b26cca80e 100755 --- a/src/ModuleManager.cpp +++ b/src/ModuleManager.cpp @@ -28,7 +28,6 @@ i.e. an alternative to the usual interface, for Audacity. #include #include -#include "AudacityApp.h" #include "FileNames.h" #include "PluginManager.h" @@ -212,7 +211,7 @@ ModuleManager::~ModuleManager() // static void ModuleManager::Initialize(CommandHandler &cmdHandler) { - const auto &audacityPathList = wxGetApp().audacityPathList; + const auto &audacityPathList = FileNames::AudacityPathList(); FilePaths pathList; FilePaths files; wxString pathVar; @@ -221,18 +220,18 @@ void ModuleManager::Initialize(CommandHandler &cmdHandler) // Code from LoadLadspa that might be useful in load modules. pathVar = wxGetenv(wxT("AUDACITY_MODULES_PATH")); if (!pathVar.empty()) - wxGetApp().AddMultiPathsToPathList(pathVar, pathList); + FileNames::AddMultiPathsToPathList(pathVar, pathList); for (i = 0; i < audacityPathList.size(); i++) { wxString prefix = audacityPathList[i] + wxFILE_SEP_PATH; - wxGetApp().AddUniquePathToPathList(prefix + wxT("modules"), + FileNames::AddUniquePathToPathList(prefix + wxT("modules"), pathList); } #if defined(__WXMSW__) - wxGetApp().FindFilesInPathList(wxT("*.dll"), pathList, files); + FileNames::FindFilesInPathList(wxT("*.dll"), pathList, files); #else - wxGetApp().FindFilesInPathList(wxT("*.so"), pathList, files); + FileNames::FindFilesInPathList(wxT("*.so"), pathList, files); #endif wxString saveOldCWD = ::wxGetCwd(); @@ -357,19 +356,19 @@ bool ModuleManager::DiscoverProviders() if (!pathVar.empty()) { - wxGetApp().AddMultiPathsToPathList(pathVar, pathList); + FileNames::AddMultiPathsToPathList(pathVar, pathList); } else { - wxGetApp().AddUniquePathToPathList(FileNames::ModulesDir(), pathList); + FileNames::AddUniquePathToPathList(FileNames::ModulesDir(), pathList); } #if defined(__WXMSW__) - wxGetApp().FindFilesInPathList(wxT("*.dll"), pathList, provList); + FileNames::FindFilesInPathList(wxT("*.dll"), pathList, provList); #elif defined(__WXMAC__) - wxGetApp().FindFilesInPathList(wxT("*.dylib"), pathList, provList); + FileNames::FindFilesInPathList(wxT("*.dylib"), pathList, provList); #else - wxGetApp().FindFilesInPathList(wxT("*.so"), pathList, provList); + FileNames::FindFilesInPathList(wxT("*.so"), pathList, provList); #endif PluginManager & pm = PluginManager::Get(); diff --git a/src/effects/nyquist/LoadNyquist.cpp b/src/effects/nyquist/LoadNyquist.cpp index 16bf8e849..881c31369 100644 --- a/src/effects/nyquist/LoadNyquist.cpp +++ b/src/effects/nyquist/LoadNyquist.cpp @@ -8,7 +8,6 @@ **********************************************************************/ -#include "../../AudacityApp.h" #include "LoadNyquist.h" #include @@ -129,7 +128,7 @@ wxString NyquistEffectsModule::GetDescription() bool NyquistEffectsModule::Initialize() { - const auto &audacityPathList = wxGetApp().audacityPathList; + const auto &audacityPathList = FileNames::AudacityPathList(); for (size_t i = 0, cnt = audacityPathList.size(); i < cnt; i++) { diff --git a/src/effects/nyquist/Nyquist.cpp b/src/effects/nyquist/Nyquist.cpp index 0f4ce058c..2fd25c8b8 100644 --- a/src/effects/nyquist/Nyquist.cpp +++ b/src/effects/nyquist/Nyquist.cpp @@ -2350,15 +2350,15 @@ void NyquistEffect::OSCallback() FilePaths NyquistEffect::GetNyquistSearchPath() { - const auto &audacityPathList = wxGetApp().audacityPathList; + const auto &audacityPathList = FileNames::AudacityPathList(); FilePaths pathList; for (size_t i = 0; i < audacityPathList.size(); i++) { wxString prefix = audacityPathList[i] + wxFILE_SEP_PATH; - wxGetApp().AddUniquePathToPathList(prefix + wxT("nyquist"), pathList); - wxGetApp().AddUniquePathToPathList(prefix + wxT("plugins"), pathList); - wxGetApp().AddUniquePathToPathList(prefix + wxT("plug-ins"), pathList); + FileNames::AddUniquePathToPathList(prefix + wxT("nyquist"), pathList); + FileNames::AddUniquePathToPathList(prefix + wxT("plugins"), pathList); + FileNames::AddUniquePathToPathList(prefix + wxT("plug-ins"), pathList); } pathList.push_back(FileNames::PlugInDir()); diff --git a/src/wxFileNameWrapper.h b/src/wxFileNameWrapper.h index 922c72eb0..078532c3d 100644 --- a/src/wxFileNameWrapper.h +++ b/src/wxFileNameWrapper.h @@ -20,7 +20,9 @@ class wxArrayString; class wxFileNameWrapper : public wxFileName { public: - explicit + using wxFileName::wxFileName; + + explicit wxFileNameWrapper(const wxFileName &that) : wxFileName(that) {}