[Project64] Be able to pass base dir to app init
This commit is contained in:
parent
8df90936f8
commit
a6bfe74a28
|
@ -12,6 +12,7 @@
|
||||||
#include "Settings/SettingType/SettingsType-Application.h"
|
#include "Settings/SettingType/SettingsType-Application.h"
|
||||||
|
|
||||||
static void FixDirectories(void);
|
static void FixDirectories(void);
|
||||||
|
void SetTraceModuleNames(void);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static void IncreaseThreadPriority(void);
|
static void IncreaseThreadPriority(void);
|
||||||
|
@ -31,11 +32,12 @@ void InitializeLog(void)
|
||||||
#else
|
#else
|
||||||
TraceSetMaxModule(MaxTraceModuleProject64, TraceError);
|
TraceSetMaxModule(MaxTraceModuleProject64, TraceError);
|
||||||
#endif
|
#endif
|
||||||
|
SetTraceModuleNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddLogModule(void)
|
void AddLogModule(void)
|
||||||
{
|
{
|
||||||
CPath LogFilePath(CPath::MODULE_DIRECTORY);
|
CPath LogFilePath(g_Settings->LoadStringVal(Cmd_BaseDirectory).c_str(), "");
|
||||||
LogFilePath.AppendDirectory("Logs");
|
LogFilePath.AppendDirectory("Logs");
|
||||||
if (!LogFilePath.DirectoryExists())
|
if (!LogFilePath.DirectoryExists())
|
||||||
{
|
{
|
||||||
|
@ -93,7 +95,6 @@ void UpdateTraceLevel(void * /*NotUsed*/)
|
||||||
|
|
||||||
void SetupTrace(void)
|
void SetupTrace(void)
|
||||||
{
|
{
|
||||||
SetTraceModuleNames();
|
|
||||||
AddLogModule();
|
AddLogModule();
|
||||||
|
|
||||||
g_Settings->RegisterChangeCB(Debugger_TraceMD5, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
g_Settings->RegisterChangeCB(Debugger_TraceMD5, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
||||||
|
@ -151,7 +152,7 @@ void TraceDone(void)
|
||||||
if (g_LogFile) { delete g_LogFile; g_LogFile = NULL; }
|
if (g_LogFile) { delete g_LogFile; g_LogFile = NULL; }
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * AppName ( void )
|
const char * AppName(void)
|
||||||
{
|
{
|
||||||
static stdstr_f ApplicationName("Project64 %s", VER_FILE_VERSION_STR);
|
static stdstr_f ApplicationName("Project64 %s", VER_FILE_VERSION_STR);
|
||||||
return ApplicationName.c_str();
|
return ApplicationName.c_str();
|
||||||
|
@ -166,13 +167,7 @@ static bool ParseCommand(int32_t argc, char **argv)
|
||||||
for (int32_t i = 1; i < argc; i++)
|
for (int32_t i = 1; i < argc; i++)
|
||||||
{
|
{
|
||||||
int32_t ArgsLeft = argc - i - 1;
|
int32_t ArgsLeft = argc - i - 1;
|
||||||
if (strcmp(argv[i], "--basedir") == 0 && ArgsLeft >= 1)
|
if (strcmp(argv[i], "--help") == 0)
|
||||||
{
|
|
||||||
g_Settings->SaveString(Cmd_BaseDirectory, argv[i + 1]);
|
|
||||||
CSettingTypeApplication::Initialize(AppName());
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
else if (strcmp(argv[i], "--help") == 0)
|
|
||||||
{
|
{
|
||||||
g_Settings->SaveBool(Cmd_ShowHelp, true);
|
g_Settings->SaveBool(Cmd_ShowHelp, true);
|
||||||
return false;
|
return false;
|
||||||
|
@ -184,26 +179,29 @@ static bool ParseCommand(int32_t argc, char **argv)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//WriteTraceF(TraceError, __FUNCTION__ ": unrecognized command-line parameter '%s'", argv[i]);
|
WriteTrace(TraceAppInit, TraceError, "unrecognized command-line parameter '%d: %s'", i, argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppInit(CNotification * Notify, int argc, char **argv)
|
bool AppInit(CNotification * Notify, const char * BaseDirectory, int argc, char **argv)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
g_Notify = Notify;
|
g_Notify = Notify;
|
||||||
InitializeLog();
|
InitializeLog();
|
||||||
|
WriteTrace(TraceAppInit, TraceDebug, "Starting");
|
||||||
if (Notify == NULL)
|
if (Notify == NULL)
|
||||||
{
|
{
|
||||||
WriteTrace(TraceAppInit, TraceError, "No Notification class passed");
|
WriteTrace(TraceAppInit, TraceError, "No Notification class passed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
WriteTrace(TraceAppInit, TraceDebug, "Settings up settings");
|
||||||
g_Settings = new CSettings;
|
g_Settings = new CSettings;
|
||||||
g_Settings->Initialize(AppName());
|
g_Settings->Initialize(BaseDirectory, AppName());
|
||||||
|
|
||||||
|
WriteTrace(TraceAppInit, TraceDebug, "Parse Commands");
|
||||||
if (!ParseCommand(argc, argv))
|
if (!ParseCommand(argc, argv))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -215,7 +213,7 @@ bool AppInit(CNotification * Notify, int argc, char **argv)
|
||||||
{
|
{
|
||||||
delete g_Settings;
|
delete g_Settings;
|
||||||
g_Settings = new CSettings;
|
g_Settings = new CSettings;
|
||||||
g_Settings->Initialize(AppName());
|
g_Settings->Initialize(BaseDirectory, AppName());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -262,7 +260,7 @@ void AppCleanup(void)
|
||||||
|
|
||||||
void FixDirectories(void)
|
void FixDirectories(void)
|
||||||
{
|
{
|
||||||
CPath Directory(CPath::MODULE_DIRECTORY);
|
CPath Directory(g_Settings->LoadStringVal(Cmd_BaseDirectory).c_str(), "");
|
||||||
Directory.AppendDirectory("Config");
|
Directory.AppendDirectory("Config");
|
||||||
if (!Directory.DirectoryExists()) Directory.DirectoryCreate();
|
if (!Directory.DirectoryExists()) Directory.DirectoryCreate();
|
||||||
|
|
||||||
|
@ -285,4 +283,4 @@ void IncreaseThreadPriority(void)
|
||||||
{
|
{
|
||||||
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
|
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -2,5 +2,5 @@
|
||||||
|
|
||||||
#include <Project64-core/Notification.h>
|
#include <Project64-core/Notification.h>
|
||||||
|
|
||||||
bool AppInit(CNotification * Notify, int argc, char **argv);
|
bool AppInit(CNotification * Notify, const char * BaseDirectory, int argc, char **argv);
|
||||||
void AppCleanup(void);
|
void AppCleanup(void);
|
||||||
|
|
|
@ -1130,9 +1130,8 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
{
|
{
|
||||||
CPath ErrorFile(CPath::MODULE_DIRECTORY);
|
CPath ErrorFile(g_Settings->LoadStringVal(Cmd_BaseDirectory).c_str(), "Sync Errors.txt");
|
||||||
ErrorFile.AppendDirectory("Logs");
|
ErrorFile.AppendDirectory("Logs");
|
||||||
ErrorFile.SetNameExtension("Sync Errors.txt");
|
|
||||||
|
|
||||||
CLog Error;
|
CLog Error;
|
||||||
Error.Open(ErrorFile);
|
Error.Open(ErrorFile);
|
||||||
|
|
|
@ -26,19 +26,17 @@ CSettingTypeApplicationPath::~CSettingTypeApplicationPath()
|
||||||
bool CSettingTypeApplicationPath::Load ( int Index, stdstr & Value ) const
|
bool CSettingTypeApplicationPath::Load ( int Index, stdstr & Value ) const
|
||||||
{
|
{
|
||||||
bool bRes = CSettingTypeApplication::Load(Index,Value);
|
bool bRes = CSettingTypeApplication::Load(Index,Value);
|
||||||
#ifdef WIN32
|
|
||||||
if (bRes)
|
if (bRes)
|
||||||
{
|
{
|
||||||
if (Value.substr(0,2) == ".\\" || Value.substr(0,2) == "./" ||
|
if (Value.substr(0,2) == ".\\" || Value.substr(0,2) == "./" ||
|
||||||
Value.substr(0,3) == "..\\" || Value.substr(0,3) == "../")
|
Value.substr(0,3) == "..\\" || Value.substr(0,3) == "../")
|
||||||
{
|
{
|
||||||
CPath FullFilePath(CPath::MODULE_DIRECTORY), RelativePath(Value);
|
CPath FullFilePath(g_Settings->LoadStringVal(Cmd_BaseDirectory).c_str(), ""), RelativePath(Value);
|
||||||
FullFilePath.SetNameExtension(RelativePath.GetNameExtension().c_str());
|
FullFilePath.SetNameExtension(RelativePath.GetNameExtension().c_str());
|
||||||
FullFilePath.AppendDirectory(RelativePath.GetDirectory().c_str());
|
FullFilePath.AppendDirectory(RelativePath.GetDirectory().c_str());
|
||||||
|
|
||||||
Value = (const std::string &)FullFilePath;
|
Value = (const std::string &)FullFilePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return bRes;
|
return bRes;
|
||||||
}
|
}
|
|
@ -80,7 +80,7 @@ void CSettings::AddHandler(SettingID TypeID, CSettingType * Handler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSettings::AddHowToHandleSetting()
|
void CSettings::AddHowToHandleSetting(const char * BaseDirectory)
|
||||||
{
|
{
|
||||||
WriteTrace(TraceAppInit, TraceDebug, "Start");
|
WriteTrace(TraceAppInit, TraceDebug, "Start");
|
||||||
|
|
||||||
|
@ -88,11 +88,7 @@ void CSettings::AddHowToHandleSetting()
|
||||||
AddHandler(Info_ShortCutsChanged, new CSettingTypeTempBool(false));
|
AddHandler(Info_ShortCutsChanged, new CSettingTypeTempBool(false));
|
||||||
|
|
||||||
//Command Settings
|
//Command Settings
|
||||||
#ifdef _WIN32
|
AddHandler(Cmd_BaseDirectory, new CSettingTypeTempString(BaseDirectory));
|
||||||
AddHandler(Cmd_BaseDirectory, new CSettingTypeTempString(CPath(CPath::MODULE_DIRECTORY)));
|
|
||||||
#else
|
|
||||||
AddHandler(Cmd_BaseDirectory, new CSettingTypeTempString(""));
|
|
||||||
#endif
|
|
||||||
AddHandler(Cmd_ShowHelp, new CSettingTypeTempBool(false));
|
AddHandler(Cmd_ShowHelp, new CSettingTypeTempBool(false));
|
||||||
AddHandler(Cmd_RomFile, new CSettingTypeTempString(""));
|
AddHandler(Cmd_RomFile, new CSettingTypeTempString(""));
|
||||||
|
|
||||||
|
@ -596,10 +592,10 @@ void CSettings::RegisterSetting(CSettings * _this, SettingID ID, SettingID Defau
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSettings::Initialize(const char * AppName)
|
bool CSettings::Initialize(const char * BaseDirectory, const char * AppName)
|
||||||
{
|
{
|
||||||
WriteTrace(TraceAppInit, TraceDebug, "Start");
|
WriteTrace(TraceAppInit, TraceDebug, "Start");
|
||||||
AddHowToHandleSetting();
|
AddHowToHandleSetting(BaseDirectory);
|
||||||
CSettingTypeApplication::Initialize(AppName);
|
CSettingTypeApplication::Initialize(AppName);
|
||||||
CSettingTypeRomDatabase::Initialize();
|
CSettingTypeRomDatabase::Initialize();
|
||||||
CSettingTypeGame::Initialize();
|
CSettingTypeGame::Initialize();
|
||||||
|
|
|
@ -7,7 +7,7 @@ int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CoInitialize(NULL);
|
CoInitialize(NULL);
|
||||||
AppInit(&Notify(), __argc, __argv);
|
AppInit(&Notify(), CPath(CPath::MODULE_DIRECTORY), __argc, __argv);
|
||||||
if (!g_Lang->IsLanguageLoaded())
|
if (!g_Lang->IsLanguageLoaded())
|
||||||
{
|
{
|
||||||
CLanguageSelector().Select();
|
CLanguageSelector().Select();
|
||||||
|
|
Loading…
Reference in New Issue