git repos / blockattack-game

commit db454a2d

sago007 · 2016-02-11 18:03
db454a2dc5f8635f86ae8a96b687b6de51f23fe1 patch · browse files
parent ee0773139cdbb40eb1e8492732c7a4bf9a301ee6

It is now possible to override the save path. The dir must exsist as we cannot create sub dirs at the moment

Changed files

M source/code/main.cpp before
M source/code/os.cpp before
M source/code/os.hpp before
diff --git a/source/code/main.cpp b/source/code/main.cpp index 0b05d2a..2331c51 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -1656,7 +1656,11 @@ int main(int argc, char* argv[]) {
("priority", "Causes the game to not sleep between frames.")
("verbose-basic", "Enables basic verbose messages")
("print-search-path", "Prints the search path and quits")
- ("bind-text-domain", boost::program_options::value<string>(), SPrintStringF("Overwrites the bind text domain used for finding translations. Default: \"%s\"", LOCALEDIR).c_str() )
+ ("bind-text-domain", boost::program_options::value<string>(), SPrintStringF("Overwrites the bind text domain used for finding translations. "
+ "Default: \"%s\"", LOCALEDIR).c_str())
+ ("homepath", boost::program_options::value<string>(), SPrintStringF("Set the home folder where settings are saved. The directory must exsist."
+ " Default: \"%s\"", getPathToSaveFiles().c_str()).c_str())
+
;
boost::program_options::variables_map vm;
try {
@@ -1672,6 +1676,11 @@ int main(int argc, char* argv[]) {
string s = vm["bind-text-domain"].as<string>();
bindtextdomain (PACKAGE, s.c_str());
}
+ if (vm.count("homepath")) {
+ string s = vm["homepath"].as<string>();
+ setPathToSaveFiles(s);
+ savepath = getPathToSaveFiles();
+ }
if (vm.count("help")) {
cout << SPrintStringF("Block Attack - Rise of the blocks %s\n"
"%s\n", VERSION_NUMBER, "www.blockattack.net");
diff --git a/source/code/os.cpp b/source/code/os.cpp index 6d481f3..2bcc0dc 100644 --- a/source/code/os.cpp +++ b/source/code/os.cpp
@@ -90,6 +90,8 @@ string getMyDocumentsPath() {
#endif
+static std::string overrideSavePath = "";
+
/**
* Returns the path to where all settings must be saved.
* On unix-like systems this is the home-folder under: ~/.gamesaves/GAMENAME
@@ -97,6 +99,9 @@ string getMyDocumentsPath() {
* Consider changing this for Vista that has a special save games folder
*/
std::string getPathToSaveFiles() {
+ if (overrideSavePath.length() > 0) {
+ return overrideSavePath;
+ }
#ifdef __unix__
return (std::string)getenv("HOME")+(std::string)"/.gamesaves/"+GAMENAME;
#elif _WIN32
@@ -106,6 +111,10 @@ std::string getPathToSaveFiles() {
#endif
}
+void setPathToSaveFiles(const std::string& path) {
+ overrideSavePath = path;
+}
+
std::string getPathToHighscoresEndless() {
return getPathToSaveFiles()+"/endless.dat";
}
diff --git a/source/code/os.hpp b/source/code/os.hpp index a0579a6..ebee643 100644 --- a/source/code/os.hpp +++ b/source/code/os.hpp
@@ -27,11 +27,13 @@ http://blockattack.net
#endif
#include <string>
-std::string getPathToSaveFiles() __attribute__((pure));
+std::string getPathToSaveFiles();
#if defined(_WIN32)
std::string getMyDocumentsPath();
#endif
+void setPathToSaveFiles(const std::string& path);
+
std::string getPathToHighscoresEndless();
std::string getPathToHighscoresTimetrial();