diff --git a/loader/include/Geode/utils/file.hpp b/loader/include/Geode/utils/file.hpp index 7378c882..7c315dc8 100644 --- a/loader/include/Geode/utils/file.hpp +++ b/loader/include/Geode/utils/file.hpp @@ -252,35 +252,35 @@ namespace geode::utils::file { std::vector filters; }; - /** - * 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 - * @param mode Type of file selection prompt to show - * @param options Picker options - */ - [[deprecated("Use pick() instead, this will be removed in a later version.")]] - GEODE_DLL Result pickFile(PickMode mode, FilePickOptions const& options); + // /** + // * 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 + // * @param mode Type of file selection prompt to show + // * @param options Picker options + // */ + // [[deprecated("Use pick() instead, this will be removed in a later version.")]] + // GEODE_DLL Result pickFile(PickMode mode, FilePickOptions const& options); - GEODE_DLL void pickFile( - PickMode mode, FilePickOptions const& options, - utils::MiniFunction callback, - utils::MiniFunction failed = {} - ); + // GEODE_DLL void pickFile( + // PickMode mode, FilePickOptions const& options, + // utils::MiniFunction callback, + // utils::MiniFunction failed = {} + // ); GEODE_DLL Task> pick(PickMode mode, FilePickOptions const& options); - /** - * 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 - * @param options Picker options - */ - [[deprecated("Use pickMany() instead, this will be removed in a later version.")]] - GEODE_DLL Result> pickFiles(FilePickOptions const& options); + // /** + // * 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 + // * @param options Picker options + // */ + // [[deprecated("Use pickMany() instead, this will be removed in a later version.")]] + // GEODE_DLL Result> pickFiles(FilePickOptions const& options); - GEODE_DLL void pickFiles( - FilePickOptions const& options, - utils::MiniFunction)> callback, - utils::MiniFunction failed = {} - ); + // GEODE_DLL void pickFiles( + // FilePickOptions const& options, + // utils::MiniFunction)> callback, + // utils::MiniFunction failed = {} + // ); GEODE_DLL Task>> pickMany(FilePickOptions const& options); class GEODE_DLL FileWatchEvent : public Event { diff --git a/loader/src/platform/android/util.cpp b/loader/src/platform/android/util.cpp index b58b14fe..489ca67d 100644 --- a/loader/src/platform/android/util.cpp +++ b/loader/src/platform/android/util.cpp @@ -10,6 +10,7 @@ using namespace geode::prelude; #include #include #include +#include #include #include #include @@ -194,6 +195,13 @@ Result file::pickFile(file::PickMode mode, file::FilePick return Err("Use the callback version"); } +GEODE_DLL Task> pick(PickMode mode, FilePickOptions const& options) { + using RetTask = Task> + return RetTask::runWithCallback([] (auto resultCallback, auto progressCallback, auto cancelCallback) { + + }); +} + void file::pickFile( PickMode mode, FilePickOptions const& options, MiniFunction callback, diff --git a/loader/src/platform/mac/util.mm b/loader/src/platform/mac/util.mm index 9644f88e..e439463d 100644 --- a/loader/src/platform/mac/util.mm +++ b/loader/src/platform/mac/util.mm @@ -8,6 +8,7 @@ using namespace geode::prelude; #include #include #include +#include #define CommentType CommentTypeDummy #import @@ -159,48 +160,27 @@ namespace { @end -Result file::pickFile( - file::PickMode mode, file::FilePickOptions const& options -) { - return Err("Use the callback version"); -} - -GEODE_DLL void file::pickFile( - PickMode mode, FilePickOptions const& options, - MiniFunction callback, - MiniFunction failed -) { +GEODE_DLL Task> pick(PickMode mode, FilePickOptions const& options) { + using RetTask = Task>; [FileDialog dispatchFilePickerWithMode:mode options:options multiple:false onCompletion: ^(FileResult result) { - Loader::get()->queueInMainThread([=]() { - if (result.isOk()) { - callback(std::move(result.unwrap()[0])); - } else { - failed(); - } - }); + if (result.isOk()) { + return RetTask::immediate(std::move(result.unwrap()[0])); + } else { + return RetTask::immediate(Err("Couldn't open file")); + } }]; } -Result> file::pickFiles( - file::FilePickOptions const& options -) { - return Err("Use the callback version"); -} - -GEODE_DLL void file::pickFiles( - FilePickOptions const& options, - MiniFunction)> callback, - MiniFunction failed -) { - [FileDialog dispatchFilePickerWithMode: file::PickMode::OpenFile options:options multiple:true onCompletion: ^(FileResult result) { - Loader::get()->queueInMainThread([=]() { - if (result.isOk()) { - callback(std::move(result.unwrap())); - } else { - failed(); - } - }); +GEODE_DLL Task>> pickMany(FilePickOptions const& options) { + using RetTask = Task>>; + [FileDialog dispatchFilePickerWithMode:mode options:options multiple:true onCompletion: ^(FileResult result) { + if (result.isOk()) { + return RetTask::immediate(std::move(result.unwrap())); + } else { + return RetTask::immediate(Err("Couldn't open file")); + } }]; + } CCPoint cocos::getMousePos() { diff --git a/loader/src/platform/windows/util.cpp b/loader/src/platform/windows/util.cpp index 655cf734..55a27092 100644 --- a/loader/src/platform/windows/util.cpp +++ b/loader/src/platform/windows/util.cpp @@ -7,11 +7,9 @@ using namespace geode::prelude; #include "nfdwin.hpp" #include #include -#include #include #include #include -#include #include #include #include @@ -103,9 +101,8 @@ bool utils::file::openFolder(std::filesystem::path const& path) { return success; } -Result utils::file::pickFile( - file::PickMode mode, file::FilePickOptions const& options -) { +Task> file::pick(PickMode mode, FilePickOptions const& options) { + using RetTask = Task>; #define TURN_INTO_NFDMODE(mode) \ case file::PickMode::mode: nfdMode = NFDMode::mode; break; @@ -114,57 +111,33 @@ Result utils::file::pickFile( TURN_INTO_NFDMODE(OpenFile); TURN_INTO_NFDMODE(SaveFile); TURN_INTO_NFDMODE(OpenFolder); - default: return Err("Unknown open mode"); + default: + return RetTask::immediate(Err("Invalid pick mode")); } std::filesystem::path path; - GEODE_UNWRAP(nfdPick(nfdMode, options, &path)); - return Ok(path); -} - -void file::pickFile( - PickMode mode, FilePickOptions const& options, - MiniFunction callback, - MiniFunction failed -) { - auto result = file::pickFile(mode, options); - - if (result.isOk()) { - callback(std::move(result.unwrap())); + Result result; + auto pickresult = nfdPick(nfdMode, options, &path); + if (pickresult.isErr()) { + result = Err(pickresult.err().value()); } else { - if (failed) { - failed(); - } + result = Ok(path); } -} -Task> file::pick(PickMode mode, FilePickOptions const& options) { - return Task>::immediate(std::move(file::pickFile(mode, options))); + return RetTask::immediate(std::move(result)); } -Result> utils::file::pickFiles( - file::FilePickOptions const& options -) { - std::vector paths; - GEODE_UNWRAP(nfdPick(NFDMode::OpenFiles, options, &paths)); - return Ok(paths); -} - -void file::pickFiles( - FilePickOptions const& options, - MiniFunction)> callback, - MiniFunction failed -) { - auto result = file::pickFiles(options); - - if (result.isOk()) { - callback(std::move(result.unwrap())); - } else { - if (failed) { - failed(); - } - } -} Task>> file::pickMany(FilePickOptions const& options) { - return Task>>::immediate(std::move(file::pickFiles(options))); + using RetTask = Task>>; + + std::vector paths; + auto pickResult = nfdPick(NFDMode::OpenFiles, options, &paths); + Result> result; + if (pickResult.isErr()) { + result = Err(pickResult.err().value()); + } else { + result = Ok(paths); + } + return RetTask::immediate(std::move(result)); + // return Task>>::immediate(std::move(file::pickFiles(options))); } void utils::web::openLinkInBrowser(std::string const& url) {