Add possibility to specify userDirectory via commandLine.
This commit is contained in:
parent
c9d9d1723e
commit
4cf60a5607
3 changed files with 18 additions and 13 deletions
src
|
@ -36,10 +36,11 @@ public:
|
|||
void SetDefaultValues();
|
||||
void SetLocalPlayerNameFromEnv();
|
||||
|
||||
const std::string &GetUserDirectory() const { return UserDirectory; }
|
||||
void SetUserDirectory(const std::string &path) { userDirectory = path; }
|
||||
const std::string &GetUserDirectory() const { return userDirectory; }
|
||||
|
||||
private:
|
||||
void SetUserDirectory();
|
||||
void SetDefaultUserDirectory();
|
||||
|
||||
public:
|
||||
std::string applicationName;
|
||||
|
@ -47,7 +48,7 @@ public:
|
|||
std::string luaEditorStartFilename;
|
||||
std::string LocalPlayerName; /// Name of local player
|
||||
private:
|
||||
std::string UserDirectory; /// Directory containing user settings and data
|
||||
std::string userDirectory; /// Directory containing user settings and data
|
||||
public:
|
||||
static Parameters Instance;
|
||||
};
|
||||
|
|
|
@ -43,27 +43,27 @@ void Parameters::SetDefaultValues()
|
|||
applicationName = "stratagus";
|
||||
luaStartFilename = "scripts/stratagus.lua";
|
||||
luaEditorStartFilename = "scripts/editor.lua";
|
||||
SetUserDirectory();
|
||||
SetDefaultUserDirectory();
|
||||
}
|
||||
|
||||
void Parameters::SetUserDirectory()
|
||||
void Parameters::SetDefaultUserDirectory()
|
||||
{
|
||||
#ifdef USE_WIN32
|
||||
UserDirectory = getenv("APPDATA");
|
||||
userDirectory = getenv("APPDATA");
|
||||
#else
|
||||
UserDirectory = getenv("HOME");
|
||||
userDirectory = getenv("HOME");
|
||||
#endif
|
||||
|
||||
if (!UserDirectory.empty()) {
|
||||
UserDirectory += "/";
|
||||
if (!userDirectory.empty()) {
|
||||
userDirectory += "/";
|
||||
}
|
||||
|
||||
#ifdef USE_WIN32
|
||||
UserDirectory += "Stratagus";
|
||||
userDirectory += "Stratagus";
|
||||
#elif defined(USE_MAC)
|
||||
UserDirectory += "Library/Stratagus";
|
||||
userDirectory += "Library/Stratagus";
|
||||
#else
|
||||
UserDirectory += ".stratagus";
|
||||
userDirectory += ".stratagus";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -446,6 +446,7 @@ static void Usage()
|
|||
"\t-P port\t\tNetwork port to use\n"
|
||||
"\t-s sleep\tNumber of frames for the AI to sleep before it starts\n"
|
||||
"\t-S speed\tSync speed (100 = 30 frames/s)\n"
|
||||
"\t-u userpath\tPath where stratagus saves preferences, log and savegame\n"
|
||||
"\t-v mode\t\tVideo mode resolution in format <xres>x<yres>\n"
|
||||
"\t-W\t\tWindowed video mode\n"
|
||||
"map is relative to StratagusLibPath=datapath, use ./map for relative to cwd\n",
|
||||
|
@ -498,7 +499,7 @@ static void RedirectOutput()
|
|||
void ParseCommandLine(int argc, char **argv, Parameters ¶meters)
|
||||
{
|
||||
for (;;) {
|
||||
switch (getopt(argc, argv, "c:d:D:eE:FhI:lN:oOP:s:S:v:W?")) {
|
||||
switch (getopt(argc, argv, "c:d:D:eE:FhI:lN:oOP:s:S:u:v:W?")) {
|
||||
case 'c':
|
||||
parameters.luaStartFilename = optarg;
|
||||
continue;
|
||||
|
@ -551,6 +552,9 @@ void ParseCommandLine(int argc, char **argv, Parameters ¶meters)
|
|||
case 'S':
|
||||
VideoSyncSpeed = atoi(optarg);
|
||||
continue;
|
||||
case 'u':
|
||||
Parameters::Instance.SetUserDirectory(optarg);
|
||||
continue;
|
||||
case 'v': {
|
||||
char *sep = strchr(optarg, 'x');
|
||||
if (!sep || !*(sep + 1)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue