summaryrefslogtreecommitdiff
path: root/common/findkicadhelppath.cpp.notused
blob: d2d781ef576e29d3a794cf54aa29e6b9618b89a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

#include <fctsys.h>
#include <pgm_base.h>
#include <macros.h>
#include <gestfich.h>


/**
 * Function FindKicadHelpPath
 * finds the absolute path for KiCad "help" (or "help/&ltlanguage&gt")
 *  Find path kicad/doc/help/xx/ or kicad/doc/help/:
 *  from BinDir
 *  else from environment variable KICAD
 *  else from one of s_HelpPathList
 *  typically c:/kicad/doc/help or /usr/share/kicad/help
 *            or /usr/local/share/kicad/help
 *  (must have kicad in path name)
 *
 *  xx = iso639-1 language id (2 letters (generic) or 4 letters):
 *  fr = french (or fr_FR)
 *  en = English (or en_GB or en_US ...)
 *  de = deutch
 *  es = spanish
 *  pt = portuguese (or pt_BR ...)
 *
 *  default = en (if not found = fr)
 */
wxString FindKicadHelpPath()
{
    bool     found = false;
    wxString bin_dir = Pgm().GetExecutablePath();

    if( bin_dir.Last() == '/' )
        bin_dir.RemoveLast();

    wxString fullPath = bin_dir.BeforeLast( '/' );  // cd ..

    fullPath += wxT( "/doc/help/" );

    wxString localeString = Pgm().GetLocale()->GetCanonicalName();

    wxString path_tmp = fullPath;

#ifdef __WINDOWS__
    path_tmp.MakeLower();
#endif

    if( path_tmp.Contains( wxT( "kicad" ) ) )
    {
        if( wxDirExists( fullPath ) )
            found = true;
    }

    // find kicad/help/ from environment variable  KICAD
    if( !found && Pgm().IsKicadEnvVariableDefined() )
    {
        fullPath = Pgm().GetKicadEnvVariable() + wxT( "/doc/help/" );

        if( wxDirExists( fullPath ) )
            found = true;
    }

    if( !found )
    {
        // Possibilities online help
        const static wxChar* possibilities[] = {
#ifdef __WINDOWS__
            wxT( "c:/kicad/doc/help/" ),
            wxT( "d:/kicad/doc/help/" ),
            wxT( "c:/Program Files/kicad/doc/help/" ),
            wxT( "d:/Program Files/kicad/doc/help/" ),
#else
            wxT( "/usr/share/doc/kicad/help/" ),
            wxT( "/usr/local/share/doc/kicad/help/" ),
            wxT( "/usr/local/kicad/doc/help/" ),    // default install for "universal
                                                    // tarballs" and build for a server
                                                    // (new)
            wxT( "/usr/local/kicad/help/" ),        // default install for "universal
                                                    // tarballs" and build for a server
                                                    // (old)
#endif
        };

        for( unsigned i=0;  i<DIM(possibilities);  ++i )
        {
            fullPath = possibilities[i];

            if( wxDirExists( fullPath ) )
            {
                found = true;
                break;
            }
        }
    }

    if( found )
    {
        wxString langFullPath = fullPath + localeString + UNIX_STRING_DIR_SEP;

        if( wxDirExists( langFullPath ) )
            return langFullPath;

        langFullPath = fullPath + localeString.Left( 2 ) + UNIX_STRING_DIR_SEP;

        if( wxDirExists( langFullPath ) )
            return langFullPath;

        langFullPath = fullPath + wxT( "en/" );

        if( wxDirExists( langFullPath ) )
        {
            return langFullPath;
        }
        else
        {
            langFullPath = fullPath + wxT( "fr/" );

            if( wxDirExists( langFullPath ) )
                return langFullPath;
        }
        return fullPath;
    }

    return wxEmptyString;
}