base: cleanup

This commit is contained in:
luboslenco
2026-03-02 08:27:09 +01:00
parent c775a41a53
commit 06846de000
11 changed files with 190 additions and 179 deletions
-1
View File
@@ -3,7 +3,6 @@
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <vulkan/vulkan.h>
#include <vulkan/vulkan_core.h>
typedef struct gpu_pipeline_impl {
-168
View File
@@ -159,16 +159,6 @@ buffer_t *embed_get(char *key) {
}
#endif
#define f64 double
#define i64 int64_t
#define u64 uint64_t
#define f32 float
#define i32 int32_t
#define u32 uint32_t
#define i16 int16_t
#define u16 uint16_t
#define i8 int8_t
#define u8 uint8_t
#define string_t char
#define any void *
#define any_ptr void **
@@ -1306,25 +1296,6 @@ void _gpu_begin(gpu_texture_t *render_target, any_array_t *additional, gpu_textu
}
}
void iron_file_save_bytes(string_t *path, buffer_t *bytes, u64 length) {
u64 byte_length = length > 0 ? length : (u64)bytes->length;
if (byte_length > (u64)bytes->length) {
byte_length = (u64)bytes->length;
}
#ifdef IRON_WINDOWS
MultiByteToWideChar(CP_UTF8, 0, path, -1, temp_wstring, 1024);
FILE *file = _wfopen(temp_wstring, L"wb");
#else
FILE *file = fopen(path, "wb");
#endif
if (file == NULL) {
return;
}
fwrite(bytes->buffer, 1, byte_length, file);
fclose(file);
}
i32 iron_sys_command(string_t *cmd) {
#ifdef IRON_WINDOWS
@@ -1359,56 +1330,6 @@ i32 iron_sys_command(string_t *cmd) {
return result;
}
typedef struct _callback_data {
int32_t size;
char url[512];
void (*func)(char *, buffer_t *);
} _callback_data_t;
void _https_callback(const char *body, void *callback_data) {
_callback_data_t *cbd = (_callback_data_t *)callback_data;
buffer_t *buffer = NULL;
if (body != NULL) {
buffer = malloc(sizeof(buffer_t));
buffer->length = cbd->size > 0 ? cbd->size : strlen(body);
buffer->buffer = malloc(buffer->length);
memcpy(buffer->buffer, body, buffer->length);
}
cbd->func(cbd->url, buffer);
free(cbd);
}
void iron_file_download(string_t *url, void (*callback)(char *, buffer_t *), i32 size, string_t *dst_path) {
_callback_data_t *cbd = malloc(sizeof(_callback_data_t));
cbd->size = size;
strcpy(cbd->url, url);
cbd->func = callback;
char url_base[512];
char url_path[512];
int i = 0;
for (; i < strlen(url) - 8; ++i) {
if (url[i + 8] == '/') {
break;
}
url_base[i] = url[i + 8]; // Strip https://
}
url_base[i] = 0;
int j = 0;
if (strlen(url_base) < strlen(url) - 8) {
++i; // Skip /
}
for (; j < strlen(url) - 8 - i; ++j) {
if (url[i + 8 + j] == 0) {
break;
}
url_path[j] = url[i + 8 + j];
}
url_path[j] = 0;
iron_net_request(url_base, url_path, NULL, 443, IRON_HTTPS_GET, &_https_callback, cbd, dst_path);
}
bool _save_and_quit_callback_internal();
bool _save_and_quit_callback(void *data) {
@@ -1507,95 +1428,6 @@ char *iron_save_dialog(char *filter_list, char *default_path) {
#endif
char *iron_read_directory(char *path) {
char *files = temp_string;
files[0] = 0;
directory dir = open_dir(path);
if (dir.handle == NULL) {
return files;
}
while (true) {
file f = read_next_file(&dir);
if (!f.valid) {
break;
}
#ifdef IRON_WINDOWS
char file_path[512];
strcpy(file_path, path);
strcat(file_path, "\\");
strcat(file_path, f.name);
if (FILE_ATTRIBUTE_HIDDEN & GetFileAttributesA(file_path)) {
continue; // Skip hidden files
}
#endif
if (files[0] != '\0') {
strcat(files, "\n");
}
strcat(files, f.name);
}
close_dir(&dir);
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_is_directory(char *path) {
#ifdef IRON_WINDOWS
DWORD attribs = GetFileAttributesA(path);
return attribs != INVALID_FILE_ATTRIBUTES && (attribs & FILE_ATTRIBUTE_DIRECTORY);
#else
struct stat st;
return stat(path, &st) == 0 && S_ISDIR(st.st_mode);
#endif
}
bool iron_file_exists(char *path) {
iron_file_reader_t reader;
if (iron_file_reader_open(&reader, path, IRON_FILE_TYPE_ASSET)) {
iron_file_reader_close(&reader);
return true;
}
return false;
}
void iron_delete_file(char *path) {
#ifdef IRON_IOS
IOSDeleteFile(path);
#elif defined(IRON_WINDOWS)
char cmd[1024];
strcpy(cmd, "del /f \"");
strcat(cmd, path);
strcat(cmd, "\"");
iron_sys_command(cmd);
#else
char cmd[1024];
strcpy(cmd, "rm \"");
strcat(cmd, path);
strcat(cmd, "\"");
iron_sys_command(cmd);
#endif
}
#ifdef WITH_COMPRESS
buffer_t *iron_inflate(buffer_t *bytes, bool raw) {
unsigned char *inflated = NULL;
+166 -2
View File
@@ -1,6 +1,9 @@
#include "iron_file.h"
#include "iron_system.h"
#include "iron_string.h"
#include "iron_net.h"
#include "libs/kong/dir.h"
#ifdef IRON_ANDROID
#include <backends/android_system.h>
#endif
@@ -10,11 +13,14 @@
#ifdef IRON_WINDOWS
#include <malloc.h>
#include <memory.h>
#endif
#ifdef IRON_WINDOWS
#include <backends/windows_mini.h>
#else
#include <sys/stat.h>
#endif
i32 iron_sys_command(char *cmd);
extern char temp_string[1024 * 128];
static char *fileslocation = NULL;
#ifdef IRON_WINDOWS
static wchar_t wfilepath[1001];
@@ -292,3 +298,161 @@ void iron_file_writer_write(iron_file_writer_t *writer, void *data, int size) {
fwrite(data, 1, size, (FILE *)writer->file);
#endif
}
char *iron_read_directory(char *path) {
char *files = temp_string;
files[0] = 0;
directory dir = open_dir(path);
if (dir.handle == NULL) {
return files;
}
while (true) {
file f = read_next_file(&dir);
if (!f.valid) {
break;
}
#ifdef IRON_WINDOWS
char file_path[512];
strcpy(file_path, path);
strcat(file_path, "\\");
strcat(file_path, f.name);
if (FILE_ATTRIBUTE_HIDDEN & GetFileAttributesA(file_path)) {
continue; // Skip hidden files
}
#endif
if (files[0] != '\0') {
strcat(files, "\n");
}
strcat(files, f.name);
}
close_dir(&dir);
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_is_directory(char *path) {
#ifdef IRON_WINDOWS
DWORD attribs = GetFileAttributesA(path);
return attribs != INVALID_FILE_ATTRIBUTES && (attribs & FILE_ATTRIBUTE_DIRECTORY);
#else
struct stat st;
return stat(path, &st) == 0 && S_ISDIR(st.st_mode);
#endif
}
bool iron_file_exists(char *path) {
iron_file_reader_t reader;
if (iron_file_reader_open(&reader, path, IRON_FILE_TYPE_ASSET)) {
iron_file_reader_close(&reader);
return true;
}
return false;
}
void iron_delete_file(char *path) {
#ifdef IRON_IOS
IOSDeleteFile(path);
#elif defined(IRON_WINDOWS)
char cmd[1024];
strcpy(cmd, "del /f \"");
strcat(cmd, path);
strcat(cmd, "\"");
iron_sys_command(cmd);
#else
char cmd[1024];
strcpy(cmd, "rm \"");
strcat(cmd, path);
strcat(cmd, "\"");
iron_sys_command(cmd);
#endif
}
void iron_file_save_bytes(char *path, buffer_t *bytes, u64 length) {
u64 byte_length = length > 0 ? length : (u64)bytes->length;
if (byte_length > (u64)bytes->length) {
byte_length = (u64)bytes->length;
}
#ifdef IRON_WINDOWS
MultiByteToWideChar(CP_UTF8, 0, path, -1, temp_wstring, 1024);
FILE *file = _wfopen(temp_wstring, L"wb");
#else
FILE *file = fopen(path, "wb");
#endif
if (file == NULL) {
return;
}
fwrite(bytes->buffer, 1, byte_length, file);
fclose(file);
}
typedef struct _callback_data {
int32_t size;
char url[512];
void (*func)(char *, buffer_t *);
} _callback_data_t;
void _https_callback(const char *body, void *callback_data) {
_callback_data_t *cbd = (_callback_data_t *)callback_data;
buffer_t *buffer = NULL;
if (body != NULL) {
buffer = malloc(sizeof(buffer_t));
buffer->length = cbd->size > 0 ? cbd->size : strlen(body);
buffer->buffer = malloc(buffer->length);
memcpy(buffer->buffer, body, buffer->length);
}
cbd->func(cbd->url, buffer);
free(cbd);
}
void iron_file_download(char *url, void (*callback)(char *, buffer_t *), i32 size, char *dst_path) {
_callback_data_t *cbd = malloc(sizeof(_callback_data_t));
cbd->size = size;
strcpy(cbd->url, url);
cbd->func = callback;
char url_base[512];
char url_path[512];
int i = 0;
for (; i < strlen(url) - 8; ++i) {
if (url[i + 8] == '/') {
break;
}
url_base[i] = url[i + 8]; // Strip https://
}
url_base[i] = 0;
int j = 0;
if (strlen(url_base) < strlen(url) - 8) {
++i; // Skip /
}
for (; j < strlen(url) - 8 - i; ++j) {
if (url[i + 8 + j] == 0) {
break;
}
url_path[j] = url[i + 8 + j];
}
url_path[j] = 0;
iron_net_request(url_base, url_path, NULL, 443, IRON_HTTPS_GET, &_https_callback, cbd, dst_path);
}
+9
View File
@@ -1,6 +1,7 @@
#pragma once
#include "iron_global.h"
#include "iron_array.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
@@ -61,3 +62,11 @@ typedef struct iron_file_writer {
bool iron_file_writer_open(iron_file_writer_t *writer, const char *filepath);
void iron_file_writer_write(iron_file_writer_t *writer, void *data, int size);
void iron_file_writer_close(iron_file_writer_t *writer);
char *iron_read_directory(char *path);
void iron_create_directory(char *path);
bool iron_is_directory(char *path);
bool iron_file_exists(char *path);
void iron_delete_file(char *path);
void iron_file_save_bytes(char *path, buffer_t *bytes, u64 length);
void iron_file_download(char *url, void (*callback)(char *, buffer_t *), i32 size, char *dst_path);
+11
View File
@@ -25,3 +25,14 @@
#endif
int kickstart(int argc, char **argv);
typedef float f32;
typedef double f64;
typedef int8_t i8;
typedef uint8_t u8;
typedef int16_t i16;
typedef uint16_t u16;
typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
View File
View File
+1 -5
View File
@@ -76,10 +76,6 @@ function file_read_directory(path: string): string[] {
return files;
}
function file_create_directory(path: string) {
iron_create_directory(path);
}
function file_copy(src_path: string, dst_path: string) {
iron_sys_command(file_cmd_copy + " \"" + src_path + "\" \"" + dst_path + "\"");
}
@@ -120,7 +116,7 @@ function file_cache_cloud(path: string, done: (s: string) => void) {
let file_dir: string = substring(dest, 0, string_last_index_of(dest, PATH_SEP));
if (file_read_directory(file_dir)[0] == "") {
file_create_directory(file_dir);
iron_create_directory(file_dir);
}
/// if arm_windows
path = string_replace_all(path, "\\", "/");