From f6fee86f1c95d95e8a5f4e57d30f15d411530685 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 24 Jan 2020 14:51:10 +1000 Subject: [PATCH] HostInterface: Create user directories on startup --- src/core/host_interface.cpp | 11 +++++++++++ src/core/host_interface.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index 1b08004d4..112b5301a 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -53,6 +53,7 @@ static std::string GetRelativePath(const std::string& path, const char* new_file HostInterface::HostInterface() { SetUserDirectory(); + CreateUserDirectorySubdirectories(); m_game_list = std::make_unique(); m_game_list->SetCacheFilename(GetGameListCacheFileName()); m_game_list->SetDatabaseFilename(GetGameListDatabaseFileName()); @@ -464,6 +465,16 @@ void HostInterface::SetUserDirectory() } } +void HostInterface::CreateUserDirectorySubdirectories() +{ + bool result = true; + + result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("cache").c_str(), false); + + if (!result) + ReportError("Failed to create one or more user directories. This may cause issues at runtime."); +} + std::string HostInterface::GetUserDirectoryRelativePath(const char* format, ...) const { std::va_list ap; diff --git a/src/core/host_interface.h b/src/core/host_interface.h index 1e546809a..199d57e37 100644 --- a/src/core/host_interface.h +++ b/src/core/host_interface.h @@ -90,6 +90,9 @@ protected: void SetUserDirectory(); + /// Ensures all subdirectories of the user directory are created. + void CreateUserDirectorySubdirectories(); + /// Returns the path of the settings file. std::string GetSettingsFileName() const;