[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"
|
||||
|
||||
static void FixDirectories(void);
|
||||
void SetTraceModuleNames(void);
|
||||
|
||||
#ifdef _WIN32
|
||||
static void IncreaseThreadPriority(void);
|
||||
|
@ -31,11 +32,12 @@ void InitializeLog(void)
|
|||
#else
|
||||
TraceSetMaxModule(MaxTraceModuleProject64, TraceError);
|
||||
#endif
|
||||
SetTraceModuleNames();
|
||||
}
|
||||
|
||||
void AddLogModule(void)
|
||||
{
|
||||
CPath LogFilePath(CPath::MODULE_DIRECTORY);
|
||||
CPath LogFilePath(g_Settings->LoadStringVal(Cmd_BaseDirectory).c_str(), "");
|
||||
LogFilePath.AppendDirectory("Logs");
|
||||
if (!LogFilePath.DirectoryExists())
|
||||
{
|
||||
|
@ -93,7 +95,6 @@ void UpdateTraceLevel(void * /*NotUsed*/)
|
|||
|
||||
void SetupTrace(void)
|
||||
{
|
||||
SetTraceModuleNames();
|
||||
AddLogModule();
|
||||
|
||||
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; }
|
||||
}
|
||||
|
||||
const char * AppName ( void )
|
||||
const char * AppName(void)
|
||||
{
|
||||
static stdstr_f ApplicationName("Project64 %s", VER_FILE_VERSION_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++)
|
||||
{
|
||||
int32_t ArgsLeft = argc - i - 1;
|
||||
if (strcmp(argv[i], "--basedir") == 0 && ArgsLeft >= 1)
|
||||
{
|
||||
g_Settings->SaveString(Cmd_BaseDirectory, argv[i + 1]);
|
||||
CSettingTypeApplication::Initialize(AppName());
|
||||
i++;
|
||||
}
|
||||
else if (strcmp(argv[i], "--help") == 0)
|
||||
if (strcmp(argv[i], "--help") == 0)
|
||||
{
|
||||
g_Settings->SaveBool(Cmd_ShowHelp, true);
|
||||
return false;
|
||||
|
@ -184,26 +179,29 @@ static bool ParseCommand(int32_t argc, char **argv)
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
||||
bool AppInit(CNotification * Notify, int argc, char **argv)
|
||||
bool AppInit(CNotification * Notify, const char * BaseDirectory, int argc, char **argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
g_Notify = Notify;
|
||||
InitializeLog();
|
||||
WriteTrace(TraceAppInit, TraceDebug, "Starting");
|
||||
if (Notify == NULL)
|
||||
{
|
||||
WriteTrace(TraceAppInit, TraceError, "No Notification class passed");
|
||||
return false;
|
||||
}
|
||||
WriteTrace(TraceAppInit, TraceDebug, "Settings up settings");
|
||||
g_Settings = new CSettings;
|
||||
g_Settings->Initialize(AppName());
|
||||
g_Settings->Initialize(BaseDirectory, AppName());
|
||||
|
||||
WriteTrace(TraceAppInit, TraceDebug, "Parse Commands");
|
||||
if (!ParseCommand(argc, argv))
|
||||
{
|
||||
return false;
|
||||
|
@ -215,7 +213,7 @@ bool AppInit(CNotification * Notify, int argc, char **argv)
|
|||
{
|
||||
delete g_Settings;
|
||||
g_Settings = new CSettings;
|
||||
g_Settings->Initialize(AppName());
|
||||
g_Settings->Initialize(BaseDirectory, AppName());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -262,7 +260,7 @@ void AppCleanup(void)
|
|||
|
||||
void FixDirectories(void)
|
||||
{
|
||||
CPath Directory(CPath::MODULE_DIRECTORY);
|
||||
CPath Directory(g_Settings->LoadStringVal(Cmd_BaseDirectory).c_str(), "");
|
||||
Directory.AppendDirectory("Config");
|
||||
if (!Directory.DirectoryExists()) Directory.DirectoryCreate();
|
||||
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
|
||||
#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);
|
||||
|
|
|
@ -1130,9 +1130,8 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
|
|||
int count;
|
||||
|
||||
{
|
||||
CPath ErrorFile(CPath::MODULE_DIRECTORY);
|
||||
CPath ErrorFile(g_Settings->LoadStringVal(Cmd_BaseDirectory).c_str(), "Sync Errors.txt");
|
||||
ErrorFile.AppendDirectory("Logs");
|
||||
ErrorFile.SetNameExtension("Sync Errors.txt");
|
||||
|
||||
CLog Error;
|
||||
Error.Open(ErrorFile);
|
||||
|
|
|
@ -26,19 +26,17 @@ CSettingTypeApplicationPath::~CSettingTypeApplicationPath()
|
|||
bool CSettingTypeApplicationPath::Load ( int Index, stdstr & Value ) const
|
||||
{
|
||||
bool bRes = CSettingTypeApplication::Load(Index,Value);
|
||||
#ifdef WIN32
|
||||
if (bRes)
|
||||
{
|
||||
if (Value.substr(0,2) == ".\\" || Value.substr(0,2) == "./" ||
|
||||
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.AppendDirectory(RelativePath.GetDirectory().c_str());
|
||||
|
||||
Value = (const std::string &)FullFilePath;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
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");
|
||||
|
||||
|
@ -88,11 +88,7 @@ void CSettings::AddHowToHandleSetting()
|
|||
AddHandler(Info_ShortCutsChanged, new CSettingTypeTempBool(false));
|
||||
|
||||
//Command Settings
|
||||
#ifdef _WIN32
|
||||
AddHandler(Cmd_BaseDirectory, new CSettingTypeTempString(CPath(CPath::MODULE_DIRECTORY)));
|
||||
#else
|
||||
AddHandler(Cmd_BaseDirectory, new CSettingTypeTempString(""));
|
||||
#endif
|
||||
AddHandler(Cmd_BaseDirectory, new CSettingTypeTempString(BaseDirectory));
|
||||
AddHandler(Cmd_ShowHelp, new CSettingTypeTempBool(false));
|
||||
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");
|
||||
AddHowToHandleSetting();
|
||||
AddHowToHandleSetting(BaseDirectory);
|
||||
CSettingTypeApplication::Initialize(AppName);
|
||||
CSettingTypeRomDatabase::Initialize();
|
||||
CSettingTypeGame::Initialize();
|
||||
|
|
|
@ -7,7 +7,7 @@ int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /
|
|||
try
|
||||
{
|
||||
CoInitialize(NULL);
|
||||
AppInit(&Notify(), __argc, __argv);
|
||||
AppInit(&Notify(), CPath(CPath::MODULE_DIRECTORY), __argc, __argv);
|
||||
if (!g_Lang->IsLanguageLoaded())
|
||||
{
|
||||
CLanguageSelector().Select();
|
||||
|
|
Loading…
Reference in New Issue