Also search the path for executable (#7871)
This commit is contained in:
parent
4a5ac6ed29
commit
d3c358513a
4 changed files with 26 additions and 12 deletions
|
@ -36,6 +36,7 @@
|
|||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/iostreams/device/file_descriptor.hpp>
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
#include <boost/process.hpp>
|
||||
#include "game_config_view.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -70,6 +71,7 @@ static lg::log_domain log_filesystem("filesystem");
|
|||
#define WRN_FS LOG_STREAM(warn, log_filesystem)
|
||||
#define ERR_FS LOG_STREAM(err, log_filesystem)
|
||||
|
||||
namespace bp = boost::process;
|
||||
namespace bfs = boost::filesystem;
|
||||
using boost::system::error_code;
|
||||
|
||||
|
@ -91,8 +93,6 @@ std::string default_preferences_path = "";
|
|||
#endif
|
||||
bool check_migration = false;
|
||||
|
||||
std::string wesnoth_program_dir;
|
||||
|
||||
const std::string observer_team_name = "observer";
|
||||
|
||||
int cache_compression_level = 6;
|
||||
|
@ -1002,18 +1002,34 @@ std::string get_exe_dir()
|
|||
bfs::path exe(process_path);
|
||||
return exe.parent_path().string();
|
||||
#else
|
||||
// first check /proc
|
||||
if(bfs::exists("/proc/")) {
|
||||
bfs::path self_exe("/proc/self/exe");
|
||||
error_code ec;
|
||||
bfs::path exe = bfs::read_symlink(self_exe, ec);
|
||||
if(ec) {
|
||||
return std::string();
|
||||
if(!ec) {
|
||||
return exe.parent_path().string();
|
||||
}
|
||||
|
||||
return exe.parent_path().string();
|
||||
} else {
|
||||
return get_cwd();
|
||||
}
|
||||
|
||||
// check the PATH for wesnoth's location
|
||||
// with version
|
||||
std::string version = std::to_string(game_config::wesnoth_version.major_version()) + "." + std::to_string(game_config::wesnoth_version.minor_version());
|
||||
std::string exe = filesystem::get_program_invocation("wesnoth-"+version);
|
||||
bfs::path search = bp::search_path(exe).string();
|
||||
if(!search.string().empty()) {
|
||||
return search.parent_path().string();
|
||||
}
|
||||
|
||||
// versionless
|
||||
exe = filesystem::get_program_invocation("wesnoth");
|
||||
search = bp::search_path(exe).string();
|
||||
if(!search.string().empty()) {
|
||||
return search.parent_path().string();
|
||||
}
|
||||
|
||||
// return the current working directory
|
||||
return get_cwd();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1698,7 +1714,7 @@ std::string get_program_invocation(const std::string& program_name)
|
|||
#endif
|
||||
);
|
||||
|
||||
return (bfs::path(game_config::wesnoth_program_dir) / real_program_name).string();
|
||||
return real_program_name;
|
||||
}
|
||||
|
||||
std::string sanitize_path(const std::string& path)
|
||||
|
|
|
@ -34,7 +34,6 @@ namespace game_config {
|
|||
extern std::string path;
|
||||
extern std::string default_preferences_path;
|
||||
extern bool check_migration;
|
||||
extern std::string wesnoth_program_dir;
|
||||
|
||||
/** observer team name used for observer team chat */
|
||||
extern const std::string observer_team_name;
|
||||
|
|
|
@ -820,7 +820,7 @@ bool game_launcher::goto_editor()
|
|||
void game_launcher::start_wesnothd()
|
||||
{
|
||||
std::string wesnothd_program = preferences::get_mp_server_program_name().empty()
|
||||
? filesystem::get_program_invocation("wesnothd")
|
||||
? filesystem::get_exe_dir() + "/" + filesystem::get_program_invocation("wesnothd")
|
||||
: preferences::get_mp_server_program_name();
|
||||
|
||||
std::string config = filesystem::get_user_config_dir() + "/lan_server.cfg";
|
||||
|
|
|
@ -751,7 +751,6 @@ static int do_gameloop(const std::vector<std::string>& args)
|
|||
srand(std::time(nullptr));
|
||||
|
||||
commandline_options cmdline_opts = commandline_options(args);
|
||||
game_config::wesnoth_program_dir = filesystem::directory_name(args[0]);
|
||||
|
||||
int finished = process_command_args(cmdline_opts);
|
||||
if(finished != -1) {
|
||||
|
|
Loading…
Add table
Reference in a new issue