diff --git a/Source/Project64-core/AppInit.cpp b/Source/Project64-core/AppInit.cpp index 0655f4b67..f574d503e 100644 --- a/Source/Project64-core/AppInit.cpp +++ b/Source/Project64-core/AppInit.cpp @@ -6,10 +6,14 @@ #include #include #include +#include "Settings/SettingType/SettingsType-Application.h" -void FixDirectories(void); +static void FixDirectories(void); +#ifdef _WIN32 static void IncreaseThreadPriority(void); +#endif + static CTraceFileLog * g_LogFile = NULL; void LogFlushChanged(CTraceFileLog * LogFile) @@ -144,30 +148,80 @@ void TraceDone(void) if (g_LogFile) { delete g_LogFile; g_LogFile = NULL; } } -void AppInit(CNotification * Notify) +const char * AppName ( void ) +{ + static stdstr_f ApplicationName("Project64 %s", VER_FILE_VERSION_STR); + return ApplicationName.c_str(); +} + +static bool ParseCommand(int32_t argc, char **argv) +{ + if (argc == 1) + { + return true; + } + 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) + { + g_Settings->SaveBool(Cmd_ShowHelp, true); + return false; + } + else if (ArgsLeft == 0 && argv[i][0] != '-') + { + g_Settings->SaveString(Cmd_RomFile, &(argv[i][0])); + return true; + } + else + { + //WriteTraceF(TraceError, __FUNCTION__ ": unrecognized command-line parameter '%s'", argv[i]); + } + } + return false; +} + +bool AppInit(CNotification * Notify, int argc, char **argv) { try { g_Notify = Notify; InitializeLog(); - - stdstr_f AppName("Project64 %s", VER_FILE_VERSION_STR); - IncreaseThreadPriority(); - + if (Notify == NULL) + { + WriteTrace(TraceAppInit, TraceError, "No Notification class passed"); + return false; + } g_Settings = new CSettings; - g_Settings->Initialize(AppName.c_str()); + g_Settings->Initialize(AppName()); + if (!ParseCommand(argc, argv)) + { + return false; + } + +#ifdef _WIN32 if (g_Settings->LoadBool(Setting_CheckEmuRunning) && pjutil::TerminatedExistingExe()) { delete g_Settings; g_Settings = new CSettings; - g_Settings->Initialize(AppName.c_str()); + g_Settings->Initialize(AppName()); } +#endif SetupTrace(); - CMipsMemoryVM::ReserveMemory(); FixDirectories(); +#ifdef _WIN32 + CMipsMemoryVM::ReserveMemory(); + IncreaseThreadPriority(); +#endif //Create the plugin container WriteTrace(TraceAppInit, TraceInfo, "Create Plugins"); @@ -176,10 +230,14 @@ void AppInit(CNotification * Notify) g_Lang = new CLanguage(); g_Lang->LoadCurrentStrings(); g_Notify->AppInitDone(); + WriteTrace(TraceAppInit, TraceDebug, "Initialized Successfully"); + return true; } catch (...) { g_Notify->DisplayError(stdstr_f("Exception caught\nFile: %s\nLine: %d", __FILE__, __LINE__).c_str()); + WriteTrace(TraceAppInit, TraceError, "Exception caught, Init was not successfull"); + return false; } } @@ -216,8 +274,10 @@ void FixDirectories(void) if (!Directory.DirectoryExists()) Directory.DirectoryCreate(); } +#ifdef _WIN32 #include void IncreaseThreadPriority(void) { SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL); -} \ No newline at end of file +} +#endif diff --git a/Source/Project64-core/AppInit.h b/Source/Project64-core/AppInit.h index d6843bd32..22c703b42 100644 --- a/Source/Project64-core/AppInit.h +++ b/Source/Project64-core/AppInit.h @@ -1,6 +1,6 @@ #pragma once -#include +#include -void AppInit(CNotification * Notify); +bool AppInit(CNotification * Notify, int argc, char **argv); void AppCleanup(void); diff --git a/Source/Project64-core/Logging.cpp b/Source/Project64-core/Logging.cpp index ab9e76931..0c779ff7c 100644 --- a/Source/Project64-core/Logging.cpp +++ b/Source/Project64-core/Logging.cpp @@ -9,7 +9,7 @@ * * ****************************************************************************/ #include "stdafx.h" -#include "Logging.h" +#include #include #include @@ -615,7 +615,7 @@ void CLogging::StartLog(void) return; } - CPath LogFile(CPath::MODULE_DIRECTORY); + CPath LogFile(g_Settings->LoadStringVal(Cmd_BaseDirectory).c_str(),""); LogFile.AppendDirectory("Logs"); LogFile.SetNameExtension("cpudebug.log"); diff --git a/Source/Project64-core/Multilanguage/LanguageClass.cpp b/Source/Project64-core/Multilanguage/LanguageClass.cpp index b27efca0f..5429700b4 100644 --- a/Source/Project64-core/Multilanguage/LanguageClass.cpp +++ b/Source/Project64-core/Multilanguage/LanguageClass.cpp @@ -573,7 +573,7 @@ LanguageList & CLanguage::GetLangList(void) { LanguageFile File; //We temporally store the values in here to added to the list - File.Filename = (std::string &)LanguageFiles; + File.Filename = (const std::string &)LanguageFiles; File.LanguageName = GetLangString(LanguageFiles, LANGUAGE_NAME); if (File.LanguageName.length() == 0) diff --git a/Source/Project64-core/Notification.h b/Source/Project64-core/Notification.h index 2b4e2868c..176409f47 100644 --- a/Source/Project64-core/Notification.h +++ b/Source/Project64-core/Notification.h @@ -1,6 +1,6 @@ #pragma once -#include "Multilanguage.h" +#include #ifndef _MSC_VER #define __interface struct diff --git a/Source/Project64-core/Settings/SettingType/SettingsType-ApplicationPath.cpp b/Source/Project64-core/Settings/SettingType/SettingsType-ApplicationPath.cpp index 07fe08c67..15331ec52 100644 --- a/Source/Project64-core/Settings/SettingType/SettingsType-ApplicationPath.cpp +++ b/Source/Project64-core/Settings/SettingType/SettingsType-ApplicationPath.cpp @@ -35,7 +35,7 @@ bool CSettingTypeApplicationPath::Load ( int Index, stdstr & Value ) const FullFilePath.SetNameExtension(RelativePath.GetNameExtension().c_str()); FullFilePath.AppendDirectory(RelativePath.GetDirectory().c_str()); - Value = (std::string &)FullFilePath; + Value = (const std::string &)FullFilePath; } } return bRes; diff --git a/Source/Project64-core/Settings/Settings.h b/Source/Project64-core/Settings/Settings.h index 5962868d3..468b9474c 100644 --- a/Source/Project64-core/Settings/Settings.h +++ b/Source/Project64-core/Settings/Settings.h @@ -24,6 +24,11 @@ enum SettingID //information - temp keys Info_ShortCutsChanged, + //Command Settings + Cmd_BaseDirectory, + Cmd_RomFile, + Cmd_ShowHelp, + //Support Files SupportFile_Settings, SupportFile_SettingsDefault, diff --git a/Source/Project64-core/Settings/SettingsClass.cpp b/Source/Project64-core/Settings/SettingsClass.cpp index e719b5137..6b9f6de9e 100644 --- a/Source/Project64-core/Settings/SettingsClass.cpp +++ b/Source/Project64-core/Settings/SettingsClass.cpp @@ -10,6 +10,7 @@ ****************************************************************************/ #include "stdafx.h" +#include #include "SettingType/SettingsType-Application.h" #include "SettingType/SettingsType-ApplicationPath.h" #include "SettingType/SettingsType-ApplicationIndex.h" @@ -30,7 +31,7 @@ #include "SettingType/SettingsType-TempNumber.h" #include "SettingType/SettingsType-TempBool.h" #include "SettingsClass.h" -#include "N64System/N64Types.h" +#include #include CSettings * g_Settings = NULL; @@ -66,7 +67,7 @@ CSettings::~CSettings() void CSettings::AddHandler(SettingID TypeID, CSettingType * Handler) { - SETTING_MAP::_Pairib res = m_SettingInfo.insert(SETTING_MAP::value_type(TypeID, Handler)); + std::pair res = m_SettingInfo.insert(SETTING_MAP::value_type(TypeID, Handler)); if (!res.second) { delete res.first->second; @@ -84,6 +85,15 @@ void CSettings::AddHowToHandleSetting() //information - temp keys 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_ShowHelp, new CSettingTypeTempBool(false)); + AddHandler(Cmd_RomFile, new CSettingTypeTempString("")); + //Support Files AddHandler(SupportFile_Settings, new CSettingTypeApplicationPath("", "ConfigFile", SupportFile_SettingsDefault)); AddHandler(SupportFile_SettingsDefault, new CSettingTypeRelativePath("Config", "Project64.cfg")); @@ -664,7 +674,7 @@ bool CSettings::LoadDword(SettingID Type, uint32_t & Value) { //if not found do nothing UnknownSetting(Type); - return 0; + return false; } if (FindInfo->second->IndexBasedSetting()) { @@ -907,7 +917,7 @@ void CSettings::LoadDefaultString(SettingID /*Type*/, char * /*Buffer*/, int /*B stdstr CSettings::LoadDefaultStringIndex(SettingID /*Type*/, int /*index*/) { g_Notify->BreakPoint(__FILE__, __LINE__); - return false; + return ""; } void CSettings::LoadDefaultStringIndex(SettingID /*Type*/, int /*index*/, stdstr & /*Value*/) @@ -1028,7 +1038,7 @@ void CSettings::SaveString(SettingID Type, const char * Buffer) //if not found do nothing UnknownSetting(Type); } - if (FindInfo->second->IndexBasedSetting()) + else if (FindInfo->second->IndexBasedSetting()) { g_Notify->BreakPoint(__FILE__, __LINE__); } diff --git a/Source/Project64-core/Settings/SettingsClass.h b/Source/Project64-core/Settings/SettingsClass.h index cdd2cc0ea..3494b8ed0 100644 --- a/Source/Project64-core/Settings/SettingsClass.h +++ b/Source/Project64-core/Settings/SettingsClass.h @@ -10,7 +10,7 @@ ****************************************************************************/ #pragma once -#include "SettingType/SettingsType-Base.h" +#include enum SettingDataType { @@ -60,8 +60,8 @@ public: uint32_t LoadDwordIndex ( SettingID Type, int32_t index ); bool LoadDwordIndex ( SettingID Type, int32_t index, uint32_t & Value ); stdstr LoadStringVal ( SettingID Type ); - bool LoadStringVal (SettingID Type, stdstr & Value); - bool LoadStringVal (SettingID Type, char * Buffer, int32_t BufferSize ); + bool LoadStringVal ( SettingID Type, stdstr & Value ); + bool LoadStringVal ( SettingID Type, char * Buffer, int32_t BufferSize ); stdstr LoadStringIndex ( SettingID Type, int32_t index ); bool LoadStringIndex ( SettingID Type, int32_t index, stdstr & Value ); bool LoadStringIndex ( SettingID Type, int32_t index, char * Buffer, int32_t BufferSize ); diff --git a/Source/Project64-core/stdafx.h b/Source/Project64-core/stdafx.h index e1e400916..c075f580f 100644 --- a/Source/Project64-core/stdafx.h +++ b/Source/Project64-core/stdafx.h @@ -2,8 +2,8 @@ #include #include -#include "Multilanguage.h" -#include "Notification.h" +#include +#include #include "Version.h" #include "Settings/SettingsClass.h" -#include "TraceModulesProject64.h" +#include diff --git a/Source/Project64/main.cpp b/Source/Project64/main.cpp index 2e210ba31..3782dfa64 100644 --- a/Source/Project64/main.cpp +++ b/Source/Project64/main.cpp @@ -7,7 +7,7 @@ int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR / try { CoInitialize(NULL); - AppInit(&Notify()); + AppInit(&Notify(), __argc, __argv); if (!g_Lang->IsLanguageLoaded()) { CLanguageSelector().Select(); @@ -20,11 +20,10 @@ int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR / g_Plugins->SetRenderWindows(&MainWindow, &HiddenWindow); Notify().SetMainWindow(&MainWindow); - if (__argc > 1) + if (g_Settings->LoadStringVal(Cmd_RomFile).length() > 0) { - WriteTrace(TraceUserInterface, TraceDebug, "Cmd line found \"%s\"", __argv[1]); MainWindow.Show(true); //Show the main window - CN64System::RunFileImage(__argv[1]); + CN64System::RunFileImage(g_Settings->LoadStringVal(Cmd_RomFile).c_str()); } else {