This commit is contained in:
HJfod 2022-10-08 13:30:05 +03:00
commit 4a1b8a67f3
4 changed files with 53 additions and 20 deletions

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,6 +23,7 @@ __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";
auto error = std::error_code();
@ -23,19 +33,30 @@ __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) {
ghc::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;
if (error) {
std::cout << "Couldn't update Geode resources: " << error.message() << std::endl;
return loadGeode();
}
}
return;
return loadGeode();
}

View file

@ -1,10 +1,20 @@
#include <Windows.h>
#include <iostream>
#include "../../../filesystem/fs/filesystem.hpp"
void showError(std::string const& error) {
MessageBoxA(nullptr, error.c_str(), "Error Loading Geode", MB_ICONERROR);
}
int loadGeode() {
if (!LoadLibraryW(L"Geode.dll")) {
auto code = GetLastError();
showError("Unable to load Geode (code " + std::to_string(code) + ")");
return code;
}
return 0;
}
DWORD WINAPI load(PVOID _) {
auto workingDir = ghc::filesystem::current_path();
auto updatesDir = workingDir / "geode" / "update";
@ -24,22 +34,22 @@ DWORD WINAPI load(PVOID _) {
}
if (ghc::filesystem::exists(updatesDir / "resources", error) && !error) {
ghc::filesystem::rename(
updatesDir / "resources",
resourcesDir / "geode.loader", error
);
ghc::filesystem::remove_all(resourcesDir / "geode.loader", error);
if (error) {
showError("Unable to update Geode resources: " + error.message());
return error.value();
} else {
ghc::filesystem::rename(
updatesDir / "resources",
resourcesDir / "geode.loader", error
);
if (error) {
showError("Unable to update Geode resources: " + error.message());
}
}
}
if (!LoadLibraryW(L"Geode.dll")) {
showError("Unable to load Geode (code " + std::to_string(GetLastError()) + ")");
return 1;
}
return 0;
return loadGeode();
}
BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID _) {

View file

@ -3,6 +3,7 @@
class InternalMod;
#include <Geode/loader/Mod.hpp>
#include <Geode/loader/Interface.hpp>
USE_GEODE_NAMESPACE();

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;
}