|
|
@ -41,7 +41,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
// protobuf
|
|
|
|
// protobuf
|
|
|
|
#include "proto/stockpiles.pb.h"
|
|
|
|
#include "proto/stockpiles.pb.h"
|
|
|
|
#include <google/protobuf/text_format.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// os
|
|
|
|
// os
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
@ -476,20 +475,6 @@ public:
|
|
|
|
return mBuffer.SerializeToOstream ( &output );
|
|
|
|
return mBuffer.SerializeToOstream ( &output );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Serializes the stockpile settings to a string.
|
|
|
|
|
|
|
|
* @return empty string on error
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
std::string serialize_to_string()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mBuffer.Clear();
|
|
|
|
|
|
|
|
write();
|
|
|
|
|
|
|
|
std::string str;
|
|
|
|
|
|
|
|
if ( !TextFormat::PrintToString ( mBuffer, &str ) )
|
|
|
|
|
|
|
|
return std::string();
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Read stockpile settings from file
|
|
|
|
* Read stockpile settings from file
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -502,15 +487,6 @@ public:
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Read text_format stockpile settings from string
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool unserialize_from_string ( const std::string & data )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mBuffer.Clear();
|
|
|
|
|
|
|
|
return TextFormat::ParseFromString ( data, &mBuffer );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
|
|
bool mDebug;
|
|
|
|
bool mDebug;
|
|
|
@ -2762,23 +2738,21 @@ static command_result savestock ( color_ostream &out, vector <string> & paramete
|
|
|
|
file = o;
|
|
|
|
file = o;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( file.empty() )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
out.printerr("You must supply a valid filename.\n");
|
|
|
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StockpileSerializer cereal ( sp );
|
|
|
|
StockpileSerializer cereal ( sp );
|
|
|
|
if ( debug )
|
|
|
|
if ( debug )
|
|
|
|
cereal.enable_debug ( out );
|
|
|
|
cereal.enable_debug ( out );
|
|
|
|
if ( file.empty() )
|
|
|
|
|
|
|
|
{
|
|
|
|
if ( !is_dfstockfile ( file ) ) file += ".dfstock";
|
|
|
|
std::string data = cereal.serialize_to_string();
|
|
|
|
if ( !cereal.serialize_to_file ( file ) )
|
|
|
|
out << data << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ( !is_dfstockfile ( file ) ) file += ".dfstock";
|
|
|
|
out.printerr ( "serialize failed\n" );
|
|
|
|
if ( !cereal.serialize_to_file ( file ) )
|
|
|
|
return CR_FAILURE;
|
|
|
|
{
|
|
|
|
|
|
|
|
out.printerr ( "serialize failed\n" );
|
|
|
|
|
|
|
|
return CR_FAILURE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -2802,9 +2776,9 @@ static command_result loadstock ( color_ostream &out, vector <string> & paramete
|
|
|
|
|
|
|
|
|
|
|
|
bool debug = false;
|
|
|
|
bool debug = false;
|
|
|
|
std::string file;
|
|
|
|
std::string file;
|
|
|
|
for( size_t i = 0; i < parameters.size(); ++i )
|
|
|
|
for( size_t i = 0; i < parameters.size(); ++i )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const std::string o = parameters.at(i);
|
|
|
|
const std::string o = parameters.at(i);
|
|
|
|
if ( o == "--debug" || o == "-d" )
|
|
|
|
if ( o == "--debug" || o == "-d" )
|
|
|
|
debug = true;
|
|
|
|
debug = true;
|
|
|
|
else if ( !o.empty() && o[0] != '-' )
|
|
|
|
else if ( !o.empty() && o[0] != '-' )
|
|
|
|