Revert commit #27137 due to two serious issues mentioned on the tracker

This commit is contained in:
Piotr Cychowski 2008-06-13 09:42:39 +00:00
parent cd568bc6c3
commit 48ddf1335c
3 changed files with 25 additions and 96 deletions

View File

@ -28,8 +28,6 @@
#ifdef _WIN32
#include "filesystem_win32.ii"
#include <shlobj.h>
#include "SDL_syswm.h"
#else /* !_WIN32 */
#include <unistd.h>
#include <dirent.h>
@ -406,83 +404,35 @@ std::string get_cwd()
}
}
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;
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";
}
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/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";
} else {
// 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;
}
}
return "userdata";
}
#elif defined(__BEOS__)
if (be_path.InitCheck() != B_OK) {
@ -533,7 +483,6 @@ std::string get_user_data_dir()
mkdir((dir_path + "/data/multiplayer").c_str(),AccessMode);
mkdir((dir_path + "/data/maps").c_str(),AccessMode);
mkdir((dir_path + "/data/maps/multiplayer").c_str(),AccessMode);
mkdir((dir_path + "/data/units").c_str(),AccessMode);
mkdir((dir_path + "/saves").c_str(),AccessMode);
if(res == 0) {
dir = opendir(dir_path.c_str());

View File

@ -83,11 +83,6 @@ std::string get_cwd();
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:
//! Basic disk I/O - read file.

View File

@ -314,13 +314,7 @@ game_controller::game_controller(int argc, char** argv)
} else if (val.substr(0, 6) == "--log-") {
} else if(val == "--nosound") {
no_sound = true;
}
#ifdef _WIN32
else if(val == "--local-userdir") {
// redundant but it must be recognized...
}
#endif /* _WIN32 */
else if(val == "--new-widgets") {
} else if(val == "--new-widgets") {
// This is a hidden option to enable the new widget toolkit.
gui2::new_widgets = true;
} else if(val[0] == '-') {
@ -2337,11 +2331,6 @@ static int play_game(int argc, char** argv)
<< " 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"
;
@ -2459,11 +2448,7 @@ static int play_game(int argc, char** argv)
std::cout << lg::list_logdomains() << "\n";
return 0;
}
#ifdef _WIN32
else if(val == "--local-userdir") {
set_local_userdata(true);
}
#endif /* _WIN32 */
}
srand(time(NULL));