Some general code cleanup.

This commit is contained in:
Leon Styhre 2022-09-07 19:59:27 +02:00
parent 8361c4f15c
commit c537de51ef
8 changed files with 56 additions and 57 deletions

View file

@ -208,7 +208,7 @@ void thegamesdb_generate_json_scraper_requests(
std::string platformQueryParam; std::string platformQueryParam;
auto& platforms = params.system->getPlatformIds(); auto& platforms = params.system->getPlatformIds();
if (!platforms.empty()) { if (!platforms.empty()) {
bool first = true; bool first {true};
platformQueryParam += "&filter%5Bplatform%5D="; platformQueryParam += "&filter%5Bplatform%5D=";
for (auto platformIt = platforms.cbegin(); // Line break. for (auto platformIt = platforms.cbegin(); // Line break.
platformIt != platforms.cend(); ++platformIt) { platformIt != platforms.cend(); ++platformIt) {
@ -243,7 +243,7 @@ void thegamesdb_generate_json_scraper_requests(
{ {
resources.prepare(); resources.prepare();
std::string path = "https://api.thegamesdb.net/v1"; std::string path = "https://api.thegamesdb.net/v1";
const std::string apiKey = std::string("apikey=") + resources.getApiKey(); const std::string apiKey {std::string("apikey=") + resources.getApiKey()};
path += "/Games/Images/GamesImages?" + apiKey + "&games_id=" + gameIDs; path += "/Games/Images/GamesImages?" + apiKey + "&games_id=" + gameIDs;
@ -285,7 +285,7 @@ namespace
return ""; return "";
std::string out = ""; std::string out = "";
bool first = true; bool first {true};
for (int i = 0; i < static_cast<int>(v.Size()); ++i) { for (int i = 0; i < static_cast<int>(v.Size()); ++i) {
auto mapIt = resources.gamesdb_new_developers_map.find(getIntOrThrow(v[i])); auto mapIt = resources.gamesdb_new_developers_map.find(getIntOrThrow(v[i]));
@ -306,8 +306,8 @@ namespace
if (!v.IsArray()) if (!v.IsArray())
return ""; return "";
std::string out = ""; std::string out;
bool first = true; bool first {true};
for (int i = 0; i < static_cast<int>(v.Size()); ++i) { for (int i = 0; i < static_cast<int>(v.Size()); ++i) {
auto mapIt = resources.gamesdb_new_publishers_map.find(getIntOrThrow(v[i])); auto mapIt = resources.gamesdb_new_publishers_map.find(getIntOrThrow(v[i]));
@ -328,8 +328,8 @@ namespace
if (!v.IsArray()) if (!v.IsArray())
return ""; return "";
std::string out = ""; std::string out;
bool first = true; bool first {true};
for (int i = 0; i < static_cast<int>(v.Size()); ++i) { for (int i = 0; i < static_cast<int>(v.Size()); ++i) {
auto mapIt = resources.gamesdb_new_genres_map.find(getIntOrThrow(v[i])); auto mapIt = resources.gamesdb_new_genres_map.find(getIntOrThrow(v[i]));
@ -416,7 +416,7 @@ void processMediaURLs(const Value& images,
// Step through each game ID in the JSON server response. // Step through each game ID in the JSON server response.
for (auto it = images.MemberBegin(); it != images.MemberEnd(); ++it) { for (auto it = images.MemberBegin(); it != images.MemberEnd(); ++it) {
result.gameID = it->name.GetString(); result.gameID = it->name.GetString();
const Value& gameMedia = images[it->name]; const Value& gameMedia {images[it->name]};
result.coverUrl = ""; result.coverUrl = "";
result.fanartUrl = ""; result.fanartUrl = "";
result.marqueeUrl = ""; result.marqueeUrl = "";
@ -469,8 +469,8 @@ void TheGamesDBJSONRequest::process(const std::unique_ptr<HttpReq>& req,
doc.Parse(req->getContent().c_str()); doc.Parse(req->getContent().c_str());
if (doc.HasParseError()) { if (doc.HasParseError()) {
std::string err = std::string("TheGamesDBJSONRequest - Error parsing JSON \n\t") + std::string err {std::string("TheGamesDBJSONRequest - Error parsing JSON \n\t") +
GetParseError_En(doc.GetParseError()); GetParseError_En(doc.GetParseError())};
setError(err); setError(err);
LOG(LogError) << err; LOG(LogError) << err;
return; return;
@ -480,8 +480,8 @@ void TheGamesDBJSONRequest::process(const std::unique_ptr<HttpReq>& req,
if (doc.HasMember("data") && doc["data"].HasMember("images") && if (doc.HasMember("data") && doc["data"].HasMember("images") &&
doc["data"]["images"].IsObject()) { doc["data"]["images"].IsObject()) {
const Value& images = doc["data"]["images"]; const Value& images {doc["data"]["images"]};
const Value& base_url = doc["data"]["base_url"]; const Value& base_url {doc["data"]["base_url"]};
std::string baseImageUrlLarge; std::string baseImageUrlLarge;
if (base_url.HasMember("large") && base_url["large"].IsString()) { if (base_url.HasMember("large") && base_url["large"].IsString()) {
@ -520,7 +520,7 @@ void TheGamesDBJSONRequest::process(const std::unique_ptr<HttpReq>& req,
return; return;
} }
const Value& games = doc["data"]["games"]; const Value& games {doc["data"]["games"]};
resources.ensureResources(); resources.ensureResources();
for (int i = 0; i < static_cast<int>(games.Size()); ++i) { for (int i = 0; i < static_cast<int>(games.Size()); ++i) {

View file

@ -55,7 +55,7 @@ namespace
void ensureScrapersResourcesDir() void ensureScrapersResourcesDir()
{ {
std::string path = getScrapersResouceDir(); std::string path {getScrapersResouceDir()};
if (!Utils::FileSystem::exists(path)) if (!Utils::FileSystem::exists(path))
Utils::FileSystem::createDirectory(path); Utils::FileSystem::createDirectory(path);
} }
@ -146,7 +146,7 @@ bool TheGamesDBJSONRequestResources::saveResource(HttpReq* req,
ensureScrapersResourcesDir(); ensureScrapersResourcesDir();
std::ofstream fout(file_name); std::ofstream fout {file_name};
fout << req->getContent(); fout << req->getContent();
fout.close(); fout.close();
loadResource(resource, resource_name, file_name); loadResource(resource, resource_name, file_name);
@ -155,9 +155,8 @@ bool TheGamesDBJSONRequestResources::saveResource(HttpReq* req,
std::unique_ptr<HttpReq> TheGamesDBJSONRequestResources::fetchResource(const std::string& endpoint) std::unique_ptr<HttpReq> TheGamesDBJSONRequestResources::fetchResource(const std::string& endpoint)
{ {
std::string path = "https://api.thegamesdb.net/v1"; std::string path {"https://api.thegamesdb.net/v1"};
path += endpoint; path.append(endpoint).append("?apikey=").append(getApiKey());
path += "?apikey=" + getApiKey();
return std::unique_ptr<HttpReq>(new HttpReq(path)); return std::unique_ptr<HttpReq>(new HttpReq(path));
} }
@ -166,7 +165,7 @@ int TheGamesDBJSONRequestResources::loadResource(std::unordered_map<int, std::st
const std::string& resource_name, const std::string& resource_name,
const std::string& file_name) const std::string& file_name)
{ {
std::ifstream fin(file_name); std::ifstream fin {file_name};
if (!fin.good()) if (!fin.good())
return 1; return 1;

View file

@ -174,8 +174,8 @@ void GuiComponent::sortChildren()
const int GuiComponent::getChildIndex() const const int GuiComponent::getChildIndex() const
{ {
std::vector<GuiComponent*>::iterator it = std::vector<GuiComponent*>::iterator it {
std::find(getParent()->mChildren.begin(), getParent()->mChildren.end(), this); std::find(getParent()->mChildren.begin(), getParent()->mChildren.end(), this)};
if (it != getParent()->mChildren.end()) if (it != getParent()->mChildren.end())
return static_cast<int>(std::distance(getParent()->mChildren.begin(), it)); return static_cast<int>(std::distance(getParent()->mChildren.begin(), it));
@ -250,7 +250,7 @@ void GuiComponent::setAnimation(Animation* anim,
{ {
assert(slot < MAX_ANIMATIONS); assert(slot < MAX_ANIMATIONS);
AnimationController* oldAnim = mAnimationMap[slot]; AnimationController* oldAnim {mAnimationMap[slot]};
mAnimationMap[slot] = new AnimationController(anim, delay, finishedCallback, reverse); mAnimationMap[slot] = new AnimationController(anim, delay, finishedCallback, reverse);
if (oldAnim) if (oldAnim)
@ -340,7 +340,7 @@ void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
getParent()->getSize() : getParent()->getSize() :
glm::vec2 {Renderer::getScreenWidth(), Renderer::getScreenHeight()}}; glm::vec2 {Renderer::getScreenWidth(), Renderer::getScreenHeight()}};
const ThemeData::ThemeElement* elem = theme->getElement(view, element, ""); const ThemeData::ThemeElement* elem {theme->getElement(view, element, "")};
if (!elem) if (!elem)
return; return;

View file

@ -82,7 +82,7 @@ HttpReq::HttpReq(const std::string& url)
} }
// Set the url. // Set the url.
CURLcode err = curl_easy_setopt(mHandle, CURLOPT_URL, url.c_str()); CURLcode err {curl_easy_setopt(mHandle, CURLOPT_URL, url.c_str())};
if (err != CURLE_OK) { if (err != CURLE_OK) {
mStatus = REQ_IO_ERROR; mStatus = REQ_IO_ERROR;
onError(curl_easy_strerror(err)); onError(curl_easy_strerror(err));
@ -176,7 +176,7 @@ HttpReq::~HttpReq()
if (mHandle) { if (mHandle) {
s_requests.erase(mHandle); s_requests.erase(mHandle);
CURLMcode merr = curl_multi_remove_handle(s_multi_handle, mHandle); CURLMcode merr {curl_multi_remove_handle(s_multi_handle, mHandle)};
if (merr != CURLM_OK) { if (merr != CURLM_OK) {
LOG(LogError) << "Error removing curl_easy handle from curl_multi: " LOG(LogError) << "Error removing curl_easy handle from curl_multi: "
@ -191,7 +191,7 @@ HttpReq::Status HttpReq::status()
{ {
if (mStatus == REQ_IN_PROGRESS) { if (mStatus == REQ_IN_PROGRESS) {
int handle_count; int handle_count;
CURLMcode merr = curl_multi_perform(s_multi_handle, &handle_count); CURLMcode merr {curl_multi_perform(s_multi_handle, &handle_count)};
if (merr != CURLM_OK && merr != CURLM_CALL_MULTI_PERFORM) { if (merr != CURLM_OK && merr != CURLM_CALL_MULTI_PERFORM) {
mStatus = REQ_IO_ERROR; mStatus = REQ_IO_ERROR;
onError(curl_multi_strerror(merr)); onError(curl_multi_strerror(merr));
@ -238,7 +238,7 @@ std::string HttpReq::getContent() const
// Return value is number of elements successfully read. // Return value is number of elements successfully read.
size_t HttpReq::write_content(void* buff, size_t size, size_t nmemb, void* req_ptr) size_t HttpReq::write_content(void* buff, size_t size, size_t nmemb, void* req_ptr)
{ {
std::stringstream& ss = (static_cast<HttpReq*>(req_ptr))->mContent; std::stringstream& ss {static_cast<HttpReq*>(req_ptr)->mContent};
ss.write(static_cast<char*>(buff), size * nmemb); ss.write(static_cast<char*>(buff), size * nmemb);
return nmemb; return nmemb;

View file

@ -101,7 +101,7 @@ void FlexboxComponent::computeLayout()
mItemsPerLine = static_cast<unsigned int>(mItems.size()); mItemsPerLine = static_cast<unsigned int>(mItems.size());
} }
glm::vec2 grid {}; glm::vec2 grid {0.0f, 0.0f};
if (mDirection == "row") if (mDirection == "row")
grid = {mItemsPerLine, mLines}; grid = {mItemsPerLine, mLines};

View file

@ -46,8 +46,8 @@ LottieAnimComponent::LottieAnimComponent()
glm::clamp(Settings::getInstance()->getInt("LottieMaxFileCache"), 0, 1024) * 1024 * 1024); glm::clamp(Settings::getInstance()->getInt("LottieMaxFileCache"), 0, 1024) * 1024 * 1024);
// Keep total cache size within 0 to 4096 MiB. // Keep total cache size within 0 to 4096 MiB.
int maxTotalCache = int maxTotalCache {glm::clamp(Settings::getInstance()->getInt("LottieMaxTotalCache"), 0, 4096) *
glm::clamp(Settings::getInstance()->getInt("LottieMaxTotalCache"), 0, 4096) * 1024 * 1024; 1024 * 1024};
if (mMaxTotalFrameCache != static_cast<size_t>(maxTotalCache)) if (mMaxTotalFrameCache != static_cast<size_t>(maxTotalCache))
mMaxTotalFrameCache = static_cast<size_t>(maxTotalCache); mMaxTotalFrameCache = static_cast<size_t>(maxTotalCache);
@ -161,7 +161,7 @@ void LottieAnimComponent::setAnimation(const std::string& path)
} }
// Some statistics for the file. // Some statistics for the file.
double duration = mAnimation->duration(); double duration {mAnimation->duration()};
mTotalFrames = mAnimation->totalFrame(); mTotalFrames = mAnimation->totalFrame();
mFrameRate = mAnimation->frameRate(); mFrameRate = mAnimation->frameRate();
mFrameSize = width * height * 4; mFrameSize = width * height * 4;
@ -229,7 +229,7 @@ void LottieAnimComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
const ThemeData::ThemeElement* elem {theme->getElement(view, element, "animation")}; const ThemeData::ThemeElement* elem {theme->getElement(view, element, "animation")};
if (elem->has("size")) { if (elem->has("size")) {
glm::vec2 size = elem->get<glm::vec2>("size"); glm::vec2 size {elem->get<glm::vec2>("size")};
if (size.x == 0.0f && size.y == 0.0f) { if (size.x == 0.0f && size.y == 0.0f) {
LOG(LogWarning) LOG(LogWarning)
<< "LottieAnimComponent: Invalid theme configuration, <size> defined as \"" << "LottieAnimComponent: Invalid theme configuration, <size> defined as \""
@ -411,7 +411,7 @@ void LottieAnimComponent::render(const glm::mat4& parentTrans)
// to the texture caching used for images. // to the texture caching used for images.
if (mCacheFrames && mLastRenderedFrame != -1 && if (mCacheFrames && mLastRenderedFrame != -1 &&
mFrameCache.find(mLastRenderedFrame) == mFrameCache.end()) { mFrameCache.find(mLastRenderedFrame) == mFrameCache.end()) {
size_t newCacheSize = mCacheSize + mFrameSize; size_t newCacheSize {mCacheSize + mFrameSize};
if (newCacheSize < mMaxCacheSize && if (newCacheSize < mMaxCacheSize &&
mTotalFrameCache + mFrameSize < mMaxTotalFrameCache) { mTotalFrameCache + mFrameSize < mMaxTotalFrameCache) {
mFrameCache[mLastRenderedFrame] = mPictureRGBA; mFrameCache[mLastRenderedFrame] = mPictureRGBA;