mirror of
https://github.com/geode-sdk/geode.git
synced 2025-02-16 16:29:43 -05:00
work
- fix file::listFiles - temporarily make loader mod min version very low to work with index - index now properly updates
This commit is contained in:
parent
9da9493816
commit
311eb2e356
5 changed files with 47 additions and 20 deletions
|
@ -106,5 +106,4 @@ namespace geode {
|
|||
bool isUpToDate() const;
|
||||
void update(bool force = false);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -19,8 +19,9 @@ namespace geode::utils::file {
|
|||
|
||||
GEODE_DLL Result<> createDirectory(ghc::filesystem::path const& path);
|
||||
GEODE_DLL Result<> createDirectoryAll(ghc::filesystem::path const& path);
|
||||
GEODE_DLL Result<std::vector<std::string>> listFiles(std::string const& path);
|
||||
GEODE_DLL Result<std::vector<std::string>> listFilesRecursively(std::string const& path);
|
||||
GEODE_DLL Result<std::vector<ghc::filesystem::path>> listFiles(
|
||||
ghc::filesystem::path const& path, bool recursive = false
|
||||
);
|
||||
|
||||
class UnzipImpl;
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include <Geode/utils/map.hpp>
|
||||
|
||||
USE_GEODE_NAMESPACE();
|
||||
using namespace geode::impl;
|
||||
|
||||
// The reason sources have private implementation events that are
|
||||
// turned into the global IndexUpdateEvent is because it makes it much
|
||||
|
@ -130,6 +129,29 @@ Result<IndexItemHandle> IndexItem::createFromDir(
|
|||
return Ok(item);
|
||||
}
|
||||
|
||||
// Helpers
|
||||
|
||||
static Result<> flattenGithubRepo(ghc::filesystem::path const& dir) {
|
||||
// github zipballs have a folder at root, but we already have our
|
||||
// own folder for that so let's just bring everything from that
|
||||
// folder to ours
|
||||
GEODE_UNWRAP_INTO(auto files, file::listFiles(dir));
|
||||
try {
|
||||
// only flatten if there is only one file and it's a directory
|
||||
if (files.size() == 1 && ghc::filesystem::is_directory(files[0])) {
|
||||
for (auto& file : ghc::filesystem::directory_iterator(files[0])) {
|
||||
ghc::filesystem::rename(
|
||||
file, dir / ghc::filesystem::relative(file, files[0])
|
||||
);
|
||||
}
|
||||
ghc::filesystem::remove(files[0]);
|
||||
}
|
||||
} catch(std::exception& e) {
|
||||
return Err(e.what());
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
// Index
|
||||
|
||||
Index::Index() {
|
||||
|
@ -300,6 +322,9 @@ void Index::downloadSource(IndexSourceImpl* src) {
|
|||
).post();
|
||||
}
|
||||
|
||||
// remove the directory github adds to the root of the zip
|
||||
(void)flattenGithubRepo(targetDir);
|
||||
|
||||
// update index
|
||||
this->updateSourceFromLocal(src);
|
||||
})
|
||||
|
|
|
@ -30,7 +30,7 @@ VersionInfo Loader::getVersion() {
|
|||
}
|
||||
|
||||
VersionInfo Loader::minModVersion() {
|
||||
return VersionInfo { 0, 6, 1 };
|
||||
return VersionInfo { 0, 3, 1 };
|
||||
}
|
||||
|
||||
VersionInfo Loader::maxModVersion() {
|
||||
|
|
|
@ -110,22 +110,24 @@ Result<> utils::file::createDirectoryAll(ghc::filesystem::path const& path) {
|
|||
}
|
||||
}
|
||||
|
||||
Result<std::vector<std::string>> utils::file::listFiles(std::string const& path) {
|
||||
if (!ghc::filesystem::exists(path)) return Err("Directory does not exist");
|
||||
|
||||
std::vector<std::string> res;
|
||||
for (auto const& file : ghc::filesystem::directory_iterator(path)) {
|
||||
res.push_back(file.path().string());
|
||||
Result<std::vector<ghc::filesystem::path>> utils::file::listFiles(
|
||||
ghc::filesystem::path const& path, bool recursive
|
||||
) {
|
||||
if (!ghc::filesystem::exists(path)) {
|
||||
return Err("Directory does not exist");
|
||||
}
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
Result<std::vector<std::string>> utils::file::listFilesRecursively(std::string const& path) {
|
||||
if (!ghc::filesystem::exists(path)) return Err("Directory does not exist");
|
||||
|
||||
std::vector<std::string> res;
|
||||
for (auto const& file : ghc::filesystem::recursive_directory_iterator(path)) {
|
||||
res.push_back(file.path().string());
|
||||
if (!ghc::filesystem::is_directory(path)) {
|
||||
return Err("Path is not a directory");
|
||||
}
|
||||
std::vector<ghc::filesystem::path> res;
|
||||
if (recursive) {
|
||||
for (auto const& file : ghc::filesystem::recursive_directory_iterator(path)) {
|
||||
res.push_back(file.path());
|
||||
}
|
||||
} else {
|
||||
for (auto const& file : ghc::filesystem::directory_iterator(path)) {
|
||||
res.push_back(file.path());
|
||||
}
|
||||
}
|
||||
return Ok(res);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue