From 46c99ba7853830fd764c09afc35dd8dd92e22611 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Mon, 8 Sep 2025 15:35:52 +0200 Subject: [PATCH] Implement iron_create_directory for ios --- base/sources/backends/ios_file_dialog.h | 1 + base/sources/backends/ios_file_dialog.m | 6 ++++++ base/sources/iron.h | 18 ++++++++++++++++++ base/sources/ts/file.ts | 4 +--- base/sources/ts/iron.ts | 1 + 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/base/sources/backends/ios_file_dialog.h b/base/sources/backends/ios_file_dialog.h index 399f40fd..696d291c 100644 --- a/base/sources/backends/ios_file_dialog.h +++ b/base/sources/backends/ios_file_dialog.h @@ -5,3 +5,4 @@ void IOSFileDialogOpen(); wchar_t *IOSFileDialogSave(); void IOSDeleteFile(const char *path); +void IOSCreateDirectory(const char *path); diff --git a/base/sources/backends/ios_file_dialog.m b/base/sources/backends/ios_file_dialog.m index dd73ac9e..57f5a4f9 100644 --- a/base/sources/backends/ios_file_dialog.m +++ b/base/sources/backends/ios_file_dialog.m @@ -27,3 +27,9 @@ void IOSDeleteFile(const char *path) { NSString *nspath = [NSString stringWithUTF8String:path]; [[NSFileManager defaultManager] removeItemAtPath:nspath error:&error]; } + +void IOSCreateDirectory(const char *path) { + NSError *error = nil; + NSString *nspath = [NSString stringWithUTF8String:path]; + [[NSFileManager defaultManager] createDirectoryAtPath:nspath withIntermediateDirectories:YES attributes:nil error:&error]; +} diff --git a/base/sources/iron.h b/base/sources/iron.h index 6d134f42..d64a5ccc 100644 --- a/base/sources/iron.h +++ b/base/sources/iron.h @@ -1546,6 +1546,24 @@ char *iron_read_directory(char *path) { return files; } +void iron_create_directory(char *path) { + #ifdef IRON_IOS + IOSCreateDirectory(path); + #elif defined(IRON_WINDOWS) + char cmd[1024]; + strcpy(cmd, "mkdir \""); + strcat(cmd, path); + strcat(cmd, "\""); + iron_sys_command(cmd); + #else + char cmd[1024]; + strcpy(cmd, "mkdir -p \""); + strcat(cmd, path); + strcat(cmd, "\""); + iron_sys_command(cmd); + #endif +} + bool iron_file_exists(char *path) { iron_file_reader_t reader; if (iron_file_reader_open(&reader, path, IRON_FILE_TYPE_ASSET)) { diff --git a/base/sources/ts/file.ts b/base/sources/ts/file.ts index 9c70e12b..b798ba76 100644 --- a/base/sources/ts/file.ts +++ b/base/sources/ts/file.ts @@ -21,10 +21,8 @@ let _file_download_bytes_map: map_t = map_cr let _file_cache_cloud_map: map_t = map_create(); ///if arm_windows -let file_cmd_mkdir: string = "mkdir"; let file_cmd_copy: string = "copy"; ///else -let file_cmd_mkdir: string = "mkdir -p"; let file_cmd_copy: string = "cp"; ///end @@ -79,7 +77,7 @@ function file_read_directory(path: string): string[] { } function file_create_directory(path: string) { - iron_sys_command(file_cmd_mkdir + " \"" + path + "\""); + iron_create_directory(path); } function file_copy(src_path: string, dst_path: string) { diff --git a/base/sources/ts/iron.ts b/base/sources/ts/iron.ts index a0061bc0..c298a8b4 100644 --- a/base/sources/ts/iron.ts +++ b/base/sources/ts/iron.ts @@ -336,6 +336,7 @@ declare function iron_delay_idle_sleep(): void; declare function iron_open_dialog(filter_list: string, default_path: string, open_multiple: bool): string[]; declare function iron_save_dialog(filter_list: string, default_path: string): string; declare function iron_read_directory(path: string): string; +declare function iron_create_directory(path: string): void; declare function iron_file_exists(path: string): bool; declare function iron_delete_file(path: string): void; declare function iron_inflate(bytes: buffer_t, raw: bool): buffer_t;