[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src game.cpp filesystem.cpp filesystem.hpp
From: |
Jon Daniel |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src game.cpp filesystem.cpp filesystem.hpp |
Date: |
Sat, 06 Aug 2005 16:26:54 -0400 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Jon Daniel <address@hidden> 05/08/06 20:26:54
Modified files:
src : game.cpp filesystem.cpp filesystem.hpp
Log message:
Applied modified and cleaned up patch #4275 from ihsan for bug #13874.
It deletes existing copies of a downloaded campaign before writing the
new one.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game.cpp.diff?tr1=1.269&tr2=1.270&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/filesystem.cpp.diff?tr1=1.76&tr2=1.77&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/filesystem.hpp.diff?tr1=1.38&tr2=1.39&r1=text&r2=text
Patches:
Index: wesnoth/src/filesystem.cpp
diff -u wesnoth/src/filesystem.cpp:1.76 wesnoth/src/filesystem.cpp:1.77
--- wesnoth/src/filesystem.cpp:1.76 Tue Jul 12 20:54:15 2005
+++ wesnoth/src/filesystem.cpp Sat Aug 6 20:26:54 2005
@@ -1,4 +1,4 @@
-/* $Id: filesystem.cpp,v 1.76 2005/07/12 20:54:15 silene Exp $ */
+/* $Id: filesystem.cpp,v 1.77 2005/08/06 20:26:54 j_daniel Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
@@ -49,7 +49,8 @@
//for getenv
#include <cstdlib>
-
+#include <cerrno>
+#include <cstring>
#include <algorithm>
#include <fstream>
#include <iostream>
@@ -314,6 +315,41 @@
#else
mkdir(path.c_str(),AccessMode);
#endif
+}
+
+//this deletes a directory with no hidden files and subdirectories
+//also deletes a single file
+bool delete_directory(const std::string& path)
+{
+ bool ret = true;
+ std::vector<std::string> files;
+ std::vector<std::string> dirs;
+
+ get_files_in_dir(path, &files, &dirs, ENTIRE_FILE_PATH);
+
+ if(!files.empty()) {
+ for(std::vector<std::string>::const_iterator i = files.begin();
i != files.end(); ++i) {
+ errno = 0;
+ if(remove((*i).c_str()) != 0) {
+ LOG_FS << "remove(" << (*i) << "): " <<
strerror(errno) << "\n";
+ ret = false;
+ }
+ }
+ }
+
+ if(!dirs.empty()) {
+ for(std::vector<std::string>::const_iterator j = dirs.begin();
j != dirs.end(); ++j) {
+ if(!delete_directory(*j))
+ ret = false;
+ }
+ }
+
+ errno = 0;
+ if(remove(path.c_str()) != 0) {
+ LOG_FS << "remove(" << path << "): " << strerror(errno) << "\n";
+ ret = false;
+ }
+ return ret;
}
std::string get_cwd()
Index: wesnoth/src/filesystem.hpp
diff -u wesnoth/src/filesystem.hpp:1.38 wesnoth/src/filesystem.hpp:1.39
--- wesnoth/src/filesystem.hpp:1.38 Sat Jul 2 21:37:18 2005
+++ wesnoth/src/filesystem.hpp Sat Aug 6 20:26:54 2005
@@ -1,4 +1,4 @@
-/* $Id: filesystem.hpp,v 1.38 2005/07/02 21:37:18 ott Exp $ */
+/* $Id: filesystem.hpp,v 1.39 2005/08/06 20:26:54 j_daniel Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
@@ -56,6 +56,7 @@
std::string get_cwd();
void make_directory(const std::string& dirname);
+bool delete_directory(const std::string& dirname);
//basic disk I/O
bool filesystem_init();
Index: wesnoth/src/game.cpp
diff -u wesnoth/src/game.cpp:1.269 wesnoth/src/game.cpp:1.270
--- wesnoth/src/game.cpp:1.269 Sat Aug 6 14:00:19 2005
+++ wesnoth/src/game.cpp Sat Aug 6 20:26:54 2005
@@ -1,4 +1,4 @@
-/* $Id: game.cpp,v 1.269 2005/08/06 14:00:19 j_daniel Exp $ */
+/* $Id: game.cpp,v 1.270 2005/08/06 20:26:54 j_daniel Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
@@ -120,6 +120,7 @@
void download_campaigns();
void upload_campaign(const std::string& campaign, network::connection
sock);
void delete_campaign(const std::string& campaign, network::connection
sock);
+ void remove_campaign(const std::string& campaign);
const int argc_;
int arg_;
@@ -987,6 +988,11 @@
return;
}
+ //remove any existing versions of the just downloaded campaign
+ //assuming it consists of a dir and a cfg file
+ remove_campaign(campaigns[index]);
+
+ //put a break at line below to see that it really works.
unarchive_campaign(cfg);
// when using zipios, force a reread zip and directory indices
@@ -1091,6 +1097,13 @@
} else if(data.child("message")) {
gui::show_dialog(disp(),NULL,_("Response"),(*data.child("message"))["message"],gui::OK_ONLY);
}
+}
+
+void game_controller::remove_campaign(const std::string& campaign)
+{
+ const std::string campaign_dir = get_user_data_dir() +
"/data/campaigns/" + campaign;
+ delete_directory(campaign_dir);
+ delete_directory(campaign_dir + ".cfg");
}
bool game_controller::play_multiplayer()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Wesnoth-cvs-commits] wesnoth/src game.cpp filesystem.cpp filesystem.hpp,
Jon Daniel <=