mail[Wesnoth-commits] r28934 - in /trunk/src: filesystem.cpp filesystem.hpp game.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by loonycyborg on August 24, 2008 - 16:29:
Author: loonycyborg
Date: Sun Aug 24 16:29:26 2008
New Revision: 28934

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28934&view=rev
Log:
Made wesnoth set data path to directory in which it's located if
data/_main.cfg exists in it.

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=28934&r1=28933&r2=28934&view=diff
==============================================================================
--- trunk/src/filesystem.cpp (original)
+++ trunk/src/filesystem.cpp Sun Aug 24 16:29:26 2008
@@ -31,6 +31,7 @@
 #else /* !_WIN32 */
 #include <unistd.h>
 #include <dirent.h>
+#include <libgen.h>
 #endif /* !_WIN32 */
 
 #ifdef __BEOS__
@@ -405,6 +406,20 @@
        }
 }
 
+std::string get_exe_dir()
+{
+#ifndef _WIN32
+       char buf[1024];
+       size_t path_size = readlink("/proc/self/exe", buf, 1024);
+       if(path_size == -1)
+               return std::string();
+       buf[path_size] = 0;
+       return std::string(dirname(buf));
+#else
+       return std::string();
+#endif
+}
+
 bool create_directory_if_missing(const std::string& dirname)
 {
        if(is_directory(dirname)) {

Modified: trunk/src/filesystem.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/filesystem.hpp?rev=28934&r1=28933&r2=28934&view=diff
==============================================================================
--- trunk/src/filesystem.hpp (original)
+++ trunk/src/filesystem.hpp Sun Aug 24 16:29:26 2008
@@ -79,6 +79,7 @@
 const std::string& get_user_data_dir();
 
 std::string get_cwd();
+std::string get_exe_dir();
 
 bool make_directory(const std::string& dirname);
 bool delete_directory(const std::string& dirname);

Modified: trunk/src/game.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game.cpp?rev=28934&r1=28933&r2=28934&view=diff
==============================================================================
--- trunk/src/game.cpp (original)
+++ trunk/src/game.cpp Sun Aug 24 16:29:26 2008
@@ -2264,6 +2264,13 @@
                } else {
                        std::cerr << "Wesnoth doesn't have the name wesnoth, 
so can't locate the server.\n";
                }
+
+               std::string exe_dir = get_exe_dir();
+               if(!exe_dir.empty() && file_exists(exe_dir + 
"/data/_main.cfg")) {
+                       std::cerr << "Found a data directory at " + exe_dir + 
", setting path to it.\n";
+                       game_config::path = exe_dir;
+               }
+
                std::cerr << "Battle for Wesnoth v" << game_config::revision 
<< '\n';
                time_t t = time(NULL);
                std::cerr << "Started on " << ctime(&t) << "\n";




Related Messages


Powered by MHonArc, Updated Sun Aug 24 16:41:27 2008