remove file::current_path, add less and more version compares

This commit is contained in:
altalk23 2023-05-01 16:06:06 +03:00
parent 866401b994
commit 1323debea7
9 changed files with 40 additions and 26 deletions

View file

@ -11,6 +11,8 @@ namespace geode {
LessEq, LessEq,
Exact, Exact,
MoreEq, MoreEq,
Less,
More,
}; };
/** /**
@ -206,7 +208,11 @@ namespace geode {
return version <= m_version; return version <= m_version;
case VersionCompare::MoreEq: case VersionCompare::MoreEq:
return version >= m_version; return version >= m_version;
default: case VersionCompare::Less:
return version < m_version;
case VersionCompare::More:
return version > m_version;
case VersionCompare::Exact:
return version == m_version; return version == m_version;
} }
} }

View file

@ -60,8 +60,6 @@ namespace geode::utils::file {
ghc::filesystem::path const& path, bool recursive = false ghc::filesystem::path const& path, bool recursive = false
); );
GEODE_DLL ghc::filesystem::path current_path();
class Unzip; class Unzip;
class GEODE_DLL Zip final { class GEODE_DLL Zip final {

View file

@ -18,10 +18,6 @@ namespace {
} }
} }
ghc::filesystem::path dirs::getGameDir() {
return utils::file::current_path();
}
ghc::filesystem::path dirs::getSaveDir() { ghc::filesystem::path dirs::getSaveDir() {
#ifdef GEODE_IS_MACOS #ifdef GEODE_IS_MACOS
// not using ~/Library/Caches // not using ~/Library/Caches
@ -32,11 +28,7 @@ ghc::filesystem::path dirs::getSaveDir() {
} }
ghc::filesystem::path dirs::getGeodeDir() { ghc::filesystem::path dirs::getGeodeDir() {
#ifdef GEODE_IS_MACOS
return utils::file::current_path() / "geode";
#else
return dirs::getGameDir() / "geode"; return dirs::getGameDir() / "geode";
#endif
} }
ghc::filesystem::path dirs::getGeodeSaveDir() { ghc::filesystem::path dirs::getGeodeSaveDir() {

View file

@ -31,7 +31,7 @@ void dynamicEntry() {
auto dylib = dlopen("GeodeBootstrapper.dylib", RTLD_NOLOAD); auto dylib = dlopen("GeodeBootstrapper.dylib", RTLD_NOLOAD);
dlclose(dylib); dlclose(dylib);
auto workingDir = utils::file::current_path(); auto workingDir = dirs::getGameDir();
auto libDir = workingDir / "Frameworks"; auto libDir = workingDir / "Frameworks";
auto updatesDir = workingDir / "geode" / "update"; auto updatesDir = workingDir / "geode" / "update";
@ -66,7 +66,7 @@ DWORD WINAPI loadThread(void* arg) {
} }
if (canMoveBootstrapper) { if (canMoveBootstrapper) {
auto workingDir = utils::file::current_path(); auto workingDir = dirs::getGameDir();
auto updatesDir = workingDir / "geode" / "update"; auto updatesDir = workingDir / "geode" / "update";
auto error = std::error_code(); auto error = std::error_code();

View file

@ -4,11 +4,11 @@
#ifdef GEODE_IS_IOS #ifdef GEODE_IS_IOS
using namespace geode::prelude; using namespace geode::prelude;
#include <Geode/loader/Dirs.hpp>
#include <UIKit/UIKit.h> #include <UIKit/UIKit.h>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <Geode/utils/web.hpp> #include <Geode/utils/web.hpp>
bool utils::clipboard::write(std::string const& data) { bool utils::clipboard::write(std::string const& data) {
[UIPasteboard generalPasteboard].string = [NSString stringWithUTF8String:data.c_str()]; [UIPasteboard generalPasteboard].string = [NSString stringWithUTF8String:data.c_str()];
@ -28,7 +28,8 @@ void geode_nslog(uintptr_t x) {
NSLog(@"geode %lx", x); NSLog(@"geode %lx", x);
} }
ghc::filesystem::path utils::file::current_path() {
ghc::filesystem::path dirs::getGameDir() {
return ghc::filesystem::current_path(); return ghc::filesystem::current_path();
} }

View file

@ -5,6 +5,7 @@
using namespace geode::prelude; using namespace geode::prelude;
#include <Geode/loader/Dirs.hpp>
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
#include <Geode/utils/web.hpp> #include <Geode/utils/web.hpp>
#include <Geode/utils/file.hpp> #include <Geode/utils/file.hpp>
@ -148,7 +149,7 @@ CCPoint cocos::getMousePos() {
return ccp(mouse.x - frame.origin.x, mouse.y - frame.origin.y) * scaleFactor; return ccp(mouse.x - frame.origin.x, mouse.y - frame.origin.y) * scaleFactor;
} }
ghc::filesystem::path utils::file::current_path() { ghc::filesystem::path dirs::getGameDir() {
std::array<char, PATH_MAX> gddir; std::array<char, PATH_MAX> gddir;
uint32_t out = PATH_MAX; uint32_t out = PATH_MAX;

View file

@ -4,7 +4,7 @@
#ifdef GEODE_IS_WINDOWS #ifdef GEODE_IS_WINDOWS
using namespace geode::prelude; using namespace geode::prelude;
#include <Geode/loader/Dirs.hpp>
#include "nfdwin.hpp" #include "nfdwin.hpp"
#include <ghc/fs_fwd.hpp> #include <ghc/fs_fwd.hpp>
#include <Windows.h> #include <Windows.h>
@ -115,7 +115,7 @@ CCPoint cocos::getMousePos() {
return ccp(mouse.x, 1.f - mouse.y) * winSize; return ccp(mouse.x, 1.f - mouse.y) * winSize;
} }
ghc::filesystem::path utils::file::current_path() { ghc::filesystem::path dirs::getGameDir() {
std::array<TCHAR, MAX_PATH> szFileName; std::array<TCHAR, MAX_PATH> szFileName;
GetModuleFileName(NULL, szFileName.data(), MAX_PATH); GetModuleFileName(NULL, szFileName.data(), MAX_PATH);

View file

@ -347,7 +347,10 @@ bool LocalModInfoPopup::init(Mod* mod, ModListLayer* list) {
uninstallBtn->setPosition(-85.f, 75.f); uninstallBtn->setPosition(-85.f, 75.f);
m_buttonMenu->addChild(uninstallBtn); m_buttonMenu->addChild(uninstallBtn);
auto indexItem = Index::get()->getItem(mod->getModInfo()); auto indexItem = Index::get()->getItem(
mod->getModInfo().id(),
ComparableVersionInfo(mod->getModInfo().version(), VersionCompare::More)
);
// todo: show update button on loader that invokes the installer // todo: show update button on loader that invokes the installer
if (indexItem && Index::get()->isUpdateAvailable(indexItem)) { if (indexItem && Index::get()->isUpdateAvailable(indexItem)) {

View file

@ -136,13 +136,24 @@ Result<ComparableVersionInfo> ComparableVersionInfo::parse(std::string const& ra
if (string.starts_with("<=")) { if (string.starts_with("<=")) {
compare = VersionCompare::LessEq; compare = VersionCompare::LessEq;
string.erase(0, 2); string.erase(0, 2);
} else if (string.starts_with(">=")) { }
else if (string.starts_with(">=")) {
compare = VersionCompare::MoreEq; compare = VersionCompare::MoreEq;
string.erase(0, 2); string.erase(0, 2);
} else if (string.starts_with("=")) { }
else if (string.starts_with("=")) {
compare = VersionCompare::Exact; compare = VersionCompare::Exact;
string.erase(0, 1); string.erase(0, 1);
} else { }
else if (string.starts_with("<")) {
compare = VersionCompare::Less;
string.erase(0, 1);
}
else if (string.starts_with(">")) {
compare = VersionCompare::More;
string.erase(0, 1);
}
else {
compare = VersionCompare::MoreEq; compare = VersionCompare::MoreEq;
} }
@ -156,6 +167,8 @@ std::string ComparableVersionInfo::toString() const {
case VersionCompare::Exact: prefix = "="; break; case VersionCompare::Exact: prefix = "="; break;
case VersionCompare::LessEq: prefix = "<="; break; case VersionCompare::LessEq: prefix = "<="; break;
case VersionCompare::MoreEq: prefix = ">="; break; case VersionCompare::MoreEq: prefix = ">="; break;
case VersionCompare::Less: prefix = "<"; break;
case VersionCompare::More: prefix = ">"; break;
} }
return prefix + m_version.toString(); return prefix + m_version.toString();
} }