diff --git a/src/campaign_server/addon_utils.cpp b/src/campaign_server/addon_utils.cpp index 4d8459d6e959..6fd63d387a50 100644 --- a/src/campaign_server/addon_utils.cpp +++ b/src/campaign_server/addon_utils.cpp @@ -1,5 +1,6 @@ /* - Copyright (C) 2013 - 2014 by Ignacio Riquelme Morelle + Copyright (C) 2003 - 2014 by David White + 2013 - 2014 by Ignacio Riquelme Morelle Part of the Battle for Wesnoth Project http://www.wesnoth.org/ This program is free software; you can redistribute it and/or modify @@ -15,10 +16,16 @@ #include "campaign_server/addon_utils.hpp" #include "config.hpp" +#include "filesystem.hpp" +#include "game_config.hpp" +#include "log.hpp" #include "serialization/string_utils.hpp" #include +static lg::log_domain log_network("network"); +#define LOG_CS if (lg::err.dont_log(log_network)) ; else lg::err(log_network, false) + namespace { typedef std::map plain_string_map; @@ -85,4 +92,47 @@ std::string format_addon_feedback_url(const std::string& format, const config& p return std::string(); } +void find_translations(const config& base_dir, config& addon) +{ + BOOST_FOREACH(const config &dir, base_dir.child_range("dir")) + { + if(dir["name"] == "LC_MESSAGES") { + addon.add_child("translation")["language"] = base_dir["name"]; + } else { + find_translations(dir, addon); + } + } +} + +void add_license(config& cfg) +{ + config& dir = cfg.find_child("dir", "name", cfg["campaign_name"]); + + // No top-level directory? Hm.. + if(!dir) { + return; + } + + // Don't add if it already exists. + if(dir.find_child("file", "name", "COPYING.txt") + || dir.find_child("file", "name", "COPYING") + || dir.find_child("file", "name", "copying.txt") + || dir.find_child("file", "name", "Copying.txt") + || dir.find_child("file", "name", "COPYING.TXT")) + { + return; + } + + // Copy over COPYING.txt + const std::string& contents = read_file("COPYING.txt"); + if (contents.empty()) { + LOG_CS << "Could not find COPYING.txt, path is \"" << game_config::path << "\"\n"; + return; + } + + config& copying = dir.add_child("file"); + copying["name"] = "COPYING.txt"; + copying["contents"] = contents; +} + } // end namespace campaignd diff --git a/src/campaign_server/addon_utils.hpp b/src/campaign_server/addon_utils.hpp index a1c7f1eb39d9..fadd42cd1fbf 100644 --- a/src/campaign_server/addon_utils.hpp +++ b/src/campaign_server/addon_utils.hpp @@ -1,5 +1,6 @@ /* - Copyright (C) 2013 - 2014 by Ignacio Riquelme Morelle + Copyright (C) 2003 - 2014 by David White + 2013 - 2014 by Ignacio Riquelme Morelle Part of the Battle for Wesnoth Project http://www.wesnoth.org/ This program is free software; you can redistribute it and/or modify @@ -49,6 +50,35 @@ inline bool is_text_markup_char(char c) */ std::string format_addon_feedback_url(const std::string& format, const config& params); + +/** + * Scans an add-on archive directory for translations. + * + * Any subdirectories of @a base_dir containing a subdirectory named + * 'LC_MESSAGES' are assumed to be translation dirs. The names of the + * subdirectories thus located are recorded into the @a addon WML node in + * [translation] children nodes like the following (comments included for + * documentation purposes): + * + * @verbatim + * [translation] + * language="es" # translations/es/LC_MESSAGES/ + * [/translation] + * [translation] + * language="ja" # translations/ja/LC_MESSAGES/ + * [/translation] + * @endverbatim + */ +void find_translations(const config& base_dir, config& addon); + +/** + * Adds a COPYING.txt file with the full text of the GNU GPL to an add-on. + * + * This only has an effect if the add-on archive @a cfg does not already + * contain an equivalent file ('copying.txt', 'COPYING', etc.). + */ +void add_license(config& cfg); + } #endif diff --git a/src/campaign_server/campaign_server.cpp b/src/campaign_server/campaign_server.cpp index e6be80779527..f5510c840de5 100644 --- a/src/campaign_server/campaign_server.cpp +++ b/src/campaign_server/campaign_server.cpp @@ -230,52 +230,6 @@ void server::send_error(const std::string& msg, network::connection sock) network::send_data(cfg, sock); } -} // end namespace campaignd - -namespace { - void find_translations(const config& cfg, config& campaign) - { - BOOST_FOREACH(const config &dir, cfg.child_range("dir")) - { - if (dir["name"] == "LC_MESSAGES") { - config &language = campaign.add_child("translation"); - language["language"] = cfg["name"]; - } else { - find_translations(dir, campaign); - } - } - } - - // Add a file COPYING.txt with the GPL to an uploaded campaign. - void add_license(config &data) - { - config &dir = data.find_child("dir", "name", data["campaign_name"]); - // No top-level directory? Hm.. - if (!dir) return; - - // Don't add if it already exists. - if (dir.find_child("file", "name", "COPYING.txt")) return; - if (dir.find_child("file", "name", "COPYING")) return; - if (dir.find_child("file", "name", "copying.txt")) return; - if (dir.find_child("file", "name", "Copying.txt")) return; - if (dir.find_child("file", "name", "COPYING.TXT")) return; - - // Copy over COPYING.txt - std::string contents = read_file("COPYING.txt"); - if (contents.empty()) { - LOG_CS << "Could not find COPYING.txt, path is \"" - << game_config::path << "\"\n"; - return; - } - config ©ing = dir.add_child("file"); - copying["name"] = "COPYING.txt"; - copying["contents"] = contents; - - } -} // end anonymous namespace 2 - -namespace campaignd { - void server::run() { if(read_only_) {