Code::Blocks  SVN r11506
compilerLCC.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3  * http://www.gnu.org/licenses/gpl-3.0.html
4  *
5  * $Revision: 8649 $
6  * $Id: compilerLCC.cpp 8649 2012-12-12 19:18:18Z mortenmacfly $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/compilergcc/compilerLCC.cpp $
8  */
9 
10 #include <sdk.h>
11 #include "logmanager.h"
12 #include "manager.h"
13 #include "compilerLCC.h"
14 #include <wx/intl.h>
15 #include <wx/regex.h>
16 #include <wx/config.h>
17 #include <wx/fileconf.h>
18 #include <wx/msgdlg.h>
19 
20 #ifdef __WXMSW__
21  #include <wx/msw/registry.h>
22 #endif // __WXMSW__
23 
25  Compiler(_("LCC Compiler"), _T("lcc")),
26  m_RegistryUpdated(false)
27 {
28  m_Weight = 36;
29  Reset();
30 }
31 
33 {
34  //dtor
35 }
36 
38 {
39  return (new CompilerLCC(*this));
40 }
41 
43 {
44  m_RegistryUpdated = false; // Check the registry another time on IsValid()
45 
48 
50 
53  m_LinkLibs.Clear();
56 }
57 
59 {
60  wxString compiler; compiler << wxFILE_SEP_PATH << _T("bin") << wxFILE_SEP_PATH << m_Programs.C;
61 
62 #ifdef __WXMSW__
63  wxRegKey key; // defaults to HKCR
64  wxString mpHKLM = wxEmptyString;
65  wxString mpHKCU = wxEmptyString;
66  wxString mpLccRoot = wxEmptyString;
67  wxString mpLccLnk = wxEmptyString;
68  wxString mpCompiler = wxEmptyString;
69 
70  // Query uninstall information if installed with admin rights:
71  key.SetName(_T("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\lcc-win32 (base system)_is1"));
72  if (key.Exists() && key.Open(wxRegKey::Read))
73  key.QueryValue(_T("Inno Setup: App Path"), mpHKLM);
74 
75  // Query uninstall information if installed *without* admin rights:
76  key.SetName(_T("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\lcc-win32 (base system)_is1"));
77  if (key.Exists() && key.Open(wxRegKey::Read))
78  key.QueryValue(_T("Inno Setup: App Path"), mpHKCU);
79 
80  // Check the LCC lccroot path
81  key.SetName(_T("HKEY_CURRENT_USER\\Software\\lcc"));
82  if (key.Exists() && key.Open(wxRegKey::Read))
83  key.QueryValue(_T("lccroot"), mpLccRoot);
84  if (mpLccRoot.IsEmpty())
85  {
86  // Check the LCC lccroot path
87  key.SetName(_T("HKEY_CURRENT_USER\\Software\\lcc\\lccroot"));
88  if (key.Exists() && key.Open(wxRegKey::Read))
89  key.QueryValue(_T("path"), mpLccRoot);
90  }
91 
92  // Check the LCC lcclnk path
93  key.SetName(_T("HKEY_CURRENT_USER\\Software\\lcc\\lcclnk"));
94  if (key.Exists() && key.Open(wxRegKey::Read))
95  {
96  key.QueryValue(_T("libpath"), mpLccLnk);
97  wxString lib_path = _T("\\lib");
98  if ( !mpLccLnk.IsEmpty()
99  && (mpLccLnk.Length()>lib_path.Length())
100  && (mpLccLnk.Lower().EndsWith(lib_path)) )
101  {
102  // Remove the lib path to point to the LCC root folder
103  mpLccLnk.Remove( (mpLccLnk.Length()-lib_path.Length()), lib_path.Length() );
104  }
105  }
106 
107  // Check the LCC compiler path
108  key.SetName(_T("HKEY_CURRENT_USER\\Software\\lcc\\compiler"));
109  if (key.Exists() && key.Open(wxRegKey::Read))
110  {
111  key.QueryValue(_T("includepath"), mpCompiler);
112  wxString inc_path = _T("\\include");
113  if ( !mpCompiler.IsEmpty()
114  && (mpCompiler.Length()>inc_path.Length())
115  && (mpCompiler.Lower().EndsWith(inc_path)) )
116  {
117  // Remove the include path to point to the LCC root folder
118  mpCompiler.Remove( (mpCompiler.Length()-inc_path.Length()), inc_path.Length() );
119  }
120  }
121 
122  // Verify all path's obtained
123  if (wxFileExists(mpHKLM + compiler))
124  m_MasterPath = mpHKLM;
125  else if (wxFileExists(mpHKCU + compiler))
126  m_MasterPath = mpHKCU;
127  else if (wxFileExists(mpLccRoot + compiler))
128  m_MasterPath = mpLccRoot;
129  else if (wxFileExists(mpLccLnk + compiler))
130  m_MasterPath = mpLccLnk;
131  else if (wxFileExists(mpCompiler + compiler))
132  m_MasterPath = mpCompiler;
133  else
134 #endif // __WXMSW__
135  m_MasterPath = _T("C:\\lcc"); // just a guess; the default installation dir
136 
137  if (!m_MasterPath.IsEmpty())
138  {
139  AddIncludeDir (m_MasterPath + wxFILE_SEP_PATH + _T("include"));
140  AddLibDir (m_MasterPath + wxFILE_SEP_PATH + _T("lib"));
141  m_ExtraPaths.Add(m_MasterPath + wxFILE_SEP_PATH + _T("bin"));
142  }
143 
144  m_RegistryUpdated = false; // Check the registry another time on IsValid()
145 
146  return wxFileExists(m_MasterPath+compiler) ? adrDetected : adrGuessed;
147 }
148 
149 #ifdef __WXMSW__
151 {
152  if (!m_RegistryUpdated)
153  {
154  wxString compiler = m_MasterPath + wxFILE_SEP_PATH
155  + _T("bin") + wxFILE_SEP_PATH + m_Programs.C;
156 
157  if (wxFileExists(compiler))
158  {
159  Manager::Get()->GetLogManager()->DebugLog(_T("LCC: Updating registry..."));
160 
161  // Make sure the registry is setup as it should be after an installation.
162  // This avoids the "smart and clever" LCC compiler asking for the
163  // <include> header and lcc libraries path's on the command line (huh?!).
164  // Note: A compiler *never ever* should ask on std::cin anything!!!
165  wxRegKey key; // defaults to HKCR
166 
167  key.SetName(_T("HKEY_CURRENT_USER\\Software\\lcc"));
168  if (!key.Exists() && key.Create())
169  key.SetValue(_T("lccroot"), m_MasterPath );
170 
171  key.SetName(_T("HKEY_CURRENT_USER\\Software\\lcc\\compiler"));
172  if (!key.Exists() && key.Create())
173  key.SetValue(_T("includepath"), m_MasterPath+_T("\\include") );
174 
175  key.SetName(_T("HKEY_CURRENT_USER\\Software\\lcc\\lcclnk"));
176  if (!key.Exists() && key.Create())
177  key.SetValue(_T("libpath"), m_MasterPath+_T("\\lib") );
178 
179  key.SetName(_T("HKEY_CURRENT_USER\\Software\\lcc\\lccroot"));
180  if (!key.Exists() && key.Create())
181  key.SetValue(_T("path"), m_MasterPath );
182 
183  m_RegistryUpdated = true;
184  }
185  }
186 
187  return Compiler::IsValid();
188 }
189 #endif // __WXMSW__
wxArrayString m_LinkLibs
wxArrayString m_CmdsBefore
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
Definition: manager.cpp:182
wxString Lower() const
bool wxFileExists(const wxString &filename)
virtual void Reset()
Reset settings to defaults.
Definition: compilerLCC.cpp:42
size_t Length() const
#define _T(string)
virtual void AddIncludeDir(const wxString &option)
bool QueryValue(const wxString &szValue, wxString &strValue, bool raw) const
bool m_RegistryUpdated
Definition: compilerLCC.h:19
bool SetValue(const wxString &szValue, long lValue)
CompilerPrograms m_Programs
Definition: compiler.h:412
wxString & Remove(size_t pos)
AutoDetectResult
Definition: compiler.h:190
wxArrayString m_CompilerOptions
const wxString & GetID() const
Get this compiler&#39;s unique ID.
Definition: compiler.h:351
virtual bool IsValid()
Check if the compiler is actually valid (installed).
Definition: compiler.cpp:190
virtual void AddLibDir(const wxString &option)
wxArrayString m_LinkerOptions
LogManager * GetLogManager() const
Definition: manager.cpp:439
wxArrayString m_ExtraPaths
Definition: compiler.h:410
virtual bool IsValid()
Check if the compiler is actually valid (installed).
wxString wxEmptyString
virtual void LoadDefaultRegExArray(bool globalPrecedence=false)
Load the default (preset) array of regexes used in errors/warnings recognition.
Definition: compiler.cpp:183
const wxString & _(const wxString &string)
CompilerOptions m_Options
Definition: compiler.h:414
virtual AutoDetectResult AutoDetectInstallationDir()
Try to auto-detect the compiler&#39;s installation directory.
Definition: compilerLCC.cpp:58
Abstract base class for compilers.
Definition: compiler.h:274
virtual ~CompilerLCC()
Definition: compilerLCC.cpp:32
virtual Compiler * CreateCopy()
Implement this in new compilers, to return a new copy.
Definition: compilerLCC.cpp:37
bool IsEmpty() const
void LoadDefaultOptions(const wxString &name, int recursion=0)
Definition: compiler.cpp:809
wxString C
Definition: compiler.h:199
void DebugLog(const wxString &msg, Logger::level lv=Logger::info)
Definition: logmanager.h:146
bool EndsWith(const wxString &suffix, wxString *rest=NULL) const
wxString m_MasterPath
Definition: compiler.h:409
bool Exists() const
bool Create(bool bOkIfExists=true)
size_t Add(const wxString &str, size_t copies=1)
bool Open(AccessMode mode=Write)
wxArrayString m_CmdsAfter
int m_Weight
Definition: compiler.h:422
void SetName(const wxString &strKey)