/**
* 解压缩一个文件
*
* @param zipFile 压缩文件
* @param folderPath 解压缩的目标目录
*/
public void upZipFile(final File zipFile, final String folderPath, final int itaskid){
Log.i(Tag, Tag + " zipFile: "+zipFile+" folderPath: " + folderPath + " itaskid: " + itaskid);
final int iTaskid = itaskid;
final int BUFF_SIZE = 1024 * 1024; // 1M Byte
new Thread() {
public void run() {
File desDir = new File(folderPath);
if (!desDir.exists()) {
desDir.mkdirs();
}
try {
ZipFile zf = new ZipFile(zipFile);
for (Enumeration<?> entries = zf.entries(); entries
.hasMoreElements();) {
ZipEntry entry = ((ZipEntry) entries.nextElement());
InputStream in = zf.getInputStream(entry);
// String str = folderPath + File.separator+"sound"
// + entry.getName();
String str = folderPath + entry.getName();
str = new String(str.getBytes("8859_1"), "GB2312");
File desFile = new File(str);
Log.i(Tag, Tag + "zipfilename"+str);
if(str.contains(".ogg"))
{
if(!desFile.exists()){
desFile.createNewFile();
}
}else{
if(!desFile.exists()){
desFile.mkdir();
}
continue;
}
OutputStream out = new FileOutputStream(desFile);
byte buffer[] = new byte[BUFF_SIZE];
int realLength;
while ((realLength = in.read(buffer)) > 0) {
out.write(buffer, 0, realLength);
}
out.flush();
out.flush();
in.close();
}
Message msg = new Message();
msg.what = Cocos2dxHandler.MT_COCOSCTIVITY_UNZIPRESULT;
Bundle shareBundle = new Bundle();
msg.setData(shareBundle);
shareBundle.putInt("RESULT", 1);
shareBundle.putInt("TASKID", iTaskid);
mtAndroidNativeBright.getCocosHandler().sendMessage(msg);
} catch (Exception e) {
// TODO: handle exception
Log.i(Tag, Tag + e.toString());
Message msg = new Message();
msg.what = Cocos2dxHandler.MT_COCOSCTIVITY_UNZIPRESULT;
Bundle shareBundle = new Bundle();
msg.setData(shareBundle);
shareBundle.putInt("RESULT", 0);
shareBundle.putInt("TASKID", iTaskid);
mtAndroidNativeBright.getCocosHandler().sendMessage(msg);
}
}
}.start();
}
* 解压缩一个文件
*
* @param zipFile 压缩文件
* @param folderPath 解压缩的目标目录
*/
public void upZipFile(final File zipFile, final String folderPath, final int itaskid){
Log.i(Tag, Tag + " zipFile: "+zipFile+" folderPath: " + folderPath + " itaskid: " + itaskid);
final int iTaskid = itaskid;
final int BUFF_SIZE = 1024 * 1024; // 1M Byte
new Thread() {
public void run() {
File desDir = new File(folderPath);
if (!desDir.exists()) {
desDir.mkdirs();
}
try {
ZipFile zf = new ZipFile(zipFile);
for (Enumeration<?> entries = zf.entries(); entries
.hasMoreElements();) {
ZipEntry entry = ((ZipEntry) entries.nextElement());
InputStream in = zf.getInputStream(entry);
// String str = folderPath + File.separator+"sound"
// + entry.getName();
String str = folderPath + entry.getName();
str = new String(str.getBytes("8859_1"), "GB2312");
File desFile = new File(str);
Log.i(Tag, Tag + "zipfilename"+str);
if(str.contains(".ogg"))
{
if(!desFile.exists()){
desFile.createNewFile();
}
}else{
if(!desFile.exists()){
desFile.mkdir();
}
continue;
}
OutputStream out = new FileOutputStream(desFile);
byte buffer[] = new byte[BUFF_SIZE];
int realLength;
while ((realLength = in.read(buffer)) > 0) {
out.write(buffer, 0, realLength);
}
out.flush();
out.flush();
in.close();
}
Message msg = new Message();
msg.what = Cocos2dxHandler.MT_COCOSCTIVITY_UNZIPRESULT;
Bundle shareBundle = new Bundle();
msg.setData(shareBundle);
shareBundle.putInt("RESULT", 1);
shareBundle.putInt("TASKID", iTaskid);
mtAndroidNativeBright.getCocosHandler().sendMessage(msg);
} catch (Exception e) {
// TODO: handle exception
Log.i(Tag, Tag + e.toString());
Message msg = new Message();
msg.what = Cocos2dxHandler.MT_COCOSCTIVITY_UNZIPRESULT;
Bundle shareBundle = new Bundle();
msg.setData(shareBundle);
shareBundle.putInt("RESULT", 0);
shareBundle.putInt("TASKID", iTaskid);
mtAndroidNativeBright.getCocosHandler().sendMessage(msg);
}
}
}.start();
}