]> git.tdb.fi Git - libs/game.git/blob - source/game/resources.cpp
Recursively add subdirectories of the data directory to resources
[libs/game.git] / source / game / resources.cpp
1 #include <msp/core/application.h>
2 #include <msp/fs/dir.h>
3 #include <msp/fs/stat.h>
4 #include "resources.h"
5
6 using namespace std;
7
8 namespace Msp::Game {
9
10 ApplicationResources::ApplicationResources()
11 {
12         FS::Path data_dir = FS::get_sys_data_dir()/"data";
13 #ifdef DEBUG
14         if(FS::exists(data_dir))
15                 add_dir(data_dir);
16         add_source(dir_src);
17 #endif
18
19         FS::Path main_pack = FS::get_sys_data_dir()/(Application::get_name()+".mdp");
20         if(FS::exists(main_pack))
21                 pack_src.add_pack_file(main_pack.str());
22         if(FS::exists(data_dir))
23         {
24                 for(const string &f: FS::list_filtered(data_dir, "\\.mdp$"))
25                         pack_src.add_pack_file((data_dir/f).str());
26         }
27         add_source(pack_src);
28 }
29
30 void ApplicationResources::add_dir(const FS::Path &path)
31 {
32         dir_src.add_directory(path);
33         for(const string &f: FS::list_files(path))
34         {
35                 FS::Path p = path/f;
36                 if(FS::is_dir(p))
37                         add_dir(p);
38         }
39 }
40
41 } // namespace Msp::Game