1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-14 17:14:07 +01:00

Use type aliases FilePath, FilePaths...

... for wxString and wxArrayStringEx, holding file paths (absolute or relative,
directory or plain file); to be replaced later with different types

(not yet using std::vector, becase of some uses of wxArrayString::Index with
two arguments)
This commit is contained in:
Paul Licameli
2019-03-07 14:50:22 -05:00
parent 485b6bb425
commit a30000cf74
80 changed files with 371 additions and 342 deletions

View File

@@ -38,7 +38,7 @@ XMLFileReader::~XMLFileReader()
}
bool XMLFileReader::Parse(XMLTagHandler *baseHandler,
const wxString &fname)
const FilePath &fname)
{
wxFFile theXMLFile(fname, wxT("rb"));
if (!theXMLFile.IsOpened()) {

View File

@@ -14,6 +14,7 @@
#include "expat.h"
#include "XMLTagHandler.h"
#include "audacity/Types.h"
class AUDACITY_DLL_API XMLFileReader final {
public:
@@ -21,7 +22,7 @@ class AUDACITY_DLL_API XMLFileReader final {
~XMLFileReader();
bool Parse(XMLTagHandler *baseHandler,
const wxString &fname);
const FilePath &fname);
wxString GetErrorStr();

View File

@@ -59,7 +59,7 @@ bool XMLValueChecker::IsGoodLongString(const wxString & str)
// "Good" means the name is well-formed and names an existing file or folder.
bool XMLValueChecker::IsGoodFileName(const wxString & strFileName, const wxString & strDirName /* = {} */)
bool XMLValueChecker::IsGoodFileName(const FilePath & strFileName, const FilePath & strDirName /* = "{} */)
{
// Test strFileName.
if (!IsGoodFileString(strFileName) ||
@@ -71,7 +71,7 @@ bool XMLValueChecker::IsGoodFileName(const wxString & strFileName, const wxStrin
return (fileName.IsOk() && fileName.FileExists());
}
bool XMLValueChecker::IsGoodFileString(const wxString &str)
bool XMLValueChecker::IsGoodFileString(const FilePath &str)
{
return (IsGoodString(str) &&
!str.empty() &&
@@ -83,7 +83,7 @@ bool XMLValueChecker::IsGoodFileString(const wxString &str)
(str.Find(wxFileName::GetPathSeparator()) == -1)); // No path separator characters.
}
bool XMLValueChecker::IsGoodSubdirName(const wxString & strSubdirName, const wxString & strDirName /* = {} */)
bool XMLValueChecker::IsGoodSubdirName(const FilePath & strSubdirName, const FilePath & strDirName /* = {} */)
{
// Test strSubdirName.
// Note this prevents path separators, and relative path to parents (strDirName),
@@ -99,14 +99,14 @@ bool XMLValueChecker::IsGoodSubdirName(const wxString & strSubdirName, const wxS
return (fileName.IsOk() && fileName.DirExists());
}
bool XMLValueChecker::IsGoodPathName(const wxString & strPathName)
bool XMLValueChecker::IsGoodPathName(const FilePath & strPathName)
{
// Test the corresponding wxFileName.
wxFileName fileName(strPathName);
return XMLValueChecker::IsGoodFileName(fileName.GetFullName(), fileName.GetPath(wxPATH_GET_VOLUME));
}
bool XMLValueChecker::IsGoodPathString(const wxString &str)
bool XMLValueChecker::IsGoodPathString(const FilePath &str)
{
return (IsGoodString(str) &&
!str.empty() &&

View File

@@ -22,6 +22,8 @@
#include <wx/string.h>
#include <stdio.h>
#include "audacity/Types.h"
#include "XMLWriter.h"
class XMLValueChecker
{
@@ -33,11 +35,11 @@ public:
// Labels are allowed to be very long. At some future date we will format long labels nicely.
static bool IsGoodLongString(const wxString & str);
static bool IsGoodFileName(const wxString & strFileName, const wxString & strDirName = {});
static bool IsGoodFileString(const wxString &str);
static bool IsGoodSubdirName(const wxString & strSubdirName, const wxString & strDirName = {});
static bool IsGoodPathName(const wxString & strPathName);
static bool IsGoodPathString(const wxString &str);
static bool IsGoodFileName(const FilePath & strFileName, const FilePath & strDirName = {});
static bool IsGoodFileString(const FilePath &str);
static bool IsGoodSubdirName(const FilePath & strSubdirName, const FilePath & strDirName = {});
static bool IsGoodPathName(const FilePath & strPathName);
static bool IsGoodPathString(const FilePath &str);
/** @brief Check that the supplied string can be converted to a long (32bit)
* integer.

View File

@@ -294,7 +294,7 @@ wxString XMLWriter::XMLEsc(const wxString & s)
/// XMLFileWriter class
///
XMLFileWriter::XMLFileWriter
( const wxString &outputPath, const wxString &caption, bool keepBackup )
( const FilePath &outputPath, const wxString &caption, bool keepBackup )
: mOutputPath{ outputPath }
, mCaption{ caption }
, mKeepBackup{ keepBackup }
@@ -359,7 +359,7 @@ void XMLFileWriter::PreCommit()
void XMLFileWriter::PostCommit()
// may throw
{
auto tempPath = GetName();
FilePath tempPath = GetName();
if (mKeepBackup) {
if (! mBackupFile.Close() ||
! wxRenameFile( mOutputPath, mBackupName ) )

View File

@@ -16,6 +16,8 @@
#include "../FileException.h"
#include "audacity/Types.h"
///
/// XMLWriter
///
@@ -78,7 +80,7 @@ class AUDACITY_DLL_API XMLFileWriter final : private wxFFile, public XMLWriter {
/// The caption is for message boxes to show in case of errors.
/// Might throw.
XMLFileWriter
( const wxString &outputPath, const wxString &caption,
( const FilePath &outputPath, const wxString &caption,
bool keepBackup = false );
virtual ~XMLFileWriter();
@@ -99,7 +101,7 @@ class AUDACITY_DLL_API XMLFileWriter final : private wxFFile, public XMLWriter {
/// Write to file. Might throw.
void Write(const wxString &data) override;
wxString GetBackupName() const { return mBackupName; }
FilePath GetBackupName() const { return mBackupName; }
private:
@@ -113,9 +115,9 @@ class AUDACITY_DLL_API XMLFileWriter final : private wxFFile, public XMLWriter {
/// Might throw.
void CloseWithoutEndingTags(); // for auto-save files
const wxString mOutputPath;
const FilePath mOutputPath;
const wxString mCaption;
wxString mBackupName;
FilePath mBackupName;
const bool mKeepBackup;
wxFFile mBackupFile;