mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 16:10:06 +02:00
Move AudacityPathList & utilities from AudacityApp.h to FileNames.h
This commit is contained in:
parent
757d90d3b9
commit
a1ff74b5bb
@ -98,6 +98,7 @@ public:
|
||||
};
|
||||
|
||||
class wxDialog;
|
||||
class wxWindow;
|
||||
class EffectUIHostInterface;
|
||||
class EffectUIClientInterface;
|
||||
|
||||
|
@ -36,7 +36,6 @@ It handles initialization and termination by subclassing wxApp.
|
||||
#include <wx/docview.h>
|
||||
#include <wx/event.h>
|
||||
#include <wx/ipc.h>
|
||||
#include <wx/log.h>
|
||||
#include <wx/window.h>
|
||||
#include <wx/intl.h>
|
||||
#include <wx/menu.h>
|
||||
@ -989,8 +988,8 @@ wxString AudacityApp::SetLang( const wxString & lang )
|
||||
}
|
||||
mLocale = std::make_unique<wxLocale>(info->Language);
|
||||
|
||||
for(unsigned int i=0; i<audacityPathList.size(); i++)
|
||||
mLocale->AddCatalogLookupPathPrefix(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<wxCmdLineParser> 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<pathList.size(); i++) {
|
||||
if (wxFileName(newpath) == wxFileName(pathList[i]))
|
||||
return;
|
||||
}
|
||||
|
||||
pathList.push_back(newpath);
|
||||
}
|
||||
|
||||
// static
|
||||
void AudacityApp::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);
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
void AudacityApp::FindFilesInPathList(const wxString & pattern,
|
||||
const FilePaths & pathList,
|
||||
FilePaths & results,
|
||||
int flags)
|
||||
{
|
||||
wxLogNull nolog;
|
||||
|
||||
if (pattern.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
wxFileName 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);
|
||||
}
|
||||
}
|
||||
|
||||
void AudacityApp::OnQueryEndSession(wxCloseEvent & event)
|
||||
{
|
||||
bool mustVeto = false;
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include "Experimental.h"
|
||||
|
||||
#include <wx/app.h> // to inherit
|
||||
#include <wx/dir.h> // for wxDIR_FILES
|
||||
#include <wx/timer.h> // 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;}
|
||||
|
||||
|
@ -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 <wx/log.h>
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "Audacity.h"
|
||||
|
||||
#include <wx/dir.h> // for wxDIR_FILES
|
||||
#include <wx/string.h> // 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.
|
||||
//
|
||||
|
@ -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 <unordered_map>
|
||||
|
||||
using LangHash = std::unordered_map<wxString, wxString>;
|
||||
@ -50,18 +49,18 @@ using LangHash = std::unordered_map<wxString, wxString>;
|
||||
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,10 +202,11 @@ 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"),
|
||||
FileNames::AddUniquePathToPathList(
|
||||
wxString::Format(wxT("%s/share/locale"),
|
||||
wxT(INSTALL_PREFIX)),
|
||||
audacityPathList);
|
||||
#endif
|
||||
|
@ -28,7 +28,6 @@ i.e. an alternative to the usual interface, for Audacity.
|
||||
#include <wx/string.h>
|
||||
#include <wx/filename.h>
|
||||
|
||||
#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();
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#include "../../AudacityApp.h"
|
||||
#include "LoadNyquist.h"
|
||||
|
||||
#include <wx/log.h>
|
||||
@ -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++)
|
||||
{
|
||||
|
@ -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());
|
||||
|
||||
|
@ -20,6 +20,8 @@ class wxArrayString;
|
||||
class wxFileNameWrapper : public wxFileName
|
||||
{
|
||||
public:
|
||||
using wxFileName::wxFileName;
|
||||
|
||||
explicit
|
||||
wxFileNameWrapper(const wxFileName &that)
|
||||
: wxFileName(that)
|
||||
|
Loading…
x
Reference in New Issue
Block a user