118 lines
4.1 KiB
C
118 lines
4.1 KiB
C
#include "utils.h"
|
|
#include "assetmeta.h"
|
|
#include "processing.h"
|
|
#include "assetsettings.h"
|
|
#include "packages.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include "runtime/uidtab.h"
|
|
|
|
typedef struct {
|
|
char path_scratch[1024];
|
|
unsigned int path_end;
|
|
} vy_discovery_data;
|
|
|
|
static vy_result LoadCompressedAsset(vy_uid uid, void **buffer, size_t size) {
|
|
}
|
|
|
|
static vy_result DirectoryHandler(const char *name, vyIterateDirElementType type, void *user) {
|
|
vy_discovery_data *data = user;
|
|
|
|
size_t name_len = strlen(name);
|
|
|
|
if (type == VY_DIR_ELEMENT_TYPE_FILE) {
|
|
/* Skip files we don't want to process */
|
|
if (name_len >= 3) {
|
|
if (memcmp(&name[name_len - 3], ".as", 3) == 0)
|
|
return VY_SUCCESS;
|
|
}
|
|
if (name_len >= 4) {
|
|
if (memcmp(&name[name_len - 4], ".pkg", 4) == 0)
|
|
return VY_SUCCESS;
|
|
else if (memcmp(&name[name_len - 4], ".bin", 4) == 0)
|
|
return VY_SUCCESS;
|
|
}
|
|
if (name[0] == '.') {
|
|
return VY_SUCCESS;
|
|
}
|
|
|
|
/* Check if we know that file */
|
|
if (data->path_end > 0) {
|
|
data->path_scratch[data->path_end] = '/';
|
|
memcpy(data->path_scratch + data->path_end + 1, name, name_len);
|
|
data->path_scratch[data->path_end + 1 + name_len] = '\0';
|
|
} else {
|
|
memcpy(data->path_scratch, name, name_len);
|
|
data->path_scratch[name_len] = '\0';
|
|
}
|
|
|
|
vy_file_id fid = vyAddFile(data->path_scratch);
|
|
if (vyLookupUID(fid) != VY_INVALID_UID) {
|
|
vy_assetmeta meta = {0};
|
|
if (!vyGetAssetMeta(fid, &meta) || (meta.last_changed >= meta.compiled_ts)) {
|
|
/* The file (may have) changed */
|
|
vy_result res = vyAddFileToProcessingQueue(fid, meta.processing_flags);
|
|
if (res != VY_SUCCESS)
|
|
return res;
|
|
}
|
|
else {
|
|
/* The file is unchanged, we just need to add it to the output again. */
|
|
vyLog("ASSETC", "File %s is unchanged.", data->path_scratch);
|
|
|
|
vy_asset_settings settings = {0};
|
|
if (vyLoadAssetSettings(data->path_scratch, &settings) != VY_SUCCESS) {
|
|
vyLog("ASSETC", "Failed to load settings for %s", data->path_scratch);
|
|
return VY_UNKNOWN_ERROR;
|
|
}
|
|
|
|
/* We need to load the processed data and add it to the package */
|
|
vy_uid uid = vyLookupUID(fid);
|
|
const vy_uid_data *asset_data = vyGetUIDData(uid);
|
|
if (!data) {
|
|
vyLog("ASSETC", "No data available for asset %s (%u)", data->path_scratch, uid);
|
|
return VY_UNKNOWN_ERROR;
|
|
}
|
|
|
|
}
|
|
} else {
|
|
/* Process it */
|
|
vy_asset_settings settings = {0};
|
|
if (vyLoadAssetSettings(data->path_scratch, &settings) != VY_SUCCESS) {
|
|
vyLog("ASSETC", "Failed to load settings for %s", data->path_scratch);
|
|
}
|
|
|
|
vy_result res = vyAddFileToProcessingQueue(fid, settings.processing_flags);
|
|
if (res != VY_SUCCESS)
|
|
return res;
|
|
}
|
|
} else if (type == VY_DIR_ELEMENT_TYPE_DIRECTORY) {
|
|
if (strcmp(name, ".") == 0)
|
|
return VY_SUCCESS;
|
|
if (strcmp(name, "..") == 0)
|
|
return VY_SUCCESS;
|
|
|
|
unsigned int path_end_before = data->path_end;
|
|
if (data->path_end > 0)
|
|
data->path_scratch[data->path_end++] = '/';
|
|
memcpy(data->path_scratch + data->path_end, name, name_len);
|
|
data->path_scratch[data->path_end + name_len] = '\0';
|
|
data->path_end += (unsigned int)name_len;
|
|
|
|
vy_result res = vyIterateDirectory(data->path_scratch, user, DirectoryHandler);
|
|
if (res != VY_SUCCESS)
|
|
return res;
|
|
|
|
data->path_end = path_end_before;
|
|
}
|
|
return VY_SUCCESS;
|
|
}
|
|
|
|
void vyDiscoverAssets(void) {
|
|
vy_discovery_data data;
|
|
data.path_scratch[0] = '.';
|
|
data.path_scratch[1] = '\0';
|
|
data.path_end = 0;
|
|
|
|
vyIterateDirectory(".", &data, DirectoryHandler);
|
|
} |