31#include <wx/mimetype.h>
32#include <wx/filename.h>
41#include "wx/tokenzr.h"
45 if( !
string.StartsWith( wxT(
"\"" ) ) )
47 string.Prepend ( wxT(
"\"" ) );
48 string.Append ( wxT(
"\"" ) );
58 wxString fullFileName =
Pgm().GetExecutablePath() + shortname;
60 wxString fullFileName =
Pgm().GetExecutablePath() + wxT(
"Contents/MacOS/" ) + shortname;
62 if( wxFileExists( fullFileName ) )
67 if(
Pgm().IsKicadEnvVariableDefined() )
69 fullFileName =
Pgm().GetKicadEnvVariable() + shortname;
71 if( wxFileExists( fullFileName ) )
75#if defined( __WINDOWS__ )
82 const static wxChar* possibilities[] = {
83#if defined( __WXMAC__ )
85 wxT(
"Contents/Applications/pcbnew.app/Contents/MacOS/" ),
86 wxT(
"Contents/Applications/eeschema.app/Contents/MacOS/" ),
87 wxT(
"Contents/Applications/gerbview.app/Contents/MacOS/" ),
88 wxT(
"Contents/Applications/bitmap2component.app/Contents/MacOS/" ),
89 wxT(
"Contents/Applications/pcb_calculator.app/Contents/MacOS/" ),
90 wxT(
"Contents/Applications/pl_editor.app/Contents/MacOS/" ),
93 wxT(
"/usr/local/bin/" ),
94 wxT(
"/usr/local/kicad/bin/" ),
99 for(
unsigned i=0; i<
arrayDim(possibilities); ++i )
102 fullFileName = possibilities[i] + shortname;
105 fullFileName =
Pgm().GetExecutablePath() + possibilities[i] + shortname;
108 if( wxFileExists( fullFileName ) )
118int ExecuteFile(
const wxString& aEditorName,
const wxString& aFileName, wxProcess *aCallback )
120 wxString fullEditorName;
121 std::vector<wxString> params;
125 bool inSingleQuotes =
false;
126 bool inDoubleQuotes =
false;
131 if( !param.IsEmpty() )
133 params.push_back( param );
138 for( wxUniChar ch : aEditorName )
145 inSingleQuotes =
false;
153 else if( inDoubleQuotes )
158 inDoubleQuotes =
false;
165 else if( ch ==
'\'' )
168 inSingleQuotes =
true;
173 inDoubleQuotes =
true;
188 params.erase( params.begin() );
193 if( wxFileExists( fullEditorName ) )
196 const wchar_t* args[4];
198 args[i++] = fullEditorName.wc_str();
200 if( !params.empty() )
202 for(
const wxString& p : params )
203 args[i++] = p.wc_str();
206 if( !aFileName.IsEmpty() )
207 args[i++] = aFileName.wc_str();
211 return wxExecute(
const_cast<wchar_t**
>( args ), wxEXEC_ASYNC, aCallback );
215 msg.Printf(
_(
"Command '%s' could not be found." ), fullEditorName );
224 wxString filename = file;
226 Pgm().ReadPdfBrowserInfos();
228 if(
Pgm().UseSystemPdfBrowser() )
232 msg.Printf(
_(
"Unable to find a PDF viewer for '%s'." ), filename );
239 const wchar_t* args[3];
241 args[0] =
Pgm().GetPdfBrowserName().wc_str();
242 args[1] = filename.wc_str();
245 if( wxExecute(
const_cast<wchar_t**
>( args ) ) == -1 )
247 msg.Printf(
_(
"Problem while running the PDF viewer '%s'." ), args[0] );
259 wxFileName fileName( file );
260 wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( fileName.GetExt() );
266 wxFileType::MessageParameters params( file );
268 filetype->GetOpenCommand( &command, params );
271 if( !command.IsEmpty() )
272 wxExecute( command );
276void KiCopyFile(
const wxString& aSrcPath,
const wxString& aDestPath, wxString& aErrors )
278 if( !wxCopyFile( aSrcPath, aDestPath ) )
282 if( !aErrors.IsEmpty() )
285 msg.Printf(
_(
"Cannot copy file '%s'." ), aDestPath );
293 return wxT(
"\"" ) + fn.GetFullPath( format ) + wxT(
"\"" );
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
This file is part of the common library.
wxString FindKicadFile(const wxString &shortname)
Search the executable file shortname in KiCad binary path and return full file name if found or short...
wxString QuoteFullPath(wxFileName &fn, wxPathFormat format)
Quote return value of wxFileName::GetFullPath().
bool OpenPDF(const wxString &file)
Run the PDF viewer and display a PDF file.
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
void OpenFile(const wxString &file)
void QuoteString(wxString &string)
Add un " to the start and the end of string (if not already done).
int ExecuteFile(const wxString &aEditorName, const wxString &aFileName, wxProcess *aCallback)
Call the executable file aEditorName with the parameter aFileName.
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.