project64/Source/Project64/main.cpp

110 lines
4.2 KiB
C++
Raw Normal View History

2016-01-27 09:11:59 +00:00
#include "stdafx.h"
2022-09-21 05:16:07 +00:00
2021-02-28 21:32:50 +00:00
#include "Settings/UISettings.h"
2022-09-21 05:16:07 +00:00
#include "UserInterface/WelcomeScreen.h"
#include <Project64-core/AppInit.h>
2016-01-27 09:11:59 +00:00
int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /*lpszArgs*/, int /*nWinMode*/)
{
try
{
2021-04-12 11:35:39 +00:00
CoInitialize(nullptr);
AppInit(&Notify(), CPath(CPath::MODULE_DIRECTORY), __argc, __argv);
2016-01-27 09:11:59 +00:00
if (!g_Lang->IsLanguageLoaded())
{
WelcomeScreen().DoModal();
2016-01-27 09:11:59 +00:00
}
// Create the main window with menu
2022-09-21 05:16:07 +00:00
WriteTrace(TraceUserInterface, TraceDebug, "Create main window");
2017-06-18 23:08:35 +00:00
CMainGui MainWindow(true, stdstr_f("Project64 %s", VER_FILE_VERSION_STR).c_str()), HiddenWindow(false);
2016-01-27 09:11:59 +00:00
CMainMenu MainMenu(&MainWindow);
CDebuggerUI Debugger;
g_Debugger = &Debugger;
2016-01-27 09:11:59 +00:00
g_Plugins->SetRenderWindows(&MainWindow, &HiddenWindow);
Notify().SetMainWindow(&MainWindow);
bool isROMLoaded = false;
2016-01-27 09:11:59 +00:00
if (CDebuggerUI::HaveDebugger())
{
Debugger.StartAutorunScripts();
}
if (g_Settings->LoadStringVal(Cmd_RomFile).length() > 0 && g_Settings->LoadStringVal(Cmd_ComboDiskFile).length() > 0)
2016-01-27 09:11:59 +00:00
{
// Handle combo loading (N64 ROM and 64DD Disk)
2022-09-21 05:16:07 +00:00
MainWindow.Show(true);
stdstr extcombo = CPath(g_Settings->LoadStringVal(Cmd_ComboDiskFile)).GetExtension();
stdstr ext = CPath(g_Settings->LoadStringVal(Cmd_RomFile)).GetExtension();
2022-09-21 05:16:07 +00:00
if (g_Settings->LoadStringVal(Cmd_ComboDiskFile).length() > 0 && ((_stricmp(extcombo.c_str(), "ndd") == 0) || (_stricmp(extcombo.c_str(), "d64") == 0)))
{
if ((!(_stricmp(ext.c_str(), "ndd") == 0)) && (!(_stricmp(ext.c_str(), "d64") == 0)))
{
// Cmd_ComboDiskFile must be a 64DD disk image
// Cmd_RomFile must be an N64 ROM image
isROMLoaded = CN64System::RunDiskComboImage(g_Settings->LoadStringVal(Cmd_RomFile).c_str(), g_Settings->LoadStringVal(Cmd_ComboDiskFile).c_str());
}
}
}
else if (g_Settings->LoadStringVal(Cmd_RomFile).length() > 0)
{
// Handle single game (N64 ROM or 64DD Disk)
2022-09-21 05:16:07 +00:00
MainWindow.Show(true);
stdstr ext = CPath(g_Settings->LoadStringVal(Cmd_RomFile)).GetExtension();
2019-08-11 16:13:52 +00:00
if ((!(_stricmp(ext.c_str(), "ndd") == 0)) && (!(_stricmp(ext.c_str(), "d64") == 0)))
{
// File extension is not *.ndd/*.d64 so it should be an N64 ROM
isROMLoaded = CN64System::RunFileImage(g_Settings->LoadStringVal(Cmd_RomFile).c_str());
}
else
{
2021-03-03 07:22:41 +00:00
// File extension is *.ndd/*.d64, so it should be an N64 disk image
isROMLoaded = CN64System::RunDiskImage(g_Settings->LoadStringVal(Cmd_RomFile).c_str());
}
2016-01-27 09:11:59 +00:00
}
if (!isROMLoaded)
2016-01-27 09:11:59 +00:00
{
2020-10-22 02:11:19 +00:00
CSupportWindow(MainWindow.Support()).Show((HWND)MainWindow.GetWindowHandle(), true);
if (UISettingsLoadBool(RomBrowser_Enabled))
2016-01-27 09:11:59 +00:00
{
WriteTrace(TraceUserInterface, TraceDebug, "Show ROM browser");
2016-01-27 09:11:59 +00:00
MainWindow.ShowRomList();
2020-10-22 02:11:19 +00:00
MainWindow.Show(true);
2016-01-27 09:11:59 +00:00
MainWindow.HighLightLastRom();
}
else
{
WriteTrace(TraceUserInterface, TraceDebug, "Show main window");
2020-10-22 02:11:19 +00:00
MainWindow.Show(true);
2016-01-27 09:11:59 +00:00
}
}
WriteTrace(TraceUserInterface, TraceDebug, "Entering message loop");
2016-01-27 09:11:59 +00:00
MainWindow.ProcessAllMessages();
WriteTrace(TraceUserInterface, TraceDebug, "Message loop finished");
2016-01-27 09:11:59 +00:00
if (g_BaseSystem)
{
g_BaseSystem->CloseCpu();
delete g_BaseSystem;
2021-04-12 11:35:39 +00:00
g_BaseSystem = nullptr;
2016-01-27 09:11:59 +00:00
}
WriteTrace(TraceUserInterface, TraceDebug, "System closed");
2016-01-27 09:11:59 +00:00
}
catch (...)
{
WriteTrace(TraceUserInterface, TraceError, "Exception caught (File: \"%s\" Line: %d)", __FILE__, __LINE__);
2021-04-12 11:35:39 +00:00
MessageBox(nullptr, stdstr_f("Exception caught\nFile: %s\nLine: %d", __FILE__, __LINE__).ToUTF16().c_str(), L"Exception", MB_OK);
2016-01-27 09:11:59 +00:00
}
AppCleanup();
CoUninitialize();
return true;
}