AxibugEmuOnline/virtuanessrc097-master/WinMain.cpp

225 lines
12 KiB
C++
Raw Normal View History

<EFBFBD><EFBFBD>#define INITGUID
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <crtdbg.h>
#include <string>
using namespace std;
#include "DebugOut.h"
#include "VirtuaNESres.h"
#include "App.h"
#include "Registry.h"
#include "Pathlib.h"
#include "MMTimer.h"
#include "Wnd.h"
#include "WndHook.h"
#include "MainFrame.h"
#include "Plugin.h"
#include "Config.h"
#include "Recent.h"
#include "DirectDraw.h"
#include "DirectSound.h"
#include "DirectInput.h"
#include "SimpleVirusChecker.h"
INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow )
{
#if _DEBUG
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0i<EFBFBD>Q
int Flag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
Flag |= _CRTDBG_LEAK_CHECK_DF;
Flag &= ~_CRTDBG_CHECK_ALWAYS_DF;
_CrtSetDbgFlag( Flag );
#endif
// !|f<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0
if( SimpleVirusChecker() > 0 ) {
if( ::GetUserDefaultLCID() == 0x0411 ) {
if( ::MessageBox( NULL, "S0n0PCo0<6F>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0k0a<>gW0f0D0<44>0<EFBFBD>S<EFBFBD><53>'`L0B0<42>0~0Y00\n"
"qSz<53>g0Y0n0g0j0<6A>0y0O0<4F>e%`k0<6B>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0L<30>c0f0 NU0D00\n\n"
"]0<>0g0<67>0<EFBFBD>[L<>W0~0Y0K0<1F>", "VirtuaNES !|f<>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0", MB_ICONWARNING|MB_YESNO|MB_DEFBUTTON2 ) == IDNO )
return -1L;
} else {
if( ::MessageBox( NULL, "This PC may be infected with a virus program!!!\n"
"Should become danger, and please do a check to it immediately!!!\n\n"
"Do execute even it?", "VirtuaNES simple virus checker", MB_ICONWARNING|MB_YESNO|MB_DEFBUTTON2 ) == IDNO )
return -1L;
}
}
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0
CMainFrame MainFrame;
// Mutex
HANDLE hMutex = NULL;
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0I{n0-<EFBFBD><EFBFBD>[
CHAR szPath[ _MAX_PATH ];
GetModuleFileName( hInstance, szPath, sizeof(szPath) );
string ModulePath = CPathlib::SplitPath( szPath );
CApp::SetModulePath( ModulePath.c_str() );
DEBUGOUT( "Module Path:\"%s\"\n", ModulePath.c_str() );
CApp::SetInstance( hInstance );
CApp::SetPrevInstance( hPrevInstance );
CApp::SetCmdLine( lpCmdLine );
CApp::SetCmdShow( nCmdShow );
//DEBUGOUT( "ThreadID:%08X\n", ::GetCurrentThreadId() );
// CRegistry::SetRegistryKey( "Emulators\\VirtuaNES" );
CRegistry::SetRegistryKey( "VirtuaNES.ini" );
if( !CPlugin::FindPlugin( CApp::GetModulePath() ) ) {
::MessageBox( NULL, "Language plug-in is not found.", "VirtuaNES", MB_ICONERROR|MB_OK );
goto _Error_Exit;
}
DEBUGOUT( "Plugin Path:\"%s\"\n", CPlugin::GetPluginPath() );
DEBUGOUT( "Language :\"%s\"\n", CPlugin::GetPluginLanguage() );
DEBUGOUT( "LCID :\"%d\" \"0x%04X\"\n", CPlugin::GetPluginLocaleID(), CPlugin::GetPluginLocaleID() );
HINSTANCE hPlugin;
if( !(hPlugin = CPlugin::LoadPlugin()) ) {
::MessageBox( NULL, "Language plug-in load failed.", "VirtuaNES", MB_ICONERROR|MB_OK );
goto _Error_Exit;
}
CApp::SetPlugin( hPlugin );
::InitCommonControls();
// -<EFBFBD><EFBFBD>[n0<EFBFBD>0<EFBFBD>0<EFBFBD>0
CRegistry::SetRegistryKey( "VirtuaNES.ini" );
Config.Load();
CRecent::Load();
// <EFBFBD>N͑w<EFBFBD><EFBFBD>Rn02<EFBFBD>bk
hMutex = ::CreateMutex( NULL, FALSE, VIRTUANES_MUTEX );
if( ::GetLastError() == ERROR_ALREADY_EXISTS ) {
::CloseHandle( hMutex );
if( Config.general.bDoubleExecute ) {
HWND hWnd = ::FindWindow( VIRTUANES_WNDCLASS, NULL );
// HWND hWnd = ::FindWindow( VIRTUANES_WNDCLASS, VIRTUANES_CAPTION );
CHAR szTitle[256];
::GetWindowText( hWnd, szTitle, sizeof(szTitle)-1 );
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0L0 TX0K0i0F0K0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0
if( ::strncmp( szTitle, VIRTUANES_CAPTION, ::strlen(VIRTUANES_CAPTION) ) == 0 ) {
// w<EFBFBD><EFBFBD>RW0f0D0_0<EFBFBD>e<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0k0Y0<EFBFBD>0
::SetForegroundWindow( hWnd );
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0_peL0B0<EFBFBD>0j0<EFBFBD>0<EFBFBD>R\O-Nn0VirtuaNESn0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0k0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0 T
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD><EFBFBD>0d0Q0f0]0a0<EFBFBD>0g0<EFBFBD>R\OU0[0<EFBFBD>0
// (S_6qn0<EFBFBD>ik0<EFBFBD>[<EFBFBD>_<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0g0j0D0h0<EFBFBD>0<EFBFBD>0)
if( ::strlen( lpCmdLine ) > 0 ) {
CHAR szCmdLine[_MAX_PATH];
::strcpy( szCmdLine, lpCmdLine );
::PathUnquoteSpaces( szCmdLine );
COPYDATASTRUCT cds;
cds.dwData = 0;
cds.lpData = (void*)szCmdLine;
cds.cbData = ::strlen(szCmdLine)+1; // B}<EFBFBD>zn0NULL<EFBFBD>0<EFBFBD><EFBFBD>0
// <EFBFBD>eW[R<EFBFBD><EFBFBD>O
::SendMessage( hWnd, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds );
}
// B}<EFBFBD>N
goto _DoubleExecute_Exit;
}
}
}
if( !MainFrame.Create(NULL) )
goto _Error_Exit;
DEBUGOUT( "CreateWindow ok.\n" );
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0n0h<EFBFBD>:y
::ShowWindow( CApp::GetHWnd(), CApp::GetCmdShow() );
::UpdateWindow( CApp::GetHWnd() );
// <EFBFBD>0<EFBFBD>0<EFBFBD>0
CWndHook::Initialize();
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0 TBfw<EFBFBD><EFBFBD>R
if( Config.general.bStartupLauncher ) {
::PostMessage( CApp::GetHWnd(), WM_COMMAND, ID_LAUNCHER, 0 );
}
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0
if( ::strlen( lpCmdLine ) > 0 ) {
LPSTR pCmd = lpCmdLine;
if( lpCmdLine[0] == '"' ) { // Shell execute!!
lpCmdLine++;
if( lpCmdLine[::strlen( lpCmdLine )-1] == '"' ) {
lpCmdLine[::strlen( lpCmdLine )-1] = '\0';
}
}
}
if( ::strlen( lpCmdLine ) > 0 ) {
::PostMessage( CApp::GetHWnd(), WM_VNS_COMMANDLINE, 0, (LPARAM)lpCmdLine );
}
MSG msg;
BOOL bRet;
while( (bRet = ::GetMessage( &msg, NULL, 0, 0 )) != 0 ) {
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>
if( bRet == -1 )
break;
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0n0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0
if( CApp::GetHWnd() == msg.hwnd ) {
CWnd* pWnd = (CWnd*)::GetWindowLong( msg.hwnd, GWL_USERDATA );
if( pWnd ) {
if( pWnd->PreTranslateMessage( &msg ) )
continue;
}
}
if( CWndList::IsDialogMessage( &msg ) )
continue;
::TranslateMessage( &msg );
::DispatchMessage( &msg );
}
// <EFBFBD>0<EFBFBD>0<EFBFBD>0
CWndHook::Release();
// -<EFBFBD><EFBFBD>[n0<EFBFBD>OX[
CRegistry::SetRegistryKey( "VirtuaNES.ini" );
Config.Save();
CRecent::Save();
// DirectX<EFBFBD>|4x<EFBFBD>h
DirectDraw.ReleaseDDraw();
DirectSound.ReleaseDSound();
DirectInput.ReleaseDInput();
if( hMutex )
::ReleaseMutex( hMutex );
CLOSEHANDLE( hMutex );
_DoubleExecute_Exit:
::FreeLibrary( CApp::GetPlugin() );
return msg.wParam;
_Error_Exit:
// DirectX<EFBFBD>|4x<EFBFBD>h
DirectDraw.ReleaseDDraw();
DirectSound.ReleaseDSound();
DirectInput.ReleaseDInput();
if( CApp::GetPlugin() ) {
::FreeLibrary( CApp::GetPlugin() );
}
return -1;
}