HostInterface: Add user directory helpers

This commit is contained in:
Connor McLaughlin 2020-01-24 14:51:00 +10:00
parent 7afb79aee6
commit 53428cb55b
2 changed files with 43 additions and 0 deletions

View File

@ -52,6 +52,7 @@ static std::string GetRelativePath(const std::string& path, const char* new_file
HostInterface::HostInterface() HostInterface::HostInterface()
{ {
SetUserDirectory();
m_game_list = std::make_unique<GameList>(); m_game_list = std::make_unique<GameList>();
m_settings.SetDefaults(); m_settings.SetDefaults();
m_last_throttle_time = Common::Timer::GetValue(); m_last_throttle_time = Common::Timer::GetValue();
@ -439,6 +440,39 @@ void HostInterface::OnPerformanceCountersUpdated() {}
void HostInterface::OnRunningGameChanged(const char* path, const char* game_code, const char* game_title) {} void HostInterface::OnRunningGameChanged(const char* path, const char* game_code, const char* game_title) {}
void HostInterface::SetUserDirectory()
{
#ifdef WIN32
// On Windows, use the path to the program.
// We might want to use My Documents in the future.
const std::string program_path = FileSystem::GetProgramPath();
Log_InfoPrintf("Program path: %s", program_path.c_str());
m_user_directory = FileSystem::GetPathDirectory(program_path.c_str());
#else
#endif
Log_InfoPrintf("User directory: %s", m_user_directory.c_str());
}
std::string HostInterface::GetUserDirectoryRelativePath(const char* format, ...)
{
std::va_list ap;
va_start(ap, format);
std::string formatted_path = StringUtil::StdStringFromFormatV(format, ap);
va_end(ap);
if (m_user_directory.empty())
{
return formatted_path;
}
else
{
return StringUtil::StdStringFromFormat("%s%c%s", m_user_directory.c_str(), FS_OSPATH_SEPERATOR_CHARACTER,
formatted_path.c_str());
}
}
void HostInterface::RunFrame() void HostInterface::RunFrame()
{ {
m_frame_timer.Reset(); m_frame_timer.Reset();

View File

@ -61,6 +61,12 @@ public:
bool LoadState(const char* filename); bool LoadState(const char* filename);
bool SaveState(const char* filename); bool SaveState(const char* filename);
/// Returns the base user directory path.
const std::string& GetUserDirectory() const { return m_user_directory; }
/// Returns a path relative to the user directory.
std::string GetUserDirectoryRelativePath(const char* format, ...);
protected: protected:
using ThrottleClock = std::chrono::steady_clock; using ThrottleClock = std::chrono::steady_clock;
@ -82,6 +88,8 @@ protected:
virtual void OnPerformanceCountersUpdated(); virtual void OnPerformanceCountersUpdated();
virtual void OnRunningGameChanged(const char* path, const char* game_code, const char* game_title); virtual void OnRunningGameChanged(const char* path, const char* game_code, const char* game_title);
void SetUserDirectory();
void RunFrame(); void RunFrame();
/// Throttles the system, i.e. sleeps until it's time to execute the next frame. /// Throttles the system, i.e. sleeps until it's time to execute the next frame.
@ -104,6 +112,7 @@ protected:
std::unique_ptr<System> m_system; std::unique_ptr<System> m_system;
std::unique_ptr<GameList> m_game_list; std::unique_ptr<GameList> m_game_list;
Settings m_settings; Settings m_settings;
std::string m_user_directory;
u64 m_last_throttle_time = 0; u64 m_last_throttle_time = 0;
s64 m_throttle_period = INT64_C(1000000000) / 60; s64 m_throttle_period = INT64_C(1000000000) / 60;