[Project64] Add Cmd_BaseDirectory

This commit is contained in:
zilmar 2016-01-13 18:23:22 +11:00
parent be7943a35d
commit 43f34c9aff
11 changed files with 106 additions and 32 deletions

View File

@ -6,10 +6,14 @@
#include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/Plugins/PluginClass.h>
#include <Project64-core/N64System/N64RomClass.h>
#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 <windows.h>
void IncreaseThreadPriority(void)
{
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
}
}
#endif

View File

@ -1,6 +1,6 @@
#pragma once
#include <Project64/UserInterface/NotificationClass.h>
#include <Project64-core/Notification.h>
void AppInit(CNotification * Notify);
bool AppInit(CNotification * Notify, int argc, char **argv);
void AppCleanup(void);

View File

@ -9,7 +9,7 @@
* *
****************************************************************************/
#include "stdafx.h"
#include "Logging.h"
#include <Project64-core/Logging.h>
#include <string.h>
#include <stdio.h>
@ -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");

View File

@ -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)

View File

@ -1,6 +1,6 @@
#pragma once
#include "Multilanguage.h"
#include <Project64-core/Multilanguage.h>
#ifndef _MSC_VER
#define __interface struct

View File

@ -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;

View File

@ -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,

View File

@ -10,6 +10,7 @@
****************************************************************************/
#include "stdafx.h"
#include <Common/Platform.h>
#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 <Project64-core/N64System/N64Types.h>
#include <Common/Trace.h>
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<SETTING_MAP::iterator, bool> 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__);
}

View File

@ -10,7 +10,7 @@
****************************************************************************/
#pragma once
#include "SettingType/SettingsType-Base.h"
#include <Project64-core/Settings/SettingType/SettingsType-Base.h>
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 );

View File

@ -2,8 +2,8 @@
#include <Common/StdString.h>
#include <Common/Trace.h>
#include "Multilanguage.h"
#include "Notification.h"
#include <Project64-core/Multilanguage.h>
#include <Project64-core/Notification.h>
#include "Version.h"
#include "Settings/SettingsClass.h"
#include "TraceModulesProject64.h"
#include <Project64-core/TraceModulesProject64.h>

View File

@ -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
{