mac
2023-11-22 3f41182984d69d7fae703776edd1591f48dff93f
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));//云端上文件MD5
        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);
            }
        });