[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src game.cpp
From: |
David White |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src game.cpp |
Date: |
Sat, 29 Jan 2005 12:25:19 -0500 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: David White <address@hidden> 05/01/29 17:25:19
Modified files:
src : game.cpp
Log message:
fixed bug where campaigns on the campaign server wouldn't display the
correct size
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game.cpp.diff?tr1=1.185&tr2=1.186&r1=text&r2=text
Patches:
Index: wesnoth/src/game.cpp
diff -u wesnoth/src/game.cpp:1.185 wesnoth/src/game.cpp:1.186
--- wesnoth/src/game.cpp:1.185 Sat Jan 29 10:05:07 2005
+++ wesnoth/src/game.cpp Sat Jan 29 17:25:19 2005
@@ -1,4 +1,4 @@
-/* $Id: game.cpp,v 1.185 2005/01/29 10:05:07 silene Exp $ */
+/* $Id: game.cpp,v 1.186 2005/01/29 17:25:19 Sirp Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -1010,6 +1010,42 @@
state_.campaign_define = campaign["define"];
return true;
+}
+
+namespace
+{
+
+std::string format_file_size(const std::string& size_str)
+{
+ double size = lexical_cast_default<double>(size_str,0.0);
+
+ const double k = 1024;
+ if(size > 0.0) {
+ std::string size_postfix = _("B");
+ if(size > k) {
+ size /= k;
+ size_postfix = _("KB");
+ if(size > k) {
+ size /= k;
+ size_postfix = _("MB");
+ }
+ }
+
+ std::ostringstream stream;
+ //Visual C++ makes 'precision' set the number of decimal
places. Other platforms
+ //make it set the number of significant figures
+#ifdef _MSC_VER
+ stream.precision(1);
+#else
+ stream.precision(3);
+#endif
+ stream << std::fixed << size << size_postfix;
+ return stream.str();
+ } else {
+ return "";
+ }
+}
+
}
void game_controller::download_campaigns()
@@ -1075,30 +1111,13 @@
delete_options.push_back(name);
}
- size_t size =
lexical_cast_default<size_t>((**i)["size"],0);
- std::string size_str = "";
-
- if(size > 0) {
- std::string size_postfix = _("B");
- if(size > 1024) {
- size /= 1024;
- size_postfix = _("KB");
- if(size > 1024) {
- size /= 1024;
- size_postfix = _("MB");
- }
- }
-
- size_str = lexical_cast<std::string>(size) +
size_postfix;
- }
-
std::replace(name.begin(),name.end(),'_',' ');
options.push_back(IMAGE_PREFIX + (**i)["icon"] +
COLUMN_SEPARATOR +
name + COLUMN_SEPARATOR +
(**i)["version"] + COLUMN_SEPARATOR +
(**i)["author"] + COLUMN_SEPARATOR +
(**i)["downloads"] + COLUMN_SEPARATOR
+
- size_str);
+ format_file_size((**i)["size"]));
}
for(std::vector<std::string>::const_iterator j =
publish_options.begin(); j != publish_options.end(); ++j) {