Added functionality to place userdata...
...in an appropriante place on windows: if a relative path is passed as argument to --config-dir it will be relative to My Documents\My Games.
This commit is contained in:
parent
ae1cec2467
commit
99ec63f13f
3 changed files with 21 additions and 41 deletions
|
@ -53,7 +53,7 @@ goes directly to the campaign selection menu.
|
|||
.BI --config-dir \ name
|
||||
sets the user configuration directory to
|
||||
.I name
|
||||
under $HOME or %APPDATA% for windows.
|
||||
under $HOME or My Documents\\My Games for windows.
|
||||
.TP
|
||||
.B --config-path
|
||||
prints the path of the user configuration directory and exits.
|
||||
|
|
|
@ -442,49 +442,29 @@ void set_preferences_dir(std::string path)
|
|||
const std::string PREFERENCES_DIR = ".wesnoth" + std::string(game_config::version).substr(0,3);
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
#ifdef APPDATA_USERDATA
|
||||
const char* const appdata = getenv("APPDATA");
|
||||
#else
|
||||
const char* appdata = "";
|
||||
#endif /*APPDATA_USERDATA*/
|
||||
if (path.size() > 2 && path[1] == ':') {
|
||||
if(path.empty()) {
|
||||
game_config::preferences_dir = get_cwd() + "/userdata";
|
||||
} else if (path.size() > 2 && path[1] == ':') {
|
||||
//allow absolute path override
|
||||
game_config::preferences_dir = path;
|
||||
return;
|
||||
}
|
||||
if (strlen(appdata) > 0)
|
||||
{
|
||||
if (path.empty())
|
||||
{
|
||||
path = PREFERENCES_DIR;
|
||||
}
|
||||
game_config::preferences_dir = appdata +std::string("/")+ path;
|
||||
return;
|
||||
} else {
|
||||
if (path.empty())
|
||||
{
|
||||
path = "userdata";
|
||||
}
|
||||
#ifndef APPDATA_USERDATA
|
||||
else
|
||||
{
|
||||
// if the path is given fallback to %APPDATA%.
|
||||
appdata = getenv("APPDATA");
|
||||
game_config::preferences_dir = appdata + std::string("/") + path;
|
||||
return;
|
||||
}
|
||||
#endif /*APPDATA_USERDATA*/
|
||||
char buf[512];
|
||||
const char* const res = getcwd(buf,sizeof(buf));
|
||||
if (res == NULL)
|
||||
{
|
||||
game_config::preferences_dir = path;
|
||||
return;
|
||||
BOOL (*SHGetSpecialFolderPath)(HWND, LPTSTR, int, BOOL);
|
||||
HMODULE module = LoadLibrary("shell32");
|
||||
SHGetSpecialFolderPath = (BOOL (*)(HWND, LPTSTR, int, BOOL))GetProcAddress(module, "SHGetSpecialFolderPathA");
|
||||
if(SHGetSpecialFolderPath) {
|
||||
LOG_FS << "Using SHGetSpecialFolderPath to find My Documents\n";
|
||||
char my_documents_path[MAX_PATH];
|
||||
if(SHGetSpecialFolderPath(NULL, my_documents_path, 5, 1)) {
|
||||
std::string mygames_path = std::string(my_documents_path) + "\\" + "My Games";
|
||||
create_directory_if_missing(mygames_path);
|
||||
game_config::preferences_dir = mygames_path + "\\" + path;
|
||||
} else {
|
||||
WRN_FS << "SHGetSpecialFolderPath failed\n";
|
||||
game_config::preferences_dir = get_cwd() + "/" + path;
|
||||
}
|
||||
} else {
|
||||
std::string cur_path(res);
|
||||
std::replace(cur_path.begin(),cur_path.end(),'\\','/');
|
||||
game_config::preferences_dir = cur_path + "/" + path;
|
||||
return;
|
||||
LOG_FS << "Failed to load SHGetSpecialFolderPath function\n";
|
||||
game_config::preferences_dir = get_cwd() + "/" + path;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1720,7 +1720,7 @@ static int process_command_args(int argc, char** argv) {
|
|||
<< " --bpp <number> sets BitsPerPixel value. Example: --bpp 32\n"
|
||||
<< " -c, --campaign goes directly to the campaign selection menu.\n"
|
||||
<< " --config-dir <name> sets the path of the user config directory to\n"
|
||||
<< " $HOME/<name> or %APPDATA%\\<name> for windows.\n"
|
||||
<< " $HOME/<name> or My Documents\\My Games\\<name> for windows.\n"
|
||||
<< " --config-path prints the path of the user config directory and\n"
|
||||
<< " exits.\n"
|
||||
<< " -d, --debug enables additional command mode options in-game.\n"
|
||||
|
|
Loading…
Add table
Reference in a new issue