wjc
2 小时以前 4db3692de0001eea35f938c1224181746e72933a
app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java
@@ -8,7 +8,11 @@
import android.text.TextUtils;
import com.hdl.photovoltaic.HDLApp;
import com.hdl.photovoltaic.config.ConstantManage;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.enums.Languages;
import com.hdl.photovoltaic.ui.adapter.LanguageAdapter;
import com.hdl.photovoltaic.utils.LocalManageUtil;
import org.apache.commons.io.FileUtils;
@@ -21,6 +25,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Objects;
/**
@@ -85,7 +90,7 @@
    }
    /**
     * 获取存放【驱动文件夹】根路径
     * 获取存放驱动【文件夹】根路径
     */
    public String getDriveRootPath() {
        return getAPPInternalStoreFilesPath() + "/upgrade/drive";
@@ -93,28 +98,55 @@
    /**
     * 获取存放【固件文件夹】根路径
     * 获取存放固件【文件夹】根路径
     */
    public String getFirmwareRootPath() {
        return getAPPInternalStoreFilesPath() + "/upgrade/firmware";
    }
    /**
     * 获取【日志文件】全路径
     * 获取json资源【文件夹】全路径
     *
     * @param language    语言 通过枚举类Languages.en获取
     * @param deviceModel 设备型号
     */
    public String getHdlESLocalJsonRootPath(String language, String deviceModel) {
        return getAPPInternalStoreFilesPath() + "/hdlESLocalJson/" + language + "/" + deviceModel;
    }
    /**
     * 获取日志【文件】全路径
     */
    public String getLogFileNamePath() {
        return getCurrentHomeRootPath() + "/log.txt";
    }
    /**
     * 获取【用户文件】全路径
     * 获取用户【文件】全路径
     */
    public String getUserFilePath() {
        return getAPPInternalStoreFilesPath() + "/userConfigManage.txt";
    }
    /**
     * 获取驱动升级文件全路径
     * 获取本地语言json资源【文件】全路径
     *
     * @param language    语言 通过枚举类Languages.en获取
     * @param deviceModel 设备型号
     * @param fileName    文件名
     */
    public String getHdlESLocalLanguageJsonFilePath(String language, String deviceModel, String fileName) {
        if (!fileName.endsWith(".json")) {
            fileName += ".json";
        }
        return getAPPInternalStoreFilesPath() + "/hdlESLocalJson/" + language + "/" + deviceModel + "/" + fileName;
    }
    /**
     * 获取驱动升级【文件】全路径
     *
     * @param driverCode 驱动编码
     * @param version    驱动版本
@@ -126,15 +158,14 @@
    }
    /**
     * 获取固件升级文件全路径
     * 获取固件升级【文件】全路径
     *
     * @param oid     该固件oid
     * @param imageId 镜像id
     * @param version 驱动版本
     * @return 全路径
     */
    public String getFirmwarePathFileName(String oid, String imageId, String version) {
        String fileName = oid + "_" + imageId + "_" + version + ".zip";
    public String getFirmwarePathFileName(String imageId, String version) {
        String fileName = imageId + "_" + version + ".zip";
        return HdlFileLogic.getInstance().getFirmwareRootPath() + "/" + fileName;
    }
@@ -143,7 +174,7 @@
    //region    ---------【文件夹】操作-----------
    /**
     * 预创建文件夹
     * 预创建【文件夹】
     */
    public void createDirectory() {
        //存放住宅信息
@@ -152,11 +183,26 @@
        this.createFileDir(this.getDriveRootPath());
        //固件文件
        this.createFileDir(this.getFirmwareRootPath());
    }
    /**
     * 预创建设备json资源【文件夹】
     */
    public void createHdlDeviceModelLocalJsonDirectory() {
        List<LanguageAdapter.ItemData> languageList = LocalManageUtil.getLanguageList();
        List<String> deviceModelList = HdlESLocalJsonLogic.getInstance().getModelList();
        for (int i = 0; i < languageList.size(); i++) {
            LanguageAdapter.ItemData languageModel = languageList.get(i);
            for (int j = 0; j < deviceModelList.size(); j++) {
                String deviceModel = deviceModelList.get(j);
                this.createFileDir(this.getHdlESLocalJsonRootPath(languageModel.getLanguage(), deviceModel));//并网-逆变器
            }
        }
    }
    /**
     * 创建文件夹
     * 创建【文件夹】
     *
     * @param fullPath fullPath 全路径
     * @return -
@@ -166,7 +212,7 @@
            File file = new File(fullPath);
            if (!file.isDirectory()) {
                boolean succeed = file.mkdirs();
                System.out.println("创建文件夹路径--->" + file.getAbsolutePath() + "===创建文件夹结果--->" + succeed);
                System.out.println("创建文件夹路径---" + file.getAbsolutePath() + "===创建文件夹结果---" + succeed);
                return succeed;
            }
            return true;
@@ -178,7 +224,7 @@
    /**
     * 删除文件夹
     * 删除【文件夹】
     *
     * @param fullPath 全路径
     */
@@ -199,7 +245,7 @@
            }
            // 删除文件夹本身
            boolean succeed = fileRoot.delete();//文件夹空这个方法才有效
            System.out.println("删除文件夹路径--->" + fileRoot.getAbsolutePath() + "===删除结果--->" + succeed);
            System.out.println("删除文件夹路径---" + fileRoot.getAbsolutePath() + "===删除结果---" + succeed);
        } catch (Exception e) {
            System.out.println("删除文件夹有异常===" + e.getMessage());
        }
@@ -212,7 +258,7 @@
    //region    ---------【文件】操作-----------
    /**
     * 创建文件
     * 创建【文件】
     *
     * @param fullPath 全路径
     * @return -
@@ -222,7 +268,7 @@
            File file = new File(fullPath);
            if (!file.exists()) {
                boolean succeed = file.createNewFile();
                System.out.println("创建文件路径--->" + file.getAbsolutePath() + "===创建文件结果--->" + succeed);
                System.out.println("创建文件路径---" + file.getAbsolutePath() + "===创建文件结果---" + succeed);
                return succeed;
            }
            return true;
@@ -233,7 +279,7 @@
    }
    /**
     * 删除文件
     * 删除【文件】
     *
     * @param fullPath 全路径
     * @return -
@@ -243,7 +289,7 @@
            File file = new File(fullPath);
            if (file.exists()) {
                boolean succeed = file.delete();
                System.out.println("删除文件--->" + fullPath + "===结果--->" + succeed);
                System.out.println("删除文件---" + fullPath + "===结果---" + succeed);
                return succeed;
            }
            return true;
@@ -274,9 +320,9 @@
            d.write(data);
            d.flush();
            d.close();
            System.out.println("写入文件成功--->" + fullPath);
            System.out.println("写入文件成功---" + fullPath);
        } catch (Exception e) {
            System.out.println("写入文件有异常--->" + e.getMessage());
            System.out.println("写入文件有异常---" + e.getMessage());
        }
    }
@@ -318,9 +364,9 @@
                //文件大于1m,删除文件前100条日志
                this.delFileLien(fullPath, 100);
            }
            System.out.println("写入一行数据到文件成功--->" + dataLine);
//            System.out.println("写入一行数据到文件成功---" + dataLine);
        } catch (Exception e) {
            System.out.println("写入一行数据到文件有异常--->" + e.getMessage());
            System.out.println("写入一行数据到文件有异常---" + e.getMessage());
        }
    }
@@ -343,10 +389,10 @@
            FileInputStream fis = new FileInputStream(f);
            byte[] bytes = FileUtils.readFileToByteArray(f);//这个方法不兼用android 6.0
            fis.close();
            System.out.println("读取文件成功--->" + filePath);
            System.out.println("读取文件成功---" + filePath);
            return bytes;
        } catch (Exception e1) {
            System.out.println("读取文件有异常--->" + e1.getMessage());
            System.out.println("读取文件有异常---" + e1.getMessage());
            return null;
        }
@@ -375,10 +421,10 @@
            int len = bis.read(bytes);
            bis.close();
            fis.close();
            System.out.println("读取文件成功--->" + filePath);
            System.out.println("读取文件成功---" + filePath);
            return bytes;
        } catch (Exception e1) {
            System.out.println("读取文件有异常--->" + e1.getMessage());
            System.out.println("读取文件有异常---" + e1.getMessage());
            return null;
        }
@@ -421,7 +467,7 @@
            fileLength = f.length();
            return new FileInputStream(f);
        } catch (Exception e1) {
            System.out.println("读取文件有异常--->" + e1.getMessage());
            System.out.println("读取文件有异常---" + e1.getMessage());
            return null;
        }
@@ -505,7 +551,7 @@
     */
    public boolean isBoolean(String path) {
        if (path.contains("//") || path.contains("\\")) {
            System.out.println("无效文件路径--->" + path);
            System.out.println("无效文件路径---" + path);
            return false;
        }
        return true;