fix resources not updating

This commit is contained in:
altalk23 2022-10-08 13:21:57 +03:00
parent 650849c242
commit 41cce1c81f
3 changed files with 61 additions and 13 deletions
loader

View file

@ -3,6 +3,15 @@
#include <unistd.h>
#include <dlfcn.h>
#include <array>
#include <iostream>
void loadGeode() {
auto dylib = dlopen("Geode.dylib", RTLD_LAZY);
if (dylib) return;
std::cout << "Couldn't open Geode: " << dlerror() << std::endl;
return;
}
__attribute__((constructor)) void _entry() {
std::array<char, PATH_MAX> gddir;
@ -14,8 +23,12 @@ __attribute__((constructor)) void _entry() {
auto workingDir = gdpath.parent_path().parent_path();
auto updatesDir = workingDir / "geode" / "update";
auto libDir = workingDir / "Frameworks";
auto resourcesDir = workingDir / "geode" / "resources";
std::cout << workingDir << std::endl;
std::cout << libDir << std::endl;
auto error = std::error_code();
if (ghc::filesystem::exists(updatesDir / "Geode.dylib", error) && !error) {
@ -23,19 +36,31 @@ __attribute__((constructor)) void _entry() {
updatesDir / "Geode.dylib",
workingDir / "Geode.dylib", error
);
if (error) return;
if (error) {
std::cout << "Couldn't update Geode: " << error.message() << std::endl;
return loadGeode();
}
}
if (ghc::filesystem::exists(updatesDir / "resources", error) && !error) {
std::filesystem::remove_all(resourcesDir / "geode.loader", error);
if (error) {
std::cout << "Couldn't update Geode resources: " << error.message() << std::endl;
return loadGeode();
}
ghc::filesystem::rename(
updatesDir / "resources",
resourcesDir / "geode.loader", error
);
if (error) return;
}
auto dylib = dlopen("Geode.dylib", RTLD_LAZY);
if (dylib) return;
std::cout << error.message() << std::endl;
if (error) {
std::cout << "Couldn't update Geode resources: " << error.message() << std::endl;
return loadGeode();
}
}
return;
return loadGeode();
}

View file

@ -1,6 +1,16 @@
#include <Windows.h>
#include <iostream>
#include "../../../filesystem/fs/filesystem.hpp"
int loadGeode() {
auto dll = LoadLibraryA("Geode.dll");
if (!dylib) {
std::cout << "Couldn't open Geode: " << GetLastError() << std::endl;
return GetLastError();
}
return 0;
}
DWORD WINAPI load(PVOID _) {
auto workingDir = ghc::filesystem::current_path();
auto updatesDir = workingDir / "geode" / "update";
@ -13,19 +23,31 @@ DWORD WINAPI load(PVOID _) {
updatesDir / "Geode.dll",
workingDir / "Geode.dll", error
);
if (error) return error.value();
if (error) {
std::cout << "Couldn't update Geode: " << error.message() << std::endl;
return loadGeode();
}
}
if (ghc::filesystem::exists(updatesDir / "resources", error) && !error) {
std::filesystem::remove_all(resourcesDir / "geode.loader", error);
if (error) {
std::cout << "Couldn't update Geode resources: " << error.message() << std::endl;
return loadGeode();
}
ghc::filesystem::rename(
updatesDir / "resources",
resourcesDir / "geode.loader", error
);
if (error) return error.value();
if (error) {
std::cout << "Couldn't update Geode resources: " << error.message() << std::endl;
return loadGeode();
}
}
LoadLibraryA("Geode.dll");
return 0;
return loadGeode();
}
BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID _) {

View file

@ -34,7 +34,8 @@ __attribute__((constructor)) void _entry() {
ghc::filesystem::path gdpath = gddir.data();
ghc::filesystem::current_path(gdpath.parent_path().parent_path());
auto workingDir = ghc::filesystem::current_path();
auto workingDir = gdpath.parent_path().parent_path();
auto libDir = workingDir / "Frameworks";
auto updatesDir = workingDir / "geode" / "update";
auto error = std::error_code();
@ -42,7 +43,7 @@ __attribute__((constructor)) void _entry() {
if (ghc::filesystem::exists(updatesDir / "GeodeBootstrapper.dylib", error) && !error) {
ghc::filesystem::rename(
updatesDir / "GeodeBootstrapper.dylib",
workingDir / "GeodeBootstrapper.dylib", error
libDir / "GeodeBootstrapper.dylib", error
);
if (error) return;
}