#include "stdafx.h"
#include "resource.h"

namespace PMConst
{
    // 패치 타입
    LPCTSTR PatchType        = _T("PATCH_TYPE");

    CString PatchType_Part1;
    CString PatchType_BattleLohan;
    CString PatchType_Part2;
    CString PatchType_Part2Test;
    CString PatchType_Part2Malay;

    // 자동패치
    LPCTSTR AP_OldPkg        = _T("AP_OLD_PKG");
    LPCTSTR AP_NewClient     = _T("AP_NEW_CLIENT");
    LPCTSTR AP_NewPkg        = _T("AP_NEW_PKG");
    LPCTSTR AP_MaxPkg        = _T("AP_MAX_PKG");
    LPCTSTR AP_FTPAddr       = _T("AP_FTP_ADDR");
    LPCTSTR AP_FTPPort       = _T("AP_FTP_PORT");
    LPCTSTR AP_FTPPassive    = _T("AP_IS_PASSIVE");
    LPCTSTR AP_PkgPosType    = _T("AP_PKG_POS_TYPE");

    UINT AP_SETTING_ENABLE   = RegisterWindowMessage(_T("AP_SETTING_ENABLE"));  // 세팅을 바꿀 수 있게 하는 메시지 ID
    UINT AP_SETTING_DISABLE  = RegisterWindowMessage(_T("AP_SETTING_DISABLE")); // 세팅을 바꿀 수 없게 하는 메시지 ID

    // 수동패치
    LPCTSTR MP_Folder        = _T("MP_FOLDER");
    LPCTSTR MP_SFXFile       = _T("MP_SFX_FILENAME");
    LPCTSTR MP_MinVer        = _T("MP_MINVER");

    UINT MP_SETTING_ENABLE   = RegisterWindowMessage(_T("MP_SETTING_ENABLE"));  // 세팅을 바꿀 수 있게 하는 메시지 ID
    UINT MP_SETTING_DISABLE  = RegisterWindowMessage(_T("MP_SETTING_DISABLE")); // 세팅을 바꿀 수 없게 하는 메시지 ID

    // 타이머 ID
    UINT AP_PROGRESS_TIMER_ID = 1;
    UINT MP_PROGRESS_TIMER_ID = 2;

    // 프로그리스 바 갱신 시간
    DWORD PROGRESS_TIMER_UPDATE_TIME = 200;

    void InitializeStrings()
    {
        PatchType_Part1.LoadString(IDS_CB_PART1);
        PatchType_BattleLohan.LoadString(IDS_CB_BATTLELOHAN_P1);
        PatchType_Part2.LoadString(IDS_CB_PART2);
        PatchType_Part2Test.LoadString(IDS_CB_PART2_TEST);
        PatchType_Part2Malay.LoadString(IDS_CB_PART2_MALAY);
    }

    void AdjustVersionInfoByPatchType(LPCTSTR szPatchType, DWORD& dwMinver, DWORD dwMaxver)
    {
        if (0 == PatchType_Part1.CompareNoCase(szPatchType) ||
            0 == PatchType_BattleLohan.CompareNoCase(szPatchType))
        {
            if (100 <= dwMinver) { dwMinver -= 100; }
            if (100 <= dwMaxver) { dwMaxver -= 100; }
        }
    }

    bool GetRYLInstalledRegKey(LPCTSTR szPatchType, CString& szInstalledRegKey, CString& szValueName)
    {
        static CString szFolderP1((LPCTSTR)IDS_FOLDER_P1);
        static CString szFolderBattle((LPCTSTR)IDS_FOLDER_BATTLELOHAN);
        static CString szFolderP2((LPCTSTR)IDS_FOLDER_P2);
        static CString szFolderP2Test((LPCTSTR)IDS_FOLDER_P2_TEST);
        
        szInstalledRegKey.Empty();
        szInstalledRegKey.LoadString(IDS_INSTALLED_REGKEY);

        if (0 == PatchType_Part1.CompareNoCase(szPatchType))            { szValueName.SetString(szFolderP1);      }
        else if (0 == PatchType_BattleLohan.CompareNoCase(szPatchType)) { szValueName.SetString(szFolderBattle);  }
        else if (0 == PatchType_Part2.CompareNoCase(szPatchType))       { szValueName.SetString(szFolderP2);      }
        else if (0 == PatchType_Part2Test.CompareNoCase(szPatchType))   { szValueName.SetString(szFolderP2Test);  }
        else if (0 == PatchType_Part2Malay.CompareNoCase(szPatchType))  
        {
            szInstalledRegKey.LoadString(IDS_INSTALLED_REGKEY_MALAY);
            szValueName.SetString(szFolderP2); 
        }
        else 
        {
            // 맞는 패치 타입이 없다.
            return false;
        }

        return true;
    }
}
