wxString EDA_APP::GetHelpFile( void ) { wxString fn; wxArrayString subdirs, altsubdirs; /* FIXME: This is not the ideal way to handle this. Unfortunately, the * CMake install paths seem to be a moving target so this crude * hack solve the problem of install path differences between * Windows and non-Windows platforms. */ // Partially fixed, but must be enhanced // Create subdir tree for "standard" linux distributions, when KiCad comes // from a distribution files are in /usr/share/doc/kicad/help and binaries // in /usr/bin or /usr/local/bin subdirs.Add( wxT( "share" ) ); subdirs.Add( _T( "doc" ) ); subdirs.Add( wxT( "kicad" ) ); subdirs.Add( _T( "help" ) ); // Create subdir tree for linux and Windows KiCad pack. // Note the pack form under linux is also useful if a user wants to // install KiCad to a server because there is only one path to mount // or export (something like /usr/local/kicad). // files are in <install dir>/kicad/doc/help // (often /usr/local/kicad/kicad/doc/help) // <install dir>/kicad/ is retrieved from m_BinDir altsubdirs.Add( _T( "doc" ) ); altsubdirs.Add( _T( "help" ) ); /* Search for a help file. * we *must* find a help file. * so help is searched in directories in this order: * help/<canonical name> like help/en_GB * help/<short name> like help/en * help/en */ // Step 1 : Try to find help file in help/<canonical name> subdirs.Add( m_Locale->GetCanonicalName() ); altsubdirs.Add( m_Locale->GetCanonicalName() ); fn = FindFileInSearchPaths( m_HelpFileName, &altsubdirs ); if( !fn ) fn = FindFileInSearchPaths( m_HelpFileName, &subdirs ); // Step 2 : if not found Try to find help file in help/<short name> if( !fn ) { subdirs.RemoveAt( subdirs.GetCount() - 1 ); altsubdirs.RemoveAt( altsubdirs.GetCount() - 1 ); // wxLocale::GetName() does not return always the short name subdirs.Add( m_Locale->GetName().BeforeLast( '_' ) ); altsubdirs.Add( m_Locale->GetName().BeforeLast( '_' ) ); fn = FindFileInSearchPaths( m_HelpFileName, &altsubdirs ); if( !fn ) fn = FindFileInSearchPaths( m_HelpFileName, &subdirs ); } // Step 3 : if not found Try to find help file in help/en if( !fn ) { subdirs.RemoveAt( subdirs.GetCount() - 1 ); altsubdirs.RemoveAt( altsubdirs.GetCount() - 1 ); subdirs.Add( _T( "en" ) ); altsubdirs.Add( _T( "en" ) ); fn = FindFileInSearchPaths( m_HelpFileName, &altsubdirs ); if( !fn ) fn = FindFileInSearchPaths( m_HelpFileName, &subdirs ); } return fn; }
// See also FindKicadHelpPath.cpp.notused. wxString SearchHelpFileFullPath( const SEARCH_STACK& aSStack, const wxString& aBaseName ) { wxArrayString subdirs; wxArrayString altsubdirs; SEARCH_STACK ss = aSStack; // It might already be in aSStack, but why depend on other code // far away when it's so easy to add it again (to our copy) as the first place to look. // This is CMAKE_INSTALL_PREFIX unless DEFAULT_INSTALL_PATH was defined during // build configuration: ss.AddPaths( wxT( DEFAULT_INSTALL_PATH ), 0 ); #if defined(__WXMAC__) ss.AddPaths( GetOSXKicadMachineDataDir() ); ss.AddPaths( Pgm().GetExecutablePath(), 0 ); // OS X packages can have the help files in // /Library/Application\ Support/kicad/help, // and in Contents/SharedSupport/help inside the // bundle. // Below we account for an international subdirectory. subdirs.Add( wxT( "help" ) ); altsubdirs.Add( wxT( "Contents" ) ); altsubdirs.Add( wxT( "SharedSupport" ) ); altsubdirs.Add( wxT( "help" ) ); #endif #if ! defined(__WXMAC__) // && defined(__linux__) // This is the executable path minus the trailing bin directory used on Windows and Linux. wxFileName tmp( Pgm().GetExecutablePath(), wxEmptyString ); wxArrayString binDirs = tmp.GetDirs(); if( !binDirs.IsEmpty() && binDirs[ binDirs.GetCount() - 1 ].CmpNoCase( wxT( "bin" ) ) == 0 ) tmp.RemoveLastDir(); ss.AddPaths( tmp.GetPath(), 0 ); // Based on kicad-doc.bzr/CMakeLists.txt, line 20, the help files are // installed into "<CMAKE_INSTALL_PREFIX>/share/doc/kicad/help" for linux. // This is ${KICAD_HELP} var in that CMakeLists.txt file. // Below we account for an international subdirectory. subdirs.Add( wxT( "share" ) ); subdirs.Add( wxT( "doc" ) ); subdirs.Add( wxT( "kicad" ) ); subdirs.Add( wxT( "help" ) ); // Based on kicad-doc.bzr/CMakeLists.txt, line 35, the help files are // installed into "<CMAKE_INSTALL_PREFIX>/doc/help" for Windows. // This is ${KICAD_HELP} var in that CMakeLists.txt file. // Below we account for an international subdirectory. altsubdirs.Add( wxT( "doc" ) ); altsubdirs.Add( wxT( "help" ) ); #endif // If there's a KICAD environment variable set, always use that guy's path first. if( !Pgm().GetKicadEnvVariable().IsEmpty() ) ss.AddPaths( Pgm().GetKicadEnvVariable(), 0 ); /* Search for a help file. * we *must* find a help file. * so help is searched in directories in this order: * help/<canonical name> like help/en_GB * help/<short name> like help/en * help/en */ wxLocale* i18n = Pgm().GetLocale(); // We try to find help file in help/<canonical name> // If fails, try to find help file in help/<short canonical name> // If fails, try to find help file in help/en wxArrayString locale_name_dirs; locale_name_dirs.Add( i18n->GetCanonicalName() ); // canonical name like fr_FR // wxLocale::GetName() does not return always the short name locale_name_dirs.Add( i18n->GetName().BeforeLast( '_' ) ); // short canonical name like fr locale_name_dirs.Add( wxT( "en" ) ); // default (en) #if defined(DEBUG) && 1 ss.Show( wxString( __func__ ) ); wxLogDebug( wxT( "%s: m_help_file:'%s'" ), __func__, GetChars( aBaseName ) ); #endif wxLogDebug( wxT( "Checking SEARCH_STACK for file %s" ), GetChars( aBaseName ) ); // Help files can be html (.html ext) or pdf (.pdf ext) files. // Therefore, <BaseName>.html file is searched and if not found, // <BaseName>.pdf file is searched in the same paths wxString fn; for( unsigned ii = 0; ii < locale_name_dirs.GetCount(); ii++ ) { subdirs.Add( locale_name_dirs[ii] ); altsubdirs.Add( locale_name_dirs[ii] ); fn = FindFileInSearchPaths( ss, aBaseName + wxT( ".html" ), &altsubdirs ); if( !fn.IsEmpty() ) break; fn = FindFileInSearchPaths( ss, aBaseName + wxT( ".pdf" ), &altsubdirs ); if( !fn.IsEmpty() ) break; fn = FindFileInSearchPaths( ss, aBaseName + wxT( ".html" ), &subdirs ); if( !fn.IsEmpty() ) break; fn = FindFileInSearchPaths( ss, aBaseName + wxT( ".pdf" ), &subdirs ); if( !fn.IsEmpty() ) break; subdirs.RemoveAt( subdirs.GetCount() - 1 ); altsubdirs.RemoveAt( altsubdirs.GetCount() - 1 ); } return fn; }