[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src Makefile.am filesystem.cpp zipios++...
From: |
Yann Dirson |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src Makefile.am filesystem.cpp zipios++... |
Date: |
Thu, 06 Jan 2005 07:16:41 -0500 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Yann Dirson <address@hidden> 05/01/05 23:25:33
Modified files:
src : Makefile.am filesystem.cpp
Added files:
src/zipios++ : xcoll.cpp xcoll.hpp
Log message:
implemented enough of zipios support to get campaign scenarios and maps
loaded from zip files
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/Makefile.am.diff?tr1=1.64&tr2=1.65&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/filesystem.cpp.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/zipios++/xcoll.cpp?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/zipios++/xcoll.hpp?rev=1.1
Patches:
Index: wesnoth/src/Makefile.am
diff -u wesnoth/src/Makefile.am:1.64 wesnoth/src/Makefile.am:1.65
--- wesnoth/src/Makefile.am:1.64 Fri Dec 31 21:01:37 2004
+++ wesnoth/src/Makefile.am Wed Jan 5 23:25:33 2005
@@ -102,6 +102,7 @@
widgets/slider.cpp \
widgets/textbox.cpp \
widgets/widget.cpp \
+ zipios++/xcoll.cpp \
sdl_ttf/SDL_ttf.c \
about.hpp \
actions.hpp \
@@ -184,6 +185,7 @@
widgets/slider.hpp \
widgets/textbox.hpp \
widgets/widget.hpp \
+ zipios++/xcoll.hpp \
sdl_ttf/SDL_ttf.h \
wesconfig.h
Index: wesnoth/src/filesystem.cpp
diff -u wesnoth/src/filesystem.cpp:1.51 wesnoth/src/filesystem.cpp:1.52
--- wesnoth/src/filesystem.cpp:1.51 Fri Dec 31 02:21:00 2004
+++ wesnoth/src/filesystem.cpp Wed Jan 5 23:25:33 2005
@@ -1,4 +1,4 @@
-/* $Id: filesystem.cpp,v 1.51 2004/12/31 02:21:00 ydirson Exp $ */
+/* $Id: filesystem.cpp,v 1.52 2005/01/05 23:25:33 ydirson Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -63,14 +63,16 @@
#include "util.hpp"
#ifdef USE_ZIPIOS
+#include <sstream>
#include <zipios++/collcoll.h>
#include <zipios++/dircoll.h>
#include <zipios++/zipfile.h>
#include <zipios++/simplesmartptr.h>
#include <zipios++/basicentry.h>
+#include "zipios++/xcoll.hpp"
namespace {
- zipios::CColl the_collection;
+ xzipios::XCColl the_collection;
}
#endif
@@ -87,19 +89,12 @@
std::cerr << "system collection has " << dir.size() << "
elements\n";
the_collection.addCollection(dir);
# if 1
+ // look for zip files
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();
+ zipios::ConstEntries entries = dir2.entries();
+ for (zipios::ConstEntries::iterator i = entries.begin(); i !=
entries.end(); ++i) {
+ if ((**i).isValid()) {
+ const std::string fname = (**i).getName();
const std::string suffix = ".zip";
if (0 == fname.compare(fname.size() -
suffix.size(), suffix.size(), suffix)) {
zipios::ZipFile zip(game_config::path +
"/" + fname);
@@ -132,80 +127,89 @@
std::vector<std::string>* dirs,
FILE_NAME_MODE mode)
{
- //if we have a path to find directories in, then convert relative
- //pathnames to be rooted on the wesnoth path
- if(!directory.empty() && directory[0] != '/' &&
!game_config::path.empty()){
- const std::string& dir = game_config::path + "/" + directory;
- if(is_directory(dir)) {
- get_files_in_dir(dir,files,dirs,mode);
- return;
- }
+#ifdef USE_ZIPIOS
+ if (the_collection.hasSubdir(directory)) {
+ the_collection.childrenOf(directory, files, dirs);
}
+ else
+#endif
+ {
+
+ //if we have a path to find directories in, then convert
relative
+ //pathnames to be rooted on the wesnoth path
+ if(!directory.empty() && directory[0] != '/' &&
!game_config::path.empty()){
+ const std::string& dir = game_config::path + "/" +
directory;
+ if(is_directory(dir)) {
+ get_files_in_dir(dir,files,dirs,mode);
+ return;
+ }
+ }
#ifdef _WIN32
- _finddata_t fileinfo;
- long dir = _findfirst((directory + "/*.*").c_str(),&fileinfo);
+ _finddata_t fileinfo;
+ long dir = _findfirst((directory + "/*.*").c_str(),&fileinfo);
#else
- DIR* dir = opendir(directory.c_str());
+ DIR* dir = opendir(directory.c_str());
#endif
- if(DIR_INVALID(dir)) {
- return;
- }
+ if(DIR_INVALID(dir)) {
+ return;
+ }
#ifdef _WIN32
- int res = dir;
- do {
- if(fileinfo.name[0] != '.') {
- const std::string path = (mode == ENTIRE_FILE_PATH ?
- directory + "/" : std::string("")) +
fileinfo.name;
-
- if(fileinfo.attrib&_A_SUBDIR) {
- if(dirs != NULL)
- dirs->push_back(path);
- } else {
- if(files != NULL)
- files->push_back(path);
+ int res = dir;
+ do {
+ if(fileinfo.name[0] != '.') {
+ const std::string path = (mode ==
ENTIRE_FILE_PATH ?
+ directory + "/" :
std::string("")) + fileinfo.name;
+
+ if(fileinfo.attrib&_A_SUBDIR) {
+ if(dirs != NULL)
+ dirs->push_back(path);
+ } else {
+ if(files != NULL)
+ files->push_back(path);
+ }
}
- }
- res = _findnext(dir,&fileinfo);
- } while(!DIR_INVALID(res));
+ res = _findnext(dir,&fileinfo);
+ } while(!DIR_INVALID(res));
- _findclose(dir);
+ _findclose(dir);
#else
- struct dirent* entry;
- while((entry = readdir(dir)) != NULL) {
- if(entry->d_name[0] == '.')
- continue;
-
- const std::string name((directory + "/") + entry->d_name);
-
- struct stat st;
- if (::stat(name.c_str(), &st) != -1) {
- if (S_ISREG(st.st_mode)) {
- if (files != NULL) {
- if (mode == ENTIRE_FILE_PATH)
- files->push_back(name);
- else
- files->push_back(entry->d_name);
- }
- } else if (S_ISDIR(st.st_mode)) {
- if (dirs != NULL) {
- if (mode == ENTIRE_FILE_PATH)
- dirs->push_back(name);
- else
- dirs->push_back(entry->d_name);
+ struct dirent* entry;
+ while((entry = readdir(dir)) != NULL) {
+ if(entry->d_name[0] == '.')
+ continue;
+
+ const std::string name((directory + "/") +
entry->d_name);
+
+ struct stat st;
+ if (::stat(name.c_str(), &st) != -1) {
+ if (S_ISREG(st.st_mode)) {
+ if (files != NULL) {
+ if (mode == ENTIRE_FILE_PATH)
+ files->push_back(name);
+ else
+
files->push_back(entry->d_name);
+ }
+ } else if (S_ISDIR(st.st_mode)) {
+ if (dirs != NULL) {
+ if (mode == ENTIRE_FILE_PATH)
+ dirs->push_back(name);
+ else
+
dirs->push_back(entry->d_name);
+ }
}
}
}
- }
- closedir(dir);
+ closedir(dir);
#endif
+ }
if(files != NULL)
std::sort(files->begin(),files->end());
@@ -423,6 +427,11 @@
std::string read_stream(std::istream& s)
{
+#if 1
+ std::stringstream ss;
+ ss << s.rdbuf();
+ return ss.str();
+#else
std::vector<char> v;
const int block_size = 65536;
@@ -440,6 +449,7 @@
res.resize(v.size());
std::copy(v.begin(),v.end(),res.begin());
return res;
+#endif
}
std::string read_stdin()
@@ -451,6 +461,7 @@
{
//if we have a path to the data,
//convert any filepath which is relative
+ //std::cerr << "Reading " << fname << "\n";
#ifdef USE_ZIPIOS
if(!fname.empty() && fname[0] != '/') {
zipios::ConstEntryPointer p = the_collection.getEntry(fname);
@@ -545,10 +556,17 @@
bool is_directory(const std::string& fname)
{
+#ifdef USE_ZIPIOS
+ if(!fname.empty() && fname[0] != '/') {
+ return the_collection.hasSubdir(fname);
+ }
+
+#else
if(!fname.empty() && fname[0] != '/' && !game_config::path.empty()) {
if(is_directory_internal(game_config::path + "/" + fname))
return true;
}
+#endif
return is_directory_internal(fname);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Wesnoth-cvs-commits] wesnoth/src Makefile.am filesystem.cpp zipios++...,
Yann Dirson <=