1
0
Fork 0

Codechange: Pass ContentInfo by reference.

Many functions take a ContentInfo pointer, but do not check for nullptr.
Pass by reference instead to assure it is present.
pull/13990/head
Peter Nelson 2025-04-10 07:37:28 +01:00 committed by Peter Nelson
parent 1cfad1474a
commit 7b31f26611
17 changed files with 94 additions and 94 deletions

View File

@ -135,8 +135,8 @@ public:
static AIScannerLibrary *GetScannerLibrary(); static AIScannerLibrary *GetScannerLibrary();
/** Wrapper function for AIScanner::HasAI */ /** Wrapper function for AIScanner::HasAI */
static bool HasAI(const struct ContentInfo *ci, bool md5sum); static bool HasAI(const ContentInfo &ci, bool md5sum);
static bool HasAILibrary(const ContentInfo *ci, bool md5sum); static bool HasAILibrary(const ContentInfo &ci, bool md5sum);
private: private:
static uint frame_counter; ///< Tick counter for the AI code static uint frame_counter; ///< Tick counter for the AI code
static std::unique_ptr<AIScannerInfo> scanner_info; ///< ScriptScanner instance that is used to find AIs static std::unique_ptr<AIScannerInfo> scanner_info; ///< ScriptScanner instance that is used to find AIs

View File

@ -334,12 +334,12 @@
* @param md5sum whether to check the MD5 checksum * @param md5sum whether to check the MD5 checksum
* @return true iff we have an AI (library) matching. * @return true iff we have an AI (library) matching.
*/ */
/* static */ bool AI::HasAI(const ContentInfo *ci, bool md5sum) /* static */ bool AI::HasAI(const ContentInfo &ci, bool md5sum)
{ {
return AI::scanner_info->HasScript(ci, md5sum); return AI::scanner_info->HasScript(ci, md5sum);
} }
/* static */ bool AI::HasAILibrary(const ContentInfo *ci, bool md5sum) /* static */ bool AI::HasAILibrary(const ContentInfo &ci, bool md5sum)
{ {
return AI::scanner_library->HasScript(ci, md5sum); return AI::scanner_library->HasScript(ci, md5sum);
} }

View File

@ -211,7 +211,7 @@ public:
* @param md5sum whether to check the MD5 checksum * @param md5sum whether to check the MD5 checksum
* @return true iff we have an set matching. * @return true iff we have an set matching.
*/ */
static bool HasSet(const ContentInfo *ci, bool md5sum); static bool HasSet(const ContentInfo &ci, bool md5sum);
}; };
/** /**
@ -222,6 +222,6 @@ public:
* @return The filename of the first file of the base set, or \c nullptr if there is no match. * @return The filename of the first file of the base set, or \c nullptr if there is no match.
*/ */
template <class Tbase_set> template <class Tbase_set>
const char *TryGetBaseSetFile(const ContentInfo *ci, bool md5sum, const Tbase_set *s); const char *TryGetBaseSetFile(const ContentInfo &ci, bool md5sum, const Tbase_set *s);
#endif /* BASE_MEDIA_BASE_H */ #endif /* BASE_MEDIA_BASE_H */

View File

@ -319,25 +319,25 @@ template <class Tbase_set>
#include "network/core/tcp_content_type.h" #include "network/core/tcp_content_type.h"
template <class Tbase_set> const char *TryGetBaseSetFile(const ContentInfo *ci, bool md5sum, const Tbase_set *s) template <class Tbase_set> const char *TryGetBaseSetFile(const ContentInfo &ci, bool md5sum, const Tbase_set *s)
{ {
for (; s != nullptr; s = s->next) { for (; s != nullptr; s = s->next) {
if (s->GetNumMissing() != 0) continue; if (s->GetNumMissing() != 0) continue;
if (s->shortname != ci->unique_id) continue; if (s->shortname != ci.unique_id) continue;
if (!md5sum) return s->files[0].filename.c_str(); if (!md5sum) return s->files[0].filename.c_str();
MD5Hash md5; MD5Hash md5;
for (const auto &file : s->files) { for (const auto &file : s->files) {
md5 ^= file.hash; md5 ^= file.hash;
} }
if (md5 == ci->md5sum) return s->files[0].filename.c_str(); if (md5 == ci.md5sum) return s->files[0].filename.c_str();
} }
return nullptr; return nullptr;
} }
template <class Tbase_set> template <class Tbase_set>
/* static */ bool BaseMedia<Tbase_set>::HasSet(const ContentInfo *ci, bool md5sum) /* static */ bool BaseMedia<Tbase_set>::HasSet(const ContentInfo &ci, bool md5sum)
{ {
return (TryGetBaseSetFile(ci, md5sum, BaseMedia<Tbase_set>::available_sets) != nullptr) || return (TryGetBaseSetFile(ci, md5sum, BaseMedia<Tbase_set>::available_sets) != nullptr) ||
(TryGetBaseSetFile(ci, md5sum, BaseMedia<Tbase_set>::duplicate_sets) != nullptr); (TryGetBaseSetFile(ci, md5sum, BaseMedia<Tbase_set>::duplicate_sets) != nullptr);

View File

@ -273,10 +273,10 @@ public:
_network_content_client.RequestContentList(CONTENT_TYPE_BASE_GRAPHICS); _network_content_client.RequestContentList(CONTENT_TYPE_BASE_GRAPHICS);
} }
void OnReceiveContentInfo(const ContentInfo *ci) override void OnReceiveContentInfo(const ContentInfo &ci) override
{ {
/* And once the meta data is received, start downloading it. */ /* And once the meta data is received, start downloading it. */
_network_content_client.Select(ci->id); _network_content_client.Select(ci.id);
new BootstrapContentDownloadStatusWindow(); new BootstrapContentDownloadStatusWindow();
this->Close(); this->Close();
} }
@ -320,19 +320,19 @@ public:
_network_content_client.RequestContentList(CONTENT_TYPE_BASE_GRAPHICS); _network_content_client.RequestContentList(CONTENT_TYPE_BASE_GRAPHICS);
} }
void OnReceiveContentInfo(const ContentInfo *ci) override void OnReceiveContentInfo(const ContentInfo &ci) override
{ {
if (this->downloading) return; if (this->downloading) return;
/* And once the metadata is received, start downloading it. */ /* And once the metadata is received, start downloading it. */
_network_content_client.Select(ci->id); _network_content_client.Select(ci.id);
_network_content_client.DownloadSelectedContent(this->total_files, this->total_bytes); _network_content_client.DownloadSelectedContent(this->total_files, this->total_bytes);
this->downloading = true; this->downloading = true;
EM_ASM({ if (window["openttd_bootstrap"]) openttd_bootstrap($0, $1); }, this->downloaded_bytes, this->total_bytes); EM_ASM({ if (window["openttd_bootstrap"]) openttd_bootstrap($0, $1); }, this->downloaded_bytes, this->total_bytes);
} }
void OnDownloadProgress(const ContentInfo *, int bytes) override void OnDownloadProgress(const ContentInfo &, int bytes) override
{ {
/* A negative value means we are resetting; for example, when retrying or using a fallback. */ /* A negative value means we are resetting; for example, when retrying or using a fallback. */
if (bytes < 0) { if (bytes < 0) {

View File

@ -2128,14 +2128,14 @@ struct ConsoleContentCallback : public ContentCallback {
* Outputs content state information to console * Outputs content state information to console
* @param ci the content info * @param ci the content info
*/ */
static void OutputContentState(const ContentInfo *const ci) static void OutputContentState(const ContentInfo &ci)
{ {
static const char * const types[] = { "Base graphics", "NewGRF", "AI", "AI library", "Scenario", "Heightmap", "Base sound", "Base music", "Game script", "GS library" }; static const char * const types[] = { "Base graphics", "NewGRF", "AI", "AI library", "Scenario", "Heightmap", "Base sound", "Base music", "Game script", "GS library" };
static_assert(lengthof(types) == CONTENT_TYPE_END - CONTENT_TYPE_BEGIN); static_assert(lengthof(types) == CONTENT_TYPE_END - CONTENT_TYPE_BEGIN);
static const char * const states[] = { "Not selected", "Selected", "Dep Selected", "Installed", "Unknown" }; static const char * const states[] = { "Not selected", "Selected", "Dep Selected", "Installed", "Unknown" };
static const TextColour state_to_colour[] = { CC_COMMAND, CC_INFO, CC_INFO, CC_WHITE, CC_ERROR }; static const TextColour state_to_colour[] = { CC_COMMAND, CC_INFO, CC_INFO, CC_WHITE, CC_ERROR };
IConsolePrint(state_to_colour[ci->state], "{}, {}, {}, {}, {:08X}, {}", ci->id, types[ci->type - 1], states[ci->state], ci->name, ci->unique_id, FormatArrayAsHex(ci->md5sum)); IConsolePrint(state_to_colour[ci.state], "{}, {}, {}, {}, {:08X}, {}", ci.id, types[ci.type - 1], states[ci.state], ci.name, ci.unique_id, FormatArrayAsHex(ci.md5sum));
} }
DEF_CONSOLE_CMD(ConContent) DEF_CONSOLE_CMD(ConContent)
@ -2173,7 +2173,7 @@ DEF_CONSOLE_CMD(ConContent)
IConsolePrint(CC_WHITE, "id, type, state, name"); IConsolePrint(CC_WHITE, "id, type, state, name");
for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) { for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) {
if ((*iter)->state != ContentInfo::SELECTED && (*iter)->state != ContentInfo::AUTOSELECTED) continue; if ((*iter)->state != ContentInfo::SELECTED && (*iter)->state != ContentInfo::AUTOSELECTED) continue;
OutputContentState(*iter); OutputContentState(**iter);
} }
} else if (StrEqualsIgnoreCase(argv[2], "all")) { } else if (StrEqualsIgnoreCase(argv[2], "all")) {
/* The intention of this function was that you could download /* The intention of this function was that you could download
@ -2206,7 +2206,7 @@ DEF_CONSOLE_CMD(ConContent)
IConsolePrint(CC_WHITE, "id, type, state, name"); IConsolePrint(CC_WHITE, "id, type, state, name");
for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) { for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) {
if (argc > 2 && !StrContainsIgnoreCase((*iter)->name, argv[2])) continue; if (argc > 2 && !StrContainsIgnoreCase((*iter)->name, argv[2])) continue;
OutputContentState(*iter); OutputContentState(**iter);
} }
return true; return true;
} }

View File

@ -680,13 +680,13 @@ static ScenarioScanner _scanner;
* @param md5sum Whether to look at the md5sum or the id. * @param md5sum Whether to look at the md5sum or the id.
* @return The filename of the file, else \c nullptr. * @return The filename of the file, else \c nullptr.
*/ */
const char *FindScenario(const ContentInfo *ci, bool md5sum) const char *FindScenario(const ContentInfo &ci, bool md5sum)
{ {
_scanner.Scan(false); _scanner.Scan(false);
for (ScenarioIdentifier &id : _scanner) { for (ScenarioIdentifier &id : _scanner) {
if (md5sum ? (id.md5sum == ci->md5sum) if (md5sum ? (id.md5sum == ci.md5sum)
: (id.scenid == ci->unique_id)) { : (id.scenid == ci.unique_id)) {
return id.filename.c_str(); return id.filename.c_str();
} }
} }
@ -700,7 +700,7 @@ const char *FindScenario(const ContentInfo *ci, bool md5sum)
* @param md5sum Whether to look at the md5sum or the id. * @param md5sum Whether to look at the md5sum or the id.
* @return True iff we've got the scenario. * @return True iff we've got the scenario.
*/ */
bool HasScenario(const ContentInfo *ci, bool md5sum) bool HasScenario(const ContentInfo &ci, bool md5sum)
{ {
return (FindScenario(ci, md5sum) != nullptr); return (FindScenario(ci, md5sum) != nullptr);
} }

View File

@ -121,7 +121,7 @@ std::tuple<FiosType, std::string> FiosGetScenarioListCallback(SaveLoadOperation
std::tuple<FiosType, std::string> FiosGetHeightmapListCallback(SaveLoadOperation fop, const std::string &file, const std::string_view ext); std::tuple<FiosType, std::string> FiosGetHeightmapListCallback(SaveLoadOperation fop, const std::string &file, const std::string_view ext);
void ScanScenarios(); void ScanScenarios();
const char *FindScenario(const ContentInfo *ci, bool md5sum); const char *FindScenario(const ContentInfo &ci, bool md5sum);
/** /**
* A savegame name automatically numbered. * A savegame name automatically numbered.

View File

@ -101,8 +101,8 @@ public:
static void ResetInstance(); static void ResetInstance();
/** Wrapper function for GameScanner::HasGame */ /** Wrapper function for GameScanner::HasGame */
static bool HasGame(const struct ContentInfo *ci, bool md5sum); static bool HasGame(const ContentInfo &ci, bool md5sum);
static bool HasGameLibrary(const ContentInfo *ci, bool md5sum); static bool HasGameLibrary(const ContentInfo &ci, bool md5sum);
/** Gets the ScriptScanner instance that is used to find Game scripts */ /** Gets the ScriptScanner instance that is used to find Game scripts */
static GameScannerInfo *GetScannerInfo(); static GameScannerInfo *GetScannerInfo();
/** Gets the ScriptScanner instance that is used to find Game Libraries */ /** Gets the ScriptScanner instance that is used to find Game Libraries */

View File

@ -242,12 +242,12 @@
* @param md5sum whether to check the MD5 checksum * @param md5sum whether to check the MD5 checksum
* @return true iff we have an Game (library) matching. * @return true iff we have an Game (library) matching.
*/ */
/* static */ bool Game::HasGame(const ContentInfo *ci, bool md5sum) /* static */ bool Game::HasGame(const ContentInfo &ci, bool md5sum)
{ {
return Game::scanner_info->HasScript(ci, md5sum); return Game::scanner_info->HasScript(ci, md5sum);
} }
/* static */ bool Game::HasGameLibrary(const ContentInfo *ci, bool md5sum) /* static */ bool Game::HasGameLibrary(const ContentInfo &ci, bool md5sum)
{ {
return Game::scanner_library->HasScript(ci, md5sum); return Game::scanner_library->HasScript(ci, md5sum);
} }

View File

@ -63,16 +63,16 @@ std::optional<std::string> ContentInfo::GetTextfile(TextfileType type) const
switch (this->type) { switch (this->type) {
default: NOT_REACHED(); default: NOT_REACHED();
case CONTENT_TYPE_AI: case CONTENT_TYPE_AI:
tmp = AI::GetScannerInfo()->FindMainScript(this, true); tmp = AI::GetScannerInfo()->FindMainScript(*this, true);
break; break;
case CONTENT_TYPE_AI_LIBRARY: case CONTENT_TYPE_AI_LIBRARY:
tmp = AI::GetScannerLibrary()->FindMainScript(this, true); tmp = AI::GetScannerLibrary()->FindMainScript(*this, true);
break; break;
case CONTENT_TYPE_GAME: case CONTENT_TYPE_GAME:
tmp = Game::GetScannerInfo()->FindMainScript(this, true); tmp = Game::GetScannerInfo()->FindMainScript(*this, true);
break; break;
case CONTENT_TYPE_GAME_LIBRARY: case CONTENT_TYPE_GAME_LIBRARY:
tmp = Game::GetScannerLibrary()->FindMainScript(this, true); tmp = Game::GetScannerLibrary()->FindMainScript(*this, true);
break; break;
case CONTENT_TYPE_NEWGRF: { case CONTENT_TYPE_NEWGRF: {
const GRFConfig *gc = FindGRFConfig(std::byteswap(this->unique_id), FGCM_EXACT, &this->md5sum); const GRFConfig *gc = FindGRFConfig(std::byteswap(this->unique_id), FGCM_EXACT, &this->md5sum);
@ -80,17 +80,17 @@ std::optional<std::string> ContentInfo::GetTextfile(TextfileType type) const
break; break;
} }
case CONTENT_TYPE_BASE_GRAPHICS: case CONTENT_TYPE_BASE_GRAPHICS:
tmp = TryGetBaseSetFile(this, true, BaseGraphics::GetAvailableSets()); tmp = TryGetBaseSetFile(*this, true, BaseGraphics::GetAvailableSets());
break; break;
case CONTENT_TYPE_BASE_SOUNDS: case CONTENT_TYPE_BASE_SOUNDS:
tmp = TryGetBaseSetFile(this, true, BaseSounds::GetAvailableSets()); tmp = TryGetBaseSetFile(*this, true, BaseSounds::GetAvailableSets());
break; break;
case CONTENT_TYPE_BASE_MUSIC: case CONTENT_TYPE_BASE_MUSIC:
tmp = TryGetBaseSetFile(this, true, BaseMusic::GetAvailableSets()); tmp = TryGetBaseSetFile(*this, true, BaseMusic::GetAvailableSets());
break; break;
case CONTENT_TYPE_SCENARIO: case CONTENT_TYPE_SCENARIO:
case CONTENT_TYPE_HEIGHTMAP: case CONTENT_TYPE_HEIGHTMAP:
tmp = FindScenario(this, true); tmp = FindScenario(*this, true);
break; break;
} }
if (tmp == nullptr) return std::nullopt; if (tmp == nullptr) return std::nullopt;

View File

@ -38,15 +38,15 @@
#include "../safeguards.h" #include "../safeguards.h"
extern bool HasScenario(const ContentInfo *ci, bool md5sum); extern bool HasScenario(const ContentInfo &ci, bool md5sum);
/** The client we use to connect to the server. */ /** The client we use to connect to the server. */
ClientNetworkContentSocketHandler _network_content_client; ClientNetworkContentSocketHandler _network_content_client;
/** Wrapper function for the HasProc */ /** Wrapper function for the HasProc */
static bool HasGRFConfig(const ContentInfo *ci, bool md5sum) static bool HasGRFConfig(const ContentInfo &ci, bool md5sum)
{ {
return FindGRFConfig(std::byteswap(ci->unique_id), md5sum ? FGCM_EXACT : FGCM_ANY, md5sum ? &ci->md5sum : nullptr) != nullptr; return FindGRFConfig(std::byteswap(ci.unique_id), md5sum ? FGCM_EXACT : FGCM_ANY, md5sum ? &ci.md5sum : nullptr) != nullptr;
} }
/** /**
@ -56,7 +56,7 @@ static bool HasGRFConfig(const ContentInfo *ci, bool md5sum)
* @param md5sum also match the MD5 checksum? * @param md5sum also match the MD5 checksum?
* @return true iff it's known * @return true iff it's known
*/ */
using HasContentProc = bool(const ContentInfo *ci, bool md5sum); using HasContentProc = bool(const ContentInfo &ci, bool md5sum);
/** /**
* Get the has-content check function for the given content type. * Get the has-content check function for the given content type.
@ -115,11 +115,11 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet &p)
HasContentProc *proc = GetHasContentProcforContentType(ci->type); HasContentProc *proc = GetHasContentProcforContentType(ci->type);
if (proc != nullptr) { if (proc != nullptr) {
if (proc(ci, true)) { if (proc(*ci, true)) {
ci->state = ContentInfo::ALREADY_HERE; ci->state = ContentInfo::ALREADY_HERE;
} else { } else {
ci->state = ContentInfo::UNSELECTED; ci->state = ContentInfo::UNSELECTED;
if (proc(ci, false)) ci->upgrade = true; if (proc(*ci, false)) ci->upgrade = true;
} }
} else { } else {
ci->state = ContentInfo::UNSELECTED; ci->state = ContentInfo::UNSELECTED;
@ -143,7 +143,7 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet &p)
*ici = *ci; *ici = *ci;
delete ci; delete ci;
this->OnReceiveContentInfo(ici); this->OnReceiveContentInfo(*ici);
return true; return true;
} }
} }
@ -160,10 +160,10 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet &p)
ConstContentVector parents; ConstContentVector parents;
this->ReverseLookupTreeDependency(parents, ci); this->ReverseLookupTreeDependency(parents, ci);
for (const ContentInfo *ici : parents) { for (const ContentInfo *ici : parents) {
this->CheckDependencyState(ici); this->CheckDependencyState(*ici);
} }
this->OnReceiveContentInfo(ci); this->OnReceiveContentInfo(*ci);
return true; return true;
} }
@ -489,7 +489,7 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_CONTENT(Packet &p)
return false; return false;
} }
this->OnDownloadProgress(this->cur_info, (int)to_read); this->OnDownloadProgress(*this->cur_info, (int)to_read);
if (to_read == 0) this->AfterDownload(); if (to_read == 0) this->AfterDownload();
} }
@ -574,7 +574,7 @@ void ClientNetworkContentSocketHandler::OnFailure()
this->http_response_index = -2; this->http_response_index = -2;
if (this->cur_file.has_value()) { if (this->cur_file.has_value()) {
this->OnDownloadProgress(this->cur_info, -1); this->OnDownloadProgress(*this->cur_info, -1);
this->cur_file.reset(); this->cur_file.reset();
} }
@ -617,7 +617,7 @@ void ClientNetworkContentSocketHandler::OnReceiveData(std::unique_ptr<char[]> da
this->OnFailure(); this->OnFailure();
} else { } else {
/* Just received the data. */ /* Just received the data. */
this->OnDownloadProgress(this->cur_info, (int)length); this->OnDownloadProgress(*this->cur_info, (int)length);
} }
/* Nothing more to do now. */ /* Nothing more to do now. */
@ -861,7 +861,7 @@ void ClientNetworkContentSocketHandler::Select(ContentID cid)
if (ci == nullptr || ci->state != ContentInfo::UNSELECTED) return; if (ci == nullptr || ci->state != ContentInfo::UNSELECTED) return;
ci->state = ContentInfo::SELECTED; ci->state = ContentInfo::SELECTED;
this->CheckDependencyState(ci); this->CheckDependencyState(*ci);
} }
/** /**
@ -874,7 +874,7 @@ void ClientNetworkContentSocketHandler::Unselect(ContentID cid)
if (ci == nullptr || !ci->IsSelected()) return; if (ci == nullptr || !ci->IsSelected()) return;
ci->state = ContentInfo::UNSELECTED; ci->state = ContentInfo::UNSELECTED;
this->CheckDependencyState(ci); this->CheckDependencyState(*ci);
} }
/** Select everything we can select */ /** Select everything we can select */
@ -883,7 +883,7 @@ void ClientNetworkContentSocketHandler::SelectAll()
for (ContentInfo *ci : this->infos) { for (ContentInfo *ci : this->infos) {
if (ci->state == ContentInfo::UNSELECTED) { if (ci->state == ContentInfo::UNSELECTED) {
ci->state = ContentInfo::SELECTED; ci->state = ContentInfo::SELECTED;
this->CheckDependencyState(ci); this->CheckDependencyState(*ci);
} }
} }
} }
@ -894,7 +894,7 @@ void ClientNetworkContentSocketHandler::SelectUpgrade()
for (ContentInfo *ci : this->infos) { for (ContentInfo *ci : this->infos) {
if (ci->state == ContentInfo::UNSELECTED && ci->upgrade) { if (ci->state == ContentInfo::UNSELECTED && ci->upgrade) {
ci->state = ContentInfo::SELECTED; ci->state = ContentInfo::SELECTED;
this->CheckDependencyState(ci); this->CheckDependencyState(*ci);
} }
} }
} }
@ -908,16 +908,16 @@ void ClientNetworkContentSocketHandler::UnselectAll()
} }
/** Toggle the state of a content info and check its dependencies */ /** Toggle the state of a content info and check its dependencies */
void ClientNetworkContentSocketHandler::ToggleSelectedState(const ContentInfo *ci) void ClientNetworkContentSocketHandler::ToggleSelectedState(const ContentInfo &ci)
{ {
switch (ci->state) { switch (ci.state) {
case ContentInfo::SELECTED: case ContentInfo::SELECTED:
case ContentInfo::AUTOSELECTED: case ContentInfo::AUTOSELECTED:
this->Unselect(ci->id); this->Unselect(ci.id);
break; break;
case ContentInfo::UNSELECTED: case ContentInfo::UNSELECTED:
this->Select(ci->id); this->Select(ci.id);
break; break;
default: default:
@ -930,9 +930,9 @@ void ClientNetworkContentSocketHandler::ToggleSelectedState(const ContentInfo *c
* @param parents list to store all parents in (is not cleared) * @param parents list to store all parents in (is not cleared)
* @param child the child to search the parents' dependencies for * @param child the child to search the parents' dependencies for
*/ */
void ClientNetworkContentSocketHandler::ReverseLookupDependency(ConstContentVector &parents, const ContentInfo *child) const void ClientNetworkContentSocketHandler::ReverseLookupDependency(ConstContentVector &parents, const ContentInfo &child) const
{ {
auto range = this->reverse_dependency_map.equal_range(child->id); auto range = this->reverse_dependency_map.equal_range(child.id);
for (auto iter = range.first; iter != range.second; ++iter) { for (auto iter = range.first; iter != range.second; ++iter) {
parents.push_back(GetContent(iter->second)); parents.push_back(GetContent(iter->second));
@ -954,7 +954,7 @@ void ClientNetworkContentSocketHandler::ReverseLookupTreeDependency(ConstContent
* pointer gets invalid. So fall back to the indices. */ * pointer gets invalid. So fall back to the indices. */
for (uint i = 0; i < tree.size(); i++) { for (uint i = 0; i < tree.size(); i++) {
ConstContentVector parents; ConstContentVector parents;
this->ReverseLookupDependency(parents, tree[i]); this->ReverseLookupDependency(parents, *tree[i]);
for (const ContentInfo *ci : parents) { for (const ContentInfo *ci : parents) {
include(tree, ci); include(tree, ci);
@ -966,25 +966,25 @@ void ClientNetworkContentSocketHandler::ReverseLookupTreeDependency(ConstContent
* Check the dependencies (recursively) of this content info * Check the dependencies (recursively) of this content info
* @param ci the content info to check the dependencies of * @param ci the content info to check the dependencies of
*/ */
void ClientNetworkContentSocketHandler::CheckDependencyState(const ContentInfo *ci) void ClientNetworkContentSocketHandler::CheckDependencyState(const ContentInfo &ci)
{ {
if (ci->IsSelected() || ci->state == ContentInfo::ALREADY_HERE) { if (ci.IsSelected() || ci.state == ContentInfo::ALREADY_HERE) {
/* Selection is easy; just walk all children and set the /* Selection is easy; just walk all children and set the
* autoselected state. That way we can see what we automatically * autoselected state. That way we can see what we automatically
* selected and thus can unselect when a dependency is removed. */ * selected and thus can unselect when a dependency is removed. */
for (auto &dependency : ci->dependencies) { for (auto &dependency : ci.dependencies) {
ContentInfo *c = this->GetContent(dependency); ContentInfo *c = this->GetContent(dependency);
if (c == nullptr) { if (c == nullptr) {
this->DownloadContentInfo(dependency); this->DownloadContentInfo(dependency);
} else if (c->state == ContentInfo::UNSELECTED) { } else if (c->state == ContentInfo::UNSELECTED) {
c->state = ContentInfo::AUTOSELECTED; c->state = ContentInfo::AUTOSELECTED;
this->CheckDependencyState(c); this->CheckDependencyState(*c);
} }
} }
return; return;
} }
if (ci->state != ContentInfo::UNSELECTED) return; if (ci.state != ContentInfo::UNSELECTED) return;
/* For unselection we need to find the parents of us. We need to /* For unselection we need to find the parents of us. We need to
* unselect them. After that we unselect all children that we * unselect them. After that we unselect all children that we
@ -998,7 +998,7 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(const ContentInfo *
this->Unselect(c->id); this->Unselect(c->id);
} }
for (auto &dependency : ci->dependencies) { for (auto &dependency : ci.dependencies) {
const ContentInfo *c = this->GetContent(dependency); const ContentInfo *c = this->GetContent(dependency);
if (c == nullptr) { if (c == nullptr) {
DownloadContentInfo(dependency); DownloadContentInfo(dependency);
@ -1008,7 +1008,7 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(const ContentInfo *
/* Only unselect when WE are the only parent. */ /* Only unselect when WE are the only parent. */
parents.clear(); parents.clear();
this->ReverseLookupDependency(parents, c); this->ReverseLookupDependency(parents, *c);
/* First check whether anything depends on us */ /* First check whether anything depends on us */
int sel_count = 0; int sel_count = 0;
@ -1048,7 +1048,7 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(const ContentInfo *
if (parent->state == ContentInfo::AUTOSELECTED) this->Unselect(parent->id); if (parent->state == ContentInfo::AUTOSELECTED) this->Unselect(parent->id);
} }
for (const ContentInfo *parent : parents) { for (const ContentInfo *parent : parents) {
this->CheckDependencyState(this->GetContent(parent->id)); this->CheckDependencyState(*this->GetContent(parent->id));
} }
} }
} }
@ -1084,7 +1084,7 @@ void ClientNetworkContentSocketHandler::OnDisconnect()
} }
} }
void ClientNetworkContentSocketHandler::OnReceiveContentInfo(const ContentInfo *ci) void ClientNetworkContentSocketHandler::OnReceiveContentInfo(const ContentInfo &ci)
{ {
for (size_t i = 0; i < this->callbacks.size(); /* nothing */) { for (size_t i = 0; i < this->callbacks.size(); /* nothing */) {
ContentCallback *cb = this->callbacks[i]; ContentCallback *cb = this->callbacks[i];
@ -1094,7 +1094,7 @@ void ClientNetworkContentSocketHandler::OnReceiveContentInfo(const ContentInfo *
} }
} }
void ClientNetworkContentSocketHandler::OnDownloadProgress(const ContentInfo *ci, int bytes) void ClientNetworkContentSocketHandler::OnDownloadProgress(const ContentInfo &ci, int bytes)
{ {
for (size_t i = 0; i < this->callbacks.size(); /* nothing */) { for (size_t i = 0; i < this->callbacks.size(); /* nothing */) {
ContentCallback *cb = this->callbacks[i]; ContentCallback *cb = this->callbacks[i];

View File

@ -42,14 +42,14 @@ struct ContentCallback {
* We received a content info. * We received a content info.
* @param ci the content info * @param ci the content info
*/ */
virtual void OnReceiveContentInfo([[maybe_unused]] const ContentInfo *ci) {} virtual void OnReceiveContentInfo([[maybe_unused]] const ContentInfo &ci) {}
/** /**
* We have progress in the download of a file * We have progress in the download of a file
* @param ci the content info of the file * @param ci the content info of the file
* @param bytes the number of bytes downloaded since the previous call * @param bytes the number of bytes downloaded since the previous call
*/ */
virtual void OnDownloadProgress([[maybe_unused]] const ContentInfo *ci, [[maybe_unused]] int bytes) {} virtual void OnDownloadProgress([[maybe_unused]] const ContentInfo &ci, [[maybe_unused]] int bytes) {}
/** /**
* We have finished downloading a file * We have finished downloading a file
@ -90,8 +90,8 @@ protected:
void OnConnect(bool success) override; void OnConnect(bool success) override;
void OnDisconnect() override; void OnDisconnect() override;
void OnReceiveContentInfo(const ContentInfo *ci) override; void OnReceiveContentInfo(const ContentInfo &ci) override;
void OnDownloadProgress(const ContentInfo *ci, int bytes) override; void OnDownloadProgress(const ContentInfo &ci, int bytes) override;
void OnDownloadComplete(ContentID cid) override; void OnDownloadComplete(ContentID cid) override;
void OnFailure() override; void OnFailure() override;
@ -126,11 +126,11 @@ public:
void SelectAll(); void SelectAll();
void SelectUpgrade(); void SelectUpgrade();
void UnselectAll(); void UnselectAll();
void ToggleSelectedState(const ContentInfo *ci); void ToggleSelectedState(const ContentInfo &ci);
void ReverseLookupDependency(ConstContentVector &parents, const ContentInfo *child) const; void ReverseLookupDependency(ConstContentVector &parents, const ContentInfo &child) const;
void ReverseLookupTreeDependency(ConstContentVector &tree, const ContentInfo *child) const; void ReverseLookupTreeDependency(ConstContentVector &tree, const ContentInfo *child) const;
void CheckDependencyState(const ContentInfo *ci); void CheckDependencyState(const ContentInfo &ci);
/** Get the number of content items we know locally. */ /** Get the number of content items we know locally. */
uint Length() const { return (uint)this->infos.size(); } uint Length() const { return (uint)this->infos.size(); }

View File

@ -165,11 +165,11 @@ void BaseNetworkContentDownloadStatusWindow::DrawWidget(const Rect &r, WidgetID
} }
} }
void BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(const ContentInfo *ci, int bytes) void BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(const ContentInfo &ci, int bytes)
{ {
if (ci->id != this->cur_id) { if (ci.id != this->cur_id) {
this->name = ci->filename; this->name = ci.filename;
this->cur_id = ci->id; this->cur_id = ci.id;
this->downloaded_files++; this->downloaded_files++;
} }
@ -298,10 +298,10 @@ public:
} }
} }
void OnDownloadProgress(const ContentInfo *ci, int bytes) override void OnDownloadProgress(const ContentInfo &ci, int bytes) override
{ {
BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(ci, bytes); BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(ci, bytes);
include(this->receivedTypes, ci->type); include(this->receivedTypes, ci.type);
/* When downloading is finished change cancel in ok */ /* When downloading is finished change cancel in ok */
if (this->downloaded_bytes == this->total_bytes) { if (this->downloaded_bytes == this->total_bytes) {
@ -792,7 +792,7 @@ public:
const NWidgetBase *checkbox = this->GetWidget<NWidgetBase>(WID_NCL_CHECKBOX); const NWidgetBase *checkbox = this->GetWidget<NWidgetBase>(WID_NCL_CHECKBOX);
if (click_count > 1 || IsInsideBS(pt.x, checkbox->pos_x, checkbox->current_x)) { if (click_count > 1 || IsInsideBS(pt.x, checkbox->pos_x, checkbox->current_x)) {
_network_content_client.ToggleSelectedState(this->selected); _network_content_client.ToggleSelectedState(*this->selected);
this->content.ForceResort(); this->content.ForceResort();
this->content.ForceRebuild(); this->content.ForceRebuild();
} }
@ -870,7 +870,7 @@ public:
case WKC_RETURN: case WKC_RETURN:
if (keycode == WKC_RETURN || !IsWidgetFocused(WID_NCL_FILTER)) { if (keycode == WKC_RETURN || !IsWidgetFocused(WID_NCL_FILTER)) {
if (this->selected != nullptr) { if (this->selected != nullptr) {
_network_content_client.ToggleSelectedState(this->selected); _network_content_client.ToggleSelectedState(*this->selected);
this->content.ForceResort(); this->content.ForceResort();
this->InvalidateData(); this->InvalidateData();
} }
@ -925,9 +925,9 @@ public:
this->vscroll->SetCapacityFromWidget(this, WID_NCL_MATRIX); this->vscroll->SetCapacityFromWidget(this, WID_NCL_MATRIX);
} }
void OnReceiveContentInfo(const ContentInfo *rci) override void OnReceiveContentInfo(const ContentInfo &rci) override
{ {
if (this->auto_select && !rci->IsSelected()) _network_content_client.ToggleSelectedState(rci); if (this->auto_select && !rci.IsSelected()) _network_content_client.ToggleSelectedState(rci);
this->content.ForceRebuild(); this->content.ForceRebuild();
this->InvalidateData(0, false); this->InvalidateData(0, false);
} }

View File

@ -35,7 +35,7 @@ public:
void Close([[maybe_unused]] int data = 0) override; void Close([[maybe_unused]] int data = 0) override;
void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override; void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override;
void DrawWidget(const Rect &r, WidgetID widget) const override; void DrawWidget(const Rect &r, WidgetID widget) const override;
void OnDownloadProgress(const ContentInfo *ci, int bytes) override; void OnDownloadProgress(const ContentInfo &ci, int bytes) override;
}; };
void BuildContentTypeStringList(); void BuildContentTypeStringList();

View File

@ -195,13 +195,13 @@ struct ScriptFileChecksumCreator : FileScanner {
* @param info The script to get the shortname and md5 sum from. * @param info The script to get the shortname and md5 sum from.
* @return True iff they're the same. * @return True iff they're the same.
*/ */
static bool IsSameScript(const ContentInfo *ci, bool md5sum, ScriptInfo *info, Subdirectory dir) static bool IsSameScript(const ContentInfo &ci, bool md5sum, ScriptInfo *info, Subdirectory dir)
{ {
uint32_t id = 0; uint32_t id = 0;
const char *str = info->GetShortName().c_str(); const char *str = info->GetShortName().c_str();
for (int j = 0; j < 4 && *str != '\0'; j++, str++) id |= *str << (8 * j); for (int j = 0; j < 4 && *str != '\0'; j++, str++) id |= *str << (8 * j);
if (id != ci->unique_id) return false; if (id != ci.unique_id) return false;
if (!md5sum) return true; if (!md5sum) return true;
ScriptFileChecksumCreator checksum(dir); ScriptFileChecksumCreator checksum(dir);
@ -229,10 +229,10 @@ static bool IsSameScript(const ContentInfo *ci, bool md5sum, ScriptInfo *info, S
checksum.Scan(".nut", path); checksum.Scan(".nut", path);
} }
return ci->md5sum == checksum.md5sum; return ci.md5sum == checksum.md5sum;
} }
bool ScriptScanner::HasScript(const ContentInfo *ci, bool md5sum) bool ScriptScanner::HasScript(const ContentInfo &ci, bool md5sum)
{ {
for (const auto &item : this->info_list) { for (const auto &item : this->info_list) {
if (IsSameScript(ci, md5sum, item.second, this->GetDirectory())) return true; if (IsSameScript(ci, md5sum, item.second, this->GetDirectory())) return true;
@ -240,7 +240,7 @@ bool ScriptScanner::HasScript(const ContentInfo *ci, bool md5sum)
return false; return false;
} }
const char *ScriptScanner::FindMainScript(const ContentInfo *ci, bool md5sum) const char *ScriptScanner::FindMainScript(const ContentInfo &ci, bool md5sum)
{ {
for (const auto &item : this->info_list) { for (const auto &item : this->info_list) {
if (IsSameScript(ci, md5sum, item.second, this->GetDirectory())) return item.second->GetMainScript().c_str(); if (IsSameScript(ci, md5sum, item.second, this->GetDirectory())) return item.second->GetMainScript().c_str();

View File

@ -66,7 +66,7 @@ public:
* @param md5sum Whether to check the MD5 checksum. * @param md5sum Whether to check the MD5 checksum.
* @return True iff we have a script matching. * @return True iff we have a script matching.
*/ */
bool HasScript(const struct ContentInfo *ci, bool md5sum); bool HasScript(const struct ContentInfo &ci, bool md5sum);
/** /**
* Find a script of a #ContentInfo * Find a script of a #ContentInfo
@ -74,7 +74,7 @@ public:
* @param md5sum Whether to check the MD5 checksum. * @param md5sum Whether to check the MD5 checksum.
* @return A filename of a file of the content, else \c nullptr. * @return A filename of a file of the content, else \c nullptr.
*/ */
const char *FindMainScript(const ContentInfo *ci, bool md5sum); const char *FindMainScript(const ContentInfo &ci, bool md5sum);
bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) override; bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) override;