Author: suokko
Date: Wed Sep 10 19:27:34 2008
New Revision: 29382

URL: http://svn.gna.org/viewcvs/wesnoth?rev=29382&view=rev
Log:
* Added commandline argument to set user data dir name (bug #12276)
* Fixed config reload forcing to work

Modified:
    trunk/src/addon_management.cpp
    trunk/src/filesystem.cpp
    trunk/src/filesystem.hpp
    trunk/src/game.cpp
    trunk/src/game_config.cpp
    trunk/src/game_config.hpp

Modified: trunk/src/addon_management.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/addon_management.cpp?rev=29382&r1=29381&r2=29382&view=diff
==============================================================================
--- trunk/src/addon_management.cpp (original)
+++ trunk/src/addon_management.cpp Wed Sep 10 19:27:34 2008
@@ -53,14 +53,6 @@
 #define ERR_NET LOG_STREAM(err , network)
 #define LOG_NET LOG_STREAM(info, network)
 
-namespace {
-       void setup_addon_dirs()
-       {
-               make_directory(get_user_data_dir() + "/data");
-               make_directory(get_addon_campaigns_dir());
-       }
-} // end unnamed namespace 1
-
 void get_addon_info(const std::string& addon_name, config& cfg)
 {
        const std::string parentd = get_addon_campaigns_dir();
@@ -293,7 +285,6 @@
 void unarchive_addon(const config& cfg)
 {
        const std::string parentd = get_addon_campaigns_dir();
-       setup_addon_dirs();
        unarchive_dir(parentd, cfg);
 }
 

Modified: trunk/src/filesystem.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/filesystem.cpp?rev=29382&r1=29381&r2=29382&view=diff
==============================================================================
--- trunk/src/filesystem.cpp (original)
+++ trunk/src/filesystem.cpp Wed Sep 10 19:27:34 2008
@@ -433,35 +433,95 @@
        return make_directory(dirname);
 }
 
+
+namespace {
+       std::string user_data_dir;
+}
+
+static std::string setup_user_data_dir();
+
+void set_preferences_dir(std::string path)
+{
 #ifndef PREFERENCES_DIR
-#define PREFERENCES_DIR ".wesnoth"
-#endif
+const std::string PREFERENCES_DIR = ".wesnoth" + 
std::string(game_config::version).substr(0,3);
+#endif
+#ifdef _WIN32
+#ifndef SHARED_USERDATA
+       const char* appdata = getenv("APPDATA");
+#else
+       const char* appdata = "";
+#endif
+       if (strlen(appdata) > 0)
+       {
+               if (path.empty())
+               {
+                       path = PREFERENCES_DIR;
+               }
+               game_config::preferences_dir += appdata +"/"+ path;
+               return;
+       } else {
+               if (path.empty())
+               {
+                       path = "userdata";
+               }
+               char buf[512];
+               const char* const res = getcwd(buf,sizeof(buf));
+               if (res == NULL)
+               {
+                       game_config::preferences_dir = path;
+                       return;
+               } else {
+                       std::string cur_path(res);
+                       std::replace(cur_path.begin(),cur_path.end(),'\\','/');
+                       game_config::preference_dir = cur_path + "/" + path;
+                       return;
+               }
+       }
+
+#else
+       if (path.empty())
+               path = PREFERENCES_DIR;
+#ifndef __AMIGAOS4__
+       const char* const current_dir = ".";
+       const char* home_str = getenv("HOME");
+#else
+       const char* const current_dir = " ";
+       const char* home_str = "PROGDIR:";
+#endif
+       if(home_str == NULL)
+               home_str = current_dir;
+
+       const std::string home(home_str);
+
+#ifndef __AMIGAOS4__
+       game_config::preferences_dir = home + std::string("/") + path;
+#else
+       game_config::preferences_dir = home + path;
+#endif
+
+#endif
+       user_data_dir = setup_user_data_dir();
+}
+
 
 static std::string setup_user_data_dir()
 {
+       if (game_config::preferences_dir.empty())
+               set_preferences_dir(std::string());
 #ifdef _WIN32
-       _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");
-
-       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 {
-               return "userdata";
-       }
+       _mkdir(game_config::preferences_dir);
+       _mkdir(game_config::preferences_dir + "/editor");
+       _mkdir(game_config::preferences_dir + "/editor/maps");
+       _mkdir(game_config::preferences_dir + "/data");
+       _mkdir(game_config::preferences_dir + "/data/ais");
+       _mkdir(game_config::preferences_dir + "/data/campaigns");
+       _mkdir(game_config::preferences_dir + "/data/multiplayer");
+       _mkdir(game_config::preferences_dir + "/data/maps");
+       _mkdir(game_config::preferences_dir + "/data/maps/multiplayer");
+       _mkdir(game_config::preferences_dir + "/data/units");
+       _mkdir(game_config::preferences_dir + "/saves");
+
+       return game_config::preferences_dir;
 #elif defined(__BEOS__)
        if (be_path.InitCheck() != B_OK) {
                BPath tpath;
@@ -489,24 +549,7 @@
        }
        return be_path.Path();
 #else
-
-#ifndef __AMIGAOS4__
-       static const char* const current_dir = ".";
-       const char* home_str = getenv("HOME");
-#else
-       static const char* const current_dir = " ";
-       const char* home_str = "PROGDIR:";
-#endif
-       if(home_str == NULL)
-               home_str = current_dir;
-
-       const std::string home(home_str);
-
-#ifndef __AMIGAOS4__
-       const std::string dir_path = home + std::string("/") + PREFERENCES_DIR;
-#else
-       const std::string dir_path = home + PREFERENCES_DIR;
-#endif
+       const std::string& dir_path = game_config::preferences_dir;
 
        const bool res = create_directory_if_missing(dir_path);
        // probe read permissions (if we could make the directory)
@@ -538,7 +581,10 @@
        // ensure setup gets called only once per session
        // FIXME: this is okay and optimized, but how should we react
        // if the user deletes a dir while we are running?
-       static std::string const user_data_dir = setup_user_data_dir();
+       if (user_data_dir.empty())
+       {
+               user_data_dir = setup_user_data_dir();
+       }
        return user_data_dir;
 }
 

Modified: trunk/src/filesystem.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/filesystem.hpp?rev=29382&r1=29381&r2=29382&view=diff
==============================================================================
--- trunk/src/filesystem.hpp (original)
+++ trunk/src/filesystem.hpp Wed Sep 10 19:27:34 2008
@@ -76,6 +76,7 @@
 //! maximum 1000 files then start always giving 999
 std::string get_next_filename(const std::string& name, const std::string& 
extension);
 std::string get_upload_dir();
+void set_preferences_dir(std::string path);
 const std::string& get_user_data_dir();
 
 std::string get_cwd();

Modified: trunk/src/game.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game.cpp?rev=29382&r1=29381&r2=29382&view=diff
==============================================================================
--- trunk/src/game.cpp (original)
+++ trunk/src/game.cpp Wed Sep 10 19:27:34 2008
@@ -331,6 +331,10 @@
                                        multiplayer_server_ = "";
                        }
 
+               } else if(val == "--config-dir") {
+                       if (argc_ <= ++arg_)
+                               break;
+                       set_preferences_dir(argv_[arg_]);
                } else if(val == "--multiplayer" || val == "-m") {
                        multiplayer_mode_ = true;
                        break; //parse the rest of the arguments when we set up 
the game
@@ -1142,6 +1146,7 @@
 
                //force a reload of configuration information
                cache_.recheck_filetree_checksum();
+               old_defines_map_.clear();
                clear_binary_paths_cache();
                init_config();
        }
@@ -1666,12 +1671,8 @@
                        std::cout << "usage: " << argv[0]
                        << " [OPTIONS] [DATA-DIRECTORY]\n"
                        << "  --bpp number                 sets BitsPerPixel 
value. Example: --bpp 32\n"
-                       << "  --compress INFILE OUTFILE    compresses a 
savefile (INFILE) that is in text WML\n"
-                       << "                               format into binary 
WML format (OUTFILE).\n"
                        << "  -d, --debug                  shows extra 
debugging information and enables\n"
                        << "                               additional command 
mode options in-game.\n"
-                       << "  --decompress INFILE OUTFILE  decompresses a 
savefile (INFILE) that is in binary\n"
-                       << "                               WML format into text 
WML format (OUTFILE).\n"
 #ifndef DISABLE_EDITOR2
                        << "  -e, --editor                 starts editor2 not 
showing title screen.\n"
 #endif
@@ -1700,6 +1701,7 @@
                        << "  --max-fps                    the maximum fps the 
game tries to run at the value\n"
                        << "                               should be between 
the 1 and 1000, the default is 50.\n"
                        << "  --config-path                prints the path to 
the game config directory and exits.\n"
+                       << "  --config-dir=<path>          set name of game 
config directory.\n"
                        << "  --path                       prints the path to 
the game data directory and exits.\n"
 #ifdef HAVE_PYTHON
                        << "  --python-api                 prints the runtime 
documentation for the python API.\n"
@@ -1776,47 +1778,6 @@
                                }
                                p = q;
                        }
-               //! @todo the (de)compress will be removed, the feature is 
broken for quite
-               //! a while and is replaced with --g(un)zip. 1.5.1 would be a 
nice point for
-               //! removal.
-               } else if(val == "--compress" || val == "--decompress") {
-                       if(argc != arg+3) {
-                               std::cerr << "format of " << val << " command: 
" << val << " <input file> <output file>\n";
-                               return 0;
-                       }
-
-                       const std::string input(argv[arg+1]);
-                       const std::string output(argv[arg+2]);
-
-                       scoped_istream stream = istream_file(input);
-                       if (stream->fail()) {
-                               std::cerr << "could not read file '" << input 
<< "'\n";
-                               return 0;
-                       }
-
-                       config cfg;
-
-                       const bool compress = val == "--compress";
-                       try {
-                               const bool is_compressed = 
detect_format_and_read(cfg, *stream);
-                               if(is_compressed && compress) {
-                                       std::cerr << input << " is already 
compressed\n";
-                                       return 0;
-                               } else if(!is_compressed && !compress) {
-                                       std::cerr << input << " is already 
decompressed\n";
-                                       return 0;
-                               }
-
-                               scoped_ostream output_stream = 
ostream_file(output);
-                               write_possibly_compressed(*output_stream, cfg, 
compress);
-                       } catch(config::error& e) {
-                               std::cerr << input << " is not a valid Wesnoth 
file: " << e.message << "\n";
-                       } catch(io_exception& e) {
-                               std::cerr << "IO error: " << e.what() << "\n";
-                       }
-
-                       return 0;
-
                } else if(val == "--gzip") {
                        if(argc != arg + 2) {
                                std::cerr << "format of " << val << " command: 
" << val << " <input file>\n";

Modified: trunk/src/game_config.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_config.cpp?rev=29382&r1=29381&r2=29382&view=diff
==============================================================================
--- trunk/src/game_config.cpp (original)
+++ trunk/src/game_config.cpp Wed Sep 10 19:27:34 2008
@@ -142,6 +142,9 @@
        std::string path = "";
 #endif
 #endif
+
+       std::string preferences_dir = "";
+
        std::vector<server_info> server_list;
 
        void load_config(const config* cfg)

Modified: trunk/src/game_config.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_config.hpp?rev=29382&r1=29381&r2=29382&view=diff
==============================================================================
--- trunk/src/game_config.hpp (original)
+++ trunk/src/game_config.hpp Wed Sep 10 19:27:34 2008
@@ -53,6 +53,7 @@
        extern int cache_compression_level;
 
        extern std::string path;
+       extern std::string preferences_dir;
 
        struct server_info {
                server_info() : name(""), address("") { }


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to