mirror of
https://github.com/geode-sdk/geode.git
synced 2024-12-18 03:42:25 -05:00
initial new file commit
This commit is contained in:
parent
1c40a63e33
commit
9d9c03f0f6
4 changed files with 72 additions and 111 deletions
|
@ -252,35 +252,35 @@ namespace geode::utils::file {
|
||||||
std::vector<Filter> filters;
|
std::vector<Filter> filters;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Prompt the user to pick a file using the system's file system picker
|
// * Prompt the user to pick a file using the system's file system picker
|
||||||
* @deprecated Will not work on Android, use the callback version instead
|
// * @deprecated Will not work on Android, use the callback version instead
|
||||||
* @param mode Type of file selection prompt to show
|
// * @param mode Type of file selection prompt to show
|
||||||
* @param options Picker options
|
// * @param options Picker options
|
||||||
*/
|
// */
|
||||||
[[deprecated("Use pick() instead, this will be removed in a later version.")]]
|
// [[deprecated("Use pick() instead, this will be removed in a later version.")]]
|
||||||
GEODE_DLL Result<std::filesystem::path> pickFile(PickMode mode, FilePickOptions const& options);
|
// GEODE_DLL Result<std::filesystem::path> pickFile(PickMode mode, FilePickOptions const& options);
|
||||||
|
|
||||||
GEODE_DLL void pickFile(
|
// GEODE_DLL void pickFile(
|
||||||
PickMode mode, FilePickOptions const& options,
|
// PickMode mode, FilePickOptions const& options,
|
||||||
utils::MiniFunction<void(std::filesystem::path)> callback,
|
// utils::MiniFunction<void(std::filesystem::path)> callback,
|
||||||
utils::MiniFunction<void()> failed = {}
|
// utils::MiniFunction<void()> failed = {}
|
||||||
);
|
// );
|
||||||
GEODE_DLL Task<Result<std::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
|
// * Prompt the user to pick a bunch of files for opening using the system's file system picker
|
||||||
* @deprecated Will not work on Android, use the callback version instead
|
// * @deprecated Will not work on Android, use the callback version instead
|
||||||
* @param options Picker options
|
// * @param options Picker options
|
||||||
*/
|
// */
|
||||||
[[deprecated("Use pickMany() instead, this will be removed in a later version.")]]
|
// [[deprecated("Use pickMany() instead, this will be removed in a later version.")]]
|
||||||
GEODE_DLL Result<std::vector<std::filesystem::path>> pickFiles(FilePickOptions const& options);
|
// GEODE_DLL Result<std::vector<std::filesystem::path>> pickFiles(FilePickOptions const& options);
|
||||||
|
|
||||||
GEODE_DLL void pickFiles(
|
// GEODE_DLL void pickFiles(
|
||||||
FilePickOptions const& options,
|
// FilePickOptions const& options,
|
||||||
utils::MiniFunction<void(std::vector<std::filesystem::path>)> callback,
|
// utils::MiniFunction<void(std::vector<std::filesystem::path>)> callback,
|
||||||
utils::MiniFunction<void()> failed = {}
|
// utils::MiniFunction<void()> failed = {}
|
||||||
);
|
// );
|
||||||
GEODE_DLL Task<Result<std::vector<std::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 {
|
class GEODE_DLL FileWatchEvent : public Event {
|
||||||
|
|
|
@ -10,6 +10,7 @@ using namespace geode::prelude;
|
||||||
#include <Geode/utils/general.hpp>
|
#include <Geode/utils/general.hpp>
|
||||||
#include <Geode/utils/MiniFunction.hpp>
|
#include <Geode/utils/MiniFunction.hpp>
|
||||||
#include <Geode/utils/permission.hpp>
|
#include <Geode/utils/permission.hpp>
|
||||||
|
#include <Geode/utils/Task.hpp>
|
||||||
#include <Geode/loader/Loader.hpp>
|
#include <Geode/loader/Loader.hpp>
|
||||||
#include <Geode/binding/AppDelegate.hpp>
|
#include <Geode/binding/AppDelegate.hpp>
|
||||||
#include <Geode/loader/Log.hpp>
|
#include <Geode/loader/Log.hpp>
|
||||||
|
@ -194,6 +195,13 @@ Result<std::filesystem::path> file::pickFile(file::PickMode mode, file::FilePick
|
||||||
return Err("Use the callback version");
|
return Err("Use the callback version");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GEODE_DLL Task<Result<std::filesystem::path>> pick(PickMode mode, FilePickOptions const& options) {
|
||||||
|
using RetTask = Task<Result<std::filesystem::path>>
|
||||||
|
return RetTask::runWithCallback([] (auto resultCallback, auto progressCallback, auto cancelCallback) {
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void file::pickFile(
|
void file::pickFile(
|
||||||
PickMode mode, FilePickOptions const& options,
|
PickMode mode, FilePickOptions const& options,
|
||||||
MiniFunction<void(std::filesystem::path)> callback,
|
MiniFunction<void(std::filesystem::path)> callback,
|
||||||
|
|
|
@ -8,6 +8,7 @@ using namespace geode::prelude;
|
||||||
#include <Geode/binding/GameManager.hpp>
|
#include <Geode/binding/GameManager.hpp>
|
||||||
#include <objc/runtime.h>
|
#include <objc/runtime.h>
|
||||||
#include <Geode/utils/web.hpp>
|
#include <Geode/utils/web.hpp>
|
||||||
|
#include <Geode/utils/Task.hpp>
|
||||||
|
|
||||||
#define CommentType CommentTypeDummy
|
#define CommentType CommentTypeDummy
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
@ -159,48 +160,27 @@ namespace {
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
Result<std::filesystem::path> file::pickFile(
|
GEODE_DLL Task<Result<std::filesystem::path>> pick(PickMode mode, FilePickOptions const& options) {
|
||||||
file::PickMode mode, file::FilePickOptions const& options
|
using RetTask = Task<Result<std::filesystem::path>>;
|
||||||
) {
|
|
||||||
return Err("Use the callback version");
|
|
||||||
}
|
|
||||||
|
|
||||||
GEODE_DLL void file::pickFile(
|
|
||||||
PickMode mode, FilePickOptions const& options,
|
|
||||||
MiniFunction<void(std::filesystem::path)> callback,
|
|
||||||
MiniFunction<void()> failed
|
|
||||||
) {
|
|
||||||
[FileDialog dispatchFilePickerWithMode:mode options:options multiple:false onCompletion: ^(FileResult result) {
|
[FileDialog dispatchFilePickerWithMode:mode options:options multiple:false onCompletion: ^(FileResult result) {
|
||||||
Loader::get()->queueInMainThread([=]() {
|
|
||||||
if (result.isOk()) {
|
if (result.isOk()) {
|
||||||
callback(std::move(result.unwrap()[0]));
|
return RetTask::immediate(std::move(result.unwrap()[0]));
|
||||||
} else {
|
} else {
|
||||||
failed();
|
return RetTask::immediate(Err("Couldn't open file"));
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<std::vector<std::filesystem::path>> file::pickFiles(
|
GEODE_DLL Task<Result<std::vector<std::filesystem::path>>> pickMany(FilePickOptions const& options) {
|
||||||
file::FilePickOptions const& options
|
using RetTask = Task<Result<std::vector<std::filesystem::path>>>;
|
||||||
) {
|
[FileDialog dispatchFilePickerWithMode:mode options:options multiple:true onCompletion: ^(FileResult result) {
|
||||||
return Err("Use the callback version");
|
|
||||||
}
|
|
||||||
|
|
||||||
GEODE_DLL void file::pickFiles(
|
|
||||||
FilePickOptions const& options,
|
|
||||||
MiniFunction<void(std::vector<std::filesystem::path>)> callback,
|
|
||||||
MiniFunction<void()> failed
|
|
||||||
) {
|
|
||||||
[FileDialog dispatchFilePickerWithMode: file::PickMode::OpenFile options:options multiple:true onCompletion: ^(FileResult result) {
|
|
||||||
Loader::get()->queueInMainThread([=]() {
|
|
||||||
if (result.isOk()) {
|
if (result.isOk()) {
|
||||||
callback(std::move(result.unwrap()));
|
return RetTask::immediate(std::move(result.unwrap()));
|
||||||
} else {
|
} else {
|
||||||
failed();
|
return RetTask::immediate(Err("Couldn't open file"));
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}];
|
}];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CCPoint cocos::getMousePos() {
|
CCPoint cocos::getMousePos() {
|
||||||
|
|
|
@ -7,11 +7,9 @@ using namespace geode::prelude;
|
||||||
#include "nfdwin.hpp"
|
#include "nfdwin.hpp"
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <processthreadsapi.h>
|
#include <processthreadsapi.h>
|
||||||
#include <iostream>
|
|
||||||
#include <ShlObj.h>
|
#include <ShlObj.h>
|
||||||
#include <shlwapi.h>
|
#include <shlwapi.h>
|
||||||
#include <shobjidl.h>
|
#include <shobjidl.h>
|
||||||
#include <sstream>
|
|
||||||
#include <Geode/utils/web.hpp>
|
#include <Geode/utils/web.hpp>
|
||||||
#include <Geode/utils/cocos.hpp>
|
#include <Geode/utils/cocos.hpp>
|
||||||
#include <Geode/loader/Log.hpp>
|
#include <Geode/loader/Log.hpp>
|
||||||
|
@ -103,9 +101,8 @@ bool utils::file::openFolder(std::filesystem::path const& path) {
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<std::filesystem::path> utils::file::pickFile(
|
Task<Result<std::filesystem::path>> file::pick(PickMode mode, FilePickOptions const& options) {
|
||||||
file::PickMode mode, file::FilePickOptions const& options
|
using RetTask = Task<Result<std::filesystem::path>>;
|
||||||
) {
|
|
||||||
#define TURN_INTO_NFDMODE(mode) \
|
#define TURN_INTO_NFDMODE(mode) \
|
||||||
case file::PickMode::mode: nfdMode = NFDMode::mode; break;
|
case file::PickMode::mode: nfdMode = NFDMode::mode; break;
|
||||||
|
|
||||||
|
@ -114,57 +111,33 @@ Result<std::filesystem::path> utils::file::pickFile(
|
||||||
TURN_INTO_NFDMODE(OpenFile);
|
TURN_INTO_NFDMODE(OpenFile);
|
||||||
TURN_INTO_NFDMODE(SaveFile);
|
TURN_INTO_NFDMODE(SaveFile);
|
||||||
TURN_INTO_NFDMODE(OpenFolder);
|
TURN_INTO_NFDMODE(OpenFolder);
|
||||||
default: return Err<std::string>("Unknown open mode");
|
default:
|
||||||
|
return RetTask::immediate(Err<std::string>("Invalid pick mode"));
|
||||||
}
|
}
|
||||||
std::filesystem::path path;
|
std::filesystem::path path;
|
||||||
GEODE_UNWRAP(nfdPick(nfdMode, options, &path));
|
Result<std::filesystem::path> result;
|
||||||
return Ok(path);
|
auto pickresult = nfdPick(nfdMode, options, &path);
|
||||||
}
|
if (pickresult.isErr()) {
|
||||||
|
result = Err(pickresult.err().value());
|
||||||
void file::pickFile(
|
|
||||||
PickMode mode, FilePickOptions const& options,
|
|
||||||
MiniFunction<void(std::filesystem::path)> callback,
|
|
||||||
MiniFunction<void()> failed
|
|
||||||
) {
|
|
||||||
auto result = file::pickFile(mode, options);
|
|
||||||
|
|
||||||
if (result.isOk()) {
|
|
||||||
callback(std::move(result.unwrap()));
|
|
||||||
} else {
|
} else {
|
||||||
if (failed) {
|
result = Ok(path);
|
||||||
failed();
|
|
||||||
}
|
}
|
||||||
}
|
return RetTask::immediate(std::move(result));
|
||||||
}
|
|
||||||
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<std::filesystem::path>> utils::file::pickFiles(
|
|
||||||
file::FilePickOptions const& options
|
|
||||||
) {
|
|
||||||
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<std::filesystem::path>)> callback,
|
|
||||||
MiniFunction<void()> failed
|
|
||||||
) {
|
|
||||||
auto result = file::pickFiles(options);
|
|
||||||
|
|
||||||
if (result.isOk()) {
|
|
||||||
callback(std::move(result.unwrap()));
|
|
||||||
} else {
|
|
||||||
if (failed) {
|
|
||||||
failed();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Task<Result<std::vector<std::filesystem::path>>> file::pickMany(FilePickOptions const& 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)));
|
using RetTask = Task<Result<std::vector<std::filesystem::path>>>;
|
||||||
|
|
||||||
|
std::vector<std::filesystem::path> paths;
|
||||||
|
auto pickResult = nfdPick(NFDMode::OpenFiles, options, &paths);
|
||||||
|
Result<std::vector<std::filesystem::path>> result;
|
||||||
|
if (pickResult.isErr()) {
|
||||||
|
result = Err(pickResult.err().value());
|
||||||
|
} else {
|
||||||
|
result = Ok(paths);
|
||||||
|
}
|
||||||
|
return RetTask::immediate(std::move(result));
|
||||||
|
// return Task<Result<std::vector<std::filesystem::path>>>::immediate(std::move(file::pickFiles(options)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void utils::web::openLinkInBrowser(std::string const& url) {
|
void utils::web::openLinkInBrowser(std::string const& url) {
|
||||||
|
|
Loading…
Reference in a new issue