2015-11-14 20:56:40 +00:00
|
|
|
#include "stdafx.h"
|
2016-01-14 06:29:38 +00:00
|
|
|
|
2015-12-19 23:52:35 +00:00
|
|
|
#include <Common/Trace.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Common/Util.h>
|
2022-09-26 02:31:54 +00:00
|
|
|
#include <Common/path.h>
|
2016-01-13 15:14:20 +00:00
|
|
|
|
2022-09-26 02:31:54 +00:00
|
|
|
#include "Settings/SettingType/SettingsType-Application.h"
|
|
|
|
#include <Project64-core/N64System/Enhancement/Enhancements.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
|
2022-09-26 02:31:54 +00:00
|
|
|
#include <Project64-core/N64System/N64Disk.h>
|
|
|
|
#include <Project64-core/N64System/N64Rom.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/N64System/SystemGlobals.h>
|
2021-04-14 05:34:15 +00:00
|
|
|
#include <Project64-core/Plugins/Plugin.h>
|
2015-11-14 20:56:40 +00:00
|
|
|
|
2016-01-13 07:23:22 +00:00
|
|
|
static void FixDirectories(void);
|
2016-01-28 09:37:44 +00:00
|
|
|
void SetTraceModuleNames(void);
|
2015-11-14 20:56:40 +00:00
|
|
|
|
2016-01-13 07:23:22 +00:00
|
|
|
#ifdef _WIN32
|
2015-11-14 20:56:40 +00:00
|
|
|
static void IncreaseThreadPriority(void);
|
2016-01-13 07:23:22 +00:00
|
|
|
#endif
|
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
static CTraceFileLog * g_LogFile = nullptr;
|
2015-11-14 20:56:40 +00:00
|
|
|
|
|
|
|
void LogFlushChanged(CTraceFileLog * LogFile)
|
|
|
|
{
|
|
|
|
LogFile->SetFlushFile(g_Settings->LoadDword(Debugger_AppLogFlush) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitializeLog(void)
|
2015-12-14 10:51:33 +00:00
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
TraceSetMaxModule(MaxTraceModuleProject64, TraceInfo);
|
|
|
|
#else
|
|
|
|
TraceSetMaxModule(MaxTraceModuleProject64, TraceError);
|
|
|
|
#endif
|
2016-01-28 09:37:44 +00:00
|
|
|
SetTraceModuleNames();
|
2015-12-14 10:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddLogModule(void)
|
2015-11-14 20:56:40 +00:00
|
|
|
{
|
2016-05-01 02:46:43 +00:00
|
|
|
CPath LogFilePath(g_Settings->LoadStringVal(Directory_Log).c_str(), "Project64.log");
|
2015-11-14 20:56:40 +00:00
|
|
|
if (!LogFilePath.DirectoryExists())
|
|
|
|
{
|
|
|
|
LogFilePath.DirectoryCreate();
|
|
|
|
}
|
|
|
|
|
2016-04-19 10:37:41 +00:00
|
|
|
g_LogFile = new CTraceFileLog(LogFilePath, g_Settings->LoadDword(Debugger_AppLogFlush) != 0, CLog::Log_New, 500);
|
2015-12-14 10:51:33 +00:00
|
|
|
TraceAddModule(g_LogFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetTraceModuleNames(void)
|
|
|
|
{
|
|
|
|
TraceSetModuleName(TraceMD5, "MD5");
|
2016-04-17 19:34:47 +00:00
|
|
|
TraceSetModuleName(TraceThread, "Thread");
|
|
|
|
TraceSetModuleName(TracePath, "Path");
|
2015-12-14 10:51:33 +00:00
|
|
|
TraceSetModuleName(TraceSettings, "Settings");
|
|
|
|
TraceSetModuleName(TraceUnknown, "Unknown");
|
|
|
|
TraceSetModuleName(TraceAppInit, "App Init");
|
|
|
|
TraceSetModuleName(TraceAppCleanup, "App Cleanup");
|
|
|
|
TraceSetModuleName(TraceN64System, "N64 System");
|
|
|
|
TraceSetModuleName(TracePlugins, "Plugins");
|
2022-06-27 10:02:38 +00:00
|
|
|
TraceSetModuleName(TraceVideoPlugin, "GFX Plugin");
|
2015-12-14 10:51:33 +00:00
|
|
|
TraceSetModuleName(TraceAudioPlugin, "Audio Plugin");
|
|
|
|
TraceSetModuleName(TraceControllerPlugin, "Controller Plugin");
|
|
|
|
TraceSetModuleName(TraceRSPPlugin, "RSP Plugin");
|
|
|
|
TraceSetModuleName(TraceRSP, "RSP");
|
|
|
|
TraceSetModuleName(TraceAudio, "Audio");
|
|
|
|
TraceSetModuleName(TraceRegisterCache, "Register Cache");
|
|
|
|
TraceSetModuleName(TraceRecompiler, "Recompiler");
|
|
|
|
TraceSetModuleName(TraceTLB, "TLB");
|
|
|
|
TraceSetModuleName(TraceProtectedMem, "Protected Memory");
|
|
|
|
TraceSetModuleName(TraceUserInterface, "User Interface");
|
2016-04-17 19:06:30 +00:00
|
|
|
TraceSetModuleName(TraceRomList, "Rom List");
|
2016-06-04 08:28:30 +00:00
|
|
|
TraceSetModuleName(TraceExceptionHandler, "Exception Handler");
|
2015-12-14 10:51:33 +00:00
|
|
|
}
|
2015-11-14 20:56:40 +00:00
|
|
|
|
2015-12-14 10:51:33 +00:00
|
|
|
void UpdateTraceLevel(void * /*NotUsed*/)
|
|
|
|
{
|
|
|
|
g_ModuleLogLevel[TraceMD5] = (uint8_t)g_Settings->LoadDword(Debugger_TraceMD5);
|
2016-04-17 19:34:47 +00:00
|
|
|
g_ModuleLogLevel[TraceThread] = (uint8_t)g_Settings->LoadDword(Debugger_TraceThread);
|
|
|
|
g_ModuleLogLevel[TracePath] = (uint8_t)g_Settings->LoadDword(Debugger_TracePath);
|
2015-12-14 10:51:33 +00:00
|
|
|
g_ModuleLogLevel[TraceSettings] = (uint8_t)g_Settings->LoadDword(Debugger_TraceSettings);
|
|
|
|
g_ModuleLogLevel[TraceUnknown] = (uint8_t)g_Settings->LoadDword(Debugger_TraceUnknown);
|
|
|
|
g_ModuleLogLevel[TraceAppInit] = (uint8_t)g_Settings->LoadDword(Debugger_TraceAppInit);
|
|
|
|
g_ModuleLogLevel[TraceAppCleanup] = (uint8_t)g_Settings->LoadDword(Debugger_TraceAppCleanup);
|
|
|
|
g_ModuleLogLevel[TraceN64System] = (uint8_t)g_Settings->LoadDword(Debugger_TraceN64System);
|
|
|
|
g_ModuleLogLevel[TracePlugins] = (uint8_t)g_Settings->LoadDword(Debugger_TracePlugins);
|
2022-06-27 10:02:38 +00:00
|
|
|
g_ModuleLogLevel[TraceVideoPlugin] = (uint8_t)g_Settings->LoadDword(Debugger_TraceVideoPlugin);
|
2015-12-14 10:51:33 +00:00
|
|
|
g_ModuleLogLevel[TraceAudioPlugin] = (uint8_t)g_Settings->LoadDword(Debugger_TraceAudioPlugin);
|
|
|
|
g_ModuleLogLevel[TraceControllerPlugin] = (uint8_t)g_Settings->LoadDword(Debugger_TraceControllerPlugin);
|
|
|
|
g_ModuleLogLevel[TraceRSPPlugin] = (uint8_t)g_Settings->LoadDword(Debugger_TraceRSPPlugin);
|
|
|
|
g_ModuleLogLevel[TraceRSP] = (uint8_t)g_Settings->LoadDword(Debugger_TraceRSP);
|
|
|
|
g_ModuleLogLevel[TraceAudio] = (uint8_t)g_Settings->LoadDword(Debugger_TraceAudio);
|
|
|
|
g_ModuleLogLevel[TraceRegisterCache] = (uint8_t)g_Settings->LoadDword(Debugger_TraceRegisterCache);
|
|
|
|
g_ModuleLogLevel[TraceRecompiler] = (uint8_t)g_Settings->LoadDword(Debugger_TraceRecompiler);
|
|
|
|
g_ModuleLogLevel[TraceTLB] = (uint8_t)g_Settings->LoadDword(Debugger_TraceTLB);
|
|
|
|
g_ModuleLogLevel[TraceProtectedMem] = (uint8_t)g_Settings->LoadDword(Debugger_TraceProtectedMEM);
|
|
|
|
g_ModuleLogLevel[TraceUserInterface] = (uint8_t)g_Settings->LoadDword(Debugger_TraceUserInterface);
|
2016-04-17 19:06:30 +00:00
|
|
|
g_ModuleLogLevel[TraceRomList] = (uint8_t)g_Settings->LoadDword(Debugger_TraceRomList);
|
2016-06-04 08:28:30 +00:00
|
|
|
g_ModuleLogLevel[TraceExceptionHandler] = (uint8_t)g_Settings->LoadDword(Debugger_TraceExceptionHandler);
|
2015-12-14 10:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetupTrace(void)
|
|
|
|
{
|
|
|
|
AddLogModule();
|
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceMD5, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceThread, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TracePath, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceSettings, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceUnknown, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceAppInit, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceAppCleanup, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceN64System, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TracePlugins, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
2022-06-27 10:02:38 +00:00
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceVideoPlugin, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
2021-04-12 11:35:39 +00:00
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceAudioPlugin, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceControllerPlugin, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceRSPPlugin, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceRSP, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceAudio, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceRegisterCache, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceRecompiler, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceTLB, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceProtectedMEM, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceUserInterface, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceRomList, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceExceptionHandler, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
2015-11-14 20:56:40 +00:00
|
|
|
g_Settings->RegisterChangeCB(Debugger_AppLogFlush, g_LogFile, (CSettings::SettingChangedFunc)LogFlushChanged);
|
2021-04-12 11:35:39 +00:00
|
|
|
UpdateTraceLevel(nullptr);
|
2015-12-14 10:51:33 +00:00
|
|
|
|
|
|
|
WriteTrace(TraceAppInit, TraceInfo, "Application Starting %s", VER_FILE_VERSION_STR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CleanupTrace(void)
|
|
|
|
{
|
|
|
|
WriteTrace(TraceAppCleanup, TraceDebug, "Done");
|
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceMD5, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceThread, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TracePath, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceSettings, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceUnknown, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceAppInit, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceAppCleanup, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceN64System, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TracePlugins, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
2022-06-27 10:02:38 +00:00
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceVideoPlugin, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
2021-04-12 11:35:39 +00:00
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceAudioPlugin, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceControllerPlugin, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceRSPPlugin, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceRSP, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceAudio, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceRegisterCache, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceRecompiler, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceTLB, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceProtectedMEM, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceUserInterface, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceRomList, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceExceptionHandler, nullptr, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
2015-12-14 10:51:33 +00:00
|
|
|
g_Settings->UnregisterChangeCB(Debugger_AppLogFlush, g_LogFile, (CSettings::SettingChangedFunc)LogFlushChanged);
|
2015-12-16 06:41:34 +00:00
|
|
|
}
|
2015-12-14 10:51:33 +00:00
|
|
|
|
2015-12-16 06:41:34 +00:00
|
|
|
void TraceDone(void)
|
|
|
|
{
|
2015-12-14 10:51:33 +00:00
|
|
|
CloseTrace();
|
2022-09-26 02:31:54 +00:00
|
|
|
if (g_LogFile)
|
|
|
|
{
|
|
|
|
delete g_LogFile;
|
|
|
|
g_LogFile = nullptr;
|
|
|
|
}
|
2015-11-14 20:56:40 +00:00
|
|
|
}
|
|
|
|
|
2016-01-28 09:37:44 +00:00
|
|
|
const char * AppName(void)
|
2016-01-13 07:23:22 +00:00
|
|
|
{
|
2016-01-26 14:31:24 +00:00
|
|
|
static stdstr_f ApplicationName("Project64 %s", VER_FILE_VERSION_STR);
|
|
|
|
return ApplicationName.c_str();
|
2016-01-13 07:23:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-26 02:31:54 +00:00
|
|
|
static bool ParseCommand(int32_t argc, char ** argv)
|
2016-01-13 07:23:22 +00:00
|
|
|
{
|
2016-02-01 05:57:59 +00:00
|
|
|
if (argc <= 1)
|
2016-01-13 07:23:22 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
for (int32_t i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
int32_t ArgsLeft = argc - i - 1;
|
2016-01-28 09:37:44 +00:00
|
|
|
if (strcmp(argv[i], "--help") == 0)
|
2016-01-13 07:23:22 +00:00
|
|
|
{
|
|
|
|
g_Settings->SaveBool(Cmd_ShowHelp, true);
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-22 11:16:58 +00:00
|
|
|
else if (strcmp(argv[i], "--combo") == 0)
|
|
|
|
{
|
|
|
|
if (ArgsLeft >= 2)
|
|
|
|
{
|
|
|
|
g_Settings->SaveString(Cmd_ComboDiskFile, &(argv[i + 1][0]));
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceError, "Not enough parameters for '%d: %s'", i, argv[i]);
|
2019-08-22 11:16:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-01-13 07:23:22 +00:00
|
|
|
else if (ArgsLeft == 0 && argv[i][0] != '-')
|
|
|
|
{
|
|
|
|
g_Settings->SaveString(Cmd_RomFile, &(argv[i][0]));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceError, "Unrecognized command-line parameter '%d: %s'", i, argv[i]);
|
2016-01-13 07:23:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-26 02:31:54 +00:00
|
|
|
bool AppInit(CNotification * Notify, const char * BaseDirectory, int argc, char ** argv)
|
2015-11-14 20:56:40 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
g_Notify = Notify;
|
2015-12-14 10:51:33 +00:00
|
|
|
InitializeLog();
|
2016-02-01 05:57:59 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceDebug, "Starting (BaseDirectory: %s)", BaseDirectory ? BaseDirectory : "null");
|
2021-04-12 11:35:39 +00:00
|
|
|
if (Notify == nullptr)
|
2016-01-26 14:31:24 +00:00
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceError, "No notification class passed");
|
2016-01-26 14:31:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceDebug, "Setting up settings");
|
2015-11-14 20:56:40 +00:00
|
|
|
g_Settings = new CSettings;
|
2016-01-28 09:37:44 +00:00
|
|
|
g_Settings->Initialize(BaseDirectory, AppName());
|
2016-01-13 07:23:22 +00:00
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceDebug, "Parse commands");
|
2016-01-13 07:23:22 +00:00
|
|
|
if (!ParseCommand(argc, argv))
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceError, "Failed to parse commands, exiting now");
|
2016-01-13 07:23:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-11-14 20:56:40 +00:00
|
|
|
|
2016-01-13 07:23:22 +00:00
|
|
|
#ifdef _WIN32
|
2015-11-14 20:56:40 +00:00
|
|
|
if (g_Settings->LoadBool(Setting_CheckEmuRunning) &&
|
|
|
|
pjutil::TerminatedExistingExe())
|
|
|
|
{
|
|
|
|
delete g_Settings;
|
|
|
|
g_Settings = new CSettings;
|
2016-01-28 09:37:44 +00:00
|
|
|
g_Settings->Initialize(BaseDirectory, AppName());
|
2015-11-14 20:56:40 +00:00
|
|
|
}
|
2016-01-13 07:23:22 +00:00
|
|
|
#endif
|
2015-11-14 20:56:40 +00:00
|
|
|
|
2015-12-14 10:51:33 +00:00
|
|
|
SetupTrace();
|
|
|
|
FixDirectories();
|
2016-01-13 07:23:22 +00:00
|
|
|
CMipsMemoryVM::ReserveMemory();
|
2016-09-26 11:10:11 +00:00
|
|
|
#ifdef _WIN32
|
2016-01-13 07:23:22 +00:00
|
|
|
IncreaseThreadPriority();
|
2016-06-05 00:32:30 +00:00
|
|
|
#else
|
|
|
|
if (!CMipsMemoryVM::SetupSegvHandler())
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceDebug, "Setup SEGV handler failed");
|
2016-06-05 00:32:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-01-13 07:23:22 +00:00
|
|
|
#endif
|
2020-12-29 22:44:04 +00:00
|
|
|
g_Enhancements = new CEnhancements();
|
2015-11-14 20:56:40 +00:00
|
|
|
|
|
|
|
//Create the plugin container
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceInfo, "Create plugins");
|
2016-08-07 08:27:14 +00:00
|
|
|
g_Plugins = new CPlugins(Directory_Plugin, false);
|
2015-11-14 20:56:40 +00:00
|
|
|
|
|
|
|
g_Lang = new CLanguage();
|
|
|
|
g_Lang->LoadCurrentStrings();
|
|
|
|
g_Notify->AppInitDone();
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceDebug, "Initialized successfully");
|
2016-01-26 14:31:24 +00:00
|
|
|
return true;
|
2015-11-14 20:56:40 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayError(stdstr_f("Exception caught\nFile: %s\nLine: %d", __FILE__, __LINE__).c_str());
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceError, "Exception caught, initialization was not successful");
|
2016-01-26 14:31:24 +00:00
|
|
|
return false;
|
2015-11-14 20:56:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppCleanup(void)
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAppCleanup, TraceDebug, "Cleaning up global objects");
|
2015-12-16 06:41:34 +00:00
|
|
|
CleanupTrace();
|
2015-11-14 20:56:40 +00:00
|
|
|
|
2022-09-26 02:31:54 +00:00
|
|
|
if (g_Enhancements)
|
|
|
|
{
|
|
|
|
delete g_Enhancements;
|
|
|
|
g_Enhancements = nullptr;
|
|
|
|
}
|
|
|
|
if (g_Rom)
|
|
|
|
{
|
|
|
|
delete g_Rom;
|
|
|
|
g_Rom = nullptr;
|
|
|
|
}
|
|
|
|
if (g_DDRom)
|
|
|
|
{
|
|
|
|
delete g_DDRom;
|
|
|
|
g_DDRom = nullptr;
|
|
|
|
}
|
|
|
|
if (g_Disk)
|
|
|
|
{
|
|
|
|
delete g_Disk;
|
|
|
|
g_Disk = nullptr;
|
|
|
|
}
|
|
|
|
if (g_Plugins)
|
|
|
|
{
|
|
|
|
delete g_Plugins;
|
|
|
|
g_Plugins = nullptr;
|
|
|
|
}
|
|
|
|
if (g_Settings)
|
|
|
|
{
|
|
|
|
delete g_Settings;
|
|
|
|
g_Settings = nullptr;
|
|
|
|
}
|
|
|
|
if (g_Lang)
|
|
|
|
{
|
|
|
|
delete g_Lang;
|
|
|
|
g_Lang = nullptr;
|
|
|
|
}
|
2015-11-14 20:56:40 +00:00
|
|
|
|
|
|
|
CMipsMemoryVM::FreeReservedMemory();
|
2015-12-16 06:41:34 +00:00
|
|
|
TraceDone();
|
2015-11-14 20:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FixDirectories(void)
|
|
|
|
{
|
2016-02-01 06:30:22 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceDebug, "Starting");
|
2016-01-28 09:37:44 +00:00
|
|
|
CPath Directory(g_Settings->LoadStringVal(Cmd_BaseDirectory).c_str(), "");
|
2015-11-14 20:56:40 +00:00
|
|
|
Directory.AppendDirectory("Config");
|
2016-02-01 06:30:22 +00:00
|
|
|
if (!Directory.DirectoryExists())
|
|
|
|
{
|
|
|
|
WriteTrace(TraceAppInit, TraceDebug, "Creating %s", (const char *)Directory);
|
|
|
|
Directory.DirectoryCreate();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-06 01:47:21 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceDebug, "%s already exists", (const char *)Directory);
|
2016-02-01 06:30:22 +00:00
|
|
|
}
|
2015-11-14 20:56:40 +00:00
|
|
|
|
|
|
|
Directory.UpDirectory();
|
|
|
|
Directory.AppendDirectory("Save");
|
2016-02-01 06:30:22 +00:00
|
|
|
if (!Directory.DirectoryExists())
|
|
|
|
{
|
|
|
|
WriteTrace(TraceAppInit, TraceDebug, "Creating %s", (const char *)Directory);
|
|
|
|
Directory.DirectoryCreate();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-06 01:47:21 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceDebug, "%s already exists", (const char *)Directory);
|
2016-02-01 06:30:22 +00:00
|
|
|
}
|
2015-11-14 20:56:40 +00:00
|
|
|
|
|
|
|
Directory.UpDirectory();
|
|
|
|
Directory.AppendDirectory("Screenshots");
|
2016-02-01 06:30:22 +00:00
|
|
|
if (!Directory.DirectoryExists())
|
|
|
|
{
|
|
|
|
WriteTrace(TraceAppInit, TraceDebug, "Creating %s", (const char *)Directory);
|
|
|
|
Directory.DirectoryCreate();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-06 01:47:21 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceDebug, "%s already exists", (const char *)Directory);
|
2016-02-01 06:30:22 +00:00
|
|
|
}
|
2015-11-14 20:56:40 +00:00
|
|
|
|
|
|
|
Directory.UpDirectory();
|
2016-08-21 21:52:17 +00:00
|
|
|
Directory.AppendDirectory("Textures");
|
2016-02-01 06:30:22 +00:00
|
|
|
if (!Directory.DirectoryExists())
|
|
|
|
{
|
|
|
|
WriteTrace(TraceAppInit, TraceDebug, "Creating %s", (const char *)Directory);
|
|
|
|
Directory.DirectoryCreate();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-06 01:47:21 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceDebug, "%s already exists", (const char *)Directory);
|
2016-02-01 06:30:22 +00:00
|
|
|
}
|
|
|
|
WriteTrace(TraceAppInit, TraceDebug, "Done");
|
2015-11-14 20:56:40 +00:00
|
|
|
}
|
|
|
|
|
2016-01-13 07:23:22 +00:00
|
|
|
#ifdef _WIN32
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <windows.h>
|
2015-11-14 20:56:40 +00:00
|
|
|
void IncreaseThreadPriority(void)
|
|
|
|
{
|
|
|
|
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
|
2016-01-13 07:23:22 +00:00
|
|
|
}
|
2016-08-21 21:52:17 +00:00
|
|
|
#endif
|