UsenetSearch/src/dbdump.cpp

86 lines
3.0 KiB
C++

/*
Copyright© 2021 John Sennesael
UsenetSearch is Free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
UsenetSearch is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
*/
#include "usenetsearch/Application.h"
#include "usenetsearch/StringUtils.h"
#include <iostream>
#include <string>
using namespace usenetsearch;
int main(int argc, char* argv[])
{
std::string tokenFile{""};
std::string newsgroupFile{""};
Application::Get().AddFileOption(
't',
"token db file to dump.",
[&tokenFile](const std::string& val)
{
tokenFile = val;
}
);
Application::Get().AddFileOption(
'n',
"newsgroup file to dump.",
[&newsgroupFile](const std::string& val)
{
newsgroupFile = val;
}
);
if (!Application::Get().Init(argc, argv)) return 1;
if (!tokenFile.empty())
{
Application::Get().GetDb().ParseTokenFile(
tokenFile,
[](const ArticleEntry& token){
std::cout << "Hash: " << HashBytesToString(token.hash) << " | "
<< "NewsgroupID: " << token.newsgroupID << " | "
<< "ArticleID: " << token.articleID << std::endl;
}
);
}
if (!newsgroupFile.empty())
{
const auto groups = Application::Get().GetDb().LoadNewsgroupList();
for(const auto& group: *groups)
{
if (Application::Get().ShouldStop()) return 1;
std::cout << std::left
<< std::setw(9) << "Id: " + std::to_string(group.id)
<< std::setw(3) << " | "
<< std::setw(27) << "LastIndexedMsgId: "
+ std::to_string(group.lastIndexedArticle)
<< std::setw(3) << " | "
<< std::setw(14) << "Count: " +
std::to_string(group.count)
<< std::setw(3) << " | "
<< std::setw(13) << "High: " + std::to_string(group.high)
<< std::setw(3) << " | "
<< std::setw(8) << "Low: " + std::to_string(group.low)
<< std::setw(3) << " | "
<< std::setw(9) << "Status: " + group.status
<< std::setw(3) << " | "
<< std::setw(group.name.size() + 5)
<< "Name: " + group.name
<< std::endl;
}
}
return 0;
}