|
@ -8,59 +8,112 @@ |
|
|
#include "structure.h" |
|
|
#include "structure.h" |
|
|
#include "assets.h" |
|
|
#include "assets.h" |
|
|
|
|
|
|
|
|
assets update; |
|
|
//assets update;
|
|
|
|
|
|
|
|
|
void assets_update(); |
|
|
//void assets_update();
|
|
|
void assets_dump(assets *info); |
|
|
//void assets_dump(assets *info);
|
|
|
void extract(const char *file); |
|
|
void extract(const char *file); |
|
|
|
|
|
|
|
|
void assets_free(assets *info) { // free assets mapping
|
|
|
//void assets_free(assets *info) { // free assets mapping
|
|
|
string_list_free(info->update_file); |
|
|
// string_list_free(info->update_file);
|
|
|
string_list_free(info->update_url); |
|
|
// string_list_free(info->update_url);
|
|
|
free(info); |
|
|
// 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 *res = (asset *)malloc(sizeof(asset)); |
|
|
|
|
|
res->file = strdup(name); |
|
|
|
|
|
res->sources = string_list_init(); // with multi sources
|
|
|
|
|
|
return res; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
assets* assets_init() { // init assets mapping
|
|
|
//void asset_add_src(asset *res, const char *src) { // append source for asset item
|
|
|
assets *info = (assets *)malloc(sizeof(assets)); |
|
|
// string_list_append(&res->sources, src);
|
|
|
info->update_file = string_list_init(); |
|
|
//}
|
|
|
info->update_url = string_list_init(); |
|
|
//
|
|
|
return info; |
|
|
//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 **asset_list = (asset **)malloc(sizeof(asset *)); |
|
|
|
|
|
*asset_list = NULL; // list end sign
|
|
|
|
|
|
return asset_list; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void assets_dump(assets *info) { // show assets mapping in debug log
|
|
|
void assets_free(asset **asset_list) { |
|
|
for (char **file = info->update_file; *file != NULL; ++file) { |
|
|
for (asset **res = asset_list; *res != NULL; ++res) { |
|
|
char **url = file - info->update_file + info->update_url; |
|
|
string_list_free((*res)->sources); |
|
|
log_info("Asset `%s` -> %s", *file, *url); |
|
|
free((*res)->file); |
|
|
|
|
|
free(*res); |
|
|
} |
|
|
} |
|
|
|
|
|
free(asset_list); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void assets_load(assets *info) { // load assets mapping
|
|
|
uint32_t assets_size(asset **asset_list) { // get size of asset list
|
|
|
update.update_file = string_list_init(); |
|
|
uint32_t num = 0; |
|
|
update.update_url = string_list_init(); |
|
|
while(asset_list[num++] != NULL); // get list size
|
|
|
string_list_update(&update.update_file, info->update_file); |
|
|
return num - 1; |
|
|
string_list_update(&update.update_url, info->update_url); |
|
|
|
|
|
signal(SIGALRM, assets_update); // receive SIGALRM signal
|
|
|
|
|
|
assets_dump(&update); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void assets_update() { // update all assets
|
|
|
void assets_dump(asset **asset_list) { |
|
|
if (!string_list_len(update.update_file)) { // empty assets mapping
|
|
|
for (asset **res = asset_list; *res != NULL; ++res) { // iterate over each item
|
|
|
log_info("Skip update assets"); |
|
|
char *sources = string_list_dump((*res)->sources); |
|
|
return; |
|
|
log_info("Asset item `%s` -> %s", (*res)->file, sources); |
|
|
} |
|
|
free(sources); |
|
|
log_info("Start assets update"); |
|
|
|
|
|
for (char **file = update.update_file; *file != NULL; ++file) { |
|
|
|
|
|
char **url = file - update.update_file + update.update_url; |
|
|
|
|
|
char *asset_file = string_join(ASSETS_DIR, *file); |
|
|
|
|
|
log_info("Update asset `%s` -> %s", asset_file, *url); |
|
|
|
|
|
download_file(asset_file, *url); // download asset from url
|
|
|
|
|
|
free(asset_file); |
|
|
|
|
|
} |
|
|
} |
|
|
log_info("Restart overture"); |
|
|
|
|
|
run_command("pgrep overture | xargs kill"); // restart overture
|
|
|
|
|
|
log_info("Assets update complete"); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void assets_append(asset ***asset_list, asset *res) { // append asset item for asset list
|
|
|
|
|
|
uint32_t len = assets_size(*asset_list); |
|
|
|
|
|
*asset_list = (asset **)realloc(*asset_list, sizeof(asset *) * (len + 2)); // extend asset list
|
|
|
|
|
|
(*asset_list)[len] = res; |
|
|
|
|
|
(*asset_list)[len + 1] = NULL; // list end sign
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//void assets_dump(assets *info) { // show assets mapping in debug log
|
|
|
|
|
|
// for (char **file = info->update_file; *file != NULL; ++file) {
|
|
|
|
|
|
// char **url = file - info->update_file + info->update_url;
|
|
|
|
|
|
// log_info("Asset `%s` -> %s", *file, *url);
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//void assets_load(assets *info) { // load assets mapping
|
|
|
|
|
|
// update.update_file = string_list_init();
|
|
|
|
|
|
// update.update_url = string_list_init();
|
|
|
|
|
|
// string_list_update(&update.update_file, info->update_file);
|
|
|
|
|
|
// string_list_update(&update.update_url, info->update_url);
|
|
|
|
|
|
// signal(SIGALRM, assets_update); // receive SIGALRM signal
|
|
|
|
|
|
// assets_dump(&update);
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//void assets_update() { // update all assets
|
|
|
|
|
|
// 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) {
|
|
|
|
|
|
// char **url = file - update.update_file + update.update_url;
|
|
|
|
|
|
// char *asset_file = string_join(ASSETS_DIR, *file);
|
|
|
|
|
|
// log_info("Update asset `%s` -> %s", asset_file, *url);
|
|
|
|
|
|
// download_file(asset_file, *url); // download asset from url
|
|
|
|
|
|
// free(asset_file);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// log_info("Restart overture");
|
|
|
|
|
|
// 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"); |
|
|
create_folder(ASSETS_DIR); |
|
|
create_folder(ASSETS_DIR); |
|
|