Codechange: use std::string for text file name resolution
This commit is contained in:
@@ -49,11 +49,11 @@ bool ContentInfo::IsValid() const
|
||||
/**
|
||||
* Search a textfile file next to this file in the content list.
|
||||
* @param type The type of the textfile to search for.
|
||||
* @return The filename for the textfile, \c nullptr otherwise.
|
||||
* @return The filename for the textfile.
|
||||
*/
|
||||
const char *ContentInfo::GetTextfile(TextfileType type) const
|
||||
std::optional<std::string> ContentInfo::GetTextfile(TextfileType type) const
|
||||
{
|
||||
if (this->state == INVALID) return nullptr;
|
||||
if (this->state == INVALID) return std::nullopt;
|
||||
const char *tmp;
|
||||
switch (this->type) {
|
||||
default: NOT_REACHED();
|
||||
@@ -88,7 +88,7 @@ const char *ContentInfo::GetTextfile(TextfileType type) const
|
||||
tmp = FindScenario(this, true);
|
||||
break;
|
||||
}
|
||||
if (tmp == nullptr) return nullptr;
|
||||
if (tmp == nullptr) return std::nullopt;
|
||||
return ::GetTextfile(type, GetContentInfoSubDir(this->type), tmp);
|
||||
}
|
||||
|
||||
|
@@ -12,6 +12,8 @@
|
||||
#ifndef NETWORK_CORE_TCP_CONTENT_TYPE_H
|
||||
#define NETWORK_CORE_TCP_CONTENT_TYPE_H
|
||||
|
||||
#include <optional>
|
||||
|
||||
/** The values in the enum are important; they are used as database 'keys' */
|
||||
enum ContentType {
|
||||
CONTENT_TYPE_BEGIN = 1, ///< Helper to mark the begin of the types
|
||||
@@ -75,7 +77,7 @@ struct ContentInfo {
|
||||
|
||||
bool IsSelected() const;
|
||||
bool IsValid() const;
|
||||
const char *GetTextfile(TextfileType type) const;
|
||||
std::optional<std::string> GetTextfile(TextfileType type) const;
|
||||
};
|
||||
|
||||
#endif /* NETWORK_CORE_TCP_CONTENT_TYPE_H */
|
||||
|
@@ -43,8 +43,8 @@ struct ContentTextfileWindow : public TextfileWindow {
|
||||
|
||||
ContentTextfileWindow(TextfileType file_type, const ContentInfo *ci) : TextfileWindow(file_type), ci(ci)
|
||||
{
|
||||
const char *textfile = this->ci->GetTextfile(file_type);
|
||||
this->LoadTextfile(textfile, GetContentInfoSubDir(this->ci->type));
|
||||
auto textfile = this->ci->GetTextfile(file_type);
|
||||
this->LoadTextfile(textfile.value(), GetContentInfoSubDir(this->ci->type));
|
||||
}
|
||||
|
||||
StringID GetTypeString() const
|
||||
@@ -998,7 +998,7 @@ public:
|
||||
this->SetWidgetDisabledState(WID_NCL_SELECT_UPDATE, !show_select_upgrade);
|
||||
this->SetWidgetDisabledState(WID_NCL_OPEN_URL, this->selected == nullptr || this->selected->url.empty());
|
||||
for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
|
||||
this->SetWidgetDisabledState(WID_NCL_TEXTFILE + tft, this->selected == nullptr || this->selected->state != ContentInfo::ALREADY_HERE || this->selected->GetTextfile(tft) == nullptr);
|
||||
this->SetWidgetDisabledState(WID_NCL_TEXTFILE + tft, this->selected == nullptr || this->selected->state != ContentInfo::ALREADY_HERE || !this->selected->GetTextfile(tft).has_value());
|
||||
}
|
||||
|
||||
this->GetWidget<NWidgetCore>(WID_NCL_CANCEL)->widget_data = this->filesize_sum == 0 ? STR_AI_SETTINGS_CLOSE : STR_AI_LIST_CANCEL;
|
||||
|
Reference in New Issue
Block a user