2018-04-01 08:12:52 +08:00
|
|
|
/**
|
|
|
|
* File: main.c
|
2018-05-15 09:31:58 +08:00
|
|
|
* Author: AWTK Develop Team
|
2018-04-01 08:12:52 +08:00
|
|
|
* Brief: res to c source
|
|
|
|
*
|
2020-01-01 11:27:36 +08:00
|
|
|
* Copyright (c) 2018 - 2020 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
2018-04-01 08:12:52 +08:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* License file for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* History:
|
|
|
|
* ================================================================
|
|
|
|
* 2018-04-01 Li XianJing <xianjimli@hotmail.com> created
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-12-15 17:22:05 +08:00
|
|
|
#include "tkc/mem.h"
|
2018-04-01 08:12:52 +08:00
|
|
|
#include "common/utils.h"
|
2018-08-24 07:45:37 +08:00
|
|
|
#include "base/assets_manager.h"
|
2018-04-01 08:12:52 +08:00
|
|
|
|
2019-12-25 17:36:14 +08:00
|
|
|
int wmain(int argc, wchar_t* argv[]) {
|
2018-04-01 08:12:52 +08:00
|
|
|
uint32_t size = 0;
|
|
|
|
uint8_t* input_buff = NULL;
|
2018-11-02 11:51:14 +08:00
|
|
|
const char* in_filename = NULL;
|
|
|
|
const char* out_filename = NULL;
|
2018-04-01 08:12:52 +08:00
|
|
|
|
2018-05-04 11:45:09 +08:00
|
|
|
TKMEM_INIT(4 * 1024 * 1024);
|
2018-04-01 08:12:52 +08:00
|
|
|
|
|
|
|
if (argc != 3) {
|
2019-12-25 17:36:14 +08:00
|
|
|
printf("Usage: %S in_filename out_filename\n", argv[0]);
|
2018-04-01 08:12:52 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-12-25 17:36:14 +08:00
|
|
|
str_t in_file;
|
|
|
|
str_t out_file;
|
|
|
|
|
|
|
|
str_init(&in_file, 0);
|
|
|
|
str_init(&out_file, 0);
|
|
|
|
|
|
|
|
str_from_wstr(&in_file, argv[1]);
|
|
|
|
str_from_wstr(&out_file, argv[2]);
|
|
|
|
|
|
|
|
in_filename = in_file.str;
|
|
|
|
out_filename = out_file.str;
|
2018-04-01 08:12:52 +08:00
|
|
|
|
2018-11-02 11:51:14 +08:00
|
|
|
exit_if_need_not_update(in_filename, out_filename);
|
|
|
|
|
|
|
|
input_buff = (uint8_t*)read_file(in_filename, &size);
|
2018-04-01 08:12:52 +08:00
|
|
|
return_value_if_fail(input_buff != NULL, 0);
|
2018-11-02 11:51:14 +08:00
|
|
|
if (end_with(in_filename, ".ttf")) {
|
|
|
|
output_res_c_source(out_filename, ASSET_TYPE_FONT, ASSET_TYPE_FONT_TTF, input_buff, size);
|
|
|
|
} else if (end_with(in_filename, ".png")) {
|
|
|
|
output_res_c_source(out_filename, ASSET_TYPE_IMAGE, ASSET_TYPE_IMAGE_PNG, input_buff, size);
|
2019-07-09 17:31:29 +08:00
|
|
|
} else if (end_with(in_filename, ".bmp")) {
|
|
|
|
output_res_c_source(out_filename, ASSET_TYPE_IMAGE, ASSET_TYPE_IMAGE_BMP, input_buff, size);
|
2018-11-02 11:51:14 +08:00
|
|
|
} else if (end_with(in_filename, ".jpg")) {
|
|
|
|
output_res_c_source(out_filename, ASSET_TYPE_IMAGE, ASSET_TYPE_IMAGE_JPG, input_buff, size);
|
2020-02-21 07:56:31 +08:00
|
|
|
} else if (end_with(in_filename, ".jpeg")) {
|
|
|
|
output_res_c_source(out_filename, ASSET_TYPE_IMAGE, ASSET_TYPE_IMAGE_JPG, input_buff, size);
|
2018-11-27 09:37:44 +08:00
|
|
|
} else if (end_with(in_filename, ".gif")) {
|
|
|
|
output_res_c_source(out_filename, ASSET_TYPE_IMAGE, ASSET_TYPE_IMAGE_GIF, input_buff, size);
|
2019-05-07 17:17:57 +08:00
|
|
|
} else if (end_with(in_filename, ".lz4")) {
|
|
|
|
output_res_c_source(out_filename, ASSET_TYPE_IMAGE, ASSET_TYPE_IMAGE_LZ4, input_buff, size);
|
|
|
|
} else if (end_with(in_filename, ".webp")) {
|
|
|
|
output_res_c_source(out_filename, ASSET_TYPE_IMAGE, ASSET_TYPE_IMAGE_WEBP, input_buff, size);
|
2019-02-07 17:27:19 +08:00
|
|
|
} else if (end_with(in_filename, ".js")) {
|
|
|
|
output_res_c_source(out_filename, ASSET_TYPE_SCRIPT, ASSET_TYPE_SCRIPT_JS, input_buff, size);
|
|
|
|
} else if (end_with(in_filename, ".lua")) {
|
|
|
|
output_res_c_source(out_filename, ASSET_TYPE_SCRIPT, ASSET_TYPE_SCRIPT_LUA, input_buff, size);
|
|
|
|
} else if (end_with(in_filename, ".py")) {
|
|
|
|
output_res_c_source(out_filename, ASSET_TYPE_SCRIPT, ASSET_TYPE_SCRIPT_PYTHON, input_buff,
|
|
|
|
size);
|
2019-03-15 17:44:48 +08:00
|
|
|
} else if (end_with(in_filename, ".xml")) {
|
|
|
|
output_res_c_source(out_filename, ASSET_TYPE_XML, 0, input_buff, size);
|
2019-05-07 17:17:57 +08:00
|
|
|
} else if (strstr(in_filename, "images") != NULL) {
|
|
|
|
output_res_c_source(out_filename, ASSET_TYPE_IMAGE, ASSET_TYPE_IMAGE_OTHER, input_buff, size);
|
2018-04-01 08:12:52 +08:00
|
|
|
} else {
|
2019-03-20 11:16:26 +08:00
|
|
|
const char* name = strrchr(in_filename, '/');
|
|
|
|
if (name == NULL) {
|
|
|
|
name = strrchr(in_filename, '\\');
|
|
|
|
}
|
|
|
|
if (name != NULL) {
|
|
|
|
name++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end_with(in_filename, ".txt")) {
|
|
|
|
output_res_c_source_ex(out_filename, ASSET_TYPE_DATA, ASSET_TYPE_DATA_TEXT, input_buff, size,
|
|
|
|
name);
|
|
|
|
} else if (end_with(in_filename, ".json")) {
|
|
|
|
output_res_c_source_ex(out_filename, ASSET_TYPE_DATA, ASSET_TYPE_DATA_JSON, input_buff, size,
|
|
|
|
name);
|
|
|
|
} else if (end_with(in_filename, ".bin")) {
|
|
|
|
output_res_c_source_ex(out_filename, ASSET_TYPE_DATA, ASSET_TYPE_DATA_BIN, input_buff, size,
|
|
|
|
name);
|
|
|
|
} else if (end_with(in_filename, ".dat")) {
|
|
|
|
output_res_c_source_ex(out_filename, ASSET_TYPE_DATA, ASSET_TYPE_DATA_DAT, input_buff, size,
|
|
|
|
name);
|
|
|
|
} else {
|
|
|
|
output_res_c_source_ex(out_filename, ASSET_TYPE_DATA, ASSET_TYPE_DATA_NONE, input_buff, size,
|
|
|
|
name);
|
|
|
|
}
|
2018-04-01 08:12:52 +08:00
|
|
|
}
|
|
|
|
|
2018-04-29 16:51:54 +08:00
|
|
|
TKMEM_FREE(input_buff);
|
2018-04-01 08:12:52 +08:00
|
|
|
|
2019-12-25 17:36:14 +08:00
|
|
|
str_reset(&in_file);
|
|
|
|
str_reset(&out_file);
|
|
|
|
|
2018-04-01 08:12:52 +08:00
|
|
|
printf("done\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-12-25 17:36:14 +08:00
|
|
|
|
|
|
|
#include "common/main.inc"
|