Skip to content

Commit 1df44b8

Browse files
committed
block storing data for the invalid mods
1 parent bc622d3 commit 1df44b8

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

loader/src/loader/ModImpl.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,19 @@ Mod::Impl::~Impl() = default;
5353

5454
Result<> Mod::Impl::setup() {
5555
m_saveDirPath = dirs::getModsSaveDir() / m_metadata.getID();
56+
m_settings = std::make_unique<ModSettingsManager>(m_metadata);
57+
58+
if (this->isEphemeral()) {
59+
return Ok();
60+
}
61+
5662
(void) utils::file::createDirectoryAll(m_saveDirPath);
5763

5864
// always create temp dir for all mods, even if disabled, so resources can be loaded
5965
GEODE_UNWRAP(this->createTempDir().mapErr([](auto const& err) {
6066
return fmt::format("Unable to create temp dir: {}", err);
6167
}));
6268

63-
m_settings = std::make_unique<ModSettingsManager>(m_metadata);
6469
auto loadRes = this->loadData();
6570
if (!loadRes) {
6671
log::warn("Unable to load data for \"{}\": {}", m_metadata.getID(), loadRes.unwrapErr());
@@ -103,6 +108,10 @@ std::string Mod::Impl::getName() const {
103108
return m_metadata.getName();
104109
}
105110

111+
bool Mod::Impl::isEphemeral() const {
112+
return ModMetadataImpl::getImpl(m_metadata).m_softInvalidReason.has_value();
113+
}
114+
106115
std::vector<std::string> Mod::Impl::getDevelopers() const {
107116
return m_metadata.getDevelopers();
108117
}
@@ -219,6 +228,10 @@ Result<> Mod::Impl::saveData() {
219228
return Ok();
220229
}
221230

231+
if (this->isEphemeral()) {
232+
return Ok();
233+
}
234+
222235
// ModSettingsManager keeps track of the whole savedata
223236
matjson::Value json = m_settings->save();
224237

loader/src/loader/ModImpl.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ namespace geode {
9797
std::filesystem::path getTempDir() const;
9898
std::filesystem::path getBinaryPath() const;
9999

100+
/**
101+
* If a mod should be considered ephemeral, in which case it will not attempt to save/load its data.
102+
* Currently used for the invalid mod objects.
103+
*/
104+
bool isEphemeral() const;
105+
100106
matjson::Value& getSaveContainer();
101107

102108
#if defined(GEODE_EXPOSE_SECRET_INTERNALS_IN_HEADERS_DO_NOT_DEFINE_PLEASE)

loader/src/loader/ModMetadataImpl.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ ModMetadataLinks& ModMetadataLinks::operator=(ModMetadataLinks&& other) noexcept
4646
}
4747
ModMetadataLinks::~ModMetadataLinks() = default;
4848

49-
ModMetadata::Impl& ModMetadataImpl::getImpl(ModMetadata& info) {
49+
ModMetadata::Impl& ModMetadataImpl::getImpl(ModMetadata& info) {
50+
return *info.m_impl;
51+
}
52+
53+
ModMetadata::Impl const& ModMetadataImpl::getImpl(ModMetadata const& info) {
5054
return *info.m_impl;
5155
}
5256

loader/src/loader/ModMetadataImpl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ namespace geode {
135135
class ModMetadataImpl : public ModMetadata::Impl {
136136
public:
137137
static ModMetadata::Impl& getImpl(ModMetadata& info);
138+
static ModMetadata::Impl const& getImpl(ModMetadata const& info);
138139
};
139140
}
140141

0 commit comments

Comments
 (0)