made the campaign server store the size of campaigns being downloaded

This commit is contained in:
Dave White 2004-11-05 04:34:50 +00:00
parent 50b2dce055
commit c8277f3b30
2 changed files with 22 additions and 3 deletions

View File

@ -118,7 +118,9 @@ void campaign_server::run()
const config* const data = upload->child("data");
if(data != NULL) {
compression_schema schema;
write_file((*campaign)["filename"],data->write_compressed(schema));
const std::string& filedata = data->write_compressed(schema);
write_file((*campaign)["filename"],filedata);
(*campaign)["size"] = lexical_cast<std::string>(filedata.size());
}
write_file(file_,cfg_.write());

View File

@ -1043,7 +1043,7 @@ void game_controller::download_campaigns()
}
std::vector<std::string> campaigns, options;
options.push_back(_(",Name,Version,Author,Downloads"));
options.push_back(_(",Name,Version,Author,Downloads,Size"));
const config::child_list& cmps = campaigns_cfg->get_children("campaign");
const std::vector<std::string>& publish_options = available_campaigns();
@ -1058,8 +1058,25 @@ void game_controller::download_campaigns()
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("&" + (**i)["icon"] + "," + name + "," + (**i)["version"] + "," + (**i)["author"] + "," + (**i)["downloads"]);
options.push_back("&" + (**i)["icon"] + "," + name + "," + (**i)["version"] + "," + (**i)["author"] + "," + (**i)["downloads"] + "," + size_str);
}
for(std::vector<std::string>::const_iterator j = publish_options.begin(); j != publish_options.end(); ++j) {