ghc::filesystem -> std::filesystem

remove ghc::filesystem :D
closes #713
This commit is contained in:
matcool 2024-06-02 22:35:05 -03:00
parent 6575754b77
commit 324795cddb
52 changed files with 331 additions and 348 deletions

View file

@ -206,7 +206,6 @@ endif()
set(MAT_JSON_AS_INTERFACE ON)
CPMAddPackage("gh:geode-sdk/json#3fe4752")
CPMAddPackage("gh:fmtlib/fmt#10.1.1")
CPMAddPackage("gh:gulrak/filesystem#3e5b930")
target_compile_definitions(${PROJECT_NAME} INTERFACE MAT_JSON_DYNAMIC=1)
@ -250,10 +249,6 @@ endif()
target_sources(${PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/entry.cpp)
add_library(GeodeFilesystemImpl ${CMAKE_CURRENT_SOURCE_DIR}/FilesystemImpl.cpp)
target_compile_features(GeodeFilesystemImpl PUBLIC cxx_std_20)
target_link_libraries(GeodeFilesystemImpl PUBLIC ghc_filesystem)
add_subdirectory(${GEODE_BINDINGS_REPO_PATH} ${CMAKE_BINARY_DIR}/bindings)
if (NOT GEODE_DISABLE_PRECOMPILED_HEADERS)
@ -269,7 +264,7 @@ target_include_directories(GeodeBindings PUBLIC
${GEODE_LOADER_PATH}/include/Geode/fmod
)
target_link_directories(GeodeBindings PUBLIC ${GEODE_LOADER_PATH}/include/link)
target_link_libraries(GeodeBindings PUBLIC ghc_filesystem fmt TulipHookInclude mat-json GeodeFilesystemImpl)
target_link_libraries(GeodeBindings PUBLIC fmt TulipHookInclude mat-json)
target_link_libraries(${PROJECT_NAME} INTERFACE GeodeBindings)
if (${GEODE_REVERT_TODO_RETURN})
target_compile_definitions(GeodeBindings PUBLIC GEODE_REVERT_TODO_RETURN)

View file

@ -1,4 +0,0 @@
// filesystem implementation
#undef GHC_FILESYSTEM_H
#include <ghc/fs_impl.hpp>

View file

@ -23,7 +23,7 @@ void readBuffered(std::ifstream& stream, Func func) {
}
}
std::string calculateSHA3_256(ghc::filesystem::path const& path) {
std::string calculateSHA3_256(std::filesystem::path const& path) {
std::ifstream file(path, std::ios::binary);
SHA3 sha;
readBuffered(file, [&](const void* data, size_t amt) {
@ -32,14 +32,14 @@ std::string calculateSHA3_256(ghc::filesystem::path const& path) {
return sha.getHash();
}
std::string calculateSHA256(ghc::filesystem::path const& path) {
std::string calculateSHA256(std::filesystem::path const& path) {
std::vector<uint8_t> hash(picosha2::k_digest_size);
std::ifstream file(path, std::ios::binary);
picosha2::hash256(file, hash.begin(), hash.end());
return picosha2::bytes_to_hex_string(hash.begin(), hash.end());
}
std::string calculateSHA256Text(ghc::filesystem::path const& path) {
std::string calculateSHA256Text(std::filesystem::path const& path) {
// remove all newlines
std::vector<uint8_t> hash(picosha2::k_digest_size);
std::ifstream file(path);
@ -52,6 +52,6 @@ std::string calculateSHA256Text(ghc::filesystem::path const& path) {
return picosha2::bytes_to_hex_string(hash.begin(), hash.end());
}
std::string calculateHash(ghc::filesystem::path const& path) {
std::string calculateHash(std::filesystem::path const& path) {
return calculateSHA3_256(path);
}

View file

@ -1,12 +1,12 @@
#pragma once
#include <string>
#include <ghc/fs_fwd.hpp>
#include <filesystem>
std::string calculateSHA3_256(ghc::filesystem::path const& path);
std::string calculateSHA3_256(std::filesystem::path const& path);
std::string calculateSHA256(ghc::filesystem::path const& path);
std::string calculateSHA256(std::filesystem::path const& path);
std::string calculateSHA256Text(ghc::filesystem::path const& path);
std::string calculateSHA256Text(std::filesystem::path const& path);
std::string calculateHash(ghc::filesystem::path const& path);
std::string calculateHash(std::filesystem::path const& path);

View file

@ -26,7 +26,7 @@ THE SOFTWARE.
#define __SUPPORT_ZIPUTILS_H__
#include <string>
#include <ghc/fs_fwd.hpp>
#include <filesystem>
#include "../../platform/CCPlatformDefine.h"
#include "../../platform/CCPlatformConfig.h"
#include "../../include/ccMacros.h"
@ -217,7 +217,7 @@ namespace cocos2d
*/
bool isLoaded() const;
bool unzipAllTo(ghc::filesystem::path const& path);
bool unzipAllTo(std::filesystem::path const& path);
/**
* Regenerate accessible file list based on a new filter string.

View file

@ -1,59 +1,59 @@
#pragma once
#include <ghc/fs_fwd.hpp>
#include <filesystem>
#include "../DefaultInclude.hpp"
namespace geode::dirs {
/**
* Directory where Geometry Dash is
*/
GEODE_DLL ghc::filesystem::path getGameDir();
GEODE_DLL std::filesystem::path getGameDir();
/**
* Directory where GD saves its files
*/
GEODE_DLL ghc::filesystem::path getSaveDir();
GEODE_DLL std::filesystem::path getSaveDir();
/**
* Directory where Geode is
*/
GEODE_DLL ghc::filesystem::path getGeodeDir();
GEODE_DLL std::filesystem::path getGeodeDir();
/**
* Directory where Geode saves its files
*/
GEODE_DLL ghc::filesystem::path getGeodeSaveDir();
GEODE_DLL std::filesystem::path getGeodeSaveDir();
/**
* Directory where Geode's resources are stored
*/
GEODE_DLL ghc::filesystem::path getGeodeResourcesDir();
GEODE_DLL std::filesystem::path getGeodeResourcesDir();
/**
* Directory where Geode's resources are stored
*/
GEODE_DLL ghc::filesystem::path getGeodeLogDir();
GEODE_DLL std::filesystem::path getGeodeLogDir();
/**
* Directory to store temporary files
*/
GEODE_DLL ghc::filesystem::path getTempDir();
GEODE_DLL std::filesystem::path getTempDir();
/**
* Directory where mods are stored by default
*/
GEODE_DLL ghc::filesystem::path getModsDir();
GEODE_DLL std::filesystem::path getModsDir();
/**
* Directory where mods' save data is stored
*/
GEODE_DLL ghc::filesystem::path getModsSaveDir();
GEODE_DLL std::filesystem::path getModsSaveDir();
/**
* Directory where mods' unzipped packages are stored at runtime
*/
GEODE_DLL ghc::filesystem::path getModRuntimeDir();
GEODE_DLL std::filesystem::path getModRuntimeDir();
/**
* Directory where mods' config files lie
*/
GEODE_DLL ghc::filesystem::path getModConfigDir();
GEODE_DLL std::filesystem::path getModConfigDir();
/**
* Directory where Geode stores the cached index
*/
GEODE_DLL ghc::filesystem::path getIndexDir();
GEODE_DLL std::filesystem::path getIndexDir();
/**
* Directory where crashlogs are stored
*/
GEODE_DLL ghc::filesystem::path getCrashlogsDir();
GEODE_DLL std::filesystem::path getCrashlogsDir();
}

View file

@ -1,6 +1,6 @@
#pragma once
#include <ghc/fs_fwd.hpp>
#include <filesystem>
#include "../utils/Result.hpp"
#include "../utils/MiniFunction.hpp"
#include "Log.hpp"
@ -18,7 +18,7 @@ namespace geode {
using ScheduledFunction = utils::MiniFunction<void()>;
struct InvalidGeodeFile {
ghc::filesystem::path path;
std::filesystem::path path;
std::string reason;
};
@ -45,7 +45,7 @@ namespace geode {
OutdatedIncompatibility,
};
Type type;
std::variant<ghc::filesystem::path, ModMetadata, Mod*> cause;
std::variant<std::filesystem::path, ModMetadata, Mod*> cause;
std::string message;
};

View file

@ -6,7 +6,7 @@
#include <Geode/DefaultInclude.hpp>
#include <ccTypes.h>
#include <chrono>
#include <ghc/fs_fwd.hpp>
#include <filesystem>
#include <matjson.hpp>
#include <type_traits>
#include <fmt/core.h>
@ -59,8 +59,8 @@ namespace gd {
}
}
namespace ghc::filesystem {
GEODE_INLINE GEODE_HIDDEN std::string format_as(ghc::filesystem::path const& value) {
namespace std::filesystem {
GEODE_INLINE GEODE_HIDDEN std::string format_as(std::filesystem::path const& value) {
return value.string();
}
}

View file

@ -91,24 +91,24 @@ namespace geode {
std::vector<std::string> getDevelopers() const;
std::optional<std::string> getDescription() const;
std::optional<std::string> getDetails() const;
ghc::filesystem::path getPackagePath() const;
std::filesystem::path getPackagePath() const;
VersionInfo getVersion() const;
bool isEnabled() const;
bool isOrWillBeEnabled() const;
bool isInternal() const;
bool needsEarlyLoad() const;
ModMetadata getMetadata() const;
ghc::filesystem::path getTempDir() const;
std::filesystem::path getTempDir() const;
/**
* Get the path to the mod's platform binary (.dll on Windows, .dylib
* on Mac & iOS, .so on Android)
*/
ghc::filesystem::path getBinaryPath() const;
std::filesystem::path getBinaryPath() const;
/**
* Get the path to the mod's runtime resources directory (contains all
* of its resources)
*/
ghc::filesystem::path getResourcesDir() const;
std::filesystem::path getResourcesDir() const;
#if defined(GEODE_EXPOSE_SECRET_INTERNALS_IN_HEADERS_DO_NOT_DEFINE_PLEASE)
void setMetadata(ModMetadata const& metadata);
@ -131,11 +131,11 @@ namespace geode {
/**
* Get the mod's save directory path
*/
ghc::filesystem::path getSaveDir() const;
std::filesystem::path getSaveDir() const;
/**
* Get the mod's config directory path
*/
ghc::filesystem::path getConfigDir(bool create = true) const;
std::filesystem::path getConfigDir(bool create = true) const;
bool hasSettings() const;
std::vector<std::string> getSettingKeys() const;

View file

@ -94,7 +94,7 @@ namespace geode {
/**
* Path to the mod file
*/
[[nodiscard]] ghc::filesystem::path getPath() const;
[[nodiscard]] std::filesystem::path getPath() const;
/**
* Name of the platform binary within
* the mod zip
@ -216,7 +216,7 @@ namespace geode {
Result<> checkGameVersion() const;
#if defined(GEODE_EXPOSE_SECRET_INTERNALS_IN_HEADERS_DO_NOT_DEFINE_PLEASE)
void setPath(ghc::filesystem::path const& value);
void setPath(std::filesystem::path const& value);
void setBinaryName(std::string const& value);
void setVersion(VersionInfo const& value);
void setID(std::string const& value);
@ -246,11 +246,11 @@ namespace geode {
/**
* Create ModInfo from a .geode package
*/
static Result<ModMetadata> createFromGeodeFile(ghc::filesystem::path const& path);
static Result<ModMetadata> createFromGeodeFile(std::filesystem::path const& path);
/**
* Create ModInfo from a mod.json file
*/
static Result<ModMetadata> createFromFile(ghc::filesystem::path const& path);
static Result<ModMetadata> createFromFile(std::filesystem::path const& path);
/**
* Create ModInfo from a parsed json document
*/
@ -287,7 +287,7 @@ namespace geode {
*/
static Result<ModMetadata> createFromSchemaV010(ModJson const& json);
Result<> addSpecialFiles(ghc::filesystem::path const& dir);
Result<> addSpecialFiles(std::filesystem::path const& dir);
Result<> addSpecialFiles(utils::file::Unzip& zip);
std::vector<std::pair<std::string, std::optional<std::string>*>> getSpecialFiles();

View file

@ -109,7 +109,7 @@ namespace geode {
* local device
*/
struct GEODE_DLL FileSetting final {
using ValueType = ghc::filesystem::path;
using ValueType = std::filesystem::path;
using Filter = utils::file::FilePickOptions::Filter;
std::optional<std::string> name;

View file

@ -7,16 +7,16 @@
#include <matjson.hpp>
#include <Geode/DefaultInclude.hpp>
#include <ghc/fs_fwd.hpp>
#include <filesystem>
#include <string>
#include <unordered_set>
template <>
struct matjson::Serialize<ghc::filesystem::path> {
static matjson::Value to_json(ghc::filesystem::path const& path) {
struct matjson::Serialize<std::filesystem::path> {
static matjson::Value to_json(std::filesystem::path const& path) {
return path.string();
}
static ghc::filesystem::path from_json(matjson::Value const& value) {
static std::filesystem::path from_json(matjson::Value const& value) {
return value.as_string();
}
static bool is_json(matjson::Value const& value) {
@ -25,12 +25,12 @@ struct matjson::Serialize<ghc::filesystem::path> {
};
namespace geode::utils::file {
GEODE_DLL Result<std::string> readString(ghc::filesystem::path const& path);
GEODE_DLL Result<matjson::Value> readJson(ghc::filesystem::path const& path);
GEODE_DLL Result<ByteVector> readBinary(ghc::filesystem::path const& path);
GEODE_DLL Result<std::string> readString(std::filesystem::path const& path);
GEODE_DLL Result<matjson::Value> readJson(std::filesystem::path const& path);
GEODE_DLL Result<ByteVector> readBinary(std::filesystem::path const& path);
template <class T>
Result<T> readFromJson(ghc::filesystem::path const& file) {
Result<T> readFromJson(std::filesystem::path const& file) {
GEODE_UNWRAP_INTO(auto json, readJson(file));
if (!json.template is<T>()) {
return Err("JSON is not of type {}", typeid(T).name());
@ -38,26 +38,26 @@ namespace geode::utils::file {
return Ok(json.template as<T>());
}
GEODE_DLL Result<> writeString(ghc::filesystem::path const& path, std::string const& data);
GEODE_DLL Result<> writeBinary(ghc::filesystem::path const& path, ByteVector const& data);
GEODE_DLL Result<> writeString(std::filesystem::path const& path, std::string const& data);
GEODE_DLL Result<> writeBinary(std::filesystem::path const& path, ByteVector const& data);
template <class T>
Result<> writeToJson(ghc::filesystem::path const& path, T const& data) {
Result<> writeToJson(std::filesystem::path const& path, T const& data) {
GEODE_UNWRAP(writeString(path, matjson::Value(data).dump()));
return Ok();
}
GEODE_DLL Result<> createDirectory(ghc::filesystem::path const& path);
GEODE_DLL Result<> createDirectoryAll(ghc::filesystem::path const& path);
GEODE_DLL Result<std::vector<ghc::filesystem::path>> readDirectory(
ghc::filesystem::path const& path, bool recursive = false
GEODE_DLL Result<> createDirectory(std::filesystem::path const& path);
GEODE_DLL Result<> createDirectoryAll(std::filesystem::path const& path);
GEODE_DLL Result<std::vector<std::filesystem::path>> readDirectory(
std::filesystem::path const& path, bool recursive = false
);
class Unzip;
class GEODE_DLL Zip final {
public:
using Path = ghc::filesystem::path;
using Path = std::filesystem::path;
private:
class Impl;
@ -143,7 +143,7 @@ namespace geode::utils::file {
Unzip(Unzip&& other);
~Unzip();
using Path = ghc::filesystem::path;
using Path = std::filesystem::path;
/**
* Create unzipper for file
@ -224,7 +224,7 @@ namespace geode::utils::file {
* Open a folder / file in the system's file explorer
* @param path Folder / file to open
*/
GEODE_DLL bool openFolder(ghc::filesystem::path const& path);
GEODE_DLL bool openFolder(std::filesystem::path const& path);
enum class PickMode {
OpenFile,
@ -245,7 +245,7 @@ namespace geode::utils::file {
* to be a filename, unless it points to an extant directory.
* On PickMode::OpenFolder, path is treated as leading up to a directory
*/
std::optional<ghc::filesystem::path> defaultPath;
std::optional<std::filesystem::path> defaultPath;
/**
* File extension filters to show on the file picker
*/
@ -259,14 +259,14 @@ namespace geode::utils::file {
* @param options Picker options
*/
[[deprecated("Use pick() instead, this will be removed in a later version.")]]
GEODE_DLL Result<ghc::filesystem::path> pickFile(PickMode mode, FilePickOptions const& options);
GEODE_DLL Result<std::filesystem::path> pickFile(PickMode mode, FilePickOptions const& options);
GEODE_DLL void pickFile(
PickMode mode, FilePickOptions const& options,
utils::MiniFunction<void(ghc::filesystem::path)> callback,
utils::MiniFunction<void(std::filesystem::path)> callback,
utils::MiniFunction<void()> failed = {}
);
GEODE_DLL Task<Result<ghc::filesystem::path>> pick(PickMode mode, FilePickOptions const& options);
GEODE_DLL Task<Result<std::filesystem::path>> pick(PickMode mode, FilePickOptions const& options);
/**
* Prompt the user to pick a bunch of files for opening using the system's file system picker
@ -274,33 +274,33 @@ namespace geode::utils::file {
* @param options Picker options
*/
[[deprecated("Use pickMany() instead, this will be removed in a later version.")]]
GEODE_DLL Result<std::vector<ghc::filesystem::path>> pickFiles(FilePickOptions const& options);
GEODE_DLL Result<std::vector<std::filesystem::path>> pickFiles(FilePickOptions const& options);
GEODE_DLL void pickFiles(
FilePickOptions const& options,
utils::MiniFunction<void(std::vector<ghc::filesystem::path>)> callback,
utils::MiniFunction<void(std::vector<std::filesystem::path>)> callback,
utils::MiniFunction<void()> failed = {}
);
GEODE_DLL Task<Result<std::vector<ghc::filesystem::path>>> pickMany(FilePickOptions const& options);
GEODE_DLL Task<Result<std::vector<std::filesystem::path>>> pickMany(FilePickOptions const& options);
class GEODE_DLL FileWatchEvent : public Event {
protected:
ghc::filesystem::path m_path;
std::filesystem::path m_path;
public:
FileWatchEvent(ghc::filesystem::path const& path);
ghc::filesystem::path getPath() const;
FileWatchEvent(std::filesystem::path const& path);
std::filesystem::path getPath() const;
};
class GEODE_DLL FileWatchFilter : public EventFilter<FileWatchEvent> {
protected:
ghc::filesystem::path m_path;
std::filesystem::path m_path;
public:
using Callback = void(FileWatchEvent*);
ListenerResult handle(utils::MiniFunction<Callback> callback, FileWatchEvent* event);
FileWatchFilter(ghc::filesystem::path const& path);
FileWatchFilter(std::filesystem::path const& path);
};
/**
@ -312,10 +312,10 @@ namespace geode::utils::file {
* so different paths that point to the same file will be considered the
* same
*/
GEODE_DLL Result<> watchFile(ghc::filesystem::path const& file);
GEODE_DLL Result<> watchFile(std::filesystem::path const& file);
/**
* Stop watching a file for changes
* @param file The file to unwatch
*/
GEODE_DLL void unwatchFile(ghc::filesystem::path const& file);
GEODE_DLL void unwatchFile(std::filesystem::path const& file);
}

View file

@ -8,20 +8,11 @@
#include <sstream>
#include <string>
#include <vector>
#include <ghc/fs_fwd.hpp>
#include <filesystem>
#include <matjson.hpp>
#include <charconv>
#include <clocale>
// for some reason std::filesystem::path doesn't have std::hash defined in C++17
// and ghc seems to have inherited this limitation
template<>
struct std::hash<ghc::filesystem::path> {
std::size_t operator()(ghc::filesystem::path const& path) const noexcept {
return ghc::filesystem::hash_value(path);
}
};
namespace geode {
using ByteVector = std::vector<uint8_t>;

View file

@ -6,7 +6,7 @@
#include "Result.hpp"
#include "general.hpp"
#include <ghc/fs_fwd.hpp>
#include <filesystem>
#include <chrono>
namespace geode::utils::web {
@ -42,7 +42,7 @@ namespace geode::utils::web {
*/
[[deprecated("Use the WebRequest class from the web2.hpp header instead")]]
GEODE_DLL Result<> fetchFile(
std::string const& url, ghc::filesystem::path const& into, FileProgressCallback prog = nullptr
std::string const& url, std::filesystem::path const& into, FileProgressCallback prog = nullptr
);
/**
@ -307,7 +307,7 @@ namespace geode::utils::web {
/**
* Download into a stream. Make sure the stream lives for the entire
* duration of the request. If you want to download a file, use the
* `ghc::filesystem::path` overload of `into` instead
* `std::filesystem::path` overload of `into` instead
* @param stream Stream to download into. Make sure it lives long
* enough, otherwise the web request will crash
* @returns AsyncWebResult, where you can specify the `then` action for
@ -325,7 +325,7 @@ namespace geode::utils::web {
* template parameter, as it can be assumed you know what you passed
* into `into`
*/
AsyncWebResult<std::monostate> into(ghc::filesystem::path const& path);
AsyncWebResult<std::monostate> into(std::filesystem::path const& path);
/**
* Download into memory as a string
* @returns AsyncWebResult, where you can specify the `then` action for

View file

@ -39,7 +39,6 @@ set_target_properties(Updater PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${GEODE_BIN_PATH}/nightly"
ARCHIVE_OUTPUT_DIRECTORY "${GEODE_BIN_PATH}/nightly"
)
target_link_libraries(Updater PUBLIC ghc_filesystem)
if (MSVC)
include(CheckLinkerFlag)

View file

@ -51,7 +51,7 @@ void CCFileUtils::updatePaths() {
bool isKnown = false;
for (auto& pack : PACKS) {
for (auto& packPath : pack.m_paths) {
if (ghc::filesystem::path(path.c_str()) == packPath) {
if (std::filesystem::path(path.c_str()) == packPath) {
isKnown = true;
break;
}
@ -60,7 +60,7 @@ void CCFileUtils::updatePaths() {
}
for (auto& pack : REMOVED_PACKS) {
for (auto& packPath : pack.m_paths) {
if (ghc::filesystem::path(path.c_str()) == packPath) {
if (std::filesystem::path(path.c_str()) == packPath) {
isKnown = true;
break;
}
@ -69,7 +69,7 @@ void CCFileUtils::updatePaths() {
}
if (isKnown) break;
for (auto& p : PATHS) {
if (ghc::filesystem::path(path.c_str()) == p) {
if (std::filesystem::path(path.c_str()) == p) {
isKnown = true;
break;
}

View file

@ -3,17 +3,17 @@
#include <Geode/DefaultInclude.hpp>
//#include <Geode/utils/general.hpp>
#include <Geode/utils/MiniFunction.hpp>
#include <ghc/fs_fwd.hpp>
#include <filesystem>
#include <functional>
#include <string>
class FileWatcher {
public:
using FileWatchCallback = geode::utils::MiniFunction<void(ghc::filesystem::path)>;
using FileWatchCallback = geode::utils::MiniFunction<void(std::filesystem::path)>;
using ErrorCallback = geode::utils::MiniFunction<void(std::string)>;
protected:
ghc::filesystem::path m_file;
std::filesystem::path m_file;
FileWatchCallback m_callback;
ErrorCallback m_error;
bool m_filemode = false;
@ -25,12 +25,12 @@ protected:
public:
bool watching() const;
ghc::filesystem::path path() const {
std::filesystem::path path() const {
return m_file;
}
FileWatcher(
ghc::filesystem::path const& file,
std::filesystem::path const& file,
FileWatchCallback callback,
ErrorCallback error = nullptr
);

View file

@ -2,6 +2,8 @@
#include <Geode/loader/Loader.hpp>
#include <server/DownloadManager.hpp>
#include <ui/mods/sources/ModSource.hpp>
#include <vector>
#include <deque>
// TODO: UNFINISHED!!!
// If you want to bring this back, you are free to do so -
@ -24,9 +26,9 @@ protected:
std::vector<std::string> m_unsolved;
std::deque<Question> m_questionQueue;
static ghc::filesystem::path getPath(LoadProblem const& problem) {
static std::filesystem::path getPath(LoadProblem const& problem) {
return std::visit(makeVisitor {
[](ghc::filesystem::path const& path) {
[](std::filesystem::path const& path) {
return path;
},
[](ModMetadata const& meta) {
@ -39,7 +41,7 @@ protected:
}
static std::string getName(LoadProblem const& problem) {
return std::visit(makeVisitor {
[](ghc::filesystem::path const& path) {
[](std::filesystem::path const& path) {
return path.string();
},
[](ModMetadata const& meta) {
@ -94,7 +96,7 @@ public:
{
auto path = getPath(problem);
std::error_code ec;
ghc::filesystem::remove(path, ec);
std::filesystem::remove(path, ec);
if (ec) {
m_unsolved.push_back(fmt::format("Failed to delete '{}'", path));
}

View file

@ -1,7 +1,7 @@
#pragma once
#include <Geode/Loader.hpp>
#include <ghc/fs_fwd.hpp>
#include <filesystem>
#include <string>
/**
@ -29,7 +29,7 @@ namespace crashlog {
* @returns Path to the directory, or an empty string if the platform does
* not support crash logs
*/
ghc::filesystem::path GEODE_DLL getCrashLogDirectory();
std::filesystem::path GEODE_DLL getCrashLogDirectory();
std::string GEODE_DLL writeCrashlog(geode::Mod* faultyMod, std::string const& info, std::string const& stacktrace, std::string const& registers);

View file

@ -7,42 +7,42 @@
using namespace geode::prelude;
ghc::filesystem::path dirs::getGeodeDir() {
std::filesystem::path dirs::getGeodeDir() {
return dirs::getGameDir() / "geode";
}
ghc::filesystem::path dirs::getGeodeSaveDir() {
std::filesystem::path dirs::getGeodeSaveDir() {
return dirs::getSaveDir() / "geode";
}
ghc::filesystem::path dirs::getGeodeResourcesDir() {
std::filesystem::path dirs::getGeodeResourcesDir() {
return dirs::getGeodeDir() / "resources";
}
ghc::filesystem::path dirs::getGeodeLogDir() {
std::filesystem::path dirs::getGeodeLogDir() {
return dirs::getGeodeDir() / "logs";
}
ghc::filesystem::path dirs::getTempDir() {
std::filesystem::path dirs::getTempDir() {
return getGeodeDir() / "temp";
}
ghc::filesystem::path dirs::getModsDir() {
std::filesystem::path dirs::getModsDir() {
return getGeodeDir() / "mods";
}
ghc::filesystem::path dirs::getModsSaveDir() {
std::filesystem::path dirs::getModsSaveDir() {
return getGeodeSaveDir() / "mods";
}
ghc::filesystem::path dirs::getModConfigDir() {
std::filesystem::path dirs::getModConfigDir() {
return dirs::getGeodeDir() / "config";
}
ghc::filesystem::path dirs::getIndexDir() {
std::filesystem::path dirs::getIndexDir() {
return dirs::getGeodeDir() / "index";
}
ghc::filesystem::path dirs::getCrashlogsDir() {
std::filesystem::path dirs::getCrashlogsDir() {
return crashlog::getCrashLogDirectory();
}

View file

@ -51,7 +51,7 @@ bool Loader::Impl::isForwardCompatMode() {
void Loader::Impl::createDirectories() {
#ifdef GEODE_IS_MACOS
ghc::filesystem::create_directory(dirs::getSaveDir());
std::filesystem::create_directory(dirs::getSaveDir());
#endif
(void) utils::file::createDirectoryAll(dirs::getGeodeResourcesDir());
@ -260,8 +260,8 @@ void Loader::Impl::queueMods(std::vector<ModMetadata>& modQueue) {
for (auto const& dir : m_modSearchDirectories) {
log::debug("Searching {}", dir);
log::pushNest();
for (auto const& entry : ghc::filesystem::directory_iterator(dir)) {
if (!ghc::filesystem::is_regular_file(entry) ||
for (auto const& entry : std::filesystem::directory_iterator(dir)) {
if (!std::filesystem::is_regular_file(entry) ||
entry.path().extension() != GEODE_MOD_EXTENSION)
continue;
@ -776,8 +776,8 @@ void Loader::Impl::forceReset() {
}
m_mods.clear();
log::Logger::get()->clear();
ghc::filesystem::remove_all(dirs::getModRuntimeDir());
ghc::filesystem::remove_all(dirs::getTempDir());
std::filesystem::remove_all(dirs::getModRuntimeDir());
std::filesystem::remove_all(dirs::getTempDir());
}
bool Loader::Impl::isReadyToHook() const {

View file

@ -33,11 +33,11 @@ namespace geode {
std::string m_gdVersion;
std::optional<bool> m_forwardCompatMode;
std::vector<ghc::filesystem::path> m_modSearchDirectories;
std::vector<std::filesystem::path> m_modSearchDirectories;
std::vector<LoadProblem> m_problems;
std::unordered_map<std::string, Mod*> m_mods;
std::deque<Mod*> m_modsToLoad;
std::vector<ghc::filesystem::path> m_texturePaths;
std::vector<std::filesystem::path> m_texturePaths;
bool m_isSetup = false;
LoadingState m_loadingState = LoadingState::None;
@ -84,7 +84,7 @@ namespace geode {
void updateModResources(Mod* mod);
void addSearchPaths();
void addNativeBinariesPath(ghc::filesystem::path const& path);
void addNativeBinariesPath(std::filesystem::path const& path);
Result<> setup();
void forceReset();

View file

@ -35,7 +35,7 @@ std::optional<std::string> Mod::getDetails() const {
return m_impl->getDetails();
}
ghc::filesystem::path Mod::getPackagePath() const {
std::filesystem::path Mod::getPackagePath() const {
return m_impl->getPackagePath();
}
@ -78,15 +78,15 @@ ModMetadata Mod::getMetadata() const {
return m_impl->getMetadata();
}
ghc::filesystem::path Mod::getTempDir() const {
std::filesystem::path Mod::getTempDir() const {
return m_impl->getTempDir();
}
ghc::filesystem::path Mod::getBinaryPath() const {
std::filesystem::path Mod::getBinaryPath() const {
return m_impl->getBinaryPath();
}
ghc::filesystem::path Mod::getResourcesDir() const {
std::filesystem::path Mod::getResourcesDir() const {
return dirs::getModRuntimeDir() / this->getID() / "resources" / this->getID();
}
@ -121,11 +121,11 @@ Result<> Mod::loadData() {
return m_impl->loadData();
}
ghc::filesystem::path Mod::getSaveDir() const {
std::filesystem::path Mod::getSaveDir() const {
return m_impl->getSaveDir();
}
ghc::filesystem::path Mod::getConfigDir(bool create) const {
std::filesystem::path Mod::getConfigDir(bool create) const {
return m_impl->getConfigDir(create);
}

View file

@ -66,7 +66,7 @@ Result<> Mod::Impl::setup() {
});
const auto binariesDir = searchPathRoot / m_metadata.getID() / "binaries" / PlatformID::toShortString(GEODE_PLATFORM_TARGET);
if (ghc::filesystem::exists(binariesDir))
if (std::filesystem::exists(binariesDir))
LoaderImpl::get()->addNativeBinariesPath(binariesDir);
m_resourcesLoaded = true;
@ -77,7 +77,7 @@ Result<> Mod::Impl::setup() {
// Getters
ghc::filesystem::path Mod::Impl::getSaveDir() const {
std::filesystem::path Mod::Impl::getSaveDir() const {
return m_saveDirPath;
}
@ -114,15 +114,15 @@ std::vector<Mod*> Mod::Impl::getDependants() const {
}
#endif
ghc::filesystem::path Mod::Impl::getTempDir() const {
std::filesystem::path Mod::Impl::getTempDir() const {
return m_tempDirName;
}
ghc::filesystem::path Mod::Impl::getBinaryPath() const {
std::filesystem::path Mod::Impl::getBinaryPath() const {
return m_tempDirName / m_metadata.getBinaryName();
}
ghc::filesystem::path Mod::Impl::getPackagePath() const {
std::filesystem::path Mod::Impl::getPackagePath() const {
return m_metadata.getPath();
}
@ -180,7 +180,7 @@ Result<> Mod::Impl::loadData() {
// Settings
// Check if settings exist
auto settingPath = m_saveDirPath / "settings.json";
if (ghc::filesystem::exists(settingPath)) {
if (std::filesystem::exists(settingPath)) {
GEODE_UNWRAP_INTO(auto settingData, utils::file::readString(settingPath));
// parse settings.json
std::string error;
@ -223,7 +223,7 @@ Result<> Mod::Impl::loadData() {
// Saved values
auto savedPath = m_saveDirPath / "saved.json";
if (ghc::filesystem::exists(savedPath)) {
if (std::filesystem::exists(savedPath)) {
GEODE_UNWRAP_INTO(auto data, utils::file::readString(savedPath));
std::string error;
auto res = matjson::parse(data, error);
@ -386,7 +386,7 @@ Result<> Mod::Impl::loadBinary() {
if (m_enabled)
return Ok();
if (!ghc::filesystem::exists(this->getBinaryPath())) {
if (!std::filesystem::exists(this->getBinaryPath())) {
return Err(
fmt::format(
"Failed to load {}: No binary could be found for current platform.\n"
@ -483,7 +483,7 @@ Result<> Mod::Impl::uninstall(bool deleteSaveData) {
Mod::get()->getSaveContainer().try_erase("should-load-" + m_metadata.getID());
std::error_code ec;
ghc::filesystem::remove(m_metadata.getPath(), ec);
std::filesystem::remove(m_metadata.getPath(), ec);
if (ec) {
return Err(
"Unable to delete mod's .geode file: " + ec.message()
@ -491,7 +491,7 @@ Result<> Mod::Impl::uninstall(bool deleteSaveData) {
}
if (deleteSaveData) {
ghc::filesystem::remove_all(this->getSaveDir(), ec);
std::filesystem::remove_all(this->getSaveDir(), ec);
if (ec) {
return Err(
"Unable to delete mod's save directory: " + ec.message()
@ -690,7 +690,7 @@ Result<> Mod::Impl::unzipGeodeFile(ModMetadata metadata) {
auto datePath = tempDir / "modified-at";
std::string currentHash = file::readString(datePath).unwrapOr("");
auto modifiedDate = ghc::filesystem::last_write_time(metadata.getPath());
auto modifiedDate = std::filesystem::last_write_time(metadata.getPath());
auto modifiedCount = std::chrono::duration_cast<std::chrono::milliseconds>(modifiedDate.time_since_epoch());
auto modifiedHash = std::to_string(modifiedCount.count());
if (currentHash == modifiedHash) {
@ -700,7 +700,7 @@ Result<> Mod::Impl::unzipGeodeFile(ModMetadata metadata) {
log::debug("Hash mismatch detected, unzipping");
std::error_code ec;
ghc::filesystem::remove_all(tempDir, ec);
std::filesystem::remove_all(tempDir, ec);
if (ec) {
auto message = ec.message();
#ifdef GEODE_IS_WINDOWS
@ -735,7 +735,7 @@ Result<> Mod::Impl::unzipGeodeFile(ModMetadata metadata) {
return Ok();
}
ghc::filesystem::path Mod::Impl::getConfigDir(bool create) const {
std::filesystem::path Mod::Impl::getConfigDir(bool create) const {
auto dir = dirs::getModConfigDir() / m_metadata.getID();
if (create) {
(void)file::createDirectoryAll(dir);

View file

@ -31,11 +31,11 @@ namespace geode {
/**
* Mod temp directory name
*/
ghc::filesystem::path m_tempDirName;
std::filesystem::path m_tempDirName;
/**
* Mod save directory name
*/
ghc::filesystem::path m_saveDirPath;
std::filesystem::path m_saveDirPath;
/**
* Pointers to mods that depend on this Mod.
* Makes it possible to enable / disable them automatically,
@ -89,14 +89,14 @@ namespace geode {
std::vector<std::string> getDevelopers() const;
std::optional<std::string> getDescription() const;
std::optional<std::string> getDetails() const;
ghc::filesystem::path getPackagePath() const;
std::filesystem::path getPackagePath() const;
VersionInfo getVersion() const;
bool isEnabled() const;
bool isInternal() const;
bool needsEarlyLoad() const;
ModMetadata getMetadata() const;
ghc::filesystem::path getTempDir() const;
ghc::filesystem::path getBinaryPath() const;
std::filesystem::path getTempDir() const;
std::filesystem::path getBinaryPath() const;
matjson::Value& getSaveContainer();
matjson::Value& getSavedSettingsData();
@ -109,8 +109,8 @@ namespace geode {
Result<> saveData();
Result<> loadData();
ghc::filesystem::path getSaveDir() const;
ghc::filesystem::path getConfigDir(bool create = true) const;
std::filesystem::path getSaveDir() const;
std::filesystem::path getConfigDir(bool create = true) const;
bool hasSettings() const;
std::vector<std::string> getSettingKeys() const;

View file

@ -362,7 +362,7 @@ Result<ModMetadata> ModMetadata::Impl::create(ModJson const& json) {
return Impl::createFromSchemaV010(json);
}
Result<ModMetadata> ModMetadata::Impl::createFromFile(ghc::filesystem::path const& path) {
Result<ModMetadata> ModMetadata::Impl::createFromFile(std::filesystem::path const& path) {
GEODE_UNWRAP_INTO(auto read, utils::file::readString(path));
std::string error;
@ -382,7 +382,7 @@ Result<ModMetadata> ModMetadata::Impl::createFromFile(ghc::filesystem::path cons
return Ok(info);
}
Result<ModMetadata> ModMetadata::Impl::createFromGeodeFile(ghc::filesystem::path const& path) {
Result<ModMetadata> ModMetadata::Impl::createFromGeodeFile(std::filesystem::path const& path) {
GEODE_UNWRAP_INTO(auto unzip, file::Unzip::create(path));
return ModMetadata::createFromGeodeZip(unzip);
}
@ -429,10 +429,10 @@ Result<> ModMetadata::Impl::addSpecialFiles(file::Unzip& unzip) {
return Ok();
}
Result<> ModMetadata::Impl::addSpecialFiles(ghc::filesystem::path const& dir) {
Result<> ModMetadata::Impl::addSpecialFiles(std::filesystem::path const& dir) {
// unzip known MD files
for (auto& [file, target] : this->getSpecialFiles()) {
if (ghc::filesystem::exists(dir / file)) {
if (std::filesystem::exists(dir / file)) {
auto data = file::readString(dir / file);
if (!data) {
return Err("Unable to read \"" + file + "\": " + data.unwrapErr());
@ -466,7 +466,7 @@ bool ModMetadata::Impl::operator==(ModMetadata::Impl const& other) const {
return this->m_id == other.m_id;
}
[[maybe_unused]] ghc::filesystem::path ModMetadata::getPath() const {
[[maybe_unused]] std::filesystem::path ModMetadata::getPath() const {
return m_impl->m_path;
}
@ -579,7 +579,7 @@ Result<> ModMetadata::checkGameVersion() const {
}
#if defined(GEODE_EXPOSE_SECRET_INTERNALS_IN_HEADERS_DO_NOT_DEFINE_PLEASE)
void ModMetadata::setPath(ghc::filesystem::path const& value) {
void ModMetadata::setPath(std::filesystem::path const& value) {
m_impl->m_path = value;
}
void ModMetadata::setBinaryName(std::string const& value) {
@ -647,10 +647,10 @@ ModMetadataLinks& ModMetadata::getLinksMut() {
Result<ModMetadata> ModMetadata::createFromGeodeZip(utils::file::Unzip& zip) {
return Impl::createFromGeodeZip(zip);
}
Result<ModMetadata> ModMetadata::createFromGeodeFile(ghc::filesystem::path const& path) {
Result<ModMetadata> ModMetadata::createFromGeodeFile(std::filesystem::path const& path) {
return Impl::createFromGeodeFile(path);
}
Result<ModMetadata> ModMetadata::createFromFile(ghc::filesystem::path const& path) {
Result<ModMetadata> ModMetadata::createFromFile(std::filesystem::path const& path) {
return Impl::createFromFile(path);
}
Result<ModMetadata> ModMetadata::create(ModJson const& json) {
@ -676,7 +676,7 @@ Result<ModMetadata> ModMetadata::createFromSchemaV010(ModJson const& json) {
return Impl::createFromSchemaV010(json);
}
Result<> ModMetadata::addSpecialFiles(ghc::filesystem::path const& dir) {
Result<> ModMetadata::addSpecialFiles(std::filesystem::path const& dir) {
return m_impl->addSpecialFiles(dir);
}
Result<> ModMetadata::addSpecialFiles(utils::file::Unzip& zip) {

View file

@ -17,7 +17,7 @@ namespace geode {
class ModMetadata::Impl {
public:
ghc::filesystem::path m_path;
std::filesystem::path m_path;
std::string m_binaryName;
VersionInfo m_version{1, 0, 0};
std::string m_id;
@ -42,8 +42,8 @@ namespace geode {
ModJson m_rawJSON;
static Result<ModMetadata> createFromGeodeZip(utils::file::Unzip& zip);
static Result<ModMetadata> createFromGeodeFile(ghc::filesystem::path const& path);
static Result<ModMetadata> createFromFile(ghc::filesystem::path const& path);
static Result<ModMetadata> createFromGeodeFile(std::filesystem::path const& path);
static Result<ModMetadata> createFromFile(std::filesystem::path const& path);
static Result<ModMetadata> create(ModJson const& json);
ModJson toJSON() const;
@ -57,7 +57,7 @@ namespace geode {
static Result<ModMetadata> createFromSchemaV010(ModJson const& rawJson);
Result<> addSpecialFiles(ghc::filesystem::path const& dir);
Result<> addSpecialFiles(std::filesystem::path const& dir);
Result<> addSpecialFiles(utils::file::Unzip& zip);
std::vector<std::pair<std::string, std::optional<std::string>*>> getSpecialFiles();

View file

@ -250,8 +250,8 @@ bool updater::verifyLoaderResources() {
// if the resources dir doesn't exist, then it's probably incorrect
if (!(
ghc::filesystem::exists(resourcesDir) &&
ghc::filesystem::is_directory(resourcesDir)
std::filesystem::exists(resourcesDir) &&
std::filesystem::is_directory(resourcesDir)
)) {
log::debug("Resources directory does not exist");
updater::downloadLoaderResources(true);
@ -260,7 +260,7 @@ bool updater::verifyLoaderResources() {
// TODO: actually have a proper way to disable checking resources
// for development builds
if (ghc::filesystem::exists(resourcesDir / "dont-update.txt")) {
if (std::filesystem::exists(resourcesDir / "dont-update.txt")) {
// this is kind of a hack, but it's the easiest way to prevent
// auto update while developing
log::debug("Not updating resources since dont-update.txt exists");
@ -271,7 +271,7 @@ bool updater::verifyLoaderResources() {
size_t coverage = 0;
// verify hashes
for (auto& file : ghc::filesystem::directory_iterator(resourcesDir)) {
for (auto& file : std::filesystem::directory_iterator(resourcesDir)) {
auto name = file.path().filename().string();
// skip unknown files
if (!LOADER_RESOURCE_HASHES.count(name)) {

View file

@ -1,9 +1,9 @@
#include <FileWatcher.hpp>
FileWatcher::FileWatcher(
ghc::filesystem::path const& file, FileWatchCallback callback, ErrorCallback error
std::filesystem::path const& file, FileWatchCallback callback, ErrorCallback error
) {
m_filemode = ghc::filesystem::is_regular_file(file);
m_filemode = std::filesystem::is_regular_file(file);
m_platformHandle = nullptr;
m_file = file;

View file

@ -33,7 +33,7 @@ bool Loader::Impl::userTriedToLoadDLLs() const {
return false;
}
void Loader::Impl::addNativeBinariesPath(ghc::filesystem::path const& path) {
void Loader::Impl::addNativeBinariesPath(std::filesystem::path const& path) {
log::warn("LoaderImpl::addNativeBinariesPath not implement on this platform, not adding path {}", path.string());
}

View file

@ -52,9 +52,9 @@ bool crashlog::setupPlatformHandler() {
);
auto crashIndicatorPath = crashlog::getCrashLogDirectory() / crashIndicatorFilename;
if (ghc::filesystem::exists(crashIndicatorPath)) {
if (std::filesystem::exists(crashIndicatorPath)) {
s_lastLaunchCrashed = true;
ghc::filesystem::remove(crashIndicatorPath);
std::filesystem::remove(crashIndicatorPath);
}
return true;
@ -69,7 +69,7 @@ using namespace geode::prelude;
#include <Geode/utils/string.hpp>
#include <array>
#include <thread>
#include <ghc/fs_fwd.hpp>
#include <filesystem>
#include <execinfo.h>
#include <dlfcn.h>
#include <cxxabi.h>
@ -257,7 +257,7 @@ int writeAndGetPid() {
int lastPid = 0;
if (ghc::filesystem::exists(pidFile)) {
if (std::filesystem::exists(pidFile)) {
auto res = file::readString(pidFile);
if (!res) {
@ -268,7 +268,7 @@ int writeAndGetPid() {
}
std::error_code ec;
ghc::filesystem::remove(pidFile, ec);
std::filesystem::remove(pidFile, ec);
if (ec) {
log::warn("Failed to remove last-pid file: {}", ec.message());
@ -367,7 +367,7 @@ void crashlog::setupPlatformHandlerPost() {
#endif
ghc::filesystem::path crashlog::getCrashLogDirectory() {
std::filesystem::path crashlog::getCrashLogDirectory() {
return geode::dirs::getGeodeDir() / "crashlogs";
}

View file

@ -6,7 +6,7 @@
#include "internalString.hpp"
#include <cocos2d.h>
#include <Geode/loader/Log.hpp>
#include <ghc/fs_fwd.hpp>
#include <filesystem>
#include <Geode/loader/Dirs.hpp>
using namespace geode::prelude;
@ -49,7 +49,7 @@ extern "C" [[gnu::visibility("default")]] jint JNI_OnLoad(JavaVM* vm, void* rese
auto updatePath = geode::dirs::getGameDir() / "update";
std::error_code ec;
ghc::filesystem::remove_all(updatePath, ec);
std::filesystem::remove_all(updatePath, ec);
if (ec) {
geode::log::warn("Failed to remove update directory: {}", ec.message());
}

View file

@ -5,7 +5,7 @@ using namespace geode::prelude;
#include <Geode/utils/cocos.hpp>
#include <Geode/loader/Dirs.hpp>
#include <Geode/utils/web.hpp>
#include <ghc/fs_fwd.hpp>
#include <filesystem>
#include <Geode/utils/file.hpp>
#include <Geode/utils/general.hpp>
#include <Geode/utils/MiniFunction.hpp>
@ -67,11 +67,11 @@ namespace {
// jni breaks over multithreading, so the value is stored to avoid more jni calls
std::string s_savedBaseDir = "";
ghc::filesystem::path getBaseDir() {
std::filesystem::path getBaseDir() {
std::string path = "/storage/emulated/0/Android/data/com.geode.launcher/files";
if (!s_savedBaseDir.empty()) {
return ghc::filesystem::path(s_savedBaseDir);
return std::filesystem::path(s_savedBaseDir);
}
JniMethodInfo t;
@ -85,19 +85,19 @@ namespace {
}
s_savedBaseDir = path;
return ghc::filesystem::path(path);
return std::filesystem::path(path);
}
}
ghc::filesystem::path dirs::getGameDir() {
std::filesystem::path dirs::getGameDir() {
return getBaseDir() / "game";
}
ghc::filesystem::path dirs::getSaveDir() {
std::filesystem::path dirs::getSaveDir() {
return getBaseDir() / "save";
}
ghc::filesystem::path dirs::getModRuntimeDir() {
std::filesystem::path dirs::getModRuntimeDir() {
static std::string cachedResult = [] {
// incase the jni fails, default to this
std::string path = "/data/user/0/com.geode.launcher/files/";
@ -114,14 +114,14 @@ ghc::filesystem::path dirs::getModRuntimeDir() {
return path;
}();
return ghc::filesystem::path(cachedResult) / "geode" / "unzipped";
return std::filesystem::path(cachedResult) / "geode" / "unzipped";
}
void utils::web::openLinkInBrowser(std::string const& url) {
CCApplication::sharedApplication()->openURL(url.c_str());
}
bool utils::file::openFolder(ghc::filesystem::path const& path) {
bool utils::file::openFolder(std::filesystem::path const& path) {
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "com/geode/launcher/utils/GeodeUtils", "openFolder", "(Ljava/lang/String;)Z")) {
jstring stringArg1 = t.env->NewStringUTF(path.string().c_str());
@ -136,8 +136,8 @@ bool utils::file::openFolder(ghc::filesystem::path const& path) {
}
static utils::MiniFunction<void(ghc::filesystem::path)> s_fileCallback;
static utils::MiniFunction<void(std::vector<ghc::filesystem::path>)> s_filesCallback;
static utils::MiniFunction<void(std::filesystem::path)> s_fileCallback;
static utils::MiniFunction<void(std::vector<std::filesystem::path>)> s_filesCallback;
static utils::MiniFunction<void()> s_failedCallback;
extern "C"
@ -164,7 +164,7 @@ JNIEXPORT void JNICALL Java_com_geode_launcher_utils_GeodeUtils_selectFilesCallb
) {
auto isCopy = jboolean();
auto count = env->GetArrayLength(datas);
auto result = std::vector<ghc::filesystem::path>();
auto result = std::vector<std::filesystem::path>();
for (int i = 0; i < count; i++) {
auto data = (jstring)env->GetObjectArrayElement(datas, i);
auto dataStr = env->GetStringUTFChars(data, &isCopy);
@ -190,13 +190,13 @@ JNIEXPORT void JNICALL Java_com_geode_launcher_utils_GeodeUtils_failedCallback(
}
}
Result<ghc::filesystem::path> file::pickFile(file::PickMode mode, file::FilePickOptions const& options) {
Result<std::filesystem::path> file::pickFile(file::PickMode mode, file::FilePickOptions const& options) {
return Err("Use the callback version");
}
void file::pickFile(
PickMode mode, FilePickOptions const& options,
MiniFunction<void(ghc::filesystem::path)> callback,
MiniFunction<void(std::filesystem::path)> callback,
MiniFunction<void()> failed
) {
s_fileCallback = callback;
@ -217,7 +217,7 @@ void file::pickFile(
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "com/geode/launcher/utils/GeodeUtils", method.c_str(), "(Ljava/lang/String;)Z")) {
jstring stringArg1 = t.env->NewStringUTF(options.defaultPath.value_or(ghc::filesystem::path()).filename().string().c_str());
jstring stringArg1 = t.env->NewStringUTF(options.defaultPath.value_or(std::filesystem::path()).filename().string().c_str());
jboolean result = t.env->CallStaticBooleanMethod(t.classID, t.methodID, stringArg1);
@ -234,13 +234,13 @@ void file::pickFile(
}
}
Result<std::vector<ghc::filesystem::path>> file::pickFiles(file::FilePickOptions const& options) {
Result<std::vector<std::filesystem::path>> file::pickFiles(file::FilePickOptions const& options) {
return Err("Use the callback version");
}
void file::pickFiles(
FilePickOptions const& options,
MiniFunction<void(std::vector<ghc::filesystem::path>)> callback,
MiniFunction<void(std::vector<std::filesystem::path>)> callback,
MiniFunction<void()> failed
) {
s_filesCallback = callback;
@ -248,7 +248,7 @@ void file::pickFiles(
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "com/geode/launcher/utils/GeodeUtils", "selectFiles", "(Ljava/lang/String;)Z")) {
jstring stringArg1 = t.env->NewStringUTF(options.defaultPath.value_or(ghc::filesystem::path()).string().c_str());
jstring stringArg1 = t.env->NewStringUTF(options.defaultPath.value_or(std::filesystem::path()).string().c_str());
jboolean result = t.env->CallStaticBooleanMethod(t.classID, t.methodID, stringArg1);

View file

@ -8,9 +8,9 @@
// FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE;
FileWatcher::FileWatcher(
ghc::filesystem::path const& file, FileWatchCallback callback, ErrorCallback error
std::filesystem::path const& file, FileWatchCallback callback, ErrorCallback error
) {
m_filemode = ghc::filesystem::is_regular_file(file);
m_filemode = std::filesystem::is_regular_file(file);
m_platformHandle = NULL;
m_file = file;

View file

@ -20,8 +20,8 @@ void Loader::Impl::logConsoleMessageWithSeverity(std::string const& msg, Severit
}
void Loader::Impl::openPlatformConsole() {
ghc::filesystem::path(getpwuid(getuid())->pw_dir);
freopen(ghc::filesystem::path(dirs::getGeodeDir() / "geode_log.txt").string().c_str(), "w", stdout);
std::filesystem::path(getpwuid(getuid())->pw_dir);
freopen(std::filesystem::path(dirs::getGeodeDir() / "geode_log.txt").string().c_str(), "w", stdout);
m_platformConsoleOpen = true;
}

View file

@ -8,6 +8,6 @@ bool crashlog::didLastLaunchCrash() {
return false;
}
ghc::filesystem::path crashlog::getCrashLogDirectory() {
std::filesystem::path crashlog::getCrashLogDirectory() {
return "";
}

View file

@ -25,8 +25,8 @@ void dynamicEntry() {
auto error = std::error_code();
if (ghc::filesystem::exists(updatesDir / "GeodeBootstrapper.dylib", error) && !error) {
ghc::filesystem::rename(
if (std::filesystem::exists(updatesDir / "GeodeBootstrapper.dylib", error) && !error) {
std::filesystem::rename(
updatesDir / "GeodeBootstrapper.dylib", libDir / "GeodeBootstrapper.dylib", error
);
if (error) return;

View file

@ -27,11 +27,11 @@ void geode_nslog(uintptr_t x) {
}
ghc::filesystem::path dirs::getGameDir() {
return ghc::filesystem::current_path();
std::filesystem::path dirs::getGameDir() {
return std::filesystem::current_path();
}
ghc::filesystem::path dirs::getSaveDir() {
std::filesystem::path dirs::getSaveDir() {
return weaklyCanonical(CCFileUtils::sharedFileUtils()->getWritablePath().c_str());
}

View file

@ -8,9 +8,9 @@
// FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE;
FileWatcher::FileWatcher(
ghc::filesystem::path const& file, FileWatchCallback callback, ErrorCallback error
std::filesystem::path const& file, FileWatchCallback callback, ErrorCallback error
) {
m_filemode = ghc::filesystem::is_regular_file(file);
m_filemode = std::filesystem::is_regular_file(file);
m_platformHandle = NULL;
m_file = file;

View file

@ -131,7 +131,7 @@ bool Loader::Impl::userTriedToLoadDLLs() const {
return false;
}
void Loader::Impl::addNativeBinariesPath(ghc::filesystem::path const& path) {
void Loader::Impl::addNativeBinariesPath(std::filesystem::path const& path) {
log::warn("LoaderImpl::addNativeBinariesPath not implement on this platform, not adding path {}", path.string());
}

View file

@ -3,7 +3,7 @@
#include <Geode/utils/string.hpp>
#include <array>
#include <thread>
#include <ghc/fs_fwd.hpp>
#include <filesystem>
#include <execinfo.h>
#include <dlfcn.h>
#include <cxxabi.h>
@ -139,20 +139,20 @@ static Mod* modFromAddress(void const* addr) {
return nullptr;
}
ghc::filesystem::path imagePath = getImageName(image);
if (!ghc::filesystem::exists(imagePath)) {
std::filesystem::path imagePath = getImageName(image);
if (!std::filesystem::exists(imagePath)) {
return nullptr;
}
auto geodePath = dirs::getGameDir() / "Frameworks" / "Geode.dylib";
if (ghc::filesystem::equivalent(imagePath, geodePath)) {
if (std::filesystem::equivalent(imagePath, geodePath)) {
return Mod::get();
}
for (auto& mod : Loader::get()->getAllMods()) {
if (!mod->isEnabled() || !ghc::filesystem::exists(mod->getBinaryPath())) {
if (!mod->isEnabled() || !std::filesystem::exists(mod->getBinaryPath())) {
continue;
}
if (ghc::filesystem::equivalent(imagePath, mod->getBinaryPath())) {
if (std::filesystem::equivalent(imagePath, mod->getBinaryPath())) {
return mod;
}
}
@ -369,10 +369,10 @@ bool crashlog::setupPlatformHandler() {
std::thread(&handlerThread).detach();
auto lastCrashedFile = crashlog::getCrashLogDirectory() / "last-crashed";
if (ghc::filesystem::exists(lastCrashedFile)) {
if (std::filesystem::exists(lastCrashedFile)) {
s_lastLaunchCrashed = true;
try {
ghc::filesystem::remove(lastCrashedFile);
std::filesystem::remove(lastCrashedFile);
}
catch (...) {
}
@ -386,6 +386,6 @@ bool crashlog::didLastLaunchCrash() {
return s_lastLaunchCrashed;
}
ghc::filesystem::path crashlog::getCrashLogDirectory() {
std::filesystem::path crashlog::getCrashLogDirectory() {
return dirs::getGeodeDir() / "crashlogs";
}

View file

@ -7,7 +7,7 @@
#include <unistd.h>
#include <tulip/TulipHook.hpp>
#include <array>
#include <ghc/fs_fwd.hpp>
#include <filesystem>
#include <Geode/Loader.hpp>
#include "../../loader/LoaderImpl.hpp"
#include <thread>
@ -30,18 +30,18 @@ void updateFiles() {
auto updatesDir = dirs::getGeodeDir() / "update";
auto resourcesDir = dirs::getGeodeResourcesDir();
if (ghc::filesystem::exists(frameworkDir) && ghc::filesystem::exists(updatesDir)) {
if (std::filesystem::exists(frameworkDir) && std::filesystem::exists(updatesDir)) {
std::error_code error;
auto bootFile = "GeodeBootstrapper.dylib";
auto geodeFile = "Geode.dylib";
if (ghc::filesystem::exists(updatesDir / bootFile)) {
ghc::filesystem::remove(frameworkDir / bootFile, error);
if (std::filesystem::exists(updatesDir / bootFile)) {
std::filesystem::remove(frameworkDir / bootFile, error);
if (error) {
log::warn("Couldn't remove old GeodeBootstrapper.dylib: {}", error.message());
}
else {
ghc::filesystem::rename(updatesDir / bootFile, frameworkDir / bootFile, error);
std::filesystem::rename(updatesDir / bootFile, frameworkDir / bootFile, error);
if (error) {
log::warn("Couldn't move new GeodeBootstrapper.dylib: {}", error.message());
}
@ -50,13 +50,13 @@ void updateFiles() {
}
}
}
if (ghc::filesystem::exists(updatesDir / geodeFile)) {
ghc::filesystem::remove(frameworkDir / geodeFile, error);
if (std::filesystem::exists(updatesDir / geodeFile)) {
std::filesystem::remove(frameworkDir / geodeFile, error);
if (error) {
log::warn("Couldn't remove old Geode.dylib: {}", error.message());
}
else {
ghc::filesystem::rename(updatesDir / geodeFile, frameworkDir / geodeFile, error);
std::filesystem::rename(updatesDir / geodeFile, frameworkDir / geodeFile, error);
if (error) {
log::warn("Couldn't move new Geode.dylib: {}", error.message());
}
@ -65,13 +65,13 @@ void updateFiles() {
}
}
}
if (ghc::filesystem::exists(updatesDir / "resources")) {
ghc::filesystem::remove_all(resourcesDir / "geode.loader", error);
if (std::filesystem::exists(updatesDir / "resources")) {
std::filesystem::remove_all(resourcesDir / "geode.loader", error);
if (error) {
log::warn("Couldn't remove old resources: {}", error.message());
}
else {
ghc::filesystem::rename(updatesDir / "resources", resourcesDir / "geode.loader", error);
std::filesystem::rename(updatesDir / "resources", resourcesDir / "geode.loader", error);
if (error) {
log::warn("Couldn't move new resources: {}", error.message());
}
@ -80,7 +80,7 @@ void updateFiles() {
}
}
}
ghc::filesystem::remove_all(updatesDir, error);
std::filesystem::remove_all(updatesDir, error);
if (error) {
log::warn("Couldn't remove old update directory: {}", error.message());
}
@ -98,12 +98,12 @@ $execute {
};
void updateGeode() {
ghc::filesystem::path oldSavePath = "/Users/Shared/Geode/geode";
std::filesystem::path oldSavePath = "/Users/Shared/Geode/geode";
auto newSavePath = dirs::getSaveDir() / "geode";
if (ghc::filesystem::exists(oldSavePath)) {
if (std::filesystem::exists(oldSavePath)) {
std::error_code error;
ghc::filesystem::rename(oldSavePath, newSavePath, error);
std::filesystem::rename(oldSavePath, newSavePath, error);
if (error) {
log::warn("Couldn't migrate old save files from {} to {}", oldSavePath.string(), newSavePath.string());
}

View file

@ -28,7 +28,7 @@ std::string utils::clipboard::read() {
return std::string(clipboard);
}
bool utils::file::openFolder(ghc::filesystem::path const& path) {
bool utils::file::openFolder(std::filesystem::path const& path) {
NSURL* fileURL = [NSURL fileURLWithPath:[NSString stringWithUTF8String:path.string().c_str()]];
NSURL* folderURL = [fileURL URLByDeletingLastPathComponent];
[[NSWorkspace sharedWorkspace] openURL:folderURL];
@ -41,13 +41,13 @@ void utils::web::openLinkInBrowser(std::string const& url) {
}
/*@interface FileDialog : NSObject
+ (Result<ghc::filesystem::path>)importDocumentWithMode:(file::PickMode)mode options:(file::FilePickOptions const&)options mult:(bool)mult;
+ (Result<std::vector<ghc::filesystem::path>>)importDocumentsWithOptions:(file::FilePickOptions const&)options;
+ (Result<std::filesystem::path>)importDocumentWithMode:(file::PickMode)mode options:(file::FilePickOptions const&)options mult:(bool)mult;
+ (Result<std::vector<std::filesystem::path>>)importDocumentsWithOptions:(file::FilePickOptions const&)options;
@end
@implementation FileDialog
+ (Result<ghc::filesystem::path>)importDocumentWithMode:(file::PickMode)mode options:(file::FilePickOptions const&)options mult:(bool)mult {
+ (Result<std::filesystem::path>)importDocumentWithMode:(file::PickMode)mode options:(file::FilePickOptions const&)options mult:(bool)mult {
NSOpenPanel* panel = [NSOpenPanel openPanel];
// TODO: [panel setAllowedFileTypes:@[]];
@ -62,7 +62,7 @@ void utils::web::openLinkInBrowser(std::string const& url) {
if (result == NSFileHandlingPanelOKButton) {
auto fileUrl = [[panel URLs] objectAtIndex:0];
auto path = std::string([[fileUrl path] UTF8String], [[fileUrl path] lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
return Ok(ghc::filesystem::path(path));
return Ok(std::filesystem::path(path));
} else {
return Err(result);
}
@ -71,16 +71,16 @@ void utils::web::openLinkInBrowser(std::string const& url) {
@end*/
namespace {
using FileResult = Result<std::vector<ghc::filesystem::path>>;
using FileResult = Result<std::vector<std::filesystem::path>>;
}
@interface FileDialog : NSObject
+(Result<std::vector<ghc::filesystem::path>>) filePickerWithMode:(file::PickMode)mode options:(file::FilePickOptions const&)options multiple:(bool)mult;
+(Result<std::vector<std::filesystem::path>>) filePickerWithMode:(file::PickMode)mode options:(file::FilePickOptions const&)options multiple:(bool)mult;
+(void) dispatchFilePickerWithMode:(file::PickMode)mode options:(file::FilePickOptions const&)options multiple:(bool)mult onCompletion:(void(^)(FileResult))onCompletion;
@end
@implementation FileDialog
+(Result<std::vector<ghc::filesystem::path>>) filePickerWithMode:(file::PickMode)mode options:(file::FilePickOptions const&)options multiple:(bool)mult {
+(Result<std::vector<std::filesystem::path>>) filePickerWithMode:(file::PickMode)mode options:(file::FilePickOptions const&)options multiple:(bool)mult {
NSSavePanel* panel;
if (mode == file::PickMode::SaveFile)
panel = [NSSavePanel savePanel];
@ -133,7 +133,7 @@ namespace {
int result = [panel runModal];
if (result == NSModalResponseOK) {
std::vector<ghc::filesystem::path> fileURLs;
std::vector<std::filesystem::path> fileURLs;
if (mode == file::PickMode::SaveFile) {
fileURLs.push_back(std::string([[[panel URL] path] UTF8String]));
}
@ -159,7 +159,7 @@ namespace {
@end
Result<ghc::filesystem::path> file::pickFile(
Result<std::filesystem::path> file::pickFile(
file::PickMode mode, file::FilePickOptions const& options
) {
return Err("Use the callback version");
@ -167,7 +167,7 @@ Result<ghc::filesystem::path> file::pickFile(
GEODE_DLL void file::pickFile(
PickMode mode, FilePickOptions const& options,
MiniFunction<void(ghc::filesystem::path)> callback,
MiniFunction<void(std::filesystem::path)> callback,
MiniFunction<void()> failed
) {
[FileDialog dispatchFilePickerWithMode:mode options:options multiple:false onCompletion: ^(FileResult result) {
@ -181,7 +181,7 @@ GEODE_DLL void file::pickFile(
}];
}
Result<std::vector<ghc::filesystem::path>> file::pickFiles(
Result<std::vector<std::filesystem::path>> file::pickFiles(
file::FilePickOptions const& options
) {
return Err("Use the callback version");
@ -189,7 +189,7 @@ Result<std::vector<ghc::filesystem::path>> file::pickFiles(
GEODE_DLL void file::pickFiles(
FilePickOptions const& options,
MiniFunction<void(std::vector<ghc::filesystem::path>)> callback,
MiniFunction<void(std::vector<std::filesystem::path>)> callback,
MiniFunction<void()> failed
) {
[FileDialog dispatchFilePickerWithMode: file::PickMode::OpenFile options:options multiple:true onCompletion: ^(FileResult result) {
@ -211,27 +211,27 @@ CCPoint cocos::getMousePos() {
return ccp(mouse.x - windowFrame.origin.x, mouse.y - windowFrame.origin.y) * scaleFactor;
}
ghc::filesystem::path dirs::getGameDir() {
std::filesystem::path dirs::getGameDir() {
static auto path = [] {
std::array<char, PATH_MAX> gddir;
uint32_t out = PATH_MAX;
_NSGetExecutablePath(gddir.data(), &out);
ghc::filesystem::path gdpath = gddir.data();
auto currentPath = ghc::filesystem::canonical(gdpath.parent_path().parent_path());
std::filesystem::path gdpath = gddir.data();
auto currentPath = std::filesystem::canonical(gdpath.parent_path().parent_path());
return currentPath;
}();
return path;
}
ghc::filesystem::path dirs::getSaveDir() {
std::filesystem::path dirs::getSaveDir() {
static auto path = [] {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *applicationSupportDirectory = [paths firstObject];
ghc::filesystem::path supportPath = [applicationSupportDirectory UTF8String];
std::filesystem::path supportPath = [applicationSupportDirectory UTF8String];
auto currentPath = supportPath / "GeometryDash";
return currentPath;
}();
@ -239,7 +239,7 @@ ghc::filesystem::path dirs::getSaveDir() {
return path;
}
ghc::filesystem::path dirs::getModRuntimeDir() {
std::filesystem::path dirs::getModRuntimeDir() {
return dirs::getGeodeDir() / "unzipped";
}

View file

@ -7,9 +7,9 @@ static constexpr auto const notifyAttributes =
FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE;
FileWatcher::FileWatcher(
ghc::filesystem::path const& file, FileWatchCallback callback, ErrorCallback error
std::filesystem::path const& file, FileWatchCallback callback, ErrorCallback error
) {
m_filemode = ghc::filesystem::is_regular_file(file);
m_filemode = std::filesystem::is_regular_file(file);
auto handle = FindFirstChangeNotificationW(
(m_filemode ? file.parent_path() : file).wstring().c_str(), false, notifyAttributes
);
@ -75,8 +75,8 @@ void FileWatcher::watch() {
auto filename = std::wstring(
info->FileName, info->FileName + info->FileNameLength / sizeof(wchar_t)
);
if (ghc::filesystem::exists(m_file) &&
ghc::filesystem::file_size(m_file) > 1000 &&
if (std::filesystem::exists(m_file) &&
std::filesystem::file_size(m_file) > 1000 &&
info->Action == FILE_ACTION_MODIFIED &&
m_file.filename().wstring() == filename) {
m_callback(m_file);

View file

@ -70,7 +70,7 @@ bool Loader::Impl::userTriedToLoadDLLs() const {
std::array<char, MAX_PATH> modName;
if (GetModuleFileNameExA(process, mods[i], modName.data(), modName.size())) {
if (KNOWN_MOD_DLLS.count(string::trim(string::toLower(
ghc::filesystem::path(modName.data()).filename().string()
std::filesystem::path(modName.data()).filename().string()
)))) {
triedToLoadDLLs = true;
}
@ -81,7 +81,7 @@ bool Loader::Impl::userTriedToLoadDLLs() const {
return triedToLoadDLLs;
}
void Loader::Impl::addNativeBinariesPath(ghc::filesystem::path const& path) {
void Loader::Impl::addNativeBinariesPath(std::filesystem::path const& path) {
// https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-adddlldirectory#remarks
static auto runOnce = [] {
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);

View file

@ -47,7 +47,7 @@ static std::string getModuleName(HMODULE module, bool fullPath = true) {
if (fullPath) {
return buffer;
}
return ghc::filesystem::path(buffer).filename().string();
return std::filesystem::path(buffer).filename().string();
}
static char const* getExceptionCodeString(DWORD code) {
@ -373,10 +373,10 @@ bool crashlog::setupPlatformHandler() {
SetUnhandledExceptionFilter(exceptionHandler);
auto lastCrashedFile = crashlog::getCrashLogDirectory() / "last-crashed";
if (ghc::filesystem::exists(lastCrashedFile)) {
if (std::filesystem::exists(lastCrashedFile)) {
g_lastLaunchCrashed = true;
try {
ghc::filesystem::remove(lastCrashedFile);
std::filesystem::remove(lastCrashedFile);
}
catch (...) {
}
@ -390,6 +390,6 @@ bool crashlog::didLastLaunchCrash() {
void crashlog::setupPlatformHandlerPost() {}
ghc::filesystem::path crashlog::getCrashLogDirectory() {
std::filesystem::path crashlog::getCrashLogDirectory() {
return dirs::getGeodeDir() / "crashlogs";
}

View file

@ -13,16 +13,16 @@ void updateGeode() {
const auto geodeDir = dirs::getGeodeDir();
const auto updatesDir = geodeDir / "update";
bool bootstrapperExists = ghc::filesystem::exists(workingDir / "GeodeBootstrapper.dll");
bool updatesDirExists = ghc::filesystem::exists(geodeDir) && ghc::filesystem::exists(updatesDir);
bool bootstrapperExists = std::filesystem::exists(workingDir / "GeodeBootstrapper.dll");
bool updatesDirExists = std::filesystem::exists(geodeDir) && std::filesystem::exists(updatesDir);
if (!bootstrapperExists && !updatesDirExists)
return;
// update updater
if (ghc::filesystem::exists(updatesDir) &&
ghc::filesystem::exists(updatesDir / "GeodeUpdater.exe"))
ghc::filesystem::rename(updatesDir / "GeodeUpdater.exe", workingDir / "GeodeUpdater.exe");
if (std::filesystem::exists(updatesDir) &&
std::filesystem::exists(updatesDir / "GeodeUpdater.exe"))
std::filesystem::rename(updatesDir / "GeodeUpdater.exe", workingDir / "GeodeUpdater.exe");
utils::game::restart();
}
@ -283,7 +283,7 @@ BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID) {
// if we find the old bootstrapper dll, don't load geode, copy new updater and let it do the rest
auto workingDir = dirs::getGameDir();
std::error_code error;
bool oldBootstrapperExists = ghc::filesystem::exists(workingDir / "GeodeBootstrapper.dll", error);
bool oldBootstrapperExists = std::filesystem::exists(workingDir / "GeodeBootstrapper.dll", error);
if (error) {
earlyError("There was an error checking whether the old GeodeBootstrapper.dll exists: " + error.message());
return FALSE;

View file

@ -2,8 +2,8 @@
#include <Geode/utils/string.hpp>
#include <algorithm>
using Path = ghc::filesystem::path;
using Paths = std::vector<ghc::filesystem::path>;
using Path = std::filesystem::path;
using Paths = std::vector<std::filesystem::path>;
static BOOL COMIsInitialized(HRESULT coResult) {
if (coResult == RPC_E_CHANGED_MODE) {
@ -83,7 +83,7 @@ static Result<Paths> convShellItems(IShellItemArray* shellItems) {
return Err("Unable to get shell item count");
}
std::vector<ghc::filesystem::path> paths;
std::vector<std::filesystem::path> paths;
for (DWORD i = 0; i < shellItemCount; i++) {
IShellItem* shellItem;
if (!SUCCEEDED(shellItems->GetItemAt(i, &shellItem))) {
@ -110,7 +110,7 @@ static Result<Paths> convShellItems(IShellItemArray* shellItems) {
static bool setDefaultPath(
IFileDialog* dialog,
ghc::filesystem::path const& defaultPath
std::filesystem::path const& defaultPath
) {
IShellItem* folder;
if (!SUCCEEDED(SHCreateItemFromParsingName(
@ -126,7 +126,7 @@ static bool setDefaultPath(
static bool setDefaultFile(
IFileDialog* dialog,
ghc::filesystem::path const& fileName
std::filesystem::path const& fileName
) {
dialog->SetFileName(fileName.wstring().c_str());
return true;
@ -181,9 +181,9 @@ Result<> nfdPick(
return Err("Unable to add filters to dialog");
}
if (options.defaultPath && options.defaultPath.value().wstring().size()) {
ghc::filesystem::path path = options.defaultPath.value();
std::filesystem::path path = options.defaultPath.value();
if (mode == NFDMode::OpenFile || mode == NFDMode::SaveFile) {
if (!ghc::filesystem::exists(path) || !ghc::filesystem::is_directory(path)) {
if (!std::filesystem::exists(path) || !std::filesystem::is_directory(path)) {
if (path.has_filename()) {
setDefaultFile(dialog, path.filename());
}

View file

@ -4,7 +4,7 @@ using namespace geode::prelude;
#include <Geode/loader/Dirs.hpp>
#include "nfdwin.hpp"
#include <ghc/fs_fwd.hpp>
#include <filesystem>
#include <Windows.h>
#include <processthreadsapi.h>
#include <iostream>
@ -76,7 +76,7 @@ std::string utils::clipboard::read() {
return text;
}
bool utils::file::openFolder(ghc::filesystem::path const& path) {
bool utils::file::openFolder(std::filesystem::path const& path) {
// mods can (and do) keep CoInitializeEx initialized on the main thread
// which results in this function just not doing anything
// which is why we're using a separate thread
@ -85,9 +85,9 @@ bool utils::file::openFolder(ghc::filesystem::path const& path) {
auto thread = std::thread([](auto const& path, bool& success) {
if (CoInitializeEx(nullptr, COINIT_MULTITHREADED) == S_OK) {
if (auto id = ILCreateFromPathW(path.wstring().c_str())) {
ghc::filesystem::path selectPath = path / ".";
std::filesystem::path selectPath = path / ".";
std::error_code whatever;
if (!ghc::filesystem::is_directory(path, whatever)) {
if (!std::filesystem::is_directory(path, whatever)) {
selectPath = path;
}
auto selectEntry = ILCreateFromPathW(selectPath.wstring().c_str());
@ -103,7 +103,7 @@ bool utils::file::openFolder(ghc::filesystem::path const& path) {
return success;
}
Result<ghc::filesystem::path> utils::file::pickFile(
Result<std::filesystem::path> utils::file::pickFile(
file::PickMode mode, file::FilePickOptions const& options
) {
#define TURN_INTO_NFDMODE(mode) \
@ -116,14 +116,14 @@ Result<ghc::filesystem::path> utils::file::pickFile(
TURN_INTO_NFDMODE(OpenFolder);
default: return Err<std::string>("Unknown open mode");
}
ghc::filesystem::path path;
std::filesystem::path path;
GEODE_UNWRAP(nfdPick(nfdMode, options, &path));
return Ok(path);
}
void file::pickFile(
PickMode mode, FilePickOptions const& options,
MiniFunction<void(ghc::filesystem::path)> callback,
MiniFunction<void(std::filesystem::path)> callback,
MiniFunction<void()> failed
) {
auto result = file::pickFile(mode, options);
@ -136,21 +136,21 @@ void file::pickFile(
}
}
}
Task<Result<ghc::filesystem::path>> file::pick(PickMode mode, FilePickOptions const& options) {
return Task<Result<ghc::filesystem::path>>::immediate(std::move(file::pickFile(mode, options)));
Task<Result<std::filesystem::path>> file::pick(PickMode mode, FilePickOptions const& options) {
return Task<Result<std::filesystem::path>>::immediate(std::move(file::pickFile(mode, options)));
}
Result<std::vector<ghc::filesystem::path>> utils::file::pickFiles(
Result<std::vector<std::filesystem::path>> utils::file::pickFiles(
file::FilePickOptions const& options
) {
std::vector<ghc::filesystem::path> paths;
std::vector<std::filesystem::path> paths;
GEODE_UNWRAP(nfdPick(NFDMode::OpenFiles, options, &paths));
return Ok(paths);
}
void file::pickFiles(
FilePickOptions const& options,
MiniFunction<void(std::vector<ghc::filesystem::path>)> callback,
MiniFunction<void(std::vector<std::filesystem::path>)> callback,
MiniFunction<void()> failed
) {
auto result = file::pickFiles(options);
@ -163,8 +163,8 @@ void file::pickFiles(
}
}
}
Task<Result<std::vector<ghc::filesystem::path>>> file::pickMany(FilePickOptions const& options) {
return Task<Result<std::vector<ghc::filesystem::path>>>::immediate(std::move(file::pickFiles(options)));
Task<Result<std::vector<std::filesystem::path>>> file::pickMany(FilePickOptions const& options) {
return Task<Result<std::vector<std::filesystem::path>>>::immediate(std::move(file::pickFiles(options)));
}
void utils::web::openLinkInBrowser(std::string const& url) {
@ -180,33 +180,33 @@ CCPoint cocos::getMousePos() {
return ccp(mouse.x, 1.f - mouse.y) * winSize;
}
ghc::filesystem::path dirs::getGameDir() {
std::filesystem::path dirs::getGameDir() {
// only fetch the path once, since ofc it'll never change
// throughout the execution
static const auto path = [] {
std::array<WCHAR, MAX_PATH> buffer;
GetModuleFileNameW(NULL, buffer.data(), MAX_PATH);
const ghc::filesystem::path path(buffer.data());
const std::filesystem::path path(buffer.data());
return std::filesystem::weakly_canonical(path.parent_path().wstring()).wstring();
}();
return path;
}
ghc::filesystem::path dirs::getSaveDir() {
std::filesystem::path dirs::getSaveDir() {
// only fetch the path once, since ofc it'll never change
// throughout the execution
static const auto path = [] {
std::array<WCHAR, MAX_PATH + 1> buffer;
GetModuleFileNameW(NULL, buffer.data(), MAX_PATH + 1);
auto executablePath = ghc::filesystem::path(buffer.data());
auto executablePath = std::filesystem::path(buffer.data());
auto executableName = executablePath.filename().wstring();
executableName = executableName.substr(0, executableName.find_last_of(L"."));
if (SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buffer.data()) >= 0) {
auto appdataPath = ghc::filesystem::path(buffer.data());
auto appdataPath = std::filesystem::path(buffer.data());
auto savePath = appdataPath / executableName;
if (SHCreateDirectoryExW(NULL, savePath.wstring().c_str(), NULL) >= 0) {
@ -220,7 +220,7 @@ ghc::filesystem::path dirs::getSaveDir() {
return path;
}
ghc::filesystem::path dirs::getModRuntimeDir() {
std::filesystem::path dirs::getModRuntimeDir() {
return dirs::getGeodeDir() / "unzipped";
}
@ -259,7 +259,7 @@ void geode::utils::game::restart() {
wchar_t buffer[MAX_PATH];
GetModuleFileNameW(nullptr, buffer, MAX_PATH);
const auto gdName = fmt::format("\"{}\"", ghc::filesystem::path(buffer).filename().string());
const auto gdName = fmt::format("\"{}\"", std::filesystem::path(buffer).filename().string());
// launch updater
const auto updaterPath = (workingDir / "GeodeUpdater.exe").string();

View file

@ -100,7 +100,7 @@ public:
// If this was an update, delete the old file first
if (auto mod = Loader::get()->getInstalledMod(m_id)) {
std::error_code ec;
ghc::filesystem::remove(mod->getPackagePath(), ec);
std::filesystem::remove(mod->getPackagePath(), ec);
if (ec) {
removingInstalledWasError = true;
m_status = DownloadStatusError {

View file

@ -21,8 +21,8 @@
using namespace geode::prelude;
using namespace geode::utils::file;
Result<std::string> utils::file::readString(ghc::filesystem::path const& path) {
if (!ghc::filesystem::exists(path))
Result<std::string> utils::file::readString(std::filesystem::path const& path) {
if (!std::filesystem::exists(path))
return Err("File does not exist");
#if _WIN32
@ -42,7 +42,7 @@ Result<std::string> utils::file::readString(ghc::filesystem::path const& path) {
return Ok(contents);
}
Result<matjson::Value> utils::file::readJson(ghc::filesystem::path const& path) {
Result<matjson::Value> utils::file::readJson(std::filesystem::path const& path) {
auto str = utils::file::readString(path);
if (!str)
return Err(str.unwrapErr());
@ -53,8 +53,8 @@ Result<matjson::Value> utils::file::readJson(ghc::filesystem::path const& path)
return Ok(res.value());
}
Result<ByteVector> utils::file::readBinary(ghc::filesystem::path const& path) {
if (!ghc::filesystem::exists(path))
Result<ByteVector> utils::file::readBinary(std::filesystem::path const& path) {
if (!std::filesystem::exists(path))
return Err("File does not exist");
#if _WIN32
@ -68,7 +68,7 @@ Result<ByteVector> utils::file::readBinary(ghc::filesystem::path const& path) {
return Ok(ByteVector(std::istreambuf_iterator<char>(in), {}));
}
Result<> utils::file::writeString(ghc::filesystem::path const& path, std::string const& data) {
Result<> utils::file::writeString(std::filesystem::path const& path, std::string const& data) {
std::ofstream file;
#if _WIN32
file.open(path.wstring());
@ -85,7 +85,7 @@ Result<> utils::file::writeString(ghc::filesystem::path const& path, std::string
return Ok();
}
Result<> utils::file::writeBinary(ghc::filesystem::path const& path, ByteVector const& data) {
Result<> utils::file::writeBinary(std::filesystem::path const& path, ByteVector const& data) {
std::ofstream file;
#if _WIN32
file.open(path.wstring(), std::ios::out | std::ios::binary);
@ -102,12 +102,12 @@ Result<> utils::file::writeBinary(ghc::filesystem::path const& path, ByteVector
return Ok();
}
Result<> utils::file::createDirectory(ghc::filesystem::path const& path) {
Result<> utils::file::createDirectory(std::filesystem::path const& path) {
std::error_code ec;
#ifdef GEODE_IS_WINDOWS
std::filesystem::create_directory(path.wstring(), ec);
#else
ghc::filesystem::create_directory(path, ec);
std::filesystem::create_directory(path, ec);
#endif
if (ec) {
return Err("Unable to create directory");
@ -115,12 +115,12 @@ Result<> utils::file::createDirectory(ghc::filesystem::path const& path) {
return Ok();
}
Result<> utils::file::createDirectoryAll(ghc::filesystem::path const& path) {
Result<> utils::file::createDirectoryAll(std::filesystem::path const& path) {
std::error_code ec;
#ifdef GEODE_IS_WINDOWS
std::filesystem::create_directories(path.wstring(), ec);
#else
ghc::filesystem::create_directories(path, ec);
std::filesystem::create_directories(path, ec);
#endif
if (ec) {
return Err("Unable to create directory");
@ -128,22 +128,22 @@ Result<> utils::file::createDirectoryAll(ghc::filesystem::path const& path) {
return Ok();
}
Result<std::vector<ghc::filesystem::path>> utils::file::readDirectory(
ghc::filesystem::path const& path, bool recursive
Result<std::vector<std::filesystem::path>> utils::file::readDirectory(
std::filesystem::path const& path, bool recursive
) {
if (!ghc::filesystem::exists(path)) {
if (!std::filesystem::exists(path)) {
return Err("Directory does not exist");
}
if (!ghc::filesystem::is_directory(path)) {
if (!std::filesystem::is_directory(path)) {
return Err("Path is not a directory");
}
std::vector<ghc::filesystem::path> res;
std::vector<std::filesystem::path> res;
if (recursive) {
for (auto const& file : ghc::filesystem::recursive_directory_iterator(path)) {
for (auto const& file : std::filesystem::recursive_directory_iterator(path)) {
res.push_back(file.path());
}
} else {
for (auto const& file : ghc::filesystem::directory_iterator(path)) {
for (auto const& file : std::filesystem::directory_iterator(path)) {
res.push_back(file.path());
}
}
@ -347,7 +347,7 @@ public:
#ifdef GEODE_IS_WINDOWS
if (!std::filesystem::relative((dir / filePath).wstring(), dir.wstring()).empty()) {
#else
if (!ghc::filesystem::relative(dir / filePath, dir).empty()) {
if (!std::filesystem::relative(dir / filePath, dir).empty()) {
#endif
if (m_entries.at(filePath).isDirectory) {
GEODE_UNWRAP(file::createDirectoryAll(dir / filePath));
@ -568,7 +568,7 @@ Result<> Unzip::intoDir(
}
if (deleteZipAfter) {
std::error_code ec;
ghc::filesystem::remove(from, ec);
std::filesystem::remove(from, ec);
}
return Ok();
}
@ -584,7 +584,7 @@ Result<> Unzip::intoDir(
GEODE_UNWRAP(unzip.extractAllTo(to));
if (deleteZipAfter) {
std::error_code ec;
ghc::filesystem::remove(from, ec);
std::filesystem::remove(from, ec);
}
return Ok();
}
@ -634,8 +634,8 @@ Result<> Zip::addFrom(Path const& file, Path const& entryDir) {
Result<> Zip::addAllFromRecurse(Path const& dir, Path const& entry) {
GEODE_UNWRAP(this->addFolder(entry / dir.filename()));
for (auto& file : ghc::filesystem::directory_iterator(dir)) {
if (ghc::filesystem::is_directory(file)) {
for (auto& file : std::filesystem::directory_iterator(dir)) {
if (std::filesystem::is_directory(file)) {
GEODE_UNWRAP(this->addAllFromRecurse(file, entry / dir.filename()));
} else {
GEODE_UNWRAP_INTO(auto data, file::readBinary(file));
@ -646,7 +646,7 @@ Result<> Zip::addAllFromRecurse(Path const& dir, Path const& entry) {
}
Result<> Zip::addAllFrom(Path const& dir) {
if (!ghc::filesystem::is_directory(dir)) {
if (!std::filesystem::is_directory(dir)) {
return Err("Path is not a directory");
}
return this->addAllFromRecurse(dir, Path());
@ -656,10 +656,10 @@ Result<> Zip::addFolder(Path const& entry) {
return m_impl->addFolder(entry);
}
FileWatchEvent::FileWatchEvent(ghc::filesystem::path const& path)
FileWatchEvent::FileWatchEvent(std::filesystem::path const& path)
: m_path(path) {}
ghc::filesystem::path FileWatchEvent::getPath() const {
std::filesystem::path FileWatchEvent::getPath() const {
return m_path;
}
@ -668,22 +668,22 @@ ListenerResult FileWatchFilter::handle(
FileWatchEvent* event
) {
std::error_code ec;
if (ghc::filesystem::equivalent(event->getPath(), m_path, ec)) {
if (std::filesystem::equivalent(event->getPath(), m_path, ec)) {
callback(event);
}
return ListenerResult::Propagate;
}
FileWatchFilter::FileWatchFilter(ghc::filesystem::path const& path)
FileWatchFilter::FileWatchFilter(std::filesystem::path const& path)
: m_path(path) {}
// This is a vector because need to use ghc::filesystem::equivalent for
// This is a vector because need to use std::filesystem::equivalent for
// comparisons and removal is not exactly performance-critical here
// (who's going to add and remove 500 file watchers every frame)
static std::vector<std::unique_ptr<FileWatcher>> FILE_WATCHERS {};
Result<> file::watchFile(ghc::filesystem::path const& file) {
if (!ghc::filesystem::exists(file)) {
Result<> file::watchFile(std::filesystem::path const& file) {
if (!std::filesystem::exists(file)) {
return Err("File does not exist");
}
auto watcher = std::make_unique<FileWatcher>(
@ -701,8 +701,8 @@ Result<> file::watchFile(ghc::filesystem::path const& file) {
return Ok();
}
void file::unwatchFile(ghc::filesystem::path const& file) {
void file::unwatchFile(std::filesystem::path const& file) {
ranges::remove(FILE_WATCHERS, [=](std::unique_ptr<FileWatcher> const& watcher) {
return ghc::filesystem::equivalent(file, watcher->path());
return std::filesystem::equivalent(file, watcher->path());
});
}

View file

@ -32,7 +32,7 @@ namespace geode::utils::fetch {
}
Result<> web::fetchFile(
std::string const& url, ghc::filesystem::path const& into, FileProgressCallback prog
std::string const& url, std::filesystem::path const& into, FileProgressCallback prog
) {
auto curl = curl_easy_init();
@ -170,7 +170,7 @@ private:
std::string m_postFields;
bool m_isJsonRequest = false;
bool m_sent = false;
std::variant<std::monostate, std::ostream*, ghc::filesystem::path> m_target;
std::variant<std::monostate, std::ostream*, std::filesystem::path> m_target;
std::vector<std::string> m_httpHeaders;
@ -211,7 +211,7 @@ public:
std::string m_postFields;
bool m_isJsonRequest = false;
bool m_sent = false;
std::variant<std::monostate, std::ostream*, ghc::filesystem::path> m_target;
std::variant<std::monostate, std::ostream*, std::filesystem::path> m_target;
std::vector<std::string> m_httpHeaders;
std::chrono::seconds m_timeoutSeconds;
@ -270,9 +270,9 @@ SentAsyncWebRequest::Impl::Impl(SentAsyncWebRequest* self, AsyncWebRequest const
std::unique_ptr<std::ofstream> file = nullptr;
// into file
if (std::holds_alternative<ghc::filesystem::path>(m_target)) {
if (std::holds_alternative<std::filesystem::path>(m_target)) {
file = std::make_unique<std::ofstream>(
std::get<ghc::filesystem::path>(m_target), std::ios::out | std::ios::binary
std::get<std::filesystem::path>(m_target), std::ios::out | std::ios::binary
);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file.get());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, utils::fetch::writeBinaryData);
@ -432,11 +432,11 @@ void SentAsyncWebRequest::Impl::doCancel() {
m_cleanedUp = true;
// remove file if downloaded to one
if (std::holds_alternative<ghc::filesystem::path>(m_target)) {
auto path = std::get<ghc::filesystem::path>(m_target);
if (ghc::filesystem::exists(path)) {
if (std::holds_alternative<std::filesystem::path>(m_target)) {
auto path = std::get<std::filesystem::path>(m_target);
if (std::filesystem::exists(path)) {
std::error_code ec;
ghc::filesystem::remove(path, ec);
std::filesystem::remove(path, ec);
}
}
@ -688,7 +688,7 @@ AsyncWebResult<std::monostate> AsyncWebResponse::into(std::ostream& stream) {
});
}
AsyncWebResult<std::monostate> AsyncWebResponse::into(ghc::filesystem::path const& path) {
AsyncWebResult<std::monostate> AsyncWebResponse::into(std::filesystem::path const& path) {
m_request.m_impl->m_target = path;
return this->as(+[](ByteVector const&) -> Result<std::monostate> {
return Ok(std::monostate());