HostInterface: Make SetUserDirectory() overridable by frontends

This commit is contained in:
Connor McLaughlin
2020-04-05 22:59:06 +10:00
parent 11e8a91e30
commit e7640d5367
13 changed files with 188 additions and 108 deletions

View File

@ -49,14 +49,7 @@ static std::string GetRelativePath(const std::string& path, const char* new_file
#endif
HostInterface::HostInterface()
{
SetUserDirectory();
CreateUserDirectorySubdirectories();
m_game_list = std::make_unique<GameList>();
m_game_list->SetCacheFilename(GetGameListCacheFileName());
m_game_list->SetDatabaseFilename(GetGameListDatabaseFileName());
}
HostInterface::HostInterface() = default;
HostInterface::~HostInterface()
{
@ -64,6 +57,21 @@ HostInterface::~HostInterface()
Assert(!m_system && !m_audio_stream && !m_display);
}
bool HostInterface::Initialize()
{
SetUserDirectory();
InitializeUserDirectory();
m_game_list = std::make_unique<GameList>();
m_game_list->SetCacheFilename(GetGameListCacheFileName());
m_game_list->SetDatabaseFilename(GetGameListDatabaseFileName());
return true;
}
void HostInterface::Shutdown()
{
}
void HostInterface::CreateAudioStream()
{
m_audio_stream = CreateAudioStream(m_settings.audio_backend);
@ -660,7 +668,10 @@ void HostInterface::SetUserDirectory()
m_user_directory = StringUtil::StdStringFromFormat("%s/Library/Application Support/DuckStation", home_path);
#endif
}
}
void HostInterface::InitializeUserDirectory()
{
Log_InfoPrintf("User directory: \"%s\"", m_user_directory.c_str());
if (m_user_directory.empty())
@ -673,13 +684,6 @@ void HostInterface::SetUserDirectory()
Log_ErrorPrintf("Failed to create user directory \"%s\".", m_user_directory.c_str());
}
// Change to the user directory so that all default/relative paths in the config are after this.
if (!FileSystem::SetWorkingDirectory(m_user_directory.c_str()))
Log_ErrorPrintf("Failed to set working directory to '%s'", m_user_directory.c_str());
}
void HostInterface::CreateUserDirectorySubdirectories()
{
bool result = true;
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("bios").c_str(), false);

View File

@ -44,6 +44,12 @@ public:
/// Access to emulated system.
ALWAYS_INLINE System* GetSystem() const { return m_system.get(); }
/// Initializes the emulator frontend.
virtual bool Initialize();
/// Shuts down the emulator frontend.
virtual void Shutdown();
bool BootSystem(const SystemBootParameters& parameters);
void PauseSystem(bool paused);
void ResetSystem();
@ -149,7 +155,8 @@ protected:
virtual void OnControllerTypeChanged(u32 slot);
virtual void DrawImGuiWindows();
void SetUserDirectory();
/// Sets the base path for the user directory. Can be overridden by platform/frontend/command line.
virtual void SetUserDirectory();
/// Ensures all subdirectories of the user directory are created.
void CreateUserDirectorySubdirectories();
@ -231,6 +238,7 @@ protected:
std::mutex m_osd_messages_lock;
private:
void InitializeUserDirectory();
void CreateAudioStream();
bool SaveState(const char* filename);
};