Cleanup file scanner code

This commit is contained in:
2025-02-17 03:00:09 -05:00
parent 91ad1c21c3
commit 8670fe3530
4 changed files with 52 additions and 52 deletions

View File

@@ -125,7 +125,7 @@ namespace fgl::engine::filesystem
void FileBrowser::drawTexture( const FileInfo& info )
{
if ( auto itter = m_file_textures.find( info.path ); itter != m_file_textures.end() )
if ( auto itter = m_file_textures.find( info.m_path ); itter != m_file_textures.end() )
{
auto& [ path, texture ] = *itter;
@@ -135,17 +135,17 @@ namespace fgl::engine::filesystem
{
m_file_texture->drawImGuiButton( { DESIRED_SIZE, DESIRED_SIZE } );
auto tex { getTextureStore().load( info.path ) };
auto tex { getTextureStore().load( info.m_path ) };
// Add the texture
m_file_textures.insert( std::make_pair( info.path, std::move( tex ) ) );
m_file_textures.insert( std::make_pair( info.m_path, std::move( tex ) ) );
}
if ( ImGui::BeginDragDropSource() )
{
ImGui::SetDragDropPayload(
DRAG_TYPE_FILE_TEXTURE_INFO, &info, sizeof( info ), ImGuiCond_Once /* Only copy the info once */ );
ImGui::SetTooltip( info.filename.c_str() );
ImGui::SetTooltip( info.m_filename.c_str() );
ImGui::EndDragDropSource();
}
@@ -168,7 +168,7 @@ namespace fgl::engine::filesystem
{
ImGui::SetDragDropPayload(
DRAG_TYPE_FILE_MODEL_INFO, &info, sizeof( info ), ImGuiCond_Once /* Only copy the info once */ );
ImGui::SetTooltip( info.filename.c_str() );
ImGui::SetTooltip( info.m_filename.c_str() );
ImGui::EndDragDropSource();
}
@@ -176,9 +176,9 @@ namespace fgl::engine::filesystem
void FileBrowser::drawFile( const FileInfo& data )
{
ImGui::PushID( data.path.c_str() );
ImGui::PushID( data.m_path.c_str() );
switch ( data.engine_type )
switch ( data.m_engine_type )
{
case TEXTURE:
drawTexture( data );
@@ -197,9 +197,9 @@ namespace fgl::engine::filesystem
break;
}
ImGui::Text( data.filename.c_str() );
ImGui::Text( data.m_filename.c_str() );
const std::string str { toHumanByteSize( data.size ) };
const std::string str { toHumanByteSize( data.m_size ) };
ImGui::Text( str.c_str() );
ImGui::NextColumn();
ImGui::PopID();

View File

@@ -30,7 +30,7 @@ namespace fgl::engine::gui
const filesystem::FileInfo* data { static_cast< filesystem::FileInfo* >( payload->Data ) };
//Determine what the file is
switch ( data->engine_type )
switch ( data->m_engine_type )
{
default:
[[fallthrough]];
@@ -48,7 +48,7 @@ namespace fgl::engine::gui
GameObject obj { GameObject::createGameObject() };
std::shared_ptr< Model > model {
Model::createModel( data->path, info.model_vertex_buffer, info.model_index_buffer )
Model::createModel( data->m_path, info.model_vertex_buffer, info.model_index_buffer )
};
obj.addFlag( IsEntity | IsVisible );
@@ -65,7 +65,7 @@ namespace fgl::engine::gui
{
SceneBuilder builder { info.model_vertex_buffer, info.model_index_buffer };
builder.loadScene( data->path );
builder.loadScene( data->m_path );
std::vector< GameObject > objs { builder.getGameObjects() };

View File

@@ -16,7 +16,7 @@
namespace fgl::engine::filesystem
{
DirInfo::DirInfo( const std::filesystem::path& path ) : m_path( path ), total_size( 0 )
DirInfo::DirInfo( const std::filesystem::path& path ) : m_path( path ), m_total_size( 0 )
{
FGL_ASSERT( std::filesystem::exists( path ), "Path must exist" );
for ( auto itter = std::filesystem::directory_iterator( path ); itter != std::filesystem::directory_iterator();
@@ -24,11 +24,11 @@ namespace fgl::engine::filesystem
{
if ( itter->is_regular_file() )
{
files.emplace_back( *itter );
m_files.emplace_back( *itter );
}
else if ( itter->is_directory() )
{
nested_dirs_to_scan.push( *itter );
m_nested_dirs_to_scan.push( *itter );
}
else
{
@@ -36,7 +36,7 @@ namespace fgl::engine::filesystem
}
}
nested_dirs.reserve( nested_dirs_to_scan.size() );
m_nested_dirs.reserve( m_nested_dirs_to_scan.size() );
}
EngineFileType determineEngineFileType( const std::filesystem::path& path )
@@ -63,32 +63,32 @@ namespace fgl::engine::filesystem
std::size_t DirInfo::fileCount() const
{
return files.size();
return m_files.size();
}
FileInfo& DirInfo::file( const std::size_t index )
{
return files[ index ];
return m_files[ index ];
}
DirInfo& DirInfo::dir( std::size_t index )
{
if ( index >= nested_dirs.size() + nested_dirs_to_scan.size() ) throw std::runtime_error( "Index OOB" );
if ( index >= m_nested_dirs.size() + m_nested_dirs_to_scan.size() ) throw std::runtime_error( "Index OOB" );
if ( index >= nested_dirs.size() )
if ( index >= m_nested_dirs.size() )
{
while ( nested_dirs.size() <= index )
while ( m_nested_dirs.size() <= index )
{
std::filesystem::path to_scan { std::move( nested_dirs_to_scan.front() ) };
nested_dirs_to_scan.pop();
std::filesystem::path to_scan { std::move( m_nested_dirs_to_scan.front() ) };
m_nested_dirs_to_scan.pop();
DirInfo info { to_scan };
nested_dirs.push_back( std::move( info ) );
m_nested_dirs.push_back( std::move( info ) );
}
}
return nested_dirs[ index ];
return m_nested_dirs[ index ];
}
} // namespace fgl::engine::filesystem

View File

@@ -17,14 +17,14 @@ namespace fgl::engine::filesystem
struct DirInfo
{
std::filesystem::path m_path;
std::size_t total_size { 0 };
std::vector< FileInfo > files {};
std::vector< DirInfo > nested_dirs {};
std::queue< std::filesystem::path > nested_dirs_to_scan {};
std::size_t m_total_size { 0 };
std::vector< FileInfo > m_files {};
std::vector< DirInfo > m_nested_dirs {};
std::queue< std::filesystem::path > m_nested_dirs_to_scan {};
public:
inline std::unique_ptr< DirInfo > up() const
std::unique_ptr< DirInfo > up() const
{
assert( std::filesystem::exists( m_path ) );
@@ -36,7 +36,7 @@ namespace fgl::engine::filesystem
bool hasParent() const { return !( m_path == "/" || m_path == "" ); }
inline std::size_t folderCount() const { return nested_dirs.size() + nested_dirs_to_scan.size(); }
std::size_t folderCount() const { return m_nested_dirs.size() + m_nested_dirs_to_scan.size(); }
DirInfo& dir( std::size_t index );
@@ -46,10 +46,10 @@ namespace fgl::engine::filesystem
DirInfo( const DirInfo& other ) :
m_path( other.m_path ),
total_size( other.total_size ),
files( other.files ),
nested_dirs( other.nested_dirs ),
nested_dirs_to_scan( other.nested_dirs_to_scan )
m_total_size( other.m_total_size ),
m_files( other.m_files ),
m_nested_dirs( other.m_nested_dirs ),
m_nested_dirs_to_scan( other.m_nested_dirs_to_scan )
{
assert( std::filesystem::exists( other.m_path ) );
}
@@ -58,10 +58,10 @@ namespace fgl::engine::filesystem
{
assert( std::filesystem::exists( other.m_path ) );
m_path = other.m_path;
total_size = other.total_size;
files = other.files;
nested_dirs = other.nested_dirs;
nested_dirs_to_scan = other.nested_dirs_to_scan;
m_total_size = other.m_total_size;
m_files = other.m_files;
m_nested_dirs = other.m_nested_dirs;
m_nested_dirs_to_scan = other.m_nested_dirs_to_scan;
return *this;
}
@@ -83,22 +83,22 @@ namespace fgl::engine::filesystem
struct FileInfo
{
std::string filename;
std::string ext;
std::filesystem::path path;
std::size_t size;
bool is_folder;
EngineFileType engine_type;
std::string m_filename;
std::string m_ext;
std::filesystem::path m_path;
std::size_t m_size;
bool m_is_folder;
EngineFileType m_engine_type;
FileInfo() = delete;
FileInfo( const std::filesystem::path& path_in ) :
filename( path_in.filename().string() ),
ext( path_in.extension().string() ),
path( path_in ),
size( std::filesystem::file_size( path_in ) ),
is_folder( std::filesystem::is_directory( path ) ),
engine_type( determineEngineFileType( path_in ) )
explicit FileInfo( const std::filesystem::path& path_in ) :
m_filename( path_in.filename().string() ),
m_ext( path_in.extension().string() ),
m_path( path_in ),
m_size( std::filesystem::file_size( path_in ) ),
m_is_folder( std::filesystem::is_directory( m_path ) ),
m_engine_type( determineEngineFileType( path_in ) )
{
assert( std::filesystem::exists( path_in ) );
}