#include "stdafx.h" #include "PatcherApp.h" #include "PatcherDlg.h" #include "FileSystem.h" #include "HttpDownloader.h" #define PATCHER_MUTEX "IrisPatcher Mutex" cPatcherApp theApp; cPatcherApp::cPatcherApp() { mMutex = 0; mSkinManager = 0; /// ÆÄÀÏ ½Ã½ºÅÛ »ý¼º new cFileSystem; } cPatcherApp::~cPatcherApp() { if( mSkinManager ) { delete mSkinManager; mSkinManager = 0; } delete FILESYSTEM; if( mMutex ) ::CloseHandle( mMutex ); } BOOL cPatcherApp::InitInstance() { CWinApp::InitInstance(); /// ÇÁ·Î±×·¥ Áߺ¹ ½ÇÇà ¹æÁö if( CheckMutex() == false ) { MessageBox( 0, "ERROR(01) : Patcher is already running", PATCHER, MB_OK ); return FALSE; } eCLIENT_EXECUTE_MODE executeMode = eCLIENT_EXECUTE_IDC; /// CmdLine : [client½ÇÇà¸ðµå_ÀÎÁõÄÚµå] char* tMode = NULL; char* tAuthCode = NULL; cString authCode; tMode = strtok( m_lpCmdLine, " " ); if( !tMode ) { MessageBox( 0, "ERROR(02) : This program must be executed by Launcher", PATCHER, MB_OK ); return FALSE; } tAuthCode = strtok( NULL, " " ); #if defined( _DEVSYS ) // ÀÎÁõÄڵ尡 ¾ø°Å³ª irisLauncher_DEV.exe¸¦ ÅëÇØ ½ÇÇàµÈ °ÍÀÌ ¾Æ´Ï¸é, ȨÆäÀÌÁö open //if( !tAuthCode || strcmp(tAuthCode, "-2") != 0 ) //{ // ShellExecute( 0, 0, "Iexplore.exe", WEB_LAUNCHER_URL, 0, SW_SHOWNORMAL ); // return FALSE; //} if( ::stricmp(tMode, "-dkdlfltmeoqkr" ) == 0 ) executeMode = eCLIENT_EXECUTE_IDC; else if( ::stricmp(tMode, "-dkdlfltmeoqkr-DEV" ) == 0 ) executeMode = eCLIENT_EXECUTE_DEV; else if( ::stricmp(tMode, "-dkdlfltmeoqkr-TEST" ) == 0 ) executeMode = eCLIENT_EXECUTE_TEST; else if( ::stricmp(tMode, "-dkdlfltmeoqkrGM-IDC" ) == 0 ) executeMode = eCLIENT_EXECUTE_GMTOOL_IDC; else if( ::stricmp(tMode, "-dkdlfltmeoqkrGM-DEV" ) == 0 ) executeMode = eCLIENT_EXECUTE_GMTOOL_DEV; else if( ::stricmp(tMode, "-dkdlfltmeoqkrGM-TEST" ) == 0 ) executeMode = eCLIENT_EXECUTE_GMTOOL_TEST; else { MessageBox( 0, "ERROR(02) : This program must be executed by Launcher", PATCHER, MB_OK ); return 0; } #elif defined( _TEST_SRV ) if( ::stricmp(tMode, "-dkdlfltmeoqkr-TEST" ) == 0 ) executeMode = eCLIENT_EXECUTE_TEST; else if( ::stricmp(tMode, "-dkdlfltmeoqkrGM-TEST" ) == 0 ) executeMode = eCLIENT_EXECUTE_GMTOOL_TEST; else { MessageBox( 0, "ERROR(02) : This program must be executed by Launcher", PATCHER, MB_OK ); return 0; } // ÀÎÁõÄڵ尡 ¾øÀ¸¸é, ȨÆäÀÌÁö open //if( !tAuthCode ) //{ // ShellExecute( 0, 0, "Iexplore.exe", WEB_LAUNCHER_URL, 0, SW_SHOWNORMAL ); // return FALSE; //} #else if( ::stricmp(tMode, "-dkdlfltmeoqkr" ) == 0 ) executeMode = eCLIENT_EXECUTE_IDC; else if( ::stricmp(tMode, "-dkdlfltmeoqkrGM-IDC" ) == 0 ) executeMode = eCLIENT_EXECUTE_GMTOOL_IDC; else { MessageBox( 0, "ERROR(02) : This program must be executed by Launcher", PATCHER, MB_OK ); return 0; } // ÀÎÁõÄڵ尡 ¾øÀ¸¸é, ȨÆäÀÌÁö open //if( !tAuthCode ) //{ // ShellExecute( 0, 0, "Iexplore.exe", WEB_LAUNCHER_URL, 0, SW_SHOWNORMAL ); // return FALSE; //} #endif authCode.Format( "%s", tAuthCode ); /// Initialize COM Library - INTERNET API(wininet.h/wininet.lib)¸¦ »ç¿ëÇϱâ À§ÇØ if( CoInitialize( 0 ) != S_OK ) { MessageBox( 0, "CoInitialize Failed!", PATCHER, MB_OK ); return 0; } /// ½ºÅ² Á¤º¸ ·Îµù if( LoadSkin() == false ) { MessageBox( 0, "Failed to load skin info.", PATCHER, MB_OK ); return FALSE; } /// ´ÙÀ̾ó·Î±× ¶ç¿ò cPatcherDlg dlg( mPath, authCode ); m_pMainWnd = &dlg; dlg.SetExecuteGM( executeMode ); dlg.DoModal( mSkinManager->GetContainer( "main" ) ); return TRUE; } int cPatcherApp::ExitInstance() { CoUninitialize(); return 0; } bool cPatcherApp::CheckMutex() { /// ¹ÂÅØ½º »ý¼º HANDLE mutex = ::CreateMutex( 0, TRUE, PATCHER_MUTEX ); /// ¹ÂÅØ½º°¡ ÀÌ¹Ì Á¸ÀçÇÏ´ÂÁö °Ë»ç bool alreadyExist = false; if( ::GetLastError() == ERROR_ALREADY_EXISTS ) alreadyExist = true; mUsageCnt++; if( mUsageCnt > 1 ) alreadyExist = true; if( ::FindWindow( NULL, "IrisPatcher" ) ) alreadyExist = true; if( alreadyExist == false ) mMutex = mutex; else if( mutex ) ::ReleaseMutex( mutex ); return !alreadyExist; } bool cPatcherApp::LoadSkin() { /// °æ·Î ¼³Á¤ mPath.Format( "Launcher/japan/" ); if( ::FileExist( mPath ) == false ) { MessageBox( 0, "Failed to access local path", PATCHER, MB_OK ); return false; } /// ½ºÅ² °ü¸®ÀÚ »ý¼º mSkinManager = new cSkinManager( mPath ); /// ½ºÅ² ¸®¼Ò½º ·Îµù return mSkinManager->Load( mPath + SKNINFO_FILENAME ); }