]> git.tdb.fi Git - libs/game.git/commitdiff
Recursively add subdirectories of the data directory to resources
authorMikko Rasa <tdb@tdb.fi>
Wed, 2 Nov 2022 22:19:21 +0000 (00:19 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 2 Nov 2022 22:19:21 +0000 (00:19 +0200)
source/game/resources.cpp
source/game/resources.h

index 0893f97525c564b6b5356e1fda5c420b309fbcc9..2b186de952049cb5ef504267775a6e0df191f96c 100644 (file)
@@ -12,7 +12,7 @@ ApplicationResources::ApplicationResources()
        FS::Path data_dir = FS::get_sys_data_dir()/"data";
 #ifdef DEBUG
        if(FS::exists(data_dir))
-               dir_src.add_directory(data_dir);
+               add_dir(data_dir);
        add_source(dir_src);
 #endif
 
@@ -27,4 +27,15 @@ ApplicationResources::ApplicationResources()
        add_source(pack_src);
 }
 
+void ApplicationResources::add_dir(const FS::Path &path)
+{
+       dir_src.add_directory(path);
+       for(const string &f: FS::list_files(path))
+       {
+               FS::Path p = path/f;
+               if(FS::is_dir(p))
+                       add_dir(p);
+       }
+}
+
 } // namespace Msp::Game
index b8f10b02b28adfe0a3e9a560e5848c7f1a99806f..c5b83726168406047a713056da7d1a1d1f3d2a21 100644 (file)
@@ -4,6 +4,7 @@
 #include <msp/datafile/collection.h>
 #include <msp/datafile/directorysource.h>
 #include <msp/datafile/packsource.h>
+#include <msp/fs/path.h>
 
 namespace Msp::Game {
 
@@ -20,6 +21,9 @@ private:
 
 public:
        ApplicationResources();
+
+private:
+       void add_dir(const FS::Path &);
 };
 
 } // namespace Msp::Game