Find Minetest Executable

master
rubenwardy 2015-02-02 20:00:33 +00:00
parent 935b87e292
commit f7486192d5
2 changed files with 25 additions and 11 deletions

View File

@ -11,43 +11,59 @@
#endif #endif
Minetest::Minetest(Configuration *conf): Minetest::Minetest(Configuration *conf):
_conf(conf), minetest_dir("") _conf(conf), minetest_dir(""), minetest_exe("")
{} {}
bool Minetest::findMinetest() 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"); std::string path = _conf->get("minetest_root");
if (path != "") { if (path != "") {
if (PathExists(path.c_str())) { if (PathExists(path.c_str())) {
std::cerr << "Minetest found at " << path.c_str() << std::endl; std::cerr << "Minetest found at " << path.c_str() << std::endl;
minetest_dir = path; 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; return true;
} }
} }
#ifndef _WIN32 #ifndef _WIN32
std::cerr << "Searching in system-wide" << std::endl; std::cerr << "Searching for Minetest in system-wide" << std::endl;
path = getenv("HOME"); path = getenv("HOME");
path += "/.minetest/"; path += "/.minetest/";
std::cerr << path.c_str() << std::endl;
if (PathExists(path.c_str())) { if (PathExists(path.c_str())) {
std::cerr << "Minetest found at " << path.c_str() << std::endl; std::cerr << "Minetest found at " << path.c_str() << std::endl;
minetest_dir = path; minetest_dir = path;
if (PathExists("/usr/local/bin/minetest"))
minetest_exe = "/usr/local/bin/minetest";
else
minetest_exe = "/usr/bin/minetest";
return true; return true;
} }
#endif #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")); path = getSaveLoadDirectory(_conf->get("save_directory"), _conf->getBool("installed"));
if (PathExists((path + "../minetest/").c_str())) { if (PathExists((path + "../minetest/").c_str())) {
std::cerr << "Minetest found at " << (path + "../minetest/").c_str() << std::endl; std::cerr << "Minetest found at " << (path + "../minetest/").c_str() << std::endl;
minetest_dir = path + "../minetest/"; 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; return true;
} }
std::cerr << "Minetest not found!" << std::endl; std::cerr << "Minetest not found!" << std::endl;
return false; return false;
} }
@ -81,11 +97,8 @@ bool Minetest::runMod(const std::string &modname, const std::string &modpath,
rename(modpath.c_str(), cmd.c_str()); rename(modpath.c_str(), cmd.c_str());
// Run minetest // Run minetest
std::string exec = minetest_dir + DIR_DELIM "bin" DIR_DELIM "minetest"; std::string exec = minetest_exe;
#ifdef _WIN32 exec = " --worldname " + world + " --go";
exec += ".exe";
#endif
exec += " --worldname " + world + " --go";
system(exec.c_str()); system(exec.c_str());
return true; return true;
} }

View File

@ -14,6 +14,7 @@ public:
private: private:
Configuration *_conf; Configuration *_conf;
std::string minetest_dir; std::string minetest_dir;
std::string minetest_exe;
}; };
#endif #endif