Skip to content

Commit

Permalink
datapath resources support
Browse files Browse the repository at this point in the history
  • Loading branch information
afwbkbc committed Nov 3, 2024
1 parent 43ec0e3 commit c9e4fb3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
27 changes: 22 additions & 5 deletions src/resource/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 + ")" );
}
Expand Down
3 changes: 2 additions & 1 deletion src/resource/ResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = {};
Expand Down

0 comments on commit c9e4fb3

Please sign in to comment.