package org.aohe.show;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import lombok.extern.slf4j.Slf4j;

import java.awt.*;

@Slf4j
public class IconUtil {
   public static Image getIcon() {
       String iconPath = getProgramPathIcon();
       log.info("当前查找路径为外部：{}", FileUtil.getAbsolutePath(iconPath));
       if(!FileUtil.exist(iconPath)){
           iconPath = ResourceUtil.getResource("ah.png").getFile();
           log.info("当前查找路径为内部：{}", FileUtil.getAbsolutePath(iconPath));
       }
       log.info("当前程序图标最终路径路径为：{}", getProgramPathIcon());

       return Toolkit.getDefaultToolkit().getImage(iconPath);
   }

   public static String getProgramPathIcon(){
       String resource = ResourceUtil.getResource("ah.png").getFile();
       String absolutePath = FileUtil.getAbsolutePath(resource);
       return absolutePath.replace("twain-service.exe!/", "");
   }
}
