// AppBase.cpp: implementation of the CAppBase class. // ////////////////////////////////////////////////////////////////////// #include #include #include "AppBase.h" //#define USE_KOREAN char g_lpszRootFolder[MAX_PATH]; char g_lpszUpdateFolder[MAX_PATH]; ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CAppBase::CAppBase() { m_hWnd = NULL; } CAppBase::~CAppBase() { } BOOL CAppBase::Create( HINSTANCE hInstance, LPCTSTR lpszAppName, WNDPROC WindowProc, LPCTSTR lpszIconName, int nCmdShow) { WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WindowProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon( hInstance, lpszIconName); wndclass.hCursor = LoadCursor( NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = lpszAppName; if ( !RegisterClass( &wndclass)) { return ( FALSE); } m_hWnd = CreateWindow( lpszAppName, lpszAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, NULL, NULL, hInstance, NULL); if ( !m_hWnd) { return ( FALSE); } ShowWindow( m_hWnd, nCmdShow); UpdateWindow( m_hWnd); // ÃʱâÈ­ DragAcceptFiles( m_hWnd, TRUE); return ( TRUE); } void CAppBase::Destroy( void) { } int CAppBase::Run( void) { MSG msg; while( GetMessage( &msg, NULL, 0, 0)) { TranslateMessage( &msg); DispatchMessage( &msg); } return ( msg.lParam); } LRESULT CAppBase::WindowProc( HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hDc; switch( iMessage) { case WM_PAINT: hDc = BeginPaint( hWnd, &ps); { RECT rtDraw = { 5, 180, 395, 295}; GetClientRect( hWnd, &rtDraw); #ifdef USE_KOREAN DrawText( hDc, "¾÷µ¥ÀÌÆ® ÆÄÀÏÀÌ µé¾îÀÖ´Â Æú´õ¸¦ µå·¡±× ÇØ ÁÖ»ç¿Í¿ä", -1, &rtDraw, DT_CENTER | DT_SINGLELINE | DT_VCENTER); #else DrawText( hDc, "Please drag folder consisting of update files.", -1, &rtDraw, DT_CENTER | DT_SINGLELINE | DT_VCENTER); #endif } EndPaint( hWnd, &ps); break; case WM_DESTROY: Destroy(); PostQuitMessage( 0); break; case WM_DROPFILES: { SetForegroundWindow( m_hWnd); HDROP hDrop = ( HDROP)wParam; char lpszFileName[MAX_PATH]; DragQueryFile( hDrop, 0, lpszFileName, MAX_PATH); DragFinish( hDrop); GenerateList( lpszFileName); } break; default: return DefWindowProc( hWnd, iMessage, wParam, lParam); } return ( 0); } BOOL CAppBase::GenerateList( char *lpszFolderName) { SHFILEINFO fi; SHGetFileInfo( lpszFolderName, 0, &fi, sizeof ( fi), SHGFI_ATTRIBUTES); if ( !( SFGAO_FOLDER & fi.dwAttributes)) { #ifdef USE_KOREAN MessageBox( m_hWnd, "Æú´õ¸¦ µå·¡±× ÇØ¾ßÁÒ!!", "¿¡·¯", MB_OK); #else MessageBox( m_hWnd, "You must drag folder.!!", NULL, MB_OK); #endif return ( FALSE); } // ¾÷µ¥ÀÌÆ® Æú´õ »ý¼º GetCurrentDirectory( MAX_PATH, g_lpszUpdateFolder); strcat( g_lpszUpdateFolder, "\\Update_"); char pszFileName[MAX_PATH]; char pszFileExt[MAX_PATH]; char pszDir[MAX_PATH]; //¿©±â¼­ ¼­¹öÆú´õ Á¶°ÇÀÌ µû¸¥´Ù. //¼­¹öÀÇ Æú´õ´Â ·çÆ®¿¡¼­ ÇÏÀ§ 1´Ü°è ±îÁö¸¸ Á¸ÀçÇÑ´Ù. _splitpath(lpszFolderName, NULL, pszDir, pszFileName, pszFileExt ); strcat( g_lpszUpdateFolder, pszFileName ); CreateDirectory( g_lpszUpdateFolder, 0); // ÆÄÀÏ »ý¼º char lpszNewFile[MAX_PATH]; wsprintf( lpszNewFile, "%s\\wz_filelist.dat", g_lpszUpdateFolder); HANDLE hFile = CreateFile( lpszNewFile, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); strcpy( g_lpszRootFolder, lpszFolderName); if ( !ShowFolder( hFile, lpszFolderName)) { CloseHandle( hFile); return ( FALSE); } CloseHandle( hFile); #ifdef USE_KOREAN MessageBox( m_hWnd, "¾÷µ¥ÀÌÆ® Áغñ ¿Ï·áµÇ¾ú½¿´Ù!", "¼º°ø", MB_OK); #else MessageBox( m_hWnd, "Complete!", "Success", MB_OK); #endif PostMessage( m_hWnd, WM_CLOSE, 0, 0); return ( TRUE); } BOOL CAppBase::ShowFolder( HANDLE hFile, char *lpszFolder) { char lpszFind[MAX_PATH]; WIN32_FIND_DATA fd; BOOL bFinding; char lpszWrite[1024]; DWORD dwNumber; // 1. ÆÄÀÏ ¸®½ºÆ® wsprintf( lpszFind, "%s\\*", lpszFolder); HANDLE hFind = FindFirstFile( lpszFind, &fd); bFinding = ( INVALID_HANDLE_VALUE != hFind) ? TRUE : FALSE; while ( bFinding) { if ( !( FILE_ATTRIBUTE_DIRECTORY & fd.dwFileAttributes)) { // ÆÄÀϸ¸ // ÆÄÀÏ À̸§ ÀúÀå wsprintf( lpszWrite, "\"%s\"\r\n", fd.cFileName); //ToLower( lpszWrite); WriteFile( hFile, lpszWrite, strlen( lpszWrite), &dwNumber, 0); // ÆÄÀÏ º¹»ç char lpszSource[MAX_PATH]; wsprintf( lpszSource, "%s\\%s", lpszFolder, fd.cFileName); char lpszTarget[MAX_PATH]; wsprintf( lpszTarget, "%s\\%s", g_lpszUpdateFolder, fd.cFileName); if ( !CopyFile( lpszSource, lpszTarget, TRUE)) { char lpszMessage[1024]; #ifdef USE_KOREAN wsprintf( lpszMessage, "%s ÆÄÀÏÀ» º¹»çÇÒ ¼ö ¾ø½À´Ï´Ù.\n°è¼ÓÇÒ±î¿ä?", lpszSource); if ( IDNO == MessageBox( m_hWnd, lpszMessage, "ÆÄÀÏ º¹»ç ½ÇÆÐ", MB_YESNO)) #else wsprintf( lpszMessage, "Failed to copy %s file\nContinue?", lpszSource); if ( IDNO == MessageBox( m_hWnd, lpszMessage, "File copy error", MB_YESNO)) #endif { return ( FALSE); } } } bFinding = FindNextFile( hFind, &fd); } FindClose( hFind); // 2. ÇÏÀ§ Æú´õ ¼ÓÀ¸·Î hFind = FindFirstFile( lpszFind, &fd); bFinding = ( INVALID_HANDLE_VALUE != hFind) ? TRUE : FALSE; while ( bFinding) { if ( FILE_ATTRIBUTE_DIRECTORY & fd.dwFileAttributes) { // Æú´õ¸¸ if ( 0 != strcmp( fd.cFileName, ".") && 0 != strcmp( fd.cFileName, "..")) { // ÇÏÀ§ Æú´õ °æ·Î ¾ò±â char lpszSubFolder[MAX_PATH]; wsprintf( lpszSubFolder, "%s\\%s", lpszFolder, fd.cFileName); // ÇÏÀ§ Æú´õ À̸§ ÀúÀå wsprintf( lpszWrite, "\r\n0 \"%s\"\r\n", lpszSubFolder + strlen( g_lpszRootFolder) + 1); //ToLower( lpszWrite); WriteFile( hFile, lpszWrite, strlen( lpszWrite), &dwNumber, 0); if ( !ShowFolder( hFile, lpszSubFolder)) { return ( FALSE); } } } bFinding = FindNextFile( hFind, &fd); } FindClose( hFind); return ( TRUE); } void CAppBase::ToLower( char *lpszText) { for ( char *lpSeek = lpszText; *lpSeek; lpSeek++) { *lpSeek = tolower( *lpSeek); } }