check whether we're using old style /Addon.pbl or new Addon/_server.pbl...

...syntax when uploading initially

(fix for bug #17419)
This commit is contained in:
Anonymissimus 2011-06-01 12:25:31 +00:00
parent 21d5a5fa76
commit 184ef0c842
2 changed files with 11 additions and 9 deletions

View file

@ -51,24 +51,26 @@ static lg::log_domain log_network("network");
#define ERR_NET LOG_STREAM(err , log_network)
#define LOG_NET LOG_STREAM(info, log_network)
void get_addon_info(const std::string& addon_name, config& cfg)
bool get_addon_info(const std::string& addon_name, config& cfg)
{
const std::string parentd = get_addon_campaigns_dir();
// Cope with old-style or new-style file organization
const std::string exterior = parentd + "/" + addon_name + ".pbl";
const std::string interior = parentd + "/" + addon_name + "/_server.pbl";
const std::string pbl_file = (file_exists(exterior)? exterior : interior);
const bool is_old_style = file_exists(exterior);
const std::string pbl_file = (is_old_style ? exterior : interior);
scoped_istream stream = istream_file(pbl_file);
read(cfg, *stream);
return is_old_style;
}
void set_addon_info(const std::string& addon_name, const config& cfg)
void set_addon_info(const std::string& addon_name, const config& cfg, const bool is_old_style)
{
const std::string parentd = get_addon_campaigns_dir();
scoped_ostream stream = ostream_file(parentd + "/" + addon_name + ".pbl");
scoped_ostream stream = ostream_file(parentd + "/" + addon_name + "/_server.pbl");
if(is_old_style) stream = ostream_file(parentd + "/" + addon_name + ".pbl");
write(*stream, cfg);
}
@ -500,7 +502,7 @@ namespace {
}
config cfg;
get_addon_info(addon,cfg);
const bool is_old_style = get_addon_info(addon,cfg);
std::string passphrase = cfg["passphrase"];
// generate a random passphrase and write it to disk
@ -511,7 +513,7 @@ namespace {
passphrase[n] = 'a' + (rand()%26);
}
cfg["passphrase"] = passphrase;
set_addon_info(addon,cfg);
set_addon_info(addon,cfg,is_old_style);
}
cfg["name"] = addon;

View file

@ -37,7 +37,7 @@ bool remove_local_addon(const std::string& addon, std::string* log = NULL);
* @param cfg A config object to store the add-on's
* properties.
*/
void get_addon_info(const std::string& addon_name, class config& cfg);
bool get_addon_info(const std::string& addon_name, class config& cfg);
/**
* Sets the publish information for an add-on
@ -46,7 +46,7 @@ void get_addon_info(const std::string& addon_name, class config& cfg);
* @param cfg A config object from which the add-on's
* properties are copied.
*/
void set_addon_info(const std::string& addon_name, const class config& cfg);
void set_addon_info(const std::string& addon_name, const class config& cfg, const bool is_old_style);
/** Returns a list of local add-ons that can be published. */
std::vector<std::string> available_addons();