//---------------------------------------- void CZFXYPlotFrame::WriteImage(const wxFileName& fileName) { vtkWindowToImageFilter* w2i = vtkWindowToImageFilter::New(); CMapImageType mapImageType; CImageType* imageType = dynamic_cast<CImageType*>(mapImageType[(const char *)(fileName.GetExt())]); if (imageType == NULL) { CException e(CTools::Format("CZFXYPlotFrame::WriteImage - extension:'%s' - dynamic_cast<CImageType*>" "(CMapImageType::GetInstance()[ext]) returns NULL pointer CMapImageType map seems to " "contain objects other than those of the class CImageType", (const char *)(fileName.GetExt())), BRATHL_LOGIC_ERROR); CTrace::Tracer("%s", e.what()); throw (e); } if (imageType->m_vtkImageWriter == NULL) { CException e(CTools::Format("CZFXYPlotFrame::WriteImage - m_vtkImageWriter == NULL - type name:'%s' (extenstion " "'%s')", (const char *)(imageType->m_name), (const char *)(fileName.GetExt())), BRATHL_LOGIC_ERROR); CTrace::Tracer("%s", e.what()); throw (e); } try { ::wxRemoveFile(fileName.GetFullPath()); } catch (...) { //do nothing } vtkRenderWindow* renderWindow = m_plotPanel->GetVtkWidget()->GetRenderWindow(); renderWindow->OffScreenRenderingOn(); w2i->SetInput(renderWindow); imageType->m_vtkImageWriter->SetInput(w2i->GetOutput()); imageType->m_vtkImageWriter->SetFileName(fileName.GetFullPath().c_str()); renderWindow->Render(); imageType->m_vtkImageWriter->Write(); w2i->Delete(); renderWindow->OffScreenRenderingOff(); }
bool CodeFormatter::ClangFormatBuffer(const wxString& content, const wxFileName& filename, wxString& formattedOutput, int& cursorPosition, int startOffset, int length) { // Write the content into a temporary file wxFileName fn(clStandardPaths::Get().GetTempDir(), "code-formatter-tmp.cpp"); fn.SetExt(filename.GetExt()); wxFFile fp(fn.GetFullPath(), "w+b"); if(fp.IsOpened()) { fp.Write(content, wxConvUTF8); fp.Close(); } FormatOptions options; m_mgr->GetConfigTool()->ReadObject(wxT("FormatterOptions"), &options); bool res = DoClangFormat(fn, formattedOutput, cursorPosition, startOffset, length, options); { // Delete the temporary file wxLogNull nl; ::wxRemoveFile(fn.GetFullPath()); } return res; }
/****************************************************************************** ** * Save the file to the memory buffer. Return the number of bytes used. * The file name is for informational purposes only, e.g. to decide * which sub-format to use. */ unsigned MCDoc::Save(uint8_t* pBuff, const wxFileName& fileName) { unsigned len = 0; if (fileName.GetExt().CmpNoCase(wxT("ami")) == 0) len = SaveAmica(pBuff); else len = SaveKoala(pBuff); return len; }
int wxExGetIconID(const wxFileName& filename) { if (filename.FileExists(filename.GetFullPath()) || filename.DirExists(filename.GetFullPath())) { if (filename.DirExists(filename.GetFullPath())) { return wxFileIconsTable::folder; } else if (!filename.GetExt().empty()) { return wxTheFileIconsTable->GetIconID(filename.GetExt()); } else { return wxFileIconsTable::file; } } else { return wxFileIconsTable::computer; } }
/** * Check how good data matches our document format. Return a sum of * MC_FORMAT_*_MATCH. */ int MCDoc::CheckFormat(uint8_t* pBuff, unsigned len, const wxFileName& fileName) { uint16_t addr; int match = 0; if (fileName.GetExt().CmpNoCase(wxT("ami")) == 0 || fileName.GetExt().CmpNoCase(wxT("kla")) == 0 || fileName.GetExt().CmpNoCase(wxT("koa")) == 0) { match += MC_FORMAT_EXTENSION_MATCH; } if (len == sizeof(koala_t)) match += MC_FORMAT_SIZE_MATCH; addr = pBuff[0] + pBuff[1] * 256; if (addr == KOALA_START_ADDR || addr == AMICA_START_ADDR) { match += MC_FORMAT_ADDR_MATCH; } return match; }
void DatabaseExplorer::DoOpenFile(const wxFileName& filename) { if(filename.GetExt() == wxT("erd")) { // try to determine used database adapter IDbAdapter* adapter = NULL; IDbAdapter::TYPE type = IDbAdapter::atUNKNOWN; wxSFDiagramManager mgr; mgr.AcceptShape(wxT("All")); mgr.SetRootItem(new ErdInfo()); if(mgr.DeserializeFromXml(filename.GetFullPath())) { ErdInfo* info = wxDynamicCast(mgr.GetRootItem(), ErdInfo); if(info) type = info->GetAdapterType(); switch(type) { case IDbAdapter::atSQLITE: #ifdef DBL_USE_SQLITE adapter = new SQLiteDbAdapter(); #endif break; case IDbAdapter::atMYSQL: #ifdef DBL_USE_MYSQL adapter = new MySqlDbAdapter(); #endif break; case IDbAdapter::atPOSTGRES: //#ifdef DBL_USE_POSTGRES adapter = new PostgreSqlDbAdapter(); //#endif break; default: break; } if(adapter) { ErdPanel* panel = new ErdPanel(m_mgr->GetEditorPaneNotebook(), adapter, NULL); m_mgr->AddEditorPage(panel, wxString::Format(wxT("ERD [%s]"), filename.GetFullName().c_str())); panel->LoadERD(filename.GetFullPath()); return; } } } }
wxFileName ClangPlugin::FindSourceIn(const wxArrayString& candidateFilesArray, const wxFileName& activeFile, bool& isCandidate) { bool extStartsWithCapital = wxIsupper(activeFile.GetExt()[0]); wxFileName candidateFile; for (size_t i = 0; i < candidateFilesArray.GetCount(); ++i) { wxFileName currentCandidateFile(candidateFilesArray[i]); if (IsSourceOf(currentCandidateFile, activeFile, isCandidate)) { bool isUpper = wxIsupper(currentCandidateFile.GetExt()[0]); if (isUpper == extStartsWithCapital && !isCandidate) return currentCandidateFile; else candidateFile = currentCandidateFile; } } isCandidate = true; return candidateFile; }
FileExtManager::FileType FileExtManager::GetTypeFromExtension(const wxFileName& filename) { wxCriticalSectionLocker locker(m_CS); std::unordered_map<wxString, FileExtManager::FileType>::iterator iter = m_map.find(filename.GetExt().Lower()); if(iter == m_map.end()) return TypeOther; return iter->second; }
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; }
bool wxFileDialog::Create(wxWindow *parent, const wxString& message, const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard, long style, const wxPoint& pos, const wxSize& sz, const wxString& name) { parent = GetParentForModalDialog(parent, style); if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFileName, wildCard, style, pos, sz, name)) { return false; } if (!PreCreation(parent, pos, wxDefaultSize) || !CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style, wxDefaultValidator, wxT("filedialog"))) { wxFAIL_MSG( wxT("wxFileDialog creation failed") ); return false; } GtkFileChooserAction gtk_action; GtkWindow* gtk_parent = NULL; if (parent) gtk_parent = GTK_WINDOW( gtk_widget_get_toplevel(parent->m_widget) ); const gchar* ok_btn_stock; if ( style & wxFD_SAVE ) { gtk_action = GTK_FILE_CHOOSER_ACTION_SAVE; ok_btn_stock = GTK_STOCK_SAVE; } else { gtk_action = GTK_FILE_CHOOSER_ACTION_OPEN; ok_btn_stock = GTK_STOCK_OPEN; } m_widget = gtk_file_chooser_dialog_new( wxGTK_CONV(m_message), gtk_parent, gtk_action, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, ok_btn_stock, GTK_RESPONSE_ACCEPT, NULL); g_object_ref(m_widget); GtkFileChooser* file_chooser = GTK_FILE_CHOOSER(m_widget); m_fc.SetWidget(file_chooser); gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_ACCEPT); if ( style & wxFD_MULTIPLE ) gtk_file_chooser_set_select_multiple(file_chooser, true); // gtk_widget_hide_on_delete is used here to avoid that Gtk automatically // destroys the dialog when the user press ESC on the dialog: in that case // a second call to ShowModal() would result in a bunch of Gtk-CRITICAL // errors... g_signal_connect(m_widget, "delete_event", G_CALLBACK (gtk_widget_hide_on_delete), this); // local-only property could be set to false to allow non-local files to be // loaded. In that case get/set_uri(s) should be used instead of // get/set_filename(s) everywhere and the GtkFileChooserDialog should // probably also be created with a backend, e.g. "gnome-vfs", "default", ... // (gtk_file_chooser_dialog_new_with_backend). Currently local-only is kept // as the default - true: // gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(m_widget), true); g_signal_connect (m_widget, "response", G_CALLBACK (gtk_filedialog_response_callback), this); g_signal_connect (m_widget, "selection-changed", G_CALLBACK (gtk_filedialog_selchanged_callback), this); // deal with extensions/filters SetWildcard(wildCard); wxString defaultFileNameWithExt = defaultFileName; if ( !wildCard.empty() && !defaultFileName.empty() && !wxFileName(defaultFileName).HasExt() ) { // append the default extension, if any, to the initial file name: GTK // won't do it for us by default (unlike e.g. MSW) const wxFileName fnWC(m_fc.GetCurrentWildCard()); if ( fnWC.HasExt() ) { // Notice that we shouldn't append the extension if it's a wildcard // because this is not useful: the user would need to change it to use // some fixed extension anyhow. const wxString& ext = fnWC.GetExt(); if ( ext.find_first_of("?*") == wxString::npos ) defaultFileNameWithExt << "." << ext; } } // if defaultDir is specified it should contain the directory and // defaultFileName should contain the default name of the file, however if // directory is not given, defaultFileName contains both wxFileName fn; if ( defaultDir.empty() ) fn.Assign(defaultFileNameWithExt); else if ( !defaultFileNameWithExt.empty() ) fn.Assign(defaultDir, defaultFileNameWithExt); else fn.AssignDir(defaultDir); // set the initial file name and/or directory fn.MakeAbsolute(); // GTK+ needs absolute path const wxString dir = fn.GetPath(); if ( !dir.empty() ) { gtk_file_chooser_set_current_folder(file_chooser, wxGTK_CONV_FN(dir)); } const wxString fname = fn.GetFullName(); if ( style & wxFD_SAVE ) { if ( !fname.empty() ) { gtk_file_chooser_set_current_name(file_chooser, wxGTK_CONV_FN(fname)); } #if GTK_CHECK_VERSION(2,7,3) if ((style & wxFD_OVERWRITE_PROMPT) #ifndef __WXGTK3__ && gtk_check_version(2,7,3) == NULL #endif ) { gtk_file_chooser_set_do_overwrite_confirmation(file_chooser, true); } #endif } else // wxFD_OPEN { if ( !fname.empty() ) { gtk_file_chooser_set_filename(file_chooser, wxGTK_CONV_FN(fn.GetFullPath())); } } if ( style & wxFD_PREVIEW ) { GtkWidget *previewImage = gtk_image_new(); gtk_file_chooser_set_preview_widget(file_chooser, previewImage); g_signal_connect(m_widget, "update-preview", G_CALLBACK(gtk_filedialog_update_preview_callback), previewImage); } return true; }
bool CSourceDataGenerator::IsFilenameSupported(const wxFileName &fileName) { return fileName.GetExt() == "h" || fileName.GetExt() == "c"; }
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; }
bool BinaryDataGenerator::IsFilenameSupported(const wxFileName &fileName) { return fileName.GetExt() == "bin"; }