mirror of
https://github.com/geode-sdk/geode.git
synced 2025-02-17 00:30:26 -05:00
add Mod::hasAvailableUpdate
This commit is contained in:
parent
8250a737e0
commit
b71ae176e9
2 changed files with 23 additions and 0 deletions
|
@ -107,6 +107,16 @@ namespace geode {
|
|||
std::vector<Mod*> getDependants() const;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Check if this Mod has updates available on the mods index. If
|
||||
* you're using this for automatic update checking, use
|
||||
* `openInfoPopup` or `openIndexPopup` from the `ui/GeodeUI.hpp`
|
||||
* header to open the Mod's page to let the user install the update
|
||||
* @returns The latest available version on the index if there are
|
||||
* updates for this mod
|
||||
*/
|
||||
std::optional<VersionInfo> hasAvailableUpdate() const;
|
||||
|
||||
Result<> saveData();
|
||||
Result<> loadData();
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <Geode/loader/Dirs.hpp>
|
||||
#include <Geode/loader/Mod.hpp>
|
||||
#include <Geode/loader/Index.hpp>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
|
||||
|
@ -85,6 +86,18 @@ std::vector<Mod*> Mod::getDependants() const {
|
|||
}
|
||||
#endif
|
||||
|
||||
std::optional<VersionInfo> Mod::hasAvailableUpdate() const {
|
||||
if (auto item = Index::get()->getItem(this->getID(), std::nullopt)) {
|
||||
if (
|
||||
item->getMetadata().getVersion() > this->getVersion() &&
|
||||
item->getAvailablePlatforms().contains(GEODE_PLATFORM_TARGET)
|
||||
) {
|
||||
return item->getMetadata().getVersion();
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
Result<> Mod::saveData() {
|
||||
return m_impl->saveData();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue