240 lines
6.5 KiB
C++
240 lines
6.5 KiB
C++
|
#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
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[<5B>N<EFBFBD><4E><EFBFBD>o
|
|||
|
int Flag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
|
|||
|
Flag |= _CRTDBG_LEAK_CHECK_DF;
|
|||
|
Flag &= ~_CRTDBG_CHECK_ALWAYS_DF;
|
|||
|
_CrtSetDbgFlag( Flag );
|
|||
|
#endif
|
|||
|
|
|||
|
// <20>ȈՃE<D583>B<EFBFBD><42><EFBFBD>X<EFBFBD>`<60>F<EFBFBD>b<EFBFBD>N
|
|||
|
if( SimpleVirusChecker() > 0 ) {
|
|||
|
if( ::GetUserDefaultLCID() == 0x0411 ) {
|
|||
|
if( ::MessageBox( NULL, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>PC<EFBFBD>̓E<EFBFBD>B<EFBFBD><EFBFBD><EFBFBD>X<EFBFBD>v<EFBFBD><EFBFBD><EFBFBD>O<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ɋ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ă<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>܂<EFBFBD><EFBFBD>B\n"
|
|||
|
"<EFBFBD>댯<EFBFBD>ł<EFBFBD><EFBFBD>̂łȂ<EFBFBD><EFBFBD>ׂ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>}<7D>ɃE<C983>B<EFBFBD><42><EFBFBD>X<EFBFBD>`<60>F<EFBFBD>b<EFBFBD>N<EFBFBD><4E><EFBFBD>s<EFBFBD><73><EFBFBD>ĉ<EFBFBD><C489><EFBFBD><EFBFBD><EFBFBD><EFBFBD>B\n\n"
|
|||
|
"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ł<EFBFBD><EFBFBD><EFBFBD><EFBFBD>s<EFBFBD><EFBFBD><EFBFBD>܂<EFBFBD><EFBFBD><EFBFBD><EFBFBD>H", "VirtuaNES <20>ȈՃE<D583>B<EFBFBD><42><EFBFBD>X<EFBFBD>`<60>F<EFBFBD>b<EFBFBD>J<EFBFBD>[", 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;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD>C<EFBFBD><43><EFBFBD>t<EFBFBD><74><EFBFBD>[<5B><><EFBFBD>E<EFBFBD>C<EFBFBD><43><EFBFBD>h<EFBFBD>E<EFBFBD>I<EFBFBD>u<EFBFBD>W<EFBFBD>F<EFBFBD>N<EFBFBD>g
|
|||
|
CMainFrame MainFrame;
|
|||
|
|
|||
|
// Mutex
|
|||
|
HANDLE hMutex = NULL;
|
|||
|
|
|||
|
// <20>A<EFBFBD>v<EFBFBD><76><EFBFBD>P<EFBFBD>[<5B>V<EFBFBD><56><EFBFBD><EFBFBD><EFBFBD>C<EFBFBD><43><EFBFBD>X<EFBFBD>^<5E><><EFBFBD>X<EFBFBD><58><EFBFBD>̐ݒ<CC90>
|
|||
|
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( "VirtuaNESex.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();
|
|||
|
|
|||
|
// <20>ݒ<EFBFBD><DD92>̃<EFBFBD><CC83>[<5B>h
|
|||
|
CRegistry::SetRegistryKey( "VirtuaNESex.ini" );
|
|||
|
Config.Load();
|
|||
|
CRecent::Load();
|
|||
|
|
|||
|
// <20><><EFBFBD>d<EFBFBD>N<EFBFBD><4E><EFBFBD>̖h<CC96>~
|
|||
|
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 );
|
|||
|
|
|||
|
// <20>N<EFBFBD><4E><EFBFBD><EFBFBD><EFBFBD>Ă<EFBFBD><C482><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>t<EFBFBD>H<EFBFBD>A<EFBFBD>O<EFBFBD><4F><EFBFBD>E<EFBFBD><45><EFBFBD>h<EFBFBD>ɂ<EFBFBD><C982><EFBFBD>
|
|||
|
::SetForegroundWindow( hWnd );
|
|||
|
|
|||
|
// <20>R<EFBFBD>}<7D><><EFBFBD>h<EFBFBD><68><EFBFBD>C<EFBFBD><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȃ瓮<C882>쒆<EFBFBD><EC9286>VirtuaNES<45>̃E<CC83>C<EFBFBD><43><EFBFBD>h<EFBFBD>E<EFBFBD>Ƀt<C983>@<40>C<EFBFBD><43><EFBFBD><EFBFBD>
|
|||
|
// <20><><EFBFBD>b<EFBFBD>Z<EFBFBD>[<5B>W<EFBFBD>𑗂<EFBFBD><F0919782><EFBFBD><C282>Ă<EFBFBD><C482><EFBFBD><EFBFBD><EFBFBD><EFBFBD>œ<EFBFBD><C593>삳<EFBFBD><EC82B3><EFBFBD><EFBFBD>
|
|||
|
// (<28><><EFBFBD>R<EFBFBD>̗l<CC97>ɑΉ<C991><CE89>o<EFBFBD>[<5B>W<EFBFBD><57><EFBFBD><EFBFBD><EFBFBD>łȂ<C582><C882>ƃ_<C683><5F>)
|
|||
|
if( ::strlen( lpCmdLine ) > 0 ) {
|
|||
|
LPSTR pCmd = lpCmdLine;
|
|||
|
if( lpCmdLine[0] == '"' ) { // Shell execute!!
|
|||
|
lpCmdLine++;
|
|||
|
if( lpCmdLine[::strlen( lpCmdLine )-1] == '"' ) {
|
|||
|
lpCmdLine[::strlen( lpCmdLine )-1] = '\0';
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
COPYDATASTRUCT cds;
|
|||
|
cds.dwData = 0;
|
|||
|
cds.lpData = (void*)lpCmdLine;
|
|||
|
cds.cbData = ::strlen(lpCmdLine)+1; // <20>I<EFBFBD>[<5B><>NULL<4C><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>M
|
|||
|
::SendMessage( hWnd, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds );
|
|||
|
}
|
|||
|
|
|||
|
// <20>I<EFBFBD><49>
|
|||
|
goto _DoubleExecute_Exit;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if( !MainFrame.Create(NULL) )
|
|||
|
goto _Error_Exit;
|
|||
|
DEBUGOUT( "CreateWindow ok.\n" );
|
|||
|
|
|||
|
// <20><><EFBFBD>C<EFBFBD><43><EFBFBD>E<EFBFBD>C<EFBFBD><43><EFBFBD>h<EFBFBD>E<EFBFBD>̕\<5C><>
|
|||
|
::ShowWindow( CApp::GetHWnd(), CApp::GetCmdShow() );
|
|||
|
::UpdateWindow( CApp::GetHWnd() );
|
|||
|
|
|||
|
// <20>t<EFBFBD>b<EFBFBD>N
|
|||
|
CWndHook::Initialize();
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>`<60><><EFBFBD>[<5B><><EFBFBD><EFBFBD><EFBFBD>N<EFBFBD><4E>
|
|||
|
if( Config.general.bStartupLauncher ) {
|
|||
|
::PostMessage( CApp::GetHWnd(), WM_COMMAND, ID_LAUNCHER, 0 );
|
|||
|
}
|
|||
|
|
|||
|
// <20>R<EFBFBD>}<7D><><EFBFBD>h<EFBFBD><68><EFBFBD>C<EFBFBD><43>
|
|||
|
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 );
|
|||
|
} else {
|
|||
|
CHAR tmpPath[100];
|
|||
|
|
|||
|
if( ::strlen( Config.path.szRomAutoRunPath ) > 4 ) {
|
|||
|
if( Config.path.szRomAutoRunPath[0] == '\\' ) { // <20><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>1 "\\file.nes"
|
|||
|
::wsprintf(tmpPath, "%s\\roms\\%s", ModulePath.c_str(), Config.path.szRomAutoRunPath);
|
|||
|
} else if( Config.path.szRomAutoRunPath[0] == '.' ) { // <20><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>2 ".\\file.nes"
|
|||
|
::wsprintf(tmpPath, "%s%s", ModulePath.c_str(), Config.path.szRomAutoRunPath + 2);
|
|||
|
} else if( Config.path.szRomAutoRunPath[1] == ':' ) { // ȫ·<C8AB><C2B7>
|
|||
|
::wsprintf(tmpPath, "%s", Config.path.szRomAutoRunPath);
|
|||
|
} else { //full path
|
|||
|
::wsprintf(tmpPath, "%s", Config.path.szRomAutoRunPath);
|
|||
|
}
|
|||
|
|
|||
|
DEBUGOUT("Ĭ<EFBFBD><EFBFBD>ROM PATH: %s\n", tmpPath);
|
|||
|
::PostMessage(CApp::GetHWnd(), WM_VNS_COMMANDLINE, 0, (LPARAM)tmpPath);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
MSG msg;
|
|||
|
BOOL bRet;
|
|||
|
while( (bRet = ::GetMessage( &msg, NULL, 0, 0 )) != 0 ) {
|
|||
|
// <20>G<EFBFBD><47><EFBFBD>[<5B>H
|
|||
|
if( bRet == -1 )
|
|||
|
break;
|
|||
|
// <20><><EFBFBD>C<EFBFBD><43><EFBFBD>E<EFBFBD>C<EFBFBD><43><EFBFBD>h<EFBFBD>E<EFBFBD>̃<EFBFBD><CC83>b<EFBFBD>Z<EFBFBD>[<5B>W<EFBFBD>t<EFBFBD>B<EFBFBD><42><EFBFBD>^<5E><><EFBFBD><EFBFBD><EFBFBD>O
|
|||
|
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 );
|
|||
|
}
|
|||
|
// <20>t<EFBFBD>b<EFBFBD>N
|
|||
|
CWndHook::Release();
|
|||
|
|
|||
|
// <20>ݒ<EFBFBD><DD92>̕ۑ<CC95>
|
|||
|
CRegistry::SetRegistryKey( "VirtuaNESex.ini" );
|
|||
|
Config.Save();
|
|||
|
CRecent::Save();
|
|||
|
|
|||
|
// DirectX<74>n<EFBFBD>j<EFBFBD><6A>
|
|||
|
DirectDraw.ReleaseDDraw();
|
|||
|
DirectSound.ReleaseDSound();
|
|||
|
DirectInput.ReleaseDInput();
|
|||
|
|
|||
|
if( hMutex )
|
|||
|
::ReleaseMutex( hMutex );
|
|||
|
CLOSEHANDLE( hMutex );
|
|||
|
|
|||
|
_DoubleExecute_Exit:
|
|||
|
::FreeLibrary( CApp::GetPlugin() );
|
|||
|
|
|||
|
return msg.wParam;
|
|||
|
|
|||
|
_Error_Exit:
|
|||
|
// DirectX<74>n<EFBFBD>j<EFBFBD><6A>
|
|||
|
DirectDraw.ReleaseDDraw();
|
|||
|
DirectSound.ReleaseDSound();
|
|||
|
DirectInput.ReleaseDInput();
|
|||
|
|
|||
|
if( CApp::GetPlugin() ) {
|
|||
|
::FreeLibrary( CApp::GetPlugin() );
|
|||
|
}
|
|||
|
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|