Author: shadowmaster
Date: Mon Mar 10 18:39:30 2008
New Revision: 24501
URL: http://svn.gna.org/viewcvs/wesnoth?rev=24501&view=rev
Log:
* Apply patch #989 (TESTING)
Modified:
branches/shadowmaster_filesystem/src/filesystem.cpp
branches/shadowmaster_filesystem/src/filesystem.hpp
branches/shadowmaster_filesystem/src/game.cpp
Modified: branches/shadowmaster_filesystem/src/filesystem.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/shadowmaster_filesystem/src/filesystem.cpp?rev=24501&r1=24500&r2=24501&view=diff
==============================================================================
--- branches/shadowmaster_filesystem/src/filesystem.cpp (original)
+++ branches/shadowmaster_filesystem/src/filesystem.cpp Mon Mar 10 18:39:30 2008
@@ -22,10 +22,10 @@
// since these functions are NOT ANSI-conforming functions.
// They may have to be altered to port to new platforms
#include <sys/types.h>
-
//for mkdir
#include <sys/stat.h>
-#include <sys/types.h>
+
+#include "SDL_syswm.h"
#ifdef _WIN32
@@ -40,6 +40,7 @@
#include <errno.h>
#include <stdlib.h>
#include <windows.h>
+#include <shlobj.h>
/* /////////////////////////////////////////////////////////////////////////
@@ -567,6 +568,19 @@
return ret;
}
+namespace {
+ // stuff for local userdata
+ bool use_local_userdata = false;
+ bool userdata_status_inited = false;
+
+}
+
+void set_local_userdata(bool use_local)
+{
+ use_local_userdata = use_local;
+ userdata_status_inited = true;
+}
+
std::string get_cwd()
{
char buf[1024];
@@ -589,30 +603,65 @@
#ifdef _WIN32
static bool inited_dirs = false;
-
- if(!inited_dirs) {
- _mkdir("userdata");
- _mkdir("userdata/editor");
- _mkdir("userdata/editor/maps");
- _mkdir("userdata/data");
- _mkdir("userdata/data/ais");
- _mkdir("userdata/data/scenarios");
- _mkdir("userdata/data/scenarios/multiplayer");
- _mkdir("userdata/data/maps");
- _mkdir("userdata/data/maps/multiplayer");
- _mkdir("userdata/saves");
- inited_dirs = true;
- }
-
- char buf[256];
- const char* const res = getcwd(buf,sizeof(buf));
-
- if(res != NULL) {
- std::string cur_path(res);
- std::replace(cur_path.begin(),cur_path.end(),'\\','/');
- return cur_path + "/userdata";
+ char buf[MAX_PATH]; // should be something around 260
+
+ if(use_local_userdata) {
+ // use local
+ if(!inited_dirs) {
+ _mkdir("userdata");
+ _mkdir("userdata/editor");
+ _mkdir("userdata/editor/maps");
+ _mkdir("userdata/data");
+ _mkdir("userdata/data/ais");
+ _mkdir("userdata/data/scenarios");
+ _mkdir("userdata/data/scenarios/multiplayer");
+ _mkdir("userdata/data/maps");
+ _mkdir("userdata/data/maps/multiplayer");
+ _mkdir("userdata/saves");
+ inited_dirs = true;
+ }
+ const char* const res = getcwd(buf,sizeof(buf));
+ if(res != NULL) {
+ std::string cur_path(res);
+ std::replace(cur_path.begin(),cur_path.end(),'\\','/');
+ return cur_path + "/userdata";
+ } else {
+ return "userdata";
+ }
} else {
- return "userdata";
+ // use user folder
+ SDL_SysWMinfo wmInfo;
+
+ SDL_GetWMInfo(&wmInfo); // need some handle for win api
+ if (SHGetSpecialFolderPath(wmInfo.window, buf, CSIDL_PERSONAL,
true)) {
+ // CSIDL_PERSONAL === My Documents
+ std::string usr_path(buf);
+ LOG_FS << "Retrieved Windows user directory: " <<
usr_path << "\n";
+ std::replace(usr_path.begin(),usr_path.end(),'\\','/');
+ if(usr_path.empty()) {
+ // fallback to local if something didn't work
+ return "userdata";
+ } else {
+ // all OK
+ usr_path += "/Wesnoth/";
+ usr_path += VERSION;
+ // sort userdata by version
+ if(!inited_dirs) {
+ _mkdir(usr_path.c_str());
+ _mkdir((usr_path + "/editor").c_str());
+ _mkdir((usr_path +
"/editor/maps").c_str());
+ _mkdir((usr_path + "/data").c_str());
+ _mkdir((usr_path +
"/data/ais").c_str());
+ _mkdir((usr_path +
"/data/scenarios").c_str());
+ _mkdir((usr_path +
"/data/scenarios/multiplayer").c_str());
+ _mkdir((usr_path +
"/data/maps").c_str());
+ _mkdir((usr_path +
"/data/maps/multiplayer").c_str());
+ _mkdir((usr_path + "/saves").c_str());
+ inited_dirs = true;
+ }
+ return usr_path;
+ }
+ }
}
#elif defined(__BEOS__)
if (be_path.InitCheck() != B_OK) {
Modified: branches/shadowmaster_filesystem/src/filesystem.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/shadowmaster_filesystem/src/filesystem.hpp?rev=24501&r1=24500&r2=24501&view=diff
==============================================================================
--- branches/shadowmaster_filesystem/src/filesystem.hpp (original)
+++ branches/shadowmaster_filesystem/src/filesystem.hpp Mon Mar 10 18:39:30 2008
@@ -62,6 +62,8 @@
std::string get_screenshot_dir();
std::string get_upload_dir();
std::string get_user_data_dir();
+
+void set_local_userdata(bool use_local);
std::string get_cwd();
Modified: branches/shadowmaster_filesystem/src/game.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/shadowmaster_filesystem/src/game.cpp?rev=24501&r1=24500&r2=24501&view=diff
==============================================================================
--- branches/shadowmaster_filesystem/src/game.cpp (original)
+++ branches/shadowmaster_filesystem/src/game.cpp Mon Mar 10 18:39:30 2008
@@ -265,6 +265,9 @@
} else if (val.substr(0, 6) == "--log-") {
} else if(val == "--nosound") {
no_sound = true;
+ } else if(val == "--local-userdir") {
+ // redundant but it must be recognized...
+ ;
} else if(val[0] == '-') {
std::cerr << "unknown option: " << val << std::endl;
throw config::error("unknown option");
@@ -2031,6 +2034,8 @@
<< " by id.\n"
<< " --turns=value sets the number of
turns. The default is \"50\".\n"
<< " --exit-at-end exit Wesnoth at end
of scenario.\n"
+ << " --local-userdir Windows only: use
directory \"userdata\" instead\n"
+ << " of \"My
Documents\\Wesnoth\"\n"
;
return 0;
} else if(val == "--version" || val == "-v") {
@@ -2175,6 +2180,8 @@
} else if(val == "--logdomains") {
std::cout << lg::list_logdomains() << "\n";
return 0;
+ } else if(val == "--local-userdir") {
+ set_local_userdata(true);
}
}
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits