wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src filesystem.cpp filesystem.hpp game.cpp


From: Yann Dirson
Subject: [Wesnoth-cvs-commits] wesnoth/src filesystem.cpp filesystem.hpp game.cpp
Date: Fri, 31 Dec 2004 14:13:14 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Yann Dirson <address@hidden>    04/12/31 02:21:00

Modified files:
        src            : filesystem.cpp filesystem.hpp game.cpp 

Log message:
        first pass at integrating zipios++ - we still do not use files from the 
zip yet, but we fetch the list of files in the zips

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/filesystem.cpp.diff?tr1=1.50&tr2=1.51&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/filesystem.hpp.diff?tr1=1.30&tr2=1.31&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game.cpp.diff?tr1=1.177&tr2=1.178&r1=text&r2=text

Patches:
Index: wesnoth/src/filesystem.cpp
diff -u wesnoth/src/filesystem.cpp:1.50 wesnoth/src/filesystem.cpp:1.51
--- wesnoth/src/filesystem.cpp:1.50     Thu Dec 30 19:32:35 2004
+++ wesnoth/src/filesystem.cpp  Fri Dec 31 02:21:00 2004
@@ -1,4 +1,4 @@
-/* $Id: filesystem.cpp,v 1.50 2004/12/30 19:32:35 ydirson Exp $ */
+/* $Id: filesystem.cpp,v 1.51 2004/12/31 02:21:00 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -62,6 +62,61 @@
 #include "scoped_resource.hpp"
 #include "util.hpp"
 
+#ifdef USE_ZIPIOS
+#include <zipios++/collcoll.h>
+#include <zipios++/dircoll.h>
+#include <zipios++/zipfile.h>
+#include <zipios++/simplesmartptr.h>
+#include <zipios++/basicentry.h>
+
+namespace {
+       zipios::CColl the_collection;
+}
+#endif
+
+bool filesystem_init()
+{
+#ifdef USE_ZIPIOS
+       if (!get_user_data_dir().empty()) {
+               zipios::DirectoryCollection dir(get_user_data_dir());
+               std::cerr << "user collection has " << dir.size() << " 
elements\n";
+               the_collection.addCollection(dir);
+       }
+       if (!game_config::path.empty()) {
+               zipios::DirectoryCollection dir(game_config::path);
+               std::cerr << "system collection has " << dir.size() << " 
elements\n";
+               the_collection.addCollection(dir);
+# if 1
+               zipios::DirectoryCollection dir2(game_config::path,false);
+               if (!dir2.entries().empty())
+               for (zipios::ConstEntries::iterator i = dir2.entries().begin(); 
i != dir2.entries().end(); ++i) {
+                       // FIXME: why the heck is the 1st entry corrupted !?
+                       if (i == dir2.entries().begin()) continue;
+
+                       zipios::EntryPointer j = *i;
+                       zipios::FileEntry& k = *j;
+                       //for (int a=0; a<sizeof(k); a++) std::cerr << std::hex 
<< (unsigned int)(((unsigned char*)&k)[a]) << ".";
+                       //      std::cerr << std::dec << "\n";
+                       //continue;
+                       if (k.isValid()) {
+                               const std::string fname = k.getName();
+                               const std::string suffix = ".zip";
+                               if (0 == fname.compare(fname.size() - 
suffix.size(), suffix.size(), suffix)) {
+                                       zipios::ZipFile zip(game_config::path + 
"/" + fname);
+                                       the_collection.addCollection(zip);
+                                       std::cerr << "zip collection " << fname 
<< 
+                                               " has " << zip.size() << " 
elements\n";
+                               }
+                               else std::cerr << "skipping non-zip " << fname 
<< "\n";
+                       }
+                       else std::cerr << "skipping invalid entry\n";
+               }
+# endif
+       }
+#endif
+       return true;
+}
+
 namespace {
        const mode_t AccessMode = 00770;
 }
@@ -366,7 +421,7 @@
 }
 } //end anon namespace
 
-std::string read_stdin()
+std::string read_stream(std::istream& s)
 {
        std::vector<char> v;
        const int block_size = 65536;
@@ -374,7 +429,7 @@
        size_t nbytes = 1;
        while(nbytes > 0) {
                v.resize(v.size() + block_size);
-               nbytes = fread(&v[v.size() - block_size],1,block_size,stdin);
+               nbytes = s.readsome(&v[v.size() - block_size],block_size);
                if(nbytes < block_size) {
                        v.resize(v.size() - (block_size - nbytes));
                        break;
@@ -387,10 +442,26 @@
        return res;
 }
 
+std::string read_stdin()
+{
+       return read_stream(std::cin);
+}
+
 std::string read_file(const std::string& fname)
 {
        //if we have a path to the data,
        //convert any filepath which is relative
+#ifdef USE_ZIPIOS
+       if(!fname.empty() && fname[0] != '/') {
+               zipios::ConstEntryPointer p = the_collection.getEntry(fname);
+               if (p != 0) {
+                       std::istream* s = the_collection.getInputStream(p);
+                       if (s != NULL) {
+                               return read_stream(*s);
+                       }
+               }
+       }
+#else
        if(!fname.empty() && fname[0] != '/' && !game_config::path.empty()) {
                std::string res;
                read_file_internal(game_config::path + "/" + fname,res);
@@ -398,10 +469,15 @@
                        return res;
                }
        }
+#endif
 
-       std::string res;
-       read_file_internal(fname,res);
-       return res;
+       // FIXME: why do we rely on this even with relative paths ?
+       {
+               // still useful with zipios, for things like cache and prefs
+               std::string res;
+               read_file_internal(fname,res);
+               return res;
+       }
 }
 
 //throws io_exception if an error occurs
Index: wesnoth/src/filesystem.hpp
diff -u wesnoth/src/filesystem.hpp:1.30 wesnoth/src/filesystem.hpp:1.31
--- wesnoth/src/filesystem.hpp:1.30     Thu Dec 30 19:32:35 2004
+++ wesnoth/src/filesystem.hpp  Fri Dec 31 02:21:00 2004
@@ -1,4 +1,4 @@
-/* $Id: filesystem.hpp,v 1.30 2004/12/30 19:32:35 ydirson Exp $ */
+/* $Id: filesystem.hpp,v 1.31 2004/12/31 02:21:00 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -45,6 +45,7 @@
 void make_directory(const std::string& dirname);
 
 //basic disk I/O
+bool filesystem_init();
 std::string read_file(const std::string& fname);
 //throws io_exception if an error occurs
 void write_file(const std::string& fname, const std::string& data);
Index: wesnoth/src/game.cpp
diff -u wesnoth/src/game.cpp:1.177 wesnoth/src/game.cpp:1.178
--- wesnoth/src/game.cpp:1.177  Mon Dec 27 17:23:32 2004
+++ wesnoth/src/game.cpp        Fri Dec 31 02:21:00 2004
@@ -1,4 +1,4 @@
-/* $Id: game.cpp,v 1.177 2004/12/27 17:23:32 silene Exp $ */
+/* $Id: game.cpp,v 1.178 2004/12/31 02:21:00 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -1583,6 +1583,11 @@
 
 int main(int argc, char** argv)
 {
+       if (!filesystem_init()) {
+               std::cerr << "cannot init filesystem code\n";
+               return 1;
+       }
+
        try {
                std::cerr << "started game: " << SDL_GetTicks() << "\n";
                const int res = play_game(argc,argv);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]