summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game.cpp27
-rw-r--r--src/game.h2
-rw-r--r--src/main.cpp68
3 files changed, 61 insertions, 36 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 83dff9d9..a91fdc23 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -85,6 +85,10 @@
#include <guichan/exception.hpp>
#include <guichan/focushandler.hpp>
+#include "physfs.h"
+
+#include <sys/stat.h>
+
#include <fstream>
#include <sstream>
#include <string>
@@ -134,6 +138,8 @@ EffectManager *effectManager = NULL;
ChatTab *localChatTab = NULL;
+std::string screenshotDir = "";
+
/**
* Tells the max tick value,
* setting it back to zero (and start again).
@@ -367,6 +373,20 @@ Game::~Game()
SDL_RemoveTimer(mSecondsCounterId);
}
+void setScreenshotDir(const std::string &dir)
+{
+ if (dir.empty())
+ {
+ screenshotDir = std::string(PHYSFS_getUserDir()) + "Desktop";
+ // If ~/Desktop does not exist, we save screenshots in the user's home.
+ struct stat statbuf;
+ if (stat(screenshotDir.c_str(), &statbuf))
+ screenshotDir = std::string(PHYSFS_getUserDir());
+ }
+ else
+ screenshotDir = dir;
+}
+
static bool saveScreenshot()
{
static unsigned int screenshotCount = 0;
@@ -383,12 +403,7 @@ static bool saveScreenshot()
screenshotCount++;
filenameSuffix.str("");
filename.str("");
-#if (defined __USE_UNIX98 || defined __FreeBSD__)
- filename << getHomeDirectory() << "/";
-#elif defined __APPLE__
- filename << PHYSFS_getUserDir();
- filename << "Desktop/";
-#endif
+ filename << screenshotDir << "/";
filenameSuffix << "Mana_Screenshot_" << screenshotCount << ".png";
filename << filenameSuffix.str();
testExists.open(filename.str().c_str(), std::ios::in);
diff --git a/src/game.h b/src/game.h
index 628c710b..1293db98 100644
--- a/src/game.h
+++ b/src/game.h
@@ -66,4 +66,6 @@ class Game : public ConfigListener
*/
int get_elapsed_time(int start_time);
+void setScreenshotDir(const std::string &dir);
+
#endif
diff --git a/src/main.cpp b/src/main.cpp
index 73752c9e..0f070dd1 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -181,6 +181,7 @@ struct Options
std::string updateHost;
std::string dataPath;
std::string homeDir;
+ std::string screenshotDir;
std::string serverName;
short serverPort;
@@ -519,23 +520,24 @@ static void printHelp()
std::cout
<< _("mana") << endl << endl
<< _("Options:") << endl
- << _(" -C --config-file : Configuration file to use") << endl
- << _(" -d --data : Directory to load game data from") << endl
- << _(" -D --default : Choose default character server and "
- "character") << endl
- << _(" -h --help : Display this help") << endl
- << _(" -S --home-dir : Directory to use as home directory") << endl
- << _(" -H --update-host : Use this update host") << endl
- << _(" -P --password : Login with this password") << endl
- << _(" -c --character : Login with this character") << endl
- << _(" -p --port : Login server port") << endl
- << _(" -s --server : Login server name or IP") << endl
- << _(" -u --skip-update : Skip the update downloads") << endl
- << _(" -U --username : Login with this username") << endl
+ << _(" -C --config-file : Configuration file to use") << endl
+ << _(" -d --data : Directory to load game data from") << endl
+ << _(" -D --default : Choose default character server and "
+ "character") << endl
+ << _(" -h --help : Display this help") << endl
+ << _(" -S --home-dir : Directory to use as home directory") << endl
+ << _(" -i --screenshot-dir : Directory to store screenshots") << endl
+ << _(" -H --update-host : Use this update host") << endl
+ << _(" -P --password : Login with this password") << endl
+ << _(" -c --character : Login with this character") << endl
+ << _(" -p --port : Login server port") << endl
+ << _(" -s --server : Login server name or IP") << endl
+ << _(" -u --skip-update : Skip the update downloads") << endl
+ << _(" -U --username : Login with this username") << endl
#ifdef USE_OPENGL
- << _(" -O --no-opengl : Disable OpenGL for this session") << endl
+ << _(" -O --no-opengl : Disable OpenGL for this session") << endl
#endif
- << _(" -v --version : Display the version") << endl;
+ << _(" -v --version : Display the version") << endl;
}
static void printVersion()
@@ -545,23 +547,24 @@ static void printVersion()
static void parseOptions(int argc, char *argv[], Options &options)
{
- const char *optstring = "hvud:U:P:Dc:s:p:C:H:S:O";
+ const char *optstring = "hvud:U:P:Dc:s:p:C:H:S:Oi:";
const struct option long_options[] = {
- { "config-file", required_argument, 0, 'C' },
- { "data", required_argument, 0, 'd' },
- { "default", no_argument, 0, 'D' },
- { "password", required_argument, 0, 'P' },
- { "character", required_argument, 0, 'c' },
- { "help", no_argument, 0, 'h' },
- { "home-dir", required_argument, 0, 'S' },
- { "update-host", required_argument, 0, 'H' },
- { "port", required_argument, 0, 'p' },
- { "server", required_argument, 0, 's' },
- { "skip-update", no_argument, 0, 'u' },
- { "username", required_argument, 0, 'U' },
- { "no-opengl", no_argument, 0, 'O' },
- { "version", no_argument, 0, 'v' },
+ { "config-file", required_argument, 0, 'C' },
+ { "data", required_argument, 0, 'd' },
+ { "default", no_argument, 0, 'D' },
+ { "password", required_argument, 0, 'P' },
+ { "character", required_argument, 0, 'c' },
+ { "help", no_argument, 0, 'h' },
+ { "home-dir", required_argument, 0, 'S' },
+ { "update-host", required_argument, 0, 'H' },
+ { "port", required_argument, 0, 'p' },
+ { "server", required_argument, 0, 's' },
+ { "skip-update", no_argument, 0, 'u' },
+ { "username", required_argument, 0, 'U' },
+ { "no-opengl", no_argument, 0, 'O' },
+ { "version", no_argument, 0, 'v' },
+ { "screenshot-dir", required_argument, 0, 'i' },
{ 0 }
};
@@ -618,6 +621,9 @@ static void parseOptions(int argc, char *argv[], Options &options)
case 'O':
options.noOpenGL = true;
break;
+ case 'i':
+ options.screenshotDir = optarg;
+ break;
}
}
}
@@ -766,6 +772,8 @@ int main(int argc, char *argv[])
initHomeDir(options);
+ setScreenshotDir(options.screenshotDir);
+
// Configure logger
logger = new Logger;
logger->setLogFile(homeDir + std::string("/mana.log"));