|
@@ -6,6 +6,7 @@
|
|
|
#include "core/update_assistant.h"
|
|
|
#include "edge/popup_service.h"
|
|
|
#include "base/strings.hpp"
|
|
|
+#include "restclient-cpp/restclient.h"
|
|
|
#include "base/http_client.h"
|
|
|
#include "net/tcp_client.h"
|
|
|
#include "os/UpgradeMonitor.h"
|
|
@@ -26,6 +27,31 @@ namespace {
|
|
|
int loading_index = 0;
|
|
|
}
|
|
|
|
|
|
+Json::Value linuxVersionList;
|
|
|
+string updateUrl;
|
|
|
+static void getLinuxVersionList() {
|
|
|
+ std::string url = getHttpGateway() + "/util/get_linux_version_list";
|
|
|
+
|
|
|
+ LOGD("请求Linux设备初始化版本列表. url = %s", url.c_str());
|
|
|
+ //发起HTTP GET请求
|
|
|
+ RestClient::Response r = RestClient::get(url);
|
|
|
+ if (r.code != 200) {
|
|
|
+ LOGD("请求Linux设备初始化版本列表-> 错误代码: %d", r.code);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ LOGD("获得Linux设备初始化版本列表. result = %s", r.body.c_str());
|
|
|
+ //解析json
|
|
|
+ Json::Reader reader;
|
|
|
+ Json::Value root;
|
|
|
+
|
|
|
+ if(reader.parse(r.body, root, false)) {
|
|
|
+ linuxVersionList = root;
|
|
|
+ mDeviceTypeListViewPtr->refreshListView();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
void NavibarSetProgressWindowVisible(bool visible) {
|
|
|
mWindowProgressPtr->setVisible(visible);
|
|
|
}
|
|
@@ -234,6 +260,7 @@ static bool onButtonClick_ButtonUpdate(ZKButton *pButton) {
|
|
|
if (!NETMANAGER->getEthernetManager()->isConnected()) {
|
|
|
std::string msg = LANGUAGEMANAGER->getValue("EthernetDisconnect");
|
|
|
srv->SetMessage(msg);
|
|
|
+ mWindow1Ptr->showWnd();
|
|
|
return -1;
|
|
|
}
|
|
|
int ret = assistant.GetLatest("bed", &info);
|
|
@@ -274,3 +301,92 @@ static bool onButtonClick_ButtonDialog1(ZKButton *pButton) {
|
|
|
LOGD(" ButtonClick ButtonDialog1 !!!\n");
|
|
|
return false;
|
|
|
}
|
|
|
+static bool onButtonClick_ButtonInit(ZKButton *pButton) {
|
|
|
+ LOGD(" ButtonClick ButtonInit !!!\n");
|
|
|
+ getLinuxVersionList();
|
|
|
+ mWindowInitPtr->showWnd();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+static int getListItemCount_DeviceTypeListView(const ZKListView *pListView) {
|
|
|
+ //LOGD("getListItemCount_DeviceTypeListView !\n");
|
|
|
+ if (linuxVersionList.size() > 5) {
|
|
|
+ return linuxVersionList.size();
|
|
|
+ }
|
|
|
+ return 5;
|
|
|
+}
|
|
|
+
|
|
|
+static void obtainListItemData_DeviceTypeListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
|
|
|
+ //LOGD(" obtainListItemData_ DeviceTypeListView !!!\n");
|
|
|
+ ZKListView::ZKListSubItem* down = pListItem->findSubItemByID(ID_DEVICEUPDATE_DownSubItem);
|
|
|
+
|
|
|
+ string version = linuxVersionList[index]["type_name"].asString() + " " + linuxVersionList[index]["version_code"].asString();
|
|
|
+ if (version != " ") {
|
|
|
+ pListItem->setText(version);
|
|
|
+ down->setText(LANGUAGEMANAGER->getValue("SoftDown"));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ pListItem->setText("");
|
|
|
+ down->setText("");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static void onListItemClick_DeviceTypeListView(ZKListView *pListView, int index, int id) {
|
|
|
+ //LOGD(" onListItemClick_ DeviceTypeListView !!!\n");
|
|
|
+
|
|
|
+ // 小于的时候,代表在linuxVersionList里面
|
|
|
+ if (linuxVersionList[index]["app_path"].asString() != "") {
|
|
|
+ mWindowProgressPtr->showWnd();
|
|
|
+ updateUrl = linuxVersionList[index]["app_path"].asString();
|
|
|
+
|
|
|
+ PopupService::Show([](PopupService* srv){
|
|
|
+
|
|
|
+ base::HttpClient client;
|
|
|
+ client.SetConnectionTimeout(5000);
|
|
|
+ client.SetTimeout(120 * 1000);
|
|
|
+
|
|
|
+ std::string url = getHttpGateway() + "/" + updateUrl;
|
|
|
+ LOGD("请求更新文件的url: %s", url.c_str());
|
|
|
+
|
|
|
+ base::HttpRequest req("GET", url, ""); // 去获取文件
|
|
|
+ const char* tmp_file = "/tmp/update.img";
|
|
|
+ base::HttpResponse response =
|
|
|
+ client.Do(req, tmp_file, [srv, info](int64_t dltotal,
|
|
|
+ int64_t dlnow, int64_t ultotal, int64_t ulnow){
|
|
|
+ LOGD("downloading %lld/%lld", dlnow, dltotal);
|
|
|
+
|
|
|
+ string msg = LANGUAGEMANAGER->getValue("Downloading") + " %.0f%%";
|
|
|
+ srv->SetMessage(base::format(msg.c_str(),
|
|
|
+ dltotal == 0 ? 0 : (dlnow * 1.0/dltotal * 100)));
|
|
|
+ return 0;
|
|
|
+ });
|
|
|
+
|
|
|
+ if (response.StatusCode() != 200) { // 下载失败
|
|
|
+ string msg = LANGUAGEMANAGER->getValue("DownloadFailed") + "%d";
|
|
|
+ srv->SetMessage(base::format(msg.c_str(), response.ErrorCode()));
|
|
|
+ mWindowProgressPtr->hideWnd();
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO: 应该去判断一下,下载的版本是否真的大于当前版本号
|
|
|
+ UpgradeMonitor::getInstance()->checkUpgradeFile("/mnt/extsd");
|
|
|
+ LOGD("img版本-> %s", "");
|
|
|
+
|
|
|
+ const char* msg = "-1";
|
|
|
+ TcpClient::instance()->sendMsg(msg);
|
|
|
+ system("touch /tmp/zkautoupgrade");
|
|
|
+ UPGRADEMONITOR->checkUpgradeFile("/tmp");
|
|
|
+ return 0;
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static bool onButtonClick_BackButton(ZKButton *pButton) {
|
|
|
+ LOGD(" ButtonClick BackButton !!!\n");
|
|
|
+ mWindowInitPtr->hideWnd();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+static bool onButtonClick_FindBackButton(ZKButton *pButton) {
|
|
|
+ LOGD(" ButtonClick FindBackButton !!!\n");
|
|
|
+ EASYUICONTEXT->goBack();
|
|
|
+ return false;
|
|
|
+}
|