revert mod.json resource and move markdowns

This commit is contained in:
altalk23 2023-05-01 13:06:46 +03:00
parent 144bb1baae
commit d7ccfdef3e
11 changed files with 36 additions and 23 deletions

View file

@ -28,6 +28,7 @@ execute_process(
# Package info file for internal representation
configure_file(resources/mod.json.in ${CMAKE_CURRENT_SOURCE_DIR}/resources/mod.json)
file(READ resources/mod.json LOADER_MOD_JSON)
configure_file(${GEODE_ROOT_PATH}/CHANGELOG.md ${CMAKE_CURRENT_SOURCE_DIR}/resources/changelog.md COPYONLY)
configure_file(src/internal/about.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/src/internal/about.hpp)

View file

@ -7,6 +7,7 @@
#include <json.hpp>
#include <optional>
#include <unordered_set>
#include <cocos2d.h>
#pragma warning(push)
#pragma warning(disable : 4275)

View file

@ -17,7 +17,7 @@ int loadGeode(PVOID module) {
}
DWORD WINAPI load(PVOID module) {
auto workingDir = utils::file::current_path();
auto workingDir = ghc::filesystem::current_path();
auto updatesDir = workingDir / "geode" / "update";
auto resourcesDir = workingDir / "geode" / "resources";

View file

@ -45,6 +45,9 @@ struct CustomLoadingLayer : Modify<CustomLoadingLayer, LoadingLayer> {
m_fields->m_updatingResources = true;
this->setUpdateText("Downloading Resources");
}
else {
LoaderImpl::get()->updateSpecialFiles();
}
}
return true;

View file

@ -13,3 +13,4 @@ static constexpr geode::VersionInfo LOADER_VERSION = {
@PROJECT_VERSION_PATCH@,
@PROJECT_VERSION_TAG_CONSTR@,
};
static constexpr const char* LOADER_MOD_JSON = R"JSON_SEPARATOR(@LOADER_MOD_JSON@)JSON_SEPARATOR";

View file

@ -14,6 +14,7 @@
#include <Geode/utils/web.hpp>
#include <Geode/utils/JsonValidation.hpp>
#include "ModImpl.hpp"
#include "ModInfoImpl.hpp"
#include <about.hpp>
#include <crashlog.hpp>
#include <fmt/format.h>
@ -498,6 +499,7 @@ void Loader::Impl::fetchLatestGithubRelease(
if (m_latestGithubRelease) {
return then(m_latestGithubRelease.value());
}
// TODO: add header to not get rate limited
web::AsyncWebRequest()
.join("loader-auto-update-check")
.fetch("https://api.github.com/repos/geode-sdk/geode/releases/latest")
@ -521,7 +523,7 @@ void Loader::Impl::tryDownloadLoaderResources(
.join(url)
.fetch(url)
.into(tempResourcesZip)
.then([tempResourcesZip, resourcesDir](auto) {
.then([tempResourcesZip, resourcesDir, this](auto) {
// unzip resources zip
auto unzip = file::Unzip::intoDir(tempResourcesZip, resourcesDir, true);
if (!unzip) {
@ -530,6 +532,8 @@ void Loader::Impl::tryDownloadLoaderResources(
).post();
return;
}
this->updateSpecialFiles();
ResourceDownloadEvent(UpdateFinished()).post();
})
.expect([this, tryLatestOnError](std::string const& info, int code) {
@ -554,6 +558,14 @@ void Loader::Impl::tryDownloadLoaderResources(
});
}
void Loader::Impl::updateSpecialFiles() {
auto resourcesDir = dirs::getGeodeResourcesDir() / Mod::get()->getID();
auto res = ModInfoImpl::getImpl(ModImpl::get()->m_info).addSpecialFiles(resourcesDir);
if (res.isErr()) {
log::warn("Unable to add special files: {}", res.unwrapErr());
}
}
void Loader::Impl::downloadLoaderResources(bool useLatestRelease) {
if (!useLatestRelease) {
this->tryDownloadLoaderResources(fmt::format(
@ -607,6 +619,7 @@ bool Loader::Impl::verifyLoaderResources() {
ghc::filesystem::exists(resourcesDir) &&
ghc::filesystem::is_directory(resourcesDir)
)) {
log::debug("Resources directory does not exist");
this->downloadLoaderResources();
return false;
}
@ -623,10 +636,9 @@ bool Loader::Impl::verifyLoaderResources() {
}
// verify hash
auto hash = calculateSHA256(file.path());
if (hash != LOADER_RESOURCE_HASHES.at(name)) {
log::debug(
"compare {} {} {}", file.path().string(), hash, LOADER_RESOURCE_HASHES.at(name)
);
auto expected = LOADER_RESOURCE_HASHES.at(name);
if (hash != expected) {
log::debug("Resource hash mismatch: {} ({}, {})", name, hash.substr(0, 7), expected.substr(0, 7));
this->downloadLoaderResources();
return false;
}
@ -635,6 +647,7 @@ bool Loader::Impl::verifyLoaderResources() {
// make sure every file was found
if (coverage != LOADER_RESOURCE_HASHES.size()) {
log::debug("Resource coverage mismatch");
this->downloadLoaderResources();
return false;
}

View file

@ -91,6 +91,7 @@ namespace geode {
Result<tulip::hook::HandlerHandle> getHandler(void* address);
Result<> removeHandler(void* address);
void updateSpecialFiles();
void tryDownloadLoaderResources(std::string const& url, bool tryLatestOnError = true);
void downloadLoaderResources(bool useLatestRelease = false);
void downloadLoaderUpdate(std::string const& url);

View file

@ -17,6 +17,10 @@
using namespace geode::prelude;
Mod::Impl* ModImpl::get() {
return Mod::get()->m_impl.get();
}
Mod::Impl* ModImpl::getImpl(Mod* mod) {
return mod->m_impl.get();
}
@ -674,27 +678,13 @@ ModJson Mod::Impl::getRuntimeInfo() const {
static Result<ModInfo> getModImplInfo() {
std::string err;
json::Value json;
auto resourcesDir = dirs::getGeodeResourcesDir() / "geode.loader";
auto jsonPath = resourcesDir / "mod.json";
try {
if (ghc::filesystem::exists(jsonPath)) {
auto data = file::readString(jsonPath);
if (!data) {
return Err("Unable to read mod.json: " + data.unwrapErr());
}
json = json::parse(data.unwrap());
}
else {
return Err("Unable to find mod.json at " + jsonPath.string());
}
json = json::parse(LOADER_MOD_JSON);
} catch (std::exception& err) {
return Err("Unable to parse mod.json: " + std::string(err.what()));
}
GEODE_UNWRAP_INTO(auto info, ModInfo::create(json));
GEODE_UNWRAP(ModInfoImpl::getImpl(info).addSpecialFiles(resourcesDir));
info.supportsDisabling() = false;
return Ok(info);
}

View file

@ -129,7 +129,7 @@ namespace geode {
class ModImpl : public Mod {
public:
static Mod* get();
static Mod::Impl* get();
static Mod::Impl* getImpl(Mod* mod);
};

View file

@ -1,3 +1,5 @@
#pragma once
#include <Geode/loader/Loader.hpp>
#include <Geode/loader/Mod.hpp>
#include <Geode/utils/JsonValidation.hpp>

View file

@ -149,7 +149,8 @@ CCPoint cocos::getMousePos() {
}
ghc::filesystem::path utils::file::current_path() {
if (ghc::filesystem::current_path().empty()) {
// if it's just a slash because for some reason it is
if (ghc::filesystem::current_path().string().size() < 2) {
std::array<char, PATH_MAX> gddir;
uint32_t out = PATH_MAX;