summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMole Shang <[email protected]>2024-03-01 23:23:11 +0800
committerMole Shang <[email protected]>2024-03-01 23:29:19 +0800
commitf4309930b547aa845f2f12824109fb606d9fb217 (patch)
tree14f0344c579df7ac8dea945ffe37cd0274e1b17f
parent2c23cf4b3968a2c4f86253dcadba9779bc00e6ff (diff)
downloadhinata-f4309930b547aa845f2f12824109fb606d9fb217.tar.gz
hinata-f4309930b547aa845f2f12824109fb606d9fb217.tar.bz2
hinata-f4309930b547aa845f2f12824109fb606d9fb217.zip
xmake: come back to NFD
-rw-r--r--src/main.c6
-rw-r--r--src/ui.c12
-rw-r--r--third_party/packages/n/nativefiledialog-extended/xmake.lua62
-rw-r--r--third_party/packages/t/tinyfiledialogs/xmake.lua35
-rw-r--r--xmake.lua4
5 files changed, 75 insertions, 44 deletions
diff --git a/src/main.c b/src/main.c
index 3410f37..1971add 100644
--- a/src/main.c
+++ b/src/main.c
@@ -7,6 +7,7 @@
#include <stdlib.h>
#include "toml.h"
+#include "nfd.h"
#define MAX_VERTEX_BUFFER 512 * 1024
#define MAX_ELEMENT_BUFFER 128 * 1024
#define NK_INCLUDE_FIXED_TYPES
@@ -111,6 +112,10 @@ int main(void) {
exit(EXIT_FAILURE);
}
+ /* NFD */
+ if (NFD_Init() != NFD_OKAY)
+ exit(EXIT_FAILURE);
+
/* Logger setup */
struct logger *logger = setup_logger();
// Put it in ui_struct
@@ -189,6 +194,7 @@ int main(void) {
}
curl_cleanup(&stat);
nk_glfw3_shutdown(&glfw);
+ NFD_Quit();
glfwTerminate();
exit(0);
}
diff --git a/src/ui.c b/src/ui.c
index 3065113..8065237 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -6,7 +6,7 @@
#include "nuklear.h"
#include "process_url.h"
-#include "tinyfiledialogs.h"
+#include "nfd.h"
#include "constants.h"
#include "logger.h"
@@ -16,7 +16,7 @@
static nk_size pct;
static bool show_app_about;
-static char *outPath;
+static nfdchar_t *outPath;
void load_ui(struct ui_struct *ui) {
static char text[USHRT_MAX], box_buffer[UINT16_MAX], status_string[UCHAR_MAX];
@@ -103,12 +103,10 @@ void load_ui(struct ui_struct *ui) {
// Clear logger text
clear_log();
- outPath = tinyfd_selectFolderDialog("Pick a download folder: ", NULL);
-
- if (outPath) {
- DEBUG_PRINT("tinyfd gets outPath: %s\n", outPath);
+ if (NFD_PickFolder(&outPath, NULL) == NFD_OKAY && outPath) {
+ DEBUG_PRINT("nfd gets outPath: %s\n", (char *)outPath);
append_log("Got URL: %s\n", text);
- add_url(text, outPath, NULL, NULL, NULL);
+ add_url(text, (char *)outPath, NULL, NULL, NULL);
} else {
LOG("NFD", "Please specify a valid file PATH to write to!\n");
}
diff --git a/third_party/packages/n/nativefiledialog-extended/xmake.lua b/third_party/packages/n/nativefiledialog-extended/xmake.lua
new file mode 100644
index 0000000..2086e7f
--- /dev/null
+++ b/third_party/packages/n/nativefiledialog-extended/xmake.lua
@@ -0,0 +1,62 @@
+package("nativefiledialog-extended")
+
+ set_homepage("https://github.com/btzy/nativefiledialog-extended")
+ set_description("Cross platform (Windows, Mac, Linux) native file dialog library with C and C++ bindings, based on mlabbe/nativefiledialog.")
+
+ add_urls("https://github.com/btzy/nativefiledialog-extended/archive/refs/tags/$(version).zip",
+ "https://github.com/btzy/nativefiledialog-extended.git")
+ add_versions("v1.1.1", "7003001d36235db2c2062cd992e61c59c77a5ad3ca5e5ed8175e56502513886e")
+ add_versions("v1.1.0", "5827d17b6bddc8881406013f419c534e8459b38f34c2f266d9c1da8a7a7464bc")
+ add_versions("v1.0.2", "1d2c4c50fb1e3ad8caa5ad9c3df54725c3a49a6d4a21d773a20b93ebeb5780f1")
+
+ add_configs("portal", {description = "Use xdg-desktop-portal instead of GTK.", default = true, type = "boolean"})
+ if is_plat("windows") then
+ add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
+ end
+
+ if is_plat("windows", "mingw") then
+ add_syslinks("shell32", "ole32")
+ elseif is_plat("macosx") then
+ add_frameworks("AppKit", "UniformTypeIdentifiers")
+ end
+ on_load("linux", function (package)
+ if package:config("portal") then
+ package:add("deps", "dbus")
+ else
+ package:add("deps", "gtk+3")
+ end
+ end)
+
+ on_install("windows", "mingw", function (package)
+ io.writefile("xmake.lua", [[
+ add_rules("mode.debug", "mode.release")
+ add_syslinks("shell32", "ole32")
+ add_includedirs("src/include")
+ target("nativefiledialog-extended")
+ set_kind("static")
+ add_files("src/nfd_win.cpp")
+ add_headerfiles("src/include/nfd.h")
+ add_headerfiles("src/include/nfd.hpp")
+ ]])
+ import("package.tools.xmake").install(package)
+ end)
+
+ on_install("macosx", "linux", function (package)
+ local configs = {"-DNFD_BUILD_TESTS=OFF"}
+ table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
+ table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+ table.insert(configs, "-DNFD_PORTAL=" .. (package:config("portal") and "ON" or "OFF"))
+ import("package.tools.cmake").install(package, configs)
+ end)
+
+ on_test(function (package)
+ assert(package:check_cxxsnippets({test = [[
+ void test() {
+ NFD_Init();
+ nfdchar_t *outPath = NULL;
+ nfdfilteritem_t filterItem[2] = {{"Source code", "c,cpp,cc"}, {"Headers", "h,hpp"}};
+ nfdresult_t result = NFD_OpenDialog(&outPath, filterItem, 2, NULL);
+ NFD_Quit();
+ }
+ ]]}, {includes = "nfd.h"}))
+ end) \ No newline at end of file
diff --git a/third_party/packages/t/tinyfiledialogs/xmake.lua b/third_party/packages/t/tinyfiledialogs/xmake.lua
deleted file mode 100644
index 72dcca1..0000000
--- a/third_party/packages/t/tinyfiledialogs/xmake.lua
+++ /dev/null
@@ -1,35 +0,0 @@
-package("tinyfiledialogs")
-
-set_homepage("https://sourceforge.net/projects/tinyfiledialogs/")
-set_description("Native dialog library for WINDOWS MAC OSX GTK+ QT CONSOLE")
-set_license("zlib")
-
-add_urls("https://git.code.sf.net/p/tinyfiledialogs/code.git")
-
-if is_plat("windows", "mingw") then
- add_syslinks("comdlg32", "ole32", "user32", "shell32")
-end
-on_install("windows", "mingw", "linux", "macosx", function(package)
- io.writefile("xmake.lua", [[
- add_rules("mode.debug", "mode.release")
- target("tinyfiledialogs")
- set_kind("static")
- add_files("tinyfiledialogs.c")
- add_headerfiles("tinyfiledialogs.h")
- ]])
- import("package.tools.xmake").install(package)
-end)
-
-on_test(function(package)
- assert(package:check_csnippets({
- test = [[
- #include <stdio.h>
- #include <string.h>
- #include "tinyfiledialogs.h"
- void test() {
- char const * lWillBeGraphicMode;
- lWillBeGraphicMode = tinyfd_inputBox("tinyfd_query", NULL, NULL);
- }
- ]]
- }))
-end) \ No newline at end of file
diff --git a/xmake.lua b/xmake.lua
index 04b0ff5..d003268 100644
--- a/xmake.lua
+++ b/xmake.lua
@@ -2,7 +2,7 @@ add_rules("mode.debug", "mode.release", "mode.releasedbg", "mode.minsizerel")
add_repositories("third_party third_party")
-add_requires("nuklear", "nuklear_glfw_gl3", "nuklear_fonts", "glew", "glfw", "tinyfiledialogs",
+add_requires("nuklear", "nuklear_glfw_gl3", "nuklear_fonts", "glew", "glfw", "nativefiledialog-extended",
"c11threads", "pcre2",
"cjson", "ffmpeg", "tomlc99")
add_requires("libcurl", { configs = { zlib = true } })
@@ -27,6 +27,6 @@ if is_mode("debug") then
add_defines("DEBUG")
end
-add_packages("nuklear", "nuklear_glfw_gl3", "nuklear_fonts", "glew", "glfw", "libcurl", "tinyfiledialogs",
+add_packages("nuklear", "nuklear_glfw_gl3", "nuklear_fonts", "glew", "glfw", "libcurl", "nativefiledialog-extended",
"c11threads", "pcre2",
"cjson", "ffmpeg", "tomlc99")