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,
Exact,
MoreEq,
Less,
More,
};
/**
@ -206,7 +208,11 @@ namespace geode {
return version <= m_version;
case VersionCompare::MoreEq:
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;
}
}

View file

@ -60,8 +60,6 @@ namespace geode::utils::file {
ghc::filesystem::path const& path, bool recursive = false
);
GEODE_DLL ghc::filesystem::path current_path();
class Unzip;
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() {
#ifdef GEODE_IS_MACOS
// not using ~/Library/Caches
@ -32,11 +28,7 @@ ghc::filesystem::path dirs::getSaveDir() {
}
ghc::filesystem::path dirs::getGeodeDir() {
#ifdef GEODE_IS_MACOS
return utils::file::current_path() / "geode";
#else
return dirs::getGameDir() / "geode";
#endif
}
ghc::filesystem::path dirs::getGeodeSaveDir() {

View file

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

View file

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

View file

@ -5,6 +5,7 @@
using namespace geode::prelude;
#include <Geode/loader/Dirs.hpp>
#import <AppKit/AppKit.h>
#include <Geode/utils/web.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;
}
ghc::filesystem::path utils::file::current_path() {
ghc::filesystem::path dirs::getGameDir() {
std::array<char, PATH_MAX> gddir;
uint32_t out = PATH_MAX;

View file

@ -4,7 +4,7 @@
#ifdef GEODE_IS_WINDOWS
using namespace geode::prelude;
#include <Geode/loader/Dirs.hpp>
#include "nfdwin.hpp"
#include <ghc/fs_fwd.hpp>
#include <Windows.h>
@ -115,7 +115,7 @@ CCPoint cocos::getMousePos() {
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;
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);
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
if (indexItem && Index::get()->isUpdateAvailable(indexItem)) {

View file

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