Adding Cedric's "Relative directory" patch I should have added a few weeks ago/
This commit is contained in:
parent
825846796c
commit
8c590c5f2b
2 changed files with 38 additions and 9 deletions
|
@ -96,13 +96,27 @@ int main(int argc, char** argv)
|
|||
preferences::set_fullscreen(true);
|
||||
} else if(val == "--datadir") {
|
||||
if (arg+1 != argc) {
|
||||
arg++;
|
||||
const std::string val(argv[arg]);
|
||||
if (!is_directory(val)) {
|
||||
std::cerr << "Could not find directory '" << val << "'\n";
|
||||
return 1;
|
||||
char buf[256];
|
||||
const std::string val(argv[++arg]);
|
||||
|
||||
if(val[0] == '/') {
|
||||
game_config::path = val;
|
||||
} else if(getcwd(buf,sizeof(buf)) != NULL) {
|
||||
std::string cwd(buf);
|
||||
|
||||
#ifdef _WIN32
|
||||
std::replace(cwd.begin(),cwd.end(),'\\','/');
|
||||
#endif
|
||||
game_config::path = cwd + '/' + val;
|
||||
} else {
|
||||
std::cerr << "Could not get working directory\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!is_directory(game_config::path)) {
|
||||
std::cerr << "Could not find directory '" << game_config::path << "'\n";
|
||||
return 0;
|
||||
}
|
||||
game_config::path = val;
|
||||
}
|
||||
} else if(val[0] == '-') {
|
||||
std::cerr << "unknown option: " << val << "\n";
|
||||
|
|
21
src/game.cpp
21
src/game.cpp
|
@ -376,12 +376,27 @@ int play_game(int argc, char** argv)
|
|||
std::cerr << "unknown option: " << val << "\n";
|
||||
return 0;
|
||||
} else {
|
||||
if(!is_directory(val)) {
|
||||
std::cerr << "Could not find directory '" << val << "'\n";
|
||||
char buf[256];
|
||||
|
||||
if(val[0] == '/') {
|
||||
game_config::path = val;
|
||||
} else if(getcwd(buf,sizeof(buf)) != NULL) {
|
||||
std::string cwd(buf);
|
||||
|
||||
#ifdef _WIN32
|
||||
std::replace(cwd.begin(),cwd.end(),'\\','/');
|
||||
#endif
|
||||
game_config::path = cwd + '/' + val;
|
||||
} else {
|
||||
std::cerr << "Could not get working directory\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!is_directory(game_config::path)) {
|
||||
std::cerr << "Could not find directory '" << game_config::path << "'\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
game_config::path = val;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue