If the masterpath is already set and the code calls CompilerXML::AutoDetectInstallationDir() then the code goes through a bunch of checks and ends up with the following check:
if ( wxFileExists(m_MasterPath + wxFILE_SEP_PATH + wxT("bin") + wxFILE_SEP_PATH + m_Programs.C)
|| wxFileExists(m_MasterPath + wxFILE_SEP_PATH + m_Programs.C)
|| (GetID() == wxT("null")) ) // Special case so "No Compiler" is valid
{
return adrDetected;
}
This check is not performed in entry to the function, but the following block is executed after the variables are setup/configured
if (!m_MasterPath.IsEmpty())
{
path += wxPATH_SEP + m_MasterPath;
wxSetEnv(wxT("PATH"), path);
m_MasterPath.Clear();
}
The block above (if (!m_MasterPath.IsEmpty())) has two potential issues:
- It adds the m_MasterPath to the end of the path. I thought it would be better to add it to the front. Have I missed something?
- The 'return adrDetected;" block could be added into the first code block above (removing the GetID()..) as follows so the detection is quicker. Again have I missed something?
The final code would look like the following:
if (!m_MasterPath.IsEmpty()) { if (wxFileExists(m_MasterPath + wxFILE_SEP_PATH + wxT("bin") + wxFILE_SEP_PATH + m_Programs.C) || wxFileExists(m_MasterPath + wxFILE_SEP_PATH + m_Programs.C)) {
return adrDetected;
}
path = m_MasterPath + wxPATH_SEP + path;
wxSetEnv(wxT("PATH"), path);
m_MasterPath.Clear();
}