127 lines
3.2 KiB
C
127 lines
3.2 KiB
C
#pragma once
|
|
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
|
|
#ifdef BUILD_SZS
|
|
// if we are building the library, use the base Wiimm's types.
|
|
#include "lib-szs.h"
|
|
#else
|
|
// if we are importing the library, do not import the types directly to avoid potential incompatibilities
|
|
// provoced by non-standard C code.
|
|
#define szs_file_t void
|
|
#define szs_subfile_t void
|
|
#endif
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <stdbool.h>
|
|
|
|
|
|
/**
|
|
* A structure representing a SZS subfile.
|
|
* Wrapper around Wiimm's szs_subfile_t.
|
|
*/
|
|
typedef struct {
|
|
szs_subfile_t* _internal; // this reference the original szs_subfile_t.
|
|
|
|
const char** path_p; // pointer to the path of the subfile.
|
|
const char** name_p; // pointer to the name of the subfile.
|
|
uint32_t* size_p; // pointer to the size of the subfile.
|
|
uint8_t** data_p; // pointer to the array of data.
|
|
bool* is_directory_p; // pointer to a boolean indicating if the file is a directory.
|
|
} SzsSubfile;
|
|
|
|
/**
|
|
* A structure representing an SZS file.
|
|
* Wrapper around Wiimm's szs_file_t.
|
|
*/
|
|
typedef struct {
|
|
szs_file_t* _internal; // this reference the original szs_file_t. Type not used for the linking when used as a library.
|
|
} SzsFile;
|
|
|
|
typedef struct {
|
|
szs_subfile_t* _internal_current; // this reference the current object in the list.
|
|
szs_subfile_t* _internal_final; // this reference the last object in the list.
|
|
} SzsSubfileIterator;
|
|
|
|
// File
|
|
|
|
/**
|
|
* Initialize a new empty SZS file.
|
|
* @return an empty SZS file
|
|
*/
|
|
SzsFile* szsFileNew();
|
|
|
|
/**
|
|
* Free the memory from an SZS file.
|
|
* @param file the file to free
|
|
*/
|
|
void szsFileFree(SzsFile *file);
|
|
|
|
/**
|
|
* Load an SZS file.
|
|
* @param path the path to the file
|
|
* @return the SZS instance
|
|
*/
|
|
SzsFile* szsFileLoad(const char* path);
|
|
|
|
/**
|
|
* Create an SZS file from a directory.
|
|
* @param path the path of the directory
|
|
* @return the SZS instance
|
|
*/
|
|
SzsFile* szsFileCreate(const char* path);
|
|
|
|
void szsFileExtract(SzsFile* file, const char* path);
|
|
|
|
// Subfile
|
|
|
|
/**
|
|
* Create a new subfile.
|
|
* @param internal_subfile the base Wiimm's szs_subfile_t structure
|
|
* @return a wrapper for this subfile
|
|
*/
|
|
SzsSubfile* szsSubfileNew(szs_subfile_t* internal_subfile);
|
|
|
|
/**
|
|
* Free the memory from an SZS subfile.
|
|
* @param subfile the subfile to free
|
|
*/
|
|
void szsSubfileFree(SzsSubfile* subfile);
|
|
|
|
/**
|
|
* Refresh the list of subfiles inside a SZS file.
|
|
* @param file the file to refresh the subfiles from
|
|
* @param force ignore the cache system and refresh the subfiles no matter what
|
|
*/
|
|
void szsFileDiscover(SzsFile* file, bool force);
|
|
|
|
/**
|
|
* Create an iterator to iterate through the subfiles of a SZS file.
|
|
* @param file the file to iterate
|
|
* @return an iterator
|
|
*/
|
|
SzsSubfileIterator* szsSubfileIterateNew(SzsFile* file);
|
|
|
|
/**
|
|
* Free from the memory a SZS subfile iterator.
|
|
* @param iterator the iterator
|
|
*/
|
|
void szsSubfileIterateFree(SzsSubfileIterator* iterator);
|
|
|
|
/**
|
|
* Return the next subfile in the iterator
|
|
* @param iterator the iterator to the subfiles
|
|
* @return the next subfile
|
|
* @warning you need to manually free the returned SzsSubfile with `szsSubfileFree` after usage.
|
|
*/
|
|
SzsSubfile* szsSubfileIterateNext(SzsSubfileIterator* iterator);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|