#include "StdAfx.h" #include "updatemanager.h" //#include "../RarLib/Rar.h" //#include "RYLLoginDlg.h" #include "../GlobalScript/Utility/CheckSum/Crc32Static.h" #include "RYLLOGIN_DEFINITIONS.H" #include "ZipArchive.h" #include "Patch_Util.h" //DWORD *CUpdateManager::m_dwZipTotalCount = NULL; //DWORD *CUpdateManager::m_dwZipNowCount = NULL; CGradientStatic *CUpdateManager::m_pInfoWnd = NULL; CWnd *CUpdateManager::m_pDisplayWnd = NULL; BOOL CUpdateManager::m_bUpdateLogin = FALSE; CUpdateManager::CUpdateManager(void) { m_bServerClosed = false; m_pDisplayState = NULL; m_nVersion = -1; m_bUpdateLogin = FALSE; m_pfProgressPercentage = NULL; m_pfFileProgressPercentage = NULL; m_bTerminate = false; } CUpdateManager::~CUpdateManager(void) { } void CUpdateManager::Init() { m_HTTPFile.Init(); // °­Á¦Á¾·á Ç÷¡±× m_bTerminate = false; } //bool IsDirectoryExist( const char* szDirectoryName ) //{ // DWORD dwAttr = ::GetFileAttributes( szDirectoryName ); // // // if( dwAttr == 0xFFFFFFFF ) // return false; // file not exists ? // // if( dwAttr & FILE_ATTRIBUTE_DIRECTORY ) // return true; // // return false; // exists but not a directory //} bool CUpdateManager::ProcessNoticeFiles() { ////////////////////////////////////////////////////////////////////////// // °øÁö»çÇ× ÆÄÀÏÀÇ Àü¼Û ¹× ¾ÐÃàÇØÁ¦ CString strNoticeRoot; CString strNoticePath, strNoticeClientPath, strFilename; std::vector< int > vecNoticeVer; // ¾÷µ¥ÀÌÆ® ¹öÀüÀ» ±Ù°Å·Î °øÁö»çÇ× ¸ñ·Ï(¹Þ¾ÆÇÒ ÆÄÀÏÀ̸§ ¸®½ºÆ®) »ý¼º strNoticeRoot = m_strServerPath + "/Notice"; // By Belldandy(2005.02.02) strNoticePath.Format( "%s/NoticeInfo.dat", strNoticeRoot ); strNoticeClientPath.Format( "%s/NoticeInfo.dat", m_strRootPath ); bool bRet = m_HTTPFile.TransferFile( strNoticePath, strNoticeClientPath, "NoticeInfo.dat" ); FILE* fp = fopen( strNoticeClientPath, "r" ); if( NULL == fp ) { // NoticeInfo.dat °¡ ¾øÀ» °æ¿ì, // Áö±ÝÀº ´Ü¼øÈ÷ ºüÁ®³ª°¡´Â ½ÄÀ¸·Î ó¸®ÇÏÁö¸¸ ÃßÈÄ¿£ º°µµ·Î ÆÄÀÏ ¸ñ·ÏÀ» // FTP·Î ºÎÅÍ ±Ü¾î¿Í ÃÖ±Ù ÆÄÀÏÀ» ¾ò´Â ½ÄÀ¸·Î 󸮵µ »ý°¢ÇØ º¼ ¼ö ÀÖ°ÚÁö? AfxMessageBox( RYLLoginGetMessage( LOGIN_MSG_FAIL_TO_GET_NOTICEINFO ) ); return false; } int nNoticeVersion = 0; bool bAddAfterAll = false; CString strTmp; while( !feof(fp) ) { int nReadCount = fscanf( fp, "%d", &nNoticeVersion ); // NoticeInfo.dat ¸»¹Ì °ø¹é½Ã ¸¶Áö¸· ¹öÀü¹øÈ£°¡ Áߺ¹ÇØ µé¾î°¡´Â ¹®Á¦ ÇØ°áÀ» À§ÇØ if( nReadCount < 1 ) { break; } if( nNoticeVersion <= 0 ) { // versioninfo.dat ÆÄÀÏÀÌ ±úÁø °æ¿ì AfxMessageBox( RYLLoginGetMessage( LOGIN_MSG_FAIL_TO_GET_NOTICEINFO ) ); return false; } strTmp.Format( "%s/Notice/%d", m_strRootPath, nNoticeVersion ); if( !IsDirectoryExist(strTmp) ) { bAddAfterAll = true; } if( bAddAfterAll ) { vecNoticeVer.push_back( nNoticeVersion ); } } fclose( fp ); DeleteFile( strNoticeClientPath ); DWORD dwNoticeTotalSize = 0; int cDown; // notice ÆÄÀÏ Àü¼Û for( cDown=0; cDown < vecNoticeVer.size(); cDown++ ) { if( m_bTerminate ) { // °­Á¦Á¾·á return false; } strNoticePath.Format( "%s/%dNotice.zip", strNoticeRoot, vecNoticeVer[cDown] ); strNoticeClientPath.Format( "%s/%dNotice.zip", m_strRootPath, vecNoticeVer[cDown] ); strFilename.Format( "%dNotice.zip", vecNoticeVer[cDown] ); m_HTTPFile.TransferFile( strNoticePath, strNoticeClientPath, strFilename ); // notice ÆÄÀÏ Àü¼Û¿¡ 5% ÇÒ´ç *m_pfProgressPercentage = (cDown*5.0f) / vecNoticeVer.size(); CRect rcUpdate; rcUpdate.left = 31; rcUpdate.top = 427; rcUpdate.right = 31 + 464; rcUpdate.bottom = 427 + 16; m_pDisplayWnd->InvalidateRect( rcUpdate, FALSE ); } // notice ÆÄÀÏ ¾ÐÃà ÇØÁ¦ CZipArchive zipArc; for( cDown = 0; cDown < vecNoticeVer.size(); ++cDown ) { if( m_bTerminate ) { for( cDown = 0; cDown < vecNoticeVer.size(); ++cDown ) { strNoticeClientPath.Format( "%s/%dNotice.zip", m_strRootPath, vecNoticeVer[cDown] ); DeleteFile( strNoticeClientPath ); } // °­Á¦Á¾·á return false; } strNoticeClientPath.Format( "%s/%dNotice.zip", m_strRootPath, vecNoticeVer[cDown] ); try { zipArc.Open( strNoticeClientPath, CZipArchive::zipOpen ); } catch(CException* e) { if( e->IsKindOf( RUNTIME_CLASS(CZipException) ) ) { CZipException* p = (CZipException*) e; //if( CZipException::badZipFile == p->m_iCause ) { CString strTmp; strTmp.Format( "Invalid zip file : %s", p->m_szFileName ); AfxMessageBox( strTmp, MB_ICONERROR|MB_OK ); } } e->Delete(); exit(0); } for( int i = 0; i < zipArc.GetCount(); ++i ) { CZipFileHeader zfh; zipArc.GetFileInfo( zfh, (WORD)i ); try { zipArc.ExtractFile( (WORD)i, m_strRootPath+"\\Notice" ); } catch(CException* e) { if( e->IsKindOf( RUNTIME_CLASS(CFileException) ) ) { CFileException* p = (CFileException*) e; if( CFileException::accessDenied == p->m_cause ) { // DWORD dwAttr = GetFileAttributes( p->m_strFileName ); // if( dwAttr & FILE_ATTRIBUTE_SYSTEM ) // { // dwAttr &= (~FILE_ATTRIBUTE_SYSTEM); // SetFileAttributes( p->m_strFileName, dwAttr ); // } // // if( dwAttr & FILE_ATTRIBUTE_HIDDEN ) // { // dwAttr &= (~FILE_ATTRIBUTE_HIDDEN); // SetFileAttributes( p->m_strFileName, dwAttr ); // } // // if( dwAttr & FILE_ATTRIBUTE_READONLY ) // { // dwAttr &= (~FILE_ATTRIBUTE_READONLY); // SetFileAttributes( p->m_strFileName, dwAttr ); // } // // DeleteFile( p->m_strFileName ); // zipArc.ExtractFile( (WORD)i, m_strRootPath+"\\Notice" ); } } e->Delete(); } } zipArc.Close(); DeleteFile( strNoticeClientPath ); // notice ÆÄÀÏ ¾ÐÃà ÇØÁ¦¿¡ 5% ÇÒ´ç *m_pfProgressPercentage = (cDown*5.0f) / vecNoticeVer.size() + 5.0f; CRect rcUpdate; rcUpdate.left = 31; rcUpdate.top = 427; rcUpdate.right = 31 + 464; rcUpdate.bottom = 427 + 16; m_pDisplayWnd->InvalidateRect( rcUpdate, FALSE ); } return true; } bool CUpdateManager::LoadServerPatchInfo() { m_pInfoWnd->SetWindowText( "Get Patchinfo" ); m_pInfoWnd->Invalidate(FALSE); // PatchInfoV2.zip ÆÄÀÏ Àü¼Û #ifdef _NATION_JP_ // ÀϺ»¼­¹ö´Â ¾ò¾î¿Â ¼­¹öÁÖ¼Ò + "/FilePatch/" °¡ ÆÐÄ¡ ÆÄÀÏÀ» °¡Á®¿Ã ÁÖ¼Ò´Ù // (°øÁöÁÖ¼Ò ÇϵåÄÚµùÀ» ¼­¹ö¿¡¼­ ¾ò¾î¿Â ÁÖ¼Ò ÀÌ¿ëÀ¸·Î ¹Ù²Þ) m_HTTPFile.TransferFile( m_strServerPath+"/FilePatch/PatchInfoV2.zip", m_strRootPath+"\\PatchInfoV2.zip", "PatchInfoV2.zip" ); #else m_HTTPFile.TransferFile( m_strServerPath+"/PatchInfoV2.zip", m_strRootPath+"\\PatchInfoV2.zip", "PatchInfoV2.zip" ); #endif // HANDLE hFile = CreateFile( m_strRootPath+"\\PatchInfo.zip", // GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, // NULL, OPEN_EXISTING, 0, 0 ); // if( INVALID_HANDLE_VALUE == hFile ) if( false == IsFileExist( m_strRootPath+"\\PatchInfoV2.zip" ) ) { // PatchInfo ÆÄÀÏÀ» ¹Þ¾Æ¿Ã ¼ö ¾ø½À´Ï´Ù AfxMessageBox( RYLLoginGetMessage(LOGIN_MSG_FAIL_TO_GET_PATCHINFO) ); return false; } // ¾ÐÃàÇØÁ¦ CZipArchive zipArc; try { zipArc.Open( m_strRootPath+"\\PatchInfoV2.zip", CZipArchive::zipOpen ); } catch(CException* e) { if( e->IsKindOf( RUNTIME_CLASS(CZipException) ) ) { CZipException* p = (CZipException*) e; //if( CZipException::badZipFile == p->m_iCause ) { CString strTmp; strTmp.Format( "Invalid zip file : %s", p->m_szFileName ); AfxMessageBox( strTmp, MB_ICONERROR|MB_OK ); } } e->Delete(); exit(0); } CString strTmp = m_strRootPath+"\\"+"PatchInfoV2"; DWORD dwAttr = 0; dwAttr = GetFileAttributes( strTmp ); if( 0xFFFFFFFF != dwAttr ) { if( FILE_ATTRIBUTE_SYSTEM & dwAttr ) { dwAttr &= (~FILE_ATTRIBUTE_SYSTEM); SetFileAttributes( strTmp, dwAttr ); } if( FILE_ATTRIBUTE_HIDDEN & dwAttr ) { dwAttr &= (~FILE_ATTRIBUTE_HIDDEN); SetFileAttributes( strTmp, dwAttr ); } if( FILE_ATTRIBUTE_READONLY & dwAttr ) { dwAttr &= (~FILE_ATTRIBUTE_READONLY); SetFileAttributes( strTmp, dwAttr ); } } zipArc.ExtractFile( 0, m_strRootPath ); zipArc.Close(); // PatchInfoV2.zip »èÁ¦ DeleteFile( m_strRootPath+"\\PatchInfoV2.zip" ); // PatchInfoV2 ·Îµå ÈÄ »èÁ¦ m_ServerFileInfoList.Reset(); m_ServerFileInfoList.Load( m_strRootPath+"\\PatchInfoV2" ); DeleteFile( m_strRootPath+"\\PatchInfoV2" ); // ¼­¹öÃø patchinfo Àü¼Û¿¡ 5%ÇÒ´ç *m_pfProgressPercentage = 15.0f; CRect rcUpdate; rcUpdate.left = 31; rcUpdate.top = 427; rcUpdate.right = 31 + 464; rcUpdate.bottom = 427 + 16; m_pDisplayWnd->InvalidateRect( rcUpdate, FALSE ); return true; } //bool CUpdateManager::LoadLocalPatchInfoCache() //{ // // ¸ñ·Ï ij½ÃÆÄÀÏÀÌ Á¸ÀçÇÏ´ÂÁö Ã¼Å©ÇØ ºÒ·¯¿È, ¾øÀ¸¸é »ý¼º // HANDLE hFile = CreateFile( m_strRootPath+"\\PatchInfo.cache", // GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, // NULL, OPEN_EXISTING, 0, 0 ); // if( INVALID_HANDLE_VALUE != hFile ) // { // CloseHandle(hFile); // // CZipArchive zipArc; // try // { // zipArc.Open( m_strRootPath+"\\PatchInfo.cache", CZipArchive::zipOpen ); // } // catch(CException* e) // { // if( e->IsKindOf( RUNTIME_CLASS(CZipException) ) ) // { // CZipException* p = (CZipException*) e; // // //if( CZipException::badZipFile == p->m_iCause ) // { // CString strTmp; // strTmp.Format( "Invalid zip file : %s", p->m_szFileName ); // AfxMessageBox( strTmp, MB_ICONERROR|MB_OK ); // } // } // // e->Delete(); // exit(0); // } // // CString strTmp = m_strRootPath+"\\"+"PatchInfo.local"; // DWORD dwAttr = 0; // dwAttr = GetFileAttributes( strTmp ); // if( 0xFFFFFFFF != dwAttr ) // { // if( FILE_ATTRIBUTE_SYSTEM & dwAttr ) // { // dwAttr &= (~FILE_ATTRIBUTE_SYSTEM); // SetFileAttributes( strTmp, dwAttr ); // } // // if( FILE_ATTRIBUTE_HIDDEN & dwAttr ) // { // dwAttr &= (~FILE_ATTRIBUTE_HIDDEN); // SetFileAttributes( strTmp, dwAttr ); // } // // if( FILE_ATTRIBUTE_READONLY & dwAttr ) // { // dwAttr &= (~FILE_ATTRIBUTE_READONLY); // SetFileAttributes( strTmp, dwAttr ); // } // } // zipArc.ExtractFile( 0, m_strRootPath ); // zipArc.Close(); // // if( false == m_LocalFileInfoList.Load( m_strRootPath+"\\PatchInfo.local" ) ) // { // if( false == CreateFileInfoCache() ) // { // return false; // } // } // } // else // { // if( false == CreateFileInfoCache() ) // { // return false; // } // } // // // // ·ÎÄà ÆÄÀϸíÀ¸·ÎÀÇ quickfind¿ë À妽º ¸Ê // int nTotal = m_LocalFileInfoList.GetList().GetSize(); // CString strProgress; // for( int i = 0; i < nTotal; ++i ) // { // if( m_bTerminate ) // { // // °­Á¦Á¾·á // return false; // } // // LocalFileInfoRecord &rLfir = m_LocalFileInfoList.GetList()[i]; // // m_mapLocalFileName2Index[ CString(rLfir.szFileName) ] = i; // // if( !(i % 100) ) // { // strProgress.Format( "[%d/%d] Building quick search index", i, nTotal ); // m_pInfoWnd->SetWindowText( strProgress ); // m_pInfoWnd->Invalidate( FALSE ); // // *m_pfFileProgressPercentage = (100.0f*i) / nTotal; // CRect rect; // rect.left = 22; // rect.right = 536; // rect.top = 405; // rect.bottom = 440; // m_pDisplayWnd->InvalidateRect( rect, FALSE ); // } // } // // // // ·ÎÄÃÃø patchinfo (»ý¼º+)·Îµù¿¡ 15%ÇÒ´ç // *m_pfProgressPercentage = 30.0f; // CRect rcUpdate; // rcUpdate.left = 31; // rcUpdate.top = 427; // rcUpdate.right = 31 + 464; // rcUpdate.bottom = 427 + 16; // m_pDisplayWnd->InvalidateRect( rcUpdate, FALSE ); // // return true; //} void CUpdateManager::AddToPkg2FileNameBucket( char* szPkgName, char* szFileName ) { std::map< PTR_STRING, std::vector< char* > *, PTR_STRING_LESS >::iterator it; std::vector< char* > * pVec; it = m_mapPackageName2FileNameVectorPtr.find( szPkgName ); if( m_mapPackageName2FileNameVectorPtr.end() == it ) { pVec = new std::vector< char* >; pVec->push_back( szFileName ); m_mapPackageName2FileNameVectorPtr[szPkgName] = pVec; } else { pVec = it->second; pVec->push_back( szFileName ); } } bool CUpdateManager::CollectDownloadFileList( bool bFileCheckMode ) { // ¼­¹öÃø ÆÄÀÏÁ¤º¸ ¸®½ºÆ®¿Í ·ÎÄÃÃø ÆÄÀÏÁ¤º¸ ¸®½ºÆ®¸¦ ºñ±³, ¾÷µ¥ÀÌÆ®°¡ ÇÊ¿äÇÑ // ÆÄÀÏÀÇ ¸ñ·ÏÀ» ¾ò¾î³¿ int i; int nTotal = m_ServerFileInfoList.GetList().size(); CString strTmp; for( i = 0; i < nTotal; ++i ) { if( m_bTerminate ) { // °­Á¦Á¾·á return false; } FilePatchInfoRecord &rServerRecord = m_ServerFileInfoList.GetList()[i]; if( !(i% 100) ) { strTmp.Format( "[%d/%d] Comparing %s", i, nTotal, rServerRecord.szFileName ); m_pInfoWnd->SetWindowText( strTmp ); m_pInfoWnd->Invalidate(FALSE); } if( bFileCheckMode ) { // File check mode ÀÏ °æ¿ì -> ÆÄÀÏÀÌ Á¸ÀçÇÏ´ÂÁö, Á¸ÀçÇÑ´Ù¸é CRC/size ÀÏÄ¡ÇÏ´ÂÁö üũ CString strTmp = m_strRootPath+"\\"+rServerRecord.szFileName; if( IsFileExist( strTmp ) ) { DWORD dwSize, dwCRC32; dwSize = GetFileSize( strTmp ); CCrc32Static::FileCrc32Assembly( strTmp, dwCRC32 ); if( rServerRecord.dwCRC32 != dwCRC32 || rServerRecord.dwSize != dwSize ) { AddToPkg2FileNameBucket( rServerRecord.szPackageFileName, rServerRecord.szFileName ); } } else { // ÆÄÀÏÀÌ Á¸ÀçÇÏÁö ¾ÊÀ»°æ¿ì -> ´ç±Ù ¼­¹ö¿¡¼­ °®±¸¿Í¾ßÁö AddToPkg2FileNameBucket( rServerRecord.szPackageFileName, rServerRecord.szFileName ); } } else { // Normal patch mode ÀÏ °æ¿ì -> ¹öÀüÇʵå¿Í Ŭ¶óÀÌ¾ðÆ® ¹öÀü ºñ±³ // ¼­¹öÆÐÄ¡ÆÄÀϸñ·ÏÀÇ ¹öÀüÇʵ尪ÀÌ Å¬¶óÀÌ¾ðÆ® ¹öÀü°ªº¸´Ù Å« °æ¿ì -> °¡Á®¿Í¾ß ÇÒ ´ë»ó if( rServerRecord.dwVersion > m_nVersion ) { AddToPkg2FileNameBucket( rServerRecord.szPackageFileName, rServerRecord.szFileName ); } } if( !(i% 100) ) { // ¼­¹ö/·ÎÄÃÃø ÆÄÀÏÁ¤º¸ ºñ±³¿¡ 45% ÇÒ´ç *m_pfProgressPercentage = (45.0f*i)/nTotal + 15.0f; *m_pfFileProgressPercentage = (i*100.0f)/nTotal; CRect rcUpdate; rcUpdate.left = 31; rcUpdate.top = 408; rcUpdate.right = 494; rcUpdate.bottom = 442; m_pDisplayWnd->InvalidateRect( rcUpdate, FALSE ); } } return true; } bool CUpdateManager::DownloadUpdateFile(void) { ////////////////////////////////////////////////////////////////////////// // // ´Ù¿î·Îµå ÇØ¾ß ÇÒ ¾ÐÃà ÆÄÀϵéÀ» Àü¼Û // char* szPackageFileName; int nTotal = m_mapPackageName2FileNameVectorPtr.size(); int nCounter = 0; // package ÆÄÀÏ Àü¼Û CString strTotalCount; std::map< PTR_STRING, std::vector< char* > *, PTR_STRING_LESS >::iterator it; for( it = m_mapPackageName2FileNameVectorPtr.begin(); it != m_mapPackageName2FileNameVectorPtr.end(); it++ ) { if( m_bTerminate ) { // °­Á¦Á¾·á return false; } szPackageFileName = it->first.m_pStr; strTotalCount.Format( " [ Total %d / %d files ]", ++nCounter, m_mapPackageName2FileNameVectorPtr.size() ); #ifdef _NATION_JP_ // ÀϺ»¼­¹ö´Â ¾ò¾î¿Â ¼­¹öÁÖ¼Ò + "/FilePatch/" °¡ ÆÐÄ¡ ÆÄÀÏÀ» °¡Á®¿Ã ÁÖ¼Ò´Ù // (°øÁöÁÖ¼Ò ÇϵåÄÚµùÀ» ¼­¹ö¿¡¼­ ¾ò¾î¿Â ÁÖ¼Ò ÀÌ¿ëÀ¸·Î ¹Ù²Þ) m_HTTPFile.TransferFile( m_strServerPath+"/FilePatch/"+szPackageFileName+".zip", m_strRootPath+"\\"+szPackageFileName+".zip", CString(szPackageFileName)+".zip"+strTotalCount ); #else m_HTTPFile.TransferFile( m_strServerPath+"/"+szPackageFileName+".zip", m_strRootPath+"\\"+szPackageFileName+".zip", CString(szPackageFileName)+".zip"+strTotalCount ); #endif // ÆÐŰÁö ÆÄÀÏ Àü¼Û¿¡ 20% ÇÒ´ç *m_pfProgressPercentage = (20.0f*nCounter)/nTotal + 60.0f; CRect rcUpdate; rcUpdate.left = 31; rcUpdate.top = 427; rcUpdate.right = 31 + 464; rcUpdate.bottom = 427 + 16; m_pDisplayWnd->InvalidateRect( rcUpdate, FALSE ); } return true; } bool CUpdateManager::ExtractPatchFiles() { // package ÆÄÀÏ¿¡¼­ ÇÊ¿äÇÑ ÆÄÀÏ ¾ÐÃà ÇØÁ¦ // ·ÎÄÃij½ÃÀÇ CRC, size Ç׸ñ ¾÷µ¥ÀÌÆ® // ¾ÐÃàÇØÁ¦ ³¡³­ package ÆÄÀÏ »èÁ¦ std::map< PTR_STRING, std::vector< char* > *, PTR_STRING_LESS >::iterator it; char* szPackageFileName; std::vector< char* > * pVec; int nTotal = 0, nCounter = 0; // ÃÑ ¾÷µ¥ÀÌÆ®ÇÒ ÆÄÀÏ °¹¼ö ÇÕ»ê for( it = m_mapPackageName2FileNameVectorPtr.begin(); it != m_mapPackageName2FileNameVectorPtr.end(); it++ ) { pVec = it->second; nTotal += pVec->size(); } CString strTmp; CZipArchive zipArc; for( it = m_mapPackageName2FileNameVectorPtr.begin(); it != m_mapPackageName2FileNameVectorPtr.end(); it++ ) { if( m_bTerminate ) { // °­Á¦Á¾·á return false; } szPackageFileName = it->first.m_pStr; pVec = it->second; // package ÆÄÀÏ ¿ÀÇ try { zipArc.Open( m_strRootPath+"\\"+szPackageFileName+".zip", CZipArchive::zipOpen ); } catch(CException* e) { if( e->IsKindOf( RUNTIME_CLASS(CZipException) ) ) { CZipException* p = (CZipException*) e; //if( CZipException::badZipFile == p->m_iCause ) { CString strTmp; strTmp.Format( "Invalid zip file : %s", p->m_szFileName ); AfxMessageBox( strTmp, MB_ICONERROR|MB_OK ); } } e->Delete(); exit(0); } // ¾ÐÃà ÇØÁ¦ for( int i = 0; i < pVec->size(); ++i ) { int nIdx = zipArc.FindFile( (*pVec)[i], CZipArchive::ffNoCaseSens ); if( -1 != nIdx ) { ++nCounter; strTmp.Format( "[%d/%d] Extracting %s\\%s", nCounter, nTotal, (*pVec)[i], (*pVec)[i] ); m_pInfoWnd->SetWindowText( strTmp ); m_pInfoWnd->Invalidate(FALSE); strTmp = m_strRootPath+"\\"+(*pVec)[i]; DWORD dwAttr = 0; dwAttr = GetFileAttributes( strTmp ); if( 0xFFFFFFFF != dwAttr ) { if( FILE_ATTRIBUTE_SYSTEM & dwAttr ) { dwAttr &= (~FILE_ATTRIBUTE_SYSTEM); SetFileAttributes( strTmp, dwAttr ); } if( FILE_ATTRIBUTE_HIDDEN & dwAttr ) { dwAttr &= (~FILE_ATTRIBUTE_HIDDEN); SetFileAttributes( strTmp, dwAttr ); } if( FILE_ATTRIBUTE_READONLY & dwAttr ) { dwAttr &= (~FILE_ATTRIBUTE_READONLY); SetFileAttributes( strTmp, dwAttr ); } } zipArc.ExtractFile( nIdx, m_strRootPath ); // ÆÐÄ¡ ÆÄÀÏ ÃßÃâ¿¡ 20% ÇÒ´ç *m_pfProgressPercentage = (20.0f*nCounter)/nTotal + 80.0f; CRect rcUpdate; rcUpdate.left = 31; rcUpdate.top = 427; rcUpdate.right = 31 + 464; rcUpdate.bottom = 427 + 16; m_pDisplayWnd->InvalidateRect( rcUpdate, FALSE ); // ·±Ã³ ¾÷µ¥ÀÌÆ® üũ if( 0 == stricmp( "Login.new", (*pVec)[i] ) ) { m_bUpdateLogin = TRUE; } } } zipArc.Close(); DeleteFile( m_strRootPath+"\\"+szPackageFileName+".zip" ); } m_nVersion = m_ServerFileInfoList.GetVersion(); return true; } bool CUpdateManager::CleanUp() { std::map< PTR_STRING, std::vector< char* > *, PTR_STRING_LESS >::iterator it; std::vector< char* > * pVec; // ÃÑ ¾÷µ¥ÀÌÆ®ÇÒ ÆÄÀÏ °¹¼ö ÇÕ»ê for( it = m_mapPackageName2FileNameVectorPtr.begin(); it != m_mapPackageName2FileNameVectorPtr.end(); it++ ) { pVec = it->second; delete pVec; } m_mapPackageName2FileNameVectorPtr.clear(); return true; } //bool CUpdateManager::SaveLocalCache() //{ // // cache ÆÄÀÏÀ» ÀúÀå // m_LocalFileInfoList.Save( m_strRootPath+"\\PatchInfo.local" ); // // CZipArchive zipArc; // // try // { // zipArc.Open( m_strRootPath+"\\PatchInfo.cache", CZipArchive::zipCreate ); // } // catch(CException* e) // { // if( e->IsKindOf( RUNTIME_CLASS(CZipException) ) ) // { // CZipException* p = (CZipException*) e; // // //if( CZipException::badZipFile == p->m_iCause ) // { // CString strTmp; // strTmp.Format( "Invalid zip file : %s", p->m_szFileName ); // AfxMessageBox( strTmp, MB_ICONERROR|MB_OK ); // } // } // // e->Delete(); // exit(0); // } // zipArc.AddNewFile( m_strRootPath+"\\PatchInfo.local", "PatchInfo.local" ); // zipArc.Close(); // // DeleteFile( m_strRootPath+"\\PatchInfo.local" ); // // return true; //} //bool CUpdateManager::CreateFileInfoCache() //{ // long lTotalFileCount = GetFileCountInSubDir( m_strRootPath ); // // WIN32_FIND_DATA w32fd; // // HANDLE hFind = FindFirstFile( m_strRootPath+"\\*.*", &w32fd ); // // if( INVALID_HANDLE_VALUE == hFind ) // { // return false; // } // // CString strCurrentSubPath(""); // CStringArray astrSubDirList; // CString strFullPathName; // CString strTmp; // int nCounter = 0; // while( 1 ) // { // if( m_bTerminate ) // { // // °­Á¦Á¾·á // return false; // } // // if( 0 != stricmp( ".", w32fd.cFileName ) && // 0 != stricmp( "..", w32fd.cFileName ) ) // { // if( w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) // { // strTmp.Format( "%s%s", strCurrentSubPath, w32fd.cFileName ); // astrSubDirList.Add( strTmp ); // } // else // { // LocalFileInfoRecord lfir; // ++nCounter; // // strcpy( lfir.szFileName, strCurrentSubPath+w32fd.cFileName ); // strFullPathName = m_strRootPath+"\\"+strCurrentSubPath+w32fd.cFileName; // // if( !(nCounter % 30) ) // { // strTmp.Format( "[%d/%d] Checking %s", nCounter, lTotalFileCount, strFullPathName ); // m_pInfoWnd->SetWindowText( strTmp ); // m_pInfoWnd->InvalidateRect(NULL,FALSE); // // // // ·ÎÄÃÃø patchinfo »ý¼º¿¡ 15%ÇÒ´ç // *m_pfProgressPercentage = (nCounter*15.0f)/lTotalFileCount + 15.0f; // *m_pfFileProgressPercentage = (nCounter*100.0f)/lTotalFileCount; // CRect rcUpdate; // rcUpdate.left = 31; // rcUpdate.top = 408; // rcUpdate.right = 494; // rcUpdate.bottom = 442; // m_pDisplayWnd->InvalidateRect( rcUpdate, FALSE ); // } // // // CCrc32Static::FileCrc32Assembly( strFullPathName, lfir.dwCRC32 ); // HANDLE hFile = CreateFile( strFullPathName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, // NULL, OPEN_EXISTING, 0, 0 ); // lfir.dwSize = GetFileSize ( hFile, NULL ); // CloseHandle( hFile ); // // m_LocalFileInfoList.GetList().Add( lfir ); // } // } // // if( 0 == FindNextFile( hFind, &w32fd ) ) // { // FindClose( hFind ); // // // sub dir queue ¿¡ ¼ø¼­¸¦ ±â´Ù¸®°í ÀÖ´Â ³ðÀÌ Á¸ÀçÇϸé // if( astrSubDirList.GetSize() > 0 ) // { // // ²¨³»¼­ ¾²°í // strCurrentSubPath = astrSubDirList[0] + "\\"; // astrSubDirList.RemoveAt(0); // hFind = FindFirstFile( m_strRootPath+"\\"+strCurrentSubPath+"*.*", &w32fd ); // } // else // { // // ¾øÀ½ ·çÇÁ Á¾·á // break; // } // } // } // // // »ý¼º Á÷ÈÄ Çѹø ÀúÀåÇØÁÜ // return SaveLocalCache(); //} long CUpdateManager::GetFileCountInSubDir( const char* szSubDirName ) { WIN32_FIND_DATA w32fd; CString strSubDirName( szSubDirName ); CString strCurrentSubPath(""); CStringArray astrSubDirList; int nCounter = 0; HANDLE hFind = FindFirstFile( strSubDirName+"\\*.*", &w32fd ); if( INVALID_HANDLE_VALUE == hFind ) { return false; } while( 1 ) { if( 0 != stricmp( ".", w32fd.cFileName ) && 0 != stricmp( "..", w32fd.cFileName ) ) { if( w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { CString strTmp; strTmp.Format( "%s%s", strCurrentSubPath, w32fd.cFileName ); astrSubDirList.Add( strTmp ); } else { ++nCounter; } } if( 0 == FindNextFile( hFind, &w32fd ) ) { FindClose( hFind ); // sub dir queue ¿¡ ¼ø¼­¸¦ ±â´Ù¸®°í ÀÖ´Â ³ðÀÌ Á¸ÀçÇϸé if( astrSubDirList.GetSize() > 0 ) { // ²¨³»¼­ ¾²°í strCurrentSubPath = astrSubDirList[0] + "\\"; astrSubDirList.RemoveAt(0); hFind = FindFirstFile( strSubDirName+"\\"+strCurrentSubPath+"*.*", &w32fd ); } else { // ¾øÀ½ ·çÇÁ Á¾·á break; } } } return nCounter; } // case-insensitive version //UINT AFXAPI HashKey(CString& string) //{ // LPCTSTR key = (LPCTSTR) string; // UINT nHash = 0; // // TCHAR tc; // // while (*key) // { // if( TCHAR('A') <= *key && *key <= TCHAR('Z') ) // { // tc = *key + ( TCHAR('a') - TCHAR('A') ); // } // else // { // tc = *key; // } // // nHash = (nHash<<5) + nHash + tc; // // +++key; // } // // return nHash; //} //void CUpdateManager::ProgressReport(char *pFilename, int nCount) //{ // static int nUpdate = 0; // CString strInfo; // // if( strcmp( pFilename, "Login.new" ) == 0 ) // { // m_bUpdateLogin = TRUE; // } // //if( ( nUpdate++ ) % 3 == 0 ) // { // // strInfo.Format( " %d / %d Extract File = %d", nCount, *m_dwZipTotalCount, pFilename ); // m_pInfoWnd->SetWindowText( strInfo ); // m_pInfoWnd->Invalidate( FALSE ); // // CRect rect; // rect.left = 22; // rect.right = 536; // rect.top = 405; // rect.bottom = 440; // // m_pDisplayWnd->InvalidateRect( rect, FALSE ); // } //} //void CUpdateManager::LoadClientFileInfoCacheList() //{ // FILE* fp; // // CString strFileName = m_strRootPath + "\\PatchInfo.cache"; // // fp = fopen( strFileName.GetBuffer(0), "rb" ); // // if( NULL == fp ) // { // return; // } // // int nFileNameLength; // //DWORD dwSize, dwCRC; // ClientFileInfo cfi; // char szFileName[1024]; // // int nCount; // // fread( &nCount, sizeof(int), 1, fp ); // // int nRealCount = 0; // while( !feof(fp) ) // { // fread( &nFileNameLength, sizeof(int), 1, fp ); // // fread( szFileName, nFileNameLength, 1, fp ); // szFileName[nFileNameLength] = '\0'; // // fread( &cfi, sizeof(ClientFileInfo), 1, fp ); // // CString strKey = szFileName; // strKey.MakeLower(); // // m_mapFileInfoCache[strKey] = cfi; // // ++nRealCount; // // if( m_pInfoWnd ) // { // CString strCacheCount; // strCacheCount.Format( "%s %d / %d", RYLLoginGetMessage(LOGIN_MSG_LOADING_PATCHINFO_CACHE), nRealCount, nCount ); // m_pInfoWnd->SetWindowText( strCacheCount ); // } // } // // fclose(fp); //} // // //void CUpdateManager::SaveClientFileInfoCacheList() //{ // FILE* fp; // // CString strPatchInfoFileName = m_strRootPath + "\\PatchInfo.cache"; // // fp = fopen( strPatchInfoFileName.GetBuffer(0), "wb" ); // // if( NULL == fp ) // { // return; // } // // int nCount = m_mapFileInfoCache.GetCount(); // // fwrite( &nCount, sizeof(int), 1, fp ); // // int nFileNameLength; // ClientFileInfo cfi; // CString strFileName; // // POSITION iter; // // iter = m_mapFileInfoCache.GetStartPosition(); // // while( NULL != iter ) // { // m_mapFileInfoCache.GetNextAssoc( iter, strFileName, cfi ); // // nFileNameLength = strFileName.GetLength(); // // fwrite( &nFileNameLength, sizeof(int), 1, fp ); // fwrite( strFileName.GetBuffer(0), nFileNameLength, 1, fp ); // fwrite( &cfi, sizeof(ClientFileInfo), 1, fp ); // } //}