diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 3d6777b4..7490e9f8 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -80,7 +80,7 @@ Engine::Engine( if ( !m_config->HasDebugFlag( config::Config::DF_GSE_ONLY ) ) #endif { - m_resource_manager->Init( m_config->GetPossibleSMACPaths(), m_config->GetSMACType() ); + m_resource_manager->Init( m_config->GetPossibleSMACPaths(), m_config->GetSMACType(), m_config->GetDataPath() ); t_main->AddModule( m_resource_manager ); } t_main->AddModule( m_input ); diff --git a/src/resource/ResourceManager.cpp b/src/resource/ResourceManager.cpp index 0d156dd2..d5f2c14a 100644 --- a/src/resource/ResourceManager.cpp +++ b/src/resource/ResourceManager.cpp @@ -230,8 +230,14 @@ ResourceManager::ResourceManager() } } -void ResourceManager::Init( std::vector< std::string > possible_smac_paths, const config::smac_type_t smac_type ) { +void ResourceManager::Init( const std::vector< std::string >& possible_smac_paths, const config::smac_type_t smac_type, const std::string& data_path ) { const bool print_errors = smac_type != config::ST_AUTO; + m_data_path = util::FS::GeneratePath( + { + data_path, + "default" + } + ); for ( const auto& path : possible_smac_paths ) { // GOG / Steam @@ -362,14 +368,25 @@ const std::string& ResourceManager::GetCustomPath( const std::string& path ) { std::string key = ""; key.resize( path.length() ); std::transform( path.begin(), path.end(), key.begin(), ::tolower ); - const auto& it = m_custom_resource_paths.find( key ); - if ( it != m_custom_resource_paths.end() ) { - return it->second; + + // look in datadir + auto resolved_file = util::FS::GetExistingCaseSensitivePath( m_data_path, path ); + + if ( resolved_file.empty() ) { + + // look in builtin paths + const auto& it = m_custom_resource_paths.find( key ); + if ( it != m_custom_resource_paths.end() ) { + return it->second; + } + + // look in SMAC dir + resolved_file = util::FS::GetExistingCaseSensitivePath( m_smac_path, GetFixedPath( path, m_extension_path_map, m_path_modifiers ) ); } - const auto resolved_file = util::FS::GetExistingCaseSensitivePath( m_smac_path, GetFixedPath( path, m_extension_path_map, m_path_modifiers ) ); if ( resolved_file.empty() ) { THROW( "could not resolve resource (path does not exist: " + path + ")" ); } + if ( !util::FS::IsFile( resolved_file ) ) { THROW( "could not resolve resource (path is not a file: " + path + ")" ); } diff --git a/src/resource/ResourceManager.h b/src/resource/ResourceManager.h index aa0c4b58..47384ed8 100644 --- a/src/resource/ResourceManager.h +++ b/src/resource/ResourceManager.h @@ -14,7 +14,7 @@ CLASS( ResourceManager, common::Module ) ResourceManager(); - void Init( std::vector< std::string > possible_smac_paths, const config::smac_type_t smac_type ); + void Init( const std::vector< std::string >& possible_smac_paths, const config::smac_type_t smac_type, const std::string& data_path ); const config::smac_type_t GetDetectedSMACType() const; const resource_t GetResource( const std::string& filename ) const; @@ -25,6 +25,7 @@ CLASS( ResourceManager, common::Module ) private: config::smac_type_t m_detected_smac_type = config::ST_AUTO; + std::string m_data_path = ""; const std::unordered_map< resource_t, std::string > m_resources_to_filenames = {}; std::unordered_map< std::string, resource_t > m_filenames_to_resources = {};