Author: ilor
Date: Sun Oct 19 00:47:54 2008
New Revision: 30261

URL: http://svn.gna.org/viewcvs/wesnoth?rev=30261&view=rev
Log:
Clean up read_file() by adding more versions of the function depending on how 
they treat relative paths. I found the current behaviour unintuitive and 
bug-friendly for some purposes (namely the editor). This should fix editor2's 
save/load inconsistencies with the --load option that fendrin spotted.

Modified:
    trunk/src/editor2/editor_map.cpp
    trunk/src/filesystem.cpp
    trunk/src/filesystem.hpp

Modified: trunk/src/editor2/editor_map.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_map.cpp?rev=30261&r1=30260&r2=30261&view=diff
==============================================================================
--- trunk/src/editor2/editor_map.cpp (original)
+++ trunk/src/editor2/editor_map.cpp Sun Oct 19 00:47:54 2008
@@ -60,7 +60,7 @@
 
 editor_map editor_map::load_from_file(const config& game_config, const 
std::string& filename)
 {
-       std::string map_string = read_file(filename);
+       std::string map_string = read_file(filename, false);
        if (map_string.empty()) {
                std::string message = _("Empty map file or file not found");
                throw editor_map_load_exception(filename, message);

Modified: trunk/src/filesystem.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/filesystem.cpp?rev=30261&r1=30260&r2=30261&view=diff
==============================================================================
--- trunk/src/filesystem.cpp (original)
+++ trunk/src/filesystem.cpp Sun Oct 19 00:47:54 2008
@@ -607,7 +607,13 @@
        return ss.str();
 }
 
-std::istream *istream_file(std::string fname)
+std::istream *istream_file(const std::string& fname, bool 
relative_from_game_path /*=true*/)
+{
+       std::string fname2(fname);
+       return istream_file(fname2, relative_from_game_path);
+}
+
+std::istream *istream_file(std::string& fname, bool relative_from_game_path 
/*=true*/)
 {
        LOG_FS << "streaming " << fname << " for reading.\n";
        if (fname.empty())
@@ -616,10 +622,10 @@
                return new std::ifstream();
        }
 #ifndef _WIN32
-       if (fname[0] != '/') {
+       if (relative_from_game_path && fname[0] != '/') {
 #else
        // Check if not start with driver letter
-       if (!std::isalpha(fname[0])) {
+       if (relative_from_game_path && !std::isalpha(fname[0])) {
 #endif
                if (!game_config::path.empty())
                        fname = game_config::path + "/" + fname;
@@ -634,9 +640,15 @@
 
 }
 
-std::string read_file(std::string const &fname)
-{
-       scoped_istream s = istream_file(fname);
+std::string read_file(const std::string &fname, bool relative_from_game_path 
/*=true*/)
+{
+       scoped_istream s = istream_file(fname, relative_from_game_path);
+       return read_stream(*s);
+}
+
+std::string read_file(std::string &fname, bool relative_from_game_path 
/*=true*/)
+{
+       scoped_istream s = istream_file(fname, relative_from_game_path);
        return read_stream(*s);
 }
 

Modified: trunk/src/filesystem.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/filesystem.hpp?rev=30261&r1=30260&r2=30261&view=diff
==============================================================================
--- trunk/src/filesystem.hpp (original)
+++ trunk/src/filesystem.hpp Sun Oct 19 00:47:54 2008
@@ -95,9 +95,15 @@
 
 // Basic disk I/O:
 
-/** Basic disk I/O - read file. */
-std::string read_file(const std::string& fname);
-std::istream *istream_file(std::string fname);
+/** Basic disk I/O - read file. 
+ * The bool relative_from_game_path determines whether relative paths should 
be treated as relative
+ * to the game path (true) or to the current directory from which Wesnoth was 
run (false).
+ * The non-const version will update the string if the game path is prepended.
+ */
+std::string read_file(const std::string &fname, bool relative_from_game_path = 
true);
+std::string read_file(std::string &fname, bool relative_from_game_path = true);
+std::istream *istream_file(const std::string& fname, bool 
relative_from_game_path = true);
+std::istream *istream_file(std::string& fname, bool relative_from_game_path = 
true);
 std::ostream *ostream_file(std::string const &fname);
 /** Throws io_exception if an error occurs. */
 void write_file(const std::string& fname, const std::string& data);


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

Reply via email to