Code::Blocks  SVN r11506
compilerGDC.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: compilerGDC.cpp 8649 2012-12-12 19:18:18Z mortenmacfly $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/compilergcc/compilerGDC.cpp $
8  */
9 
10 #include <sdk.h>
11 #include <prep.h>
12 #include "compilerGDC.h"
13 #include <wx/intl.h>
14 #include <wx/regex.h>
15 #include <wx/config.h>
16 #include <wx/fileconf.h>
17 #include <wx/msgdlg.h>
18 #include "manager.h"
19 #include "logmanager.h"
20 
21 #include <configmanager.h>
22 
23 #ifdef __WXMSW__
24  #include <wx/msw/registry.h>
25 #endif
26 
28  : Compiler(_("GDC D Compiler"), _T("gdc"))
29 {
30  m_Weight = 76;
31  Reset();
32 }
33 
35 {
36  //dtor
37 }
38 
40 {
41  return (new CompilerGDC(*this));
42 }
43 
45 {
47  if (platform::windows)
48  {
49  // look first if MinGW was installed with Code::Blocks (new in beta6)
51  if (!wxFileExists(m_MasterPath + sep + _T("bin") + sep + m_Programs.C))
52  {
53  // no... search for MinGW installation dir
54  wxString windir = wxGetOSDirectory();
55  wxFileConfig ini(_T(""), _T(""), windir + _T("/MinGW.ini"), _T(""), wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_NO_ESCAPE_CHARACTERS);
56  m_MasterPath = ini.Read(_T("/InstallSettings/InstallPath"), _T("C:\\MinGW"));
57  if (!wxFileExists(m_MasterPath + sep + _T("bin") + sep + m_Programs.C))
58  {
59 #ifdef __WXMSW__ // for wxRegKey
60  // not found...
61  // look for dev-cpp installation
62  wxRegKey key; // defaults to HKCR
63  key.SetName(_T("HKEY_LOCAL_MACHINE\\Software\\Dev-C++"));
64  if (key.Exists() && key.Open(wxRegKey::Read)) {
65  // found; read it
66  key.QueryValue(_T("Install_Dir"), m_MasterPath);
67  }
68  else {
69  // installed by inno-setup
70  // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Minimalist GNU for Windows 4.1_is1
71  wxString name;
72  long index;
73  key.SetName(_T("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"));
74  //key.SetName("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion");
75  bool ok = key.GetFirstKey(name, index);
76  while (ok && !name.StartsWith(_T("Minimalist GNU for Windows"))) {
77  ok = key.GetNextKey(name, index);
78  }
79  if (ok) {
80  name = key.GetName() + _T("\\") + name;
81  key.SetName(name);
82  Manager::Get()->GetLogManager()->DebugLog(F(_T("name: %s"), name.wx_str()));
83  if (key.Exists()) key.QueryValue(_T("InstallLocation"), m_MasterPath);
84  }
85  }
86 #endif
87  }
88  }
89  else
90  m_Programs.MAKE = _T("make.exe"); // we distribute "make" not "mingw32-make"
91  }
92  else
93  m_MasterPath = _T("/usr");
94 
96  if (ret == adrDetected)
97  {
98  AddIncludeDir(m_MasterPath + sep + _T("include") + sep + _T("d"));
99  AddLibDir(m_MasterPath + sep + _T("lib"));
100  }
101  return ret;
102 }
wxString F(const wxChar *msg,...)
sprintf-like function
Definition: logmanager.h:20
wxString GetName(bool bShortPrefix=true) const
virtual Compiler * CreateCopy()
Implement this in new compilers, to return a new copy.
Definition: compilerGDC.cpp:39
bool Read(const wxString &key, wxString *str) const
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
virtual ~CompilerGDC()
Definition: compilerGDC.cpp:34
bool wxFileExists(const wxString &filename)
bool GetFirstKey(wxString &strKeyName, long &lIndex)
virtual void Reset()
Reset settings to defaults.
Definition: compiler.cpp:157
#define _T(string)
virtual void AddIncludeDir(const wxString &option)
bool QueryValue(const wxString &szValue, wxString &strValue, bool raw) const
CompilerPrograms m_Programs
Definition: compiler.h:412
AutoDetectResult
Definition: compiler.h:190
virtual void AddLibDir(const wxString &option)
wxString MAKE
Definition: compiler.h:204
static const wxString sep
LogManager * GetLogManager() const
Definition: manager.cpp:439
static wxUniChar GetPathSeparator(wxPathFormat format=wxPATH_NATIVE)
const wxStringCharType * wx_str() const
wxString wxGetOSDirectory()
const wxString & _(const wxString &string)
Abstract base class for compilers.
Definition: compiler.h:274
virtual AutoDetectResult AutoDetectInstallationDir()
Try to auto-detect the compiler&#39;s installation directory.
Definition: compilerGDC.cpp:44
wxString C
Definition: compiler.h:199
static wxString GetExecutableFolder()
void DebugLog(const wxString &msg, Logger::level lv=Logger::info)
Definition: logmanager.h:146
bool GetNextKey(wxString &strKeyName, long &lIndex) const
wxString m_MasterPath
Definition: compiler.h:409
bool Exists() const
bool StartsWith(const wxString &prefix, wxString *rest=NULL) const
bool Open(AccessMode mode=Write)
int m_Weight
Definition: compiler.h:422
void SetName(const wxString &strKey)