2010-05-22 04:47:15 +00:00
|
|
|
#include "stdafx.h"
|
2012-12-29 10:50:45 +00:00
|
|
|
#include <Tlhelp32.h>
|
2008-09-18 03:15:49 +00:00
|
|
|
//#pragma comment(linker,"/merge:.rdata=.text")
|
|
|
|
|
|
|
|
void FixUPXIssue ( BYTE * ProgramLocation )
|
|
|
|
{
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
DWORD VirtualAddress;
|
|
|
|
DWORD SizeOfRawData;
|
|
|
|
DWORD Characteristics;
|
|
|
|
} ORIGINAL_SECTION;
|
|
|
|
|
|
|
|
char FileName[MAX_PATH];
|
|
|
|
GetModuleFileName((HMODULE)ProgramLocation,FileName,sizeof(FileName));
|
|
|
|
|
|
|
|
|
|
|
|
HANDLE hFile = CreateFile(FileName,GENERIC_READ,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,OPEN_ALWAYS,0,NULL);
|
|
|
|
DWORD TestID, NoOfSections, dwRead;
|
|
|
|
SetFilePointer(hFile,-4,0,FILE_END);
|
|
|
|
ReadFile(hFile,&TestID,4,&dwRead,NULL);
|
|
|
|
|
|
|
|
if (TestID != 0x3345505a)
|
|
|
|
{
|
|
|
|
/* //Read Dos Header from file
|
|
|
|
IMAGE_DOS_HEADER * DosHeader = (IMAGE_DOS_HEADER *)ProgramLocation;
|
|
|
|
if (DosHeader->e_magic != IMAGE_DOS_SIGNATURE )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Read NT (PE) Header
|
|
|
|
IMAGE_NT_HEADERS * NTHeader = (IMAGE_NT_HEADERS *)(ProgramLocation + DosHeader->e_lfanew);
|
|
|
|
if (NTHeader->Signature != IMAGE_NT_SIGNATURE )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMAGE_SECTION_HEADER * Sections = (IMAGE_SECTION_HEADER *)(ProgramLocation + DosHeader->e_lfanew +
|
|
|
|
sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + NTHeader->FileHeader.SizeOfOptionalHeader);
|
|
|
|
|
|
|
|
for (int count = 0; count < NTHeader->FileHeader.NumberOfSections; count ++ )
|
|
|
|
{
|
|
|
|
IMAGE_SECTION_HEADER & Section = Sections[count];
|
|
|
|
LPVOID Address = ProgramLocation + Section.VirtualAddress;
|
|
|
|
MEMORY_BASIC_INFORMATION Buffer;
|
|
|
|
if (VirtualQuery(Address,&Buffer,sizeof(Buffer)))
|
|
|
|
{
|
|
|
|
DWORD OldProtect = Buffer.Protect;
|
|
|
|
//VirtualProtect(Address, Section.SizeOfRawData,PAGE_READONLY,&OldProtect);
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
CloseHandle(hFile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SetFilePointer(hFile,-8,0,FILE_END);
|
|
|
|
ReadFile(hFile,&NoOfSections,4,&dwRead,NULL);
|
|
|
|
|
|
|
|
ORIGINAL_SECTION * Section = new ORIGINAL_SECTION[NoOfSections];
|
|
|
|
DWORD SizeOfSections = (NoOfSections * sizeof(ORIGINAL_SECTION));
|
|
|
|
|
|
|
|
SetFilePointer(hFile,(8 + SizeOfSections) * -1,0,FILE_END);
|
|
|
|
ReadFile(hFile,Section,SizeOfSections,&dwRead,NULL);
|
|
|
|
|
2010-09-22 21:43:42 +00:00
|
|
|
for (DWORD count = 0; count < NoOfSections; count ++ )
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
LPVOID Address = ProgramLocation + Section[count].VirtualAddress;
|
|
|
|
MEMORY_BASIC_INFORMATION Buffer;
|
|
|
|
|
|
|
|
if (VirtualQuery(Address,&Buffer,sizeof(Buffer)))
|
|
|
|
{
|
|
|
|
DWORD MemoryProctect = PAGE_EXECUTE_READWRITE;
|
|
|
|
switch (Section[count].Characteristics & 0xF0000000)
|
|
|
|
{
|
|
|
|
case 0x20000000: MemoryProctect = PAGE_EXECUTE; break;
|
|
|
|
case 0x40000000: MemoryProctect = PAGE_READONLY; break;
|
|
|
|
case 0x60000000: MemoryProctect = PAGE_EXECUTE_READ; break;
|
|
|
|
case 0x80000000: MemoryProctect = PAGE_READWRITE; break;
|
|
|
|
case 0xA0000000: MemoryProctect = PAGE_EXECUTE_READWRITE; break;
|
|
|
|
case 0xC0000000: MemoryProctect = PAGE_READWRITE; break;
|
|
|
|
case 0xE0000000: MemoryProctect = PAGE_EXECUTE_READWRITE; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Buffer.Protect != MemoryProctect)
|
|
|
|
{
|
|
|
|
DWORD OldProtect;
|
|
|
|
VirtualProtect(Address, Section[count].SizeOfRawData,MemoryProctect,&OldProtect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete [] Section;
|
|
|
|
CloseHandle(hFile);
|
|
|
|
/*
|
|
|
|
|
|
|
|
//Read Dos Header from file
|
|
|
|
IMAGE_DOS_HEADER * DosHeader = (IMAGE_DOS_HEADER *)ProgramLocation;
|
|
|
|
if (DosHeader->e_magic != IMAGE_DOS_SIGNATURE )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Read NT (PE) Header
|
|
|
|
IMAGE_NT_HEADERS * NTHeader = (IMAGE_NT_HEADERS *)(ProgramLocation + DosHeader->e_lfanew);
|
|
|
|
if (NTHeader->Signature != IMAGE_NT_SIGNATURE )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD a = sizeof(DWORD);
|
|
|
|
DWORD b = sizeof(IMAGE_FILE_HEADER);
|
|
|
|
IMAGE_SECTION_HEADER * Sections = (IMAGE_SECTION_HEADER *)(ProgramLocation + DosHeader->e_lfanew +
|
|
|
|
sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + NTHeader->FileHeader.SizeOfOptionalHeader);
|
|
|
|
|
|
|
|
for (int count = 0; count < NTHeader->FileHeader.NumberOfSections; count ++ )
|
|
|
|
{
|
|
|
|
IMAGE_SECTION_HEADER & Section = Sections[count];
|
|
|
|
if (_stricmp((char *)Section.Name,".rdata") == 0)
|
|
|
|
{
|
|
|
|
LPVOID Address = ProgramLocation + Section.VirtualAddress;
|
|
|
|
MEMORY_BASIC_INFORMATION Buffer;
|
|
|
|
if (VirtualQuery(Address,&Buffer,sizeof(Buffer)))
|
|
|
|
{
|
|
|
|
if (Buffer.Protect != 2)
|
|
|
|
{
|
|
|
|
DWORD OldProtect;
|
|
|
|
VirtualProtect(Address, Section.SizeOfRawData,PAGE_READONLY,&OldProtect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//break;
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
2010-06-04 06:25:07 +00:00
|
|
|
CTraceFileLog * LogFile = NULL;
|
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
void LogLevelChanged (CTraceFileLog * LogFile)
|
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
LogFile->SetTraceLevel((TraceLevel)g_Settings->LoadDword(Debugger_AppLogLevel));
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LogFlushChanged (CTraceFileLog * LogFile)
|
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
LogFile->SetFlushFile(g_Settings->LoadDword(Debugger_AppLogFlush) != 0);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InitializeLog ( void)
|
|
|
|
{
|
2010-05-14 23:28:15 +00:00
|
|
|
CPath LogFilePath(CPath::MODULE_DIRECTORY);
|
|
|
|
LogFilePath.AppendDirectory("Logs");
|
|
|
|
if (!LogFilePath.DirectoryExists())
|
|
|
|
{
|
|
|
|
LogFilePath.CreateDirectory();
|
|
|
|
}
|
|
|
|
LogFilePath.SetNameExtension(_T("Project64.log"));
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2012-11-17 01:02:04 +00:00
|
|
|
LogFile = new CTraceFileLog(LogFilePath, g_Settings->LoadDword(Debugger_AppLogFlush) != 0, Log_New,500);
|
2008-11-17 10:02:22 +00:00
|
|
|
#ifdef VALIDATE_DEBUG
|
2012-11-17 01:02:04 +00:00
|
|
|
LogFile->SetTraceLevel((TraceLevel)(g_Settings->LoadDword(Debugger_AppLogLevel) | TraceValidate));
|
2008-11-17 10:02:22 +00:00
|
|
|
#else
|
2012-11-17 01:02:04 +00:00
|
|
|
LogFile->SetTraceLevel((TraceLevel)g_Settings->LoadDword(Debugger_AppLogLevel));
|
2008-11-17 10:02:22 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
AddTraceModule(LogFile);
|
|
|
|
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->RegisterChangeCB(Debugger_AppLogLevel,LogFile,(CSettings::SettingChangedFunc)LogLevelChanged);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_AppLogFlush,LogFile,(CSettings::SettingChangedFunc)LogFlushChanged);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-06-04 06:25:07 +00:00
|
|
|
|
2010-05-14 23:28:15 +00:00
|
|
|
/*bool ChangeDirPermission ( const CPath & Dir)
|
|
|
|
{
|
|
|
|
if (Dir.DirectoryExists())
|
|
|
|
{
|
|
|
|
HANDLE hDir = CreateFile(Dir,READ_CONTROL|WRITE_DAC,0,NULL,OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,NULL);
|
|
|
|
if (hDir != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ACL * pOldDACL = NULL;
|
|
|
|
PSECURITY_DESCRIPTOR pSD = NULL;
|
|
|
|
|
|
|
|
if (GetSecurityInfo(hDir,SE_FILE_OBJECT,DACL_SECURITY_INFORMATION,NULL,NULL,&pOldDACL,NULL,&pSD) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
bool bAdd = true;
|
|
|
|
|
|
|
|
PEXPLICIT_ACCESS_W pListOfExplictEntries;
|
|
|
|
ULONG cCountOfExplicitEntries;
|
|
|
|
if (GetExplicitEntriesFromAclW(pOldDACL,&cCountOfExplicitEntries,&pListOfExplictEntries) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < cCountOfExplicitEntries; i ++)
|
|
|
|
{
|
|
|
|
EXPLICIT_ACCESS_W &ea = pListOfExplictEntries[i];
|
|
|
|
if (ea.grfAccessMode != GRANT_ACCESS) { continue; }
|
|
|
|
if (ea.grfAccessPermissions != GENERIC_ALL) { continue; }
|
|
|
|
if ((ea.grfInheritance & (CONTAINER_INHERIT_ACE|OBJECT_INHERIT_ACE)) != (CONTAINER_INHERIT_ACE|OBJECT_INHERIT_ACE)) { continue; }
|
|
|
|
|
|
|
|
if (ea.Trustee.TrusteeType == TRUSTEE_IS_SID)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
bAdd = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bAdd)
|
|
|
|
{
|
|
|
|
EXPLICIT_ACCESS ea = {0};
|
|
|
|
ea.grfAccessMode = GRANT_ACCESS;
|
|
|
|
ea.grfAccessPermissions = GENERIC_ALL;
|
|
|
|
ea.grfInheritance = CONTAINER_INHERIT_ACE|OBJECT_INHERIT_ACE;
|
|
|
|
ea.Trustee.TrusteeType = TRUSTEE_IS_GROUP;
|
|
|
|
ea.Trustee.TrusteeForm = TRUSTEE_IS_NAME;
|
|
|
|
ea.Trustee.ptstrName = TEXT("Users");
|
|
|
|
|
|
|
|
ACL * pNewDACL = NULL;
|
|
|
|
SetEntriesInAcl(1,&ea,pOldDACL,&pNewDACL);
|
|
|
|
|
|
|
|
SetSecurityInfo(hDir,SE_FILE_OBJECT,DACL_SECURITY_INFORMATION,NULL,NULL,pNewDACL,NULL);
|
|
|
|
LocalFree(pNewDACL);
|
|
|
|
}
|
|
|
|
LocalFree(pSD);
|
|
|
|
}
|
|
|
|
CloseHandle(hDir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
void FixDirectories ( void )
|
|
|
|
{
|
2010-05-16 06:27:33 +00:00
|
|
|
CPath Directory(CPath::MODULE_DIRECTORY);
|
|
|
|
Directory.AppendDirectory(_T("Config"));
|
2013-04-15 03:52:34 +00:00
|
|
|
if (!Directory.DirectoryExists()) Directory.CreateDirectory();
|
2010-05-16 06:27:33 +00:00
|
|
|
|
|
|
|
Directory.UpDirectory();
|
|
|
|
Directory.AppendDirectory("Logs");
|
2013-04-15 03:52:34 +00:00
|
|
|
if (!Directory.DirectoryExists()) Directory.CreateDirectory();
|
2010-05-16 06:27:33 +00:00
|
|
|
|
|
|
|
Directory.UpDirectory();
|
|
|
|
Directory.AppendDirectory("Save");
|
2013-04-15 03:52:34 +00:00
|
|
|
if (!Directory.DirectoryExists()) Directory.CreateDirectory();
|
2010-05-16 06:27:33 +00:00
|
|
|
|
|
|
|
Directory.UpDirectory();
|
|
|
|
Directory.AppendDirectory("Screenshots");
|
2013-04-15 03:52:34 +00:00
|
|
|
if (!Directory.DirectoryExists()) Directory.CreateDirectory();
|
2013-04-28 05:49:14 +00:00
|
|
|
|
|
|
|
Directory.UpDirectory();
|
|
|
|
Directory.AppendDirectory("textures");
|
|
|
|
if (!Directory.DirectoryExists()) Directory.CreateDirectory();
|
2010-05-14 23:28:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-29 10:50:45 +00:00
|
|
|
bool TerminatedExistingEmu()
|
|
|
|
{
|
|
|
|
bool bTerminated = false;
|
|
|
|
bool AskedUser = false;
|
|
|
|
DWORD pid = GetCurrentProcessId();
|
|
|
|
|
|
|
|
HANDLE nSearch = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
|
|
|
if(nSearch != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
PROCESSENTRY32 lppe;
|
|
|
|
|
|
|
|
memset(&lppe, 0, sizeof(PROCESSENTRY32));
|
|
|
|
lppe.dwSize = sizeof(PROCESSENTRY32);
|
|
|
|
stdstr ModuleName = CPath(CPath::MODULE_FILE).GetNameExtension();
|
|
|
|
|
|
|
|
if (Process32First(nSearch, &lppe))
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if(_stricmp(lppe.szExeFile, ModuleName.c_str()) != 0 ||
|
|
|
|
lppe.th32ProcessID == pid)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!AskedUser)
|
|
|
|
{
|
|
|
|
AskedUser = true;
|
|
|
|
int res = MessageBox(NULL,stdstr_f("Project64.exe currently running\n\nTerminate pid %d now?",lppe.th32ProcessID).c_str(),"Terminate project64",MB_YESNO|MB_ICONEXCLAMATION);
|
|
|
|
if (res != IDYES)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HANDLE hHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, lppe.th32ProcessID);
|
|
|
|
if(hHandle != NULL)
|
|
|
|
{
|
|
|
|
if (TerminateProcess(hHandle, 0))
|
|
|
|
{
|
|
|
|
bTerminated = true;
|
|
|
|
} else {
|
|
|
|
MessageBox(NULL,stdstr_f("Failed to terminate pid %d",lppe.th32ProcessID).c_str(),"Terminate project64 failed!",MB_YESNO|MB_ICONEXCLAMATION);
|
|
|
|
}
|
|
|
|
CloseHandle(hHandle);
|
|
|
|
}
|
|
|
|
} while (Process32Next(nSearch, &lppe));
|
|
|
|
}
|
|
|
|
CloseHandle(nSearch);
|
|
|
|
}
|
|
|
|
return bTerminated;
|
|
|
|
}
|
|
|
|
|
2012-10-05 09:20:53 +00:00
|
|
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpszArgs*/, int /*nWinMode*/)
|
2010-05-14 23:28:15 +00:00
|
|
|
{
|
|
|
|
FixDirectories();
|
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
CoInitialize(NULL);
|
|
|
|
try
|
|
|
|
{
|
2012-09-22 05:53:39 +00:00
|
|
|
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL );
|
2012-12-20 09:19:17 +00:00
|
|
|
LPCSTR AppName = "Project64 2.0";
|
2008-09-18 03:15:49 +00:00
|
|
|
_Lang = new CLanguage();
|
|
|
|
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings = new CSettings;
|
|
|
|
g_Settings->Initilize(AppName);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2012-12-29 10:50:45 +00:00
|
|
|
if (g_Settings->LoadBool(Setting_CheckEmuRunning) &&
|
|
|
|
TerminatedExistingEmu())
|
|
|
|
{
|
|
|
|
delete g_Settings;
|
|
|
|
g_Settings = new CSettings;
|
|
|
|
g_Settings->Initilize(AppName);
|
|
|
|
}
|
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
InitializeLog();
|
|
|
|
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceDebug,__FUNCTION__ ": Application Starting");
|
2008-09-18 03:15:49 +00:00
|
|
|
FixUPXIssue((BYTE *)hInstance);
|
|
|
|
|
2012-12-18 10:43:29 +00:00
|
|
|
CMipsMemoryVM::ReserveMemory();
|
|
|
|
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify = &Notify();
|
2010-05-22 04:47:15 +00:00
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
//Create the plugin container
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceDebug,__FUNCTION__ ": Create Plugins");
|
2012-11-17 02:20:21 +00:00
|
|
|
g_Plugins = new CPlugins(g_Settings->LoadString(Directory_Plugin));
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Select the language
|
|
|
|
_Lang->LoadCurrentStrings(true);
|
|
|
|
|
|
|
|
//Create the main window with Menu
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceDebug,__FUNCTION__ ": Create Main Window");
|
2008-09-18 03:15:49 +00:00
|
|
|
stdstr WinTitle(AppName);
|
2013-03-22 05:47:20 +00:00
|
|
|
#ifdef BETA_RELEASE
|
|
|
|
WinTitle.Format("Project64 %s (%s)",VersionInfo(VERSION_PRODUCT_VERSION).c_str(),g_Settings->LoadString(Beta_UserName).c_str());
|
|
|
|
#else
|
|
|
|
WinTitle.Format("Project64 %s",VersionInfo(VERSION_PRODUCT_VERSION).c_str());
|
|
|
|
#endif
|
2010-05-22 04:47:15 +00:00
|
|
|
CMainGui MainWindow(true,WinTitle.c_str()), HiddenWindow(false);
|
|
|
|
CMainMenu MainMenu(&MainWindow);
|
2012-11-17 02:20:21 +00:00
|
|
|
g_Plugins->SetRenderWindows(&MainWindow,&HiddenWindow);
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->SetMainWindow(&MainWindow);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2013-03-22 05:47:20 +00:00
|
|
|
#ifdef BETA_RELEASE
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr_f User("%s",g_Settings->LoadString(Beta_UserName).c_str());
|
|
|
|
stdstr_f Email("%s",g_Settings->LoadString(Beta_EmailAddress).c_str());
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2012-11-17 01:02:04 +00:00
|
|
|
if (MD5(User).hex_digest() != g_Settings->LoadString(Beta_UserNameMD5) ||
|
|
|
|
MD5(Email).hex_digest() != g_Settings->LoadString(Beta_EmailAddressMD5))
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-03-22 05:47:20 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
if (__argc > 1) {
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTraceF(TraceDebug,__FUNCTION__ ": Cmd line found \"%s\"",__argv[1]);
|
2008-09-18 03:15:49 +00:00
|
|
|
MainWindow.Show(true); //Show the main window
|
2010-05-22 04:47:15 +00:00
|
|
|
CN64System::RunFileImage(__argv[1]);
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
2012-11-17 01:02:04 +00:00
|
|
|
if (g_Settings->LoadDword(RomBrowser_Enabled))
|
2008-11-14 20:51:06 +00:00
|
|
|
{
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceDebug,__FUNCTION__ ": Show Rom Browser");
|
2008-09-18 03:15:49 +00:00
|
|
|
//Display the rom browser
|
|
|
|
MainWindow.ShowRomList();
|
|
|
|
MainWindow.Show(true); //Show the main window
|
|
|
|
MainWindow.HighLightLastRom();
|
|
|
|
} else {
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceDebug,__FUNCTION__ ": Show Main Window");
|
2008-09-18 03:15:49 +00:00
|
|
|
MainWindow.Show(true); //Show the main window
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Process Messages till program is closed
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceDebug,__FUNCTION__ ": Entering Message Loop");
|
2008-09-18 03:15:49 +00:00
|
|
|
MainWindow.ProcessAllMessages();
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceDebug,__FUNCTION__ ": Message Loop Finished");
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2012-11-17 01:09:19 +00:00
|
|
|
if (g_BaseSystem)
|
2010-05-22 04:47:15 +00:00
|
|
|
{
|
2012-11-17 01:09:19 +00:00
|
|
|
g_BaseSystem->CloseCpu();
|
|
|
|
delete g_BaseSystem;
|
|
|
|
g_BaseSystem = NULL;
|
2010-05-22 04:47:15 +00:00
|
|
|
}
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceDebug,__FUNCTION__ ": System Closed");
|
2010-06-04 06:25:07 +00:00
|
|
|
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->UnregisterChangeCB(Debugger_AppLogLevel,LogFile,(CSettings::SettingChangedFunc)LogLevelChanged);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_AppLogFlush,LogFile,(CSettings::SettingChangedFunc)LogFlushChanged);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTraceF(TraceError,__FUNCTION__ ": Exception caught (File: \"%s\" Line: %d)",__FILE__,__LINE__);
|
2008-09-18 03:15:49 +00:00
|
|
|
MessageBox(NULL,stdstr_f("Exception caught\nFile: %s\nLine: %d",__FILE__,__LINE__).c_str(),"Exception",MB_OK);
|
|
|
|
}
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceDebug,__FUNCTION__ ": cleaning up global objects");
|
2010-05-22 04:47:15 +00:00
|
|
|
|
2012-11-17 02:24:42 +00:00
|
|
|
if (g_Rom) { delete g_Rom; g_Rom = NULL; }
|
2012-11-17 02:20:21 +00:00
|
|
|
if (g_Plugins) { delete g_Plugins; g_Plugins = NULL; }
|
2012-11-17 01:02:04 +00:00
|
|
|
if (g_Settings) { delete g_Settings; g_Settings = NULL; }
|
2010-05-22 04:47:15 +00:00
|
|
|
if (_Lang) { delete _Lang; _Lang = NULL; }
|
|
|
|
|
2012-12-18 23:55:05 +00:00
|
|
|
CMipsMemoryVM::FreeReservedMemory();
|
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
CoUninitialize();
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceDebug,__FUNCTION__ ": Done");
|
2008-09-18 03:15:49 +00:00
|
|
|
CloseTrace();
|
|
|
|
return true;
|
|
|
|
}
|