From 973bce82e5f936105965d1ae60a0924a16c3fb0a Mon Sep 17 00:00:00 2001 From: Menci Date: Sat, 19 Jun 2021 03:29:47 +0800 Subject: [PATCH 1/2] Fix Linux support --- .../Linux/x86_64/libStandaloneFileBrowser.so | Bin 26984 -> 34856 bytes .../Linux/StandaloneFileBrowser/.gitignore | 3 +- .../StandaloneFileBrowser/CMakeLists.txt | 11 +- Plugins/Linux/StandaloneFileBrowser/Makefile | 22 ++ Plugins/Linux/StandaloneFileBrowser/dialog.c | 238 ++++++++++++++++ Plugins/Linux/StandaloneFileBrowser/library.c | 258 +++++------------- Plugins/Linux/StandaloneFileBrowser/main.c | 5 +- 7 files changed, 335 insertions(+), 202 deletions(-) create mode 100644 Plugins/Linux/StandaloneFileBrowser/Makefile create mode 100644 Plugins/Linux/StandaloneFileBrowser/dialog.c diff --git a/Assets/StandaloneFileBrowser/Plugins/Linux/x86_64/libStandaloneFileBrowser.so b/Assets/StandaloneFileBrowser/Plugins/Linux/x86_64/libStandaloneFileBrowser.so index 344084e5b50162962b072b74f6f5b50b59811366..2279ff90342c8d00639ee2c8be35bb0d0d53b07b 100755 GIT binary patch literal 34856 zcmeHw4SZBpmgh?d5K$@tfsML0B?c!T35f#Bw9;0EB)oJ7%tBE7po=0^NlHT!t11}$ z7-I)mszX}Fv0Z=L_KNoWY}V-ydRkc*r@JHJ%l>d^#<6L8M`;K3Rih9UG2N}!{?EPV zR9?N*LuY3{dVasU`K8V~|9j54_nv#-*M0ZAcVBHoU4CAkA!(fP1%tT8DH`!{M%(?o z0pc?j8|UHo660beTQHh6W^3mp4GA@hHBV)Xr%mRa^!W)|PN?LQo+{6)^9=`GH%{Y1 z?RsQ#q+I8ZEXkyU^_oAzRP^!zlU`wk&M*8zCLN>-Aqg$itg0i`b1@mnLQ6Gl2vuzY z*7!y|MBCdh(*jOC3n;Gy|DVHu z{LtXOGt2HcRCDPM54OeHO1fTpZuY`$6Mz21x0>c}{F{y+y!b&~u{X5(@oOKy=+z7N z-t^x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oejMA%?Kyt^K)>crqz~%~hVc!urw89w$1dPB!UG2OHT?J`7B(jW z_#zVM#CCQ!mX9IB6B)vbG(Nj{@vXRO;exYhcOU@~_Er2o!xId8Hsh5M`(UgGA1CqU zhW4SrVuJYgYYgew9%<}~(=Zy^>Q-W_d)0EfJ=DO*7sKV2NcZwKEI^xEmf_8&rJ-T9 ztKDd?TZWB$5aLeJC{uSRVBoVX-sPFGeC?{bl}+_n>+?;@xcA_g^}4!?QfxEF-eXF) zI@Z>zdk^WhLtcIQxM_%;^XNsC;+sk=aiV=Vlx=z=Bti7HjCHuU2NX+e@%cNc}{c-BY|1a9mX#69H*-3;!wGT$Uomj-@nAI zukjb9j@jlcUY`V4t#p_@h~XtX?o%o3c6qDtF}F%=E8`10hx$CBK33Je*$++;W7~u0 zsO>58DV@(e5}{JpNux021{1djcx$>FlI$ zt}+L|Zt|)$45Mc1|F@XlsPIDaXxO#PO?r7!|*(2&Dj3u9CMWj$hpuqhkCLE9RlL zGCwy1ApKP})xJ(NHWN!)GwKeBQ~dG&o(CNeGe7a=-;Ydl`D&j?#ZOVD>4`H3`vvl7 zk3;#Fx*tdVJ0J1%3Rdx9@X}V9;#d1l$K}3)q5}zk6s+Rk0!zN9_|^Nr`gc^6VO6~q zpK8Zz!An()@=tdHV%X2(5p#+t8Y+Gjzlt0)e{{b~GS(!qpW^?Yar|muqo!CCspteW z*8ddz77|3G^jGg;izL6Qr=pLSH-ZdOu|^TdSn-#|;Z=21`~mV++Dy8xSU~Y|$I${Y z4hPmflK&5J14uk=W)lAO=ZNwfRL79Y#q$>=;lFpWV6fqR%>2ajmrMTmdOlJsxQ62z zK=GU7I2AeL&I<* E-{|r>Gynhq diff --git a/Plugins/Linux/StandaloneFileBrowser/.gitignore b/Plugins/Linux/StandaloneFileBrowser/.gitignore index 8b1aab2..5dc6142 100644 --- a/Plugins/Linux/StandaloneFileBrowser/.gitignore +++ b/Plugins/Linux/StandaloneFileBrowser/.gitignore @@ -1,2 +1,3 @@ .idea -cmake-build-debug \ No newline at end of file +cmake-build-debug +build diff --git a/Plugins/Linux/StandaloneFileBrowser/CMakeLists.txt b/Plugins/Linux/StandaloneFileBrowser/CMakeLists.txt index cbe75a6..4db42af 100644 --- a/Plugins/Linux/StandaloneFileBrowser/CMakeLists.txt +++ b/Plugins/Linux/StandaloneFileBrowser/CMakeLists.txt @@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.12) project(StandaloneFileBrowser C) set(CMAKE_C_STANDARD 11) +set(CMAKE_C_FLAGS "-Wall") +set(CMAKE_C_FLAGS_DEBUG "-g") +set(CMAKE_C_FLAGS_RELEASE "-O2") # Use the package PkgConfig to detect GTK+ headers/library files FIND_PACKAGE(PkgConfig REQUIRED) @@ -15,10 +18,6 @@ LINK_DIRECTORIES(${GTK3_LIBRARY_DIRS}) # Add other flags to the compiler ADD_DEFINITIONS(${GTK3_CFLAGS_OTHER}) -add_library(${PROJECT_NAME} SHARED library.c library.h) +add_executable(dialog dialog.c) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${GTK3_LIBRARIES}) - -add_executable(${PROJECT_NAME}_EXE main.c) - -TARGET_LINK_LIBRARIES(${PROJECT_NAME}_EXE ${PROJECT_NAME} ${GTK3_LIBRARIES}) \ No newline at end of file +TARGET_LINK_LIBRARIES(dialog ${GTK3_LIBRARIES}) diff --git a/Plugins/Linux/StandaloneFileBrowser/Makefile b/Plugins/Linux/StandaloneFileBrowser/Makefile new file mode 100644 index 0000000..44f511a --- /dev/null +++ b/Plugins/Linux/StandaloneFileBrowser/Makefile @@ -0,0 +1,22 @@ +LD = ld +CC = gcc +COPTS = -O2 -Wall -Wextra + +.PHONY: all +all: build/main build/libStandaloneFileBrowser.so + +build/dialog: dialog.c + mkdir -p build + cd build && cmake .. -DCMAKE_BUILD_TYPE=Release && make +build/dialog.bin.o: build/dialog + $(LD) -r -b binary -o build/dialog.bin.o build/dialog +build/library.o: library.c library.h + $(CC) $(COPTS) -o build/library.o -c library.c -fPIC +build/libStandaloneFileBrowser.so: build/dialog.bin.o build/library.o + $(CC) $(COPTS) -o build/libStandaloneFileBrowser.so build/library.o build/dialog.bin.o -shared +build/main: build/libStandaloneFileBrowser.so main.c library.h + $(CC) $(COPTS) -o build/main main.c build/libStandaloneFileBrowser.so + +.PHONY: clean +clean: + rm -rf build diff --git a/Plugins/Linux/StandaloneFileBrowser/dialog.c b/Plugins/Linux/StandaloneFileBrowser/dialog.c new file mode 100644 index 0000000..3bd7b54 --- /dev/null +++ b/Plugins/Linux/StandaloneFileBrowser/dialog.c @@ -0,0 +1,238 @@ +#include +#include +#include +#include +#include +#include + +char* strcat_realloc(char* str1, const char* str2) { + char* new_str; + size_t length; + size_t str1length; + + if (str2 == NULL) + return str1; + str1length = 0; + if (str1 != NULL) + str1length = strlen(str1); + length = strlen(str2) + str1length; + new_str = (char*) realloc(str1, (1 + length) * sizeof(char)); + if (new_str == NULL) + return str1; + new_str[str1length] = '\0'; + + strcat(new_str, str2); + + return new_str; +} + +// Rewrite strcpy() to avoid linking with memcpy function of high version (2.14) glibc ABI +char *strcpy_menci(char* dst, const char* src) { + char *p = dst; + do *p++ = *src; while (*src++); + return dst; +} + +void DialogInit() { + gtk_init(0, NULL); +} + +const char* +GTKOpenPanel(const char* title, const char* directory, const char* extension, bool multiselect, + GtkFileChooserAction action); + +const char* +GTKSavePanel(const char* title, const char* directory, const char* defaultName, const char* filters); + +void GTKSetFilters(const char* extension, GtkWidget* dialog); + +const char* DialogOpenFilePanel(const char* title, const char* directory, const char* extension, + bool multiselect) { + return GTKOpenPanel(title, directory, extension, multiselect, + GTK_FILE_CHOOSER_ACTION_OPEN); +} + +const char* DialogOpenFolderPanel(const char* title, const char* directory, bool multiselect) { + return GTKOpenPanel(title, directory, "", multiselect, + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); +} + +const char* DialogSaveFilePanel(const char* title, const char* directory, const char* defaultName, + const char* filters) { + return GTKSavePanel(title, directory, defaultName, filters); +} + +const char* +GTKOpenPanel(const char* title, const char* directory, const char* extensions, bool multiselect, + GtkFileChooserAction action) { + char* filename = NULL; + GtkWidget* dialog; + gint res; + + dialog = gtk_file_chooser_dialog_new(title, + NULL, + action, + ("_Cancel"), + GTK_RESPONSE_CANCEL, + ("_Open"), + GTK_RESPONSE_ACCEPT, + NULL); + gtk_file_chooser_set_select_multiple((GtkFileChooser*) dialog, multiselect); + gtk_file_chooser_set_current_folder((GtkFileChooser*) dialog, directory); + + GTKSetFilters(extensions, dialog); + + res = gtk_dialog_run(GTK_DIALOG (dialog)); + if (res == GTK_RESPONSE_ACCEPT) { + GtkFileChooser* chooser = GTK_FILE_CHOOSER (dialog); + + if (multiselect) { + GSList* filenamepus = gtk_file_chooser_get_filenames(chooser); + + int nIndex; + GSList* node; + + char split[] = {(char)28, 0}; + for (nIndex = 0; (node = g_slist_nth(filenamepus, (guint) nIndex)); nIndex++) { + if (nIndex == 0) { + filename = malloc((strlen(node->data) + 1) * sizeof(char)); + strcpy_menci(filename, node->data); + continue; + } + filename = strcat_realloc(filename, split); + filename = strcat_realloc(filename, node->data); + + g_free(node->data); + } + g_slist_free(filenamepus); + } else { + char* name = gtk_file_chooser_get_filename(chooser); + filename = malloc(strlen(name) * sizeof(char) + 1); + strcpy_menci(filename, name); + g_free(name); + } + } else { // if (res == GTK_RESPONSE_CANCEL) { + filename = malloc(sizeof(char)); + filename[0] = '\0'; + } + + gtk_widget_destroy(dialog); + + while (gtk_events_pending ()) + gtk_main_iteration (); + return filename; +} + +const char* +GTKSavePanel(const char* title, const char* directory, const char* defaultName, const char* filters) { + char* filename = NULL; + GtkWidget *dialog; + GtkFileChooser *chooser; + gint res; + + dialog = gtk_file_chooser_dialog_new ("Save File", + NULL, + GTK_FILE_CHOOSER_ACTION_SAVE, + ("_Cancel"), + GTK_RESPONSE_CANCEL, + ("_Save"), + GTK_RESPONSE_ACCEPT, + NULL); + chooser = GTK_FILE_CHOOSER (dialog); + + gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE); + gtk_file_chooser_set_current_name(chooser, defaultName); + gtk_file_chooser_set_current_folder(chooser, directory); + + GTKSetFilters(filters, dialog); + + res = gtk_dialog_run (GTK_DIALOG (dialog)); + if (res == GTK_RESPONSE_ACCEPT) + { + char* name = gtk_file_chooser_get_filename(chooser); + filename = malloc(strlen(name) * sizeof(char) + 1); + strcpy_menci(filename, name); + g_free(name); + } + else if (res == GTK_RESPONSE_CANCEL) { + filename = malloc(sizeof(char)); + filename[0] = '\0'; + } + + gtk_widget_destroy (dialog); + + while (gtk_events_pending ()) + gtk_main_iteration (); + return filename; +} + +void GTKSetFilters(const char* extensions, GtkWidget* dialog) { + if (extensions == NULL || strlen(extensions) == 0) { + return; + } + + // Image Files;png,jpg,jpeg|Sound Files;mp3,wav|All Files;* + char* extensions_tok = malloc(sizeof(char) * (1+ strlen(extensions))); + extensions_tok = strcpy_menci(extensions_tok, extensions); + char* extensions_tok_beginning = extensions_tok; + + char *extension_filters; + char *name_or_filters; + char *ext; + while ((extension_filters = strtok_r(extensions_tok, "|", &extensions_tok))) { + puts(extension_filters); + int i = 0; + GtkFileFilter* filter = gtk_file_filter_new(); + if (extension_filters[0] == ';') { // no filter name + ++i; + } + while ((name_or_filters = strtok_r(extension_filters, ";", &extension_filters))) { + puts(name_or_filters); + if (i == 0) { + // Filter Name + gtk_file_filter_set_name(filter, name_or_filters); + } else { + // Filter extentions + while ((ext = strtok_r(name_or_filters, ",", &name_or_filters))) { + puts(ext); + if (ext[0] == '*') { + gtk_file_filter_add_pattern(filter, ext); + } else { + char* ext_s;// = "*."; + ext_s = malloc(3 * sizeof(char)); + ext_s = strcpy_menci(ext_s, "*."); + ext_s = strcat_realloc(ext_s, ext); + gtk_file_filter_add_pattern(filter, ext_s); + free(ext_s); + } + } + } + ++i; + } + gtk_file_chooser_add_filter((GtkFileChooser*) dialog, filter); + } + + free(extensions_tok_beginning); +} + +int main(int argc, char *argv[]) { + DialogInit(); + + // fprintf(stderr, "operation = %s\n", argv[1]); + + const char *result = NULL; + if (strcmp(argv[1], "DialogOpenFolderPanel") == 0) { + result = DialogOpenFolderPanel(argv[2], argv[3], argv[4][0] == '1'); + } else if (strcmp(argv[1], "DialogOpenFilePanel") == 0) { + result = DialogOpenFilePanel(argv[2], argv[3], argv[4], argv[5][0] == '1'); + } else if (strcmp(argv[1], "DialogSaveFilePanel") == 0) { + result = DialogSaveFilePanel(argv[2], argv[3], argv[4], argv[5]); + } + + size_t size = result ? strlen(result) : 0; + write(STDOUT_FILENO, &size, sizeof(size)); + if (result) + write(STDOUT_FILENO, result, size); + + return 0; +} diff --git a/Plugins/Linux/StandaloneFileBrowser/library.c b/Plugins/Linux/StandaloneFileBrowser/library.c index 0599616..72b71b4 100644 --- a/Plugins/Linux/StandaloneFileBrowser/library.c +++ b/Plugins/Linux/StandaloneFileBrowser/library.c @@ -1,232 +1,106 @@ +#define _GNU_SOURCE #include -#include #include #include +#include +#include +#include +#include +#include +#include + #include "library.h" -char* strcat_realloc(char* str1, const char* str2) { - char* new_str; - size_t length; - size_t str1length; - - if (str2 == NULL) - return str1; - str1length = 0; - if (str1 != NULL) - str1length = strlen(str1); - length = strlen(str2) + str1length; - new_str = (char*) realloc(str1, (1 + length) * sizeof(char)); - if (new_str == NULL) - return str1; - new_str[str1length] = '\0'; - - strcat(new_str, str2); - - return new_str; -} +typedef void (*callbackFunc)(const char *); -static callbackFunc asyncCallback; +extern char _binary_build_dialog_start[]; +extern char _binary_build_dialog_end[]; + +char *dialogExecutablePath; void DialogInit() { - gtk_init(0, NULL); + // Avoid linking against higher glibc ABI version + // int fd = memfd_create("Menci", MFD_CLOEXEC); + int fd = syscall(__NR_memfd_create, "Menci", MFD_CLOEXEC); + assert(fd != 0); + write(fd, _binary_build_dialog_start, _binary_build_dialog_end - _binary_build_dialog_start); + asprintf(&dialogExecutablePath, "/proc/self/fd/%d", fd); } -const char* -GTKOpenPanel(const char* title, const char* directory, const char* extension, bool multiselect, - GtkFileChooserAction action); +void readn(int fd, void *buffer, size_t n) { + while (n) { + ssize_t r; + assert((r = read(fd, buffer, n)) >= 0); + n -= r; + buffer = (void *)((char *)buffer + r); + } +} + +const char* runSubprocess(const char **args) { + args[0] = "Menci"; + + int pipeFd[2]; + assert(pipe(pipeFd) != -1); -const char* -GTKSavePanel(const char* title, const char* directory, const char* defaultName, const char* filters); + pid_t pid = fork(); + assert(pid != -1); + if (pid == 0) { + assert(dup2(pipeFd[1], STDOUT_FILENO) != -1); + assert((execv(dialogExecutablePath, (char* const*)args), false)); + return NULL; + } else { + assert(close(pipeFd[1]) == 0); -void GTKSetFilters(const char* extension, GtkWidget* dialog); + size_t size; + readn(pipeFd[0], &size, sizeof(size)); + + char *result = malloc(size + 1); + readn(pipeFd[0], result, size); + result[size] = '\0'; + + assert(close(pipeFd[0]) == 0); + + int status; + waitpid(pid, &status, 0); + assert(WIFEXITED(status) && WEXITSTATUS(status) == 0); + + return result; + } +} const char* DialogOpenFilePanel(const char* title, const char* directory, const char* extension, bool multiselect) { - return GTKOpenPanel(title, directory, extension, multiselect, - GTK_FILE_CHOOSER_ACTION_OPEN); + const char *args[] = {NULL, "DialogOpenFilePanel", title, directory, extension, multiselect ? "1" : "0", NULL}; + return runSubprocess(args); } const char* DialogOpenFolderPanel(const char* title, const char* directory, bool multiselect) { - return GTKOpenPanel(title, directory, "", multiselect, - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); + const char *args[] = {NULL, "DialogOpenFolderPanel", title, directory, multiselect ? "1" : "0", NULL}; + return runSubprocess(args); } const char* DialogSaveFilePanel(const char* title, const char* directory, const char* defaultName, const char* filters) { - return GTKSavePanel(title, directory, defaultName, filters); + const char *args[] = {NULL, "DialogSaveFilePanel", title, directory, defaultName, filters, NULL}; + return runSubprocess(args); } void DialogOpenFilePanelAsync(const char* title, const char* directory, const char* extension, bool multiselect, callbackFunc cb) { // TODO Add async capability - cb(GTKOpenPanel(title, directory, extension, multiselect, - GTK_FILE_CHOOSER_ACTION_OPEN)); + cb(DialogOpenFilePanel(title, directory, extension, multiselect)); } void DialogOpenFolderPanelAsync(const char* title, const char* directory, bool multiselect, callbackFunc cb) { // TODO Add async capability - cb(GTKOpenPanel(title, directory, "", multiselect, - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)); + cb(DialogOpenFolderPanel(title, directory, multiselect)); } void DialogSaveFilePanelAsync(const char* title, const char* directory, const char* defaultName, const char* filters, callbackFunc cb) { // TODO Add async capability - cb(GTKSavePanel(title, directory, defaultName, filters)); -} - -const char* -GTKOpenPanel(const char* title, const char* directory, const char* extensions, bool multiselect, - GtkFileChooserAction action) { - char* filename = NULL; - GtkWidget* dialog; - gint res; - - dialog = gtk_file_chooser_dialog_new(title, - NULL, - action, - ("_Cancel"), - GTK_RESPONSE_CANCEL, - ("_Open"), - GTK_RESPONSE_ACCEPT, - NULL); - gtk_file_chooser_set_select_multiple((GtkFileChooser*) dialog, multiselect); - gtk_file_chooser_set_current_folder((GtkFileChooser*) dialog, directory); - - GTKSetFilters(extensions, dialog); - - res = gtk_dialog_run(GTK_DIALOG (dialog)); - if (res == GTK_RESPONSE_ACCEPT) { - GtkFileChooser* chooser = GTK_FILE_CHOOSER (dialog); - - if (multiselect) { - GSList* filenamepus = gtk_file_chooser_get_filenames(chooser); - - int nIndex; - GSList* node; - - char split = (char) 28; - for (nIndex = 0; (node = g_slist_nth(filenamepus, (guint) nIndex)); nIndex++) { - if (nIndex == 0) { - filename = malloc((strlen(node->data) + 1) * sizeof(char)); - strcpy(filename, node->data); - continue; - } - filename = strcat_realloc(filename, &split); - filename = strcat_realloc(filename, node->data); - - g_free(node->data); - } - g_slist_free(filenamepus); - } else { - char* name = gtk_file_chooser_get_filename(chooser); - filename = malloc(strlen(name) * sizeof(char)); - strcpy(filename, name); - g_free(name); - } - } else { // if (res == GTK_RESPONSE_CANCEL) { - filename = malloc(sizeof(char)); - filename[0] = '\0'; - } - - gtk_widget_destroy(dialog); - - while (gtk_events_pending ()) - gtk_main_iteration (); - return filename; -} - -const char* -GTKSavePanel(const char* title, const char* directory, const char* defaultName, const char* filters) { - char* filename = NULL; - GtkWidget *dialog; - GtkFileChooser *chooser; - gint res; - - dialog = gtk_file_chooser_dialog_new ("Save File", - NULL, - GTK_FILE_CHOOSER_ACTION_SAVE, - ("_Cancel"), - GTK_RESPONSE_CANCEL, - ("_Save"), - GTK_RESPONSE_ACCEPT, - NULL); - chooser = GTK_FILE_CHOOSER (dialog); - - gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE); - gtk_file_chooser_set_current_name(chooser, defaultName); - gtk_file_chooser_set_current_folder(chooser, directory); - - GTKSetFilters(filters, dialog); - - res = gtk_dialog_run (GTK_DIALOG (dialog)); - if (res == GTK_RESPONSE_ACCEPT) - { - char* name = gtk_file_chooser_get_filename(chooser); - filename = malloc(strlen(name) * sizeof(char)); - strcpy(filename, name); - g_free(name); - } - else if (res == GTK_RESPONSE_CANCEL) { - filename = malloc(sizeof(char)); - filename[0] = '\0'; - } - - gtk_widget_destroy (dialog); - - while (gtk_events_pending ()) - gtk_main_iteration (); - return filename; + cb(DialogSaveFilePanel(title, directory, defaultName, filters)); } - -void GTKSetFilters(const char* extensions, GtkWidget* dialog) { - if (extensions == NULL || strlen(extensions) == 0) { - return; - } - - // Image Files;png,jpg,jpeg|Sound Files;mp3,wav|All Files;* - char* extensions_tok = malloc(sizeof(char) * (1+ strlen(extensions))); - extensions_tok = strcpy(extensions_tok, extensions); - char* extensions_tok_beginning = extensions_tok; - - char *extension_filters; - char *name_or_filters; - char *ext; - while ((extension_filters = strtok_r(extensions_tok, "|", &extensions_tok))) { - puts(extension_filters); - int i = 0; - GtkFileFilter* filter = gtk_file_filter_new(); - if (extension_filters[0] == ';') { // no filter name - ++i; - } - while ((name_or_filters = strtok_r(extension_filters, ";", &extension_filters))) { - puts(name_or_filters); - if (i == 0) { - // Filter Name - gtk_file_filter_set_name(filter, name_or_filters); - } else { - // Filter extentions - while ((ext = strtok_r(name_or_filters, ",", &name_or_filters))) { - puts(ext); - if (ext[0] == '*') { - gtk_file_filter_add_pattern(filter, ext); - } else { - char* ext_s;// = "*."; - ext_s = malloc(3 * sizeof(char)); - ext_s = strcpy(ext_s, "*."); - ext_s = strcat_realloc(ext_s, ext); - gtk_file_filter_add_pattern(filter, ext_s); - free(ext_s); - } - } - } - ++i; - } - gtk_file_chooser_add_filter((GtkFileChooser*) dialog, filter); - } - - free(extensions_tok_beginning); -} \ No newline at end of file diff --git a/Plugins/Linux/StandaloneFileBrowser/main.c b/Plugins/Linux/StandaloneFileBrowser/main.c index 0fab69f..0a42217 100644 --- a/Plugins/Linux/StandaloneFileBrowser/main.c +++ b/Plugins/Linux/StandaloneFileBrowser/main.c @@ -1,9 +1,8 @@ #include -#include #include #include "library.h" -int main(int argc, char *argv[]) { +int main() { DialogInit(); const char* folders = DialogOpenFolderPanel("Unity Open Folder", "/", true); printf("Folders selected: %s\n", folders); @@ -12,4 +11,4 @@ int main(int argc, char *argv[]) { const char* filesFilters = DialogOpenFilePanel("Unity Open File With Filters", "", "Image Files;png,jpg,jpeg|Sound Files;mp3,wav|All Files;*", true); printf("Files selected: %s\n", filesFilters); return 0; -} \ No newline at end of file +} From 9dbdb16bc8696c0e6fd1e618eded47728f7f6c91 Mon Sep 17 00:00:00 2001 From: Menci Date: Sun, 20 Jun 2021 00:22:22 +0800 Subject: [PATCH 2/2] Fix error handling on Linux --- .../Linux/x86_64/libStandaloneFileBrowser.so | Bin 34856 -> 34960 bytes Plugins/Linux/StandaloneFileBrowser/library.c | 16 +++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Assets/StandaloneFileBrowser/Plugins/Linux/x86_64/libStandaloneFileBrowser.so b/Assets/StandaloneFileBrowser/Plugins/Linux/x86_64/libStandaloneFileBrowser.so index 2279ff90342c8d00639ee2c8be35bb0d0d53b07b..d913c9b63e6d5739eaa129a81dbd6af9b58cca5e 100755 GIT binary patch delta 3344 zcmZu!4R90372cICTN1XU!*9#gyeg23LlsMn)@ka@3a2Uyh6Z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T)OO@7Nf<#Ltk&rzfPc|7)@Jc;N>-PrM6QM&e!DE+y?lwD5O`kp9#S}t9Q z8)?kG>5g=foD~aZ+CP3|m$znS2B$fej??6*)2vaad7Vyk{3i5gtndCHm4-&T6$>+{nUx4a2!F(qLL?As(Q< z<#}4utCu1lb{kHc`VQ0gK$R^ZZqR-`A0<ONo^n&~Xz^wI-Ep(u#y5}q&KeT>rdkHw|u ztMma%KZkVuFm}UYWL|_`OGefn)c2kjrR{kRQNkS-qn2g7O7IV{q(ID4NEYCIi#=I~ zPMAM%$YNi69r@miqNIF7%ahbv@szHh*AXbTt|KApM1BHo){Pp;2+vsa@t;MN)&3=B zY9db`GQE1fN}7o;!GEmTn!uN^M!1VSAKN0lsRu{O@DaxYQ03SQe2#cuzH+qX2ZH{l zeS5ayG1ngQ?{2EE_JOlBxCb0;&k20* z=%=zALgDCDS^foL=AtbB9x;Ttgc$f-mh&-{K0+)<3@phqy?QPob|Eey9!Jc)Cd(%Y zy!hZ6aOCQBHVo^6O}Y1OqhBL{Pc=@U9Pt(D{E((R-PWH}p6-Zf>(g!CbpG4vdhg8a zTVAT^Pa49Dl%^0}PzU-gz-zf1el&;DJ)g<4a)FemS8G~~=#`?}tnSDRF^=0s#rb~ zTkP6JV!lJyN$m0P(**dQQ9~RjrA-TqEdtE-@a8d{s!8A#SnP3{hgoVSa4WbYPGcfr z=aOM>WDAtE^DrK9-OlbrmXE_?q?@>)rPq184o_t7ZkXtG8WXvNKg=h+50F7{_c;xB z%IjcXi8-F5t}B5Zv5CG?{25@e-)TtHQe#jsP+~}Yl}QK=ln~c5okX8s6wqrI*3|R0(+kf={jgFK(Y2WdHyG diff --git a/Plugins/Linux/StandaloneFileBrowser/library.c b/Plugins/Linux/StandaloneFileBrowser/library.c index 72b71b4..576ee23 100644 --- a/Plugins/Linux/StandaloneFileBrowser/library.c +++ b/Plugins/Linux/StandaloneFileBrowser/library.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -27,8 +28,12 @@ void DialogInit() { asprintf(&dialogExecutablePath, "/proc/self/fd/%d", fd); } -void readn(int fd, void *buffer, size_t n) { +void readn(pid_t pid, int fd, void *buffer, size_t n) { while (n) { + int status; + if (waitpid(pid, &status, WNOHANG) == pid) { + assert(("The child process exited unexpectedly. Please refer to the log in stderr.", false)); + } ssize_t r; assert((r = read(fd, buffer, n)) >= 0); n -= r; @@ -46,16 +51,17 @@ const char* runSubprocess(const char **args) { assert(pid != -1); if (pid == 0) { assert(dup2(pipeFd[1], STDOUT_FILENO) != -1); - assert((execv(dialogExecutablePath, (char* const*)args), false)); - return NULL; + execv(dialogExecutablePath, (char* const*)args); + perror("execv"); + abort(); } else { assert(close(pipeFd[1]) == 0); size_t size; - readn(pipeFd[0], &size, sizeof(size)); + readn(pid, pipeFd[0], &size, sizeof(size)); char *result = malloc(size + 1); - readn(pipeFd[0], result, size); + readn(pid, pipeFd[0], result, size); result[size] = '\0'; assert(close(pipeFd[0]) == 0);