Skip to content
This repository has been archived by the owner on Dec 3, 2020. It is now read-only.

Commit

Permalink
Find Minetest Executable
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Feb 2, 2015
1 parent 935b87e commit f748619
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/minetest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/minetest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Minetest
private:
Configuration *_conf;
std::string minetest_dir;
std::string minetest_exe;
};

#endif

0 comments on commit f748619

Please sign in to comment.