From 21944a0d3c5284f6bf1e61286ddbcc2ab2f1e2aa Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sat, 26 Sep 2015 09:06:13 +0200 Subject: Add environment variable MINETEST_WORLD_PATH Also add PATH_DELIM for Windows compatibility. --- src/filesys.h | 2 ++ src/subgame.cpp | 46 ++++++++++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/filesys.h b/src/filesys.h index 19fcbb673..cc6f43ec4 100644 --- a/src/filesys.h +++ b/src/filesys.h @@ -28,10 +28,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #define DIR_DELIM "\\" #define DIR_DELIM_CHAR '\\' #define FILESYS_CASE_INSENSITIVE 1 +#define PATH_DELIM ";" #else // POSIX #define DIR_DELIM "/" #define DIR_DELIM_CHAR '/' #define FILESYS_CASE_INSENSITIVE 0 +#define PATH_DELIM ":" #endif namespace fs diff --git a/src/subgame.cpp b/src/subgame.cpp index a3fdce15a..20f5116e2 100644 --- a/src/subgame.cpp +++ b/src/subgame.cpp @@ -63,15 +63,10 @@ struct GameFindPath {} }; -Strfnd getSubgamePathEnv() { - std::string sp; +std::string getSubgamePathEnv() +{ char *subgame_path = getenv("MINETEST_SUBGAME_PATH"); - - if(subgame_path) { - sp = std::string(subgame_path); - } - - return Strfnd(sp); + return subgame_path ? std::string(subgame_path) : ""; } SubgameSpec findSubgame(const std::string &id) @@ -82,10 +77,10 @@ SubgameSpec findSubgame(const std::string &id) std::string user = porting::path_user; std::vector find_paths; - Strfnd search_paths = getSubgamePathEnv(); + Strfnd search_paths(getSubgamePathEnv()); - while(!search_paths.atend()) { - std::string path = search_paths.next(":"); + while (!search_paths.atend()) { + std::string path = search_paths.next(PATH_DELIM); find_paths.push_back(GameFindPath( path + DIR_DELIM + id, false)); find_paths.push_back(GameFindPath( @@ -156,13 +151,12 @@ std::set getAvailableGameIds() gamespaths.insert(porting::path_share + DIR_DELIM + "games"); gamespaths.insert(porting::path_user + DIR_DELIM + "games"); - Strfnd search_paths = getSubgamePathEnv(); + Strfnd search_paths(getSubgamePathEnv()); - while(!search_paths.atend()) { - gamespaths.insert(search_paths.next(":")); - } + while (!search_paths.atend()) + gamespaths.insert(search_paths.next(PATH_DELIM)); - for(std::set::const_iterator i = gamespaths.begin(); + for (std::set::const_iterator i = gamespaths.begin(); i != gamespaths.end(); ++i){ std::vector dirlist = fs::GetDirListing(*i); for(u32 j=0; j getAvailableWorlds() { std::vector worlds; std::set worldspaths; + + Strfnd search_paths(getWorldPathEnv()); + + while (!search_paths.atend()) + worldspaths.insert(search_paths.next(PATH_DELIM)); + worldspaths.insert(porting::path_user + DIR_DELIM + "worlds"); - infostream<<"Searching worlds..."<::const_iterator i = worldspaths.begin(); - i != worldspaths.end(); ++i){ - infostream<<" In "<<(*i)<<": "<::const_iterator i = worldspaths.begin(); + i != worldspaths.end(); ++i) { + infostream << " In " << (*i) << ": " < dirvector = fs::GetDirListing(*i); for(u32 j=0; j