2018-05-04 11:47:09 +08:00
|
|
|
/**
|
|
|
|
* File: main.cc
|
2018-05-15 09:31:58 +08:00
|
|
|
* Author: AWTK Develop Team
|
2018-05-04 11:47:09 +08:00
|
|
|
* Brief: generate str binary data from xml
|
|
|
|
*
|
2020-01-01 11:27:36 +08:00
|
|
|
* Copyright (c) 2018 - 2020 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
2018-05-04 11:47:09 +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-05-03 Li XianJing <xianjimli@hotmail.com> created
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-12-15 17:22:05 +08:00
|
|
|
#include "tkc/mem.h"
|
2018-05-04 11:47:09 +08:00
|
|
|
#include "xml_str_gen.h"
|
2019-12-25 17:36:14 +08:00
|
|
|
#include "tkc/str.h"
|
2020-03-23 12:16:07 +08:00
|
|
|
#include "tkc/fs.h"
|
|
|
|
#include "tkc/path.h"
|
|
|
|
#include "common/utils.h"
|
|
|
|
|
|
|
|
ret_t gen_one(const char* input_file, const char* output_file, const char* theme,
|
|
|
|
bool_t output_bin) {
|
|
|
|
ret_t ret = RET_OK;
|
|
|
|
if (!xml_to_str_gen(input_file, output_file, theme, output_bin)) {
|
|
|
|
ret = RET_FAIL;
|
|
|
|
GEN_ERROR(input_file);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-01-15 18:36:34 +08:00
|
|
|
static ret_t gen_folder(const char* in_foldername, const char* out_foldername, const char* theme,
|
2020-03-23 12:16:07 +08:00
|
|
|
bool_t output_bin) {
|
|
|
|
ret_t ret = RET_OK;
|
2021-01-15 18:36:34 +08:00
|
|
|
fs_dir_t* dir = fs_open_dir(os_fs(), in_foldername);
|
2020-03-23 12:16:07 +08:00
|
|
|
fs_item_t item;
|
|
|
|
char in_name[MAX_PATH] = {0};
|
2020-05-04 15:28:46 +08:00
|
|
|
while (fs_dir_read(dir, &item) != RET_FAIL) {
|
2020-11-27 16:24:49 +08:00
|
|
|
if (item.is_reg_file && case_end_with(item.name, ".xml")) {
|
2021-01-15 18:36:34 +08:00
|
|
|
path_build(in_name, MAX_PATH, in_foldername, item.name, NULL);
|
|
|
|
ret = gen_one(in_name, out_foldername, theme, output_bin);
|
2020-03-23 16:36:06 +08:00
|
|
|
if (ret == RET_FAIL) {
|
2020-03-23 12:16:07 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fs_dir_close(dir);
|
|
|
|
return ret;
|
|
|
|
}
|
2018-05-04 11:47:09 +08:00
|
|
|
|
2019-12-25 17:36:14 +08:00
|
|
|
int wmain(int argc, wchar_t* argv[]) {
|
2020-03-23 12:16:07 +08:00
|
|
|
bool_t output_bin = argc == 4;
|
2018-05-04 11:47:09 +08:00
|
|
|
|
2020-06-17 17:59:38 +08:00
|
|
|
platform_prepare();
|
2018-05-04 11:47:09 +08:00
|
|
|
|
|
|
|
if (argc < 3) {
|
2020-07-14 16:54:20 +08:00
|
|
|
printf("Usage: %S input outputdir [bin] [theme]\n", argv[0]);
|
2018-05-04 11:47:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-12-25 17:36:14 +08:00
|
|
|
const char* in_filename = NULL;
|
|
|
|
const char* out_filename = NULL;
|
|
|
|
|
|
|
|
str_t in_file;
|
|
|
|
str_t out_file;
|
2020-03-23 12:16:07 +08:00
|
|
|
str_t theme_name;
|
2019-12-25 17:36:14 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2020-03-23 12:16:07 +08:00
|
|
|
str_init(&theme_name, 0);
|
|
|
|
if (argc > 4) {
|
|
|
|
str_from_wstr(&theme_name, argv[4]);
|
|
|
|
}
|
|
|
|
|
|
|
|
fs_stat_info_t in_stat_info;
|
|
|
|
fs_stat_info_t out_stat_info;
|
|
|
|
fs_stat(os_fs(), in_filename, &in_stat_info);
|
|
|
|
fs_stat(os_fs(), out_filename, &out_stat_info);
|
|
|
|
if (in_stat_info.is_dir == TRUE && out_stat_info.is_dir == TRUE) {
|
2021-01-15 18:36:34 +08:00
|
|
|
gen_folder(in_filename, out_filename, theme_name.str, output_bin);
|
2020-03-23 12:16:07 +08:00
|
|
|
} else if (in_stat_info.is_reg_file == TRUE) {
|
|
|
|
gen_one(in_filename, out_filename, theme_name.str, output_bin);
|
|
|
|
} else {
|
|
|
|
GEN_ERROR(in_filename);
|
|
|
|
}
|
2019-12-25 17:36:14 +08:00
|
|
|
|
|
|
|
str_reset(&in_file);
|
|
|
|
str_reset(&out_file);
|
2020-03-23 12:16:07 +08:00
|
|
|
str_reset(&theme_name);
|
2018-05-04 11:47:09 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-12-25 17:36:14 +08:00
|
|
|
|
|
|
|
#include "common/main.inc"
|