int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& param, wxProcess *callback ) { wxString fullFileName; fullFileName = FindKicadFile( ExecFile ); #ifdef __WXMAC__ if( wxFileExists( fullFileName ) || wxDir::Exists( fullFileName ) ) { return ProcessExecute( Pgm().GetExecutablePath() + wxT( "/" ) + ExecFile + wxT( " " ) + param, wxEXEC_ASYNC, callback ); } else { return ProcessExecute( wxT( "/usr/bin/open " ) + param, wxEXEC_ASYNC, callback ); } #else if( wxFileExists( fullFileName ) ) { if( !param.IsEmpty() ) fullFileName += wxT( " " ) + param; return ProcessExecute( fullFileName, wxEXEC_ASYNC, callback ); } #endif wxString msg; msg.Printf( _( "Command <%s> could not found" ), GetChars( fullFileName ) ); DisplayError( frame, msg, 20 ); return -1; }
int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& param ) { wxString FullFileName; FullFileName = FindKicadFile( ExecFile ); #ifdef __WXMAC__ if( wxFileExists( FullFileName ) || wxDir::Exists( FullFileName ) ) { ProcessExecute( wxT("open -a ") + ExecFile + wxT(" ") + param ); } else { ProcessExecute( wxT("open ") + param ); } return 0; #else if( wxFileExists( FullFileName ) ) { if( !param.IsEmpty() ) FullFileName += wxT( " " ) + param; ProcessExecute( FullFileName ); return 0; } #endif wxString msg; msg.Printf( _( "Command <%s> could not found" ), GetChars( FullFileName ) ); DisplayError( frame, msg, 20 ); return -1; }
static int _unmount_fuse( const char * m_dir ) { /* * ZULUCRYPTumount is defined in ../constants.h */ return ProcessExecute( ZULUCRYPTumount,m_dir,NULL ) ; }
/* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RUN_FREEROUTE */ void DIALOG_FREEROUTE::OnLaunchButtonClick( wxCommandEvent& event ) { wxString url; wxString command; wxFileName fileName( FindKicadFile( wxT( "freeroute.jnlp" ) ), wxPATH_UNIX ); if( fileName.FileExists() ) { wxString javaWebStartCommand = wxT( "javaws" ); // Find the Java web start application on Windows. #ifdef __WINDOWS__ // If you thought the registry was brain dead before, now you have to deal with // accessing it in either 64 or 32 bit mode depending on the build version of // Windows and the build version of KiCad. // This key works for 32 bit Java on 32 bit Windows and 64 bit Java on 64 bit Windows. wxRegKey key( wxRegKey::HKLM, wxT( "SOFTWARE\\JavaSoft\\Java Web Start" ), wxIsPlatform64Bit() ? wxRegKey::WOW64ViewMode_64 : wxRegKey::WOW64ViewMode_Default ); // It's possible that 32 bit Java is installed on 64 bit Windows. if( !key.Exists() && wxIsPlatform64Bit() ) key.SetName( wxRegKey::HKLM, wxT( "SOFTWARE\\Wow6432Node\\JavaSoft\\Java Web Start" ) ); if( !key.Exists() ) { ::wxMessageBox( _( "It appears that the Java run time environment is not " "installed on this computer. Java is required to use " "FreeRoute." ), _( "Pcbnew Error" ), wxOK | wxICON_ERROR ); return; } key.Open( wxRegKey::Read ); // Get the current version of java installed to determine the executable path. wxString value; key.QueryValue( wxT( "CurrentVersion" ), value ); key.SetName( key.GetName() + wxT( "\\" ) + value ); key.QueryValue( wxT( "Home" ), value ); javaWebStartCommand = value + wxFileName::GetPathSeparator() + javaWebStartCommand; #endif // Wrap FullFileName in double quotes in case it has C:\Program Files in it. // The space is interpreted as an argument separator. command << javaWebStartCommand << wxChar( ' ' ) << wxChar( '"' ) << fileName.GetFullPath() << wxChar( '"' ); ProcessExecute( command ); return; } url = m_FreerouteURLName->GetValue() + wxT( "/java/freeroute.jnlp" ); wxLaunchDefaultBrowser( url ); }
void OpenFile( const wxString& file ) { wxString command; wxString filename = file; wxFileName CurrentFileName( filename ); wxString ext, type; ext = CurrentFileName.GetExt(); wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( ext ); bool success = false; wxFileType::MessageParameters params( filename, type ); if( filetype ) success = filetype->GetOpenCommand( &command, params ); delete filetype; if( success && !command.IsEmpty() ) ProcessExecute( command ); }
bool GetAssociatedDocument( wxWindow* aParent, const wxString& aDocName, const wxPathList* aPaths) { wxString docname, fullfilename; wxString msg; wxString command; bool success = false; // Is an internet url static const wxChar* url_header[3] = { wxT( "http:" ), wxT( "ftp:" ), wxT( "www." ) }; for( unsigned ii = 0; ii < DIM(url_header); ii++ ) { if( aDocName.First( url_header[ii] ) == 0 ) //. seems an internet url { wxLaunchDefaultBrowser( aDocName ); return true; } } docname = aDocName; #ifdef __WINDOWS__ docname.Replace( UNIX_STRING_DIR_SEP, WIN_STRING_DIR_SEP ); #else docname.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP ); #endif /* Compute the full file name */ if( wxIsAbsolutePath( aDocName ) || aPaths == NULL) fullfilename = aDocName; /* If the file exists, this is a trivial case: return the filename * "as this". the name can be an absolute path, or a relative path * like ./filename or ../<filename> */ else if( wxFileName::FileExists( aDocName ) ) fullfilename = aDocName; else { fullfilename = aPaths->FindValidPath( aDocName ); } wxString mask( wxT( "*" ) ), extension; #ifdef __WINDOWS__ mask += wxT( ".*" ); extension = wxT( ".*" ); #endif if( wxIsWild( fullfilename ) ) { fullfilename = EDA_FILE_SELECTOR( _( "Doc Files" ), wxPathOnly( fullfilename ), fullfilename, extension, mask, aParent, wxFD_OPEN, true, wxPoint( -1, -1 ) ); if( fullfilename.IsEmpty() ) return false; } if( !wxFileExists( fullfilename ) ) { msg.Printf( _( "Doc File '%s' not found" ), GetChars( aDocName ) ); DisplayError( aParent, msg ); return false; } wxFileName currentFileName( fullfilename ); wxString file_ext = currentFileName.GetExt(); if( file_ext == wxT( "pdf" ) ) { success = OpenPDF( fullfilename ); return success; } /* Try to launch some browser (useful under linux) */ wxFileType* filetype; wxString type; filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( file_ext ); if( !filetype ) // 2nd attempt. { mimeDatabase = new wxMimeTypesManager; mimeDatabase->AddFallbacks( EDAfallbacks ); filetype = mimeDatabase->GetFileTypeFromExtension( file_ext ); delete mimeDatabase; mimeDatabase = NULL; } if( filetype ) { wxFileType::MessageParameters params( fullfilename, type ); success = filetype->GetOpenCommand( &command, params ); delete filetype; if( success ) success = ProcessExecute( command ); } if( !success ) { msg.Printf( _( "Unknown MIME type for doc file <%s>" ), GetChars( fullfilename ) ); DisplayError( aParent, msg ); } return success; }
bool OpenPDF( const wxString& file ) { wxString command; wxString filename = file; wxString type; bool success = false; Pgm().ReadPdfBrowserInfos(); if( !Pgm().UseSystemPdfBrowser() ) // Run the preferred PDF Browser { AddDelimiterString( filename ); command = Pgm().GetPdfBrowserName() + wxT( " " ) + filename; } else { wxFileType* filetype = NULL; wxFileType::MessageParameters params( filename, type ); filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( wxT( "pdf" ) ); if( filetype ) success = filetype->GetOpenCommand( &command, params ); delete filetype; #ifndef __WINDOWS__ // Bug ? under linux wxWidgets returns acroread as PDF viewer, even if // it does not exist. if( command.StartsWith( wxT( "acroread" ) ) ) // Workaround success = false; #endif if( success && !command.IsEmpty() ) { success = ProcessExecute( command ); if( success ) return success; } success = false; command.clear(); if( !success ) { #if !defined(__WINDOWS__) AddDelimiterString( filename ); // here is a list of PDF viewers candidates static const wxChar* tries[] = { wxT( "/usr/bin/evince" ), wxT( "/usr/bin/okular" ), wxT( "/usr/bin/gpdf" ), wxT( "/usr/bin/konqueror" ), wxT( "/usr/bin/kpdf" ), wxT( "/usr/bin/xpdf" ), wxT( "/usr/bin/open" ), // BSD and OSX file & dir opener wxT( "/usr/bin/xdg-open" ), // Freedesktop file & dir opener }; for( unsigned ii = 0; ii<DIM(tries); ii++ ) { if( wxFileExists( tries[ii] ) ) { command = tries[ii]; command += wxT( ' ' ); command += filename; break; } } #endif } } if( !command.IsEmpty() ) { success = ProcessExecute( command ); if( !success ) { wxString msg; msg.Printf( _( "Problem while running the PDF viewer\nCommand is '%s'" ), GetChars( command ) ); DisplayError( NULL, msg ); } } else { wxString msg; msg.Printf( _( "Unable to find a PDF viewer for <%s>" ), GetChars( filename ) ); DisplayError( NULL, msg ); success = false; } return success; }
bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList, int aFormat, const wxString& aFullFileName, unsigned aNetlistOptions, REPORTER* aReporter ) { bool res = true; bool executeCommandLine = false; wxString fileName = aFullFileName; NETLIST_EXPORTER *helper; switch( aFormat ) { case NET_TYPE_PCBNEW: helper = new NETLIST_EXPORTER_KICAD( aConnectedItemsList, Prj().SchLibs() ); break; case NET_TYPE_ORCADPCB2: helper = new NETLIST_EXPORTER_ORCADPCB2( aConnectedItemsList, Prj().SchLibs() ); break; case NET_TYPE_CADSTAR: helper = new NETLIST_EXPORTER_CADSTAR( aConnectedItemsList, Prj().SchLibs() ); break; case NET_TYPE_SPICE: helper = new NETLIST_EXPORTER_PSPICE( aConnectedItemsList, Prj().SchLibs() ); break; default: { wxFileName tmpFile = fileName; tmpFile.SetExt( GENERIC_INTERMEDIATE_NETLIST_EXT ); fileName = tmpFile.GetFullPath(); helper = new NETLIST_EXPORTER_GENERIC( aConnectedItemsList, Prj().SchLibs() ); executeCommandLine = true; } break; } res = helper->WriteNetlist( fileName, aNetlistOptions ); delete helper; // If user provided a plugin command line, execute it. if( executeCommandLine && res && !m_netListerCommand.IsEmpty() ) { wxString prj_dir = Prj().GetProjectPath(); // build full command line from user's format string, e.g.: // "xsltproc -o %O /usr/local/lib/kicad/plugins/netlist_form_pads-pcb.xsl %I" // becomes, after the user selects /tmp/s1.net as the output file from the file dialog: // "xsltproc -o /tmp/s1.net /usr/local/lib/kicad/plugins/netlist_form_pads-pcb.xsl /tmp/s1.xml" wxString commandLine = NETLIST_EXPORTER::MakeCommandLine( m_netListerCommand, fileName, aFullFileName, prj_dir.SubString( 0, prj_dir.Len() - 2 ) // strip trailing '/' ); if( aReporter ) { wxArrayString output, errors; int diag = wxExecute( commandLine, output, errors, m_exec_flags ); wxString msg; msg << _( "Run command:" ) << wxT( "\n" ) << commandLine << wxT( "\n\n" ); aReporter->Report( msg, REPORTER::RPT_ACTION ); if( diag != 0 ) aReporter->Report( wxString::Format( _("Command error. Return code %d" ), diag ), REPORTER::RPT_ERROR ); else aReporter->Report( _( "Success" ), REPORTER::RPT_INFO ); *aReporter << wxT("\n"); if( output.GetCount() ) { msg.Empty(); msg << wxT( "\n" ) << _( "Info messages:" ) << wxT( "\n" ); aReporter->Report( msg, REPORTER::RPT_INFO ); for( unsigned ii = 0; ii < output.GetCount(); ii++ ) aReporter->Report( output[ii] + wxT( "\n" ), REPORTER::RPT_INFO ); } if( errors.GetCount() ) { msg.Empty(); msg << wxT("\n") << _( "Error messages:" ) << wxT( "\n" ); aReporter->Report( msg, REPORTER::RPT_INFO ); for( unsigned ii = 0; ii < errors.GetCount(); ii++ ) aReporter->Report( errors[ii] + wxT( "\n" ), REPORTER::RPT_ERROR ); } } else ProcessExecute( commandLine, m_exec_flags ); DefaultExecFlags(); // Reset flags to default after executing } return res; }
bool OpenPDF( const wxString& file ) { wxString command; wxString filename = file; wxString type; bool success = false; wxGetApp().ReadPdfBrowserInfos(); if( !wxGetApp().UseSystemPdfBrowser() ) // Run the preferred PDF Browser { AddDelimiterString( filename ); command = wxGetApp().GetPdfBrowserFileName() + wxT( " " ) + filename; } else { wxFileType* filetype = NULL; wxFileType::MessageParameters params( filename, type ); filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( wxT( "pdf" ) ); if( filetype ) success = filetype->GetOpenCommand( &command, params ); delete filetype; #ifndef __WINDOWS__ // Bug ? under linux wxWidgets returns acroread as PDF viewer, even if // it does not exist. if( command.StartsWith( wxT( "acroread" ) ) ) // Workaround success = false; #endif if( success && !command.IsEmpty() ) { success = ProcessExecute( command ); if( success ) return success; } success = false; command.Empty(); if( !success ) { #ifndef __WINDOWS__ AddDelimiterString( filename ); /* here is a list of PDF viewers candidates */ const static wxString tries[] = { wxT( "/usr/bin/evince" ), wxT( "/usr/bin/gpdf" ), wxT( "/usr/bin/konqueror" ), wxT( "/usr/bin/kpdf" ), wxT( "/usr/bin/xpdf" ), wxT( "/usr/bin/open" ), // BSD and OSX file & dir opener wxT( "/usr/bin/xdg-open" ), // Freedesktop file & dir opener wxT( "" ), }; for( int ii = 0; ; ii++ ) { if( tries[ii].IsEmpty() ) break; if( wxFileExists( tries[ii] ) ) { command = tries[ii] + wxT( " " ) + filename; break; } } #endif } } if( !command.IsEmpty() ) { success = ProcessExecute( command ); if( !success ) { wxString msg = _( "Problem while running the PDF viewer" ); msg << _( "\n command is " ) << command; DisplayError( NULL, msg ); } } else { wxString msg = _( "Unable to find a PDF viewer for" ); msg << wxT( " " ) << filename; DisplayError( NULL, msg ); success = false; } return success; }
// Run freeroute, if it is available (freeroute.jar found in kicad binaries) void DIALOG_FREEROUTE::OnLaunchButtonClick( wxCommandEvent& event ) { wxString dsnFile; if( m_freeRouterFound ) { dsnFile = createDSN_File(); if( dsnFile.IsEmpty() ) // Something is wrong or command cancelled return; } wxFileName jarfileName( FindKicadFile( wxT( "freeroute.jar" ) ), wxPATH_UNIX ); wxString command; // Find the Java application on Windows. // Colud be no more needed since we now have to run only java, not java web start #ifdef __WINDOWS__ // If you thought the registry was brain dead before, now you have to deal with // accessing it in either 64 or 32 bit mode depending on the build version of // Windows and the build version of KiCad. // This key works for 32 bit Java on 32 bit Windows and 64 bit Java on 64 bit Windows. wxString keyName = wxT( "SOFTWARE\\JavaSoft\\Java Runtime Environment" ); wxRegKey key( wxRegKey::HKLM, keyName, wxIsPlatform64Bit() ? wxRegKey::WOW64ViewMode_64 : wxRegKey::WOW64ViewMode_Default ); // It's possible that 32 bit Java is installed on 64 bit Windows. if( !key.Exists() && wxIsPlatform64Bit() ) { keyName = wxT( "SOFTWARE\\Wow6432Node\\JavaSoft\\Java Runtime Environment" ); key.SetName( wxRegKey::HKLM, keyName ); } if( !key.Exists() ) { ::wxMessageBox( _( "It appears that the Java run time environment is not " "installed on this computer. Java is required to use " "FreeRoute." ), _( "Pcbnew Error" ), wxOK | wxICON_ERROR ); return; } key.Open( wxRegKey::Read ); // Get the current version of java installed to determine the executable path. wxString value; key.QueryValue( wxT( "CurrentVersion" ), value ); key.SetName( key.GetName() + wxT( "\\" ) + value ); key.QueryValue( wxT( "JavaHome" ), value ); command = value + wxFileName::GetPathSeparator(); command << wxT("bin\\java"); #else // __WINDOWS__ command = wxT( "java" ); #endif command << wxT(" -jar "); // add "freeroute.jar" to command line: command << wxChar( '"' ) << jarfileName.GetFullPath() << wxChar( '"' ); // add option to load the .dsn file command << wxT( " -de " ); // add *.dsn full filename (quoted): command << wxChar( '"' ) << dsnFile << wxChar( '"' ); ProcessExecute( command ); }
bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST * aConnectedItemsList, int aFormat, const wxString& aFullFileName, unsigned aNetlistOptions ) { bool res = true; bool executeCommandLine = false; wxString fileName = aFullFileName; wxBusyCursor Busy; NETLIST_EXPORTER *helper; switch( aFormat ) { case NET_TYPE_PCBNEW: helper = new NETLIST_EXPORTER_KICAD( aConnectedItemsList, Prj().SchLibs() ); break; case NET_TYPE_ORCADPCB2: helper = new NETLIST_EXPORTER_ORCADPCB2( aConnectedItemsList, Prj().SchLibs() ); break; case NET_TYPE_CADSTAR: helper = new NETLIST_EXPORTER_CADSTAR( aConnectedItemsList, Prj().SchLibs() ); break; case NET_TYPE_SPICE: helper = new NETLIST_EXPORTER_PSPICE( aConnectedItemsList, Prj().SchLibs() ); break; default: { wxFileName tmpFile = fileName; tmpFile.SetExt( GENERIC_INTERMEDIATE_NETLIST_EXT ); fileName = tmpFile.GetFullPath(); helper = new NETLIST_EXPORTER_GENERIC( aConnectedItemsList, Prj().SchLibs() ); executeCommandLine = true; break; } } res = helper->Write( fileName, aNetlistOptions ); if( executeCommandLine ) { if( !res ) return res; // If user provided no plugin command line, return now. if( m_netListerCommand.IsEmpty() ) return res; // build full command line from user's format string, e.g.: // "xsltproc -o %O /usr/local/lib/kicad/plugins/netlist_form_pads-pcb.xsl %I" // becomes, after the user selects /tmp/s1.net as the output file from the file dialog: // "xsltproc -o /tmp/s1.net /usr/local/lib/kicad/plugins/netlist_form_pads-pcb.xsl /tmp/s1.xml" wxString commandLine = NETLIST_EXPORTER::MakeCommandLine( m_netListerCommand, fileName, aFullFileName ); ProcessExecute( commandLine, wxEXEC_SYNC ); } delete helper; return res; }