also check gd version on index items

This commit is contained in:
matcool 2024-01-23 14:59:32 -03:00
parent 4a6b5b7c37
commit 82808c3a86
5 changed files with 35 additions and 28 deletions
loader

View file

@ -159,7 +159,13 @@ namespace geode {
* Gets the target GD version for the current platform.
* Returns nullopt if mod targets any GD version.
*/
[[nodiscard]] std::optional<std::string> getGDVersion() const;
[[nodiscard]] std::optional<std::string> getGameVersion() const;
/**
* Checks if mod can be installed on the current GD version.
* Returns Ok() if it can, Err otherwise.
*/
Result<> checkGameVersion() const;
#if defined(GEODE_EXPOSE_SECRET_INTERNALS_IN_HEADERS_DO_NOT_DEFINE_PLEASE)
void setPath(ghc::filesystem::path const& value);

View file

@ -613,6 +613,8 @@ Result<> Index::canInstall(IndexItemHandle item) const {
return Err("Mod is not available on {}", GEODE_PLATFORM_NAME);
}
GEODE_UNWRAP(item->getMetadata().checkGameVersion());
for (auto& dep : item->getMetadata().getDependencies()) {
// if the dep is resolved, then all its dependencies must be installed
// already in order for that to have happened

View file

@ -332,27 +332,7 @@ bool Mod::Impl::hasSetting(std::string_view const key) const {
Result<> Mod::Impl::loadBinary() {
// i dont know where to put this so ill just plop it here
auto const gdVerOpt = m_metadata.getGDVersion();
if (gdVerOpt) {
auto const ver = gdVerOpt.value();
double modTargetVer;
try {
// assume gd version is always a valid double
modTargetVer = std::stod(ver);
} catch (...) {
return Err("Mod has invalid target GD version");
}
if (LoaderImpl::get()->isForwardCompatMode()) {
// this means current gd version is > GEODE_GD_VERSION
if (modTargetVer <= GEODE_GD_VERSION) {
return Err(fmt::format("Mod doesn't support this GD version ({} < current version)", ver));
}
} else if (ver != GEODE_STR(GEODE_GD_VERSION)) {
// we are not in forward compat mode, so GEODE_GD_VERSION is the current gd version
return Err(fmt::format("Mod doesn't support this GD version ({} != {})", ver, GEODE_STR(GEODE_GD_VERSION)));
}
}
GEODE_UNWRAP(m_metadata.checkGameVersion());
log::debug("Loading binary for mod {}", m_metadata.getID());
if (m_enabled)

View file

@ -386,11 +386,30 @@ bool ModMetadata::isAPI() const {
return m_impl->m_isAPI;
}
std::optional<std::string> ModMetadata::getGDVersion() const {
std::optional<std::string> ModMetadata::getGameVersion() const {
if (m_impl->m_gdVersion.empty()) return std::nullopt;
return m_impl->m_gdVersion;
}
Result<> ModMetadata::checkGameVersion() const {
if (!m_impl->m_gdVersion.empty()) {
auto const ver = m_impl->m_gdVersion;
double modTargetVer = std::stod(ver);
if (LoaderImpl::get()->isForwardCompatMode()) {
// this means current gd version is > GEODE_GD_VERSION
if (modTargetVer <= GEODE_GD_VERSION) {
return Err(fmt::format("Mod doesn't support this GD version ({} < current version)", ver));
}
} else if (ver != GEODE_STR(GEODE_GD_VERSION)) {
// we are not in forward compat mode, so GEODE_GD_VERSION is the current gd version
return Err(fmt::format("Mod doesn't support this GD version ({} != {})", ver, GEODE_STR(GEODE_GD_VERSION)));
}
}
return Ok();
}
#if defined(GEODE_EXPOSE_SECRET_INTERNALS_IN_HEADERS_DO_NOT_DEFINE_PLEASE)
void ModMetadata::setPath(ghc::filesystem::path const& value) {
m_impl->m_path = value;

View file

@ -108,11 +108,11 @@ static std::optional<int> queryMatch(ModListQuery const& query, IndexItemHandle
// if no force visibility was provided and item is already installed, don't show it
auto canInstall = Index::get()->canInstall(item);
if (!query.forceInvalid && !canInstall) {
log::warn(
"Removing {} from the list because it cannot be installed: {}",
item->getMetadata().getID(),
canInstall.unwrapErr()
);
// log::warn(
// "Removing {} from the list because it cannot be installed: {}",
// item->getMetadata().getID(),
// canInstall.unwrapErr()
// );
return std::nullopt;
}
// otherwise match keywords