2022-12-12 14:23:53 -05:00
|
|
|
#include <ghc/filesystem.hpp>
|
2022-10-08 05:41:36 -04:00
|
|
|
#include <mach-o/dyld.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <array>
|
2022-10-08 06:21:57 -04:00
|
|
|
#include <iostream>
|
2022-10-08 06:43:24 -04:00
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
|
|
|
|
|
|
void displayError(std::string alertMessage) {
|
|
|
|
CFStringRef cfTitle = CFStringCreateWithCString(NULL, "Geode Bootstrapper", kCFStringEncodingUTF8);
|
|
|
|
CFStringRef cfMessage = CFStringCreateWithCString(NULL, alertMessage.c_str(), kCFStringEncodingUTF8);
|
|
|
|
|
|
|
|
CFUserNotificationDisplayNotice(0, kCFUserNotificationCautionAlertLevel, NULL, NULL, NULL, cfTitle, cfMessage, NULL);
|
|
|
|
}
|
2022-10-08 06:21:57 -04:00
|
|
|
|
|
|
|
void loadGeode() {
|
2022-12-13 10:34:09 -05:00
|
|
|
auto dylib = dlopen("Geode.dylib", RTLD_NOW);
|
|
|
|
if (!dylib) {
|
|
|
|
displayError(std::string("Couldn't load Geode: ") + dlerror());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto trigger = dlsym(dylib, "dynamicTrigger");
|
|
|
|
if (!trigger) {
|
|
|
|
displayError(std::string("Couldn't start Geode: ") + dlerror());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
reinterpret_cast<void(*)()>(trigger)();
|
2022-10-08 06:21:57 -04:00
|
|
|
return;
|
|
|
|
}
|
2022-10-08 05:41:36 -04:00
|
|
|
|
|
|
|
__attribute__((constructor)) void _entry() {
|
|
|
|
std::array<char, PATH_MAX> gddir;
|
|
|
|
|
|
|
|
uint32_t out = PATH_MAX;
|
|
|
|
_NSGetExecutablePath(gddir.data(), &out);
|
|
|
|
|
|
|
|
ghc::filesystem::path gdpath = gddir.data();
|
|
|
|
auto workingDir = gdpath.parent_path().parent_path();
|
|
|
|
|
|
|
|
auto updatesDir = workingDir / "geode" / "update";
|
2022-10-08 06:21:57 -04:00
|
|
|
auto libDir = workingDir / "Frameworks";
|
2022-10-08 05:41:36 -04:00
|
|
|
auto resourcesDir = workingDir / "geode" / "resources";
|
|
|
|
|
|
|
|
auto error = std::error_code();
|
|
|
|
|
|
|
|
if (ghc::filesystem::exists(updatesDir / "Geode.dylib", error) && !error) {
|
|
|
|
ghc::filesystem::rename(
|
|
|
|
updatesDir / "Geode.dylib",
|
2022-10-08 06:59:51 -04:00
|
|
|
libDir / "Geode.dylib", error
|
2022-10-08 05:41:36 -04:00
|
|
|
);
|
2022-10-08 06:21:57 -04:00
|
|
|
if (error) {
|
2022-10-08 06:43:24 -04:00
|
|
|
displayError(std::string("Couldn't update Geode: ") + error.message());
|
2022-10-08 06:21:57 -04:00
|
|
|
return loadGeode();
|
|
|
|
}
|
2022-10-08 05:41:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ghc::filesystem::exists(updatesDir / "resources", error) && !error) {
|
2022-10-08 06:23:48 -04:00
|
|
|
ghc::filesystem::remove_all(resourcesDir / "geode.loader", error);
|
2022-10-08 06:21:57 -04:00
|
|
|
|
|
|
|
if (error) {
|
2022-10-08 06:43:24 -04:00
|
|
|
displayError(std::string("Couldn't update Geode resources: ") + error.message());
|
2022-10-08 06:21:57 -04:00
|
|
|
return loadGeode();
|
|
|
|
}
|
|
|
|
|
2022-10-08 05:41:36 -04:00
|
|
|
ghc::filesystem::rename(
|
|
|
|
updatesDir / "resources",
|
|
|
|
resourcesDir / "geode.loader", error
|
|
|
|
);
|
2022-10-08 06:21:57 -04:00
|
|
|
|
|
|
|
if (error) {
|
2022-10-08 06:43:24 -04:00
|
|
|
displayError(std::string("Couldn't update Geode resources: ") + error.message());
|
2022-10-08 06:21:57 -04:00
|
|
|
return loadGeode();
|
|
|
|
}
|
|
|
|
}
|
2022-10-08 05:41:36 -04:00
|
|
|
|
2022-10-08 06:21:57 -04:00
|
|
|
return loadGeode();
|
2022-10-08 05:41:36 -04:00
|
|
|
}
|