package com.njcn.advance.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.*;
import java.net.URLDecoder;

/**
 * pqs
 *
 * @author cdf
 * @date 2023/6/20
 */
@Slf4j
public class JnaCallDllOrSo {
    private String path = "";
    private String nameDll;

    public static String jarPath = "";

    public JnaCallDllOrSo(String name) {
        super();
        try {
            String os = System.getProperty("os.name");
            // windows操作系统为1 否则为0
            int beginIndex = os != null && os.startsWith("Windows") ? 1 : 0;
            if(beginIndex == 0){
                //linux操作系统
                this.nameDll = name+".os";
                this.path = URLDecoder.decode(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8");
            }else {
                this.nameDll = name+".dll";
                this.path = URLDecoder.decode(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath().replaceFirst("/", ""), "UTF-8");
            }

        } catch (UnsupportedEncodingException e) {
            log.error(e.getMessage());
        }
        if (JnaCallDllOrSo.jarPath.equals("")) {
            JnaCallDllOrSo.jarPath = this.path.substring(0, this.path.lastIndexOf('/'));
        }
    }



    public String getStrpath() {
        String aa = this.path+this.nameDll;
        String bb= aa.replace("/", File.separator);
        return bb;
    }

    public void setPath() {

    }
}
