base: add iron_exec_async_output_file

This commit is contained in:
luboslenco
2026-05-06 19:51:52 +02:00
parent 5cb936cbbb
commit 071e4b4e76
7 changed files with 39 additions and 12 deletions
+2 -1
View File
@@ -1269,6 +1269,7 @@ bool _save_and_quit_callback_internal() {
return false;
}
volatile int iron_exec_async_done = 1;
volatile int iron_exec_async_done = 1;
char *iron_exec_async_output_file = NULL;
void iron_exec_async(const char *path, char *argv[]) {}
+1 -1
View File
@@ -25,7 +25,7 @@ static NSURLSession *download_session = nil;
NSURL *destURL = [NSURL fileURLWithPath:dstPath];
[[NSFileManager defaultManager] moveItemAtURL:location toURL:destURL error:&error];
// todo
if ([dstPath hasSuffix:@"sd_vulkan"] || [dstPath hasSuffix:@"sd_cpu"]) {
if ([dstPath hasSuffix:@"sd_vulkan"] || [dstPath hasSuffix:@"sd_cpu"] || [dstPath hasSuffix:@"llama_metal"]) {
NSDictionary *attrs = @{NSFilePosixPermissions : @0755};
NSError *chmodError = nil;
[[NSFileManager defaultManager] setAttributes:attrs ofItemAtPath:dstPath error:&chmodError];
+2 -1
View File
@@ -616,6 +616,7 @@ bool _save_and_quit_callback_internal() {
return false;
}
volatile int iron_exec_async_done = 1;
volatile int iron_exec_async_done = 1;
char *iron_exec_async_output_file = NULL;
void iron_exec_async(const char *path, char *argv[]) {}
+9 -2
View File
@@ -1536,10 +1536,12 @@ bool _save_and_quit_callback_internal() {
return false;
}
#include <fcntl.h>
#include <signal.h>
#include <sys/wait.h>
static pid_t child_pid = -1;
volatile int iron_exec_async_done = 1;
static pid_t child_pid = -1;
volatile int iron_exec_async_done = 1;
char *iron_exec_async_output_file = NULL;
void iron_exec_handler(int sig) {
int status;
@@ -1552,6 +1554,11 @@ void iron_exec_async(const char *path, char *argv[]) {
iron_exec_async_done = 0;
child_pid = fork();
if (child_pid == 0) {
if (iron_exec_async_output_file != NULL) {
int fd = open(iron_exec_async_output_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
dup2(fd, STDOUT_FILENO);
close(fd);
}
execve(path, argv, NULL);
exit(1);
}
+4 -3
View File
@@ -642,7 +642,7 @@ void iron_window_change_window_mode(iron_window_mode_t mode) {
}
void iron_window_set_close_callback(bool (*callback)(void *), void *data) {
windows[0].close_callback = callback;
windows[0].close_callback = callback;
windows[0].close_callback_data = data;
}
@@ -811,7 +811,7 @@ void iron_window_set_title(const char *title) {
}
void iron_window_set_resize_callback(void (*callback)(int x, int y, void *data), void *data) {
windows[0].resize_callback = callback;
windows[0].resize_callback = callback;
windows[0].resize_callback_data = data;
}
@@ -1165,7 +1165,8 @@ bool _save_and_quit_callback_internal() {
return false;
}
volatile int iron_exec_async_done = 1;
volatile int iron_exec_async_done = 1;
char *iron_exec_async_output_file = NULL;
void iron_exec_async(const char *path, char *argv[]) {
iron_exec_async_done = 0;
+20 -4
View File
@@ -1766,9 +1766,10 @@ void iron_gamepad_handle_messages() {
#include <process.h>
volatile int iron_exec_async_done = 1;
static HANDLE child_handle = NULL;
static HANDLE wait_handle = NULL;
volatile int iron_exec_async_done = 1;
char *iron_exec_async_output_file = NULL;
static HANDLE child_handle = NULL;
static HANDLE wait_handle = NULL;
static void CALLBACK exec_wait_callback(PVOID lparam, BOOLEAN b) {
iron_exec_async_done = 1;
@@ -1792,7 +1793,22 @@ void iron_exec_async(const char *path, char *argv[]) {
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
BOOL success = CreateProcessW(NULL, wcmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
HANDLE out_handle = INVALID_HANDLE_VALUE;
if (iron_exec_async_output_file != NULL) {
wchar_t wpath[1024];
MultiByteToWideChar(CP_UTF8, 0, iron_exec_async_output_file, -1, wpath, 1024);
SECURITY_ATTRIBUTES sa = {sizeof(sa), NULL, TRUE};
out_handle = CreateFileW(wpath, GENERIC_WRITE, 0, &sa, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
si.dwFlags |= STARTF_USESTDHANDLES;
si.hStdOutput = out_handle;
si.hStdError = out_handle;
}
BOOL success = CreateProcessW(NULL, wcmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
if (out_handle != INVALID_HANDLE_VALUE) {
CloseHandle(out_handle);
}
if (!success) {
iron_exec_async_done = 1;
return;
+1
View File
@@ -102,6 +102,7 @@ void iron_stop(void);
void iron_set_keep_screen_on(bool on);
void iron_exec_async(const char *path, char *argv[]);
extern volatile int iron_exec_async_done;
extern char *iron_exec_async_output_file;
void iron_copy_to_clipboard(const char *text);
void iron_set_update_callback(void (*callback)(void));