From 3f41182984d69d7fae703776edd1591f48dff93f Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期三, 22 十一月 2023 17:13:05 +0800 Subject: [PATCH] 2023年11月22日17:12:40 --- app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java | 42 ++++++++++++++++++------------------------ 1 files changed, 18 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java index a5be3d4..18a7ce7 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java @@ -53,6 +53,7 @@ import java.util.Objects; import io.dcloud.feature.unimp.DCUniMPJSCallback; +import okhttp3.ResponseBody; /** * uni灏忕▼搴忕殑閫昏緫 @@ -530,12 +531,15 @@ File file = new File(driverFileList); if (file.list() != null) { for (int i = 0; i < Objects.requireNonNull(file.list()).length; i++) { - String path = Objects.requireNonNull(file.list())[i]; - String[] ary = path.split("/"); - String[] driverInfoAry = ary[ary.length - 1].split("_"); + String fileName = Objects.requireNonNull(file.list())[i]; + if (!fileName.contains(driveCode)) { + continue; + } + String[] driverInfoAry = fileName.split("_"); GatewayDriverBean gatewayDriverBean = new GatewayDriverBean(); gatewayDriverBean.setDriverCode(driverInfoAry[0]); gatewayDriverBean.setVersion(driverInfoAry[1].replace(".zip", "")); + gatewayDriverBean.setLocalUrl(HdlFileLogic.getInstance().getDrivePathFileName(gatewayDriverBean.getDriverCode(), gatewayDriverBean.getVersion())); list.add(gatewayDriverBean); } } @@ -557,32 +561,22 @@ String imageId = getKeyValue("imageId", getKeyValue("data", data));//椹卞姩闀滃儚id String version = getKeyValue("version", getKeyValue("data", data));//椹卞姩鐗堟湰 String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//椹卞姩鐗堟湰id - HdlOtaLogic.getInstance().getDeviceDriverDownloadUrl(driverVersionId, new CloudCallBeak<DownloadUrlBean>() { + String localUrl = getKeyValue("localUrl", getKeyValue("data", data));//鍌ㄥ瓨鍦ㄦ湰鍦伴┍鍔ㄦ枃浠惰矾寰� + String url = getKeyValue("url", getKeyValue("data", data));//浜戠涓婃枃浠跺湴鍧� + String md5 = getKeyValue("md5", getKeyValue("data", data));//浜戠涓婃枃浠禡D5 + HdlOtaLogic.getInstance().getDeviceDriverDownloadFile(url, new CloudCallBeak<ResponseBody>() { @Override - public void onSuccess(DownloadUrlBean downloadUrlBean) { - if (downloadUrlBean == null) { - uniCallbackData(null, -2, "涓嬭浇閾炬帴鎵句笉鍒�", callback); - return; - } - HdlOtaLogic.getInstance().getDeviceDriverDownloadFile(downloadUrlBean.getDownloadUrl(), new CloudCallBeak<DownloadUrlBean>() { - @Override - public void onSuccess(DownloadUrlBean obj) { - Gson gson = new Gson(); - String json = gson.toJson(obj); - String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName(driverCode, version); - HdlFileLogic.getInstance().writeFile(drivePathFileName, json); - - } - - @Override - public void onFailure(HDLException e) { - - } - }); + public void onSuccess(ResponseBody responseBody) { + byte[] bytes = HdlOtaLogic.getInstance().disposeDownLoadFile(responseBody, md5); + HdlFileLogic.getInstance().deleteFile(localUrl);//鍒犻櫎鏃ф枃浠� + String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName(driverCode, version); + HdlFileLogic.getInstance().writeFile(drivePathFileName, bytes);//鍐欏叆鏂版枃浠� + HdlLogLogic.print("鍐欏叆鏂伴┍鍔ㄦ枃浠跺埌鍐呭瓨鎴愬姛.", false); } @Override public void onFailure(HDLException e) { + HdlLogLogic.print("涓嬭浇椹卞姩鏂囦欢鍒板唴瀛樺け璐�.", false); uniCallbackData(null, e.getCode(), e.getMsg(), callback); } }); -- Gitblit v1.8.0