// PatchMakerDlg.cpp : ±¸Çö ÆÄÀÏ // #include "stdafx.h" #include "PatchMaker.h" #include "PatchMakerDlg.h" #include #include "PatchMaker.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // ÀÀ¿ë ÇÁ·Î±×·¥ Á¤º¸¿¡ »ç¿ëµÇ´Â CAboutDlg ´ëÈ­ »óÀÚÀÔ´Ï´Ù. class CAboutDlg : public CDialog { public: CAboutDlg(); // ´ëÈ­ »óÀÚ µ¥ÀÌÅÍÀÔ´Ï´Ù. enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV Áö¿øÀÔ´Ï´Ù. // ±¸ÇöÀÔ´Ï´Ù. protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CPatchMakerDlg ´ëÈ­ »óÀÚ CPatchMakerDlg::CPatchMakerDlg(CWnd* pParent /*=NULL*/) : CDialog(CPatchMakerDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1); } void CPatchMakerDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_EDIT_WORKER, mEditWorker); DDX_Control(pDX, IDC_EDIT_SOURCE, mEditSource); DDX_Control(pDX, IDC_EDIT_TARGET, mEditTarget); DDX_Control(pDX, IDC_EDIT_BACKUP, mEditBackup); DDX_Control(pDX, IDC_EDIT_SOURCE_LIST, mEditSourceList); } BEGIN_MESSAGE_MAP(CPatchMakerDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_MESSAGE( WM_PATCH_MSG, PatchMsg ) //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON_WORKER, &CPatchMakerDlg::OnBnClickedButtonWorker) ON_BN_CLICKED(IDC_BUTTON_SOURCE, &CPatchMakerDlg::OnBnClickedButtonSource) ON_BN_CLICKED(IDC_BUTTON_TARGET, &CPatchMakerDlg::OnBnClickedButtonTarget) ON_BN_CLICKED(IDC_BUTTON_BACKUP, &CPatchMakerDlg::OnBnClickedButtonBackup) ON_BN_CLICKED(IDC_BUTTON_SOURCE_LIST, &CPatchMakerDlg::OnBnClickedButtonSourceList) ON_BN_CLICKED(IDC_BUTTON_START, &CPatchMakerDlg::OnBnClickedButtonStart) ON_BN_CLICKED(IDC_BT_OPTION, &CPatchMakerDlg::OnClickDelOption) END_MESSAGE_MAP() // CPatchMakerDlg ¸Þ½ÃÁö 󸮱â BOOL CPatchMakerDlg::OnInitDialog() { CDialog::OnInitDialog(); // ½Ã½ºÅÛ ¸Þ´º¿¡ "Á¤º¸..." ¸Þ´º Ç׸ñÀ» Ãß°¡ÇÕ´Ï´Ù. // IDM_ABOUTBOX´Â ½Ã½ºÅÛ ¸í·É ¹üÀ§¿¡ ÀÖ¾î¾ß ÇÕ´Ï´Ù. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // ÀÌ ´ëÈ­ »óÀÚÀÇ ¾ÆÀÌÄÜÀ» ¼³Á¤ÇÕ´Ï´Ù. ÀÀ¿ë ÇÁ·Î±×·¥ÀÇ ÁÖ Ã¢ÀÌ ´ëÈ­ »óÀÚ°¡ ¾Æ´Ò °æ¿ì¿¡´Â // ÇÁ·¹ÀÓ¿öÅ©°¡ ÀÌ ÀÛ¾÷À» ÀÚµ¿À¸·Î ¼öÇàÇÕ´Ï´Ù. SetIcon(m_hIcon, TRUE); // Å« ¾ÆÀÌÄÜÀ» ¼³Á¤ÇÕ´Ï´Ù. SetIcon(m_hIcon, FALSE); // ÀÛÀº ¾ÆÀÌÄÜÀ» ¼³Á¤ÇÕ´Ï´Ù. // TODO: ¿©±â¿¡ Ãß°¡ ÃʱâÈ­ ÀÛ¾÷À» Ãß°¡ÇÕ´Ï´Ù. LoadOptionFile(); mPatchMaker = new Patchmaker( ); if( mPatchMaker == NULL ) EndDialog( IDCANCEL ); return TRUE; // Æ÷Ä¿½º¸¦ ÄÁÆ®·Ñ¿¡ ¼³Á¤ÇÏÁö ¾ÊÀ¸¸é TRUE¸¦ ¹ÝȯÇÕ´Ï´Ù. } BOOL CPatchMakerDlg::DestroyWindow() { /// ¿É¼Ç ÆÄÀÏ ÀÚµ¿ ÀúÀå. SaveCurrentPathOption(); if( mPatchMaker ) mPatchMaker->Destroy(); SafeDelete( mPatchMaker ); return CDialog::DestroyWindow(); } void CPatchMakerDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // ´ëÈ­ »óÀÚ¿¡ ÃÖ¼ÒÈ­ ´ÜÃ߸¦ Ãß°¡ÇÒ °æ¿ì ¾ÆÀÌÄÜÀ» ±×¸®·Á¸é // ¾Æ·¡ Äڵ尡 ÇÊ¿äÇÕ´Ï´Ù. ¹®¼­/ºä ¸ðµ¨À» »ç¿ëÇÏ´Â MFC ÀÀ¿ë ÇÁ·Î±×·¥ÀÇ °æ¿ì¿¡´Â // ÇÁ·¹ÀÓ¿öÅ©¿¡¼­ ÀÌ ÀÛ¾÷À» ÀÚµ¿À¸·Î ¼öÇàÇÕ´Ï´Ù. void CPatchMakerDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // ±×¸®±â¸¦ À§ÇÑ µð¹ÙÀ̽º ÄÁÅØ½ºÆ® SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // Ŭ¶óÀÌ¾ðÆ® »ç°¢Çü¿¡¼­ ¾ÆÀÌÄÜÀ» °¡¿îµ¥¿¡ ¸ÂÃä´Ï´Ù. int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // ¾ÆÀÌÄÜÀ» ±×¸³´Ï´Ù. dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // »ç¿ëÀÚ°¡ ÃÖ¼ÒÈ­µÈ âÀ» ²ô´Â µ¿¾È¿¡ Ä¿¼­°¡ Ç¥½ÃµÇµµ·Ï ½Ã½ºÅÛ¿¡¼­ // ÀÌ ÇÔ¼ö¸¦ È£ÃâÇÕ´Ï´Ù. HCURSOR CPatchMakerDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } /// Æú´õ Ž»ö±â BOOL CPatchMakerDlg::BrowseFolder( TCHAR* pTitle, TCHAR* pFolderPath ) { ITEMIDLIST *pidlBrowse = NULL; BROWSEINFO BrInfo; BrInfo.hwndOwner = GetSafeHwnd(); BrInfo.pidlRoot = NULL; memset( &BrInfo, 0, sizeof(BrInfo) ); BrInfo.pszDisplayName = pFolderPath; BrInfo.lpszTitle = pTitle; BrInfo.ulFlags = BIF_RETURNONLYFSDIRS; // ´ÙÀ̾ó·Î±×¸¦ ¶ç¿ì±â pidlBrowse = ::SHBrowseForFolder(&BrInfo); if( pidlBrowse != NULL) { // ÆÐ½º¸¦ ¾ò¾î¿È ::SHGetPathFromIDList(pidlBrowse, pFolderPath); return true; } return false; } void CPatchMakerDlg::OnBnClickedButtonWorker() { TCHAR pathName[MAX_PATH] = {0,}; TCHAR* pTitle = "Select Worker Directory"; if( BrowseFolder( pTitle, pathName ) == TRUE ) mEditWorker.SetWindowText( pathName ); } void CPatchMakerDlg::OnBnClickedButtonSource() { TCHAR pathName[MAX_PATH] = {0,}; TCHAR* pTitle = "Select Source Directory"; if( BrowseFolder( pTitle, pathName ) == TRUE ) mEditSource.SetWindowText( pathName ); } void CPatchMakerDlg::OnBnClickedButtonTarget() { TCHAR pathName[MAX_PATH] = {0,}; TCHAR* pTitle = "Select Target Directory"; if( BrowseFolder( pTitle, pathName ) == TRUE ) mEditTarget.SetWindowText( pathName ); } void CPatchMakerDlg::OnBnClickedButtonBackup() { TCHAR pathName[MAX_PATH] = {0,}; TCHAR* pTitle = "Select Backup Directory"; if( BrowseFolder( pTitle, pathName ) == TRUE ) mEditBackup.SetWindowText( pathName ); } void CPatchMakerDlg::OnBnClickedButtonSourceList() { TCHAR pathName[MAX_PATH] = {0,}; TCHAR* pTitle = "Select Source List"; if( BrowseFolder( pTitle, pathName ) == TRUE ) mEditSourceList.SetWindowText( pathName ); } void CPatchMakerDlg::LoadOptionFile() { CStdioFile optionFile; CFileException ex; CString strFileName; TCHAR currentPath[MAX_PATH] = {0,}; GetCurrentDirectory( MAX_PATH, currentPath ); strFileName.Format( "%s\\option.txt", currentPath ); if( optionFile.Open( strFileName, CFile::modeRead, &ex ) != 0 ) { CString workerPath; CString sourcePath; CString targetPath; CString backupPath; CString sourceListPath; bool optionCheck = false; BOOL isReadLine; isReadLine=optionFile.ReadString(workerPath); if( isReadLine == FALSE ) return; isReadLine=optionFile.ReadString(sourcePath); if( isReadLine == FALSE ) return; isReadLine=optionFile.ReadString(targetPath); if( isReadLine == FALSE ) return; isReadLine=optionFile.ReadString(backupPath); if( isReadLine == FALSE ) return; isReadLine=optionFile.ReadString(sourceListPath); if( isReadLine == FALSE ) return; if( _access( workerPath, 0 ) == 0 ) mEditWorker.SetWindowText( workerPath ); if( _access( sourcePath, 0 ) == 0 ) mEditSource.SetWindowText( sourcePath ); if( _access( targetPath, 0 ) == 0 ) mEditTarget.SetWindowText( targetPath ); if( _access( backupPath, 0 ) == 0 ) mEditBackup.SetWindowText( backupPath ); if( _access( sourceListPath, 0 ) == 0 ) mEditSourceList.SetWindowText( sourceListPath ); optionFile.Close(); } } void CPatchMakerDlg::LoadPatchList() { CFile patchListFile; CFileException ex; CString strPath; TCHAR currentPath[MAX_PATH] = {0,}; TCHAR* buf = NULL; UINT bufSize = 0; bool sourcePathExist = false; GetCurrentDirectory( MAX_PATH, currentPath ); mEditSourceList.GetWindowText( strPath ); if( _access( strPath.GetBuffer(), 0 ) == 0 ) sourcePathExist = true; strPath += "\\SourceList.txt"; /// ¼Ò½º ¸®½ºÆ® °æ·Î´Â Àִµ¥ ÆÄÀÏÀÌ ¾øÀ¸¸é ¼Ò½ºÆú´õ¿¡¼­ ¼Ò½º¸®½ºÆ®¿¡¼­ À籸¼º. if( _access( strPath.GetBuffer(), 0 ) != 0 && sourcePathExist == true ) { mEditSource.GetWindowText( strPath ); mPatchMaker->SetStatus( GetSafeHwnd(), "Collect Source List..." ); if( mPatchMaker->CollectListInfo( strPath.GetBuffer(), NULL ) == 0 ) mPatchMaker->SetUseSourceListFlag( true ); return; } if( patchListFile.Open( strPath, CFile::modeRead, &ex ) != 0 ) { bufSize = (UINT)patchListFile.GetLength(); buf = new TCHAR[bufSize]; patchListFile.Read( buf, bufSize ); mPatchMaker->ReadSourceList( buf ); delete[] buf; patchListFile.Close(); } } void CPatchMakerDlg::SaveCurrentPathOption() { CStdioFile optionFile; CFileException ex; CString strFileName; TCHAR currentPath[MAX_PATH] = {0,}; GetCurrentDirectory( MAX_PATH, currentPath ); strFileName.Format( "%s\\option.txt", currentPath ); if( optionFile.Open( strFileName, CFile::modeCreate | CFile::modeWrite, &ex ) != 0 ) { CString workerPath; CString sourcePath; CString targetPath; CString backupPath; CString sourceListPath; mEditWorker.GetWindowText( workerPath ); mEditSource.GetWindowText( sourcePath ); mEditTarget.GetWindowText( targetPath ); mEditBackup.GetWindowText( backupPath ); mEditSourceList.GetWindowText( sourceListPath ); workerPath += "\n"; sourcePath += "\n"; targetPath += "\n"; backupPath += "\n"; sourceListPath += "\n"; /// ¶óÀÎ ´ÜÀ§·Î °ª ÀúÀå optionFile.WriteString( workerPath ); optionFile.WriteString( sourcePath ); optionFile.WriteString( targetPath ); optionFile.WriteString( backupPath ); optionFile.WriteString( sourceListPath ); optionFile.Close(); } } void CPatchMakerDlg::OnBnClickedButtonStart() { /// ½ÇÇàÁß ÇÊ¿ä¾ø´Â ºÎºÐ ´Ý±â. SetEnableState( FALSE ); CString workerPath; CString sourcePath; CString targetPath; CString backupPath; CString sourceListPath; mEditWorker.GetWindowText( workerPath ); mEditSource.GetWindowText( sourcePath ); mEditTarget.GetWindowText( targetPath ); mEditBackup.GetWindowText( backupPath ); mEditSourceList.GetWindowText( sourceListPath ); SendDlgItemMessage( IDC_PROGRESS , PBM_SETPOS, 0, 0 ); mPatchMaker->ClearList(); if( mPatchMaker->SetDirectory( workerPath.GetBuffer(), sourcePath.GetBuffer(), targetPath.GetBuffer(), backupPath.GetBuffer(), sourceListPath.GetBuffer() ) == false ) return; LoadPatchList(); if( mPatchMaker->Run( GetSafeHwnd() ) == -1 ) return; } LRESULT CPatchMakerDlg::PatchMsg(WPARAM wParam, LPARAM lParam ) { if( wParam == ePM_COMPLETE || wParam == ePM_ERROR ) SetEnableState( TRUE ); return mPatchMaker->PatchMsg( GetSafeHwnd(), wParam, lParam ); } void CPatchMakerDlg::SetEnableState( BOOL isPatchMaking ) { mEditWorker.EnableWindow( isPatchMaking ); mEditSource.EnableWindow( isPatchMaking ); mEditTarget.EnableWindow( isPatchMaking ); mEditBackup.EnableWindow( isPatchMaking ); mEditSourceList.EnableWindow( isPatchMaking ); GetDlgItem( IDC_BUTTON_WORKER )->EnableWindow( isPatchMaking ); GetDlgItem( IDC_BUTTON_SOURCE )->EnableWindow( isPatchMaking ); GetDlgItem( IDC_BUTTON_TARGET )->EnableWindow( isPatchMaking ); GetDlgItem( IDC_BUTTON_BACKUP )->EnableWindow( isPatchMaking ); GetDlgItem( IDC_BUTTON_SOURCE_LIST )->EnableWindow( isPatchMaking ); GetDlgItem( IDC_BUTTON_START )->EnableWindow( isPatchMaking ); } void CPatchMakerDlg::OnClickDelOption() { CButton * pSource = (CButton*)GetDlgItem( IDC_CHK_SOURCE ); CButton * pTarget = (CButton*)GetDlgItem( IDC_CHK_TARGETPATH ); CString path; /// sourceList.txt »èÁ¦ if( pSource->GetCheck() ) { mEditSourceList.GetWindowText( path ); path += "\\SourceList.txt"; if( _access( path, 0 ) == 0 ) DeleteFile( path ); } /// target Directory ÆÄÀÏµé »èÁ¦ if( pTarget->GetCheck() ) { char target[ 1024 ] = { 0, }; mEditTarget.GetWindowText( path ); strcpy_s( target, path.GetBuffer(path.GetLength()) ); if( _access( target, 0 ) == 0 ) mPatchMaker->DeleteSubFiles( target, NULL ); } }