Commit b38ea101 authored by feihuaduo's avatar feihuaduo

新增读取额外卡库压缩包数据库卡图

parent f94ac2ef
......@@ -23,6 +23,8 @@ import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.zip.ZipEntry;
......@@ -43,6 +45,7 @@ import static com.bumptech.glide.Glide.with;
public class ImageLoader implements Closeable {
private static final String TAG = ImageLoader.class.getSimpleName();
private ZipFile mZipFile;
private List<ZipFile> zipFileList;
private LruBitmapPool mLruBitmapPool;
// private ExecutorService mExecutorService = Executors.newSingleThreadExecutor();
private boolean isClose = false;
......@@ -72,6 +75,7 @@ public class ImageLoader implements Closeable {
private ImageLoader(Context context) {
mContext = context;
mLruBitmapPool = new LruBitmapPool(100);
zipFileList=new ArrayList<>();
}
private class BpgResourceDecoder implements ResourceDecoder<ImageVideoWrapper, GifBitmapWrapper> {
......@@ -179,6 +183,7 @@ public class ImageLoader implements Closeable {
String path = AppsSettings.get().getResourcePath();
boolean bind = false;
File zip = new File(path, Constants.CORE_PICS_ZIP);
List<File> zipList=new ArrayList<>();
for (String ex : Constants.IMAGE_EX) {
File file = new File(AppsSettings.get().getResourcePath(), name + ex);
File file_ex = new File(AppsSettings.get().getResourcePath(), name_ex + ex);
......@@ -218,6 +223,48 @@ public class ImageLoader implements Closeable {
IOUtils.close(inputStream);
}
}
if (!bind) {
File[] files = new File(AppsSettings.get().getResourcePath(), Constants.CORE_EXPANSIONS).listFiles();
if (files != null) {
for (File file :files) {
if (file.isFile() && file.getName().endsWith(".zip")) {
ZipEntry entry = null;
InputStream inputStream = null;
ByteArrayOutputStream outputStream = null;
try {
ZipFile zipFile = null;
for(ZipFile zipFile1:zipFileList){
if (zipFile1.getName().equals(file.getAbsolutePath())){
zipFile=zipFile1;
break;
}
}
if (zipFile==null){
zipFile=new ZipFile(file.getAbsoluteFile());
zipFileList.add(zipFile);
}
for (String ex : Constants.IMAGE_EX) {
entry = zipFile.getEntry(name + ex);
if (entry != null) {
inputStream = zipFile.getInputStream(entry);
outputStream = new ByteArrayOutputStream();
IOUtils.copy(inputStream, outputStream);
bind(outputStream.toByteArray(), imageview, Constants.BPG.equals(ex), code, pre, isBig);
bind = true;
break;
}
}
if (bind)
break;
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.close(inputStream);
}
}
}
}
}
if (!bind) {
if (Constants.NETWORK_IMAGE && NetUtils.isWifiConnected(imageview.getContext())) {
bind(String.format(Constants.IMAGE_URL, "" + code), imageview, code, pre, isBig);
......
......@@ -6,9 +6,21 @@ import android.support.annotation.WorkerThread;
import android.util.Log;
import android.util.SparseArray;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import cn.garymb.ygomobile.App;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.utils.IOUtils;
import ocgcore.data.Card;
......@@ -47,13 +59,24 @@ public class CardManager {
@Override
public boolean accept(File dir, String name) {
File file = new File(dir, name);
return file.isFile() && name.endsWith(".cdb");
return file.isFile() && (name.endsWith(".cdb")||name.endsWith(".zip"));
}
});
//读取全部卡片
if (files != null) {
for (File file : files) {
if (file.getName().endsWith(".cdb")){
count = readAllCards(file, cardDataHashMap);
}else if(file.getName().endsWith(".zip")){
Log.e("CardManager","读取压缩包");
try {
for(File file1:readZipCdb(file.getAbsolutePath())){
count = readAllCards(file1, cardDataHashMap);
}
} catch (IOException e) {
Log.e("CardManager","读取压缩包错误"+e);
}
}
Log.i("Irrlicht", "load " + count + " cdb:" + file);
}
}
......@@ -96,6 +119,37 @@ public class CardManager {
return rs;
}
public static List<File> readZipCdb(String zipPath) throws IOException {
String savePath= App.get().getExternalCacheDir().getAbsolutePath();
List<File> fileList=new ArrayList<>();
int num=0;
ZipFile zf = new ZipFile(zipPath);
InputStream in = new BufferedInputStream(new FileInputStream(zipPath));
ZipInputStream zin = new ZipInputStream(in);
ZipEntry ze;
while ((ze = zin.getNextEntry()) != null) {
if (ze.isDirectory()) {
//Do nothing
} else {
if (ze.getName().endsWith(".cdb")) {
File file=new File(savePath,"cards"+num+".cdb");
InputStream inputStream = zf.getInputStream(ze);
OutputStream os = new FileOutputStream(file);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.close();
inputStream.close();
fileList.add(file);
}
}
}
zin.closeEntry();
return fileList;
}
@WorkerThread
protected int readAllCards(File file, SparseArray<Card> cardMap) {
if (!file.exists()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment