You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
6.4 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
19 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
19 years ago
18 years ago
18 years ago
18 years ago
18 years ago
19 years ago
19 years ago
19 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file gestfich.cpp
  27. * @brief Functions for file management
  28. */
  29. #include <wx/mimetype.h>
  30. #include <wx/filename.h>
  31. #include <wx/dir.h>
  32. #include <pgm_base.h>
  33. #include <confirm.h>
  34. #include <core/arraydim.h>
  35. #include <gestfich.h>
  36. #include <string_utils.h>
  37. #include <launch_ext.h>
  38. void QuoteString( wxString& string )
  39. {
  40. if( !string.StartsWith( wxT( "\"" ) ) )
  41. {
  42. string.Prepend ( wxT( "\"" ) );
  43. string.Append ( wxT( "\"" ) );
  44. }
  45. }
  46. wxString FindKicadFile( const wxString& shortname )
  47. {
  48. // Test the presence of the file in the directory shortname of
  49. // the KiCad binary path.
  50. #ifndef __WXMAC__
  51. wxString fullFileName = Pgm().GetExecutablePath() + shortname;
  52. #else
  53. wxString fullFileName = Pgm().GetExecutablePath() + wxT( "Contents/MacOS/" ) + shortname;
  54. #endif
  55. if( wxFileExists( fullFileName ) )
  56. return fullFileName;
  57. // Test the presence of the file in the directory shortname
  58. // defined by the environment variable KiCad.
  59. if( Pgm().IsKicadEnvVariableDefined() )
  60. {
  61. fullFileName = Pgm().GetKicadEnvVariable() + shortname;
  62. if( wxFileExists( fullFileName ) )
  63. return fullFileName;
  64. }
  65. #if defined( __WINDOWS__ )
  66. // kicad can be installed highly portably on Windows, anywhere and concurrently
  67. // either the "kicad file" is immediately adjacent to the exe or it's not a valid install
  68. return shortname;
  69. #endif
  70. // Path list for KiCad binary files
  71. const static wxChar* possibilities[] = {
  72. #if defined( __WXMAC__ )
  73. // all internal paths are relative to main bundle kicad.app
  74. wxT( "Contents/Applications/pcbnew.app/Contents/MacOS/" ),
  75. wxT( "Contents/Applications/eeschema.app/Contents/MacOS/" ),
  76. wxT( "Contents/Applications/gerbview.app/Contents/MacOS/" ),
  77. wxT( "Contents/Applications/bitmap2component.app/Contents/MacOS/" ),
  78. wxT( "Contents/Applications/pcb_calculator.app/Contents/MacOS/" ),
  79. wxT( "Contents/Applications/pl_editor.app/Contents/MacOS/" ),
  80. #else
  81. wxT( "/usr/bin/" ),
  82. wxT( "/usr/local/bin/" ),
  83. wxT( "/usr/local/kicad/bin/" ),
  84. #endif
  85. };
  86. // find binary file from possibilities list:
  87. for( unsigned i=0; i<arrayDim(possibilities); ++i )
  88. {
  89. #ifndef __WXMAC__
  90. fullFileName = possibilities[i] + shortname;
  91. #else
  92. // make relative paths absolute
  93. fullFileName = Pgm().GetExecutablePath() + possibilities[i] + shortname;
  94. #endif
  95. if( wxFileExists( fullFileName ) )
  96. return fullFileName;
  97. }
  98. return shortname;
  99. }
  100. int ExecuteFile( const wxString& aEditorName, const wxString& aFileName, wxProcess *aCallback )
  101. {
  102. wxString fullEditorName;
  103. wxString param;
  104. #ifdef __UNIX__
  105. int space = aEditorName.Find( ' ' );
  106. if( space > 0 && !aEditorName.Contains( "\"" ) && !aEditorName.Contains( "\'" ) )
  107. {
  108. fullEditorName = FindKicadFile( aEditorName.Mid( 0, space ) );
  109. param = aEditorName.Mid( space + 1 );
  110. }
  111. else
  112. #endif
  113. {
  114. fullEditorName = FindKicadFile( aEditorName );
  115. }
  116. if( wxFileExists( fullEditorName ) )
  117. {
  118. int i = 0;
  119. const wchar_t* args[4];
  120. args[i++] = fullEditorName.wc_str();
  121. if( !param.IsEmpty() )
  122. args[i++] = param.wc_str();
  123. if( !aFileName.IsEmpty() )
  124. args[i++] = aFileName.wc_str();
  125. args[i] = nullptr;
  126. return wxExecute( const_cast<wchar_t**>( args ), wxEXEC_ASYNC, aCallback );
  127. }
  128. wxString msg;
  129. msg.Printf( _( "Command '%s' could not be found." ), fullEditorName );
  130. DisplayError( nullptr, msg, 20 );
  131. return -1;
  132. }
  133. bool OpenPDF( const wxString& file )
  134. {
  135. wxString msg;
  136. wxString filename = file;
  137. Pgm().ReadPdfBrowserInfos();
  138. if( Pgm().UseSystemPdfBrowser() )
  139. {
  140. if( !LaunchExternal( filename ) )
  141. {
  142. msg.Printf( _( "Unable to find a PDF viewer for '%s'." ), filename );
  143. DisplayError( nullptr, msg );
  144. return false;
  145. }
  146. }
  147. else
  148. {
  149. const wchar_t* args[3];
  150. args[0] = Pgm().GetPdfBrowserName().wc_str();
  151. args[1] = filename.wc_str();
  152. args[2] = nullptr;
  153. if( wxExecute( const_cast<wchar_t**>( args ) ) == -1 )
  154. {
  155. msg.Printf( _( "Problem while running the PDF viewer '%s'." ), args[0] );
  156. DisplayError( nullptr, msg );
  157. return false;
  158. }
  159. }
  160. return true;
  161. }
  162. void OpenFile( const wxString& file )
  163. {
  164. wxFileName fileName( file );
  165. wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( fileName.GetExt() );
  166. if( !filetype )
  167. return;
  168. wxString command;
  169. wxFileType::MessageParameters params( file );
  170. filetype->GetOpenCommand( &command, params );
  171. delete filetype;
  172. if( !command.IsEmpty() )
  173. wxExecute( command );
  174. }
  175. void KiCopyFile( const wxString& aSrcPath, const wxString& aDestPath, wxString& aErrors )
  176. {
  177. if( !wxCopyFile( aSrcPath, aDestPath ) )
  178. {
  179. wxString msg;
  180. if( !aErrors.IsEmpty() )
  181. aErrors += "\n";
  182. msg.Printf( _( "Cannot copy file '%s'." ), aDestPath );
  183. aErrors += msg;
  184. }
  185. }
  186. wxString QuoteFullPath( wxFileName& fn, wxPathFormat format )
  187. {
  188. return wxT( "\"" ) + fn.GetFullPath( format ) + wxT( "\"" );
  189. }