Author: shadowmaster
Date: Fri Jun 13 01:23:42 2008
New Revision: 27137
URL: http://svn.gna.org/viewcvs/wesnoth?rev=27137&view=rev
Log:
* Apply patch #989 for production purposes on the Win32 platform
Modified:
trunk/src/filesystem.cpp
trunk/src/filesystem.hpp
trunk/src/game.cpp
Modified: trunk/src/filesystem.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/filesystem.cpp?rev=27137&r1=27136&r2=27137&view=diff
==============================================================================
--- trunk/src/filesystem.cpp (original)
+++ trunk/src/filesystem.cpp Fri Jun 13 01:23:42 2008
@@ -28,6 +28,8 @@
#ifdef _WIN32
#include "filesystem_win32.ii"
+#include <shlobj.h>
+#include "SDL_syswm.h"
#else /* !_WIN32 */
#include <unistd.h>
#include <dirent.h>
@@ -404,36 +406,83 @@
}
}
+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_user_data_dir()
{
#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/campaigns");
- _mkdir("userdata/data/multiplayer");
- _mkdir("userdata/data/maps");
- _mkdir("userdata/data/maps/multiplayer");
- _mkdir("userdata/data/units");
- _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 + 1];
+ 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/campaigns");
+ _mkdir("userdata/data/multiplayer");
+ _mkdir("userdata/data/maps");
+ _mkdir("userdata/data/maps/multiplayer");
+ _mkdir("userdata/data/units");
+ _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 per-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/campaigns").c_str());
+ _mkdir((usr_path +
"/data/multiplayer").c_str());
+ _mkdir((usr_path +
"/data/maps").c_str());
+ _mkdir((usr_path +
"/data/maps/multiplayer").c_str());
+ _mkdir((usr_path +
"/data/units").c_str());
+ _mkdir((usr_path + "/saves").c_str());
+ inited_dirs = true;
+ }
+ return usr_path;
+ }
+ }
}
#elif defined(__BEOS__)
if (be_path.InitCheck() != B_OK) {
Modified: trunk/src/filesystem.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/filesystem.hpp?rev=27137&r1=27136&r2=27137&view=diff
==============================================================================
--- trunk/src/filesystem.hpp (original)
+++ trunk/src/filesystem.hpp Fri Jun 13 01:23:42 2008
@@ -82,6 +82,11 @@
bool make_directory(const std::string& dirname);
bool delete_directory(const std::string& dirname);
+
+//! Sets whether a "userdata" dir located in the working path
+//! should be used instead of per-user directories in Windows.
+//! This has no effect on other systems.
+void set_local_userdata(bool use_local);
// Basic disk I/O:
Modified: trunk/src/game.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game.cpp?rev=27137&r1=27136&r2=27137&view=diff
==============================================================================
--- trunk/src/game.cpp (original)
+++ trunk/src/game.cpp Fri Jun 13 01:23:42 2008
@@ -314,7 +314,13 @@
} else if (val.substr(0, 6) == "--log-") {
} else if(val == "--nosound") {
no_sound = true;
- } else if(val == "--new-widgets") {
+ }
+#ifdef _WIN32
+ else if(val == "--local-userdir") {
+ // redundant but it must be recognized...
+ }
+#endif /* _WIN32 */
+ else if(val == "--new-widgets") {
// This is a hidden option to enable the new widget
toolkit.
gui2::new_widgets = true;
} else if(val[0] == '-') {
@@ -2331,6 +2337,11 @@
<< " 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"
+#ifdef _WIN32
+ << " --local-userdir Windows only: use
directory \"userdata\" in the\n"
+ << " working path instead
of per-user\n"
+ << " \"My
Documents\\Wesnoth\"\n"
+#endif
<< " --new-widgets there is a new WIP
widget toolkit this switch enables the new toolkit\n"
<< " (VERY EXPERIMENTAL
don't file bug reports since most are known).\n"
;
@@ -2448,7 +2459,11 @@
std::cout << lg::list_logdomains() << "\n";
return 0;
}
-
+#ifdef _WIN32
+ else if(val == "--local-userdir") {
+ set_local_userdata(true);
+ }
+#endif /* _WIN32 */
}
srand(time(NULL));
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits