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.

126 lines
3.3 KiB

  1. #include <fctsys.h>
  2. #include <pgm_base.h>
  3. #include <macros.h>
  4. #include <gestfich.h>
  5. /**
  6. * Function FindKicadHelpPath
  7. * finds the absolute path for KiCad "help" (or "help/&ltlanguage&gt")
  8. * Find path kicad/doc/help/xx/ or kicad/doc/help/:
  9. * from BinDir
  10. * else from environment variable KICAD
  11. * else from one of s_HelpPathList
  12. * typically c:/kicad/doc/help or /usr/share/kicad/help
  13. * or /usr/local/share/kicad/help
  14. * (must have kicad in path name)
  15. *
  16. * xx = iso639-1 language id (2 letters (generic) or 4 letters):
  17. * fr = french (or fr_FR)
  18. * en = English (or en_GB or en_US ...)
  19. * de = deutch
  20. * es = spanish
  21. * pt = portuguese (or pt_BR ...)
  22. *
  23. * default = en (if not found = fr)
  24. */
  25. wxString FindKicadHelpPath()
  26. {
  27. bool found = false;
  28. wxString bin_dir = Pgm().GetExecutablePath();
  29. if( bin_dir.Last() == '/' )
  30. bin_dir.RemoveLast();
  31. wxString fullPath = bin_dir.BeforeLast( '/' ); // cd ..
  32. fullPath += wxT( "/doc/help/" );
  33. wxString localeString = Pgm().GetLocale()->GetCanonicalName();
  34. wxString path_tmp = fullPath;
  35. #ifdef __WINDOWS__
  36. path_tmp.MakeLower();
  37. #endif
  38. if( path_tmp.Contains( wxT( "kicad" ) ) )
  39. {
  40. if( wxDirExists( fullPath ) )
  41. found = true;
  42. }
  43. // find kicad/help/ from environment variable KICAD
  44. if( !found && Pgm().IsKicadEnvVariableDefined() )
  45. {
  46. fullPath = Pgm().GetKicadEnvVariable() + wxT( "/doc/help/" );
  47. if( wxDirExists( fullPath ) )
  48. found = true;
  49. }
  50. if( !found )
  51. {
  52. // Possibilities online help
  53. const static wxChar* possibilities[] = {
  54. #ifdef __WINDOWS__
  55. wxT( "c:/kicad/doc/help/" ),
  56. wxT( "d:/kicad/doc/help/" ),
  57. wxT( "c:/Program Files/kicad/doc/help/" ),
  58. wxT( "d:/Program Files/kicad/doc/help/" ),
  59. #else
  60. wxT( "/usr/share/doc/kicad/help/" ),
  61. wxT( "/usr/local/share/doc/kicad/help/" ),
  62. wxT( "/usr/local/kicad/doc/help/" ), // default install for "universal
  63. // tarballs" and build for a server
  64. // (new)
  65. wxT( "/usr/local/kicad/help/" ), // default install for "universal
  66. // tarballs" and build for a server
  67. // (old)
  68. #endif
  69. };
  70. for( unsigned i=0; i<DIM(possibilities); ++i )
  71. {
  72. fullPath = possibilities[i];
  73. if( wxDirExists( fullPath ) )
  74. {
  75. found = true;
  76. break;
  77. }
  78. }
  79. }
  80. if( found )
  81. {
  82. wxString langFullPath = fullPath + localeString + UNIX_STRING_DIR_SEP;
  83. if( wxDirExists( langFullPath ) )
  84. return langFullPath;
  85. langFullPath = fullPath + localeString.Left( 2 ) + UNIX_STRING_DIR_SEP;
  86. if( wxDirExists( langFullPath ) )
  87. return langFullPath;
  88. langFullPath = fullPath + wxT( "en/" );
  89. if( wxDirExists( langFullPath ) )
  90. {
  91. return langFullPath;
  92. }
  93. else
  94. {
  95. langFullPath = fullPath + wxT( "fr/" );
  96. if( wxDirExists( langFullPath ) )
  97. return langFullPath;
  98. }
  99. return fullPath;
  100. }
  101. return wxEmptyString;
  102. }