meta: replace bluelib with fx

This commit is contained in:
2026-06-22 17:45:54 +01:00
parent 4190a5c54a
commit c6c4b0c1f9
81 changed files with 3933 additions and 1349 deletions
+129 -36
View File
@@ -1,78 +1,90 @@
#include "reader.h"
#include <blue/core/error.h>
#include <blue/io/directory.h>
#include <fx/compression/cstream.h>
#include <fx/compression/zstd.h>
#include <fx/error.h>
#include <fx/io/directory.h>
#include <ropkg/package.h>
#include <ropkg/reader.h>
#include <stdlib.h>
static b_result extract_file(
struct ropkg_package {
fx_file *pkg_file;
fx_cstream *pkg_file_cstream;
struct ropkg_reader *pkg_reader;
fx_directory *pkg_metadata;
};
static fx_result extract_file(
struct ropkg_reader *pkg,
const char *path_cstr,
b_directory *dest)
fx_directory *dest)
{
b_path *path = b_path_create_from_cstr(path_cstr);
fx_path *path = fx_path_create_from_cstr(path_cstr);
if (!path) {
return ROPKG_RESULT_ERR(NO_MEMORY);
}
b_path *dir_path = NULL;
b_path_get_directory(path, &dir_path);
fx_path *dir_path = NULL;
fx_path_get_directory(path, &dir_path);
if (!dir_path) {
b_path_release(path);
fx_path_unref(path);
return ROPKG_RESULT_ERR(NO_MEMORY);
}
b_result result = B_RESULT_SUCCESS;
if (b_path_length(dir_path) > 0) {
b_directory *parent_dir;
result = b_directory_open(
fx_result result = FX_RESULT_SUCCESS;
if (fx_path_length(dir_path) > 0) {
fx_directory *parent_dir;
result = fx_directory_open(
dest,
dir_path,
B_DIRECTORY_OPEN_CREATE_INTERMEDIATE,
FX_DIRECTORY_OPEN_CREATE_INTERMEDIATE,
&parent_dir);
b_directory_release(parent_dir);
fx_directory_unref(parent_dir);
}
if (b_result_is_error(result)) {
if (fx_result_is_error(result)) {
goto end;
}
b_file *dest_file = NULL;
result = b_file_open(
fx_file *dest_file = NULL;
result = fx_file_open(
dest,
path,
B_FILE_WRITE_ONLY | B_FILE_CREATE | B_FILE_BINARY,
FX_FILE_WRITE_ONLY | FX_FILE_CREATE | FX_FILE_BINARY,
&dest_file);
if (b_result_is_error(result)) {
if (fx_result_is_error(result)) {
goto end;
}
char data[] = "Hello";
size_t nr_written = 0;
b_file_write(dest_file, 0, sizeof data, data, &nr_written);
b_file_release(dest_file);
fx_file_write(dest_file, 0, sizeof data, data, &nr_written);
fx_file_unref(dest_file);
end:
b_path_release(path);
b_path_release(dir_path);
fx_path_unref(path);
fx_path_unref(dir_path);
return result;
}
static b_result extract_subpackage(
static fx_result extract_subpackage(
struct ropkg_reader *pkg,
const char *name,
b_directory *dest)
fx_directory *dest)
{
b_directory *dest_subdir;
b_result result = b_directory_open(
fx_directory *dest_subdir;
fx_result result = fx_directory_open(
dest,
B_RV_PATH(name),
B_DIRECTORY_OPEN_CREATE,
FX_RV_PATH(name),
FX_DIRECTORY_OPEN_CREATE,
&dest_subdir);
if (b_result_is_error(result)) {
if (fx_result_is_error(result)) {
return result;
}
b_cstream_begin_compressed_section(pkg->r_stream, NULL);
fx_cstream_begin_compressed_section(pkg->r_stream, NULL);
struct ropkg_reader *subpkg = NULL;
enum ropkg_status status = ropkg_reader_open(pkg->r_stream, &subpkg);
@@ -85,7 +97,7 @@ static b_result extract_subpackage(
const struct ropkg_file_info *file
= ropkg_reader_current_file(subpkg);
result = extract_file(subpkg, file->f_filename, dest_subdir);
if (b_result_is_error(result)) {
if (fx_result_is_error(result)) {
break;
}
@@ -97,13 +109,13 @@ static b_result extract_subpackage(
}
end:
b_cstream_end_compressed_section(pkg->r_stream, NULL, NULL);
fx_cstream_end_compressed_section(pkg->r_stream, NULL, NULL);
return result;
}
b_result ropkg_extract_metadata(struct ropkg_reader *pkg, b_directory *dest)
static fx_result extract_metadata(struct ropkg_reader *pkg, fx_directory *dest)
{
b_result result = B_RESULT_SUCCESS;
fx_result result = FX_RESULT_SUCCESS;
while (!ropkg_reader_eof(pkg)) {
const struct ropkg_file_info *file
@@ -117,7 +129,7 @@ b_result ropkg_extract_metadata(struct ropkg_reader *pkg, b_directory *dest)
result = extract_subpackage(pkg, "control", dest);
}
if (b_result_is_error(result)) {
if (fx_result_is_error(result)) {
break;
}
@@ -130,3 +142,84 @@ b_result ropkg_extract_metadata(struct ropkg_reader *pkg, b_directory *dest)
return result;
}
fx_result ropkg_package_open(
fx_directory *dir,
const char *path,
struct ropkg_package **out)
{
struct ropkg_package *pkg = malloc(sizeof *pkg);
if (!pkg) {
return ROPKG_RESULT_ERR(NO_MEMORY);
}
memset(pkg, 0x0, sizeof *pkg);
fx_result result = fx_file_open(
dir,
FX_RV_PATH(path),
FX_FILE_READ_ONLY | FX_FILE_BINARY,
&pkg->pkg_file);
if (fx_result_is_error(result)) {
ropkg_package_close(pkg);
return fx_result_propagate(result);
}
fx_status bstatus = fx_cstream_open(
pkg->pkg_file,
FX_TYPE_ZSTD_COMPRESSOR,
FX_COMPRESSOR_MODE_DECOMPRESS,
&pkg->pkg_file_cstream);
if (!FX_OK(bstatus)) {
ropkg_package_close(pkg);
return FX_RESULT_STATUS(bstatus);
}
enum ropkg_status status
= ropkg_reader_open(pkg->pkg_file_cstream, &pkg->pkg_reader);
if (status != ROPKG_SUCCESS) {
ropkg_package_close(pkg);
return ROPKG_RESULT_STATUS(status);
}
result = fx_directory_open_temp(&pkg->pkg_metadata);
if (fx_result_is_error(result)) {
ropkg_package_close(pkg);
return fx_result_propagate(result);
}
result = extract_metadata(pkg->pkg_reader, pkg->pkg_metadata);
if (fx_result_is_error(result)) {
ropkg_package_close(pkg);
return fx_result_propagate(result);
}
*out = pkg;
return ROPKG_RESULT_SUCCESS;
}
fx_result ropkg_package_close(struct ropkg_package *pkg)
{
if (pkg->pkg_reader) {
ropkg_reader_close(pkg->pkg_reader);
pkg->pkg_reader = NULL;
}
if (pkg->pkg_file_cstream) {
fx_cstream_unref(pkg->pkg_file_cstream);
pkg->pkg_file_cstream = NULL;
}
if (pkg->pkg_file) {
fx_file_unref(pkg->pkg_file);
pkg->pkg_file = NULL;
}
if (pkg->pkg_metadata) {
fx_directory_unref(pkg->pkg_metadata);
pkg->pkg_metadata = NULL;
}
free(pkg);
return FX_RESULT_SUCCESS;
}