31#include <wx/mimetype.h>
32#include <wx/filename.h>
44 if( !
string.StartsWith( wxT(
"\"" ) ) )
46 string.Prepend ( wxT(
"\"" ) );
47 string.Append ( wxT(
"\"" ) );
57 wxString fullFileName =
Pgm().GetExecutablePath() + shortname;
59 wxString fullFileName =
Pgm().GetExecutablePath() + wxT(
"Contents/MacOS/" ) + shortname;
61 if( wxFileExists( fullFileName ) )
66 if(
Pgm().IsKicadEnvVariableDefined() )
68 fullFileName =
Pgm().GetKicadEnvVariable() + shortname;
70 if( wxFileExists( fullFileName ) )
74#if defined( __WINDOWS__ )
81 const static wxChar* possibilities[] = {
82#if defined( __WXMAC__ )
84 wxT(
"Contents/Applications/pcbnew.app/Contents/MacOS/" ),
85 wxT(
"Contents/Applications/eeschema.app/Contents/MacOS/" ),
86 wxT(
"Contents/Applications/gerbview.app/Contents/MacOS/" ),
87 wxT(
"Contents/Applications/bitmap2component.app/Contents/MacOS/" ),
88 wxT(
"Contents/Applications/pcb_calculator.app/Contents/MacOS/" ),
89 wxT(
"Contents/Applications/pl_editor.app/Contents/MacOS/" ),
92 wxT(
"/usr/local/bin/" ),
93 wxT(
"/usr/local/kicad/bin/" ),
98 for(
unsigned i=0; i<
arrayDim(possibilities); ++i )
101 fullFileName = possibilities[i] + shortname;
104 fullFileName =
Pgm().GetExecutablePath() + possibilities[i] + shortname;
107 if( wxFileExists( fullFileName ) )
115int ExecuteFile(
const wxString& aEditorName,
const wxString& aFileName, wxProcess *aCallback )
117 wxString fullEditorName;
121 int space = aEditorName.Find(
' ' );
123 if( space > 0 && !aEditorName.Contains(
"\"" ) && !aEditorName.Contains(
"\'" ) )
125 fullEditorName =
FindKicadFile( aEditorName.Mid( 0, space ) );
126 param = aEditorName.Mid( space + 1 );
134 if( wxFileExists( fullEditorName ) )
137 const wchar_t* args[4];
139 args[i++] = fullEditorName.wc_str();
141 if( !param.IsEmpty() )
142 args[i++] = param.wc_str();
144 if( !aFileName.IsEmpty() )
145 args[i++] = aFileName.wc_str();
149 return wxExecute(
const_cast<wchar_t**
>( args ), wxEXEC_ASYNC, aCallback );
153 msg.Printf(
_(
"Command '%s' could not be found." ), fullEditorName );
162 wxString filename = file;
164 Pgm().ReadPdfBrowserInfos();
166 if(
Pgm().UseSystemPdfBrowser() )
170 msg.Printf(
_(
"Unable to find a PDF viewer for '%s'." ), filename );
177 const wchar_t* args[3];
179 args[0] =
Pgm().GetPdfBrowserName().wc_str();
180 args[1] = filename.wc_str();
183 if( wxExecute(
const_cast<wchar_t**
>( args ) ) == -1 )
185 msg.Printf(
_(
"Problem while running the PDF viewer '%s'." ), args[0] );
197 wxFileName fileName( file );
198 wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( fileName.GetExt() );
204 wxFileType::MessageParameters params( file );
206 filetype->GetOpenCommand( &command, params );
209 if( !command.IsEmpty() )
210 wxExecute( command );
214void KiCopyFile(
const wxString& aSrcPath,
const wxString& aDestPath, wxString& aErrors )
216 if( !wxCopyFile( aSrcPath, aDestPath ) )
220 if( !aErrors.IsEmpty() )
223 msg.Printf(
_(
"Cannot copy file '%s'." ), aDestPath );
231 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.