|
@ -8,25 +8,11 @@ |
|
|
#include "structure.h" |
|
|
#include "structure.h" |
|
|
#include "assets.h" |
|
|
#include "assets.h" |
|
|
|
|
|
|
|
|
//assets update;
|
|
|
asset **update_info; |
|
|
|
|
|
|
|
|
//void assets_update();
|
|
|
void assets_update_entry(); |
|
|
//void assets_dump(assets *info);
|
|
|
|
|
|
void extract(const char *file); |
|
|
void extract(const char *file); |
|
|
|
|
|
|
|
|
//void assets_free(assets *info) { // free assets mapping
|
|
|
|
|
|
// string_list_free(info->update_file);
|
|
|
|
|
|
// string_list_free(info->update_url);
|
|
|
|
|
|
// free(info);
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//assets* assets_init() { // init assets mapping
|
|
|
|
|
|
// assets *info = (assets *)malloc(sizeof(assets));
|
|
|
|
|
|
// info->update_file = string_list_init();
|
|
|
|
|
|
// info->update_url = string_list_init();
|
|
|
|
|
|
// return info;
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
asset* asset_init(const char *name) { // init asset item
|
|
|
asset* asset_init(const char *name) { // init asset item
|
|
|
asset *res = (asset *)malloc(sizeof(asset)); |
|
|
asset *res = (asset *)malloc(sizeof(asset)); |
|
|
res->file = strdup(name); |
|
|
res->file = strdup(name); |
|
@ -34,23 +20,13 @@ asset* asset_init(const char *name) { // init asset item |
|
|
return res; |
|
|
return res; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//void asset_add_src(asset *res, const char *src) { // append source for asset item
|
|
|
|
|
|
// string_list_append(&res->sources, src);
|
|
|
|
|
|
//}
|
|
|
|
|
|
//
|
|
|
|
|
|
//void asset_free(asset *res) { // free asset item
|
|
|
|
|
|
// string_list_free(res->sources);
|
|
|
|
|
|
// free(res->file);
|
|
|
|
|
|
// free(res);
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
asset** assets_init() { // init assets list
|
|
|
asset** assets_init() { // init assets list
|
|
|
asset **asset_list = (asset **)malloc(sizeof(asset *)); |
|
|
asset **asset_list = (asset **)malloc(sizeof(asset *)); |
|
|
*asset_list = NULL; // list end sign
|
|
|
*asset_list = NULL; // list end sign
|
|
|
return asset_list; |
|
|
return asset_list; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void assets_free(asset **asset_list) { |
|
|
void assets_free(asset **asset_list) { // free assets list
|
|
|
for (asset **res = asset_list; *res != NULL; ++res) { |
|
|
for (asset **res = asset_list; *res != NULL; ++res) { |
|
|
string_list_free((*res)->sources); |
|
|
string_list_free((*res)->sources); |
|
|
free((*res)->file); |
|
|
free((*res)->file); |
|
@ -59,49 +35,46 @@ void assets_free(asset **asset_list) { |
|
|
free(asset_list); |
|
|
free(asset_list); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
uint32_t assets_size(asset **asset_list) { // get size of asset list
|
|
|
uint32_t assets_size(asset **asset_list) { // get size of assets list
|
|
|
uint32_t num = 0; |
|
|
uint32_t num = 0; |
|
|
while(asset_list[num++] != NULL); // get list size
|
|
|
while(asset_list[num++] != NULL); // get list size
|
|
|
return num - 1; |
|
|
return num - 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void assets_dump(asset **asset_list) { |
|
|
void assets_dump(asset **asset_list) { // dump assets list content into debug log
|
|
|
for (asset **res = asset_list; *res != NULL; ++res) { // iterate over each item
|
|
|
for (asset **res = asset_list; *res != NULL; ++res) { // iterate over each item
|
|
|
char *sources = string_list_dump((*res)->sources); |
|
|
char *sources = string_list_dump((*res)->sources); |
|
|
log_info("Asset item `%s` -> %s", (*res)->file, sources); |
|
|
log_debug("Asset item `%s` -> %s", (*res)->file, sources); |
|
|
free(sources); |
|
|
free(sources); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void assets_append(asset ***asset_list, asset *res) { // append asset item for asset list
|
|
|
void assets_append(asset ***asset_list, asset *res) { // push asset item for assets list
|
|
|
uint32_t len = assets_size(*asset_list); |
|
|
uint32_t len = assets_size(*asset_list); |
|
|
*asset_list = (asset **)realloc(*asset_list, sizeof(asset *) * (len + 2)); // extend asset list
|
|
|
*asset_list = (asset **)realloc(*asset_list, sizeof(asset *) * (len + 2)); // extend asset list
|
|
|
(*asset_list)[len] = res; |
|
|
(*asset_list)[len] = res; |
|
|
(*asset_list)[len + 1] = NULL; // list end sign
|
|
|
(*asset_list)[len + 1] = NULL; // list end sign
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//void assets_dump(assets *info) { // show assets mapping in debug log
|
|
|
void assets_load(asset **info) { // load assets list
|
|
|
// for (char **file = info->update_file; *file != NULL; ++file) {
|
|
|
update_info = assets_init(); |
|
|
// char **url = file - info->update_file + info->update_url;
|
|
|
for (asset **res = info; *res != NULL; ++res) { |
|
|
// log_info("Asset `%s` -> %s", *file, *url);
|
|
|
assets_append(&update_info, *res); // pointer movement
|
|
|
// }
|
|
|
} |
|
|
//}
|
|
|
*info = NULL; // disable old assets list
|
|
|
|
|
|
assets_dump(update_info); |
|
|
|
|
|
log_info("Remote assets load success"); |
|
|
|
|
|
signal(SIGALRM, assets_update_entry); // receive SIGALRM signal
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//void assets_load(assets *info) { // load assets mapping
|
|
|
void assets_update_entry() { // receive SIGALRM for update all assets
|
|
|
// update.update_file = string_list_init();
|
|
|
if (assets_size(update_info) == 0) { // empty assets list
|
|
|
// update.update_url = string_list_init();
|
|
|
log_info("Skip update assets"); |
|
|
// string_list_update(&update.update_file, info->update_file);
|
|
|
return; |
|
|
// string_list_update(&update.update_url, info->update_url);
|
|
|
} |
|
|
// signal(SIGALRM, assets_update); // receive SIGALRM signal
|
|
|
log_info("Start assets update"); |
|
|
// assets_dump(&update);
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//void assets_update() { // update all assets
|
|
|
// TODO: call rust `assets_update` function
|
|
|
// if (!string_list_len(update.update_file)) { // empty assets mapping
|
|
|
|
|
|
// log_info("Skip update assets");
|
|
|
|
|
|
// return;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// log_info("Start assets update");
|
|
|
|
|
|
// for (char **file = update.update_file; *file != NULL; ++file) {
|
|
|
// for (char **file = update.update_file; *file != NULL; ++file) {
|
|
|
// char **url = file - update.update_file + update.update_url;
|
|
|
// char **url = file - update.update_file + update.update_url;
|
|
|
// char *asset_file = string_join(ASSETS_DIR, *file);
|
|
|
// char *asset_file = string_join(ASSETS_DIR, *file);
|
|
@ -109,10 +82,11 @@ void assets_append(asset ***asset_list, asset *res) { // append asset item for a |
|
|
// download_file(asset_file, *url); // download asset from url
|
|
|
// download_file(asset_file, *url); // download asset from url
|
|
|
// free(asset_file);
|
|
|
// free(asset_file);
|
|
|
// }
|
|
|
// }
|
|
|
// log_info("Restart overture");
|
|
|
|
|
|
// run_command("pgrep overture | xargs kill"); // restart overture
|
|
|
log_info("Restart overture"); |
|
|
// log_info("Assets update complete");
|
|
|
run_command("pgrep overture | xargs kill"); // restart overture
|
|
|
//}
|
|
|
log_info("Assets update complete"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void assets_extract() { // init assets and load update process
|
|
|
void assets_extract() { // init assets and load update process
|
|
|
log_info("Start loading assets"); |
|
|
log_info("Start loading assets"); |
|
|