// Path: src/main/java/me/xwang1024/sifResExplorer/config/SIFConfig.java
// public class SIFConfig {
// 	private static final Logger logger = LoggerFactory
// 			.getLogger(SIFConfig.class);
// 
// 	public static SIFConfig instance;
// 	private String filePath = "sif.xml";
// 	private Map<String, String> conf = Collections
// 			.synchronizedMap(new HashMap<String, String>());
// 
// 	public static SIFConfig getInstance() {
// 		if (instance == null) {
// 			instance = new SIFConfig();
// 		}
// 		return instance;
// 	}
// 
// 	private SIFConfig() {
// 	}
// 
// 	public void loadConfig() throws DocumentException {
// 		if(!new File(filePath).exists()) {
// 			logger.info("Could not find sif.xml.");
// 			return;
// 		}
// 		logger.info("Read config file sif.xml");
// 		SAXReader reader = new SAXReader();
// 		Document doc = reader.read(new File(filePath));
// 		List nodes = doc.getRootElement().elements("config");
// 		for (Iterator it = nodes.iterator(); it.hasNext();) {
// 			Element elm = (Element) it.next();
// 			String name = elm.attributeValue("name");
// 			String value = elm.attributeValue("value");
// 			if (name != null && value != null) {
// 				conf.put(name, value);
// 				logger.info("Read conf: {}={}", name, value);
// 			}
// 		}
// 	}
// 
// 	public void saveConfig() throws IOException {
// 		logger.info("Save config file sif.xml");
// 		Document doc = DocumentHelper.createDocument();
// 		Element root = DocumentHelper.createElement("configuration");
// 		for (String name : conf.keySet()) {
// 			String value = "" + conf.get(name);
// 			Element conf = DocumentHelper.createElement("config");
// 			conf.addAttribute(new QName("name"), name);
// 			conf.addAttribute(new QName("value"), value);
// 			root.add(conf);
// 		}
// 		doc.setRootElement(root);
// 
// 		OutputFormat format = OutputFormat.createPrettyPrint();
// 		format.setEncoding("UTF-8"); // 指定XML编码
// 		XMLWriter writer = new XMLWriter(new FileWriter(filePath), format);
// 		writer.write(doc);
// 		writer.close();
// 	}
// 
// 	public String get(String name) {
// 		return conf.get(name);
// 	}
// 
// 	public String set(String name, String value) {
// 		return conf.put(name, value);
// 	}
// 
// 	public static class ConfigName {
// 		public static final String dbPath = "dbPath";
// 		public static final String assetsPath = "assetsPath";
// 	}
// }
// 
// Path: src/main/java/me/xwang1024/sifResExplorer/config/SIFConfig.java
// public static class ConfigName {
// 	public static final String dbPath = "dbPath";
// 	public static final String assetsPath = "assetsPath";
// }
// 
// Path: src/main/java/me/xwang1024/sifResExplorer/data/ImagDao.java
// public interface ImagDao {
// 	public BufferedImage getImage(String imagPath) throws IOException;
// 	
// 	public BufferedImage getImageWithoutSplit(String texbPath) throws IOException;
// 	
// 	public String getRefTextureFilePath(String imagPath) throws IOException;
// 	
// 	public List<String> getImagList();
// 	
// 	public List<String> getTexbList();
// }


import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.zip.Inflater;
import javax.imageio.ImageIO;
import me.xwang1024.sifResExplorer.config.SIFConfig;
import me.xwang1024.sifResExplorer.config.SIFConfig.ConfigName;
import me.xwang1024.sifResExplorer.data.ImagDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

			}
			if (img.path.contains(this.imagPath)) {
				cache = bimg;
			} else {
				logger.debug("{}:{}", img.path, this.imagPath);
			}
		}
		return cache;
	}

	private Texb extractTexb(String texbPath) throws IOException {
		// 构造texb文件的位置
		String assetsPath = SIFConfig.getInstance().get(ConfigName.assetsPath);
		File root = new File(assetsPath).getParentFile();
		File texbFile = new File(root, texbPath);
		logger.info("Extract Texture: {}", texbFile.getAbsolutePath());
		// 解压Texb文件
		Texb t = new Texb();
		FileInputStream texbFile_;
		try{
			texbFile_ = new FileInputStream(texbFile);
		}catch(FileNotFoundException e){
			logger.info("Can't find image in external, searching in install...");
			root = new File(assetsPath.replace("external", "install")).getParentFile();
			texbFile = new File(root, texbPath);
			texbFile_ = new FileInputStream(texbFile);
		}
		DataInputStream dis = new DataInputStream(texbFile_);
		t.tag = readString(dis, 4);
		t.size = dis.readInt();

// Path: src/main/java/me/xwang1024/sifResExplorer/config/SIFConfig.java
// public class SIFConfig {
// 	private static final Logger logger = LoggerFactory
// 			.getLogger(SIFConfig.class);
// 
// 	public static SIFConfig instance;
// 	private String filePath = "sif.xml";
// 	private Map<String, String> conf = Collections
// 			.synchronizedMap(new HashMap<String, String>());
// 
// 	public static SIFConfig getInstance() {
// 		if (instance == null) {
// 			instance = new SIFConfig();
// 		}
// 		return instance;
// 	}
// 
// 	private SIFConfig() {
// 	}
// 
// 	public void loadConfig() throws DocumentException {
// 		if(!new File(filePath).exists()) {
// 			logger.info("Could not find sif.xml.");
// 			return;
// 		}
// 		logger.info("Read config file sif.xml");
// 		SAXReader reader = new SAXReader();
// 		Document doc = reader.read(new File(filePath));
// 		List nodes = doc.getRootElement().elements("config");
// 		for (Iterator it = nodes.iterator(); it.hasNext();) {
// 			Element elm = (Element) it.next();
// 			String name = elm.attributeValue("name");
// 			String value = elm.attributeValue("value");
// 			if (name != null && value != null) {
// 				conf.put(name, value);
// 				logger.info("Read conf: {}={}", name, value);
// 			}
// 		}
// 	}
// 
// 	public void saveConfig() throws IOException {
// 		logger.info("Save config file sif.xml");
// 		Document doc = DocumentHelper.createDocument();
// 		Element root = DocumentHelper.createElement("configuration");
// 		for (String name : conf.keySet()) {
// 			String value = "" + conf.get(name);
// 			Element conf = DocumentHelper.createElement("config");
// 			conf.addAttribute(new QName("name"), name);
// 			conf.addAttribute(new QName("value"), value);
// 			root.add(conf);
// 		}
// 		doc.setRootElement(root);
// 
// 		OutputFormat format = OutputFormat.createPrettyPrint();
// 		format.setEncoding("UTF-8"); // 指定XML编码
// 		XMLWriter writer = new XMLWriter(new FileWriter(filePath), format);
// 		writer.write(doc);
// 		writer.close();
// 	}
// 
// 	public String get(String name) {
// 		return conf.get(name);
// 	}
// 
// 	public String set(String name, String value) {
// 		return conf.put(name, value);
// 	}
// 
// 	public static class ConfigName {
// 		public static final String dbPath = "dbPath";
// 		public static final String assetsPath = "assetsPath";
// 	}
// }
// 
// Path: src/main/java/me/xwang1024/sifResExplorer/config/SIFConfig.java
// public static class ConfigName {
// 	public static final String dbPath = "dbPath";
// 	public static final String assetsPath = "assetsPath";
// }
// 
// Path: src/main/java/me/xwang1024/sifResExplorer/data/ImagDao.java
// public interface ImagDao {
// 	public BufferedImage getImage(String imagPath) throws IOException;
// 	
// 	public BufferedImage getImageWithoutSplit(String texbPath) throws IOException;
// 	
// 	public String getRefTextureFilePath(String imagPath) throws IOException;
// 	
// 	public List<String> getImagList();
// 	
// 	public List<String> getTexbList();
// }


// Path: src/main/java/me/xwang1024/sifResExplorer/data/impl/ImagDaoImpl.java
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.zip.Inflater;
import javax.imageio.ImageIO;
import me.xwang1024.sifResExplorer.config.SIFConfig;
import me.xwang1024.sifResExplorer.config.SIFConfig.ConfigName;
import me.xwang1024.sifResExplorer.data.ImagDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

			}
			if (img.path.contains(this.imagPath)) {
				cache = bimg;
			} else {
				logger.debug("{}:{}", img.path, this.imagPath);
			}
		}
		return cache;
	}

	private Texb extractTexb(String texbPath) throws IOException {
		// 构造texb文件的位置
		String assetsPath = SIFConfig.getInstance().get(ConfigName.assetsPath);
		File root = new File(assetsPath).getParentFile();
		File texbFile = new File(root, texbPath);
		logger.info("Extract Texture: {}", texbFile.getAbsolutePath());
		// 解压Texb文件
		Texb t = new Texb();
		FileInputStream texbFile_;
		try{
			texbFile_ = new FileInputStream(texbFile);
		}catch(FileNotFoundException e){
			logger.info("Can't find image in external, searching in install...");
			root = new File(assetsPath.replace("external", "install")).getParentFile();
			texbFile = new File(root, texbPath);
			texbFile_ = new FileInputStream(texbFile);
		}
		DataInputStream dis = new DataInputStream(texbFile_);
		t.tag = readString(dis, 4);
		t.size = dis.readInt();

		t.pathLen = dis.readUnsignedShort();
