Files
Sun1602/Tools/UpdateListGen/AppBase.cpp
T
2022-10-26 12:25:11 +08:00

279 lines
6.3 KiB
C++

// AppBase.cpp: implementation of the CAppBase class.
//
//////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <shlobj.h>
#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);
}
}