mirror of
https://github.com/cookiengineer/audacity
synced 2026-02-05 03:03:10 +01:00
Internat.cpp has fewer dependencies...
... after we move a function to FileNames.cpp. This frees ten files from cyclic dependencies
This commit is contained in:
@@ -581,3 +581,43 @@ void FileNames::FindFilesInPathList(const wxString & pattern,
|
||||
wxDir::GetAllFiles(ff.GetPath(), &results, ff.GetFullName(), flags);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__WXMSW__)
|
||||
//
|
||||
// On Windows, wxString::mb_str() can return a NULL pointer if the
|
||||
// conversion to multi-byte fails. So, based on direction intent,
|
||||
// returns a pointer to an empty string or prompts for a NEW name.
|
||||
//
|
||||
char *FileNames::VerifyFilename(const wxString &s, bool input)
|
||||
{
|
||||
static wxCharBuffer buf;
|
||||
wxString name = s;
|
||||
|
||||
if (input) {
|
||||
if ((char *) (const char *)name.mb_str() == NULL) {
|
||||
name = wxEmptyString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
wxFileName ff(name);
|
||||
wxString ext;
|
||||
while ((char *) (const char *)name.mb_str() == NULL) {
|
||||
AudacityMessageBox(_("The specified filename could not be converted due to Unicode character use."));
|
||||
|
||||
ext = ff.GetExt();
|
||||
name = FileNames::SelectFile(FileNames::Operation::_None,
|
||||
_("Specify New Filename:"),
|
||||
wxEmptyString,
|
||||
name,
|
||||
ext,
|
||||
wxT("*.") + ext,
|
||||
wxFD_SAVE | wxRESIZE_BORDER,
|
||||
wxGetTopLevelParent(NULL));
|
||||
}
|
||||
}
|
||||
|
||||
mFilename = name.mb_str();
|
||||
|
||||
return (char *) (const char *) mFilename;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -145,6 +145,12 @@ public:
|
||||
FilePaths &results,
|
||||
int flags = wxDIR_FILES);
|
||||
|
||||
/** \brief Protect against Unicode to multi-byte conversion failures
|
||||
* on Windows */
|
||||
#if defined(__WXMSW__)
|
||||
static char *VerifyFilename(const wxString &s, bool input = true);
|
||||
#endif
|
||||
|
||||
private:
|
||||
// Private constructors: No one is ever going to instantiate it.
|
||||
//
|
||||
@@ -152,4 +158,22 @@ private:
|
||||
~FileNames(){;};
|
||||
};
|
||||
|
||||
// Use this macro to wrap all filenames and pathnames that get
|
||||
// passed directly to a system call, like opening a file, creating
|
||||
// a directory, checking to see that a file exists, etc...
|
||||
#if defined(__WXMSW__)
|
||||
// Note, on Windows we don't define an OSFILENAME() to prevent accidental use.
|
||||
// See VerifyFilename() for an explanation.
|
||||
#define OSINPUT(X) FileNames::VerifyFilename(X, true)
|
||||
#define OSOUTPUT(X) FileNames::VerifyFilename(X, false)
|
||||
#elif defined(__WXMAC__)
|
||||
#define OSFILENAME(X) ((char *) (const char *)(X).fn_str())
|
||||
#define OSINPUT(X) OSFILENAME(X)
|
||||
#define OSOUTPUT(X) OSFILENAME(X)
|
||||
#else
|
||||
#define OSFILENAME(X) ((char *) (const char *)(X).mb_str())
|
||||
#define OSINPUT(X) OSFILENAME(X)
|
||||
#define OSOUTPUT(X) OSFILENAME(X)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,6 +23,7 @@ and on Mac OS X for the filesystem.
|
||||
#include "Internat.h"
|
||||
|
||||
#include "Experimental.h"
|
||||
#include "MemoryX.h"
|
||||
|
||||
#include <wx/log.h>
|
||||
#include <wx/intl.h>
|
||||
@@ -31,8 +32,6 @@ and on Mac OS X for the filesystem.
|
||||
#include <locale.h>
|
||||
#include <math.h> // for pow()
|
||||
|
||||
#include "FileNames.h"
|
||||
#include "widgets/ErrorDialog.h"
|
||||
#include "../include/audacity/ComponentInterface.h"
|
||||
|
||||
// in order for the static member variables to exist, they must appear here
|
||||
@@ -226,46 +225,6 @@ wxString Internat::FormatSize(double size)
|
||||
return sizeStr;
|
||||
}
|
||||
|
||||
#if defined(__WXMSW__)
|
||||
//
|
||||
// On Windows, wxString::mb_str() can return a NULL pointer if the
|
||||
// conversion to multi-byte fails. So, based on direction intent,
|
||||
// returns a pointer to an empty string or prompts for a NEW name.
|
||||
//
|
||||
char *Internat::VerifyFilename(const wxString &s, bool input)
|
||||
{
|
||||
static wxCharBuffer buf;
|
||||
wxString name = s;
|
||||
|
||||
if (input) {
|
||||
if ((char *) (const char *)name.mb_str() == NULL) {
|
||||
name = wxEmptyString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
wxFileName ff(name);
|
||||
wxString ext;
|
||||
while ((char *) (const char *)name.mb_str() == NULL) {
|
||||
AudacityMessageBox(_("The specified filename could not be converted due to Unicode character use."));
|
||||
|
||||
ext = ff.GetExt();
|
||||
name = FileNames::SelectFile(FileNames::Operation::_None,
|
||||
_("Specify New Filename:"),
|
||||
wxEmptyString,
|
||||
name,
|
||||
ext,
|
||||
wxT("*.") + ext,
|
||||
wxFD_SAVE | wxRESIZE_BORDER,
|
||||
wxGetTopLevelParent(NULL));
|
||||
}
|
||||
}
|
||||
|
||||
mFilename = name.mb_str();
|
||||
|
||||
return (char *) (const char *) mFilename;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool Internat::SanitiseFilename(wxString &name, const wxString &sub)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
@@ -120,12 +120,6 @@ public:
|
||||
static wxString FormatSize(wxLongLong size);
|
||||
static wxString FormatSize(double size);
|
||||
|
||||
/** \brief Protect against Unicode to multi-byte conversion failures
|
||||
* on Windows */
|
||||
#if defined(__WXMSW__)
|
||||
static char *VerifyFilename(const wxString &s, bool input = true);
|
||||
#endif
|
||||
|
||||
/** \brief Check a proposed file name string for illegal characters and
|
||||
* remove them
|
||||
* return true iff name is "visibly" changed (not necessarily equivalent to
|
||||
@@ -156,24 +150,6 @@ private:
|
||||
|
||||
#define _NoAcc(X) Internat::StripAccelerators(_(X))
|
||||
|
||||
// Use this macro to wrap all filenames and pathnames that get
|
||||
// passed directly to a system call, like opening a file, creating
|
||||
// a directory, checking to see that a file exists, etc...
|
||||
#if defined(__WXMSW__)
|
||||
// Note, on Windows we don't define an OSFILENAME() to prevent accidental use.
|
||||
// See VerifyFilename() for an explanation.
|
||||
#define OSINPUT(X) Internat::VerifyFilename(X, true)
|
||||
#define OSOUTPUT(X) Internat::VerifyFilename(X, false)
|
||||
#elif defined(__WXMAC__)
|
||||
#define OSFILENAME(X) ((char *) (const char *)(X).fn_str())
|
||||
#define OSINPUT(X) OSFILENAME(X)
|
||||
#define OSOUTPUT(X) OSFILENAME(X)
|
||||
#else
|
||||
#define OSFILENAME(X) ((char *) (const char *)(X).mb_str())
|
||||
#define OSINPUT(X) OSFILENAME(X)
|
||||
#define OSOUTPUT(X) OSFILENAME(X)
|
||||
#endif
|
||||
|
||||
// Convert C strings to wxString
|
||||
#define UTF8CTOWX(X) wxString((X), wxConvUTF8)
|
||||
#define LAT1CTOWX(X) wxString((X), wxConvISO8859_1)
|
||||
|
||||
Reference in New Issue
Block a user