|
1 | 1 | # Define default assets files (Absolute url starting with http or https is supported)
|
2 |
| -set(ASSETS_PUHUI_COMMON_14_1 "none-font_puhui_common_14_1-none.bin") |
3 |
| -set(ASSETS_XIAOZHI_WAKENET_ONLY "wn9_nihaoxiaozhi_tts-none-none.bin") |
4 |
| -set(ASSETS_XIAOZHI_PUHUI_COMMON_14_1 "wn9_nihaoxiaozhi_tts-font_puhui_common_14_1-none.bin") |
5 |
| -set(ASSETS_XIAOZHI_PUHUI_COMMON_16_4_EMOJI_32 "wn9_nihaoxiaozhi_tts-font_puhui_common_16_4-emojis_32.bin") |
6 |
| -set(ASSETS_XIAOZHI_PUHUI_COMMON_16_4_EMOJI_64 "wn9_nihaoxiaozhi_tts-font_puhui_common_16_4-emojis_64.bin") |
7 |
| -set(ASSETS_XIAOZHI_PUHUI_COMMON_20_4_EMOJI_64 "wn9_nihaoxiaozhi_tts-font_puhui_common_20_4-emojis_64.bin") |
8 |
| -set(ASSETS_XIAOZHI_PUHUI_COMMON_30_4_EMOJI_64 "wn9_nihaoxiaozhi_tts-font_puhui_common_30_4-emojis_64.bin") |
9 |
| -set(ASSETS_XIAOZHI_S_WAKENET_ONLY "wn9s_nihaoxiaozhi-none-none.bin") |
10 |
| -set(ASSETS_XIAOZHI_S_PUHUI_COMMON_14_1 "wn9s_nihaoxiaozhi-font_puhui_common_14_1-none.bin") |
11 |
| -set(ASSETS_XIAOZHI_S_PUHUI_COMMON_16_4_EMOJI_32 "wn9s_nihaoxiaozhi-font_puhui_common_16_4-emojis_32.bin") |
12 |
| -set(ASSETS_XIAOZHI_S_PUHUI_COMMON_20_4_EMOJI_32 "wn9s_nihaoxiaozhi-font_puhui_common_20_4-emojis_32.bin") |
13 |
| -set(ASSETS_XIAOZHI_S_PUHUI_COMMON_20_4_EMOJI_64 "wn9s_nihaoxiaozhi-font_puhui_common_20_4-emojis_64.bin") |
14 |
| -set(ASSETS_XIAOZHI_S_PUHUI_COMMON_30_4_EMOJI_64 "wn9s_nihaoxiaozhi-font_puhui_common_30_4-emojis_64.bin") |
| 2 | +set(ASSETS_URL_PREFIX "https://files.xiaozhi.me/assets/default/") |
| 3 | + |
| 4 | +set(ASSETS_PUHUI_COMMON_14_1 "${ASSETS_URL_PREFIX}none-font_puhui_common_14_1-none.bin") |
| 5 | +set(ASSETS_XIAOZHI_WAKENET_ONLY "${ASSETS_URL_PREFIX}wn9_nihaoxiaozhi_tts-none-none.bin") |
| 6 | +set(ASSETS_XIAOZHI_PUHUI_COMMON_14_1 "${ASSETS_URL_PREFIX}wn9_nihaoxiaozhi_tts-font_puhui_common_14_1-none.bin") |
| 7 | +set(ASSETS_XIAOZHI_PUHUI_COMMON_16_4_EMOJI_32 "${ASSETS_URL_PREFIX}wn9_nihaoxiaozhi_tts-font_puhui_common_16_4-emojis_32.bin") |
| 8 | +set(ASSETS_XIAOZHI_PUHUI_COMMON_16_4_EMOJI_64 "${ASSETS_URL_PREFIX}wn9_nihaoxiaozhi_tts-font_puhui_common_16_4-emojis_64.bin") |
| 9 | +set(ASSETS_XIAOZHI_PUHUI_COMMON_20_4_EMOJI_64 "${ASSETS_URL_PREFIX}wn9_nihaoxiaozhi_tts-font_puhui_common_20_4-emojis_64.bin") |
| 10 | +set(ASSETS_XIAOZHI_PUHUI_COMMON_30_4_EMOJI_64 "${ASSETS_URL_PREFIX}wn9_nihaoxiaozhi_tts-font_puhui_common_30_4-emojis_64.bin") |
| 11 | +set(ASSETS_XIAOZHI_S_WAKENET_ONLY "${ASSETS_URL_PREFIX}wn9s_nihaoxiaozhi-none-none.bin") |
| 12 | +set(ASSETS_XIAOZHI_S_PUHUI_COMMON_14_1 "${ASSETS_URL_PREFIX}wn9s_nihaoxiaozhi-font_puhui_common_14_1-none.bin") |
| 13 | +set(ASSETS_XIAOZHI_S_PUHUI_COMMON_16_4_EMOJI_32 "${ASSETS_URL_PREFIX}wn9s_nihaoxiaozhi-font_puhui_common_16_4-emojis_32.bin") |
| 14 | +set(ASSETS_XIAOZHI_S_PUHUI_COMMON_20_4_EMOJI_32 "${ASSETS_URL_PREFIX}wn9s_nihaoxiaozhi-font_puhui_common_20_4-emojis_32.bin") |
| 15 | +set(ASSETS_XIAOZHI_S_PUHUI_COMMON_20_4_EMOJI_64 "${ASSETS_URL_PREFIX}wn9s_nihaoxiaozhi-font_puhui_common_20_4-emojis_64.bin") |
| 16 | +set(ASSETS_XIAOZHI_S_PUHUI_COMMON_30_4_EMOJI_64 "${ASSETS_URL_PREFIX}wn9s_nihaoxiaozhi-font_puhui_common_30_4-emojis_64.bin") |
15 | 17 |
|
16 | 18 | # Embedded font files defined in `xiaozhi-fonts` component
|
17 | 19 | # Basic fonts include ASCII and about 600 characters used in assets/locales
|
@@ -743,43 +745,76 @@ if(DEFAULT_ASSETS)
|
743 | 745 | validate_default_assets_prefix("${BOARD_TYPE}" "${DEFAULT_ASSETS}")
|
744 | 746 | endif()
|
745 | 747 |
|
746 |
| -# Download and flash DEFAULT_ASSETS if defined and enabled |
747 |
| -if(DEFAULT_ASSETS AND CONFIG_FLASH_DEFAULT_ASSETS) |
748 |
| - # Construct the full URL |
749 |
| - set(ASSETS_URL "${CONFIG_DEFAULT_ASSETS_URL_PREFIX}${DEFAULT_ASSETS}") |
750 |
| - set(ASSETS_LOCAL_FILE "${CMAKE_BINARY_DIR}/${DEFAULT_ASSETS}") |
751 |
| - set(ASSETS_TEMP_FILE "${CMAKE_BINARY_DIR}/${DEFAULT_ASSETS}.tmp") |
752 |
| - |
753 |
| - # Check if local file exists |
754 |
| - if(EXISTS ${ASSETS_LOCAL_FILE}) |
755 |
| - message(STATUS "Assets file ${DEFAULT_ASSETS} already exists, skipping download") |
756 |
| - else() |
757 |
| - message(STATUS "Downloading ${DEFAULT_ASSETS}") |
758 |
| - |
759 |
| - # Clean up any existing temp file |
760 |
| - if(EXISTS ${ASSETS_TEMP_FILE}) |
761 |
| - file(REMOVE ${ASSETS_TEMP_FILE}) |
762 |
| - endif() |
| 748 | +# Function to get local assets file path (handles both URL and local file) |
| 749 | +function(get_assets_local_file assets_source assets_local_file_var) |
| 750 | + # Check if it's a URL (starts with http:// or https://) |
| 751 | + if(assets_source MATCHES "^https?://") |
| 752 | + # It's a URL, download it |
| 753 | + get_filename_component(ASSETS_FILENAME "${assets_source}" NAME) |
| 754 | + set(ASSETS_LOCAL_FILE "${CMAKE_BINARY_DIR}/${ASSETS_FILENAME}") |
| 755 | + set(ASSETS_TEMP_FILE "${CMAKE_BINARY_DIR}/${ASSETS_FILENAME}.tmp") |
763 | 756 |
|
764 |
| - # Download to temporary file first |
765 |
| - file(DOWNLOAD ${ASSETS_URL} ${ASSETS_TEMP_FILE} |
766 |
| - STATUS DOWNLOAD_STATUS) |
767 |
| - list(GET DOWNLOAD_STATUS 0 STATUS_CODE) |
768 |
| - if(NOT STATUS_CODE EQUAL 0) |
769 |
| - # Clean up temp file on failure |
| 757 | + # Check if local file exists |
| 758 | + if(EXISTS ${ASSETS_LOCAL_FILE}) |
| 759 | + message(STATUS "Assets file ${ASSETS_FILENAME} already exists, skipping download") |
| 760 | + else() |
| 761 | + message(STATUS "Downloading ${ASSETS_FILENAME}") |
| 762 | + |
| 763 | + # Clean up any existing temp file |
770 | 764 | if(EXISTS ${ASSETS_TEMP_FILE})
|
771 | 765 | file(REMOVE ${ASSETS_TEMP_FILE})
|
772 | 766 | endif()
|
773 |
| - message(FATAL_ERROR "Failed to download ${DEFAULT_ASSETS} from ${ASSETS_URL}") |
| 767 | + |
| 768 | + # Download to temporary file first |
| 769 | + file(DOWNLOAD ${assets_source} ${ASSETS_TEMP_FILE} |
| 770 | + STATUS DOWNLOAD_STATUS) |
| 771 | + list(GET DOWNLOAD_STATUS 0 STATUS_CODE) |
| 772 | + if(NOT STATUS_CODE EQUAL 0) |
| 773 | + # Clean up temp file on failure |
| 774 | + if(EXISTS ${ASSETS_TEMP_FILE}) |
| 775 | + file(REMOVE ${ASSETS_TEMP_FILE}) |
| 776 | + endif() |
| 777 | + message(FATAL_ERROR "Failed to download ${ASSETS_FILENAME} from ${assets_source}") |
| 778 | + endif() |
| 779 | + |
| 780 | + # Move temp file to final location (atomic operation) |
| 781 | + file(RENAME ${ASSETS_TEMP_FILE} ${ASSETS_LOCAL_FILE}) |
| 782 | + message(STATUS "Successfully downloaded ${ASSETS_FILENAME}") |
| 783 | + endif() |
| 784 | + else() |
| 785 | + # It's a local file path |
| 786 | + if(IS_ABSOLUTE "${assets_source}") |
| 787 | + set(ASSETS_LOCAL_FILE "${assets_source}") |
| 788 | + else() |
| 789 | + set(ASSETS_LOCAL_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${assets_source}") |
| 790 | + endif() |
| 791 | + |
| 792 | + # Check if local file exists |
| 793 | + if(NOT EXISTS ${ASSETS_LOCAL_FILE}) |
| 794 | + message(FATAL_ERROR "Assets file not found: ${ASSETS_LOCAL_FILE}") |
774 | 795 | endif()
|
775 | 796 |
|
776 |
| - # Move temp file to final location (atomic operation) |
777 |
| - file(RENAME ${ASSETS_TEMP_FILE} ${ASSETS_LOCAL_FILE}) |
778 |
| - message(STATUS "Successfully downloaded ${DEFAULT_ASSETS}") |
| 797 | + message(STATUS "Using assets file: ${ASSETS_LOCAL_FILE}") |
779 | 798 | endif()
|
780 | 799 |
|
781 |
| - # Flash assets to partition using esptool_py_flash_to_partition |
| 800 | + set(${assets_local_file_var} ${ASSETS_LOCAL_FILE} PARENT_SCOPE) |
| 801 | +endfunction() |
| 802 | + |
| 803 | +# Flash assets based on configuration |
| 804 | +if(CONFIG_FLASH_DEFAULT_ASSETS) |
| 805 | + # Flash default assets |
| 806 | + if(DEFAULT_ASSETS) |
| 807 | + get_assets_local_file("${DEFAULT_ASSETS}" ASSETS_LOCAL_FILE) |
| 808 | + esptool_py_flash_to_partition(flash "assets" "${ASSETS_LOCAL_FILE}") |
| 809 | + message(STATUS "Default assets download and flash configured: ${DEFAULT_ASSETS} -> assets partition") |
| 810 | + else() |
| 811 | + message(WARNING "FLASH_DEFAULT_ASSETS is enabled but no DEFAULT_ASSETS is defined for board ${BOARD_TYPE}") |
| 812 | + endif() |
| 813 | +elseif(CONFIG_FLASH_CUSTOM_ASSETS) |
| 814 | + # Flash custom assets |
| 815 | + get_assets_local_file("${CONFIG_CUSTOM_ASSETS_FILE}" ASSETS_LOCAL_FILE) |
782 | 816 | esptool_py_flash_to_partition(flash "assets" "${ASSETS_LOCAL_FILE}")
|
783 |
| - |
784 |
| - message(STATUS "Assets download and flash configured: ${ASSETS_URL} -> assets partition") |
| 817 | + message(STATUS "Custom assets flash configured: ${ASSETS_LOCAL_FILE} -> assets partition") |
| 818 | +elseif(CONFIG_FLASH_NONE_ASSETS) |
| 819 | + message(STATUS "Assets flashing disabled (FLASH_NONE_ASSETS)") |
785 | 820 | endif()
|
0 commit comments