Heroes III HD v1.1.6版本的 MD5 值为:99ed52e2d6b85487933b8dc8c0440b36
以下内容为反编译后的 GameInstaller.java 源代码,内容仅作参考
package com.dotemu.homm3.installer;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Environment;
import android.os.StatFs;
import android.util.Log;
import com.flurry.android.Constants;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import obfuse.NPStringFog;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
public class GameInstaller extends AsyncTask<String, String, String> {
public static final int GAME_INSTALLER_ERROR_DOWNLOAD = 1;
public static final int GAME_INSTALLER_ERROR_FINISH = 4;
public static final int GAME_INSTALLER_ERROR_UNPACK = 3;
public static final int GAME_INSTALLER_ERROR_VERIFY = 2;
private String apkExpansionDir;
protected Context context;
private String gameDirectory;
private GameInstallerProgressListener listener;
protected InputStream standAloneIs = null;
private ArrayList<GamePackage> packages = new ArrayList<>(10);
protected GamePackage currentPackage = null;
private boolean bInstallOccured = false;
public GameInstaller(Context context, GameInstallerProgressListener listener) {
this.gameDirectory = null;
this.apkExpansionDir = null;
this.context = context;
this.listener = listener;
this.gameDirectory = Environment.getExternalStorageDirectory() + NPStringFog.decode("413103051C0E0E015D0A11190041") + context.getPackageName() + NPStringFog.decode("4116040D0B12");
this.apkExpansionDir = Environment.getExternalStorageDirectory() + NPStringFog.decode("411F0F0341") + context.getPackageName();
}
public boolean isOnline() {
ConnectivityManager cm = (ConnectivityManager) this.context.getSystemService(NPStringFog.decode("0D1F030F0B02130C04070414"));
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo == null) {
return false;
}
return netInfo.isConnected();
}
public boolean isSpaceAvailable(int megaBytes) {
StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
long nBlocks = statFs.getFreeBlocks();
int iBlockSize = statFs.getBlockSize();
long lSize = nBlocks * iBlockSize;
return lSize >= ((long) ((megaBytes * 1024) * 1024));
}
public void addPackage(GamePackage gamePackage) {
if (this.packages != null && gamePackage != null) {
this.packages.add(gamePackage);
}
}
public final boolean checkSdCard() {
String externalState = Environment.getExternalStorageState();
if (externalState.equals(NPStringFog.decode("031F180F1A0403"))) {
return true;
}
if (externalState.equals(NPStringFog.decode("1B1E000E1B0F130016")) || externalState.equals(NPStringFog.decode("1C15000E180403"))) {
if (this.listener != null) {
this.listener.onSdCardError(externalState);
return false;
}
return false;
} else if (externalState.equals(NPStringFog.decode("0C11093E1C040A0A040F1C"))) {
if (this.listener != null) {
this.listener.onSdCardError(externalState);
return false;
}
return false;
} else if (externalState.equals(NPStringFog.decode("0D18080205080902"))) {
if (this.listener != null) {
this.listener.onSdCardError(externalState);
return false;
}
return false;
} else if (externalState.equals(NPStringFog.decode("1D180C130B05"))) {
if (this.listener != null) {
this.listener.onSdCardError(externalState);
return false;
}
return false;
} else if (this.listener != null) {
this.listener.onSdCardError(externalState);
return false;
} else {
return false;
}
}
public boolean checkCurrentPackage() {
File fMarker;
return this.currentPackage != null && (fMarker = new File(this.gameDirectory, this.currentPackage.getMarker())) != null && fMarker.exists() && fMarker.isFile();
}
public boolean downloadCurrentPackage() {
HttpResponse response;
int statusCode;
int bytesRead;
if (this.currentPackage.getUrl().equals(NPStringFog.decode("2F2026"))) {
this.currentPackage.setFullPath(this.currentPackage.getFile());
return true;
} else if (this.currentPackage.getUrl().equals(NPStringFog.decode("3D242C2F2A3E26293D2035"))) {
this.currentPackage.setFullPath(this.currentPackage.getFile());
return true;
} else {
this.currentPackage.setFullPath(String.valueOf(this.gameDirectory) + NPStringFog.decode("41") + this.currentPackage.getFile());
BasicHttpParams basicHttpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(basicHttpParams, 20000);
HttpConnectionParams.setSoTimeout(basicHttpParams, 20000);
DefaultHttpClient defaultHttpClient = new DefaultHttpClient(basicHttpParams);
HttpGet getRequest = new HttpGet(this.currentPackage.getUrl());
File zipFile = new File(this.currentPackage.getFullPath());
if (!zipFile.exists()) {
try {
new File(zipFile.getParent()).mkdirs();
zipFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
try {
response = defaultHttpClient.execute(getRequest);
statusCode = response.getStatusLine().getStatusCode();
} catch (IOException e2) {
getRequest.abort();
Log.e(NPStringFog.decode("281901042A0E100B1E011109041C"), NPStringFog.decode("275F22410B13150A004E07050802044717171A0204041808090252081901044E07150A1F4E") + this.currentPackage.getUrl(), e2);
} catch (IllegalStateException e3) {
getRequest.abort();
Log.e(NPStringFog.decode("281901042A0E100B1E011109041C"), NPStringFog.decode("271E0E0E1C130206064E253F2D5441") + this.currentPackage.getUrl());
} catch (Exception e4) {
getRequest.abort();
Log.e(NPStringFog.decode("281901042A0E100B1E011109041C"), NPStringFog.decode("2B021F0E1C41100D1B02154D130B15150C17181903064E070E09174E161F0E0341") + this.currentPackage.getUrl(), e4);
}
if (statusCode != 200) {
Log.e(NPStringFog.decode("281901042A0E100B1E011109041C"), NPStringFog.decode("2B021F0E1C41") + statusCode + NPStringFog.decode("4E07050802044717171A0204041808090252") + this.currentPackage.getUrl());
return false;
}
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream inputStream = null;
long readBytes = 0;
try {
long totalBytes = entity.getContentLength();
if (zipFile.length() != totalBytes) {
inputStream = entity.getContent();
BufferedInputStream bis = new BufferedInputStream(inputStream);
byte[] buffer = new byte[524288];
FileOutputStream fos = new FileOutputStream(zipFile);
do {
bytesRead = bis.read(buffer, 0, buffer.length);
if (bytesRead > 0) {
readBytes += bytesRead;
fos.write(buffer, 0, bytesRead);
if (this.listener != null) {
this.listener.onPackageDownload((int) readBytes);
}
}
if (isCancelled()) {
if (inputStream != null) {
inputStream.close();
entity.consumeContent();
}
return false;
}
} while (bytesRead != -1);
bis.close();
fos.flush();
fos.close();
}
System.gc();
} finally {
if (inputStream != null) {
inputStream.close();
entity.consumeContent();
}
}
}
return true;
}
}
public boolean unpackCurrentPackage() {
if (this.currentPackage == null) {
return false;
}
if (this.currentPackage.getUrl().equals(NPStringFog.decode("3D242C2F2A3E26293D2035"))) {
this.currentPackage.getFile().equals(NPStringFog.decode("061F000C5D3E0A041B0055094F140817"));
}
if (!this.currentPackage.getUnpack()) {
return true;
}
String filePath = this.currentPackage.getFullPath();
try {
if (this.listener != null) {
this.listener.onPackageUnpack(NPStringFog.decode(""), 0);
}
if (this.currentPackage.getUrl().equals(NPStringFog.decode("3D242C2F2A3E26293D2035"))) {
int nEntries = 0;
try {
ZipInputStream standAloneZis = new ZipInputStream(new BufferedInputStream(this.standAloneIs));
while (standAloneZis.getNextEntry() != null) {
nEntries++;
}
int nProcessedEntries = 0;
this.standAloneIs.reset();
ZipInputStream standAloneZis2 = new ZipInputStream(new BufferedInputStream(this.standAloneIs));
while (true) {
try {
ZipEntry ze = standAloneZis2.getNextEntry();
if (ze == null) {
break;
} else if (ze.isDirectory()) {
nProcessedEntries++;
String filename = ze.getName();
if (this.listener != null) {
this.listener.onPackageUnpack(filename, (nProcessedEntries * 100) / nEntries);
}
File fDir = new File(String.valueOf(this.gameDirectory) + NPStringFog.decode("41") + filename);
fDir.mkdirs();
File noMediaFile = new File(fDir, NPStringFog.decode("401E020C0B050E04"));
noMediaFile.createNewFile();
if (isCancelled()) {
return false;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
this.standAloneIs.reset();
ZipInputStream standAloneZis3 = new ZipInputStream(new BufferedInputStream(this.standAloneIs));
byte[] buffer = new byte[262144];
while (true) {
ZipEntry ze2 = standAloneZis3.getNextEntry();
if (ze2 == null) {
break;
} else if (!ze2.isDirectory()) {
nProcessedEntries++;
String filename2 = ze2.getName();
if (!this.currentPackage.getUrl().equals(NPStringFog.decode("2F2026")) || filename2.startsWith(NPStringFog.decode("0F031E041A1248"))) {
int lastSeparator = filename2.lastIndexOf(47);
String fName = lastSeparator != -1 ? filename2.substring(lastSeparator + 1) : filename2;
if (this.listener != null) {
this.listener.onPackageUnpack(fName, (nProcessedEntries * 100) / nEntries);
}
if (isCancelled()) {
return false;
}
File fFile = new File(String.valueOf(this.gameDirectory) + NPStringFog.decode("41") + filename2);
if (fFile.exists()) {
if (fFile.length() != ze2.getSize()) {
fFile.delete();
} else {
continue;
}
}
fFile.createNewFile();
FileOutputStream fout = new FileOutputStream(String.valueOf(this.gameDirectory) + '/' + filename2);
BufferedOutputStream bos = new BufferedOutputStream(fout, 65536);
while (true) {
int count = standAloneZis3.read(buffer);
if (count == -1) {
break;
}
bos.write(buffer, 0, count);
}
bos.flush();
fout.flush();
bos.close();
fout.close();
standAloneZis3.closeEntry();
if (isCancelled()) {
return false;
}
}
}
}
} catch (IOException e2) {
e2.printStackTrace();
return false;
}
} else {
ZipFile zf = new ZipFile(filePath);
int nEntries2 = 0;
Enumeration<? extends ZipEntry> entries = zf.entries();
while (entries.hasMoreElements()) {
entries.nextElement();
nEntries2++;
}
int nProcessedEntries2 = 0;
InputStream is = new FileInputStream(filePath);
BufferedInputStream bis = new BufferedInputStream(is);
ZipInputStream zis = new ZipInputStream(bis);
while (true) {
try {
ZipEntry ze3 = zis.getNextEntry();
if (ze3 == null) {
break;
} else if (ze3.isDirectory()) {
nProcessedEntries2++;
String filename3 = ze3.getName();
if (this.listener != null) {
this.listener.onPackageUnpack(filename3, (nProcessedEntries2 * 100) / nEntries2);
}
File fDir2 = new File(String.valueOf(this.gameDirectory) + NPStringFog.decode("41") + filename3);
fDir2.mkdirs();
File noMediaFile2 = new File(fDir2, NPStringFog.decode("401E020C0B050E04"));
noMediaFile2.createNewFile();
if (isCancelled()) {
return false;
}
}
} catch (IOException e3) {
e3.printStackTrace();
}
}
InputStream is2 = new FileInputStream(filePath);
BufferedInputStream bis2 = new BufferedInputStream(is2);
ZipInputStream zis2 = new ZipInputStream(bis2);
byte[] buffer2 = new byte[262144];
while (true) {
ZipEntry ze4 = zis2.getNextEntry();
if (ze4 != null) {
if (!ze4.isDirectory()) {
nProcessedEntries2++;
String filename4 = ze4.getName();
if (!this.currentPackage.getUrl().equals(NPStringFog.decode("2F2026")) || filename4.startsWith(NPStringFog.decode("0F031E041A1248"))) {
int lastSeparator2 = filename4.lastIndexOf(47);
String fName2 = lastSeparator2 != -1 ? filename4.substring(lastSeparator2 + 1) : filename4;
if (this.listener != null) {
this.listener.onPackageUnpack(fName2, (nProcessedEntries2 * 100) / nEntries2);
}
if (isCancelled()) {
return false;
}
File fFile2 = new File(String.valueOf(this.gameDirectory) + NPStringFog.decode("41") + filename4);
if (fFile2.exists()) {
if (fFile2.length() != ze4.getSize()) {
fFile2.delete();
} else {
continue;
}
}
fFile2.createNewFile();
FileOutputStream fout2 = new FileOutputStream(String.valueOf(this.gameDirectory) + NPStringFog.decode("41") + filename4);
BufferedOutputStream bos2 = new BufferedOutputStream(fout2, 65536);
while (true) {
int count2 = zis2.read(buffer2);
if (count2 == -1) {
break;
}
bos2.write(buffer2, 0, count2);
}
bos2.flush();
fout2.flush();
bos2.close();
fout2.close();
zis2.closeEntry();
if (isCancelled()) {
return false;
}
}
}
} else {
zis2.close();
break;
}
}
}
} catch (IOException e4) {
e4.printStackTrace();
return false;
}
}
public boolean finishCurrentPackage() {
File fMarker = new File(this.gameDirectory, this.currentPackage.getMarker());
boolean bResult = false;
try {
bResult = fMarker.createNewFile();
} catch (Exception e) {
e.printStackTrace();
}
if (this.currentPackage.getUnpack()) {
try {
File fZip = new File(this.gameDirectory, this.currentPackage.getFile());
fZip.delete();
} catch (Exception e2) {
e2.printStackTrace();
}
}
return bResult;
}
public boolean verifyCurrentPackage() {
int bytesRead;
if (this.currentPackage == null) {
return false;
}
if (this.currentPackage.getMD5() == null || this.currentPackage.getMD5().isEmpty()) {
return true;
}
try {
File file = new File(String.valueOf(this.gameDirectory) + '/' + this.currentPackage.getFile());
if (file == null || !file.exists()) {
return false;
}
FileInputStream fis = new FileInputStream(file);
byte[] fileBuffer = new byte[65536];
MessageDigest digest = MessageDigest.getInstance(NPStringFog.decode("233458"));
do {
bytesRead = fis.read(fileBuffer, 0, 65536);
if (bytesRead != -1) {
digest.update(fileBuffer, 0, bytesRead);
}
} while (bytesRead != -1);
byte[] messageDigest = digest.digest();
StringBuffer hexString = new StringBuffer();
for (byte b : messageDigest) {
hexString.append(Integer.toHexString(b & Constants.UNKNOWN));
}
String computedHash = hexString.toString();
if (computedHash.equalsIgnoreCase(this.currentPackage.getMD5())) {
return true;
}
return false;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
private final void createRequiredDirectories() {
File fDirectory = new File(Environment.getExternalStorageDirectory() + NPStringFog.decode("413103051C0E0E01"));
if (!fDirectory.exists()) {
fDirectory.mkdir();
}
File fDirectory2 = new File(Environment.getExternalStorageDirectory() + NPStringFog.decode("413103051C0E0E015D0A111900"));
if (!fDirectory2.exists()) {
fDirectory2.mkdir();
}
File fDirectory3 = new File(Environment.getExternalStorageDirectory() + NPStringFog.decode("413103051C0E0E015D0A11190041") + this.context.getPackageName());
if (!fDirectory3.exists()) {
fDirectory3.mkdir();
}
File fDirectory4 = new File(Environment.getExternalStorageDirectory() + NPStringFog.decode("413103051C0E0E015D0A11190041") + this.context.getPackageName() + NPStringFog.decode("4116040D0B12"));
if (!fDirectory4.exists()) {
fDirectory4.mkdir();
}
}
public final boolean checkGameInstallation() {
createRequiredDirectories();
Iterator<GamePackage> it = this.packages.iterator();
while (it.hasNext()) {
GamePackage gp = it.next();
this.currentPackage = gp;
if (!checkCurrentPackage()) {
return false;
}
}
return true;
}
@Override
public String doInBackground(String... params) {
createRequiredDirectories();
File noMediaFile = new File(this.gameDirectory, NPStringFog.decode("401E020C0B050E04"));
try {
if (!noMediaFile.exists()) {
noMediaFile.createNewFile();
}
} catch (IOException e) {
e.printStackTrace();
}
Iterator<GamePackage> it = this.packages.iterator();
while (it.hasNext()) {
GamePackage gp = it.next();
this.currentPackage = gp;
if (this.listener != null) {
this.listener.onPackageBegin(this.currentPackage.getName(), this.currentPackage.getSize());
}
if (isCancelled()) {
return null;
}
if (!checkCurrentPackage()) {
this.bInstallOccured = true;
if (isCancelled()) {
return null;
}
if (!isOnline()) {
if (this.listener != null) {
this.listener.onNoInternetError();
return null;
}
return null;
} else if (isCancelled()) {
return null;
} else {
int packageSize = (this.currentPackage.getSize() / 1024) / 1024;
if (this.currentPackage.getUnpack()) {
packageSize *= 2;
}
if (!isSpaceAvailable(packageSize)) {
if (this.listener != null) {
this.listener.onNoFreeSpaceError(packageSize);
return null;
}
return null;
} else if (!downloadCurrentPackage()) {
if (this.listener != null) {
this.listener.onPackageError(this.currentPackage.getName(), 1);
return null;
}
return null;
} else if (isCancelled()) {
return null;
} else {
if (!verifyCurrentPackage()) {
if (this.listener != null) {
this.listener.onPackageError(this.currentPackage.getName(), 2);
return null;
}
return null;
} else if (isCancelled()) {
return null;
} else {
if (!unpackCurrentPackage()) {
if (this.listener != null) {
this.listener.onPackageError(this.currentPackage.getName(), 3);
return null;
}
return null;
} else if (isCancelled()) {
return null;
} else {
if (!finishCurrentPackage()) {
if (this.listener != null) {
this.listener.onPackageError(this.currentPackage.getName(), 4);
return null;
}
return null;
}
}
}
}
}
}
}
this.packages.clear();
return NPStringFog.decode("213B");
}
@Override
public void onPostExecute(String string) {
if (this.listener != null) {
this.listener.onInstallFinished(this.bInstallOccured);
}
}
}