standardization

- remove m_ prefix from structs
 - make IPC event members public
 - make IPC event reply as json
This commit is contained in:
HJfod 2022-12-09 21:29:21 +02:00
parent b3b5370c4b
commit 286bdb2bc6
19 changed files with 192 additions and 231 deletions

View file

@ -26,29 +26,24 @@ namespace geode {
class GEODE_DLL IPCEvent : public Event {
protected:
void* m_rawPipeHandle;
std::string m_targetModID;
std::string m_messageID;
std::string* m_replyString;
nlohmann::json m_messageData;
bool m_replied = false;
public:
std::string targetModID;
std::string messageID;
nlohmann::json messageData;
nlohmann::json& replyData;
friend class IPCFilter;
public:
IPCEvent(
void* rawPipeHandle,
std::string const& targetModID,
std::string const& messageID,
nlohmann::json const& messageData,
std::string* replyString = nullptr
nlohmann::json& replyData
);
virtual ~IPCEvent();
std::string getTargetModID() const;
std::string getMessageID() const;
std::string getReplyString() const;
void setReplyString(std::string const& reply);
nlohmann::json getMessageData() const;
};
class GEODE_DLL IPCFilter : public EventFilter<IPCEvent> {

View file

@ -12,8 +12,8 @@ namespace geode {
using ScheduledFunction = std::function<void GEODE_CALL(void)>;
struct InvalidGeodeFile {
ghc::filesystem::path m_path;
std::string m_reason;
ghc::filesystem::path path;
std::string reason;
};
class GEODE_DLL Loader {

View file

@ -148,7 +148,7 @@ namespace geode {
ghc::filesystem::path getConfigDir(bool create = true) const;
bool hasSettings() const;
decltype(ModInfo::m_settings) getSettings() const;
decltype(ModInfo::settings) getSettings() const;
bool hasSetting(std::string const& key) const;
std::shared_ptr<Setting> getSetting(std::string const& key) const;

View file

@ -21,8 +21,8 @@ namespace geode {
};
struct IssuesInfo {
std::string m_info;
std::optional<std::string> m_url;
std::string info;
std::optional<std::string> url;
};
/**
@ -33,16 +33,16 @@ namespace geode {
/**
* Path to the mod file
*/
ghc::filesystem::path m_path;
ghc::filesystem::path path;
/**
* Name of the platform binary within
* the mod zip
*/
std::string m_binaryName;
std::string binaryName;
/**
* Mod Version. Should follow semver.
*/
VersionInfo m_version { 1, 0, 0 };
VersionInfo version { 1, 0, 0 };
/**
* Human-readable ID of the Mod.
* Recommended to be in the format
@ -52,14 +52,14 @@ namespace geode {
* be restricted to the ASCII
* character set.
*/
std::string m_id;
std::string id;
/**
* Name of the mod. May contain
* spaces & punctuation, but should
* be restricted to the ASCII
* character set.
*/
std::string m_name;
std::string name;
/**
* The name of the head developer.
* Should be a single name, like
@ -71,60 +71,60 @@ namespace geode {
* should be named in `m_credits`
* instead.
*/
std::string m_developer;
std::string developer;
/**
* Short & concise description of the
* mod.
*/
std::optional<std::string> m_description;
std::optional<std::string> description;
/**
* Detailed description of the mod, writtenin Markdown (see
* <Geode/ui/MDTextArea.hpp>) for more info
*/
std::optional<std::string> m_details;
std::optional<std::string> details;
/**
* Changelog for the mod, written in Markdown (see
* <Geode/ui/MDTextArea.hpp>) for more info
*/
std::optional<std::string> m_changelog;
std::optional<std::string> changelog;
/**
* Support info for the mod; this means anything to show ways to
* support the mod's development, like donations. Written in Markdown
* (see <Geode/ui/MDTextArea.hpp>) for more info
*/
std::optional<std::string> m_supportInfo;
std::optional<std::string> supportInfo;
/**
* Git Repository of the mod
*/
std::optional<std::string> m_repository;
std::optional<std::string> repository;
/**
* Info about where users should report issues and request help
*/
std::optional<IssuesInfo> m_issues;
std::optional<IssuesInfo> issues;
/**
* Dependencies
*/
std::vector<Dependency> m_dependencies;
std::vector<Dependency> dependencies;
/**
* Mod spritesheet names
*/
std::vector<std::string> m_spritesheets;
std::vector<std::string> spritesheets;
/**
* Mod settings
*/
std::vector<std::pair<std::string, std::shared_ptr<Setting>>> m_settings;
std::vector<std::pair<std::string, std::shared_ptr<Setting>>> settings;
/**
* Whether the mod can be disabled or not
*/
bool m_supportsDisabling = true;
bool supportsDisabling = true;
/**
* Whether the mod can be unloaded or not
*/
bool m_supportsUnloading = false;
bool supportsUnloading = false;
/**
* Whether this mod has to be loaded before the loading screen or not
*/
bool m_needsEarlyLoad = false;
bool needsEarlyLoad = false;
/**
* Create ModInfo from an unzipped .geode package
*/

View file

@ -216,12 +216,9 @@ bool InternalLoader::verifyLoaderResources() {
return true;
}
std::string InternalLoader::processRawIPC(void* rawHandle, std::string const& buffer) {
std::string reply;
nlohmann::json InternalLoader::processRawIPC(void* rawHandle, std::string const& buffer) {
nlohmann::json reply;
try {
std::optional<std::string> replyID = std::nullopt;
// parse received message
auto json = nlohmann::json::parse(buffer);
if (!json.contains("mod") || !json["mod"].is_string()) {
@ -232,19 +229,15 @@ std::string InternalLoader::processRawIPC(void* rawHandle, std::string const& bu
log::warn("Received IPC message without 'message' field");
return reply;
}
if (json.contains("reply") && json["reply"].is_string()) {
replyID = json["reply"];
}
nlohmann::json data;
if (json.contains("data")) {
data = json["data"];
}
// log::debug("Posting IPC event");
// ! warning: if the event system is ever made asynchronous this will break!
IPCEvent(rawHandle, json["mod"], json["message"], data, &reply).post();
IPCEvent(rawHandle, json["mod"], json["message"], data, reply).post();
} catch(...) {
log::warn("Received IPC message that isn't valid JSON");
}
return reply;
}

View file

@ -62,7 +62,7 @@ public:
bool setup();
static std::string processRawIPC(void* rawHandle, std::string const& buffer);
static nlohmann::json processRawIPC(void* rawHandle, std::string const& buffer);
/**
* Check if a one-time event has been shown to the user,

View file

@ -23,9 +23,9 @@ static ModInfo getInternalModInfo() {
exit(1);
}
auto info = infoRes.unwrap();
info.m_details = LOADER_ABOUT_MD;
info.m_supportInfo = SUPPORT_INFO;
info.m_supportsDisabling = false;
info.details = LOADER_ABOUT_MD;
info.supportInfo = SUPPORT_INFO;
info.supportsDisabling = false;
return info;
}
catch (std::exception& e) {
@ -41,7 +41,7 @@ static ModInfo getInternalModInfo() {
}
InternalMod::InternalMod() : Mod(getInternalModInfo()) {
m_saveDirPath = dirs::getModsSaveDir() / m_info.m_id;
m_saveDirPath = dirs::getModsSaveDir() / m_info.id;
ghc::filesystem::create_directories(m_saveDirPath);

View file

@ -8,43 +8,18 @@ IPCEvent::IPCEvent(
std::string const& targetModID,
std::string const& messageID,
nlohmann::json const& messageData,
std::string* replyString
nlohmann::json& replyData
) : m_rawPipeHandle(rawPipeHandle),
m_targetModID(targetModID),
m_messageID(messageID),
m_replyString(replyString),
m_messageData(messageData) {}
targetModID(targetModID),
messageID(messageID),
replyData(replyData),
messageData(messageData) {}
IPCEvent::~IPCEvent() {}
std::string IPCEvent::getTargetModID() const {
return m_targetModID;
}
std::string IPCEvent::getMessageID() const {
return m_messageID;
}
std::string IPCEvent::getReplyString() const {
return *m_replyString;
}
void IPCEvent::setReplyString(std::string const& reply) {
*m_replyString = reply;
}
nlohmann::json IPCEvent::getMessageData() const {
return m_messageData;
}
ListenerResult IPCFilter::handle(std::function<Callback> fn, IPCEvent* event) {
if (
event->getTargetModID() == m_modID &&
event->getMessageID() == m_messageID
) {
event->setReplyString(fn(event));
if (event->targetModID == m_modID && event->messageID == m_messageID) {
event->replyData = fn(event);
return ListenerResult::Stop;
}
return ListenerResult::Propagate;

View file

@ -376,16 +376,16 @@ void Index::updateSourceFromLocal(IndexSourceImpl* src) {
}
auto add = addRes.unwrap();
// check if this major version of this item has already been added
if (m_items[add->info.m_id].count(add->info.m_version.getMajor())) {
if (m_items[add->info.id].count(add->info.version.getMajor())) {
log::warn(
"Item {}@{} has already been added, skipping",
add->info.m_id, add->info.m_version
add->info.id, add->info.version
);
continue;
}
// add new major version of this item
m_items[add->info.m_id].insert({
add->info.m_version.getMajor(),
m_items[add->info.id].insert({
add->info.version.getMajor(),
add
});
}
@ -492,7 +492,7 @@ IndexItemHandle Index::getItem(
if (version) {
// prefer most major version
for (auto& [_, item] : ranges::reverse(m_items.at(id))) {
if (version.value() == item->info.m_version) {
if (version.value() == item->info.version) {
return item;
}
}
@ -512,7 +512,7 @@ IndexItemHandle Index::getItem(
if (m_items.count(id)) {
// prefer most major version
for (auto& [_, item] : ranges::reverse(m_items.at(id))) {
if (version.compare(item->info.m_version)) {
if (version.compare(item->info.version)) {
return item;
}
}
@ -521,7 +521,7 @@ IndexItemHandle Index::getItem(
}
IndexItemHandle Index::getItem(ModInfo const& info) const {
return this->getItem(info.m_id, info.m_version);
return this->getItem(info.id, info.version);
}
IndexItemHandle Index::getItem(Mod* mod) const {
@ -529,17 +529,17 @@ IndexItemHandle Index::getItem(Mod* mod) const {
}
bool Index::isUpdateAvailable(IndexItemHandle item) const {
auto installed = Loader::get()->getInstalledMod(item->info.m_id);
auto installed = Loader::get()->getInstalledMod(item->info.id);
if (!installed) {
return false;
}
return item->info.m_version > installed->getVersion();
return item->info.version > installed->getVersion();
}
bool Index::areUpdatesAvailable() const {
for (auto& mod : Loader::get()->getAllMods()) {
auto item = this->getItem(mod);
if (item && item->info.m_version > mod->getVersion()) {
if (item && item->info.version > mod->getVersion()) {
return true;
}
}
@ -551,7 +551,7 @@ bool Index::areUpdatesAvailable() const {
Result<IndexInstallList> Index::getInstallList(IndexItemHandle item) const {
IndexInstallList list;
list.target = item;
for (auto& dep : item->info.m_dependencies) {
for (auto& dep : item->info.dependencies) {
if (!dep.isResolved()) {
// check if this dep is available in the index
if (auto depItem = this->getItem(dep.id, dep.version)) {
@ -573,7 +573,7 @@ Result<IndexInstallList> Index::getInstallList(IndexItemHandle item) const {
"reason is that the version of the dependency this mod "
"depends on is not available. Please let the the developer "
"({}) of the mod know!",
dep.id, dep.version.toString(), item->info.m_developer
dep.id, dep.version.toString(), item->info.developer
);
}
}
@ -588,7 +588,7 @@ Result<IndexInstallList> Index::getInstallList(IndexItemHandle item) const {
void Index::installNext(size_t index, IndexInstallList const& list) {
auto postError = [this, list](std::string const& error) {
m_runningInstallations.erase(list.target);
ModInstallEvent(list.target->info.m_id, error).post();
ModInstallEvent(list.target->info.id, error).post();
};
// If we're at the end of the list, move the downloaded items to mods
@ -597,12 +597,12 @@ void Index::installNext(size_t index, IndexInstallList const& list) {
// Move all downloaded files
for (auto& item : list.list) {
// If the mod is already installed, delete the old .geode file
if (auto mod = Loader::get()->getInstalledMod(item->info.m_id)) {
if (auto mod = Loader::get()->getInstalledMod(item->info.id)) {
auto res = mod->uninstall();
if (!res) {
return postError(fmt::format(
"Unable to uninstall old version of {}: {}",
item->info.m_id, res.unwrapErr()
item->info.id, res.unwrapErr()
));
}
}
@ -610,13 +610,13 @@ void Index::installNext(size_t index, IndexInstallList const& list) {
// Move the temp file
try {
ghc::filesystem::rename(
dirs::getTempDir() / (item->info.m_id + ".index"),
dirs::getModsDir() / (item->info.m_id + ".geode")
dirs::getTempDir() / (item->info.id + ".index"),
dirs::getModsDir() / (item->info.id + ".geode")
);
} catch(std::exception& e) {
return postError(fmt::format(
"Unable to install {}: {}",
item->info.m_id, e.what()
item->info.id, e.what()
));
}
}
@ -624,7 +624,7 @@ void Index::installNext(size_t index, IndexInstallList const& list) {
// load mods
(void)Loader::get()->refreshModsList();
ModInstallEvent(list.target->info.m_id, UpdateFinished()).post();
ModInstallEvent(list.target->info.id, UpdateFinished()).post();
return;
}
@ -635,9 +635,9 @@ void Index::installNext(size_t index, IndexInstallList const& list) {
};
auto item = list.list.at(index);
auto tempFile = dirs::getTempDir() / (item->info.m_id + ".index");
auto tempFile = dirs::getTempDir() / (item->info.id + ".index");
m_runningInstallations[list.target] = web::AsyncWebRequest()
.join("install_item_" + item->info.m_id)
.join("install_item_" + item->info.id)
.fetch(item->download.url)
.into(tempFile)
.then([=](auto) {
@ -647,16 +647,16 @@ void Index::installNext(size_t index, IndexInstallList const& list) {
return postError(fmt::format(
"Binary file download for {} returned \"404 Not found\". "
"Report this to the Geode development team.",
item->info.m_id
item->info.id
));
}
// Verify checksum
ModInstallEvent(
list.target->info.m_id,
list.target->info.id,
UpdateProgress(
scaledProgress(100),
fmt::format("Verifying {}", item->info.m_id)
fmt::format("Verifying {}", item->info.id)
)
).post();
@ -665,7 +665,7 @@ void Index::installNext(size_t index, IndexInstallList const& list) {
"Checksum mismatch with {}! (Downloaded file did not match what "
"was expected. Try again, and if the download fails another time, "
"report this to the Geode development team.)",
item->info.m_id
item->info.id
));
}
@ -675,15 +675,15 @@ void Index::installNext(size_t index, IndexInstallList const& list) {
.expect([postError, list, item](std::string const& err) {
postError(fmt::format(
"Unable to download {}: {}",
item->info.m_id, err
item->info.id, err
));
})
.progress([this, item, list, scaledProgress](auto&, double now, double total) {
ModInstallEvent(
list.target->info.m_id,
list.target->info.id,
UpdateProgress(
scaledProgress(now / total * 100.0),
fmt::format("Downloading {}", item->info.m_id)
fmt::format("Downloading {}", item->info.id)
)
).post();
})
@ -718,7 +718,7 @@ void Index::install(IndexItemHandle item) {
this->install(list.unwrap());
} else {
ModInstallEvent(
item->info.m_id,
item->info.id,
UpdateFailed(list.unwrapErr())
).post();
}

View file

@ -126,15 +126,15 @@ Result<> Loader::setup() {
}
Result<Mod*> Loader::loadModFromInfo(ModInfo const& info) {
if (m_mods.count(info.m_id)) {
return Err(fmt::format("Mod with ID '{}' already loaded", info.m_id));
if (m_mods.count(info.id)) {
return Err(fmt::format("Mod with ID '{}' already loaded", info.id));
}
// create Mod instance
auto mod = new Mod(info);
m_mods.insert({ info.m_id, mod });
m_mods.insert({ info.id, mod });
mod->m_enabled = InternalMod::get()->getSavedValue<bool>(
"should-load-" + info.m_id, true
"should-load-" + info.id, true
);
// this loads the mod if its dependencies are resolved
GEODE_UNWRAP(mod->updateDependencies());
@ -154,8 +154,8 @@ Result<Mod*> Loader::loadModFromFile(ghc::filesystem::path const& file) {
auto res = ModInfo::createFromGeodeFile(file);
if (!res) {
m_invalidMods.push_back(InvalidGeodeFile {
.m_path = file,
.m_reason = res.unwrapErr(),
.path = file,
.reason = res.unwrapErr(),
});
return Err(res.unwrapErr());
}
@ -185,7 +185,7 @@ Result<> Loader::loadModsFromDirectory(
}
// skip this entry if it's already loaded
if (map::contains<std::string, Mod*>(m_mods, [entry](Mod* p) -> bool {
return p->m_info.m_path == entry.path();
return p->m_info.path == entry.path();
})) {
continue;
}
@ -201,8 +201,8 @@ Result<> Loader::loadModsFromDirectory(
auto res = ModInfo::createFromGeodeFile(entry.path());
if (!res) {
m_invalidMods.push_back(InvalidGeodeFile {
.m_path = entry.path(),
.m_reason = res.unwrapErr(),
.path = entry.path(),
.reason = res.unwrapErr(),
});
continue;
}
@ -230,7 +230,7 @@ Result<> Loader::refreshModsList() {
// load early-load mods first
for (auto& mod : m_modsToLoad) {
if (mod.m_needsEarlyLoad) {
if (mod.needsEarlyLoad) {
GEODE_UNWRAP(this->loadModFromInfo(mod));
}
}
@ -240,7 +240,7 @@ Result<> Loader::refreshModsList() {
// load the rest of the mods
for (auto& mod : m_modsToLoad) {
if (!mod.m_needsEarlyLoad) {
if (!mod.needsEarlyLoad) {
GEODE_UNWRAP(this->loadModFromInfo(mod));
}
}
@ -329,7 +329,7 @@ void Loader::closePlatfromConsole() {
}
void Loader::updateModResources(Mod* mod) {
if (!mod->m_info.m_spritesheets.size()) {
if (!mod->m_info.spritesheets.size()) {
return;
}
@ -338,7 +338,7 @@ void Loader::updateModResources(Mod* mod) {
log::debug("Adding resources for {}", mod->getID());
// add spritesheets
for (auto const& sheet : mod->m_info.m_spritesheets) {
for (auto const& sheet : mod->m_info.spritesheets) {
log::debug("Adding sheet {}", sheet);
auto png = sheet + ".png";
auto plist = sheet + ".plist";
@ -348,7 +348,7 @@ void Loader::updateModResources(Mod* mod) {
plist == std::string(ccfu->fullPathForFilename(plist.c_str(), false))) {
log::warn(
"The resource dir of \"{}\" is missing \"{}\" png and/or plist files",
mod->m_info.m_id, sheet
mod->m_info.id, sheet
);
}
else {

View file

@ -14,7 +14,7 @@ USE_GEODE_NAMESPACE();
Mod::Mod(ModInfo const& info) {
m_info = info;
m_saveDirPath = dirs::getModsSaveDir() / info.m_id;
m_saveDirPath = dirs::getModsSaveDir() / info.id;
ghc::filesystem::create_directories(m_saveDirPath);
}
@ -29,23 +29,23 @@ ghc::filesystem::path Mod::getSaveDir() const {
}
std::string Mod::getID() const {
return m_info.m_id;
return m_info.id;
}
std::string Mod::getName() const {
return m_info.m_name;
return m_info.name;
}
std::string Mod::getDeveloper() const {
return m_info.m_developer;
return m_info.developer;
}
std::optional<std::string> Mod::getDescription() const {
return m_info.m_description;
return m_info.description;
}
std::optional<std::string> Mod::getDetails() const {
return m_info.m_details;
return m_info.details;
}
ModInfo Mod::getModInfo() const {
@ -57,15 +57,15 @@ ghc::filesystem::path Mod::getTempDir() const {
}
ghc::filesystem::path Mod::getBinaryPath() const {
return m_tempDirName / m_info.m_binaryName;
return m_tempDirName / m_info.binaryName;
}
ghc::filesystem::path Mod::getPackagePath() const {
return m_info.m_path;
return m_info.path;
}
VersionInfo Mod::getVersion() const {
return m_info.m_version;
return m_info.version;
}
bool Mod::isEnabled() const {
@ -77,11 +77,11 @@ bool Mod::isLoaded() const {
}
bool Mod::supportsDisabling() const {
return m_info.m_supportsDisabling;
return m_info.supportsDisabling;
}
bool Mod::supportsUnloading() const {
return m_info.m_supportsUnloading;
return m_info.supportsUnloading;
}
bool Mod::wasSuccesfullyLoaded() const {
@ -93,11 +93,11 @@ std::vector<Hook*> Mod::getHooks() const {
}
bool Mod::hasSettings() const {
return m_info.m_settings.size();
return m_info.settings.size();
}
decltype(ModInfo::m_settings) Mod::getSettings() const {
return m_info.m_settings;
decltype(ModInfo::settings) Mod::getSettings() const {
return m_info.settings;
}
// Settings and saved values
@ -159,7 +159,7 @@ Result<> Mod::saveData() {
// Settings
auto json = nlohmann::json::object();
for (auto& [key, value] : m_info.m_settings) {
for (auto& [key, value] : m_info.settings) {
if (!value->save(json[key])) return Err("Unable to save setting \"" + key + "\"");
}
@ -172,7 +172,7 @@ Result<> Mod::saveData() {
}
std::shared_ptr<Setting> Mod::getSetting(std::string const& key) const {
for (auto& setting : m_info.m_settings) {
for (auto& setting : m_info.settings) {
if (setting.first == key) {
return setting.second;
}
@ -181,7 +181,7 @@ std::shared_ptr<Setting> Mod::getSetting(std::string const& key) const {
}
bool Mod::hasSetting(std::string const& key) const {
for (auto& setting : m_info.m_settings) {
for (auto& setting : m_info.settings) {
if (setting.first == key) {
return true;
}
@ -212,7 +212,7 @@ Result<> Mod::loadBinary() {
auto loadRes = this->loadData();
if (!loadRes) {
log::warn("Unable to load data for \"{}\": {}", m_info.m_id, loadRes.unwrapErr());
log::warn("Unable to load data for \"{}\": {}", m_info.id, loadRes.unwrapErr());
}
Loader::get()->updateAllDependencies();
@ -227,7 +227,7 @@ Result<> Mod::unloadBinary() {
return Ok();
}
if (!m_info.m_supportsUnloading) {
if (!m_info.supportsUnloading) {
return Err("Mod does not support unloading");
}
@ -280,7 +280,7 @@ Result<> Mod::disable() {
if (!m_enabled) {
return Ok();
}
if (!m_info.m_supportsDisabling) {
if (!m_info.supportsDisabling) {
return Err("Mod does not support disabling");
}
@ -301,15 +301,15 @@ Result<> Mod::disable() {
}
Result<> Mod::uninstall() {
if (m_info.m_supportsDisabling) {
if (m_info.supportsDisabling) {
GEODE_UNWRAP(this->disable());
if (m_info.m_supportsUnloading) {
if (m_info.supportsUnloading) {
GEODE_UNWRAP(this->unloadBinary());
}
}
try {
ghc::filesystem::remove(m_info.m_path);
ghc::filesystem::remove(m_info.path);
} catch(std::exception& e) {
return Err(
"Unable to delete mod's .geode file! "
@ -322,14 +322,14 @@ Result<> Mod::uninstall() {
}
bool Mod::isUninstalled() const {
return this != InternalMod::get() && !ghc::filesystem::exists(m_info.m_path);
return this != InternalMod::get() && !ghc::filesystem::exists(m_info.path);
}
// Dependencies
Result<> Mod::updateDependencies() {
bool hasUnresolved = false;
for (auto& dep : m_info.m_dependencies) {
for (auto& dep : m_info.dependencies) {
// set the dependency's loaded mod if such exists
if (!dep.mod) {
dep.mod = Loader::get()->getLoadedMod(dep.id);
@ -363,20 +363,20 @@ Result<> Mod::updateDependencies() {
}
// load if there weren't any unresolved dependencies
if (!hasUnresolved) {
log::debug("All dependencies for {} found", m_info.m_id);
log::debug("All dependencies for {} found", m_info.id);
if (m_enabled) {
log::debug("Resolved & loading {}", m_info.m_id);
log::debug("Resolved & loading {}", m_info.id);
GEODE_UNWRAP(this->loadBinary());
}
else {
log::debug("Resolved {}, however not loading it as it is disabled", m_info.m_id);
log::debug("Resolved {}, however not loading it as it is disabled", m_info.id);
}
}
return Ok();
}
bool Mod::hasUnresolvedDependencies() const {
for (auto const& dep : m_info.m_dependencies) {
for (auto const& dep : m_info.dependencies) {
if (!dep.isResolved()) {
return true;
}
@ -386,7 +386,7 @@ bool Mod::hasUnresolvedDependencies() const {
std::vector<Dependency> Mod::getUnresolvedDependencies() {
std::vector<Dependency> unresolved;
for (auto const& dep : m_info.m_dependencies) {
for (auto const& dep : m_info.dependencies) {
if (!dep.isResolved()) {
unresolved.push_back(dep);
}
@ -396,7 +396,7 @@ std::vector<Dependency> Mod::getUnresolvedDependencies() {
bool Mod::depends(std::string const& id) const {
return utils::ranges::contains(
m_info.m_dependencies,
m_info.dependencies,
[id](Dependency const& t) {
return t.id == id;
}
@ -488,16 +488,16 @@ Result<> Mod::createTempDir() {
}
// Create geode/temp/mod.id
auto tempPath = tempDir / m_info.m_id;
auto tempPath = tempDir / m_info.id;
if (!file::createDirectoryAll(tempPath)) {
return Err("Unable to create mod runtime directory");
}
// Unzip .geode file into temp dir
GEODE_UNWRAP_INTO(auto unzip, file::Unzip::create(m_info.m_path));
if (!unzip.hasEntry(m_info.m_binaryName)) {
GEODE_UNWRAP_INTO(auto unzip, file::Unzip::create(m_info.path));
if (!unzip.hasEntry(m_info.binaryName)) {
return Err(fmt::format(
"Unable to find platform binary under the name \"{}\"", m_info.m_binaryName
"Unable to find platform binary under the name \"{}\"", m_info.binaryName
));
}
GEODE_UNWRAP(unzip.extractAllTo(tempPath));
@ -509,19 +509,19 @@ Result<> Mod::createTempDir() {
}
ghc::filesystem::path Mod::getConfigDir(bool create) const {
auto dir = dirs::getModConfigDir() / m_info.m_id;
auto dir = dirs::getModConfigDir() / m_info.id;
if (create) {
(void)file::createDirectoryAll(dir);
}
return dir;
}
char const* Mod::expandSpriteName(char const* name) {
static std::unordered_map<std::string, char const*> expanded = {};
const char* Mod::expandSpriteName(const char* name) {
static std::unordered_map<std::string, const char*> expanded = {};
if (expanded.count(name)) return expanded[name];
auto exp = new char[strlen(name) + 2 + m_info.m_id.size()];
auto exps = m_info.m_id + "/" + name;
auto exp = new char[strlen(name) + 2 + m_info.id.size()];
auto exps = m_info.id + "/" + name;
memcpy(exp, exps.c_str(), exps.size() + 1);
expanded[name] = exp;

View file

@ -47,15 +47,15 @@ Result<ModInfo> ModInfo::createFromSchemaV010(ModJson const& rawJson) {
using nlohmann::detail::value_t;
root.needs("id").validate(&ModInfo::validateID).into(info.m_id);
root.needs("version").validate(&VersionInfo::validate).into(info.m_version);
root.needs("name").into(info.m_name);
root.needs("developer").into(info.m_developer);
root.has("description").into(info.m_description);
root.has("repository").into(info.m_repository);
root.has("toggleable").into(info.m_supportsDisabling);
root.has("unloadable").into(info.m_supportsUnloading);
root.has("early-load").into(info.m_needsEarlyLoad);
root.needs("id").validate(&ModInfo::validateID).into(info.id);
root.needs("version").validate(&VersionInfo::validate).into(info.version);
root.needs("name").into(info.name);
root.needs("developer").into(info.developer);
root.has("description").into(info.description);
root.has("repository").into(info.repository);
root.has("toggleable").into(info.supportsDisabling);
root.has("unloadable").into(info.supportsUnloading);
root.has("early-load").into(info.needsEarlyLoad);
for (auto& dep : root.has("dependencies").iterate()) {
auto obj = dep.obj();
@ -68,30 +68,30 @@ Result<ModInfo> ModInfo::createFromSchemaV010(ModJson const& rawJson) {
obj.has("required").into(depobj.required);
obj.checkUnknownKeys();
info.m_dependencies.push_back(depobj);
info.dependencies.push_back(depobj);
}
for (auto& [key, value] : root.has("settings").items()) {
GEODE_UNWRAP_INTO(auto sett, Setting::parse(key, value.json()));
sett->m_modID = info.m_id;
info.m_settings.push_back({ key, sett });
sett->m_modID = info.id;
info.settings.push_back({ key, sett });
}
if (auto resources = root.has("resources").obj()) {
for (auto& [key, _] : resources.has("spritesheets").items()) {
info.m_spritesheets.push_back(info.m_id + "/" + key);
info.spritesheets.push_back(info.id + "/" + key);
}
}
if (auto issues = root.has("issues").obj()) {
IssuesInfo issuesInfo;
issues.needs("info").into(issuesInfo.m_info);
issues.has("url").intoAs<std::string>(issuesInfo.m_url);
info.m_issues = issuesInfo;
issues.needs("info").into(issuesInfo.info);
issues.has("url").intoAs<std::string>(issuesInfo.url);
info.issues = issuesInfo;
}
// with new cli, binary name is always mod id
info.m_binaryName = info.m_id + GEODE_PLATFORM_EXTENSION;
info.binaryName = info.id + GEODE_PLATFORM_EXTENSION;
// removed keys
if (root.has("datastore")) {
@ -171,7 +171,7 @@ Result<ModInfo> ModInfo::createFromFile(ghc::filesystem::path const& path) {
GEODE_UNWRAP_INTO(auto read, utils::file::readString(path));
try {
GEODE_UNWRAP_INTO(auto info, ModInfo::create(ModJson::parse(read)));
info.m_path = path;
info.path = path;
if (path.has_parent_path()) {
GEODE_UNWRAP(info.addSpecialFiles(path.parent_path()));
}
@ -211,7 +211,7 @@ Result<ModInfo> ModInfo::createFromGeodeZip(file::Unzip& unzip) {
return Err("\"" + unzip.getPath().string() + "\" - " + res.unwrapErr());
}
auto info = res.unwrap();
info.m_path = unzip.getPath();
info.path = unzip.getPath();
GEODE_UNWRAP(
info.addSpecialFiles(unzip)
@ -250,16 +250,16 @@ Result<> ModInfo::addSpecialFiles(ghc::filesystem::path const& dir) {
std::vector<std::pair<std::string, std::optional<std::string>*>> ModInfo::getSpecialFiles() {
return {
{ "about.md", &m_details },
{ "changelog.md", &m_changelog },
{ "support.md", &m_supportInfo },
{ "about.md", &this->details },
{ "changelog.md", &this->changelog },
{ "support.md", &this->supportInfo },
};
}
ModJson ModInfo::toJSON() const {
auto json = m_rawJSON;
json["path"] = m_path;
json["binary"] = m_binaryName;
json["path"] = this->path;
json["binary"] = this->binaryName;
return json;
}
@ -268,7 +268,7 @@ ModJson ModInfo::getRawJSON() const {
}
bool ModInfo::operator==(ModInfo const& other) const {
return m_id == other.m_id;
return this->id == other.id;
}
void geode::to_json(nlohmann::json& json, ModInfo const& info) {

View file

@ -17,7 +17,7 @@ T findSymbolOrMangled(void* dylib, char const* name, char const* mangled) {
Result<> Mod::loadPlatformBinary() {
auto dylib =
dlopen((this->m_tempDirName / this->m_info.m_binaryName).string().c_str(), RTLD_LAZY);
dlopen((this->m_tempDirName / this->m_info.binaryName).string().c_str(), RTLD_LAZY);
if (dylib) {
this->m_implicitLoadFunc =
findSymbolOrMangled<geode_load>(dylib, "geode_implicit_load", "_geode_implicit_load");

View file

@ -18,7 +18,7 @@ T findSymbolOrMangled(void* dylib, char const* name, char const* mangled) {
Result<> Mod::loadPlatformBinary() {
auto dylib =
dlopen((this->m_tempDirName / this->m_info.m_binaryName).string().c_str(), RTLD_LAZY);
dlopen((this->m_tempDirName / this->m_info.binaryName).string().c_str(), RTLD_LAZY);
if (dylib) {
this->m_implicitLoadFunc =
findSymbolOrMangled<decltype(geode_implicit_load)*>(dylib, "geode_implicit_load", "_geode_implicit_load");

View file

@ -43,13 +43,11 @@ void ipcPipeThread(HANDLE pipe) {
char buffer[IPC_BUFFER_SIZE * sizeof(TCHAR)];
DWORD read;
std::optional<std::string> replyID = std::nullopt;
// log::debug("Waiting for I/O");
if (ReadFile(pipe, buffer, sizeof(buffer) - 1, &read, nullptr)) {
buffer[read] = '\0';
std::string reply = InternalLoader::processRawIPC((void*)pipe, buffer);
auto reply = InternalLoader::processRawIPC((void*)pipe, buffer).dump();
DWORD written;
WriteFile(pipe, reply.c_str(), reply.size(), &written, nullptr);

View file

@ -72,7 +72,7 @@ std::string getLastWinError() {
}
Result<> Mod::loadPlatformBinary() {
auto load = LoadLibraryW((m_tempDirName / m_info.m_binaryName).wstring().c_str());
auto load = LoadLibraryW((m_tempDirName / m_info.binaryName).wstring().c_str());
if (load) {
if (!(m_implicitLoadFunc = findSymbolOrMangled<decltype(geode_implicit_load)*>(
load, "geode_implicit_load", "_geode_implicit_load@4"

View file

@ -13,19 +13,19 @@ void geode::openModsList() {
}
void geode::openIssueReportPopup(Mod* mod) {
if (mod->getModInfo().m_issues) {
if (mod->getModInfo().issues) {
MDPopup::create(
"Issue Report",
mod->getModInfo().m_issues.value().m_info +
mod->getModInfo().issues.value().info +
"\n\n"
"If your issue relates to a <cr>game crash</c>, <cb>please include</c> the "
"latest crash log(s) from `" +
dirs::getCrashlogsDir().string() + "`",
"OK", (mod->getModInfo().m_issues.value().m_url ? "Open URL" : ""),
"OK", (mod->getModInfo().issues.value().url ? "Open URL" : ""),
[mod](bool btn2) {
if (btn2) {
web::openLinkInBrowser(
mod->getModInfo().m_issues.value().m_url.value()
mod->getModInfo().issues.value().url.value()
);
}
}

View file

@ -52,7 +52,7 @@ bool ModInfoPopup::init(ModInfo const& info, ModListLayer* list) {
constexpr float logoSize = 40.f;
constexpr float logoOffset = 10.f;
auto nameLabel = CCLabelBMFont::create(info.m_name.c_str(), "bigFont.fnt");
auto nameLabel = CCLabelBMFont::create(info.name.c_str(), "bigFont.fnt");
nameLabel->setAnchorPoint({ .0f, .5f });
nameLabel->limitLabelWidth(200.f, .7f, .1f);
m_mainLayer->addChild(nameLabel, 2);
@ -60,7 +60,7 @@ bool ModInfoPopup::init(ModInfo const& info, ModListLayer* list) {
auto logoSpr = this->createLogo({ logoSize, logoSize });
m_mainLayer->addChild(logoSpr);
auto developerStr = "by " + info.m_developer;
auto developerStr = "by " + info.developer;
auto developerLabel = CCLabelBMFont::create(developerStr.c_str(), "goldFont.fnt");
developerLabel->setScale(.5f);
developerLabel->setAnchorPoint({ .0f, .5f });
@ -87,7 +87,7 @@ bool ModInfoPopup::init(ModInfo const& info, ModListLayer* list) {
);
auto versionLabel = CCLabelBMFont::create(
info.m_version.toString().c_str(),
info.version.toString().c_str(),
"bigFont.fnt"
);
versionLabel->setAnchorPoint({ .0f, .5f });
@ -103,7 +103,7 @@ bool ModInfoPopup::init(ModInfo const& info, ModListLayer* list) {
this->registerWithTouchDispatcher();
m_detailsArea = MDTextArea::create(
(info.m_details ? info.m_details.value() : "### No description provided."),
(info.details ? info.details.value() : "### No description provided."),
{ 350.f, 137.5f }
);
m_detailsArea->setPosition(
@ -120,8 +120,8 @@ bool ModInfoPopup::init(ModInfo const& info, ModListLayer* list) {
m_mainLayer->addChild(m_scrollbar);
// changelog
if (info.m_changelog) {
m_changelogArea = MDTextArea::create(info.m_changelog.value(), { 350.f, 137.5f });
if (info.changelog) {
m_changelogArea = MDTextArea::create(info.changelog.value(), { 350.f, 137.5f });
m_changelogArea->setPosition(
-5000.f, winSize.height / 2 -
m_changelogArea->getScaledContentSize().height / 2 - 20.f
@ -163,7 +163,7 @@ bool ModInfoPopup::init(ModInfo const& info, ModListLayer* list) {
m_buttonMenu->addChild(m_infoBtn);
// repo button
if (info.m_repository) {
if (info.repository) {
auto repoBtn = CCMenuItemSpriteExtra::create(
CCSprite::createWithSpriteFrameName("github.png"_spr), this,
menu_selector(ModInfoPopup::onRepository)
@ -176,7 +176,7 @@ bool ModInfoPopup::init(ModInfo const& info, ModListLayer* list) {
}
// support button
if (info.m_supportInfo) {
if (info.supportInfo) {
auto supportBtn = CCMenuItemSpriteExtra::create(
CCSprite::createWithSpriteFrameName("gift.png"_spr), this,
menu_selector(ModInfoPopup::onSupport)
@ -208,30 +208,30 @@ bool ModInfoPopup::init(ModInfo const& info, ModListLayer* list) {
void ModInfoPopup::onSupport(CCObject*) {
MDPopup::create(
"Support " + this->getModInfo().m_name,
this->getModInfo().m_supportInfo.value(),
"Support " + this->getModInfo().name,
this->getModInfo().supportInfo.value(),
"OK"
)->show();
}
void ModInfoPopup::onRepository(CCObject*) {
web::openLinkInBrowser(this->getModInfo().m_repository.value());
web::openLinkInBrowser(this->getModInfo().repository.value());
}
void ModInfoPopup::onInfo(CCObject*) {
auto info = this->getModInfo();
FLAlertLayer::create(
nullptr,
("About " + info.m_name).c_str(),
("About " + info.name).c_str(),
fmt::format(
"<cr>ID: {}</c>\n"
"<cg>Version: {}</c>\n"
"<cp>Developer: {}</c>\n"
"<cb>Path: {}</c>\n",
info.m_id,
info.m_version.toString(),
info.m_developer,
info.m_path.string()
info.id,
info.version.toString(),
info.developer,
info.path.string()
),
"OK", nullptr, 400.f
)->show();
@ -391,7 +391,7 @@ bool LocalModInfoPopup::init(Mod* mod, ModListLayer* list) {
m_mainLayer->addChild(m_installStatus);
m_updateVersionLabel = CCLabelBMFont::create(
("Available: " + indexItem->info.m_version.toString()).c_str(),
("Available: " + indexItem->info.version.toString()).c_str(),
"bigFont.fnt"
);
m_updateVersionLabel->setScale(.35f);
@ -405,7 +405,7 @@ bool LocalModInfoPopup::init(Mod* mod, ModListLayer* list) {
}
// issue report button
if (mod->getModInfo().m_issues) {
if (mod->getModInfo().issues) {
auto issuesBtnSpr = ButtonSprite::create(
"Report an Issue", "goldFont.fnt", "GJ_button_04.png", .8f
);
@ -569,7 +569,7 @@ IndexItemInfoPopup::IndexItemInfoPopup()
bool IndexItemInfoPopup::init(IndexItemHandle item, ModListLayer* list) {
m_item = item;
m_installListener.setFilter(m_item->info.m_id);
m_installListener.setFilter(m_item->info.id);
auto winSize = CCDirector::sharedDirector()->getWinSize();
@ -658,7 +658,7 @@ void IndexItemInfoPopup::onInstall(CCObject*) {
[](IndexItemHandle handle) {
return fmt::format(
" - <cr>{}</c> (<cy>{}</c>)",
handle->info.m_name, handle->info.m_id
handle->info.name, handle->info.id
);
}
),

View file

@ -39,9 +39,9 @@ void ModListCell::setupInfo(ModInfo const& info, bool spaceForTags) {
bool hasDesc =
m_layer->getDisplay() == ModListDisplay::Expanded &&
info.m_description.has_value();
info.description.has_value();
auto titleLabel = CCLabelBMFont::create(info.m_name.c_str(), "bigFont.fnt");
auto titleLabel = CCLabelBMFont::create(info.name.c_str(), "bigFont.fnt");
titleLabel->setAnchorPoint({ .0f, .5f });
titleLabel->setPositionX(m_height / 2 + logoSize / 2 + 13.f);
if (hasDesc && spaceForTags) {
@ -59,7 +59,7 @@ void ModListCell::setupInfo(ModInfo const& info, bool spaceForTags) {
titleLabel->limitLabelWidth(m_width / 2 - 40.f, .5f, .1f);
this->addChild(titleLabel);
auto versionLabel = CCLabelBMFont::create(info.m_version.toString().c_str(), "bigFont.fnt");
auto versionLabel = CCLabelBMFont::create(info.version.toString().c_str(), "bigFont.fnt");
versionLabel->setAnchorPoint({ .0f, .5f });
versionLabel->setScale(.3f);
versionLabel->setPosition(
@ -69,7 +69,7 @@ void ModListCell::setupInfo(ModInfo const& info, bool spaceForTags) {
versionLabel->setColor({ 0, 255, 0 });
this->addChild(versionLabel);
auto creatorStr = "by " + info.m_developer;
auto creatorStr = "by " + info.developer;
auto creatorLabel = CCLabelBMFont::create(creatorStr.c_str(), "goldFont.fnt");
creatorLabel->setAnchorPoint({ .0f, .5f });
creatorLabel->setScale(.43f);
@ -101,7 +101,7 @@ void ModListCell::setupInfo(ModInfo const& info, bool spaceForTags) {
descBG->setScale(.25f);
this->addChild(descBG);
m_description = CCLabelBMFont::create(info.m_description.value().c_str(), "chatFont.fnt");
m_description = CCLabelBMFont::create(info.description.value().c_str(), "chatFont.fnt");
m_description->setAnchorPoint({ .0f, .5f });
m_description->setPosition(m_height / 2 + logoSize / 2 + 18.f, descBG->getPositionY());
m_description->limitLabelWidth(m_width / 2 - 10.f, .5f, .1f);
@ -324,7 +324,7 @@ CCNode* IndexItemCell::createLogo(CCSize const& size) {
void InvalidGeodeFileCell::onInfo(CCObject*) {
FLAlertLayer::create(
this, "Error Info",
m_info.m_reason,
m_info.reason,
"OK", "Remove file", 360.f
)->show();
}
@ -332,22 +332,22 @@ void InvalidGeodeFileCell::onInfo(CCObject*) {
void InvalidGeodeFileCell::FLAlert_Clicked(FLAlertLayer*, bool btn2) {
if (btn2) {
try {
if (ghc::filesystem::remove(m_info.m_path)) {
if (ghc::filesystem::remove(m_info.path)) {
FLAlertLayer::create(
"File removed", "Removed <cy>" + m_info.m_path.string() + "</c>", "OK"
"File removed", "Removed <cy>" + m_info.path.string() + "</c>", "OK"
)->show();
}
else {
FLAlertLayer::create(
"Unable to remove file",
"Unable to remove <cy>" + m_info.m_path.string() + "</c>", "OK"
"Unable to remove <cy>" + m_info.path.string() + "</c>", "OK"
)->show();
}
}
catch (std::exception& e) {
FLAlertLayer::create(
"Unable to remove file",
"Unable to remove <cy>" + m_info.m_path.string() + "</c>: <cr>" +
"Unable to remove <cy>" + m_info.path.string() + "</c>: <cr>" +
std::string(e.what()) + "</c>",
"OK"
)->show();
@ -378,7 +378,7 @@ bool InvalidGeodeFileCell::init(
this->addChild(titleLabel);
auto pathLabel = CCLabelBMFont::create(
m_info.m_path.string().c_str(),
m_info.path.string().c_str(),
"chatFont.fnt"
);
pathLabel->setAnchorPoint({ .0f, .5f });