1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-19 17:40:15 +02:00

Sweep for filename copying: various

This commit is contained in:
Paul Licameli 2016-02-22 00:17:20 -05:00
parent 2d7e21536e
commit f00144e9a5
15 changed files with 91 additions and 80 deletions

View File

@ -832,7 +832,7 @@ void AudacityApp::OnMRUClear(wxCommandEvent& WXUNUSED(event))
// Better, for example, to check the file type early on.
void AudacityApp::OnMRUFile(wxCommandEvent& event) {
int n = event.GetId() - ID_RECENT_FIRST;
wxString fullPathStr = mRecentFiles->GetHistoryFile(n);
const wxString &fullPathStr = mRecentFiles->GetHistoryFile(n);
// Try to open only if not already open.
// Test IsAlreadyOpen() here even though AudacityProject::MRUOpen() also now checks,
@ -852,7 +852,8 @@ void AudacityApp::OnTimer(wxTimerEvent& WXUNUSED(event))
if (ofqueue.GetCount()) {
// Load each file on the queue
while (ofqueue.GetCount()) {
wxString name(ofqueue[0]);
wxString name;
name.swap(ofqueue[0]);
ofqueue.RemoveAt(0);
// Get the user's attention if no file name was specified
@ -1860,14 +1861,14 @@ void AudacityApp::AddUniquePathToPathList(const wxString &pathArg,
{
wxFileName pathNorm = pathArg;
pathNorm.Normalize();
wxString path = pathNorm.GetFullPath();
const wxString newpath{ pathNorm.GetFullPath() };
for(unsigned int i=0; i<pathList.GetCount(); i++) {
if (wxFileName(path) == wxFileName(pathList[i]))
if (wxFileName(newpath) == wxFileName(pathList[i]))
return;
}
pathList.Add(path);
pathList.Add(newpath);
}
// static
@ -1894,11 +1895,11 @@ void AudacityApp::FindFilesInPathList(const wxString & pattern,
return;
}
wxFileName f;
wxFileName ff;
for(size_t i = 0; i < pathList.GetCount(); i++) {
f = pathList[i] + wxFILE_SEP_PATH + pattern;
wxDir::GetAllFiles(f.GetPath(), &results, f.GetFullName(), flags);
ff = pathList[i] + wxFILE_SEP_PATH + pattern;
wxDir::GetAllFiles(ff.GetPath(), &results, ff.GetFullName(), flags);
}
}

View File

@ -123,7 +123,7 @@ void AutoRecoveryDialog::PopulateList()
int i = 0;
for (bool c = dir.GetFirst(&filename, wxT("*.autosave"), wxDIR_FILES);
c; c = dir.GetNext(&filename))
mFileList->InsertItem(i++, wxFileName(filename).GetName());
mFileList->InsertItem(i++, wxFileName{ filename }.GetName());
mFileList->SetColumnWidth(0, wxLIST_AUTOSIZE);
}
@ -685,10 +685,11 @@ bool AutoSaveFile::Decode(const wxString & fileName)
char ident[sizeof(AutoSaveIdent)];
size_t len = strlen(AutoSaveIdent);
wxFileName fn(fileName);
const wxFileName fn(fileName);
const wxString fnPath{fn.GetFullPath()};
wxFFile file;
if (!file.Open(fn.GetFullPath(), wxT("rb")))
if (!file.Open(fnPath, wxT("rb")))
{
return false;
}
@ -703,7 +704,7 @@ bool AutoSaveFile::Decode(const wxString & fileName)
file.Close();
// Add </project> tag, if necessary
if (!file.Open(fn.GetFullPath(), wxT("r+b")))
if (!file.Open(fnPath, wxT("r+b")))
{
// Really shouldn't happen, but let the caller deal with it
return false;
@ -749,7 +750,7 @@ bool AutoSaveFile::Decode(const wxString & fileName)
file.Close();
// Decode to a temporary file to preserve the orignal.
wxString tempName = fn.CreateTempFileName(fn.GetFullPath());
wxString tempName = fn.CreateTempFileName(fnPath);
bool opened = false;
XMLFileWriter out;

View File

@ -413,7 +413,7 @@ bool BatchCommands::IsMono()
wxString BatchCommands::BuildCleanFileName(const wxString &fileName, const wxString &extension)
{
wxFileName newFileName(fileName);
const wxFileName newFileName{ fileName };
wxString justName = newFileName.GetName();
wxString pathName = newFileName.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
@ -776,9 +776,10 @@ wxArrayString BatchCommands::GetNames()
wxDir::GetAllFiles(FileNames::ChainDir(), &files, wxT("*.txt"), wxDIR_FILES);
size_t i;
wxFileName ff;
for (i = 0; i < files.GetCount(); i++) {
wxFileName f(files[i]);
names.Add(f.GetName());
ff = (files[i]);
names.Add(ff.GetName());
}
return names;

View File

@ -262,12 +262,12 @@ int ufile_fopen_input(std::unique_ptr<FFmpegContext> &context_ptr, wxString & na
context_ptr.reset();
auto context = std::make_unique<FFmpegContext>();
wxFileName f(name);
wxFileName ff{ name };
wxCharBuffer fname;
const char *filename;
int err;
fname = f.GetFullName().mb_str();
fname = ff.GetFullName().mb_str();
filename = (const char *) fname;
// Open the file to prepare for probing
@ -458,7 +458,7 @@ class FindFFmpegDialog final : public wxDialog
{
public:
FindFFmpegDialog(wxWindow *parent, wxString path, wxString name, wxString type)
FindFFmpegDialog(wxWindow *parent, const wxString &path, const wxString &name, const wxString &type)
: wxDialog(parent, wxID_ANY, wxString(_("Locate FFmpeg")))
{
SetName(GetTitle());
@ -606,7 +606,7 @@ bool FFmpegLibs::FindLibs(wxWindow *parent)
wxLogMessage(wxT("Looking for FFmpeg libraries..."));
if (!mLibAVFormatPath.IsEmpty()) {
wxLogMessage(wxT("mLibAVFormatPath ('%s') is not empty."), mLibAVFormatPath.c_str());
wxFileName fn = mLibAVFormatPath;
const wxFileName fn{ mLibAVFormatPath };
path = fn.GetPath();
name = fn.GetFullName();
}
@ -663,7 +663,7 @@ bool FFmpegLibs::LoadLibs(wxWindow * WXUNUSED(parent), bool showerr)
// If not successful, try loading it from default path
if (!mLibsLoaded && !GetLibAVFormatPath().IsEmpty()) {
wxFileName fn(GetLibAVFormatPath(), GetLibAVFormatName());
const wxFileName fn{ GetLibAVFormatPath(), GetLibAVFormatName() };
wxString path = fn.GetFullPath();
wxLogMessage(wxT("Trying to load FFmpeg libraries from default path, '%s'."), path.c_str());
mLibsLoaded = InitLibs(path,showerr);
@ -675,7 +675,7 @@ bool FFmpegLibs::LoadLibs(wxWindow * WXUNUSED(parent), bool showerr)
#if defined(__WXMAC__)
// If not successful, try loading it from legacy path
if (!mLibsLoaded && !GetLibAVFormatPath().IsEmpty()) {
wxFileName fn(wxT("/usr/local/lib/audacity"), GetLibAVFormatName());
const wxFileName fn{wxT("/usr/local/lib/audacity"), GetLibAVFormatName()};
wxString path = fn.GetFullPath();
wxLogMessage(wxT("Trying to load FFmpeg libraries from legacy path, '%s'."), path.c_str());
mLibsLoaded = InitLibs(path,showerr);
@ -738,9 +738,9 @@ bool FFmpegLibs::InitLibs(const wxString &libpath_format, bool WXUNUSED(showerr)
if (wxGetEnv(wxT("PATH"),&syspath))
{
wxLogMessage(wxT("PATH = '%s'"), syspath.c_str());
wxString fmtdirsc = wxPathOnly(libpath_format) + wxT(";");
wxString scfmtdir = wxT(";") + wxPathOnly(libpath_format);
wxString fmtdir = wxPathOnly(libpath_format);
const wxString &fmtdir{ wxPathOnly(libpath_format) };
wxString fmtdirsc = fmtdir + wxT(";");
wxString scfmtdir = wxT(";") + fmtdir;
wxLogMessage(wxT("Checking that '%s' is in PATH..."), fmtdir.c_str());
// If the directory, where libavformat is, is not in PATH - add it
if (!syspath.Contains(fmtdirsc) && !syspath.Contains(scfmtdir) && !syspath.Contains(fmtdir))
@ -780,20 +780,21 @@ bool FFmpegLibs::InitLibs(const wxString &libpath_format, bool WXUNUSED(showerr)
wxDynamicLibrary *util = NULL;
wxFileName avcodec_filename;
wxFileName avutil_filename;
wxFileName name(libpath_format);
wxFileName name{ libpath_format };
wxString nameFull{name.GetFullPath()};
bool gotError = false;
// Check for a monolithic avformat
avformat = new wxDynamicLibrary();
wxLogMessage(wxT("Checking for monolithic avformat from '%s'."), name.GetFullPath().c_str());
gotError = !avformat->Load(name.GetFullPath(), wxDL_LAZY);
wxLogMessage(wxT("Checking for monolithic avformat from '%s'."), nameFull.c_str());
gotError = !avformat->Load(nameFull, wxDL_LAZY);
// Verify it really is monolithic
if (!gotError) {
avutil_filename = FileNames::PathFromAddr(avformat->GetSymbol(wxT("avutil_version")));
avcodec_filename = FileNames::PathFromAddr(avformat->GetSymbol(wxT("avcodec_version")));
if (avutil_filename.GetFullPath().IsSameAs(name.GetFullPath())) {
if (avcodec_filename.GetFullPath().IsSameAs(name.GetFullPath())) {
if (avutil_filename.GetFullPath().IsSameAs(nameFull)) {
if (avcodec_filename.GetFullPath().IsSameAs(nameFull)) {
util = avformat;
codec = avformat;
}
@ -816,22 +817,27 @@ bool FFmpegLibs::InitLibs(const wxString &libpath_format, bool WXUNUSED(showerr)
}
}
// The two wxFileNames don't change after this
const wxString avcodec_filename_full{ avcodec_filename.GetFullPath() };
const wxString avutil_filename_full{ avutil_filename.GetFullPath() };
if (!util) {
avutil = util = new wxDynamicLibrary();
wxLogMessage(wxT("Loading avutil from '%s'."), avutil_filename.GetFullPath().c_str());
util->Load(avutil_filename.GetFullPath(), wxDL_LAZY);
wxLogMessage(wxT("Loading avutil from '%s'."), avutil_filename_full.c_str());
util->Load(avutil_filename_full, wxDL_LAZY);
}
if (!codec) {
avcodec = codec = new wxDynamicLibrary();
wxLogMessage(wxT("Loading avcodec from '%s'."), avcodec_filename.GetFullPath().c_str());
codec->Load(avcodec_filename.GetFullPath(), wxDL_LAZY);
wxLogMessage(wxT("Loading avcodec from '%s'."), avcodec_filename_full.c_str());
codec->Load(avcodec_filename_full, wxDL_LAZY);
}
if (!avformat->IsLoaded()) {
name.SetFullName(libpath_format);
wxLogMessage(wxT("Loading avformat from '%s'."), name.GetFullPath().c_str());
gotError = !avformat->Load(name.GetFullPath(), wxDL_LAZY);
nameFull = name.GetFullPath();
wxLogMessage(wxT("Loading avformat from '%s'."), nameFull.c_str());
gotError = !avformat->Load(nameFull, wxDL_LAZY);
}
#if defined(__WXMSW__)

View File

@ -50,8 +50,7 @@ void Internat::Init()
// wxLogDebug(wxT("Decimal separator set to '%c'"), mDecimalSeparator);
// Setup list of characters that aren't allowed in file names
wxFileName tmpFile;
forbid = tmpFile.GetForbiddenChars();
forbid = wxFileName::GetForbiddenChars();
for(unsigned int i=0; i < forbid.Length(); i++)
exclude.Add( forbid.Mid(i, 1) );
}
@ -183,15 +182,17 @@ char *Internat::VerifyFilename(const wxString &s, bool input)
}
}
else {
wxFileName f(name);
wxFileName ff(name);
wxString ext;
while ((char *) (const char *)name.mb_str() == NULL) {
wxMessageBox(_("The specified filename could not be converted due to Unicode character use."));
ext = ff.GetExt();
name = FileSelector(_("Specify New Filename:"),
wxEmptyString,
name,
f.GetExt(),
wxT("*.") + f.GetExt(),
ext,
wxT("*.") + ext,
wxFD_SAVE | wxRESIZE_BORDER,
wxGetTopLevelParent(NULL));
}

View File

@ -284,7 +284,7 @@ static bool ConvertLegacyTrack(wxTextFile *f, XMLFileWriter &xmlFile)
return false;
}
bool ConvertLegacyProjectFile(wxFileName filename)
bool ConvertLegacyProjectFile(const wxFileName &filename)
{
wxTextFile f;
XMLFileWriter xmlFile;

View File

@ -11,4 +11,4 @@
#include <wx/defs.h>
#include <wx/filename.h>
bool ConvertLegacyProjectFile(wxFileName filename);
bool ConvertLegacyProjectFile(const wxFileName &filename);

View File

@ -31,7 +31,7 @@ wxString PlatformCompatibility::GetLongFileName(const wxString& shortFileName)
return fn.GetLongPath();
}
wxString PlatformCompatibility::GetExecutablePath()
const wxString &PlatformCompatibility::GetExecutablePath()
{
static bool found = false;
static wxString path;

View File

@ -36,8 +36,9 @@ public:
//
// Get filename and path of executable (e.g. "/usr/bin/audacity" on
// Linux or "C:\Program Files\Audacity\Audacity.exe" on Windows)
// This string is unchanging
//
static wxString GetExecutablePath();
static const wxString &GetExecutablePath();
//
// Audacity treats the / as a file seperator always for Mac OS,

View File

@ -620,7 +620,7 @@ void PluginRegistrationDialog::PopulateOrExchange(ShuttleGui &S)
continue;
}
wxString path = plug.GetPath();
const wxString &path = plug.GetPath();
ItemData & item = mItems[path]; // will create NEW entry
item.plugs.Add(&plug);
item.path = path;
@ -1437,28 +1437,29 @@ void PluginManager::FindFilesInPathList(const wxString & pattern,
// TODO: We REALLY need to figure out the "Audacity" plug-in path(s)
wxFileName f;
wxArrayString paths;
// Add the "per-user" plug-ins directory
f = FileNames::PlugInDir();
paths.Add(f.GetFullPath());
{
const wxFileName &ff = FileNames::PlugInDir();
paths.Add(ff.GetFullPath());
}
// Add the "Audacity" plug-ins directory
f = PlatformCompatibility::GetExecutablePath();
wxFileName ff = PlatformCompatibility::GetExecutablePath();
#if defined(__WXMAC__)
f.RemoveLastDir();
f.RemoveLastDir();
f.RemoveLastDir();
#endif
f.AppendDir(wxT("plug-ins"));
paths.Add(f.GetPath());
ff.AppendDir(wxT("plug-ins"));
paths.Add(ff.GetPath());
// Weed out duplicates
for (size_t i = 0, cnt = pathList.size(); i < cnt; i++)
{
f = pathList[i];
wxString path = f.GetFullPath();
ff = pathList[i];
const wxString path{ ff.GetFullPath() };
if (paths.Index(path, wxFileName::IsCaseSensitive()) == wxNOT_FOUND)
{
paths.Add(path);
@ -1468,8 +1469,8 @@ void PluginManager::FindFilesInPathList(const wxString & pattern,
// Find all matching files in each path
for (size_t i = 0, cnt = paths.GetCount(); i < cnt; i++)
{
f = paths[i] + wxFILE_SEP_PATH + pattern;
wxDir::GetAllFiles(f.GetPath(), &files, f.GetFullName(), directories ? wxDIR_DEFAULT : wxDIR_FILES);
ff = paths[i] + wxFILE_SEP_PATH + pattern;
wxDir::GetAllFiles(ff.GetPath(), &files, ff.GetFullName(), directories ? wxDIR_DEFAULT : wxDIR_FILES);
}
return;
@ -2796,10 +2797,10 @@ wxString PluginManager::SharedGroup(const PluginID & ID, const wxString & group)
{
wxString path = SettingsPath(ID, true);
wxFileName f(group);
if (!f.GetName().IsEmpty())
wxFileName ff(group);
if (!ff.GetName().IsEmpty())
{
path += f.GetFullPath(wxPATH_UNIX) + wxCONFIG_PATH_SEPARATOR;
path += ff.GetFullPath(wxPATH_UNIX) + wxCONFIG_PATH_SEPARATOR;
}
return path;
@ -2820,10 +2821,10 @@ wxString PluginManager::PrivateGroup(const PluginID & ID, const wxString & group
{
wxString path = SettingsPath(ID, false);
wxFileName f(group);
if (!f.GetName().IsEmpty())
wxFileName ff(group);
if (!ff.GetName().IsEmpty())
{
path += f.GetFullPath(wxPATH_UNIX) + wxCONFIG_PATH_SEPARATOR;
path += ff.GetFullPath(wxPATH_UNIX) + wxCONFIG_PATH_SEPARATOR;
}
return path;

View File

@ -144,12 +144,14 @@ void InitPreferences()
wxString langCode = gPrefs->Read(wxT("/Locale/Language"), wxEmptyString);
bool writeLang = false;
wxFileName fn(wxStandardPaths::Get().GetResourcesDir(), wxT("FirstTime.ini"));
const wxFileName fn(wxStandardPaths::Get().GetResourcesDir(), wxT("FirstTime.ini"));
if (fn.FileExists()) // it will exist if the (win) installer put it there
{
const wxString fullPath{fn.GetFullPath()};
wxFileConfig ini(wxEmptyString,
wxEmptyString,
fn.GetFullPath(),
fullPath,
wxEmptyString,
wxCONFIG_USE_LOCAL_FILE);
@ -167,11 +169,10 @@ void InitPreferences()
ini.Read(wxT("/FromInno/ResetPrefs"), &resetPrefs, false);
bool gone = wxRemoveFile(fn.GetFullPath()); // remove FirstTime.ini
bool gone = wxRemoveFile(fullPath); // remove FirstTime.ini
if (!gone)
{
wxString fileName = fn.GetFullPath();
wxMessageBox(wxString::Format( _("Failed to remove %s"), fileName.c_str()), _("Failed!"));
wxMessageBox(wxString::Format(_("Failed to remove %s"), fullPath.c_str()), _("Failed!"));
}
}

View File

@ -2349,7 +2349,7 @@ void AudacityProject::OnCloseWindow(wxCloseEvent & event)
void AudacityProject::OnOpenAudioFile(wxCommandEvent & event)
{
wxString cmd = event.GetString();
const wxString &cmd = event.GetString();
if (!cmd.IsEmpty()) {
OpenFile(cmd);
@ -2466,7 +2466,7 @@ wxArrayString AudacityProject::ShowOpenDialog(const wxString &extraformat, const
// static method, can be called outside of a project
bool AudacityProject::IsAlreadyOpen(const wxString & projPathName)
{
wxFileName newProjPathName(projPathName);
const wxFileName newProjPathName(projPathName);
size_t numProjects = gAudacityProjects.Count();
for (size_t i = 0; i < numProjects; i++)
{
@ -2504,7 +2504,7 @@ void AudacityProject::OpenFiles(AudacityProject *proj)
ODManager::Pause();
for (size_t ff = 0; ff < selectedFiles.GetCount(); ff++) {
wxString fileName = selectedFiles[ff];
const wxString &fileName = selectedFiles[ff];
// Make sure it isn't already open.
if (AudacityProject::IsAlreadyOpen(fileName))
@ -2569,13 +2569,11 @@ bool AudacityProject::WarnOfLegacyFile( )
// See comment in AudacityApp::MRUOpen().
void AudacityProject::OpenFile(const wxString &fileNameArg, bool addtohistory)
{
wxString fileName(fileNameArg);
// On Win32, we may be given a short (DOS-compatible) file name on rare
// occassions (e.g. stuff like "C:\PROGRA~1\AUDACI~1\PROJEC~1.AUP"). We
// convert these to long file name first.
fileName = PlatformCompatibility::ConvertSlashInFileName(
PlatformCompatibility::GetLongFileName(fileName));
wxString fileName = PlatformCompatibility::ConvertSlashInFileName(
PlatformCompatibility::GetLongFileName(fileNameArg));
// Make sure it isn't already open.
// Vaughan, 2011-03-25: This was done previously in AudacityProject::OpenFiles()
@ -2639,7 +2637,7 @@ void AudacityProject::OpenFile(const wxString &fileNameArg, bool addtohistory)
if( !WarnOfLegacyFile() )
return;
// Convert to the NEW format.
bool success = ConvertLegacyProjectFile(wxFileName(fileName));
bool success = ConvertLegacyProjectFile(wxFileName{ fileName });
if (!success) {
wxMessageBox(_("Audacity was unable to convert an Audacity 1.0 project to the new project format."),
_("Error Opening Project"),

View File

@ -619,7 +619,7 @@ void ThemeBase::CreateImageCache( bool bBinarySave )
// IF nBinarySave, THEN saving to a normal PNG file.
if( bBinarySave )
{
wxString FileName = FileNames::ThemeCachePng();
const wxString &FileName = FileNames::ThemeCachePng();
// Perhaps we should prompt the user if they are overwriting
// an existing theme cache?
@ -650,7 +650,7 @@ void ThemeBase::CreateImageCache( bool bBinarySave )
else
{
SourceOutputStream OutStream;
wxString FileName = FileNames::ThemeCacheAsCee( );
const wxString &FileName = FileNames::ThemeCacheAsCee( );
if( !OutStream.OpenFile( FileName ))
{
wxMessageBox(
@ -791,7 +791,7 @@ bool ThemeBase::ReadImageCache( bool bBinaryRead, bool bOkIfNotFound)
// IF bBinary read THEN a normal read from a PNG file
if( bBinaryRead )
{
wxString FileName = FileNames::ThemeCachePng();
const wxString &FileName = FileNames::ThemeCachePng();
if( !wxFileExists( FileName ))
{
if( bOkIfNotFound )

View File

@ -81,7 +81,7 @@ void FileHistory::Clear()
AddFilesToMenu();
}
wxString FileHistory::GetHistoryFile(size_t i) const
const wxString &FileHistory::GetHistoryFile(size_t i) const
{
wxASSERT(i < mHistory.GetCount());

View File

@ -37,7 +37,7 @@ class AUDACITY_DLL_API FileHistory
void AddFilesToMenu(wxMenu *menu);
size_t GetCount();
wxString GetHistoryFile(size_t i) const;
const wxString &GetHistoryFile(size_t i) const;
private:
size_t mMaxFiles;