#include "stdafx.h"
#include "resource.h"
#include "DnsDbgLauncher.h"
#include "StartProcCmdLineInfo.h"
#include "Trace.h"
#include "StartProcCmdLineInfo.tmh"


CStartProcCmdLineInfo::CStartProcCmdLineInfo()
{
}


CStartProcCmdLineInfo::~CStartProcCmdLineInfo()
{
}


void CStartProcCmdLineInfo::ParseParam(
    const TCHAR* pszParam,
    BOOL bFlag,
    BOOL bLast
    )
{
    CString sParam(pszParam);
    wchar_t *pEndPoint;
    TraceEvents(
        TRACE_LEVEL_INFORMATION,
        TRACE_STARTPROCCMDLINEINFO,
        "%!FUNC! line:%!LINE! %!LEVEL! Enter"
        );
    TraceEvents(
        TRACE_LEVEL_INFORMATION,
        TRACE_STARTPROCCMDLINEINFO,
        "%!FUNC! line:%!LINE! %!LEVEL!    pszParam = \"%ws\"",
        pszParam
        );
    TraceEvents(
        TRACE_LEVEL_INFORMATION,
        TRACE_STARTPROCCMDLINEINFO,
        "%!FUNC! line:%!LINE! %!LEVEL!    bFlag = %!bool!",
        bFlag
        );
    TraceEvents(
        TRACE_LEVEL_INFORMATION,
        TRACE_STARTPROCCMDLINEINFO,
        "%!FUNC! line:%!LINE! %!LEVEL!    bLast = %!bool!",
        bLast
        );
    if (!theApp.m_bRestart)
    {
        theApp.m_bRestart = (sParam == L"rs") && bFlag && (!bLast);
    }
    if (!theApp.m_bRestart)
    {
        if ((!bFlag) && bLast)
        {
            theApp.m_sDebuggedFileName = pszParam;
            TraceEvents(
                TRACE_LEVEL_INFORMATION,
                TRACE_STARTPROCCMDLINEINFO,
                "%!FUNC! line:%!LINE! %!LEVEL! Exit"
                );
            return;
        }
        theApp.m_bCmdLineError = true;
        TraceEvents(
            TRACE_LEVEL_ERROR,
            TRACE_STARTPROCCMDLINEINFO,
            "%!FUNC! line:%!LINE! %!LEVEL! Exit with parse error"
            );
        return;
    }
    if (theApp.m_bRestart && (!bLast))
    {
        TraceEvents(
            TRACE_LEVEL_INFORMATION,
            TRACE_STARTPROCCMDLINEINFO,
            "%!FUNC! line:%!LINE! %!LEVEL! Exit"
            );
        return;
    }
    if (bFlag || (!bLast))
    {
        theApp.m_bCmdLineError = true;
        TraceEvents(
            TRACE_LEVEL_ERROR,
            TRACE_STARTPROCCMDLINEINFO,
            "%!FUNC! line:%!LINE! %!LEVEL! Exit with parse error"
            );
        return;
    }
    theApp.m_dwLauncherId = wcstoul(
        pszParam,
        &pEndPoint,
        10
        );
    TraceEvents(
        TRACE_LEVEL_INFORMATION,
        TRACE_STARTPROCCMDLINEINFO,
        "%!FUNC! line:%!LINE! %!LEVEL! Exit"
        );
}
