[General] Move printWithWidth and intToHexStr to components

0.6.1
Koncord 8 years ago
parent 34e77c5dae
commit 47e6820f97

@ -44,18 +44,6 @@
using namespace std;
using namespace mwmp;
void printWithWidth(ostringstream &sstr, string str, size_t width)
{
sstr << left << setw(width) << setfill(' ') << str;
}
string intToHexStr(unsigned val)
{
ostringstream sstr;
sstr << "0x" << setfill('0') << setw(8) << uppercase << hex << val;
return sstr.str();
}
string comparePlugins(PacketPreInit::PluginContainer checksums, PacketPreInit::PluginContainer checksumsResponse)
{
std::ostringstream sstr;
@ -78,7 +66,7 @@ string comparePlugins(PacketPreInit::PluginContainer checksums, PacketPreInit::P
string plugin = checksums.at(i).first;
sstr << plugin << " (" << intToHexStr(checksums.at(i).second[0]) << ")";
sstr << plugin << " (" << Utils::intToHexStr(checksums.at(i).second[0]) << ")";
lineLength = lineLength + plugin.size() + 13;
}
@ -105,7 +93,7 @@ string comparePlugins(PacketPreInit::PluginContainer checksums, PacketPreInit::P
if (responseHashSize > 0)
{
sstr << intToHexStr(checksumsResponse.at(i).second[0]);
sstr << Utils::intToHexStr(checksumsResponse.at(i).second[0]);
if (responseHashSize > 1)
sstr << " & " << (responseHashSize - 1) << " more";
@ -136,12 +124,12 @@ string comparePluginsMonospaced(PacketPreInit::PluginContainer checksums, Packet
pluginNameLen2 = checksumsResponse[i].first.size();
sstr << "Your plugins or their load order don't match the server's.\n\n";
printWithWidth(sstr, "Your current plugins are:", pluginNameLen1 + 16);
Utils::printWithWidth(sstr, "Your current plugins are:", pluginNameLen1 + 16);
sstr << "To join this server, use:\n";
printWithWidth(sstr, "name", pluginNameLen1 + 2);
printWithWidth(sstr, "hash", 14);
printWithWidth(sstr, "name", pluginNameLen2 + 2);
Utils::printWithWidth(sstr, "name", pluginNameLen1 + 2);
Utils::printWithWidth(sstr, "hash", 14);
Utils::printWithWidth(sstr, "name", pluginNameLen2 + 2);
sstr << "hash\n";
for (size_t i = 0; i < checksums.size() || i < checksumsResponse.size(); i++)
@ -154,24 +142,22 @@ string comparePluginsMonospaced(PacketPreInit::PluginContainer checksums, Packet
plugin = checksums.at(i).first;
val = checksums.at(i).second[0];
printWithWidth(sstr, plugin, pluginNameLen1 + 2);
printWithWidth(sstr, intToHexStr(val), 14);
Utils::printWithWidth(sstr, plugin, pluginNameLen1 + 2);
Utils::printWithWidth(sstr, Utils::intToHexStr(val), 14);
}
else
{
printWithWidth(sstr, "", pluginNameLen1 + 16);
}
Utils::printWithWidth(sstr, "", pluginNameLen1 + 16);
if (i < checksumsResponse.size())
{
printWithWidth(sstr, checksumsResponse[i].first, pluginNameLen2 + 2);
Utils::printWithWidth(sstr, checksumsResponse[i].first, pluginNameLen2 + 2);
if (checksumsResponse[i].second.size() > 0)
{
if (full)
for (size_t j = 0; j < checksumsResponse[i].second.size(); j++)
printWithWidth(sstr, intToHexStr(checksumsResponse[i].second[j]), 14);
Utils::printWithWidth(sstr, Utils::intToHexStr(checksumsResponse[i].second[j]), 14);
else
sstr << intToHexStr(checksumsResponse[i].second[0]);
sstr << Utils::intToHexStr(checksumsResponse[i].second[0]);
}
else
sstr << "any";

@ -12,6 +12,7 @@
#include <sstream>
#include <boost/crc.hpp>
#include <boost/filesystem/fstream.hpp>
#include <iomanip>
using namespace std;
@ -147,3 +148,15 @@ unsigned int ::Utils::crc32checksum(const std::string &file)
}
return crc32.checksum();
}
void Utils::printWithWidth(ostringstream &sstr, string str, size_t width)
{
sstr << left << setw(width) << setfill(' ') << str;
}
string Utils::intToHexStr(unsigned val)
{
ostringstream sstr;
sstr << "0x" << setfill('0') << setw(8) << uppercase << hex << val;
return sstr.str();
}

@ -6,6 +6,7 @@
#define UTILS_HPP
#include <string>
#include <sstream>
#ifdef _WIN32
int setenv(const char *name, const char *value, int overwrite);
@ -30,5 +31,9 @@ namespace Utils
long int FileLength(const char *file);
unsigned int crc32checksum(const std::string &file);
void printWithWidth(std::ostringstream &sstr, std::string str, size_t width);
std::string intToHexStr(unsigned val);
}
#endif //UTILS_HPP

Loading…
Cancel
Save