mail[Wesnoth-commits] r33313 - in /trunk/src: editor2/editor_map.cpp filesystem.cpp filesystem.hpp


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

Header


Content

Posted by guillaume . melquiond on March 03, 2009 - 18:44:
Author: silene
Date: Tue Mar  3 18:44:26 2009
New Revision: 33313

URL: http://svn.gna.org/viewcvs/wesnoth?rev=33313&view=rev
Log:
Removed relative_from_game_path parameter, as it was mostly unused and broken 
under Windows anyway. Removed now unused non-const versions. Added a 
(temporary) check for enforcing that only absolute paths get there.

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=33313&r1=33312&r2=33313&view=diff
==============================================================================
--- trunk/src/editor2/editor_map.cpp (original)
+++ trunk/src/editor2/editor_map.cpp Tue Mar  3 18:44:26 2009
@@ -78,7 +78,7 @@
 editor_map editor_map::load_from_file(const config& game_config, const 
std::string& filename)
 {
        log_scope2(editor, "Loading map " + filename);
-       std::string map_string = read_file(filename, false);
+       std::string map_string = read_file(filename);
 
 
        if (map_string.empty()) {

Modified: trunk/src/filesystem.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/filesystem.cpp?rev=33313&r1=33312&r2=33313&view=diff
==============================================================================
--- trunk/src/filesystem.cpp (original)
+++ trunk/src/filesystem.cpp Tue Mar  3 18:44:26 2009
@@ -613,48 +613,37 @@
        return ss.str();
 }
 
-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";
+std::istream *istream_file(const std::string &fname)
+{
+       LOG_FS << "Streaming " << fname << " for reading.\n";
        if (fname.empty())
        {
-               ERR_FS << "Trying to open file with empty name\n";
-               return new std::ifstream();
+               ERR_FS << "Trying to open file with empty name.\n";
+               std::ifstream *s = new std::ifstream();
+               s->clear(std::ios_base::failbit);
+               return s;
        }
 #ifndef _WIN32
-       if (relative_from_game_path && fname[0] != '/') {
-#else
-       // Check if not start with driver letter
-       if (relative_from_game_path && !std::isalpha(fname[0])) {
-#endif
-               if (!game_config::path.empty())
-                       fname = game_config::path + "/" + fname;
-               else
-                       WRN_FS << "Using relative path for opening file 
without game_config::path set\n";
-       }
+       // TODO: Should also be done for Windows; but *nix systems should
+       // already be sufficient to catch most offenders.
+       if (fname[0] != '/') {
+               ERR_FS << "Trying to open file with relative path: '" << 
fname << "'.\n";
+               std::ifstream *s = new std::ifstream();
+               s->clear(std::ios_base::failbit);
+               return s;
+       }
+#endif
        std::ifstream *s = new 
std::ifstream(fname.c_str(),std::ios_base::binary);
        if (s->is_open())
                return s;
-       LOG_FS << "could not open '" << fname << "' for reading.\n";
+       ERR_FS << "Could not open '" << fname << "' for reading.\n";
        return s;
 
 }
 
-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);
+std::string read_file(const std::string &fname)
+{
+       scoped_istream s = istream_file(fname);
        return read_stream(*s);
 }
 
@@ -689,12 +678,9 @@
 
 std::string read_map(const std::string& name)
 {
-       std::string res = read_file("data/maps/" + name);
-       if(res == "") {
-               res = read_file(get_user_data_dir() + "/data/maps/" + name);
-       }
-
-       if(res == "") {
+       std::string res = read_file(get_wml_location("maps/" + name));
+
+       if (res.empty()) {
                res = read_file(get_user_data_dir() + "/editor/maps/" + name);
        }
 
@@ -1044,7 +1030,7 @@
                if (filename[0] == '@' && !already_found && 
!game_config::path.empty())
                        result = game_config::path + "/data/" + 
filename.substr(1);
        }
-       else if (filename.size() >= 2 && filename[0] == '.' && filename[1] == 
'/' )
+       else if (filename.size() >= 2 && filename[0] == '.' && filename[1] == 
'/')
        {
                // If the filename begins with a "./", look in the same 
directory
                // as the file currrently being preprocessed.

Modified: trunk/src/filesystem.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/filesystem.hpp?rev=33313&r1=33312&r2=33313&view=diff
==============================================================================
--- trunk/src/filesystem.hpp (original)
+++ trunk/src/filesystem.hpp Tue Mar  3 18:44:26 2009
@@ -98,12 +98,9 @@
 /** 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::string read_file(const std::string &fname);
+std::istream *istream_file(const std::string &fname);
 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);




Related Messages


Powered by MHonArc, Updated Tue Mar 03 19:00:07 2009