Code::Blocks  SVN r11506
compilerCYGWIN.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: compilerCYGWIN.cpp 8649 2012-12-12 19:18:18Z mortenmacfly $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/compilergcc/compilerCYGWIN.cpp $
8  */
9 
10 #include "compilerCYGWIN.h"
11 #include <wx/filefn.h>
12 #ifdef __WXMSW__
13  #include <wx/msw/registry.h>
14 #endif // __WXMSW__
15 
17  : CompilerMINGW(_("Cygwin GCC"), _T("cygwin"))
18 {
19  m_Weight = 32;
20  Reset();
21 }
22 
24 {
25 }
26 
28 {
29  return (new CompilerCYGWIN(*this));
30 }
31 
33 {
35  m_MasterPath = _T("C:\\Cygwin"); // just a guess
36  wxString tempMasterPath(m_MasterPath);
37  bool validInstallationDir = false;
38 
39  // look in registry for Cygwin
40 
41 #ifdef __WXMSW__
42  wxRegKey key; // defaults to HKCR
43  key.SetName(_T("HKEY_LOCAL_MACHINE\\Software\\Cygwin\\setup"));
44  if (key.Exists() && key.Open(wxRegKey::Read))
45  {
46  // found CygWin version 1.7 or newer; read it
47  key.QueryValue(_T("rootdir"), tempMasterPath);
48  if (wxDirExists(tempMasterPath + wxFILE_SEP_PATH + _T("bin")))
49  validInstallationDir = true;
50  }
51  if (!validInstallationDir)
52  {
53  key.SetName(_T("HKEY_LOCAL_MACHINE\\Software\\Cygnus Solutions\\Cygwin\\mounts v2\\/"));
54  if (key.Exists() && key.Open(wxRegKey::Read))
55  {
56  // found CygWin version 1.5 or older; read it
57  key.QueryValue(_T("native"), tempMasterPath);
58  if ( wxDirExists(tempMasterPath + wxFILE_SEP_PATH + _T("bin")) )
59  validInstallationDir = true;
60  }
61  }
62 #endif // __WXMSW__
63 
64  if (!validInstallationDir)
65  return ret;
66 
67  wxString cProgramDir = tempMasterPath + wxFILE_SEP_PATH + _T("bin") + wxFILE_SEP_PATH;
68  wxString cProgramFullname = cProgramDir + m_Programs.C;
69  if ( !wxFileExists(cProgramFullname) )
70  return ret;
71 
72  wxFile pfFile(cProgramFullname);
73  if ( !pfFile.IsOpened() )
74  return ret;
75 
76  char buffer[10] = {0};
77  pfFile.Read(buffer,10);
78  if (memcmp("!<symlink>", buffer, 10) != 0)
79  {
80  m_MasterPath = tempMasterPath;
81  ret = adrDetected;
82  }
83 
84  return ret;
85 }
bool wxFileExists(const wxString &filename)
bool wxDirExists(const wxString &dirname)
virtual void Reset()
Reset settings to defaults.
Definition: compiler.cpp:157
#define _T(string)
bool QueryValue(const wxString &szValue, wxString &strValue, bool raw) const
CompilerPrograms m_Programs
Definition: compiler.h:412
AutoDetectResult
Definition: compiler.h:190
virtual AutoDetectResult AutoDetectInstallationDir()
Try to auto-detect the compiler&#39;s installation directory.
virtual Compiler * CreateCopy()
Implement this in new compilers, to return a new copy.
bool IsOpened() const
const wxString & _(const wxString &string)
ssize_t Read(void *buffer, size_t count)
Abstract base class for compilers.
Definition: compiler.h:274
wxString C
Definition: compiler.h:199
wxString m_MasterPath
Definition: compiler.h:409
bool Exists() const
bool Open(AccessMode mode=Write)
int m_Weight
Definition: compiler.h:422
void SetName(const wxString &strKey)