Add environment variable MINETEST_WORLD_PATH
Also add PATH_DELIM for Windows compatibility.
This commit is contained in:
parent
8aaae7db05
commit
21944a0d3c
|
@ -28,10 +28,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#define DIR_DELIM "\\"
|
#define DIR_DELIM "\\"
|
||||||
#define DIR_DELIM_CHAR '\\'
|
#define DIR_DELIM_CHAR '\\'
|
||||||
#define FILESYS_CASE_INSENSITIVE 1
|
#define FILESYS_CASE_INSENSITIVE 1
|
||||||
|
#define PATH_DELIM ";"
|
||||||
#else // POSIX
|
#else // POSIX
|
||||||
#define DIR_DELIM "/"
|
#define DIR_DELIM "/"
|
||||||
#define DIR_DELIM_CHAR '/'
|
#define DIR_DELIM_CHAR '/'
|
||||||
#define FILESYS_CASE_INSENSITIVE 0
|
#define FILESYS_CASE_INSENSITIVE 0
|
||||||
|
#define PATH_DELIM ":"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace fs
|
namespace fs
|
||||||
|
|
|
@ -63,15 +63,10 @@ struct GameFindPath
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
Strfnd getSubgamePathEnv() {
|
std::string getSubgamePathEnv()
|
||||||
std::string sp;
|
{
|
||||||
char *subgame_path = getenv("MINETEST_SUBGAME_PATH");
|
char *subgame_path = getenv("MINETEST_SUBGAME_PATH");
|
||||||
|
return subgame_path ? std::string(subgame_path) : "";
|
||||||
if(subgame_path) {
|
|
||||||
sp = std::string(subgame_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Strfnd(sp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SubgameSpec findSubgame(const std::string &id)
|
SubgameSpec findSubgame(const std::string &id)
|
||||||
|
@ -82,10 +77,10 @@ SubgameSpec findSubgame(const std::string &id)
|
||||||
std::string user = porting::path_user;
|
std::string user = porting::path_user;
|
||||||
std::vector<GameFindPath> find_paths;
|
std::vector<GameFindPath> find_paths;
|
||||||
|
|
||||||
Strfnd search_paths = getSubgamePathEnv();
|
Strfnd search_paths(getSubgamePathEnv());
|
||||||
|
|
||||||
while(!search_paths.atend()) {
|
while (!search_paths.atend()) {
|
||||||
std::string path = search_paths.next(":");
|
std::string path = search_paths.next(PATH_DELIM);
|
||||||
find_paths.push_back(GameFindPath(
|
find_paths.push_back(GameFindPath(
|
||||||
path + DIR_DELIM + id, false));
|
path + DIR_DELIM + id, false));
|
||||||
find_paths.push_back(GameFindPath(
|
find_paths.push_back(GameFindPath(
|
||||||
|
@ -156,13 +151,12 @@ std::set<std::string> getAvailableGameIds()
|
||||||
gamespaths.insert(porting::path_share + DIR_DELIM + "games");
|
gamespaths.insert(porting::path_share + DIR_DELIM + "games");
|
||||||
gamespaths.insert(porting::path_user + DIR_DELIM + "games");
|
gamespaths.insert(porting::path_user + DIR_DELIM + "games");
|
||||||
|
|
||||||
Strfnd search_paths = getSubgamePathEnv();
|
Strfnd search_paths(getSubgamePathEnv());
|
||||||
|
|
||||||
while(!search_paths.atend()) {
|
while (!search_paths.atend())
|
||||||
gamespaths.insert(search_paths.next(":"));
|
gamespaths.insert(search_paths.next(PATH_DELIM));
|
||||||
}
|
|
||||||
|
|
||||||
for(std::set<std::string>::const_iterator i = gamespaths.begin();
|
for (std::set<std::string>::const_iterator i = gamespaths.begin();
|
||||||
i != gamespaths.end(); ++i){
|
i != gamespaths.end(); ++i){
|
||||||
std::vector<fs::DirListNode> dirlist = fs::GetDirListing(*i);
|
std::vector<fs::DirListNode> dirlist = fs::GetDirListing(*i);
|
||||||
for(u32 j=0; j<dirlist.size(); j++){
|
for(u32 j=0; j<dirlist.size(); j++){
|
||||||
|
@ -223,15 +217,27 @@ std::string getWorldGameId(const std::string &world_path, bool can_be_legacy)
|
||||||
return conf.get("gameid");
|
return conf.get("gameid");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string getWorldPathEnv()
|
||||||
|
{
|
||||||
|
char *world_path = getenv("MINETEST_WORLD_PATH");
|
||||||
|
return world_path ? std::string(world_path) : "";
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<WorldSpec> getAvailableWorlds()
|
std::vector<WorldSpec> getAvailableWorlds()
|
||||||
{
|
{
|
||||||
std::vector<WorldSpec> worlds;
|
std::vector<WorldSpec> worlds;
|
||||||
std::set<std::string> worldspaths;
|
std::set<std::string> worldspaths;
|
||||||
|
|
||||||
|
Strfnd search_paths(getWorldPathEnv());
|
||||||
|
|
||||||
|
while (!search_paths.atend())
|
||||||
|
worldspaths.insert(search_paths.next(PATH_DELIM));
|
||||||
|
|
||||||
worldspaths.insert(porting::path_user + DIR_DELIM + "worlds");
|
worldspaths.insert(porting::path_user + DIR_DELIM + "worlds");
|
||||||
infostream<<"Searching worlds..."<<std::endl;
|
infostream << "Searching worlds..." << std::endl;
|
||||||
for(std::set<std::string>::const_iterator i = worldspaths.begin();
|
for (std::set<std::string>::const_iterator i = worldspaths.begin();
|
||||||
i != worldspaths.end(); ++i){
|
i != worldspaths.end(); ++i) {
|
||||||
infostream<<" In "<<(*i)<<": "<<std::endl;
|
infostream << " In " << (*i) << ": " <<std::endl;
|
||||||
std::vector<fs::DirListNode> dirvector = fs::GetDirListing(*i);
|
std::vector<fs::DirListNode> dirvector = fs::GetDirListing(*i);
|
||||||
for(u32 j=0; j<dirvector.size(); j++){
|
for(u32 j=0; j<dirvector.size(); j++){
|
||||||
if(!dirvector[j].dir)
|
if(!dirvector[j].dir)
|
||||||
|
|
Loading…
Reference in New Issue