#define APP_RES_PATH "/user/res"
#define APP_MUSIC_PATH "/user/music"
#define APP_VIDEO_PATH "/user/video"
-#define APP_DIAL_PATH "/user/dial"
+#define APP_DEFAULT_DIAL_PATH "/user/dial" /*默认表盘路径*/
+#define APP_DOWNLOAD_DIAL_PATH "/user/userdata/dial" /*安装表盘路径*/
#define APP_LIST_PATH "/user/res/applist_icon"
/* ---------------------------------- 卡片管理 --------------------------------- */
static constexpr const char *CARD_CONFIG_PATH = "/user/cardconfig.bin";
static constexpr const char *PNG_TOGGLEBUTTON_OFF_IMAGE = APP_RES_PATH "/TOGGLEBUTTON_OFF.bin"; // togglebuttton未选中图片
static constexpr const char *PNG_TOGGLEBUTTON_ON_IMAGE = APP_RES_PATH "/TOGGLEBUTTON_ON.bin"; // togglebuttton选中图片
static constexpr const char *PNG_ATTENTION_IMAGE = APP_RES_PATH "/Attention.bin"; // 注意
- static constexpr const char *PNG_BUTTON_466x100_IMAGE = APP_RES_PATH "/466x100button.bin";
+ static constexpr const char *PNG_BUTTON_466x100_IMAGE = APP_RES_PATH "/466x100button.bin";
static constexpr const char *PNG_SUCC_IMAGE = APP_RES_PATH "/OK.bin"; // 成功
+/***
+ * @Date: 2024-06-17 11:38:34
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-21 11:13:24
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h
+ */
/***
* @Date: 2024-05-30 15:59:37
* @LastEditors: Caisking 3449750381@qq.com
namespace OHOS
{
+ // 表盘类型
+ enum DIALTYPE
+ {
+ DEFULTDIAL,
+ DOWNLOADDIAL,
+ };
class SetDialModel
{
public:
private:
void LoadAllDialFromRam(void);
void LoadAllDialFromFs(void);
+ void LoadAllDialFromDefult(void);
SetDialModel();
SetDialModel(const SetDialModel &);
SetDialModel &operator=(const SetDialModel &);
virtual ~SetDialModel();
- int32_t ParseDialHeader(const std::string &dialFileName, SetDialInfo &dialInfo);
+ int32_t ParseDialHeader(int type, const std::string &dialFileName, SetDialInfo &dialInfo);
std::vector<SetDialInfo> dialInfoList;
uint16_t currentDialID;
};
/* 注册表盘map */
void SetDialModel::RegisterDial(uint16_t ID, const char *dialname)
{
- // char *dialname_=(char *)malloc(strlen(dialname)+1);
-
- // memcpy_s(dialname_,strlen(dialname)+1,dialname,strlen(dialname)+1);
-
std::string *dialname_ = new std::string(dialname);
registeredDials[ID] = *dialname_; // 唯一性
{
memcpy_s(allidStr + length, 512, &entry.first, 2);
length += 2;
- // // 格式化表盘ID为两个字节长度的字符串,不足两位则在前面补0
- // std::stringstream ss;
- // ss << std::setw(2) << std::setfill('0') << entry.first;
- // allIDs += ss.str();
}
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "allidStr is %s %d", allIDs.c_str(), length);
-
- // // 将字符串拷贝到allidStr中
- // int length = allIDs.size();
- // if (length > 0)
- // {
- // strcpy(allidStr, allIDs.c_str());
- // allidStr[length] = '\0'; // 添加字符串结尾的空字符
- // }
-
return length;
}
/* 判断表盘是否存在*/
return false;
}
- /*删除文件操作*/
- std::string dialFullName = APP_DIAL_PATH;
+ /*删除文件操作 只删除下载表盘*/
+ std::string dialFullName = APP_DOWNLOAD_DIAL_PATH;
dialFullName += "/";
dialFullName += registeredDials[ID];
dialFullName += ".bin";
dialInfoList.clear();
LoadAllDialFromRam();
size_t dialSize = dialInfoList.size();
+ LoadAllDialFromDefult();
LoadAllDialFromFs();
/* 只排序离线表盘 */
std::sort(dialInfoList.begin() + dialSize, dialInfoList.end(), [](const SetDialInfo &f, const SetDialInfo &n)
struct dirent *direntp;
// 打开目录
- DIR *dirp = opendir(APP_DIAL_PATH);
+ DIR *dirp = opendir(APP_DOWNLOAD_DIAL_PATH);
// 遍历文件
if (dirp != nullptr)
{
while ((direntp = readdir(dirp)) != nullptr)
{
SetDialInfo dialInfo{0};
- int ret = ParseDialHeader(direntp->d_name, dialInfo);
+ int ret = ParseDialHeader(DOWNLOADDIAL, direntp->d_name, dialInfo);
+ if (ret == 0)
+ {
+ dialInfoList.push_back(dialInfo);
+ }
+ }
+ }
+ // 关闭目录
+ closedir(dirp);
+ return;
+ }
+ /*加载默认表盘*/
+ void SetDialModel::LoadAllDialFromDefult(void)
+ {
+ int ret;
+ struct dirent *direntp;
+
+ // 打开目录
+ DIR *dirp = opendir(APP_DEFAULT_DIAL_PATH);
+ // 遍历文件
+ if (dirp != nullptr)
+ {
+ while ((direntp = readdir(dirp)) != nullptr)
+ {
+ SetDialInfo dialInfo{0};
+ int ret = ParseDialHeader(DEFULTDIAL, direntp->d_name, dialInfo);
if (ret == 0)
{
dialInfoList.push_back(dialInfo);
return;
}
/*通过表盘名称解析表盘*/
- int32_t SetDialModel::ParseDialHeader(const std::string &dialFileName, SetDialInfo &dialInfo)
+ int32_t SetDialModel::ParseDialHeader(int type, const std::string &dialFileName, SetDialInfo &dialInfo)
{
- std::string dialFullName = APP_DIAL_PATH;
+ std::string dialFullName;
+ if (type == DEFULTDIAL)
+ {
+ dialFullName = APP_DEFAULT_DIAL_PATH;
+ }
+ else if (type == DOWNLOADDIAL)
+ {
+ dialFullName = APP_DOWNLOAD_DIAL_PATH;
+ }
dialFullName += "/";
dialFullName += dialFileName;
FILE *fp = fopen(dialFullName.c_str(), "rb");