PATCH: fix C::B 8.02 failed to import single configration project(VC6)

pluginsprojectsimportermsvcloader.cpp
bool MSVCLoader::ReadConfigurations()
{
    m_Configurations.Clear();
    m_ConfigurationsLineIndex.Clear();
    m_BeginTargetLine = -1;
    wxFileInputStream file(m_Filename.GetFullPath());
    if (!file.Ok())
        return false; // error opening file???
    wxArrayString comps;
    wxTextInputStream input(file);
    //** use for record someinfo
    wxString defaultconfigration;
    int firstconfigline=0;

    int currentLine = 0;
    while (!file.Eof())
    {
        wxString line = input.ReadLine();
        ++currentLine;
        line.Trim(true);
        line.Trim(false);
        int size = -1;
        if (line.StartsWith(_T("# TARGTYPE")))
        {
            // # TARGTYPE "Win32 (x86) Application" 0x0103
            int idx = line.Find(‘ ‘, true);
            if (idx != -1)
            {
                TargetType type;
                wxString targtype = line.Mid(12, idx-1-12);
                wxString projcode = line.Mid(idx+3, 4);
                if      (projcode.Matches(_T("0101"))) type = ttExecutable;
                else if (projcode.Matches(_T("0102"))) type = ttDynamicLib;
                else if (projcode.Matches(_T("0103"))) type = ttConsoleOnly;
                else if (projcode.Matches(_T("0104"))) type = ttStaticLib;
                else if (projcode.Matches(_T("010a"))) type = ttCommandsOnly;
                else
                {
                    type = ttCommandsOnly;
                    Manager::Get()->GetLogManager()->DebugLog(_T("unrecognized target type"));
                }
                //Manager::Get()->GetLogManager()->DebugLog(_T("TargType ‘%s’ is %d"), targtype.c_str(), type);
                m_TargType[targtype] = type;
            }
            continue;
        }
        else if (line.StartsWith(_T("!MESSAGE "")))
        {
            //  !MESSAGE "anothertest – Win32 Release" (based on "Win32 (x86) Application")
            int pos;
            pos = line.Find(‘"’);
            line = line.Mid(pos + 1);
            pos = line.Find(‘"’);
            wxArrayString projectTarget = GetArrayFromString(line.Left(pos), _T("-"));
            wxString target = projectTarget[1];
            if (projectTarget.GetCount() != 2)
            {
                Manager::Get()->GetLogManager()->DebugLog(_T("ERROR: bad target format"));
                return false;
            }
            line = line.Mid(pos + 1);
            pos = line.Find(‘"’);
            line = line.Mid(pos + 1);
            pos = line.Find(‘"’);
            wxString basedon = line.Left(pos);
            TargetType type = ttCommandsOnly;
            HashTargetType::iterator it = m_TargType.find(basedon);
            if (it != m_TargType.end())
                type = it->second;
            else
            {
                Manager::Get()->GetLogManager()->DebugLog(_T("ERROR: target type not found"));
                return false;
            }
            m_TargetBasedOn[target] = type;
            //Manager::Get()->GetLogManager()->DebugLog(_T("Target ‘%s’ type %d"), target.c_str(), type);
        }
        else if (line.StartsWith(_T("!IF  "$(CFG)" ==")))
            size = 16;
        else if (line.StartsWith(_T("!ELSEIF  "$(CFG)" ==")))
            size = 20;
        //**patch for single configration project file
       else if (line.StartsWith(_T("CFG=")))
        {
            // read configuration name
            line = line.Mid(4);
            line.Trim(true);
            line.Trim(false);
            defaultconfigration = line;
            int idx = defaultconfigration.Find(‘-‘);
            if (idx != -1)
            {
                defaultconfigration = defaultconfigration.Mid(idx + 1);
                defaultconfigration.Trim(false);
            }


        }
        //**record only once
        else if (firstconfigline==0 && line.StartsWith(_T("# PROP BASE")))
        {
            firstconfigline=currentLine;
        }

        else if (line == _T("# Begin Target"))
        {
            // done
            m_BeginTargetLine = currentLine;
            break;
        }
        if (size != -1)
        {
            // read configuration name
            line = line.Mid(size);
            line.Trim(true);
            line.Trim(false);
            wxString tmp = RemoveQuotes(line);
            // remove the project name part, i.e "anothertest – "
            int idx = tmp.Find(‘-‘);
            if (idx != -1)
            {
                tmp = tmp.Mid(idx + 1);
                tmp.Trim(false);
            }
            if (m_Configurations.Index(tmp) == wxNOT_FOUND)
            {
                m_Configurations.Add(tmp);
                m_ConfigurationsLineIndex.Add(currentLine);
                Manager::Get()->GetLogManager()->DebugLog(F(_T("Detected configuration ‘%s’ at line %d"), tmp.c_str(), currentLine));
            }
        }
    }
    //**test if failed to add configration
    if(0==m_Configurations.GetCount() && firstconfigline>0 && !defaultconfigration.IsEmpty())
    {
        if (m_Configurations.Index(defaultconfigration) == wxNOT_FOUND)
        {
            m_Configurations.Add(defaultconfigration);
            m_ConfigurationsLineIndex.Add(firstconfigline);
            Manager::Get()->GetLogManager()->DebugLog(F(_T("Detected configuration ‘%s’ at line %d"), defaultconfigration.c_str(), firstconfigline));
        }
    }

    return true;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s