/*
 * Decompiled with CFR 0.152.
 */
package com.hst.hwface.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class TheApp {
    private static String localPhotoDir = null;
    private static String hwRecogLib64Name = null;
    private static String hwRecogLib32Name = null;
    private static String hwIDCardRcgLib64Name = null;
    private static String hwIDCardRcgLib32Name = null;
    private static float photoThreshold;
    private static String programPath;
    private static String defaultCompanyCode;

    static {
        programPath = null;
        defaultCompanyCode = null;
    }

    public static void initlize() {
        File file1;
        programPath = System.getProperty("user.dir");
        System.out.println("\u7528\u6237\u7684\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55:\n" + programPath);
        FileInputStream is = null;
        try {
            is = new FileInputStream(String.valueOf(programPath) + File.separator + "app.properties");
        }
        catch (FileNotFoundException e1) {
            e1.printStackTrace();
        }
        if (is == null) {
            return;
        }
        Properties p = new Properties();
        try {
            p.load(is);
            ((InputStream)is).close();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        photoThreshold = TheApp.getFloatValue(p, "server.threshold.idCard");
        defaultCompanyCode = p.getProperty("server.defaultCompanyCode");
        localPhotoDir = String.valueOf(programPath) + File.separator + "photo" + File.separator + defaultCompanyCode;
        File file = new File(String.valueOf(programPath) + File.separator + "photo");
        if (!file.exists() && !file.isDirectory()) {
            file.mkdir();
        }
        if (!(file1 = new File(localPhotoDir)).exists() && !file1.isDirectory()) {
            file1.mkdir();
        }
        hwRecogLib64Name = p.getProperty("server.hwFaceRecogLib64Name");
        hwRecogLib32Name = p.getProperty("server.hwFaceRecogLib32Name");
        hwIDCardRcgLib64Name = p.getProperty("server.hwIDCardRcgLib64Name");
        hwIDCardRcgLib32Name = p.getProperty("server.hwIDCardRcgLib32Name");
    }

    private static float getFloatValue(Properties p, String key) {
        float th;
        float defaultValue = 0.0f;
        String threshold = p.getProperty(key);
        if (threshold != null && threshold.matches("\\d*[\\.]\\d*") && (th = Float.parseFloat(threshold)) < 1.0f && th > 0.0f) {
            return th;
        }
        return defaultValue;
    }

    public static void setRealTimeThreshold(float value) {
        photoThreshold = value;
    }

    public static float getRealTimeThreshold() {
        return photoThreshold;
    }

    public static String getLocalPhotoDir() {
        return localPhotoDir;
    }

    public static String getHwRecogLib64Name() {
        return hwRecogLib64Name;
    }

    public static String getHwRecogLib32Name() {
        return hwRecogLib32Name;
    }

    public static String getProgramPath() {
        return programPath;
    }

    public static void setProgramPath(String programPath) {
        TheApp.programPath = programPath;
    }

    public static String getHwIDCardRcgLib64Name() {
        return hwIDCardRcgLib64Name;
    }

    public static String getHwIDCardRcgLib32Name() {
        return hwIDCardRcgLib32Name;
    }

    public static String getHWFaceRecLibPath() {
        File directory = new File("");
        String relativelyPath = System.getProperty("user.dir");
        System.out.println(relativelyPath);
        return String.valueOf(directory.getAbsolutePath()) + "\\lib\\HWCompare.dll";
    }

    public static String getHWIdCardRcgLibPath() {
        Properties prop = System.getProperties();
        String os = prop.getProperty("os.name");
        String arch = prop.getProperty("os.arch");
        StringBuilder libPath = new StringBuilder(TheApp.getProgramPath());
        TheApp.getProgramPath().endsWith(File.separator);
        libPath.append(File.separator).append("lib").append(File.separator).append("libs").append(File.separator);
        if (arch != null && arch.contains("64")) {
            libPath.append("lib64").append(File.separator).append("ocr").append(File.separator).append(TheApp.getHwIDCardRcgLib64Name());
        } else {
            libPath.append("lib32").append(File.separator).append("ocr").append(File.separator).append(TheApp.getHwIDCardRcgLib32Name());
            System.out.println("\u7531\u4e8e\u672c\u8f6f\u4ef6\u7684\u7279\u6b8a\u6027\uff0c\u6682\u4e0d\u652f\u630132\u4f4d\u7cfb\u7edf\uff0c\u8bf7\u66f4\u636264\u4f4d\u64cd\u4f5c\u7cfb\u7edf\uff01");
        }
        if (os != null && os.toUpperCase().startsWith("WIN")) {
            libPath.append(".dll");
        } else {
            libPath.append(".so");
        }
        return libPath.toString();
    }

    public static String getHWIdCardRcgDatabasePath() {
        Properties prop = System.getProperties();
        prop.getProperty("os.name");
        String arch = prop.getProperty("os.arch");
        StringBuilder libPath = new StringBuilder(TheApp.getProgramPath());
        TheApp.getProgramPath().endsWith(File.separator);
        libPath.append(File.separator).append("lib").append(File.separator).append("libs").append(File.separator);
        if (arch != null && arch.contains("64")) {
            libPath.append("lib64").append(File.separator).append("ocr").append(File.separator).append("database").append(File.separator);
        } else {
            libPath.append("lib32").append(File.separator).append("ocr").append(File.separator).append("database").append(File.separator);
            System.out.println("\u7531\u4e8e\u672c\u8f6f\u4ef6\u7684\u7279\u6b8a\u6027\uff0c\u6682\u4e0d\u652f\u630132\u4f4d\u7cfb\u7edf\uff0c\u8bf7\u66f4\u636264\u4f4d\u64cd\u4f5c\u7cfb\u7edf\uff01");
        }
        return libPath.toString();
    }

    public static String getHWFaceRecLibDir() {
        Properties prop = System.getProperties();
        prop.getProperty("os.name");
        String arch = prop.getProperty("os.arch");
        StringBuilder libPath = new StringBuilder(TheApp.getProgramPath());
        if (!TheApp.getProgramPath().endsWith(File.separator)) {
            libPath.append(File.separator);
        }
        libPath.append("WEB-INF").append(File.separator).append("lib").append(File.separator).append("libs").append(File.separator);
        if (arch != null && arch.contains("64")) {
            libPath.append("lib64").append(File.separator).append("face");
        } else {
            libPath.append("lib32").append(File.separator).append("face");
            System.out.println("\u7531\u4e8e\u672c\u8f6f\u4ef6\u7684\u7279\u6b8a\u6027\uff0c\u6682\u4e0d\u652f\u630132\u4f4d\u7cfb\u7edf\uff0c\u8bf7\u66f4\u636264\u4f4d\u64cd\u4f5c\u7cfb\u7edf\uff01");
        }
        System.out.println("HWFaceRecLibDir: " + libPath.toString());
        return libPath.toString();
    }
}
