本文整理汇总了C++中wxFileName::GetName方法的典型用法代码示例。如果您正苦于以下问题:C++ wxFileName::GetName方法的具体用法?C++ wxFileName::GetName怎么用?C++ wxFileName::GetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wxFileName
的用法示例。
在下文中一共展示了wxFileName::GetName方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DoExport
bool ExportMultiple::DoExport(int channels,
wxFileName name,
bool selectedOnly,
double t0,
double t1,
Tags tags)
{
// Generate a unique name if we're not allowed to overwrite
if (!mOverwrite->GetValue()) {
int i = 2;
wxString base(name.GetName());
while (name.FileExists()) {
name.SetName(wxString::Format(wxT("%s-%d"), base.c_str(), i++));
}
}
// Call the format export routine
bool rc = mPlugins[mFormatIndex]->Export(mProject,
channels,
name.GetFullPath(),
selectedOnly,
t0,
t1,
NULL,
&tags);
return rc;
}
示例2: freader
/**
* Read a file to detect the type.
* @param aFile - open file to be read. File pointer will be closed.
* @param aFileName - file name to be read
* @param aName - wxString to receive the module name iff type is LEGACY
*/
static IO_MGR::PCB_FILE_T detect_file_type( FILE* aFile, const wxFileName& aFileName,
wxString* aName )
{
FILE_LINE_READER freader( aFile, aFileName.GetFullPath() );
WHITESPACE_FILTER_READER reader( freader );
IO_MGR::PCB_FILE_T file_type;
wxASSERT( aName );
reader.ReadLine();
char* line = reader.Line();
if( !strncasecmp( line, "(module", strlen( "(module" ) ) )
{
file_type = IO_MGR::KICAD_SEXP;
*aName = aFileName.GetName();
}
else if( !strncasecmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) )
{
file_type = IO_MGR::LEGACY;
while( reader.ReadLine() )
{
if( !strncasecmp( line, "$MODULE", strlen( "$MODULE" ) ) )
{
*aName = FROM_UTF8( StrPurge( line + strlen( "$MODULE" ) ) );
break;
}
}
}
else if( !strncasecmp( line, "Element", strlen( "Element" ) ) )
{
file_type = IO_MGR::GEDA_PCB;
*aName = aFileName.GetName();
}
else
{
file_type = IO_MGR::FILE_TYPE_NONE;
}
return file_type;
}
示例3: IsSourceOf
bool ClangPlugin::IsSourceOf(const wxFileName& candidateFile, const wxFileName& activeFile, bool& isCandidate)
{
if (candidateFile.GetName().CmpNoCase(activeFile.GetName()) == 0)
{
isCandidate = (candidateFile.GetName() != activeFile.GetName());
if (FileTypeOf(candidateFile.GetFullName()) == ftSource)
{
if (candidateFile.GetPath() != activeFile.GetPath())
{
wxArrayString fileArray;
wxDir::GetAllFiles(candidateFile.GetPath(wxPATH_GET_VOLUME), &fileArray, candidateFile.GetName() + wxT(".*"), wxDIR_FILES | wxDIR_HIDDEN);
for (size_t i = 0; i < fileArray.GetCount(); ++i)
if (wxFileName(fileArray[i]).GetFullName() == activeFile.GetFullName())
return false;
}
return candidateFile.FileExists();
}
}
return false;
}
示例4: MakeNameUnique
// originally an ExportMultiple method. Append suffix if newName appears in otherNames.
void FileNames::MakeNameUnique(wxArrayString &otherNames, wxFileName &newName)
{
if (otherNames.Index(newName.GetFullName(), false) >= 0) {
int i=2;
wxString orig = newName.GetName();
do {
newName.SetName(wxString::Format(wxT("%s-%d"), orig.c_str(), i));
i++;
} while (otherNames.Index(newName.GetFullName(), false) >= 0);
}
otherNames.Add(newName.GetFullName());
}
示例5: BuildCleanFileName
wxString BatchCommands::BuildCleanFileName(const wxString &fileName, const wxString &extension)
{
const wxFileName newFileName{ fileName };
wxString justName = newFileName.GetName();
wxString pathName = newFileName.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
if (justName == wxT("")) {
wxDateTime now = wxDateTime::Now();
int year = now.GetYear();
wxDateTime::Month month = now.GetMonth();
wxString monthName = now.GetMonthName(month);
int dom = now.GetDay();
int hour = now.GetHour();
int minute = now.GetMinute();
int second = now.GetSecond();
justName = wxString::Format(wxT("%d-%s-%02d-%02d-%02d-%02d"),
year, monthName.c_str(), dom, hour, minute, second);
// SetName(cleanedFileName);
// bool isStereo;
// double endTime = project->mTracks->GetEndTime();
// double startTime = 0.0;
//OnSelectAll();
pathName = gPrefs->Read(wxT("/DefaultOpenPath"), ::wxGetCwd());
::wxMessageBox(wxString::Format(wxT("Export recording to %s\n/cleaned/%s%s"),
pathName.c_str(), justName.c_str(), extension.c_str()),
wxT("Export recording"),
wxOK | wxCENTRE);
pathName += wxT("/");
}
wxString cleanedName = pathName;
cleanedName += wxT("cleaned");
bool flag = ::wxFileName::FileExists(cleanedName);
if (flag == true) {
::wxMessageBox(wxT("Cannot create directory 'cleaned'. \nFile already exists that is not a directory"));
return wxT("");
}
::wxFileName::Mkdir(cleanedName, 0777, wxPATH_MKDIR_FULL); // make sure it exists
cleanedName += wxT("/");
cleanedName += justName;
cleanedName += extension;
wxGetApp().AddFileToHistory(cleanedName);
return cleanedName;
}
示例6: Append
void FbExportParentData::Append(FbModel & model, int book, wxFileName &filename, int size)
{
int number = 0;
wxString name = filename.GetName();
while (true) {
wxString fullname = Lower(filename.GetFullName());
size_t count = Count(model);
bool ok = true;
for (size_t i = 0; i < count; i++) {
FbModelData * data = Items(model, i);
if (!data) continue;
if (Lower(data->GetValue(model)) == fullname) { ok = false; break; }
}
if (ok) break;
filename.SetName(name + wxString::Format(wxT("(%d)"), ++number));
}
new FbExportChildData(model, this, book, filename, size);
}
示例7: CreateProject
bool PROJECT_TEMPLATE::CreateProject( wxFileName& aNewProjectPath )
{
bool result = true;
vector<wxFileName> srcFiles = GetFileList();
vector<wxFileName> dstFiles;
for( size_t i=0; i < srcFiles.size(); i++ )
{
// Replace the template path
wxFileName destination = srcFiles[i];
wxString destname = destination.GetName();
// Replace the template name with the project name for the new project creation
destname.Replace( GetName(), aNewProjectPath.GetName() );
// Add the file extension (if there was one!)
if( destination.GetExt() != wxEmptyString )
destname += wxT(".") + destination.GetExt();
wxString destpath = destination.GetPathWithSep();
destpath.Replace( templateBasePath.GetPathWithSep(), aNewProjectPath.GetPathWithSep() );
// Check to see if the path already exists, if not attempt to create it here. Don't worry
// about error checking, if the path isn't created the file copy will fail anyway
if( !wxFileName::DirExists( destpath ) )
wxFileName::Mkdir( destpath, 0777, wxPATH_MKDIR_FULL );
destination = destpath + destname;
dstFiles.push_back( destination );
wxString srcFile = srcFiles[i].GetFullPath();
wxString dstFile = dstFiles[i].GetFullPath();
if( !wxCopyFile( srcFile, dstFile ) )
{
result = false;
break;
}
}
return result;
}
示例8: CheckForAutoSaveFile
void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName,
const wxString& aBackupFileExtension )
{
wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
wxCHECK_RET( !aBackupFileExtension.IsEmpty(), wxT( "Invalid backup file extension!" ) );
wxFileName autoSaveFileName = aFileName;
// Check for auto save file.
autoSaveFileName.SetName( wxT( "$" ) + aFileName.GetName() );
wxLogTrace( traceAutoSave,
wxT( "Checking for auto save file " ) + autoSaveFileName.GetFullPath() );
if( !autoSaveFileName.FileExists() )
return;
wxString msg = wxString::Format( _(
"Well this is potentially embarrassing! It appears that the last time "
"you were editing the file '%s' it was not saved properly. Do you wish to restore the last "
"edits you made?" ),
GetChars( aFileName.GetFullName() )
);
int response = wxMessageBox( msg, Pgm().App().GetAppName(), wxYES_NO | wxICON_QUESTION, this );
// Make a backup of the current file, delete the file, and rename the auto save file to
// the file name.
if( response == wxYES )
{
// Get the backup file name.
wxFileName backupFileName = aFileName;
backupFileName.SetExt( aBackupFileExtension );
// If an old backup file exists, delete it. If an old copy of the file exists, rename
// it to the backup file name
if( aFileName.FileExists() )
{
// Remove the old file backup file.
if( backupFileName.FileExists() )
wxRemoveFile( backupFileName.GetFullPath() );
// Rename the old file to the backup file name.
if( !wxRenameFile( aFileName.GetFullPath(), backupFileName.GetFullPath() ) )
{
msg.Printf( _( "Could not create backup file <%s>" ),
GetChars( backupFileName.GetFullPath() ) );
wxMessageBox( msg );
}
}
if( !wxRenameFile( autoSaveFileName.GetFullPath(), aFileName.GetFullPath() ) )
{
wxMessageBox( _( "The auto save file could not be renamed to the board file name." ),
Pgm().App().GetAppName(), wxOK | wxICON_EXCLAMATION, this );
}
}
else
{
wxLogTrace( traceAutoSave,
wxT( "Removing auto save file " ) + autoSaveFileName.GetFullPath() );
// Remove the auto save file when using the previous file as is.
wxRemoveFile( autoSaveFileName.GetFullPath() );
}
}
示例9: ConvertLegacyProjectFile
bool ConvertLegacyProjectFile(wxFileName filename)
{
wxTextFile f;
XMLFileWriter xmlFile;
int index = 0;
wxString backupName;
do {
index++;
fflush(stdout);
backupName = filename.GetPath() + wxFILE_SEP_PATH + filename.GetName() +
wxT("_bak") + wxString::Format(wxT("%d"), index) + wxT(".") + filename.GetExt();
} while(::wxFileExists(backupName));
// This will move the original file out of the way, but
// move it back if we exit from this function early.
AutoRollbackRenamer renamer(filename.GetFullPath(), backupName);
if (!renamer.RenameSucceeded())
return false;
f.Open(backupName);
if (!f.IsOpened())
return false;
wxString name = filename.GetFullPath();
try
{
xmlFile.Open(name, wxT("wb"));
}
catch (XMLFileWriterException* pException)
{
delete pException;
return false;
}
renamer.SetNewFile(xmlFile.fp());
try
{
xmlFile.Write(wxT("<?xml version=\"1.0\"?>\n"));
wxString label;
wxString value;
if (f.GetFirstLine() != wxT("AudacityProject"))
return false;
if (f.GetNextLine() != wxT("Version"))
return false;
if (f.GetNextLine() != wxT("0.95"))
return false;
if (f.GetNextLine() != wxT("projName"))
return false;
xmlFile.StartTag(wxT("audacityproject"));
xmlFile.WriteAttr(wxT("projname"), f.GetNextLine());
xmlFile.WriteAttr(wxT("version"), wxT("1.1.0"));
xmlFile.WriteAttr(wxT("audacityversion"),AUDACITY_VERSION_STRING);
label = f.GetNextLine();
while (label != wxT("BeginTracks")) {
xmlFile.WriteAttr(label, f.GetNextLine());
label = f.GetNextLine();
}
label = f.GetNextLine();
while (label != wxT("EndTracks")) {
bool success = ConvertLegacyTrack(&f, xmlFile);
if (!success)
return false;
label = f.GetNextLine();
}
xmlFile.EndTag(wxT("audacityproject"));
xmlFile.Close();
}
catch (XMLFileWriterException* pException)
{
// Error writing XML file (e.g. disk full)
delete pException;
return false;
}
renamer.Finished();
::wxMessageBox(wxString::Format(_("Converted a 1.0 project file to the new format.\nThe old file has been saved as '%s'"), backupName.c_str()),
_("Opening Audacity Project"));
return true;
}
示例10: EnsureSafeFilename
bool DirManager::EnsureSafeFilename(wxFileName fName)
{
// Quick check: If it's not even in our alias list,
// then the file name is A-OK.
#if 0
printf("file name: %s\n", fName.GetFullPath().c_str());
printf("string list:\n");
wxStringListNode *node = aliasList.GetFirst();
while (node)
{
wxString string = node->GetData();
printf("%s\n", string.c_str());
node = node->GetNext();
}
#endif
if (!aliasList.Member(fName.GetFullPath()))
return true;
// If any of the following commands fail, your guess is as
// good as mine why. The following error message is the
// best we can do - we'll use it if any of the renames,
// creates, or deletes fail.
wxString errStr =
_( "Error: is directory write-protected or disk full?" );
/* i18n-hint: 'old' is part of a filename used when a file is renamed. */
// Figure out what the new name for the existing file would be.
/* i18n-hint: e.g. Try to go from "mysong.wav" to "mysong-old1.wav". */
// Keep trying until we find a filename that doesn't exist.
wxFileName renamedFile = fName;
int i = 0;
do {
i++;
/* i18n-hint: This is the pattern for filenames that are created
when a file needs to be backed up to a different name. For
example, mysong would become mysong-old1, mysong-old2, etc. */
renamedFile.SetName(wxString::Format(_("%s-old%d"), fName.GetName().c_str(), i));
} while (renamedFile.FileExists());
// Test creating a file by that name to make sure it will
// be possible to do the rename
wxFile testFile(renamedFile.GetFullPath(), wxFile::write);
if (!testFile.IsOpened()) {
wxMessageBox(errStr);
return false;
}
if (!wxRemoveFile(renamedFile.GetFullPath())) {
wxMessageBox(errStr);
return false;
}
printf(_("Renamed file: %s\n"), (const char *)renamedFile.GetFullPath());
// Go through our block files and see if any indeed point to
// the file we're concerned about. If so, point the block file
// to the renamed file and when we're done, perform the rename.
bool needToRename = false;
wxBusyCursor busy;
blockFileHash->BeginFind();
wxNode *n = blockFileHash->Next();
while(n) {
BlockFile *b = (BlockFile *)n->GetData();
// don't worry, we don't rely on this cast unless IsAlias is true
AliasBlockFile *ab = (AliasBlockFile*)b;
if (b->IsAlias() && ab->GetAliasedFile() == fName) {
needToRename = true;
printf(_("Changing block %s\n"), (const char *)b->GetFileName().GetFullName());
ab->ChangeAliasedFile(renamedFile);
}
n = blockFileHash->Next();
}
if (needToRename) {
if (!wxRenameFile(fName.GetFullPath(), renamedFile.GetFullPath())) {
// ACK!!! The renaming was unsuccessful!!!
// (This shouldn't happen, since we tried creating a
// file of this name and then deleted it just a
// second earlier.) But we'll handle this scenario
// just in case!!!
// Put things back where they were
blockFileHash->BeginFind();
n = blockFileHash->Next();
while(n) {
BlockFile *b = (BlockFile *)n->GetData();
AliasBlockFile *ab = (AliasBlockFile*)b;
if (b->IsAlias() && ab->GetAliasedFile() == renamedFile)
ab->ChangeAliasedFile(fName);
n = blockFileHash->Next();
}
// Print error message and cancel the export
//.........这里部分代码省略.........
示例11: ConvertLegacyProjectFile
bool ConvertLegacyProjectFile(wxFileName filename)
{
wxTextFile f;
FILE *outf;
int index = 0;
wxString backupName;
do {
index++;
fflush(stdout);
backupName = filename.GetPath() + wxFILE_SEP_PATH + filename.GetName() +
wxT("_bak") + wxString::Format(wxT("%d"), index) + wxT(".") + filename.GetExt();
} while(::wxFileExists(FILENAME(backupName)));
// This will move the original file out of the way, but
// move it back if we exit from this function early.
AutoRollbackRenamer renamer(filename.GetFullPath(), backupName);
if (!renamer.RenameSucceeded())
return false;
f.Open(FILENAME(backupName));
if (!f.IsOpened())
return false;
wxString name = filename.GetFullPath();
wxFFile out_wxFFile(FILENAME(name).c_str(), wxT("wb"));
if (!out_wxFFile.IsOpened())
return false;
outf = out_wxFFile.fp();
fprintf(outf, "<?xml version='1.0'?>\n");
renamer.SetNewFile(outf);
wxString label;
wxString value;
if (f.GetFirstLine() != wxT("AudacityProject"))
return false;
if (f.GetNextLine() != wxT("Version"))
return false;
if (f.GetNextLine() != wxT("0.95"))
return false;
if (f.GetNextLine() != wxT("projName"))
return false;
fprintf(outf, "<audacityproject projname='%s'",
(const char *)f.GetNextLine().mb_str());
fprintf(outf, " version='1.1.0' audacityversion='%s'",
AUDACITY_VERSION_STRING);
label = f.GetNextLine();
while (label != wxT("BeginTracks")) {
value = f.GetNextLine();
fprintf(outf, " %s='%s'", (const char *)label.mb_str(), (const char *)value.mb_str());
label = f.GetNextLine();
}
fprintf(outf, ">\n");
label = f.GetNextLine();
while (label != wxT("EndTracks")) {
bool success = ConvertLegacyTrack(&f, outf);
if (!success)
return false;
label = f.GetNextLine();
}
fprintf(outf, "</audacityproject>\n");
renamer.Finished();
::wxMessageBox(wxString::Format(_("Converted a 1.0 project file to the new format.\nThe old file has been saved as '%s'"), backupName.c_str()),
_("Opening Audacity Project"));
return true;
}
示例12: EnsureSafeFilename
bool DirManager::EnsureSafeFilename(wxFileName fName)
{
// Quick check: If it's not even in our alias list,
// then the file name is A-OK.
if (aliasList.Index(fName.GetFullPath()) == wxNOT_FOUND)
return true;
/* i18n-hint: 'old' is part of a filename used when a file is renamed. */
// Figure out what the new name for the existing file would be.
/* i18n-hint: e.g. Try to go from "mysong.wav" to "mysong-old1.wav". */
// Keep trying until we find a filename that doesn't exist.
wxFileName renamedFile = fName;
int i = 0;
do {
i++;
/* i18n-hint: This is the pattern for filenames that are created
when a file needs to be backed up to a different name. For
example, mysong would become mysong-old1, mysong-old2, etc. */
renamedFile.SetName(wxString::Format(_("%s-old%d"), fName.GetName().c_str(), i));
} while (wxFileExists(renamedFile.GetFullPath()));
// Test creating a file by that name to make sure it will
// be possible to do the rename
wxFile testFile(renamedFile.GetFullPath(), wxFile::write);
if (!testFile.IsOpened()) {
wxLogSysError(_("Unable to open/create test file"),
renamedFile.GetFullPath().c_str());
return false;
}
// Close the file prior to renaming.
testFile.Close();
if (!wxRemoveFile(renamedFile.GetFullPath())) {
wxLogSysError(_("Unable to remove '%s'"),
renamedFile.GetFullPath().c_str());
return false;
}
wxPrintf(_("Renamed file: %s\n"), renamedFile.GetFullPath().c_str());
// Go through our block files and see if any indeed point to
// the file we're concerned about. If so, point the block file
// to the renamed file and when we're done, perform the rename.
bool needToRename = false;
wxBusyCursor busy;
BlockHash::iterator it=blockFileHash.begin();
while(it != blockFileHash.end()) {
BlockFile *b = it->second;
// don't worry, we don't rely on this cast unless IsAlias is true
AliasBlockFile *ab = (AliasBlockFile*)b;
if (b->IsAlias() && ab->GetAliasedFile() == fName) {
needToRename = true;
wxPrintf(_("Changing block %s\n"), b->GetFileName().GetFullName().c_str());
ab->ChangeAliasedFile(renamedFile);
}
it++;
}
if (needToRename) {
if (!wxRenameFile(fName.GetFullPath(),
renamedFile.GetFullPath())) {
// ACK!!! The renaming was unsuccessful!!!
// (This shouldn't happen, since we tried creating a
// file of this name and then deleted it just a
// second earlier.) But we'll handle this scenario
// just in case!!!
// Put things back where they were
BlockHash::iterator it=blockFileHash.begin();
while(it != blockFileHash.end()) {
BlockFile *b = it->second;
AliasBlockFile *ab = (AliasBlockFile*)b;
if (b->IsAlias() && ab->GetAliasedFile() == renamedFile)
ab->ChangeAliasedFile(fName);
it++;
}
// Print error message and cancel the export
wxLogSysError(_("Unable to rename '%s' to '%s'"),
fName.GetFullPath().c_str(),
renamedFile.GetFullPath().c_str());
return false;
}
aliasList.Remove(fName.GetFullPath());
aliasList.Add(renamedFile.GetFullPath());
}
// Success!!! Either we successfully renamed the file,
// or we didn't need to!
return true;
}
示例13: Create_BOM_Lists
void DIALOG_BUILD_BOM::Create_BOM_Lists( int aTypeFile,
bool aIncludeSubComponents,
char aExportSeparatorSymbol,
bool aRunBrowser )
{
wxString wildcard;
static wxFileName fn;
wxFileName current = g_RootSheet->GetScreen()->GetFileName();
s_ExportSeparatorSymbol = aExportSeparatorSymbol;
if( !fn.HasName() || fn.GetName()==NAMELESS_PROJECT )
{
fn.SetName( current.GetName() );
}
// else use a previous run's name, because fn was set before and user
// is probably just iteratively refining the BOM.
if( fn.GetPath().IsEmpty() )
{
fn.SetPath( current.GetPath() );
}
// else use a previous run's path, because fn was set before and user
// is probably just iteratively refining the BOM.
wxString bomDesc = _( "Bill of Materials" ); // translate once, use twice.
if( aTypeFile == 0 )
{
fn.SetExt( wxT( "lst" ) );
wildcard = bomDesc + wxT( " (*.lst)|*.lst" );
}
else
{
fn.SetExt( wxT( "csv" ) );
wildcard = bomDesc + wxT( " (*.csv)|*.csv" );
}
wxFileDialog dlg( this, bomDesc, fn.GetPath(),
fn.GetFullName(), wildcard, wxFD_SAVE );
if( dlg.ShowModal() == wxID_CANCEL )
return;
fn = dlg.GetPath(); // remember path+filename+ext for subsequent runs.
m_listFileName = dlg.GetPath();
// Close dialog, then show the list (if so requested)
switch( aTypeFile )
{
case 0: // list
CreatePartsAndLabelsFullList( aIncludeSubComponents );
break;
case 1: // spreadsheet, Single Part per line
CreateSpreadSheetPartsFullList( aIncludeSubComponents, s_Add_Location, false );
break;
case 2: // spreadsheet, group Part with same fields per line
CreateSpreadSheetPartsFullList( aIncludeSubComponents, s_Add_Location, true );
break;
case 3: // spreadsheet, one value per line and no sub-component
CreateSpreadSheetPartsShortList();
break;
}
EndModal( 1 );
if( aRunBrowser )
{
wxString editorname = wxGetApp().GetEditorName();
wxString filename = m_listFileName;
AddDelimiterString( filename );
ExecuteFile( this, editorname, filename );
}
}