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


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

Header


Content

Posted by paniemin on August 26, 2008 - 17:42:
Author: suokko
Date: Tue Aug 26 17:42:43 2008
New Revision: 28996

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28996&view=rev
Log:
Dropped zipios support from istream_file function

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

Modified: trunk/src/filesystem.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/filesystem.cpp?rev=28996&r1=28995&r2=28996&view=diff
==============================================================================
--- trunk/src/filesystem.cpp (original)
+++ trunk/src/filesystem.cpp Tue Aug 26 17:42:43 2008
@@ -28,6 +28,7 @@
 
 #ifdef _WIN32
 #include "filesystem_win32.ii"
+#include <cctype>
 #else /* !_WIN32 */
 #include <unistd.h>
 #include <dirent.h>
@@ -548,25 +549,31 @@
        return ss.str();
 }
 
-std::istream *istream_file(std::string const &fname)
+std::istream *istream_file(std::string fname)
 {
        LOG_FS << "streaming " << fname << " for reading.\n";
-       if (!fname.empty() && fname[0] != '/' && !game_config::path.empty()) {
-               std::ifstream *s = new std::ifstream((game_config::path + "/" 
+ fname).c_str(),std::ios_base::binary);
-               if (s->is_open())
-                       return s;
-               LOG_FS << "could not open " << (game_config::path + "/" + 
fname) << " for reading.\n";
-               delete s;
-       }
-
-       //! @todo FIXME: why do we rely on this even with relative paths ?
-       // Still useful with zipios, for things like cache and prefs.
-       // NOTE zipios has been removed - not sure what to do with this code.
-       std::istream *s = new std::ifstream(fname.c_str(), 
std::ios_base::binary);
-       if (s->fail()) {
-               LOG_FS << "streaming " << fname << " failed.\n";
-       }
+       if (fname.empty())
+       {
+               ERR_FS << "Trying to open file with empty name\n";
+               return new std::ifstream();
+       }
+#ifndef _WIN32
+       if (fname[0] != '/') {
+#else
+       // Check if not start with driver letter
+       if (!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";
+       }
+       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";
        return s;
+
 }
 
 std::string read_file(std::string const &fname)

Modified: trunk/src/filesystem.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/filesystem.hpp?rev=28996&r1=28995&r2=28996&view=diff
==============================================================================
--- trunk/src/filesystem.hpp (original)
+++ trunk/src/filesystem.hpp Tue Aug 26 17:42:43 2008
@@ -88,7 +88,7 @@
 
 //! Basic disk I/O - read file.
 std::string read_file(const std::string& fname);
-std::istream *istream_file(std::string const &fname);
+std::istream *istream_file(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 Aug 26 18:01:32 2008