mirror of
https://github.com/geode-sdk/geode.git
synced 2025-03-28 13:52:07 -04:00
fix paths not properly being removed due to trailing /, and other logic errors
This commit is contained in:
parent
3313a4461d
commit
aeaf7f7b88
3 changed files with 18 additions and 20 deletions
loader/src
|
@ -8,7 +8,6 @@ using namespace geode::prelude;
|
|||
static std::vector<CCTexturePack> REMOVED_PACKS;
|
||||
static std::vector<CCTexturePack> PACKS;
|
||||
static std::vector<std::string> PATHS;
|
||||
static bool DONT_ADD_PATHS = false;
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4273)
|
||||
|
@ -31,13 +30,13 @@ void CCFileUtils::addTexturePack(CCTexturePack const& pack) {
|
|||
|
||||
void CCFileUtils::removeTexturePack(std::string const& id) {
|
||||
std::optional<CCTexturePack> pack = getTexturePack(id);
|
||||
if(pack.has_value()) {
|
||||
if (pack.has_value()) {
|
||||
REMOVED_PACKS.push_back(pack.value());
|
||||
ranges::remove(PACKS, [id](CCTexturePack const& pack) {
|
||||
return pack.m_id == id;
|
||||
});
|
||||
this->updatePaths();
|
||||
}
|
||||
ranges::remove(PACKS, [id](CCTexturePack const& pack) {
|
||||
return pack.m_id == id;
|
||||
});
|
||||
this->updatePaths();
|
||||
}
|
||||
|
||||
void CCFileUtils::addPriorityPath(char const* path) {
|
||||
|
@ -45,31 +44,38 @@ void CCFileUtils::addPriorityPath(char const* path) {
|
|||
this->updatePaths();
|
||||
}
|
||||
|
||||
// cocos adds a trailing / to paths, so we need to check for that
|
||||
bool isPathEqual(std::filesystem::path const& cocosPath, std::filesystem::path const& ourPath) {
|
||||
return cocosPath == ourPath || (cocosPath == (ourPath / ""));
|
||||
}
|
||||
|
||||
void CCFileUtils::updatePaths() {
|
||||
// add search paths that aren't in PATHS or PACKS to PATHS
|
||||
for (auto& path : m_searchPathArray) {
|
||||
std::filesystem::path const cocosPath = path;
|
||||
bool isKnown = false;
|
||||
for (auto& pack : PACKS) {
|
||||
for (auto& packPath : pack.m_paths) {
|
||||
if (std::filesystem::path(path.c_str()) == packPath) {
|
||||
if (isPathEqual(cocosPath, packPath)) {
|
||||
isKnown = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isKnown) break;
|
||||
}
|
||||
if (isKnown) continue;
|
||||
for (auto& pack : REMOVED_PACKS) {
|
||||
for (auto& packPath : pack.m_paths) {
|
||||
if (std::filesystem::path(path.c_str()) == packPath) {
|
||||
if (isPathEqual(cocosPath, packPath)) {
|
||||
isKnown = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isKnown) break;
|
||||
}
|
||||
if (isKnown) break;
|
||||
if (isKnown) continue;
|
||||
for (auto& p : PATHS) {
|
||||
if (std::filesystem::path(path.c_str()) == p) {
|
||||
if (isPathEqual(cocosPath, p)) {
|
||||
isKnown = true;
|
||||
break;
|
||||
}
|
||||
|
@ -83,9 +89,6 @@ void CCFileUtils::updatePaths() {
|
|||
REMOVED_PACKS.clear();
|
||||
m_searchPathArray.clear();
|
||||
|
||||
// make sure addSearchPath doesn't add to PACKS or PATHS
|
||||
DONT_ADD_PATHS = true;
|
||||
|
||||
// add texture packs first
|
||||
for (auto& pack : PACKS) {
|
||||
for (auto& path : pack.m_paths) {
|
||||
|
@ -96,7 +99,6 @@ void CCFileUtils::updatePaths() {
|
|||
for (auto& path : PATHS) {
|
||||
this->addSearchPath(path.c_str());
|
||||
}
|
||||
DONT_ADD_PATHS = false;
|
||||
}
|
||||
|
||||
#pragma warning(pop)
|
||||
|
|
|
@ -215,11 +215,7 @@ Mod* Loader::Impl::getLoadedMod(std::string const& id) const {
|
|||
}
|
||||
|
||||
void Loader::Impl::updateModResources(Mod* mod) {
|
||||
if (mod != Mod::get()) {
|
||||
// geode.loader resource is stored somewhere else, which is already added anyway
|
||||
auto searchPathRoot = dirs::getModRuntimeDir() / mod->getID() / "resources";
|
||||
CCFileUtils::get()->addSearchPath(searchPathRoot.string().c_str());
|
||||
}
|
||||
// search path is added in Mod::Impl::setup
|
||||
|
||||
// only thing needs previous setup is spritesheets
|
||||
if (mod->getMetadata().getSpritesheets().empty())
|
||||
|
|
|
@ -58,7 +58,7 @@ Result<> Mod::Impl::setup() {
|
|||
if (!loadRes) {
|
||||
log::warn("Unable to load data for \"{}\": {}", m_metadata.getID(), loadRes.unwrapErr());
|
||||
}
|
||||
if (!m_resourcesLoaded) {
|
||||
if (!m_resourcesLoaded && !this->isInternal()) {
|
||||
auto searchPathRoot = dirs::getModRuntimeDir() / m_metadata.getID() / "resources";
|
||||
|
||||
// Hi, linux bros!
|
||||
|
|
Loading…
Add table
Reference in a new issue