mirror of https://github.com/OpenTTD/OpenTTD
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
parent
1cfad1474a
commit
7b31f26611
|
@ -135,8 +135,8 @@ public:
|
|||
static AIScannerLibrary *GetScannerLibrary();
|
||||
|
||||
/** Wrapper function for AIScanner::HasAI */
|
||||
static bool HasAI(const struct ContentInfo *ci, bool md5sum);
|
||||
static bool HasAILibrary(const ContentInfo *ci, bool md5sum);
|
||||
static bool HasAI(const ContentInfo &ci, bool md5sum);
|
||||
static bool HasAILibrary(const ContentInfo &ci, bool md5sum);
|
||||
private:
|
||||
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
|
||||
|
|
|
@ -334,12 +334,12 @@
|
|||
* @param md5sum whether to check the MD5 checksum
|
||||
* @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);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
|
|
@ -211,7 +211,7 @@ public:
|
|||
* @param md5sum whether to check the MD5 checksum
|
||||
* @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.
|
||||
*/
|
||||
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 */
|
||||
|
|
|
@ -319,25 +319,25 @@ template <class Tbase_set>
|
|||
|
||||
#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) {
|
||||
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();
|
||||
|
||||
MD5Hash md5;
|
||||
for (const auto &file : s->files) {
|
||||
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;
|
||||
}
|
||||
|
||||
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) ||
|
||||
(TryGetBaseSetFile(ci, md5sum, BaseMedia<Tbase_set>::duplicate_sets) != nullptr);
|
||||
|
|
|
@ -273,10 +273,10 @@ public:
|
|||
_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. */
|
||||
_network_content_client.Select(ci->id);
|
||||
_network_content_client.Select(ci.id);
|
||||
new BootstrapContentDownloadStatusWindow();
|
||||
this->Close();
|
||||
}
|
||||
|
@ -320,19 +320,19 @@ public:
|
|||
_network_content_client.RequestContentList(CONTENT_TYPE_BASE_GRAPHICS);
|
||||
}
|
||||
|
||||
void OnReceiveContentInfo(const ContentInfo *ci) override
|
||||
void OnReceiveContentInfo(const ContentInfo &ci) override
|
||||
{
|
||||
if (this->downloading) return;
|
||||
|
||||
/* 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);
|
||||
this->downloading = true;
|
||||
|
||||
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. */
|
||||
if (bytes < 0) {
|
||||
|
|
|
@ -2128,14 +2128,14 @@ struct ConsoleContentCallback : public ContentCallback {
|
|||
* Outputs content state information to console
|
||||
* @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_assert(lengthof(types) == CONTENT_TYPE_END - CONTENT_TYPE_BEGIN);
|
||||
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 };
|
||||
|
||||
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)
|
||||
|
@ -2173,7 +2173,7 @@ DEF_CONSOLE_CMD(ConContent)
|
|||
IConsolePrint(CC_WHITE, "id, type, state, name");
|
||||
for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) {
|
||||
if ((*iter)->state != ContentInfo::SELECTED && (*iter)->state != ContentInfo::AUTOSELECTED) continue;
|
||||
OutputContentState(*iter);
|
||||
OutputContentState(**iter);
|
||||
}
|
||||
} else if (StrEqualsIgnoreCase(argv[2], "all")) {
|
||||
/* 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");
|
||||
for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) {
|
||||
if (argc > 2 && !StrContainsIgnoreCase((*iter)->name, argv[2])) continue;
|
||||
OutputContentState(*iter);
|
||||
OutputContentState(**iter);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -680,13 +680,13 @@ static ScenarioScanner _scanner;
|
|||
* @param md5sum Whether to look at the md5sum or the id.
|
||||
* @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);
|
||||
|
||||
for (ScenarioIdentifier &id : _scanner) {
|
||||
if (md5sum ? (id.md5sum == ci->md5sum)
|
||||
: (id.scenid == ci->unique_id)) {
|
||||
if (md5sum ? (id.md5sum == ci.md5sum)
|
||||
: (id.scenid == ci.unique_id)) {
|
||||
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.
|
||||
* @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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
void ScanScenarios();
|
||||
const char *FindScenario(const ContentInfo *ci, bool md5sum);
|
||||
const char *FindScenario(const ContentInfo &ci, bool md5sum);
|
||||
|
||||
/**
|
||||
* A savegame name automatically numbered.
|
||||
|
|
|
@ -101,8 +101,8 @@ public:
|
|||
static void ResetInstance();
|
||||
|
||||
/** Wrapper function for GameScanner::HasGame */
|
||||
static bool HasGame(const struct ContentInfo *ci, bool md5sum);
|
||||
static bool HasGameLibrary(const ContentInfo *ci, bool md5sum);
|
||||
static bool HasGame(const ContentInfo &ci, bool md5sum);
|
||||
static bool HasGameLibrary(const ContentInfo &ci, bool md5sum);
|
||||
/** Gets the ScriptScanner instance that is used to find Game scripts */
|
||||
static GameScannerInfo *GetScannerInfo();
|
||||
/** Gets the ScriptScanner instance that is used to find Game Libraries */
|
||||
|
|
|
@ -242,12 +242,12 @@
|
|||
* @param md5sum whether to check the MD5 checksum
|
||||
* @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);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
|
|
@ -63,16 +63,16 @@ std::optional<std::string> ContentInfo::GetTextfile(TextfileType type) const
|
|||
switch (this->type) {
|
||||
default: NOT_REACHED();
|
||||
case CONTENT_TYPE_AI:
|
||||
tmp = AI::GetScannerInfo()->FindMainScript(this, true);
|
||||
tmp = AI::GetScannerInfo()->FindMainScript(*this, true);
|
||||
break;
|
||||
case CONTENT_TYPE_AI_LIBRARY:
|
||||
tmp = AI::GetScannerLibrary()->FindMainScript(this, true);
|
||||
tmp = AI::GetScannerLibrary()->FindMainScript(*this, true);
|
||||
break;
|
||||
case CONTENT_TYPE_GAME:
|
||||
tmp = Game::GetScannerInfo()->FindMainScript(this, true);
|
||||
tmp = Game::GetScannerInfo()->FindMainScript(*this, true);
|
||||
break;
|
||||
case CONTENT_TYPE_GAME_LIBRARY:
|
||||
tmp = Game::GetScannerLibrary()->FindMainScript(this, true);
|
||||
tmp = Game::GetScannerLibrary()->FindMainScript(*this, true);
|
||||
break;
|
||||
case CONTENT_TYPE_NEWGRF: {
|
||||
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;
|
||||
}
|
||||
case CONTENT_TYPE_BASE_GRAPHICS:
|
||||
tmp = TryGetBaseSetFile(this, true, BaseGraphics::GetAvailableSets());
|
||||
tmp = TryGetBaseSetFile(*this, true, BaseGraphics::GetAvailableSets());
|
||||
break;
|
||||
case CONTENT_TYPE_BASE_SOUNDS:
|
||||
tmp = TryGetBaseSetFile(this, true, BaseSounds::GetAvailableSets());
|
||||
tmp = TryGetBaseSetFile(*this, true, BaseSounds::GetAvailableSets());
|
||||
break;
|
||||
case CONTENT_TYPE_BASE_MUSIC:
|
||||
tmp = TryGetBaseSetFile(this, true, BaseMusic::GetAvailableSets());
|
||||
tmp = TryGetBaseSetFile(*this, true, BaseMusic::GetAvailableSets());
|
||||
break;
|
||||
case CONTENT_TYPE_SCENARIO:
|
||||
case CONTENT_TYPE_HEIGHTMAP:
|
||||
tmp = FindScenario(this, true);
|
||||
tmp = FindScenario(*this, true);
|
||||
break;
|
||||
}
|
||||
if (tmp == nullptr) return std::nullopt;
|
||||
|
|
|
@ -38,15 +38,15 @@
|
|||
|
||||
#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. */
|
||||
ClientNetworkContentSocketHandler _network_content_client;
|
||||
|
||||
/** 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?
|
||||
* @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.
|
||||
|
@ -115,11 +115,11 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet &p)
|
|||
|
||||
HasContentProc *proc = GetHasContentProcforContentType(ci->type);
|
||||
if (proc != nullptr) {
|
||||
if (proc(ci, true)) {
|
||||
if (proc(*ci, true)) {
|
||||
ci->state = ContentInfo::ALREADY_HERE;
|
||||
} else {
|
||||
ci->state = ContentInfo::UNSELECTED;
|
||||
if (proc(ci, false)) ci->upgrade = true;
|
||||
if (proc(*ci, false)) ci->upgrade = true;
|
||||
}
|
||||
} else {
|
||||
ci->state = ContentInfo::UNSELECTED;
|
||||
|
@ -143,7 +143,7 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet &p)
|
|||
*ici = *ci;
|
||||
delete ci;
|
||||
|
||||
this->OnReceiveContentInfo(ici);
|
||||
this->OnReceiveContentInfo(*ici);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -160,10 +160,10 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet &p)
|
|||
ConstContentVector parents;
|
||||
this->ReverseLookupTreeDependency(parents, ci);
|
||||
for (const ContentInfo *ici : parents) {
|
||||
this->CheckDependencyState(ici);
|
||||
this->CheckDependencyState(*ici);
|
||||
}
|
||||
|
||||
this->OnReceiveContentInfo(ci);
|
||||
this->OnReceiveContentInfo(*ci);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -489,7 +489,7 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_CONTENT(Packet &p)
|
|||
return false;
|
||||
}
|
||||
|
||||
this->OnDownloadProgress(this->cur_info, (int)to_read);
|
||||
this->OnDownloadProgress(*this->cur_info, (int)to_read);
|
||||
|
||||
if (to_read == 0) this->AfterDownload();
|
||||
}
|
||||
|
@ -574,7 +574,7 @@ void ClientNetworkContentSocketHandler::OnFailure()
|
|||
this->http_response_index = -2;
|
||||
|
||||
if (this->cur_file.has_value()) {
|
||||
this->OnDownloadProgress(this->cur_info, -1);
|
||||
this->OnDownloadProgress(*this->cur_info, -1);
|
||||
|
||||
this->cur_file.reset();
|
||||
}
|
||||
|
@ -617,7 +617,7 @@ void ClientNetworkContentSocketHandler::OnReceiveData(std::unique_ptr<char[]> da
|
|||
this->OnFailure();
|
||||
} else {
|
||||
/* Just received the data. */
|
||||
this->OnDownloadProgress(this->cur_info, (int)length);
|
||||
this->OnDownloadProgress(*this->cur_info, (int)length);
|
||||
}
|
||||
|
||||
/* Nothing more to do now. */
|
||||
|
@ -861,7 +861,7 @@ void ClientNetworkContentSocketHandler::Select(ContentID cid)
|
|||
if (ci == nullptr || ci->state != ContentInfo::UNSELECTED) return;
|
||||
|
||||
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;
|
||||
|
||||
ci->state = ContentInfo::UNSELECTED;
|
||||
this->CheckDependencyState(ci);
|
||||
this->CheckDependencyState(*ci);
|
||||
}
|
||||
|
||||
/** Select everything we can select */
|
||||
|
@ -883,7 +883,7 @@ void ClientNetworkContentSocketHandler::SelectAll()
|
|||
for (ContentInfo *ci : this->infos) {
|
||||
if (ci->state == ContentInfo::UNSELECTED) {
|
||||
ci->state = ContentInfo::SELECTED;
|
||||
this->CheckDependencyState(ci);
|
||||
this->CheckDependencyState(*ci);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -894,7 +894,7 @@ void ClientNetworkContentSocketHandler::SelectUpgrade()
|
|||
for (ContentInfo *ci : this->infos) {
|
||||
if (ci->state == ContentInfo::UNSELECTED && ci->upgrade) {
|
||||
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 */
|
||||
void ClientNetworkContentSocketHandler::ToggleSelectedState(const ContentInfo *ci)
|
||||
void ClientNetworkContentSocketHandler::ToggleSelectedState(const ContentInfo &ci)
|
||||
{
|
||||
switch (ci->state) {
|
||||
switch (ci.state) {
|
||||
case ContentInfo::SELECTED:
|
||||
case ContentInfo::AUTOSELECTED:
|
||||
this->Unselect(ci->id);
|
||||
this->Unselect(ci.id);
|
||||
break;
|
||||
|
||||
case ContentInfo::UNSELECTED:
|
||||
this->Select(ci->id);
|
||||
this->Select(ci.id);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -930,9 +930,9 @@ void ClientNetworkContentSocketHandler::ToggleSelectedState(const ContentInfo *c
|
|||
* @param parents list to store all parents in (is not cleared)
|
||||
* @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) {
|
||||
parents.push_back(GetContent(iter->second));
|
||||
|
@ -954,7 +954,7 @@ void ClientNetworkContentSocketHandler::ReverseLookupTreeDependency(ConstContent
|
|||
* pointer gets invalid. So fall back to the indices. */
|
||||
for (uint i = 0; i < tree.size(); i++) {
|
||||
ConstContentVector parents;
|
||||
this->ReverseLookupDependency(parents, tree[i]);
|
||||
this->ReverseLookupDependency(parents, *tree[i]);
|
||||
|
||||
for (const ContentInfo *ci : parents) {
|
||||
include(tree, ci);
|
||||
|
@ -966,25 +966,25 @@ void ClientNetworkContentSocketHandler::ReverseLookupTreeDependency(ConstContent
|
|||
* Check the dependencies (recursively) of this content info
|
||||
* @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
|
||||
* autoselected state. That way we can see what we automatically
|
||||
* 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);
|
||||
if (c == nullptr) {
|
||||
this->DownloadContentInfo(dependency);
|
||||
} else if (c->state == ContentInfo::UNSELECTED) {
|
||||
c->state = ContentInfo::AUTOSELECTED;
|
||||
this->CheckDependencyState(c);
|
||||
this->CheckDependencyState(*c);
|
||||
}
|
||||
}
|
||||
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
|
||||
* unselect them. After that we unselect all children that we
|
||||
|
@ -998,7 +998,7 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(const ContentInfo *
|
|||
this->Unselect(c->id);
|
||||
}
|
||||
|
||||
for (auto &dependency : ci->dependencies) {
|
||||
for (auto &dependency : ci.dependencies) {
|
||||
const ContentInfo *c = this->GetContent(dependency);
|
||||
if (c == nullptr) {
|
||||
DownloadContentInfo(dependency);
|
||||
|
@ -1008,7 +1008,7 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(const ContentInfo *
|
|||
|
||||
/* Only unselect when WE are the only parent. */
|
||||
parents.clear();
|
||||
this->ReverseLookupDependency(parents, c);
|
||||
this->ReverseLookupDependency(parents, *c);
|
||||
|
||||
/* First check whether anything depends on us */
|
||||
int sel_count = 0;
|
||||
|
@ -1048,7 +1048,7 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(const ContentInfo *
|
|||
if (parent->state == ContentInfo::AUTOSELECTED) this->Unselect(parent->id);
|
||||
}
|
||||
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 */) {
|
||||
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 */) {
|
||||
ContentCallback *cb = this->callbacks[i];
|
||||
|
|
|
@ -42,14 +42,14 @@ struct ContentCallback {
|
|||
* We received a 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
|
||||
* @param ci the content info of the file
|
||||
* @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
|
||||
|
@ -90,8 +90,8 @@ protected:
|
|||
|
||||
void OnConnect(bool success) override;
|
||||
void OnDisconnect() override;
|
||||
void OnReceiveContentInfo(const ContentInfo *ci) override;
|
||||
void OnDownloadProgress(const ContentInfo *ci, int bytes) override;
|
||||
void OnReceiveContentInfo(const ContentInfo &ci) override;
|
||||
void OnDownloadProgress(const ContentInfo &ci, int bytes) override;
|
||||
void OnDownloadComplete(ContentID cid) override;
|
||||
|
||||
void OnFailure() override;
|
||||
|
@ -126,11 +126,11 @@ public:
|
|||
void SelectAll();
|
||||
void SelectUpgrade();
|
||||
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 CheckDependencyState(const ContentInfo *ci);
|
||||
void CheckDependencyState(const ContentInfo &ci);
|
||||
|
||||
/** Get the number of content items we know locally. */
|
||||
uint Length() const { return (uint)this->infos.size(); }
|
||||
|
|
|
@ -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) {
|
||||
this->name = ci->filename;
|
||||
this->cur_id = ci->id;
|
||||
if (ci.id != this->cur_id) {
|
||||
this->name = ci.filename;
|
||||
this->cur_id = ci.id;
|
||||
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);
|
||||
include(this->receivedTypes, ci->type);
|
||||
include(this->receivedTypes, ci.type);
|
||||
|
||||
/* When downloading is finished change cancel in ok */
|
||||
if (this->downloaded_bytes == this->total_bytes) {
|
||||
|
@ -792,7 +792,7 @@ public:
|
|||
|
||||
const NWidgetBase *checkbox = this->GetWidget<NWidgetBase>(WID_NCL_CHECKBOX);
|
||||
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.ForceRebuild();
|
||||
}
|
||||
|
@ -870,7 +870,7 @@ public:
|
|||
case WKC_RETURN:
|
||||
if (keycode == WKC_RETURN || !IsWidgetFocused(WID_NCL_FILTER)) {
|
||||
if (this->selected != nullptr) {
|
||||
_network_content_client.ToggleSelectedState(this->selected);
|
||||
_network_content_client.ToggleSelectedState(*this->selected);
|
||||
this->content.ForceResort();
|
||||
this->InvalidateData();
|
||||
}
|
||||
|
@ -925,9 +925,9 @@ public:
|
|||
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->InvalidateData(0, false);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
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 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();
|
||||
|
|
|
@ -195,13 +195,13 @@ struct ScriptFileChecksumCreator : FileScanner {
|
|||
* @param info The script to get the shortname and md5 sum from.
|
||||
* @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;
|
||||
const char *str = info->GetShortName().c_str();
|
||||
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;
|
||||
|
||||
ScriptFileChecksumCreator checksum(dir);
|
||||
|
@ -229,10 +229,10 @@ static bool IsSameScript(const ContentInfo *ci, bool md5sum, ScriptInfo *info, S
|
|||
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) {
|
||||
if (IsSameScript(ci, md5sum, item.second, this->GetDirectory())) return true;
|
||||
|
@ -240,7 +240,7 @@ bool ScriptScanner::HasScript(const ContentInfo *ci, bool md5sum)
|
|||
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) {
|
||||
if (IsSameScript(ci, md5sum, item.second, this->GetDirectory())) return item.second->GetMainScript().c_str();
|
||||
|
|
|
@ -66,7 +66,7 @@ public:
|
|||
* @param md5sum Whether to check the MD5 checksum.
|
||||
* @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
|
||||
|
@ -74,7 +74,7 @@ public:
|
|||
* @param md5sum Whether to check the MD5 checksum.
|
||||
* @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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue