+static int gui_type_check(VTOY_JSON *pstNode)
+{
+ FILE *fp = NULL;
+ const char *env = NULL;
+ const char *arch = NULL;
+ const char *srctype = NULL;
+ const char *srcname = NULL;
+ const char *condition = NULL;
+ const char *expression = NULL;
+ char line[1024];
+
+ arch = vtoy_json_get_string_ex(pstNode, "arch");
+ srctype = vtoy_json_get_string_ex(pstNode, "type");
+ srcname = vtoy_json_get_string_ex(pstNode, "name");
+ condition = vtoy_json_get_string_ex(pstNode, "condition");
+ expression = vtoy_json_get_string_ex(pstNode, "expression");
+
+ if (srctype == NULL || srcname == NULL || condition == NULL)
+ {
+ return 0;
+ }
+
+ if (arch && NULL == strstr(arch, VTOY_GUI_ARCH))
+ {
+ return 0;
+ }
+
+ vlog("check <%s> <%s> <%s>\n", srctype, srcname, condition);
+
+ if (strcmp(srctype, "file") == 0)
+ {
+ if (access(srcname, F_OK) == -1)
+ {
+ return 0;
+ }
+
+ if (strcmp(condition, "exist") == 0)
+ {
+ vlog("File %s exist\n", srcname);
+ return 1;
+ }
+ else if (strcmp(condition, "contains") == 0)
+ {
+ fp = fopen(srcname, "r");
+ if (fp == NULL)
+ {
+ return 0;
+ }
+
+ while (fgets(line, sizeof(line), fp))
+ {
+ if (strstr(line, expression))
+ {
+ vlog("File %s contains %s\n", srcname, expression);
+ fclose(fp);
+ return 1;
+ }
+ }
+
+ fclose(fp);
+ return 0;
+ }
+ }
+ else if (strcmp(srctype, "env") == 0)
+ {
+ env = getenv(srcname);
+ if (env == NULL)
+ {
+ return 0;
+ }
+
+ if (strcmp(condition, "exist") == 0)
+ {
+ vlog("env %s exist\n", srcname);
+ return 1;
+ }
+ else if (strcmp(condition, "equal") == 0)
+ {
+ if (strcmp(expression, env) == 0)
+ {
+ vlog("env %s is %s\n", srcname, env);
+ return 1;
+ }
+ return 0;
+ }
+ else if (strcmp(condition, "contains") == 0)
+ {
+ if (strstr(env, expression))
+ {
+ vlog("env %s is %s contains %s\n", srcname, env, expression);
+ return 1;
+ }
+ return 0;
+ }
+ }
+
+ return 0;
+}
+
+static int read_file_to_buf(const char *FileName, int ExtLen, void **Bufer, int *BufLen)
+{
+ int FileSize;
+ FILE *fp = NULL;
+ void *Data = NULL;
+
+ fp = fopen(FileName, "rb");
+ if (fp == NULL)
+ {
+ vlog("Failed to open file %s", FileName);
+ return 1;
+ }
+
+ fseek(fp, 0, SEEK_END);
+ FileSize = (int)ftell(fp);
+
+ Data = malloc(FileSize + ExtLen);
+ if (!Data)
+ {
+ fclose(fp);
+ return 1;
+ }
+
+ fseek(fp, 0, SEEK_SET);
+ fread(Data, 1, FileSize, fp);
+
+ fclose(fp);
+
+ *Bufer = Data;
+ *BufLen = FileSize;
+
+ return 0;
+}
+
+static int distro_check_gui_env(char *type, int len, int *pver)
+{
+ int size;
+ int length;
+ char *pBuf = NULL;
+ VTOY_JSON *pstNode = NULL;
+ VTOY_JSON *pstJson = NULL;
+
+ vlog("distro_check_gui_env ...\n");
+
+ if (access("./tool/distro_gui_type.json", F_OK) == -1)
+ {
+ vlog("distro_gui_type.json file not exist\n");
+ return 0;
+ }
+
+ read_file_to_buf("./tool/distro_gui_type.json", 1, (void **)&pBuf, &size);
+ pBuf[size] = 0;
+
+ pstJson = vtoy_json_create();
+ vtoy_json_parse(pstJson, pBuf);
+
+ for (pstNode = pstJson->pstChild; pstNode; pstNode = pstNode->pstNext)
+ {
+ if (gui_type_check(pstNode->pstChild))
+ {
+ length = (int)snprintf(type, len, "%s", vtoy_json_get_string_ex(pstNode->pstChild, "gui"));
+ *pver = type[length - 1] - '0';
+ type[length - 1] = 0;
+ break;
+ }
+ }
+
+ vtoy_json_destroy(pstJson);
+ return pstNode ? 1 : 0;
+}
+
+static int detect_gui_exe_path(int argc, char **argv, const char *curpath, char *pathbuf, int buflen)