diff --git a/src/minetest.cpp b/src/minetest.cpp index 74ea6c8..d775345 100644 --- a/src/minetest.cpp +++ b/src/minetest.cpp @@ -11,43 +11,59 @@ #endif Minetest::Minetest(Configuration *conf): - _conf(conf), minetest_dir("") + _conf(conf), minetest_dir(""), minetest_exe("") {} bool Minetest::findMinetest() { - std::cerr << "Looking in settings for minetest_root" << std::endl; + std::cerr << "Searching for Minetest using minetest_root setting" << std::endl; std::string path = _conf->get("minetest_root"); if (path != "") { if (PathExists(path.c_str())) { std::cerr << "Minetest found at " << path.c_str() << std::endl; minetest_dir = path; + minetest_exe = minetest_dir + "bin/minetest"; + #ifdef _WIN32 + minetest_exe += ".exe"; + #endif + if (!PathExists(minetest_exe.c_str())) + std::cerr << "Error! exe missing from Minetest/bin" << std::endl; + return true; } } #ifndef _WIN32 - std::cerr << "Searching in system-wide" << std::endl; + std::cerr << "Searching for Minetest in system-wide" << std::endl; path = getenv("HOME"); path += "/.minetest/"; - std::cerr << path.c_str() << std::endl; if (PathExists(path.c_str())) { std::cerr << "Minetest found at " << path.c_str() << std::endl; minetest_dir = path; + if (PathExists("/usr/local/bin/minetest")) + minetest_exe = "/usr/local/bin/minetest"; + else + minetest_exe = "/usr/bin/minetest"; return true; } #endif - std::cerr << "Finding relative to nbe" << std::endl; + std::cerr << "Searching for Minetest relative to NBE save directory" << std::endl; path = getSaveLoadDirectory(_conf->get("save_directory"), _conf->getBool("installed")); if (PathExists((path + "../minetest/").c_str())) { std::cerr << "Minetest found at " << (path + "../minetest/").c_str() << std::endl; minetest_dir = path + "../minetest/"; + minetest_exe = minetest_dir + "bin/minetest"; +#ifdef _WIN32 + minetest_exe += ".exe"; +#endif + if (!PathExists(minetest_exe.c_str())) + std::cerr << "Error! exe missing from Minetest/bin" << std::endl; + return true; } - std::cerr << "Minetest not found!" << std::endl; return false; } @@ -81,11 +97,8 @@ bool Minetest::runMod(const std::string &modname, const std::string &modpath, rename(modpath.c_str(), cmd.c_str()); // Run minetest - std::string exec = minetest_dir + DIR_DELIM "bin" DIR_DELIM "minetest"; -#ifdef _WIN32 - exec += ".exe"; -#endif - exec += " --worldname " + world + " --go"; + std::string exec = minetest_exe; + exec = " --worldname " + world + " --go"; system(exec.c_str()); return true; } diff --git a/src/minetest.hpp b/src/minetest.hpp index 60255c8..7ce5a72 100644 --- a/src/minetest.hpp +++ b/src/minetest.hpp @@ -14,6 +14,7 @@ public: private: Configuration *_conf; std::string minetest_dir; + std::string minetest_exe; }; #endif