备份,含修复插件
This commit is contained in:
parent
65f12c822c
commit
825b3d820f
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.분綾SDK.zip
|
||||
|
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
1
.idea/modules.xml
generated
1
.idea/modules.xml
generated
@ -4,6 +4,7 @@
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/RefreshRecyclerView/RefreshRecyclerView.iml" filepath="$PROJECT_DIR$/RefreshRecyclerView/RefreshRecyclerView.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/harmony/harmony.iml" filepath="$PROJECT_DIR$/harmony/harmony.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/jianrmg_v2.iml" filepath="$PROJECT_DIR$/jianrmg_v2.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/mylibrary/mylibrary.iml" filepath="$PROJECT_DIR$/mylibrary/mylibrary.iml" />
|
||||
</modules>
|
||||
|
@ -129,8 +129,8 @@ dependencies {
|
||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
|
||||
|
||||
//友盟
|
||||
implementation 'com.umeng.umsdk:analytics:7.5.4'
|
||||
implementation 'com.umeng.umsdk:common:1.5.4'
|
||||
implementation 'com.umeng.umsdk:analytics:8.0.0'
|
||||
implementation 'com.umeng.umsdk:common:2.0.0'
|
||||
|
||||
//友盟推动
|
||||
implementation 'com.umeng.umsdk:utdid:1.1.5.3'
|
||||
@ -143,4 +143,8 @@ dependencies {
|
||||
api project(path: ':ResModl')
|
||||
api project(path: ':UserModel')*/
|
||||
implementation files('libs/tbs_sdk_thirdapp_v3.6.0.1371_43624_sharewithdownload_withoutGame_obfs_20181106_121046.jar')
|
||||
//七牛云
|
||||
implementation 'com.qiniu:qiniu-android-sdk:7.3.15'
|
||||
//zip4j
|
||||
implementation group: 'net.lingala.zip4j', name: 'zip4j', version: '1.3.3'
|
||||
}
|
||||
|
@ -89,6 +89,8 @@
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
|
||||
android:screenOrientation="landscape" />
|
||||
<activity android:name=".views.WarLogActivity" />
|
||||
<activity android:name=".views.GameDataActivity" />
|
||||
<activity android:name=".views.NativeAdActivity" />
|
||||
|
||||
|
||||
<provider
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.yutou.jianr_mg.Adapters.GameDataAdapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
@ -8,13 +9,21 @@ import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.kaopiz.kprogresshud.KProgressHUD;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.yutou.jianr_mg.Interfaces.ModInterface;
|
||||
import com.yutou.jianr_mg.R;
|
||||
import com.yutou.jianr_mg.Tools.ModUtils;
|
||||
import com.yutou.jianr_mg.Tools.Utils;
|
||||
import com.yutou.jianr_mg.Tools.ZipUtils;
|
||||
import com.yutou.jianr_mg.views.WarLogActivity;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
@ -95,7 +104,33 @@ public class WarAdapter extends RecyclerAdapter<List<Map<String, JSONObject>>> {
|
||||
@Override
|
||||
public void onItemViewClick(List<Map<String, JSONObject>> data) {
|
||||
super.onItemViewClick(data);
|
||||
Utils.toast(getContext(),"详细内容正在咕,敬请期待");
|
||||
// Utils.toast(getContext(),"详细内容正在咕,敬请期待");
|
||||
ModUtils utils= ModUtils.init(getContext());
|
||||
utils.notRootInstall(new File(Utils.getAppPath()+"/harmony/Cocos2dxPrefsFile.xml"),"../shared_prefs/");
|
||||
utils.notRootInstallStart(new ModInterface() {
|
||||
@Override
|
||||
public void onAction(boolean flag, int type) {
|
||||
System.out.println("反和谐结果:"+flag);
|
||||
}
|
||||
},false);
|
||||
|
||||
/* JSONArray array=new JSONArray();
|
||||
for (Map<String, JSONObject> datum : data) {
|
||||
try {
|
||||
JSONObject json=new JSONObject();
|
||||
json.put("data",datum.get("data"));
|
||||
json.put("DealNode",datum.get("DealNode"));
|
||||
json.put("WarReport",datum.get("GetWarResult"));
|
||||
array.put(json);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
Intent intent=new Intent(getContext(), WarLogActivity.class);
|
||||
intent.putExtra("data", array.toString());
|
||||
getContext().startActivity(intent);*/
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,10 @@ package com.yutou.jianr_mg.Adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ClipDrawable;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -25,7 +29,7 @@ public class MagicTeamDataAdapter extends BaseAdapter {
|
||||
List<TeamData> list;
|
||||
Context context;
|
||||
ImageLoader loader;
|
||||
boolean spoiler=false;
|
||||
boolean spoiler = true;
|
||||
|
||||
|
||||
public MagicTeamDataAdapter(List<TeamData> list, Context context) {
|
||||
@ -35,7 +39,7 @@ public class MagicTeamDataAdapter extends BaseAdapter {
|
||||
}
|
||||
|
||||
public void setSpoiler(boolean spoiler) {
|
||||
this.spoiler = spoiler;
|
||||
// this.spoiler = spoiler;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,13 +56,13 @@ public class MagicTeamDataAdapter extends BaseAdapter {
|
||||
public long getItemId(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
ItemViews item = null;
|
||||
@Override
|
||||
public View getView(int i, View view, ViewGroup viewGroup) {
|
||||
ItemViews item = null;
|
||||
|
||||
if (view == null) {
|
||||
item = new ItemViews();
|
||||
view = LayoutInflater.from(context).inflate(R.layout.item_team, viewGroup,false);
|
||||
view = LayoutInflater.from(context).inflate(R.layout.item_team, viewGroup, false);
|
||||
item.hp = view.findViewById(R.id.hp);
|
||||
item.hpMax = view.findViewById(R.id.hpMax);
|
||||
item.hpBar = view.findViewById(R.id.itemHp);
|
||||
@ -69,30 +73,58 @@ public class MagicTeamDataAdapter extends BaseAdapter {
|
||||
item.item2 = view.findViewById(R.id.item2);
|
||||
item.item3 = view.findViewById(R.id.item3);
|
||||
item.item4 = view.findViewById(R.id.item4);
|
||||
item.hpLayout=view.findViewById(R.id.hpLayout);
|
||||
item.hpLayout = view.findViewById(R.id.hpLayout);
|
||||
view.setTag(item);
|
||||
} else {
|
||||
item = (ItemViews) view.getTag();
|
||||
}
|
||||
TeamData data = list.get(i);
|
||||
item.hp.setText(data.getHp());
|
||||
if(!spoiler){
|
||||
if (!spoiler) {
|
||||
item.hp.setText("???");
|
||||
}
|
||||
item.hpMax.setText(data.getHpMax());
|
||||
item.hpBar.setMax(Integer.valueOf(data.getHpMax()));
|
||||
item.hpBar.setProgress(Integer.valueOf(data.getHp()));
|
||||
if(!spoiler){
|
||||
item.hpBar.setProgress(0);
|
||||
item.hpBar.setMax(100);
|
||||
|
||||
if (Float.valueOf(data.getHp()) > (Float.valueOf(data.getHpMax()) / 2)) {
|
||||
ClipDrawable d = new ClipDrawable(new ColorDrawable(Color.DKGRAY), Gravity.START, ClipDrawable.HORIZONTAL);
|
||||
item.hpBar.setProgressDrawable(d);
|
||||
System.out.println(data.getTitle()+"设置颜色:绿色"+data.getHp()+"/"+data.getHpMax());
|
||||
} else if (Float.valueOf(data.getHp()) < (Float.valueOf(data.getHpMax()) / 2)&&Float.valueOf(data.getHp()) >= (Float.valueOf(data.getHpMax()) / 2/ 2)) {
|
||||
ClipDrawable d = new ClipDrawable(new ColorDrawable(Color.YELLOW), Gravity.START, ClipDrawable.HORIZONTAL);
|
||||
item.hpBar.setProgressDrawable(d);
|
||||
System.out.println(data.getTitle()+"设置颜色:黄色"+data.getHp()+"/"+data.getHpMax());
|
||||
} else if (Float.valueOf(data.getHp()) < (Float.valueOf(data.getHpMax()) / 2/ 2) ) {
|
||||
ClipDrawable d = new ClipDrawable(new ColorDrawable(Color.RED), Gravity.START, ClipDrawable.HORIZONTAL);
|
||||
item.hpBar.setProgressDrawable(d);
|
||||
System.out.println(data.getTitle()+"设置颜色:红色"+data.getHp()+"/"+data.getHpMax());
|
||||
}else{
|
||||
System.out.println("没有设置颜色");
|
||||
}
|
||||
if(data.getTitle().equals("凰")){
|
||||
item.hpBar.setMax(100);
|
||||
item.hpBar.setProgress(86);
|
||||
System.out.println("赤城的参数"+getHp(data.getHp(),data.getHpMax())+" "+(Float.valueOf(data.getHp()) > (Float.valueOf(data.getHpMax()) / 2)));
|
||||
|
||||
}else
|
||||
item.hpBar.setProgress((int) getHp(data.getHp(),data.getHpMax()));
|
||||
if (!spoiler) {
|
||||
// item.hpBar.setProgress(0);
|
||||
}
|
||||
item.title.setText(data.getTitle());
|
||||
if(!data.isUser()){
|
||||
((LinearLayout.LayoutParams)item.hpLayout.getLayoutParams()).gravity=Gravity.END;
|
||||
item.title.setVisibility(View.VISIBLE);
|
||||
item.hp.setVisibility(View.VISIBLE);
|
||||
item.hpMax.setVisibility(View.VISIBLE);
|
||||
item.title.setTextColor(Color.BLACK);
|
||||
item.hp.setTextColor(Color.BLACK);
|
||||
item.hpMax.setTextColor(Color.BLACK);
|
||||
if (!data.isUser()) {
|
||||
((LinearLayout.LayoutParams) item.hpLayout.getLayoutParams()).gravity = Gravity.END;
|
||||
item.title.setGravity(Gravity.END);
|
||||
item.icon.setVisibility(View.GONE);
|
||||
item.icon_.setVisibility(View.VISIBLE);
|
||||
}else{
|
||||
((LinearLayout.LayoutParams)item.hpLayout.getLayoutParams()).gravity=Gravity.LEFT;
|
||||
} else {
|
||||
((LinearLayout.LayoutParams) item.hpLayout.getLayoutParams()).gravity = Gravity.LEFT;
|
||||
item.title.setGravity(Gravity.LEFT);
|
||||
item.icon.setVisibility(View.VISIBLE);
|
||||
item.icon_.setVisibility(View.GONE);
|
||||
@ -105,33 +137,34 @@ public class MagicTeamDataAdapter extends BaseAdapter {
|
||||
}
|
||||
}
|
||||
if (data.getItem1Url() != null) {
|
||||
loader.displayImage(data.getItem1Url(), item.item1,new imageListener() );
|
||||
loader.displayImage(data.getItem1Url(), item.item1, new imageListener());
|
||||
item.item1.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||
item.item1.setVisibility(View.VISIBLE);
|
||||
}else{
|
||||
} else {
|
||||
item.item1.setVisibility(View.GONE);
|
||||
}
|
||||
if (data.getItem2Url() != null) {
|
||||
loader.displayImage(data.getItem2Url(), item.item2,new imageListener());
|
||||
loader.displayImage(data.getItem2Url(), item.item2, new imageListener());
|
||||
item.item2.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||
item.item2.setVisibility(View.VISIBLE);
|
||||
}else{
|
||||
} else {
|
||||
item.item2.setVisibility(View.GONE);
|
||||
}
|
||||
if (data.getItem3Url() != null) {
|
||||
loader.displayImage(data.getItem3Url(), item.item3,new imageListener());
|
||||
loader.displayImage(data.getItem3Url(), item.item3, new imageListener());
|
||||
item.item3.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||
item.item3.setVisibility(View.VISIBLE);
|
||||
}else{
|
||||
} else {
|
||||
item.item3.setVisibility(View.GONE);
|
||||
}
|
||||
if (data.getItem4Url() != null) {
|
||||
loader.displayImage(data.getItem4Url(), item.item4,new imageListener());
|
||||
loader.displayImage(data.getItem4Url(), item.item4, new imageListener());
|
||||
item.item4.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||
item.item4.setVisibility(View.VISIBLE);
|
||||
}else{
|
||||
} else {
|
||||
item.item4.setVisibility(View.GONE);
|
||||
}
|
||||
item.reload();
|
||||
return view;
|
||||
}
|
||||
|
||||
@ -144,12 +177,30 @@ public class MagicTeamDataAdapter extends BaseAdapter {
|
||||
return this.list;
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
if(item!=null){
|
||||
item.reload();
|
||||
}
|
||||
}
|
||||
public float getHp(String hp,String maxHp){
|
||||
float h=Float.parseFloat(hp);
|
||||
float max=Float.parseFloat(maxHp);
|
||||
return 100/max*h;
|
||||
}
|
||||
class ItemViews {
|
||||
TextView title, hp, hpMax;
|
||||
ImageView icon, icon_, item1, item2, item3, item4;
|
||||
ProgressBar hpBar;
|
||||
LinearLayout hpLayout;
|
||||
|
||||
void reload() {
|
||||
title.postInvalidate();
|
||||
hp.postInvalidate();
|
||||
hpMax.postInvalidate();
|
||||
hpBar.postInvalidate();
|
||||
}
|
||||
}
|
||||
|
||||
class imageListener implements ImageLoadingListener {
|
||||
@Override
|
||||
public void onLoadingStarted(String imageUri, View view) {
|
||||
@ -158,7 +209,7 @@ public class MagicTeamDataAdapter extends BaseAdapter {
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
ImageView imageView= (ImageView) view;
|
||||
ImageView imageView = (ImageView) view;
|
||||
imageView.setImageResource(R.mipmap.icon_logo);
|
||||
}
|
||||
|
||||
|
@ -74,11 +74,13 @@ public class MainUtilsAdapter extends RecyclerAdapter<MAppTools> {
|
||||
getContext().startService(intent);
|
||||
break;
|
||||
case "localActivity":
|
||||
System.out.println("数据:"+data.toString());
|
||||
intent=new Intent(getContext(), BaseActivity.class);
|
||||
intent.putExtra("activityName",main);
|
||||
intent.putExtra("jar",data.getPluginName()+".jar");
|
||||
intent.putExtra("jar",data.getUrl().split("/")[data.getUrl().split("/").length-1]);
|
||||
intent.putExtra("name",data.getName());
|
||||
intent.putExtra("url",data.getUrl());
|
||||
System.out.println("插件数据:"+data.getUrl().split("/")[data.getUrl().split("/").length-1]);
|
||||
if(data.getParameter()!=null){
|
||||
intent.putExtra("parameter",data.getParameter());
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import android.app.Notification;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import com.tencent.smtt.sdk.QbSdk;
|
||||
import com.umeng.analytics.MobclickAgent;
|
||||
@ -49,29 +50,27 @@ public class Application extends android.app.Application {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Application.application = this;
|
||||
// DoraemonKit.install(application);
|
||||
UMConfigure.setLogEnabled(true);
|
||||
// DoraemonKit.install(application);
|
||||
//UMConfigure.setLogEnabled(true);
|
||||
System.out.println("开始初始化");
|
||||
|
||||
init();
|
||||
initPlugs();
|
||||
regActivity();
|
||||
JianRUtils.initShipCardId();
|
||||
|
||||
initUmeng();
|
||||
initTx();
|
||||
|
||||
|
||||
//initUmeng();
|
||||
// initTx();
|
||||
|
||||
|
||||
System.out.println("初始化结束");
|
||||
}
|
||||
private void initUmeng(){
|
||||
|
||||
private void initUmeng() {
|
||||
try {
|
||||
UMConfigure.init(this, UMConfigure.DEVICE_TYPE_PHONE, "c5ec76e4a6ebb1516359792ffee09eb5");
|
||||
MobclickAgent.setScenarioType(this, MobclickAgent.EScenarioType.E_UM_NORMAL);
|
||||
PushAgent pushAgent= PushAgent.getInstance(this);
|
||||
pushAgent.register(new IUmengRegisterCallback() {
|
||||
PushAgent pushAgent = PushAgent.getInstance(this);
|
||||
pushAgent.register(new IUmengRegisterCallback() {
|
||||
@Override
|
||||
public void onSuccess(String s) {
|
||||
System.out.println("友盟推送注册成功:" + s);
|
||||
@ -82,23 +81,24 @@ public class Application extends android.app.Application {
|
||||
System.out.println("友盟推送注册失败:" + s + "(" + s1 + ")");
|
||||
}
|
||||
});
|
||||
pushAgent.setMessageHandler(new UmengMessageHandler(){
|
||||
pushAgent.setMessageHandler(new UmengMessageHandler() {
|
||||
@Override
|
||||
public Notification getNotification(Context context, UMessage uMessage) {
|
||||
for (Map.Entry<String, String> entry : uMessage.extra.entrySet()) {
|
||||
if(entry.getKey().equals("url")){
|
||||
LoadingActivity.url=entry.getValue();
|
||||
if (entry.getKey().equals("url")) {
|
||||
LoadingActivity.url = entry.getValue();
|
||||
}
|
||||
|
||||
}
|
||||
return super.getNotification(context, uMessage);
|
||||
}
|
||||
});
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private void initTx(){
|
||||
|
||||
private void initTx() {
|
||||
try {
|
||||
QbSdk.initX5Environment(this, new QbSdk.PreInitCallback() {
|
||||
@Override
|
||||
@ -108,24 +108,31 @@ public class Application extends android.app.Application {
|
||||
|
||||
@Override
|
||||
public void onViewInitFinished(boolean b) {
|
||||
Log.e("QDSDK","加载内核是否成功:"+b);
|
||||
Log.e("QDSDK", "加载内核是否成功:" + b);
|
||||
}
|
||||
});
|
||||
}catch (Exception ignored){
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initPlugs() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
|
||||
Map<String, DexClassLoader> plugsin = new HashMap<>();
|
||||
File path = new File(Utils.getAppPath() + "/plugin/");
|
||||
File dex = new File(Application.application.getFilesDir() + "/plugs/");
|
||||
if (!dex.exists()) {
|
||||
dex.mkdirs();
|
||||
}
|
||||
if (path.exists()) {
|
||||
for (File file : path.listFiles()) {
|
||||
if (file.getName().contains(".jar")) {
|
||||
DexClassLoader dexClassLoader = new DexClassLoader(file.getAbsolutePath(), Application.application.getFilesDir() + "/plugs/", null, getClassLoader());
|
||||
DexClassLoader dexClassLoader = new DexClassLoader(file.getAbsolutePath(), dex.getAbsolutePath(), null, getClassLoader());
|
||||
plugsin.put(file.getName(), dexClassLoader);
|
||||
System.out.println("加载插件:"+file.getName());
|
||||
AppData.plugsin.put(file.getName(), dexClassLoader);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -208,7 +215,7 @@ public class Application extends android.app.Application {
|
||||
public void onActivityCreated(Activity activity, Bundle bundle) {
|
||||
Log.i(TAG, "创建:" + activity.getClass().getName());
|
||||
AppData.activity = activity;
|
||||
AppData.handler = new Handler();
|
||||
AppData.handler = new Handler(Looper.getMainLooper());
|
||||
ActivitysManager.addActivity(activity);
|
||||
PushAgent.getInstance(activity).onAppStart();
|
||||
}
|
||||
|
@ -27,4 +27,5 @@ public class AppData {
|
||||
public static Handler handler;
|
||||
public static String version="1.0";
|
||||
public static String magicPackageName ="com.bigzhao.jianrmagicbox";
|
||||
public static boolean debug=false;
|
||||
}
|
||||
|
988
app/src/main/java/com/yutou/jianr_mg/Data/JianNiang.java
Normal file
988
app/src/main/java/com/yutou/jianr_mg/Data/JianNiang.java
Normal file
@ -0,0 +1,988 @@
|
||||
package com.yutou.jianr_mg.Data;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class JianNiang {
|
||||
private int cid;
|
||||
private int star;
|
||||
private String title;
|
||||
private int country;
|
||||
private int type;
|
||||
private int hp;
|
||||
private int atk;
|
||||
private int def;
|
||||
private String torpedo;
|
||||
private int miss;
|
||||
private int hit;
|
||||
private int capacity;
|
||||
private String antisub;
|
||||
private int speed;
|
||||
private int radar;
|
||||
private int range;
|
||||
private int luck;
|
||||
private DismantleBean dismantle;
|
||||
private String author;
|
||||
private int release;
|
||||
private String desc;
|
||||
private String vow;
|
||||
private int npc;
|
||||
private String shipIndex;
|
||||
private int shipTon;
|
||||
private int guardType;
|
||||
private String subTitle;
|
||||
private String titleClass;
|
||||
private String subTitleClass;
|
||||
private String classNo;
|
||||
private String subClassNo;
|
||||
private String picId;
|
||||
private int hpMax;
|
||||
private int atkMax;
|
||||
private int defMax;
|
||||
private String torpedoMax;
|
||||
private int missMax;
|
||||
private int hitMax;
|
||||
private int airDef;
|
||||
private int airDefMax;
|
||||
private String missileSlot;
|
||||
private String missileInit;
|
||||
private String antisubMax;
|
||||
private int radarMax;
|
||||
private int luckMax;
|
||||
private int evoLevel;
|
||||
private int evoCid;
|
||||
private int evoNeedItemCid;
|
||||
private int evoToCid;
|
||||
private EvoNeedResourceBean evoNeedResource;
|
||||
private int haveSkin;
|
||||
private String borderId;
|
||||
private String skillType;
|
||||
private String initSkillLevel;
|
||||
private int maxSkillLevel;
|
||||
private int canEvo;
|
||||
private int equipmentNum;
|
||||
private int maxLevel;
|
||||
private int maxOil;
|
||||
private int maxAmmo;
|
||||
private double repairOilModulus;
|
||||
private double repairSteelModulus;
|
||||
private double repairTime;
|
||||
private StrengthenTopBean strengthenTop;
|
||||
private StrengthenSupplyExpBean strengthenSupplyExp;
|
||||
private int strengthenLevelUpExp;
|
||||
private String evoClass;
|
||||
private String medalDesc;
|
||||
private String customField;
|
||||
private String getDialogue;
|
||||
private String atkDialogue;
|
||||
private String sinkDialogue;
|
||||
private String breakDialogue;
|
||||
private String formationDialogue;
|
||||
private String marryMainDialogue;
|
||||
private String nightAtkDialogue;
|
||||
private String myRoomDialogue;
|
||||
private String friendRoomDialogue;
|
||||
private String planeImgType;
|
||||
private String planeImgType2;
|
||||
private String gunType;
|
||||
private String teamShip;
|
||||
private List<?> skills;
|
||||
private List<Integer> equipment;
|
||||
private List<String> mainDialogue;
|
||||
private List<?> capacitySlot;
|
||||
private List<Integer> capacityInit;
|
||||
private List<Integer> equipmentType;
|
||||
private List<Integer> showAttribute;
|
||||
private List<Integer> kitchenPosition;
|
||||
|
||||
public int getCid() {
|
||||
return cid;
|
||||
}
|
||||
|
||||
public void setCid(int cid) {
|
||||
this.cid = cid;
|
||||
}
|
||||
|
||||
public int getStar() {
|
||||
return star;
|
||||
}
|
||||
|
||||
public void setStar(int star) {
|
||||
this.star = star;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public int getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(int country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getHp() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
public void setHp(int hp) {
|
||||
this.hp = hp;
|
||||
}
|
||||
|
||||
public int getAtk() {
|
||||
return atk;
|
||||
}
|
||||
|
||||
public void setAtk(int atk) {
|
||||
this.atk = atk;
|
||||
}
|
||||
|
||||
public int getDef() {
|
||||
return def;
|
||||
}
|
||||
|
||||
public void setDef(int def) {
|
||||
this.def = def;
|
||||
}
|
||||
|
||||
public String getTorpedo() {
|
||||
return torpedo;
|
||||
}
|
||||
|
||||
public void setTorpedo(String torpedo) {
|
||||
this.torpedo = torpedo;
|
||||
}
|
||||
|
||||
public int getMiss() {
|
||||
return miss;
|
||||
}
|
||||
|
||||
public void setMiss(int miss) {
|
||||
this.miss = miss;
|
||||
}
|
||||
|
||||
public int getHit() {
|
||||
return hit;
|
||||
}
|
||||
|
||||
public void setHit(int hit) {
|
||||
this.hit = hit;
|
||||
}
|
||||
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public void setCapacity(int capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
public String getAntisub() {
|
||||
return antisub;
|
||||
}
|
||||
|
||||
public void setAntisub(String antisub) {
|
||||
this.antisub = antisub;
|
||||
}
|
||||
|
||||
public int getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public void setSpeed(int speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public int getRadar() {
|
||||
return radar;
|
||||
}
|
||||
|
||||
public void setRadar(int radar) {
|
||||
this.radar = radar;
|
||||
}
|
||||
|
||||
public int getRange() {
|
||||
return range;
|
||||
}
|
||||
|
||||
public void setRange(int range) {
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
public int getLuck() {
|
||||
return luck;
|
||||
}
|
||||
|
||||
public void setLuck(int luck) {
|
||||
this.luck = luck;
|
||||
}
|
||||
|
||||
public DismantleBean getDismantle() {
|
||||
return dismantle;
|
||||
}
|
||||
|
||||
public void setDismantle(DismantleBean dismantle) {
|
||||
this.dismantle = dismantle;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public int getRelease() {
|
||||
return release;
|
||||
}
|
||||
|
||||
public void setRelease(int release) {
|
||||
this.release = release;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getVow() {
|
||||
return vow;
|
||||
}
|
||||
|
||||
public void setVow(String vow) {
|
||||
this.vow = vow;
|
||||
}
|
||||
|
||||
public int getNpc() {
|
||||
return npc;
|
||||
}
|
||||
|
||||
public void setNpc(int npc) {
|
||||
this.npc = npc;
|
||||
}
|
||||
|
||||
public String getShipIndex() {
|
||||
return shipIndex;
|
||||
}
|
||||
|
||||
public void setShipIndex(String shipIndex) {
|
||||
this.shipIndex = shipIndex;
|
||||
}
|
||||
|
||||
public int getShipTon() {
|
||||
return shipTon;
|
||||
}
|
||||
|
||||
public void setShipTon(int shipTon) {
|
||||
this.shipTon = shipTon;
|
||||
}
|
||||
|
||||
public int getGuardType() {
|
||||
return guardType;
|
||||
}
|
||||
|
||||
public void setGuardType(int guardType) {
|
||||
this.guardType = guardType;
|
||||
}
|
||||
|
||||
public String getSubTitle() {
|
||||
return subTitle;
|
||||
}
|
||||
|
||||
public void setSubTitle(String subTitle) {
|
||||
this.subTitle = subTitle;
|
||||
}
|
||||
|
||||
public String getTitleClass() {
|
||||
return titleClass;
|
||||
}
|
||||
|
||||
public void setTitleClass(String titleClass) {
|
||||
this.titleClass = titleClass;
|
||||
}
|
||||
|
||||
public String getSubTitleClass() {
|
||||
return subTitleClass;
|
||||
}
|
||||
|
||||
public void setSubTitleClass(String subTitleClass) {
|
||||
this.subTitleClass = subTitleClass;
|
||||
}
|
||||
|
||||
public String getClassNo() {
|
||||
return classNo;
|
||||
}
|
||||
|
||||
public void setClassNo(String classNo) {
|
||||
this.classNo = classNo;
|
||||
}
|
||||
|
||||
public String getSubClassNo() {
|
||||
return subClassNo;
|
||||
}
|
||||
|
||||
public void setSubClassNo(String subClassNo) {
|
||||
this.subClassNo = subClassNo;
|
||||
}
|
||||
|
||||
public String getPicId() {
|
||||
return picId;
|
||||
}
|
||||
|
||||
public void setPicId(String picId) {
|
||||
this.picId = picId;
|
||||
}
|
||||
|
||||
public int getHpMax() {
|
||||
return hpMax;
|
||||
}
|
||||
|
||||
public void setHpMax(int hpMax) {
|
||||
this.hpMax = hpMax;
|
||||
}
|
||||
|
||||
public int getAtkMax() {
|
||||
return atkMax;
|
||||
}
|
||||
|
||||
public void setAtkMax(int atkMax) {
|
||||
this.atkMax = atkMax;
|
||||
}
|
||||
|
||||
public int getDefMax() {
|
||||
return defMax;
|
||||
}
|
||||
|
||||
public void setDefMax(int defMax) {
|
||||
this.defMax = defMax;
|
||||
}
|
||||
|
||||
public String getTorpedoMax() {
|
||||
return torpedoMax;
|
||||
}
|
||||
|
||||
public void setTorpedoMax(String torpedoMax) {
|
||||
this.torpedoMax = torpedoMax;
|
||||
}
|
||||
|
||||
public int getMissMax() {
|
||||
return missMax;
|
||||
}
|
||||
|
||||
public void setMissMax(int missMax) {
|
||||
this.missMax = missMax;
|
||||
}
|
||||
|
||||
public int getHitMax() {
|
||||
return hitMax;
|
||||
}
|
||||
|
||||
public void setHitMax(int hitMax) {
|
||||
this.hitMax = hitMax;
|
||||
}
|
||||
|
||||
public int getAirDef() {
|
||||
return airDef;
|
||||
}
|
||||
|
||||
public void setAirDef(int airDef) {
|
||||
this.airDef = airDef;
|
||||
}
|
||||
|
||||
public int getAirDefMax() {
|
||||
return airDefMax;
|
||||
}
|
||||
|
||||
public void setAirDefMax(int airDefMax) {
|
||||
this.airDefMax = airDefMax;
|
||||
}
|
||||
|
||||
public String getMissileSlot() {
|
||||
return missileSlot;
|
||||
}
|
||||
|
||||
public void setMissileSlot(String missileSlot) {
|
||||
this.missileSlot = missileSlot;
|
||||
}
|
||||
|
||||
public String getMissileInit() {
|
||||
return missileInit;
|
||||
}
|
||||
|
||||
public void setMissileInit(String missileInit) {
|
||||
this.missileInit = missileInit;
|
||||
}
|
||||
|
||||
public String getAntisubMax() {
|
||||
return antisubMax;
|
||||
}
|
||||
|
||||
public void setAntisubMax(String antisubMax) {
|
||||
this.antisubMax = antisubMax;
|
||||
}
|
||||
|
||||
public int getRadarMax() {
|
||||
return radarMax;
|
||||
}
|
||||
|
||||
public void setRadarMax(int radarMax) {
|
||||
this.radarMax = radarMax;
|
||||
}
|
||||
|
||||
public int getLuckMax() {
|
||||
return luckMax;
|
||||
}
|
||||
|
||||
public void setLuckMax(int luckMax) {
|
||||
this.luckMax = luckMax;
|
||||
}
|
||||
|
||||
public int getEvoLevel() {
|
||||
return evoLevel;
|
||||
}
|
||||
|
||||
public void setEvoLevel(int evoLevel) {
|
||||
this.evoLevel = evoLevel;
|
||||
}
|
||||
|
||||
public int getEvoCid() {
|
||||
return evoCid;
|
||||
}
|
||||
|
||||
public void setEvoCid(int evoCid) {
|
||||
this.evoCid = evoCid;
|
||||
}
|
||||
|
||||
public int getEvoNeedItemCid() {
|
||||
return evoNeedItemCid;
|
||||
}
|
||||
|
||||
public void setEvoNeedItemCid(int evoNeedItemCid) {
|
||||
this.evoNeedItemCid = evoNeedItemCid;
|
||||
}
|
||||
|
||||
public int getEvoToCid() {
|
||||
return evoToCid;
|
||||
}
|
||||
|
||||
public void setEvoToCid(int evoToCid) {
|
||||
this.evoToCid = evoToCid;
|
||||
}
|
||||
|
||||
public EvoNeedResourceBean getEvoNeedResource() {
|
||||
return evoNeedResource;
|
||||
}
|
||||
|
||||
public void setEvoNeedResource(EvoNeedResourceBean evoNeedResource) {
|
||||
this.evoNeedResource = evoNeedResource;
|
||||
}
|
||||
|
||||
public int getHaveSkin() {
|
||||
return haveSkin;
|
||||
}
|
||||
|
||||
public void setHaveSkin(int haveSkin) {
|
||||
this.haveSkin = haveSkin;
|
||||
}
|
||||
|
||||
public String getBorderId() {
|
||||
return borderId;
|
||||
}
|
||||
|
||||
public void setBorderId(String borderId) {
|
||||
this.borderId = borderId;
|
||||
}
|
||||
|
||||
public String getSkillType() {
|
||||
return skillType;
|
||||
}
|
||||
|
||||
public void setSkillType(String skillType) {
|
||||
this.skillType = skillType;
|
||||
}
|
||||
|
||||
public String getInitSkillLevel() {
|
||||
return initSkillLevel;
|
||||
}
|
||||
|
||||
public void setInitSkillLevel(String initSkillLevel) {
|
||||
this.initSkillLevel = initSkillLevel;
|
||||
}
|
||||
|
||||
public int getMaxSkillLevel() {
|
||||
return maxSkillLevel;
|
||||
}
|
||||
|
||||
public void setMaxSkillLevel(int maxSkillLevel) {
|
||||
this.maxSkillLevel = maxSkillLevel;
|
||||
}
|
||||
|
||||
public int getCanEvo() {
|
||||
return canEvo;
|
||||
}
|
||||
|
||||
public void setCanEvo(int canEvo) {
|
||||
this.canEvo = canEvo;
|
||||
}
|
||||
|
||||
public int getEquipmentNum() {
|
||||
return equipmentNum;
|
||||
}
|
||||
|
||||
public void setEquipmentNum(int equipmentNum) {
|
||||
this.equipmentNum = equipmentNum;
|
||||
}
|
||||
|
||||
public int getMaxLevel() {
|
||||
return maxLevel;
|
||||
}
|
||||
|
||||
public void setMaxLevel(int maxLevel) {
|
||||
this.maxLevel = maxLevel;
|
||||
}
|
||||
|
||||
public int getMaxOil() {
|
||||
return maxOil;
|
||||
}
|
||||
|
||||
public void setMaxOil(int maxOil) {
|
||||
this.maxOil = maxOil;
|
||||
}
|
||||
|
||||
public int getMaxAmmo() {
|
||||
return maxAmmo;
|
||||
}
|
||||
|
||||
public void setMaxAmmo(int maxAmmo) {
|
||||
this.maxAmmo = maxAmmo;
|
||||
}
|
||||
|
||||
public double getRepairOilModulus() {
|
||||
return repairOilModulus;
|
||||
}
|
||||
|
||||
public void setRepairOilModulus(double repairOilModulus) {
|
||||
this.repairOilModulus = repairOilModulus;
|
||||
}
|
||||
|
||||
public double getRepairSteelModulus() {
|
||||
return repairSteelModulus;
|
||||
}
|
||||
|
||||
public void setRepairSteelModulus(double repairSteelModulus) {
|
||||
this.repairSteelModulus = repairSteelModulus;
|
||||
}
|
||||
|
||||
public double getRepairTime() {
|
||||
return repairTime;
|
||||
}
|
||||
|
||||
public void setRepairTime(double repairTime) {
|
||||
this.repairTime = repairTime;
|
||||
}
|
||||
|
||||
public StrengthenTopBean getStrengthenTop() {
|
||||
return strengthenTop;
|
||||
}
|
||||
|
||||
public void setStrengthenTop(StrengthenTopBean strengthenTop) {
|
||||
this.strengthenTop = strengthenTop;
|
||||
}
|
||||
|
||||
public StrengthenSupplyExpBean getStrengthenSupplyExp() {
|
||||
return strengthenSupplyExp;
|
||||
}
|
||||
|
||||
public void setStrengthenSupplyExp(StrengthenSupplyExpBean strengthenSupplyExp) {
|
||||
this.strengthenSupplyExp = strengthenSupplyExp;
|
||||
}
|
||||
|
||||
public int getStrengthenLevelUpExp() {
|
||||
return strengthenLevelUpExp;
|
||||
}
|
||||
|
||||
public void setStrengthenLevelUpExp(int strengthenLevelUpExp) {
|
||||
this.strengthenLevelUpExp = strengthenLevelUpExp;
|
||||
}
|
||||
|
||||
public String getEvoClass() {
|
||||
return evoClass;
|
||||
}
|
||||
|
||||
public void setEvoClass(String evoClass) {
|
||||
this.evoClass = evoClass;
|
||||
}
|
||||
|
||||
public String getMedalDesc() {
|
||||
return medalDesc;
|
||||
}
|
||||
|
||||
public void setMedalDesc(String medalDesc) {
|
||||
this.medalDesc = medalDesc;
|
||||
}
|
||||
|
||||
public String getCustomField() {
|
||||
return customField;
|
||||
}
|
||||
|
||||
public void setCustomField(String customField) {
|
||||
this.customField = customField;
|
||||
}
|
||||
|
||||
public String getGetDialogue() {
|
||||
return getDialogue;
|
||||
}
|
||||
|
||||
public void setGetDialogue(String getDialogue) {
|
||||
this.getDialogue = getDialogue;
|
||||
}
|
||||
|
||||
public String getAtkDialogue() {
|
||||
return atkDialogue;
|
||||
}
|
||||
|
||||
public void setAtkDialogue(String atkDialogue) {
|
||||
this.atkDialogue = atkDialogue;
|
||||
}
|
||||
|
||||
public String getSinkDialogue() {
|
||||
return sinkDialogue;
|
||||
}
|
||||
|
||||
public void setSinkDialogue(String sinkDialogue) {
|
||||
this.sinkDialogue = sinkDialogue;
|
||||
}
|
||||
|
||||
public String getBreakDialogue() {
|
||||
return breakDialogue;
|
||||
}
|
||||
|
||||
public void setBreakDialogue(String breakDialogue) {
|
||||
this.breakDialogue = breakDialogue;
|
||||
}
|
||||
|
||||
public String getFormationDialogue() {
|
||||
return formationDialogue;
|
||||
}
|
||||
|
||||
public void setFormationDialogue(String formationDialogue) {
|
||||
this.formationDialogue = formationDialogue;
|
||||
}
|
||||
|
||||
public String getMarryMainDialogue() {
|
||||
return marryMainDialogue;
|
||||
}
|
||||
|
||||
public void setMarryMainDialogue(String marryMainDialogue) {
|
||||
this.marryMainDialogue = marryMainDialogue;
|
||||
}
|
||||
|
||||
public String getNightAtkDialogue() {
|
||||
return nightAtkDialogue;
|
||||
}
|
||||
|
||||
public void setNightAtkDialogue(String nightAtkDialogue) {
|
||||
this.nightAtkDialogue = nightAtkDialogue;
|
||||
}
|
||||
|
||||
public String getMyRoomDialogue() {
|
||||
return myRoomDialogue;
|
||||
}
|
||||
|
||||
public void setMyRoomDialogue(String myRoomDialogue) {
|
||||
this.myRoomDialogue = myRoomDialogue;
|
||||
}
|
||||
|
||||
public String getFriendRoomDialogue() {
|
||||
return friendRoomDialogue;
|
||||
}
|
||||
|
||||
public void setFriendRoomDialogue(String friendRoomDialogue) {
|
||||
this.friendRoomDialogue = friendRoomDialogue;
|
||||
}
|
||||
|
||||
public String getPlaneImgType() {
|
||||
return planeImgType;
|
||||
}
|
||||
|
||||
public void setPlaneImgType(String planeImgType) {
|
||||
this.planeImgType = planeImgType;
|
||||
}
|
||||
|
||||
public String getPlaneImgType2() {
|
||||
return planeImgType2;
|
||||
}
|
||||
|
||||
public void setPlaneImgType2(String planeImgType2) {
|
||||
this.planeImgType2 = planeImgType2;
|
||||
}
|
||||
|
||||
public String getGunType() {
|
||||
return gunType;
|
||||
}
|
||||
|
||||
public void setGunType(String gunType) {
|
||||
this.gunType = gunType;
|
||||
}
|
||||
|
||||
public String getTeamShip() {
|
||||
return teamShip;
|
||||
}
|
||||
|
||||
public void setTeamShip(String teamShip) {
|
||||
this.teamShip = teamShip;
|
||||
}
|
||||
|
||||
public List<?> getSkills() {
|
||||
return skills;
|
||||
}
|
||||
|
||||
public void setSkills(List<?> skills) {
|
||||
this.skills = skills;
|
||||
}
|
||||
|
||||
public List<Integer> getEquipment() {
|
||||
return equipment;
|
||||
}
|
||||
|
||||
public void setEquipment(List<Integer> equipment) {
|
||||
this.equipment = equipment;
|
||||
}
|
||||
|
||||
public List<String> getMainDialogue() {
|
||||
return mainDialogue;
|
||||
}
|
||||
|
||||
public void setMainDialogue(List<String> mainDialogue) {
|
||||
this.mainDialogue = mainDialogue;
|
||||
}
|
||||
|
||||
public List<?> getCapacitySlot() {
|
||||
return capacitySlot;
|
||||
}
|
||||
|
||||
public void setCapacitySlot(List<?> capacitySlot) {
|
||||
this.capacitySlot = capacitySlot;
|
||||
}
|
||||
|
||||
public List<Integer> getCapacityInit() {
|
||||
return capacityInit;
|
||||
}
|
||||
|
||||
public void setCapacityInit(List<Integer> capacityInit) {
|
||||
this.capacityInit = capacityInit;
|
||||
}
|
||||
|
||||
public List<Integer> getEquipmentType() {
|
||||
return equipmentType;
|
||||
}
|
||||
|
||||
public void setEquipmentType(List<Integer> equipmentType) {
|
||||
this.equipmentType = equipmentType;
|
||||
}
|
||||
|
||||
public List<Integer> getShowAttribute() {
|
||||
return showAttribute;
|
||||
}
|
||||
|
||||
public void setShowAttribute(List<Integer> showAttribute) {
|
||||
this.showAttribute = showAttribute;
|
||||
}
|
||||
|
||||
public List<Integer> getKitchenPosition() {
|
||||
return kitchenPosition;
|
||||
}
|
||||
|
||||
public void setKitchenPosition(List<Integer> kitchenPosition) {
|
||||
this.kitchenPosition = kitchenPosition;
|
||||
}
|
||||
|
||||
public static class DismantleBean {
|
||||
/**
|
||||
* 2 : 40
|
||||
* 3 : 50
|
||||
* 4 : 40
|
||||
* 9 : 0
|
||||
*/
|
||||
|
||||
@JSONField(name = "2")
|
||||
private int _$2;
|
||||
@JSONField(name = "3")
|
||||
private int _$3;
|
||||
@JSONField(name = "4")
|
||||
private int _$4;
|
||||
@JSONField(name = "9")
|
||||
private int _$9;
|
||||
|
||||
public int get_$2() {
|
||||
return _$2;
|
||||
}
|
||||
|
||||
public void set_$2(int _$2) {
|
||||
this._$2 = _$2;
|
||||
}
|
||||
|
||||
public int get_$3() {
|
||||
return _$3;
|
||||
}
|
||||
|
||||
public void set_$3(int _$3) {
|
||||
this._$3 = _$3;
|
||||
}
|
||||
|
||||
public int get_$4() {
|
||||
return _$4;
|
||||
}
|
||||
|
||||
public void set_$4(int _$4) {
|
||||
this._$4 = _$4;
|
||||
}
|
||||
|
||||
public int get_$9() {
|
||||
return _$9;
|
||||
}
|
||||
|
||||
public void set_$9(int _$9) {
|
||||
this._$9 = _$9;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EvoNeedResourceBean {
|
||||
/**
|
||||
* 4 : 200
|
||||
* 10241 : 20
|
||||
*/
|
||||
|
||||
@JSONField(name = "4")
|
||||
private int _$4;
|
||||
@JSONField(name = "10241")
|
||||
private int _$10241;
|
||||
|
||||
public int get_$4() {
|
||||
return _$4;
|
||||
}
|
||||
|
||||
public void set_$4(int _$4) {
|
||||
this._$4 = _$4;
|
||||
}
|
||||
|
||||
public int get_$10241() {
|
||||
return _$10241;
|
||||
}
|
||||
|
||||
public void set_$10241(int _$10241) {
|
||||
this._$10241 = _$10241;
|
||||
}
|
||||
}
|
||||
|
||||
public static class StrengthenTopBean {
|
||||
/**
|
||||
* atk : 625
|
||||
* torpedo : 0
|
||||
* air_def : 750
|
||||
* def : 375
|
||||
*/
|
||||
|
||||
private int atk;
|
||||
private int torpedo;
|
||||
private int air_def;
|
||||
private int def;
|
||||
|
||||
public int getAtk() {
|
||||
return atk;
|
||||
}
|
||||
|
||||
public void setAtk(int atk) {
|
||||
this.atk = atk;
|
||||
}
|
||||
|
||||
public int getTorpedo() {
|
||||
return torpedo;
|
||||
}
|
||||
|
||||
public void setTorpedo(int torpedo) {
|
||||
this.torpedo = torpedo;
|
||||
}
|
||||
|
||||
public int getAir_def() {
|
||||
return air_def;
|
||||
}
|
||||
|
||||
public void setAir_def(int air_def) {
|
||||
this.air_def = air_def;
|
||||
}
|
||||
|
||||
public int getDef() {
|
||||
return def;
|
||||
}
|
||||
|
||||
public void setDef(int def) {
|
||||
this.def = def;
|
||||
}
|
||||
}
|
||||
|
||||
public static class StrengthenSupplyExpBean {
|
||||
/**
|
||||
* atk : 73
|
||||
* torpedo : 0
|
||||
* air_def : 24
|
||||
* def : 65
|
||||
*/
|
||||
|
||||
private int atk;
|
||||
private int torpedo;
|
||||
private int air_def;
|
||||
private int def;
|
||||
|
||||
public int getAtk() {
|
||||
return atk;
|
||||
}
|
||||
|
||||
public void setAtk(int atk) {
|
||||
this.atk = atk;
|
||||
}
|
||||
|
||||
public int getTorpedo() {
|
||||
return torpedo;
|
||||
}
|
||||
|
||||
public void setTorpedo(int torpedo) {
|
||||
this.torpedo = torpedo;
|
||||
}
|
||||
|
||||
public int getAir_def() {
|
||||
return air_def;
|
||||
}
|
||||
|
||||
public void setAir_def(int air_def) {
|
||||
this.air_def = air_def;
|
||||
}
|
||||
|
||||
public int getDef() {
|
||||
return def;
|
||||
}
|
||||
|
||||
public void setDef(int def) {
|
||||
this.def = def;
|
||||
}
|
||||
}
|
||||
}
|
120
app/src/main/java/com/yutou/jianr_mg/Data/MAdConfig.java
Normal file
120
app/src/main/java/com/yutou/jianr_mg/Data/MAdConfig.java
Normal file
@ -0,0 +1,120 @@
|
||||
package com.yutou.jianr_mg.Data;
|
||||
|
||||
public class MAdConfig {
|
||||
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column m_ad_config.id
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column m_ad_config.appid
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
private String appid;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column m_ad_config.posId
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
private String posid;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column m_ad_config.adshow
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
private Integer adshow=0;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column m_ad_config.adtype
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
private Integer adtype;
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column m_ad_config.id
|
||||
* @return the value of m_ad_config.id
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column m_ad_config.id
|
||||
* @param id the value for m_ad_config.id
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column m_ad_config.appid
|
||||
* @return the value of m_ad_config.appid
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public String getAppid() {
|
||||
return appid;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column m_ad_config.appid
|
||||
* @param appid the value for m_ad_config.appid
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public void setAppid(String appid) {
|
||||
this.appid = appid;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column m_ad_config.posId
|
||||
* @return the value of m_ad_config.posId
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public String getPosid() {
|
||||
return posid;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column m_ad_config.posId
|
||||
* @param posid the value for m_ad_config.posId
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public void setPosid(String posid) {
|
||||
this.posid = posid;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column m_ad_config.adshow
|
||||
* @return the value of m_ad_config.adshow
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public Integer getAdshow() {
|
||||
return adshow;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column m_ad_config.adshow
|
||||
* @param adshow the value for m_ad_config.adshow
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public void setAdshow(Integer adshow) {
|
||||
this.adshow = adshow;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column m_ad_config.adtype
|
||||
* @return the value of m_ad_config.adtype
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public Integer getAdtype() {
|
||||
return adtype;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column m_ad_config.adtype
|
||||
* @param adtype the value for m_ad_config.adtype
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public void setAdtype(Integer adtype) {
|
||||
this.adtype = adtype;
|
||||
}
|
||||
}
|
168
app/src/main/java/com/yutou/jianr_mg/Data/MAdLog.java
Normal file
168
app/src/main/java/com/yutou/jianr_mg/Data/MAdLog.java
Normal file
@ -0,0 +1,168 @@
|
||||
package com.yutou.jianr_mg.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class MAdLog {
|
||||
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column m_ad_log.id
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column m_ad_log.adtype
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
private Integer adtype;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column m_ad_log.utype
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
private Integer utype;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column m_ad_log.uid
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
private Integer uid;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column m_ad_log.IP
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
private String ip;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column m_ad_log.IMEI
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
private String imei;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column m_ad_log.createTime
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
private Date createtime;
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column m_ad_log.id
|
||||
* @return the value of m_ad_log.id
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column m_ad_log.id
|
||||
* @param id the value for m_ad_log.id
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column m_ad_log.adtype
|
||||
* @return the value of m_ad_log.adtype
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
public Integer getAdtype() {
|
||||
return adtype;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column m_ad_log.adtype
|
||||
* @param adtype the value for m_ad_log.adtype
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
public void setAdtype(Integer adtype) {
|
||||
this.adtype = adtype;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column m_ad_log.utype
|
||||
* @return the value of m_ad_log.utype
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
public Integer getUtype() {
|
||||
return utype;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column m_ad_log.utype
|
||||
* @param utype the value for m_ad_log.utype
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
public void setUtype(Integer utype) {
|
||||
this.utype = utype;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column m_ad_log.uid
|
||||
* @return the value of m_ad_log.uid
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
public Integer getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column m_ad_log.uid
|
||||
* @param uid the value for m_ad_log.uid
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
public void setUid(Integer uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column m_ad_log.IP
|
||||
* @return the value of m_ad_log.IP
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column m_ad_log.IP
|
||||
* @param ip the value for m_ad_log.IP
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column m_ad_log.IMEI
|
||||
* @return the value of m_ad_log.IMEI
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
public String getImei() {
|
||||
return imei;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column m_ad_log.IMEI
|
||||
* @param imei the value for m_ad_log.IMEI
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
public void setImei(String imei) {
|
||||
this.imei = imei;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column m_ad_log.createTime
|
||||
* @return the value of m_ad_log.createTime
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
public Date getCreatetime() {
|
||||
return createtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column m_ad_log.createTime
|
||||
* @param createtime the value for m_ad_log.createTime
|
||||
* @mbg.generated Mon May 13 14:10:16 CST 2019
|
||||
*/
|
||||
public void setCreatetime(Date createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
}
|
@ -201,4 +201,29 @@ public class MAppTools {
|
||||
public void setParameter(String parameter) {
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("\"pluginName\":\"")
|
||||
.append(pluginName).append('\"');
|
||||
sb.append(",\"parameter\":\"")
|
||||
.append(parameter).append('\"');
|
||||
sb.append(",\"id\":")
|
||||
.append(id);
|
||||
sb.append(",\"name\":\"")
|
||||
.append(name).append('\"');
|
||||
sb.append(",\"image\":\"")
|
||||
.append(image).append('\"');
|
||||
sb.append(",\"url\":\"")
|
||||
.append(url).append('\"');
|
||||
sb.append(",\"mainFunction\":\"")
|
||||
.append(mainFunction).append('\"');
|
||||
sb.append(",\"permission\":")
|
||||
.append(permission);
|
||||
sb.append(",\"isshow\":")
|
||||
.append(isshow);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
391
app/src/main/java/com/yutou/jianr_mg/Data/ShipEquipmnt.java
Normal file
391
app/src/main/java/com/yutou/jianr_mg/Data/ShipEquipmnt.java
Normal file
@ -0,0 +1,391 @@
|
||||
package com.yutou.jianr_mg.Data;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ShipEquipmnt {
|
||||
private int cid;
|
||||
private int star;
|
||||
private String title;
|
||||
private String country;
|
||||
private int type;
|
||||
private String hp;
|
||||
private int atk;
|
||||
private String def;
|
||||
private String torpedo;
|
||||
private String antisub;
|
||||
private String radar;
|
||||
private String hit;
|
||||
private int range;
|
||||
private String miss;
|
||||
private String luck;
|
||||
private String correction;
|
||||
private String effect;
|
||||
private DismantleBean dismantle;
|
||||
private String author;
|
||||
private String desc;
|
||||
private String desc2;
|
||||
private String equipIndex;
|
||||
private int picId;
|
||||
private int boreType;
|
||||
private String handbookType;
|
||||
private String aircraftAtk;
|
||||
private String missileTmd;
|
||||
private String missileHit;
|
||||
private String airDef;
|
||||
private int airDefRate;
|
||||
private String airDefCorrect;
|
||||
private String missleDefModulus;
|
||||
private String shipCid;
|
||||
private String shipCountry;
|
||||
private String specialEffect;
|
||||
private String aluminiumUse;
|
||||
private List<Integer> shipType;
|
||||
|
||||
public int getCid() {
|
||||
return cid;
|
||||
}
|
||||
|
||||
public void setCid(int cid) {
|
||||
this.cid = cid;
|
||||
}
|
||||
|
||||
public int getStar() {
|
||||
return star;
|
||||
}
|
||||
|
||||
public void setStar(int star) {
|
||||
this.star = star;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getHp() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
public void setHp(String hp) {
|
||||
this.hp = hp;
|
||||
}
|
||||
|
||||
public int getAtk() {
|
||||
return atk;
|
||||
}
|
||||
|
||||
public void setAtk(int atk) {
|
||||
this.atk = atk;
|
||||
}
|
||||
|
||||
public String getDef() {
|
||||
return def;
|
||||
}
|
||||
|
||||
public void setDef(String def) {
|
||||
this.def = def;
|
||||
}
|
||||
|
||||
public String getTorpedo() {
|
||||
return torpedo;
|
||||
}
|
||||
|
||||
public void setTorpedo(String torpedo) {
|
||||
this.torpedo = torpedo;
|
||||
}
|
||||
|
||||
public String getAntisub() {
|
||||
return antisub;
|
||||
}
|
||||
|
||||
public void setAntisub(String antisub) {
|
||||
this.antisub = antisub;
|
||||
}
|
||||
|
||||
public String getRadar() {
|
||||
return radar;
|
||||
}
|
||||
|
||||
public void setRadar(String radar) {
|
||||
this.radar = radar;
|
||||
}
|
||||
|
||||
public String getHit() {
|
||||
return hit;
|
||||
}
|
||||
|
||||
public void setHit(String hit) {
|
||||
this.hit = hit;
|
||||
}
|
||||
|
||||
public int getRange() {
|
||||
return range;
|
||||
}
|
||||
|
||||
public void setRange(int range) {
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
public String getMiss() {
|
||||
return miss;
|
||||
}
|
||||
|
||||
public void setMiss(String miss) {
|
||||
this.miss = miss;
|
||||
}
|
||||
|
||||
public String getLuck() {
|
||||
return luck;
|
||||
}
|
||||
|
||||
public void setLuck(String luck) {
|
||||
this.luck = luck;
|
||||
}
|
||||
|
||||
public String getCorrection() {
|
||||
return correction;
|
||||
}
|
||||
|
||||
public void setCorrection(String correction) {
|
||||
this.correction = correction;
|
||||
}
|
||||
|
||||
public String getEffect() {
|
||||
return effect;
|
||||
}
|
||||
|
||||
public void setEffect(String effect) {
|
||||
this.effect = effect;
|
||||
}
|
||||
|
||||
public DismantleBean getDismantle() {
|
||||
return dismantle;
|
||||
}
|
||||
|
||||
public void setDismantle(DismantleBean dismantle) {
|
||||
this.dismantle = dismantle;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getDesc2() {
|
||||
return desc2;
|
||||
}
|
||||
|
||||
public void setDesc2(String desc2) {
|
||||
this.desc2 = desc2;
|
||||
}
|
||||
|
||||
public String getEquipIndex() {
|
||||
return equipIndex;
|
||||
}
|
||||
|
||||
public void setEquipIndex(String equipIndex) {
|
||||
this.equipIndex = equipIndex;
|
||||
}
|
||||
|
||||
public int getPicId() {
|
||||
return picId;
|
||||
}
|
||||
|
||||
public void setPicId(int picId) {
|
||||
this.picId = picId;
|
||||
}
|
||||
|
||||
public int getBoreType() {
|
||||
return boreType;
|
||||
}
|
||||
|
||||
public void setBoreType(int boreType) {
|
||||
this.boreType = boreType;
|
||||
}
|
||||
|
||||
public String getHandbookType() {
|
||||
return handbookType;
|
||||
}
|
||||
|
||||
public void setHandbookType(String handbookType) {
|
||||
this.handbookType = handbookType;
|
||||
}
|
||||
|
||||
public String getAircraftAtk() {
|
||||
return aircraftAtk;
|
||||
}
|
||||
|
||||
public void setAircraftAtk(String aircraftAtk) {
|
||||
this.aircraftAtk = aircraftAtk;
|
||||
}
|
||||
|
||||
public String getMissileTmd() {
|
||||
return missileTmd;
|
||||
}
|
||||
|
||||
public void setMissileTmd(String missileTmd) {
|
||||
this.missileTmd = missileTmd;
|
||||
}
|
||||
|
||||
public String getMissileHit() {
|
||||
return missileHit;
|
||||
}
|
||||
|
||||
public void setMissileHit(String missileHit) {
|
||||
this.missileHit = missileHit;
|
||||
}
|
||||
|
||||
public String getAirDef() {
|
||||
return airDef;
|
||||
}
|
||||
|
||||
public void setAirDef(String airDef) {
|
||||
this.airDef = airDef;
|
||||
}
|
||||
|
||||
public int getAirDefRate() {
|
||||
return airDefRate;
|
||||
}
|
||||
|
||||
public void setAirDefRate(int airDefRate) {
|
||||
this.airDefRate = airDefRate;
|
||||
}
|
||||
|
||||
public String getAirDefCorrect() {
|
||||
return airDefCorrect;
|
||||
}
|
||||
|
||||
public void setAirDefCorrect(String airDefCorrect) {
|
||||
this.airDefCorrect = airDefCorrect;
|
||||
}
|
||||
|
||||
public String getMissleDefModulus() {
|
||||
return missleDefModulus;
|
||||
}
|
||||
|
||||
public void setMissleDefModulus(String missleDefModulus) {
|
||||
this.missleDefModulus = missleDefModulus;
|
||||
}
|
||||
|
||||
public String getShipCid() {
|
||||
return shipCid;
|
||||
}
|
||||
|
||||
public void setShipCid(String shipCid) {
|
||||
this.shipCid = shipCid;
|
||||
}
|
||||
|
||||
public String getShipCountry() {
|
||||
return shipCountry;
|
||||
}
|
||||
|
||||
public void setShipCountry(String shipCountry) {
|
||||
this.shipCountry = shipCountry;
|
||||
}
|
||||
|
||||
public String getSpecialEffect() {
|
||||
return specialEffect;
|
||||
}
|
||||
|
||||
public void setSpecialEffect(String specialEffect) {
|
||||
this.specialEffect = specialEffect;
|
||||
}
|
||||
|
||||
public String getAluminiumUse() {
|
||||
return aluminiumUse;
|
||||
}
|
||||
|
||||
public void setAluminiumUse(String aluminiumUse) {
|
||||
this.aluminiumUse = aluminiumUse;
|
||||
}
|
||||
|
||||
public List<Integer> getShipType() {
|
||||
return shipType;
|
||||
}
|
||||
|
||||
public void setShipType(List<Integer> shipType) {
|
||||
this.shipType = shipType;
|
||||
}
|
||||
|
||||
public static class DismantleBean {
|
||||
/**
|
||||
* 2 : 0
|
||||
* 3 : 5
|
||||
* 4 : 5
|
||||
* 9 : 0
|
||||
*/
|
||||
|
||||
@JSONField(name = "2")
|
||||
private int _$2;
|
||||
@JSONField(name = "3")
|
||||
private int _$3;
|
||||
@JSONField(name = "4")
|
||||
private int _$4;
|
||||
@JSONField(name = "9")
|
||||
private int _$9;
|
||||
|
||||
public int get_$2() {
|
||||
return _$2;
|
||||
}
|
||||
|
||||
public void set_$2(int _$2) {
|
||||
this._$2 = _$2;
|
||||
}
|
||||
|
||||
public int get_$3() {
|
||||
return _$3;
|
||||
}
|
||||
|
||||
public void set_$3(int _$3) {
|
||||
this._$3 = _$3;
|
||||
}
|
||||
|
||||
public int get_$4() {
|
||||
return _$4;
|
||||
}
|
||||
|
||||
public void set_$4(int _$4) {
|
||||
this._$4 = _$4;
|
||||
}
|
||||
|
||||
public int get_$9() {
|
||||
return _$9;
|
||||
}
|
||||
|
||||
public void set_$9(int _$9) {
|
||||
this._$9 = _$9;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,8 +3,13 @@ package com.yutou.jianr_mg.Data;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.SplittableRandom;
|
||||
|
||||
public class TeamData {
|
||||
private int id;
|
||||
private int jid;
|
||||
private int type;
|
||||
private String title;
|
||||
private String hp;
|
||||
private String hpMax;
|
||||
@ -13,14 +18,64 @@ public class TeamData {
|
||||
private String item2Url;
|
||||
private String item3Url;
|
||||
private String item4Url;
|
||||
private List<String> equipments;
|
||||
private boolean user;
|
||||
private JSONObject src;
|
||||
private long createTime;
|
||||
|
||||
public int getJid() {
|
||||
return jid;
|
||||
}
|
||||
|
||||
public void setJid(int jid) {
|
||||
this.jid = jid;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public TeamData() {
|
||||
createTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("\"id\":")
|
||||
.append(id);
|
||||
sb.append(",\"jid\":")
|
||||
.append(jid);
|
||||
sb.append(",\"title\":\"")
|
||||
.append(title).append('\"');
|
||||
sb.append(",\"hp\":\"")
|
||||
.append(hp).append('\"');
|
||||
sb.append(",\"hpMax\":\"")
|
||||
.append(hpMax).append('\"');
|
||||
sb.append(",\"imageUrl\":\"")
|
||||
.append(imageUrl).append('\"');
|
||||
sb.append(",\"item1Url\":\"")
|
||||
.append(item1Url).append('\"');
|
||||
sb.append(",\"item2Url\":\"")
|
||||
.append(item2Url).append('\"');
|
||||
sb.append(",\"item3Url\":\"")
|
||||
.append(item3Url).append('\"');
|
||||
sb.append(",\"item4Url\":\"")
|
||||
.append(item4Url).append('\"');
|
||||
sb.append(",\"user\":")
|
||||
.append(user);
|
||||
sb.append(",\"src\":")
|
||||
.append(src);
|
||||
sb.append(",\"createTime\":")
|
||||
.append(createTime);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
@ -105,6 +160,14 @@ public class TeamData {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public List<String> getEquipments() {
|
||||
return equipments;
|
||||
}
|
||||
|
||||
public void setEquipments(List<String> equipments) {
|
||||
this.equipments = equipments;
|
||||
}
|
||||
|
||||
public JSONObject getSrc() {
|
||||
try {
|
||||
if (src != null)
|
||||
@ -119,34 +182,4 @@ public class TeamData {
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("\"id\":")
|
||||
.append(id);
|
||||
sb.append(",\"title\":\"")
|
||||
.append(title).append('\"');
|
||||
sb.append(",\"hp\":\"")
|
||||
.append(hp).append('\"');
|
||||
sb.append(",\"hpMax\":\"")
|
||||
.append(hpMax).append('\"');
|
||||
sb.append(",\"imageUrl\":\"")
|
||||
.append(imageUrl).append('\"');
|
||||
sb.append(",\"item1Url\":\"")
|
||||
.append(item1Url).append('\"');
|
||||
sb.append(",\"item2Url\":\"")
|
||||
.append(item2Url).append('\"');
|
||||
sb.append(",\"item3Url\":\"")
|
||||
.append(item3Url).append('\"');
|
||||
sb.append(",\"item4Url\":\"")
|
||||
.append(item4Url).append('\"');
|
||||
sb.append(",\"user\":")
|
||||
.append(user);
|
||||
sb.append(",\"src\":")
|
||||
.append(src);
|
||||
sb.append(",\"createTime\":")
|
||||
.append(createTime);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,41 +1,64 @@
|
||||
package com.yutou.jianr_mg.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class UUserdata {
|
||||
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column u_userdata.id
|
||||
* @mbg.generated Sun Jan 21 18:14:28 CST 2018
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column u_userdata.uid
|
||||
* @mbg.generated Sun Jan 21 18:14:28 CST 2018
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
private Integer uid;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column u_userdata.email
|
||||
* @mbg.generated Sun Jan 21 18:14:28 CST 2018
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
private String email;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column u_userdata.createTime
|
||||
* @mbg.generated Sun Jan 21 18:14:28 CST 2018
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
private Long createtime;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column u_userdata.image
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
private String image;
|
||||
|
||||
public String getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(String image) {
|
||||
this.image = image;
|
||||
}
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column u_userdata.beanTime
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
private Date beantime;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column u_userdata.unBeanTime
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
private Date unbeantime;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column u_userdata.beanIndex
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
private Integer beanindex;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column u_userdata.credit
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
private Integer credit;
|
||||
/**
|
||||
* This field was generated by MyBatis Generator. This field corresponds to the database column u_userdata.loginTime
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
private Date logintime;
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column u_userdata.id
|
||||
* @return the value of u_userdata.id
|
||||
* @mbg.generated Sun Jan 21 18:14:28 CST 2018
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public Integer getId() {
|
||||
return id;
|
||||
@ -44,7 +67,7 @@ public class UUserdata {
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column u_userdata.id
|
||||
* @param id the value for u_userdata.id
|
||||
* @mbg.generated Sun Jan 21 18:14:28 CST 2018
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
@ -53,7 +76,7 @@ public class UUserdata {
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column u_userdata.uid
|
||||
* @return the value of u_userdata.uid
|
||||
* @mbg.generated Sun Jan 21 18:14:28 CST 2018
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public Integer getUid() {
|
||||
return uid;
|
||||
@ -62,7 +85,7 @@ public class UUserdata {
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column u_userdata.uid
|
||||
* @param uid the value for u_userdata.uid
|
||||
* @mbg.generated Sun Jan 21 18:14:28 CST 2018
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public void setUid(Integer uid) {
|
||||
this.uid = uid;
|
||||
@ -71,7 +94,7 @@ public class UUserdata {
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column u_userdata.email
|
||||
* @return the value of u_userdata.email
|
||||
* @mbg.generated Sun Jan 21 18:14:28 CST 2018
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public String getEmail() {
|
||||
return email;
|
||||
@ -80,7 +103,7 @@ public class UUserdata {
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column u_userdata.email
|
||||
* @param email the value for u_userdata.email
|
||||
* @mbg.generated Sun Jan 21 18:14:28 CST 2018
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
@ -89,7 +112,7 @@ public class UUserdata {
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column u_userdata.createTime
|
||||
* @return the value of u_userdata.createTime
|
||||
* @mbg.generated Sun Jan 21 18:14:28 CST 2018
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public Long getCreatetime() {
|
||||
return createtime;
|
||||
@ -98,9 +121,117 @@ public class UUserdata {
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column u_userdata.createTime
|
||||
* @param createtime the value for u_userdata.createTime
|
||||
* @mbg.generated Sun Jan 21 18:14:28 CST 2018
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public void setCreatetime(Long createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column u_userdata.image
|
||||
* @return the value of u_userdata.image
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public String getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column u_userdata.image
|
||||
* @param image the value for u_userdata.image
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public void setImage(String image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column u_userdata.beanTime
|
||||
* @return the value of u_userdata.beanTime
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public Date getBeantime() {
|
||||
return beantime;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column u_userdata.beanTime
|
||||
* @param beantime the value for u_userdata.beanTime
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public void setBeantime(Date beantime) {
|
||||
this.beantime = beantime;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column u_userdata.unBeanTime
|
||||
* @return the value of u_userdata.unBeanTime
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public Date getUnbeantime() {
|
||||
return unbeantime;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column u_userdata.unBeanTime
|
||||
* @param unbeantime the value for u_userdata.unBeanTime
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public void setUnbeantime(Date unbeantime) {
|
||||
this.unbeantime = unbeantime;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column u_userdata.beanIndex
|
||||
* @return the value of u_userdata.beanIndex
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public Integer getBeanindex() {
|
||||
return beanindex;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column u_userdata.beanIndex
|
||||
* @param beanindex the value for u_userdata.beanIndex
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public void setBeanindex(Integer beanindex) {
|
||||
this.beanindex = beanindex;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column u_userdata.credit
|
||||
* @return the value of u_userdata.credit
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public Integer getCredit() {
|
||||
return credit;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column u_userdata.credit
|
||||
* @param credit the value for u_userdata.credit
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public void setCredit(Integer credit) {
|
||||
this.credit = credit;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method returns the value of the database column u_userdata.loginTime
|
||||
* @return the value of u_userdata.loginTime
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public Date getLogintime() {
|
||||
return logintime;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator. This method sets the value of the database column u_userdata.loginTime
|
||||
* @param logintime the value for u_userdata.loginTime
|
||||
* @mbg.generated Mon May 13 14:48:33 CST 2019
|
||||
*/
|
||||
public void setLogintime(Date logintime) {
|
||||
this.logintime = logintime;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class DaytimeFragment extends Fragment {
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
public class NightFragment extends Fragment {
|
||||
}
|
@ -45,9 +45,9 @@ public class My extends Fragment {
|
||||
private View view;
|
||||
private User user;
|
||||
private UUserdata udata;
|
||||
private TextView uname,item_title;
|
||||
private TextView uname,item_title,credit;
|
||||
private ImageView icon,item_icon,image_top;
|
||||
// private LinearLayout items;
|
||||
private LinearLayout items;
|
||||
private ListView myItems;
|
||||
|
||||
private static My my;
|
||||
@ -66,8 +66,9 @@ public class My extends Fragment {
|
||||
item_title=view.findViewById(R.id.item_title);
|
||||
item_icon=view.findViewById(R.id.item_icon);
|
||||
image_top=view.findViewById(R.id.image_top);
|
||||
// items=view.findViewById(R.id.items);
|
||||
items=view.findViewById(R.id.items);
|
||||
myItems=view.findViewById(R.id._my_items);
|
||||
credit=view.findViewById(R.id.credit);
|
||||
}
|
||||
icon.setOnClickListener(view->{
|
||||
Utils.toast(getContext(),"个人资料...咕了!诶嘿(<ゝω·)~☆kira");
|
||||
@ -104,6 +105,7 @@ public class My extends Fragment {
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
credit.setText("积分:"+udata.getCredit());
|
||||
myItems.setAdapter(new MyItemGridViewAdapter(getItemData(),getContext()));
|
||||
}
|
||||
private List<MyItemGridViewAdapter.ItemData> getItemData(){
|
||||
|
@ -31,6 +31,7 @@ import com.qq.e.comm.util.AdError;
|
||||
import com.umeng.analytics.MobclickAgent;
|
||||
import com.umeng.message.UmengMessageHandler;
|
||||
import com.yutou.jianr_mg.Data.AppData;
|
||||
import com.yutou.jianr_mg.Data.MAdConfig;
|
||||
import com.yutou.jianr_mg.Data.MGamePackname;
|
||||
import com.yutou.jianr_mg.Data.SConfig;
|
||||
import com.yutou.jianr_mg.Data.UUserdata;
|
||||
@ -40,6 +41,7 @@ import com.yutou.jianr_mg.Interfaces.HttpInterface;
|
||||
import com.yutou.jianr_mg.Network.HttpApi;
|
||||
import com.yutou.jianr_mg.Network.HttpUtils;
|
||||
import com.yutou.jianr_mg.Tools.ActivitysManager;
|
||||
import com.yutou.jianr_mg.Tools.AdTools;
|
||||
import com.yutou.jianr_mg.Tools.AppPermissions;
|
||||
import com.yutou.jianr_mg.Tools.ConfigUtils;
|
||||
import com.yutou.jianr_mg.Tools.Log;
|
||||
@ -59,35 +61,36 @@ import me.drakeet.materialdialog.MaterialDialog;
|
||||
*/
|
||||
|
||||
public class LoadingActivity extends AppCompatActivity {
|
||||
private static final String APPID = "1105310947";
|
||||
private static final String POSID = "7090537892072921";
|
||||
public static String url=null;
|
||||
// private static final String APPID = "1105310947";
|
||||
// private static final String POSID = "7090537892072921";
|
||||
public static String url = null;
|
||||
|
||||
private LinearLayout loginLayout,adLayout;
|
||||
private LinearLayout loginLayout, adLayout;
|
||||
private Button login, reg;
|
||||
private TextView notlogin, uname, password;
|
||||
private ImageView icon;
|
||||
private Handler handler;
|
||||
private boolean isLogin=false;
|
||||
private boolean isLogin = false;
|
||||
private Class clazz;
|
||||
private MAdConfig ad=new MAdConfig();
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,
|
||||
WindowManager.LayoutParams. FLAG_FULLSCREEN);
|
||||
AppData.debug=true;
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_loading);
|
||||
Utils.setImmersion(this);
|
||||
if(url==null){
|
||||
clazz=MainActivity.class;
|
||||
}else{
|
||||
clazz=WebActivity.class;
|
||||
if (url == null) {
|
||||
clazz = MainActivity.class;
|
||||
} else {
|
||||
clazz = WebActivity.class;
|
||||
}
|
||||
handler = new Handler();
|
||||
initViews();
|
||||
initData();
|
||||
startOpenAd();
|
||||
|
||||
initAd();
|
||||
}
|
||||
|
||||
private void login(String name, String pass) {
|
||||
@ -100,16 +103,16 @@ public class LoadingActivity extends AppCompatActivity {
|
||||
public void httpGetData(String string, int code) {
|
||||
try {
|
||||
JSONObject json = new JSONObject(string);
|
||||
final String msg=json.getString("msg");
|
||||
final String msg = json.getString("msg");
|
||||
if (json.getInt("code") == 100) {
|
||||
AppData.user = JSON.parseObject(json.getJSONObject("data").toString(), User.class);
|
||||
AppData.Token = json.getString("token");
|
||||
AppData.user.setToken(AppData.Token);
|
||||
UserDatabase.init().login(AppData.user.getId(),AppData.user.getName(),AppData.Token);
|
||||
isLogin=true;
|
||||
handler.post(()-> start());
|
||||
}else{
|
||||
handler.post(() -> Utils.toast(LoadingActivity.this,msg));
|
||||
UserDatabase.init().login(AppData.user.getId(), AppData.user.getName(), AppData.Token);
|
||||
isLogin = true;
|
||||
handler.post(() -> start());
|
||||
} else {
|
||||
handler.post(() -> Utils.toast(LoadingActivity.this, msg));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
@ -121,7 +124,7 @@ public class LoadingActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
e.printStackTrace();
|
||||
Utils.toast(LoadingActivity.this,"登录失败:"+e.getMessage());
|
||||
Utils.toast(LoadingActivity.this, "登录失败:" + e.getMessage());
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
@ -135,13 +138,14 @@ public class LoadingActivity extends AppCompatActivity {
|
||||
String fileName;
|
||||
switch (Build.CPU_ABI) {
|
||||
case "armeabi-v7a":
|
||||
fileName="busybox-armv7l";
|
||||
fileName = "busybox-armv7l";
|
||||
break;
|
||||
default: fileName="busybox-armv7l";
|
||||
default:
|
||||
fileName = "busybox-armv7l";
|
||||
}
|
||||
InputStream inputStream = manager.open(fileName);
|
||||
//jar.createNewFile();
|
||||
FileOutputStream outputStream = new FileOutputStream(getFilesDir()+"/busybox");
|
||||
FileOutputStream outputStream = new FileOutputStream(getFilesDir() + "/busybox");
|
||||
int len = 0;
|
||||
byte[] bytes = new byte[inputStream.available()];
|
||||
while ((len = inputStream.read(bytes)) != -1) {
|
||||
@ -150,14 +154,14 @@ public class LoadingActivity extends AppCompatActivity {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Utils.toast(this, Build.CPU_ABI);
|
||||
// Utils.toast(this, Build.CPU_ABI);
|
||||
initUser();
|
||||
initGamePackName();
|
||||
initConfig();
|
||||
initUser();
|
||||
if(Build.VERSION.SDK_INT<Build.VERSION_CODES.O){
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
ready(1);
|
||||
}else
|
||||
ActivityCompat.requestPermissions(this,AppPermissions.permissions,AppPermissions.REQUEST_CODE);
|
||||
} else
|
||||
ActivityCompat.requestPermissions(this, AppPermissions.permissions, AppPermissions.REQUEST_CODE);
|
||||
}
|
||||
|
||||
private void initConfig() {
|
||||
@ -179,7 +183,7 @@ public class LoadingActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
e.printStackTrace();
|
||||
Utils.toast(LoadingActivity.this,"初始化失败:"+e.getMessage());
|
||||
Utils.toast(LoadingActivity.this, "初始化失败:" + e.getMessage());
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
@ -221,33 +225,59 @@ public class LoadingActivity extends AppCompatActivity {
|
||||
public void httpGetData(String string, int code) {
|
||||
try {
|
||||
JSONObject json = new JSONObject(string);
|
||||
Log.i("LOGIN","登录状态:"+string);
|
||||
Log.i("LOGIN", "登录状态:" + string);
|
||||
if (json.getInt("code") == 100) {
|
||||
JSONObject data = json.getJSONObject("data").getJSONObject("data");
|
||||
AppData.user = JSON.parseObject(data.getJSONObject("user").toString(), User.class);
|
||||
AppData.userdata=JSON.parseObject(data.getJSONObject("userdata").toString(), UUserdata.class);
|
||||
AppData.userdata = JSON.parseObject(data.getJSONObject("userdata").toString(), UUserdata.class);
|
||||
ConfigUtils.init().save(ConfigUtils.collection, data.getJSONArray("collection"));
|
||||
isLogin=true;
|
||||
}else{
|
||||
isLogin=false;
|
||||
isLogin = true;
|
||||
} else {
|
||||
isLogin = false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ready(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
ready(1);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
start();
|
||||
}
|
||||
|
||||
}
|
||||
private void initAd(){
|
||||
try {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("type", 1);
|
||||
HttpUtils.post(HttpApi.HOME_URL + HttpApi.AD_GET, json, new HttpInterface() {
|
||||
@Override
|
||||
public void httpGetData(String string, int code) {
|
||||
try {
|
||||
JSONObject json = new JSONObject(string);
|
||||
if (json.getInt("code") == 100) {
|
||||
ad = JSON.parseObject(json.getJSONObject("data").toString(), MAdConfig.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
AppData.handler.post(()->startOpenAd());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
handler.post(()->start());
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
start();
|
||||
}
|
||||
}
|
||||
private void initViews() {
|
||||
loginLayout = findViewById(R.id.loginLayout);
|
||||
login = findViewById(R.id.login);
|
||||
@ -256,14 +286,14 @@ public class LoadingActivity extends AppCompatActivity {
|
||||
uname = findViewById(R.id.uname);
|
||||
password = findViewById(R.id.password);
|
||||
adLayout = findViewById(R.id.adLayout);
|
||||
reg=findViewById(R.id.reg);
|
||||
reg = findViewById(R.id.reg);
|
||||
|
||||
|
||||
Intent regIntent=getIntent();
|
||||
if(regIntent!=null){
|
||||
String name=regIntent.getStringExtra("name");
|
||||
String pass=regIntent.getStringExtra("password");
|
||||
if(!Utils.testStringIsNull(name,pass)){
|
||||
Intent regIntent = getIntent();
|
||||
if (regIntent != null) {
|
||||
String name = regIntent.getStringExtra("name");
|
||||
String pass = regIntent.getStringExtra("password");
|
||||
if (!Utils.testStringIsNull(name, pass)) {
|
||||
uname.setText(name);
|
||||
password.setText(pass);
|
||||
login.callOnClick();
|
||||
@ -281,7 +311,7 @@ public class LoadingActivity extends AppCompatActivity {
|
||||
login(name, pass);
|
||||
});
|
||||
reg.setOnClickListener(view -> {
|
||||
Intent intent=new Intent(LoadingActivity.this, RegisterActivity.class);
|
||||
Intent intent = new Intent(LoadingActivity.this, RegisterActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
}
|
||||
@ -289,13 +319,13 @@ public class LoadingActivity extends AppCompatActivity {
|
||||
public void start() {
|
||||
adLayout.removeAllViews();
|
||||
adLayout.setVisibility(View.GONE);
|
||||
ConstraintLayout.LayoutParams params=new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
params.topMargin=Utils.getPixelsFromDp(this,512);
|
||||
params.startToStart=Utils.getPixelsFromDp(this,8);
|
||||
params.startToEnd=Utils.getPixelsFromDp(this,8);
|
||||
// icon.setLayoutParams(params);
|
||||
if(true){
|
||||
// return;
|
||||
ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
params.topMargin = Utils.getPixelsFromDp(this, 512);
|
||||
params.startToStart = Utils.getPixelsFromDp(this, 8);
|
||||
params.startToEnd = Utils.getPixelsFromDp(this, 8);
|
||||
// icon.setLayoutParams(params);
|
||||
if (true) {
|
||||
// return;
|
||||
}
|
||||
|
||||
PackageManager manager = getPackageManager();
|
||||
@ -307,25 +337,25 @@ public class LoadingActivity extends AppCompatActivity {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(AppData.appConfig!=null&&!AppData.appConfig.getApkVersion().equals(code)){
|
||||
MaterialDialog dialog=new MaterialDialog(this);
|
||||
if (AppData.appConfig != null && !AppData.appConfig.getApkVersion().equals(code)) {
|
||||
MaterialDialog dialog = new MaterialDialog(this);
|
||||
dialog.setTitle("检测到更新");
|
||||
dialog.setMessage(AppData.appConfig.getMessage());
|
||||
dialog.setNegativeButton("放弃",v -> {
|
||||
dialog.setNegativeButton("放弃", v -> {
|
||||
dialog.dismiss();
|
||||
if(isLogin) {
|
||||
if (isLogin) {
|
||||
Intent intent = new Intent(LoadingActivity.this, clazz);
|
||||
if(url!=null){
|
||||
intent.putExtra("url",url);
|
||||
if (url != null) {
|
||||
intent.putExtra("url", url);
|
||||
}
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}else{
|
||||
Utils.toast(this,"未登录/登录信息失效");
|
||||
finish();
|
||||
} else {
|
||||
Utils.toast(this, "未登录/登录信息失效");
|
||||
showLogin();
|
||||
}
|
||||
});
|
||||
dialog.setPositiveButton("升级",v -> {
|
||||
dialog.setPositiveButton("升级", v -> {
|
||||
dialog.dismiss();
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
@ -335,16 +365,16 @@ public class LoadingActivity extends AppCompatActivity {
|
||||
});
|
||||
dialog.show();
|
||||
|
||||
}else{
|
||||
if(isLogin) {
|
||||
} else {
|
||||
if (isLogin) {
|
||||
Intent intent = new Intent(LoadingActivity.this, clazz);
|
||||
if(url!=null){
|
||||
intent.putExtra("url",url);
|
||||
if (url != null) {
|
||||
intent.putExtra("url", url);
|
||||
}
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}else{
|
||||
Utils.toast(this,"未登录/登录信息失效");
|
||||
} else {
|
||||
Utils.toast(this, "未登录/登录信息失效");
|
||||
showLogin();
|
||||
}
|
||||
}
|
||||
@ -397,35 +427,44 @@ public class LoadingActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
boolean flag=true;
|
||||
if(requestCode==AppPermissions.REQUEST_CODE){
|
||||
boolean flag = true;
|
||||
if (requestCode == AppPermissions.REQUEST_CODE) {
|
||||
for (String permission : AppPermissions.permissions) {
|
||||
if(ActivityCompat.checkSelfPermission(this,permission)!=PackageManager.PERMISSION_GRANTED){
|
||||
if (ActivityCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
|
||||
System.out.println(permission);
|
||||
flag=false;
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!flag){
|
||||
MaterialDialog dialog=new MaterialDialog(this);
|
||||
if (!flag) {
|
||||
MaterialDialog dialog = new MaterialDialog(this);
|
||||
dialog.setTitle(">__<");
|
||||
dialog.setMessage("缺少起床的必要权限哦!");
|
||||
dialog.setNegativeButton("不给", view -> {
|
||||
Utils.toast(LoadingActivity.this,"哼,小气");
|
||||
handler.postDelayed(()-> {ActivitysManager.AppExit(LoadingActivity.this);dialog.dismiss();},300);
|
||||
Utils.toast(LoadingActivity.this, "哼,小气");
|
||||
handler.postDelayed(() -> {
|
||||
ActivitysManager.AppExit(LoadingActivity.this);
|
||||
dialog.dismiss();
|
||||
}, 300);
|
||||
});
|
||||
dialog.setPositiveButton("拿去吧",view->{
|
||||
ActivityCompat.requestPermissions(LoadingActivity.this,AppPermissions.permissions,AppPermissions.REQUEST_CODE);
|
||||
dialog.setPositiveButton("拿去吧", view -> {
|
||||
ActivityCompat.requestPermissions(LoadingActivity.this, AppPermissions.permissions, AppPermissions.REQUEST_CODE);
|
||||
dialog.dismiss();
|
||||
});
|
||||
dialog.show();
|
||||
}else{
|
||||
} else {
|
||||
ready(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void startOpenAd(){
|
||||
new SplashAD(this, adLayout, APPID, POSID, new SplashADListener() {
|
||||
|
||||
private void startOpenAd() {
|
||||
if(ad.getAdshow()!=1){
|
||||
start();
|
||||
return;
|
||||
}
|
||||
AdTools.upload(AdTools.Open,AdTools.req);
|
||||
new SplashAD(this, adLayout, ad.getAppid(), ad.getPosid(), new SplashADListener() {
|
||||
@Override
|
||||
public void onADDismissed() {
|
||||
start();
|
||||
@ -433,7 +472,7 @@ public class LoadingActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onNoAD(AdError adError) {
|
||||
handler.postDelayed(()->start(),3000);
|
||||
handler.postDelayed(() -> start(), 3000);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -443,7 +482,7 @@ public class LoadingActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onADClicked() {
|
||||
|
||||
AdTools.upload(AdTools.Open,AdTools.click);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -453,11 +492,12 @@ public class LoadingActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onADExposure() {
|
||||
|
||||
AdTools.upload(AdTools.Open,AdTools.show);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
@ -17,6 +17,7 @@ import com.yutou.jianr_mg.Fragments.MGList;
|
||||
import com.yutou.jianr_mg.Fragments.My;
|
||||
import com.yutou.jianr_mg.Fragments.UtilsFragments;
|
||||
import com.yutou.jianr_mg.Tools.ActivitysManager;
|
||||
import com.yutou.jianr_mg.Tools.JianRUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -39,7 +40,11 @@ public class MainActivity extends AppCompatActivity {
|
||||
AppData.handler=new Handler();
|
||||
ActivitysManager.finishActivity(LoadingActivity.class);
|
||||
initViews();
|
||||
|
||||
JianRUtils.downlaodInit(true);
|
||||
new Thread(()->{
|
||||
JianRUtils.reloadJianNiang();
|
||||
JianRUtils.reloadEquipmnts();
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
|
@ -6,9 +6,9 @@ package com.yutou.jianr_mg.Network;
|
||||
|
||||
public class HttpApi {
|
||||
public static final String HOME="http://jianr.jianrmod.cn/";
|
||||
//public static final String HOME = "http://192.168.31.241:8088/"; //zzz_gz wifi
|
||||
// public static final String HOME = "http://192.168.31.240:8088/"; //zzz_gz wifi
|
||||
//public static final String HOME = "http://192.168.137.1:8088/"; //笔记本本身WIFI
|
||||
// public static final String HOME = "http://192.168.1.84:8088/"; //公司
|
||||
// public static final String HOME = "http://192.168.1.84:8088/"; //公司
|
||||
public static final String HOME_URL=HOME+"android/"; //服务器
|
||||
|
||||
public static final String MOD_ALL = "mod/all.do";
|
||||
@ -45,6 +45,12 @@ public class HttpApi {
|
||||
|
||||
public static final String INSTALL_PATH = "config/installPath.do";
|
||||
|
||||
public static final String DATA_UP_GAMEDATA="data/upGameData.do";
|
||||
public static final String DATA_DOWN_GAMEDATA="data/downGameData.do";
|
||||
|
||||
public static final String AD_GET="ad/ad.do";
|
||||
public static final String AD_LOG="ad/user.do";
|
||||
|
||||
|
||||
public static final String HITOKOTO_API = "https://v1.hitokoto.cn/";
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.yutou.jianr_mg.Network;
|
||||
|
||||
|
||||
|
||||
import com.yutou.jianr_mg.Data.AppData;
|
||||
import com.yutou.jianr_mg.Interfaces.DownloadFileInerface;
|
||||
import com.yutou.jianr_mg.Interfaces.HttpInterface;
|
||||
import com.yutou.jianr_mg.Tools.Log;
|
||||
import com.yutou.jianr_mg.Tools.Utils;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@ -30,15 +30,17 @@ import okhttp3.Response;
|
||||
|
||||
public class HttpUtils {
|
||||
private static OkHttpClient client;
|
||||
private static OkHttpClient getClient(){
|
||||
return new OkHttpClient.Builder()
|
||||
.connectTimeout(3000, TimeUnit.SECONDS)
|
||||
.readTimeout(3000,TimeUnit.SECONDS).build();
|
||||
|
||||
private static OkHttpClient getClient() {
|
||||
return new OkHttpClient.Builder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.readTimeout(30, TimeUnit.SECONDS).build();
|
||||
|
||||
}
|
||||
public static void get(final String url, final HttpInterface httpInterface) {
|
||||
if(client==null){
|
||||
client=getClient();
|
||||
|
||||
public static void get(final String url, final HttpInterface httpInterface) {
|
||||
if (client == null) {
|
||||
client = getClient();
|
||||
}
|
||||
Request request = new Request.Builder().url(url).build();
|
||||
Call call = client.newCall(request);
|
||||
@ -49,13 +51,13 @@ public class HttpUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) {
|
||||
public void onResponse(Call call, Response response) {
|
||||
try {
|
||||
String http=response.body().string();
|
||||
if(httpInterface!=null)
|
||||
String http = response.body().string();
|
||||
if (httpInterface != null)
|
||||
httpInterface.httpGetData(http, response.code());
|
||||
Log.i(url,"传参:"+url.replace(HttpApi.HOME_URL,"")+" 接收:"+http);
|
||||
}catch (Exception e){
|
||||
Log.i(url, "传参:" + url.replace(HttpApi.HOME_URL, "") + " 接收:" + http);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -63,8 +65,8 @@ public class HttpUtils {
|
||||
}
|
||||
|
||||
public static void post(final String url, final JSONObject json, final HttpInterface httpInterface) {
|
||||
if(client==null){
|
||||
client=getClient();
|
||||
if (client == null) {
|
||||
client = getClient();
|
||||
}
|
||||
Request request = new Request.Builder().url(url).post(mapToBody(json)).removeHeader("User-Agent").build();
|
||||
Call call = client.newCall(request);
|
||||
@ -72,47 +74,51 @@ public class HttpUtils {
|
||||
call.enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
if(httpInterface!=null)
|
||||
if (httpInterface != null)
|
||||
httpInterface.httpError(e);
|
||||
e.printStackTrace();
|
||||
Log.e(e,HttpUtils.class);
|
||||
Log.e(e, HttpUtils.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) {
|
||||
try {
|
||||
String http=response.body().string();
|
||||
if(httpInterface!=null)
|
||||
String http = response.body().string();
|
||||
if (httpInterface != null)
|
||||
httpInterface.httpGetData(http, response.code());
|
||||
Log.i(url,"传参:"+json.toString()+" 接收:"+http);
|
||||
}catch (Exception e){
|
||||
Log.i(url, "传参:" + json.toString() + " 接收:" + http);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void downloadFile(final String url, final String srcPath, final DownloadFileInerface downloadFileInerface){
|
||||
if(client==null)
|
||||
client=getClient();
|
||||
File path=new File(srcPath);
|
||||
if(!path.exists())
|
||||
|
||||
public static void downloadFile(final String url, final String srcPath, final DownloadFileInerface downloadFileInerface) {
|
||||
if (client == null)
|
||||
client = getClient();
|
||||
File path = new File(srcPath);
|
||||
if (!path.exists())
|
||||
path.mkdirs();
|
||||
Request request=new Request.Builder().url(url).build();
|
||||
Request request = new Request.Builder().url(url).build();
|
||||
client.newCall(request).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
AppData.handler.post(()->downloadFileInerface.over(false));
|
||||
e.printStackTrace();
|
||||
AppData.handler.post(() -> downloadFileInerface.over(false));
|
||||
}
|
||||
boolean isflag=true;
|
||||
|
||||
boolean isflag = true;
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) {
|
||||
InputStream is = null;
|
||||
byte[] buf = new byte[1024];
|
||||
byte[] buf = new byte[1024];
|
||||
int len = 0;
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
@ -121,49 +127,50 @@ public class HttpUtils {
|
||||
File file = new File(srcPath, getNameFromUrl(url));
|
||||
fos = new FileOutputStream(file);
|
||||
long sum = 0;
|
||||
int pr=-1;
|
||||
int pr = -1;
|
||||
while ((len = is.read(buf)) != -1) {
|
||||
fos.write(buf, 0, len);
|
||||
sum += len;
|
||||
int progress = (int) (sum * 1.0f / total * 100);
|
||||
// 下载中
|
||||
if(progress==pr){
|
||||
isflag=false;
|
||||
}else{
|
||||
isflag=true;
|
||||
pr=progress;
|
||||
if (progress == pr) {
|
||||
isflag = false;
|
||||
} else {
|
||||
isflag = true;
|
||||
pr = progress;
|
||||
}
|
||||
if(progress==100){
|
||||
isflag=true;
|
||||
pr=progress;
|
||||
if (progress == 100) {
|
||||
isflag = true;
|
||||
pr = progress;
|
||||
}
|
||||
if(isflag)
|
||||
while (!downloadFileInerface.downloading(getNameFromUrl(url),progress,total)){
|
||||
Thread.sleep(10);
|
||||
}
|
||||
System.out.println("下载:"+progress);
|
||||
if (isflag)
|
||||
while (!downloadFileInerface.downloading(getNameFromUrl(url), progress, total)) {
|
||||
Thread.sleep(10);
|
||||
}
|
||||
System.out.println("下载:" + progress);
|
||||
}
|
||||
fos.flush();
|
||||
// 下载完成
|
||||
AppData.handler.post(()->downloadFileInerface.over(true));
|
||||
}catch (Exception e){
|
||||
AppData.handler.post(() -> downloadFileInerface.over(true));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
AppData.handler.post(()->downloadFileInerface.over(false));
|
||||
AppData.handler.post(() -> downloadFileInerface.over(false));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
private static String getNameFromUrl(String url) {
|
||||
|
||||
public static String getNameFromUrl(String url) {
|
||||
return url.substring(url.lastIndexOf("/") + 1);
|
||||
}
|
||||
|
||||
public static String getHtml(String url){
|
||||
Log.i("获取网页源码:"+url);
|
||||
if(client==null)
|
||||
client=getClient();
|
||||
Request request=new Request.Builder().url(url).build();
|
||||
public static String getHtml(String url) {
|
||||
Log.i("获取网页源码:" + url);
|
||||
if (client == null)
|
||||
client = getClient();
|
||||
Request request = new Request.Builder().url(url).build();
|
||||
try {
|
||||
Response response= client.newCall(request).execute();
|
||||
Response response = client.newCall(request).execute();
|
||||
return response.body().string();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -186,10 +193,14 @@ public class HttpUtils {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if(json.isNull("token"))
|
||||
builder.add("token", AppData.Token);
|
||||
if(json.isNull("uid"))
|
||||
builder.add("uid",AppData.user.getId()+"");
|
||||
if (json.isNull("token"))
|
||||
builder.add("token", AppData.Token);
|
||||
if (json.isNull("uid"))
|
||||
builder.add("uid", AppData.user.getId() + "");
|
||||
if (json.isNull("imei"))
|
||||
builder.add("imei", Utils.getIMEI());
|
||||
if (json.isNull("clientVersion"))
|
||||
builder.add("clientVersion", Utils.getVersion());
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
50
app/src/main/java/com/yutou/jianr_mg/Tools/AdTools.java
Normal file
50
app/src/main/java/com/yutou/jianr_mg/Tools/AdTools.java
Normal file
@ -0,0 +1,50 @@
|
||||
package com.yutou.jianr_mg.Tools;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.yutou.jianr_mg.Application;
|
||||
import com.yutou.jianr_mg.Data.AppData;
|
||||
import com.yutou.jianr_mg.Data.UUserdata;
|
||||
import com.yutou.jianr_mg.Interfaces.HttpInterface;
|
||||
import com.yutou.jianr_mg.Network.HttpApi;
|
||||
import com.yutou.jianr_mg.Network.HttpUtils;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class AdTools {
|
||||
public static int req=0,show=1,click=2;
|
||||
public static int Open=1,Inter=2,Banner=3,Native=4;
|
||||
public static void upload(int adType,int uType){
|
||||
try {
|
||||
JSONObject json=new JSONObject();
|
||||
json.put("adtype",adType);
|
||||
json.put("utype",uType);
|
||||
json.put("imei",Utils.getIMEI());
|
||||
HttpUtils.post(HttpApi.HOME_URL + HttpApi.AD_LOG, json, new HttpInterface() {
|
||||
@Override
|
||||
public void httpGetData(String string, int code) {
|
||||
try{
|
||||
JSONObject json=new JSONObject(string);
|
||||
if(json.getInt("code")==100){
|
||||
JSONObject data=json.getJSONObject("data");
|
||||
if(data.getInt("code")==100){
|
||||
Utils.toast(null,data.getString("msg"));
|
||||
}
|
||||
if(!data.isNull("user")){
|
||||
AppData.userdata= JSON.parseObject(data.getJSONObject("user").getJSONObject("data").getJSONObject("userdata").toString(), UUserdata.class);
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
|
||||
}
|
||||
});
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -7,5 +7,6 @@ public class AppPermissions {
|
||||
public static String[] permissions=new String[]{
|
||||
Manifest.permission.READ_PHONE_STATE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION
|
||||
};
|
||||
}
|
||||
|
60
app/src/main/java/com/yutou/jianr_mg/Tools/CDNTools.java
Normal file
60
app/src/main/java/com/yutou/jianr_mg/Tools/CDNTools.java
Normal file
@ -0,0 +1,60 @@
|
||||
package com.yutou.jianr_mg.Tools;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.kaopiz.kprogresshud.KProgressHUD;
|
||||
import com.qiniu.android.http.ResponseInfo;
|
||||
import com.qiniu.android.storage.Configuration;
|
||||
import com.qiniu.android.storage.UpCompletionHandler;
|
||||
import com.qiniu.android.storage.UpProgressHandler;
|
||||
import com.qiniu.android.storage.UploadManager;
|
||||
import com.qiniu.android.storage.UploadOptions;
|
||||
import com.yutou.jianr_mg.Application;
|
||||
import com.yutou.jianr_mg.Data.AppData;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CDNTools {
|
||||
private static CDNTools cdn;
|
||||
private UploadManager uploadManager;
|
||||
private KProgressHUD hud;
|
||||
private Context context;
|
||||
public static CDNTools getInstance(Context context){
|
||||
if(cdn==null){
|
||||
cdn=new CDNTools(context);
|
||||
}
|
||||
return cdn;
|
||||
}
|
||||
private CDNTools(Context context){
|
||||
this.context=context;
|
||||
init();
|
||||
}
|
||||
private void init(){
|
||||
Configuration config = new Configuration.Builder()
|
||||
.build();
|
||||
uploadManager = new UploadManager(config);
|
||||
}
|
||||
|
||||
public void upload(File file,String token){
|
||||
hud=Utils.showLoading(context,"正在上传","请稍后");
|
||||
hud.show();
|
||||
Map<String,String> map=new HashMap<>();
|
||||
map.put("x:uToken",AppData.Token);
|
||||
map.put("x:uuid",AppData.user.getId()+"");
|
||||
uploadManager.put(file, AppData.user.getId()+"/gamedata/"+file.getName(), token, (key, info, response) -> {
|
||||
if(info.isOK()){
|
||||
Log.i(cdn.getClass().getName(),key+"上传成功");
|
||||
Utils.toast(Application.application,"上传完成");
|
||||
}else{
|
||||
Log.i(cdn.getClass().getName(),"上传失败:"+info.error);
|
||||
}
|
||||
AppData.handler.post(()->hud.dismiss());
|
||||
},new UploadOptions(map, null, false, (key, percent) -> {
|
||||
hud.setDetailsLabel("正在上传:"+percent+"/"+file.length());
|
||||
},null));
|
||||
}
|
||||
}
|
@ -1,62 +1,276 @@
|
||||
package com.yutou.jianr_mg.Tools;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.yutou.jianr_mg.Application;
|
||||
import com.yutou.jianr_mg.Data.AppData;
|
||||
import com.yutou.jianr_mg.Data.JianNiang;
|
||||
import com.yutou.jianr_mg.Data.ShipEquipmnt;
|
||||
import com.yutou.jianr_mg.Data.TeamData;
|
||||
import com.yutou.jianr_mg.Interfaces.DownloadFileInerface;
|
||||
import com.yutou.jianr_mg.Network.HttpUtils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class JianRUtils {
|
||||
private static JSONArray shipCardId;
|
||||
public static int jianCidToid(String cid){
|
||||
if(cid.substring(1,2).equals("1")){
|
||||
int con=Integer.valueOf(cid.substring(2,cid.length()-2));
|
||||
return 1000+con;
|
||||
}else{
|
||||
return Integer.valueOf(cid.substring(2,cid.length()-2));
|
||||
|
||||
public static int jianCidToid(String cid) {
|
||||
if (cid.substring(1, 2).equals("1")) {
|
||||
int con = Integer.valueOf(cid.substring(2, cid.length() - 2));
|
||||
return 1000 + con;
|
||||
} else {
|
||||
return Integer.valueOf(cid.substring(2, cid.length() - 2));
|
||||
}
|
||||
}
|
||||
public static int equipCidToid(String cid){
|
||||
return Integer.valueOf(cid.substring(2))/100;
|
||||
|
||||
public static int equipCidToid(String cid) {
|
||||
return Integer.valueOf(cid.substring(2)) / 100;
|
||||
}
|
||||
public static int EnemyShipCardId(String cid){
|
||||
|
||||
public static int EnemyShipCardId(String cid) {
|
||||
try {
|
||||
for (int i = 0; i < shipCardId.length(); i++) {
|
||||
JSONObject json=shipCardId.getJSONObject(i);
|
||||
if(json.getString("cid").equals(cid)){
|
||||
JSONObject json = shipCardId.getJSONObject(i);
|
||||
if (json.getString("cid").equals(cid)) {
|
||||
return json.getInt("picId");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void initShipCardId() {
|
||||
try {
|
||||
File file = new File(Application.application.getFilesDir() + "/shipCardid");
|
||||
InputStream inputStream;
|
||||
if (!file.exists()) {
|
||||
inputStream = Application.application.getAssets().open("shipCardId");
|
||||
} else {
|
||||
inputStream = new FileInputStream(file);
|
||||
}
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
StringBuilder str = new StringBuilder();
|
||||
String tmp;
|
||||
while ((tmp = reader.readLine()) != null) {
|
||||
str.append(tmp);
|
||||
}
|
||||
reader.close();
|
||||
inputStream.close();
|
||||
shipCardId = new JSONArray(str.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<TeamData> getUserTeam(JSONObject json) {
|
||||
List<TeamData> data = new ArrayList<>();
|
||||
try {
|
||||
JSONObject warRepoot = json.getJSONObject("warReport");
|
||||
JSONArray selfShips = warRepoot.getJSONArray("selfShips");
|
||||
for (int i = 0; i < selfShips.length(); i++) {
|
||||
TeamData team = new TeamData();
|
||||
JSONObject js = selfShips.getJSONObject(i);
|
||||
team.setId(i);
|
||||
team.setHpMax(js.get("hpMax").toString());
|
||||
team.setTitle(js.getString("title"));
|
||||
team.setJid(js.getInt("id"));
|
||||
team.setHp(warRepoot.getJSONArray("hpBeforeNightWarSelf").get(i).toString());
|
||||
team.setImageUrl("http://jianr.jianrmod.cn/jianr/ship/S_NORMAL_" + JianRUtils.jianCidToid(js.get("shipCid").toString()) + ".png");
|
||||
team.setType(js.getInt("type"));
|
||||
JSONArray array = js.getJSONArray("equipment");
|
||||
List<String> list = new ArrayList<>();
|
||||
for (int j = 0; j < array.length(); j++) {
|
||||
list.add(array.getString(j));
|
||||
}
|
||||
team.setEquipments(list);
|
||||
try {
|
||||
team.setItem1Url("http://jianr.jianrmod.cn/jianr/equipment/equip_L_" + JianRUtils.equipCidToid(array.get(0).toString()) + ".png");
|
||||
team.setItem2Url("http://jianr.jianrmod.cn/jianr/equipment/equip_L_" + JianRUtils.equipCidToid(array.get(1).toString()) + ".png");
|
||||
team.setItem3Url("http://jianr.jianrmod.cn/jianr/equipment/equip_L_" + JianRUtils.equipCidToid(array.get(2).toString()) + ".png");
|
||||
team.setItem4Url("http://jianr.jianrmod.cn/jianr/equipment/equip_L_" + JianRUtils.equipCidToid(array.get(3).toString()) + ".png");
|
||||
} catch (Exception ignored) {
|
||||
|
||||
}
|
||||
|
||||
team.setUser(true);
|
||||
team.setSrc(json);
|
||||
data.add(team);
|
||||
}
|
||||
return data;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static List<TeamData> getNightUserTeam(JSONObject json) {
|
||||
List<TeamData> data = getUserTeam(json);
|
||||
System.out.println("用户数量:" + data.size());
|
||||
try {
|
||||
JSONObject warRepoot = json.getJSONObject("warResult");
|
||||
JSONArray selfShips = warRepoot.getJSONArray("selfShipResults");
|
||||
for (int i = 0; i < selfShips.length(); i++) {
|
||||
JSONObject js = selfShips.getJSONObject(i);
|
||||
TeamData ut = data.get(i);
|
||||
ut.setHp(js.getInt("hp") + "");
|
||||
data.set(i, ut);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static List<TeamData> getNightEnemyTeam(JSONObject json) {
|
||||
List<TeamData> data = getEnemyTeam(json);
|
||||
try {
|
||||
JSONObject warRepoot = json.getJSONObject("warResult");
|
||||
JSONArray selfShips = warRepoot.getJSONArray("enemyShipResults");
|
||||
System.out.println("血量参数:" + selfShips.length());
|
||||
for (int i = 0; i < selfShips.length(); i++) {
|
||||
JSONObject js = selfShips.getJSONObject(i);
|
||||
System.out.println("敌方血量:" + js.getInt("hp"));
|
||||
System.out.println("敌方数量:" + data.size());
|
||||
TeamData ut = data.get(i);
|
||||
ut.setHp(js.getInt("hp") + "");
|
||||
data.set(i, ut);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static List<TeamData> getEnemyTeam(JSONObject json) {
|
||||
List<TeamData> data = new ArrayList<>();
|
||||
try {
|
||||
JSONObject warRepoot = json.getJSONObject("warReport");
|
||||
JSONArray selfShips = warRepoot.getJSONArray("enemyShips");
|
||||
for (int i = 0; i < selfShips.length(); i++) {
|
||||
TeamData team = new TeamData();
|
||||
JSONObject js = selfShips.getJSONObject(i);
|
||||
team.setId(i);
|
||||
team.setHpMax(js.get("hpMax").toString());
|
||||
team.setTitle(js.getString("title"));
|
||||
team.setHp(warRepoot.getJSONArray("hpBeforeNightWarEnemy").get(i).toString());
|
||||
team.setImageUrl("http://jianr.jianrmod.cn/jianr/ship/S_NORMAL_" + JianRUtils.EnemyShipCardId(js.get("shipCid").toString()) + ".png");
|
||||
team.setUser(false);
|
||||
team.setSrc(json);
|
||||
data.add(team);
|
||||
}
|
||||
return data;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
private static List<JianNiang> jianNiangs;
|
||||
private static List<ShipEquipmnt> equipmnts;
|
||||
public static List<JianNiang> reloadJianNiang() {
|
||||
try {
|
||||
if(jianNiangs==null){
|
||||
jianNiangs=new ArrayList<>();
|
||||
JSONArray array=new JSONArray(Utils.readFile(Utils.getAppPath() + "/jdata/shipCardWu.json"));
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
JSONObject json=array.getJSONObject(i);
|
||||
JianNiang jianNiang= JSON.parseObject(json.toString(),JianNiang.class);
|
||||
jianNiangs.add(jianNiang);
|
||||
}
|
||||
System.out.println("缓存舰娘数:"+jianNiangs.size());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
getInit();
|
||||
}
|
||||
return jianNiangs;
|
||||
}
|
||||
public static List<ShipEquipmnt> reloadEquipmnts() {
|
||||
try {
|
||||
if(equipmnts==null){
|
||||
equipmnts=new ArrayList<>();
|
||||
JSONArray array=new JSONArray(Utils.readFile(Utils.getAppPath() + "/jdata/shipEquipmnt.json"));
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
JSONObject json=array.getJSONObject(i);
|
||||
ShipEquipmnt jianNiang= JSON.parseObject(json.toString(),ShipEquipmnt.class);
|
||||
equipmnts.add(jianNiang);
|
||||
}
|
||||
System.out.println("缓存装备数:"+equipmnts.size());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
getInit();
|
||||
}
|
||||
return equipmnts;
|
||||
}
|
||||
public static ShipEquipmnt getEquipmnt(int cid,int type){
|
||||
try{
|
||||
List<ShipEquipmnt>equipmnts=reloadEquipmnts();
|
||||
for (ShipEquipmnt equipmnt : equipmnts) {
|
||||
if(equipmnt.getCid()==cid){
|
||||
return equipmnt;
|
||||
}
|
||||
if(equipmnt.getType()==type){
|
||||
return equipmnt;
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
return null;
|
||||
}
|
||||
public static void initShipCardId(){
|
||||
try{
|
||||
File file=new File(Application.application.getFilesDir()+"/shipCardid");
|
||||
InputStream inputStream;
|
||||
if(!file.exists()){
|
||||
inputStream=Application.application.getAssets().open("shipCardId");
|
||||
}else{
|
||||
inputStream=new FileInputStream(file);
|
||||
public static void getInit() {
|
||||
File file = new File(Utils.getAppPath() + "/getInitConfigs");
|
||||
try {
|
||||
InputStream inputStream = new FileInputStream(file);
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
byte[] bytes = new byte[1024];
|
||||
int len = 0;
|
||||
while ((len = inputStream.read(bytes)) != -1) {
|
||||
outputStream.write(bytes, 0, len);
|
||||
}
|
||||
BufferedReader reader=new BufferedReader(new InputStreamReader(inputStream));
|
||||
StringBuilder str= new StringBuilder();
|
||||
String tmp;
|
||||
while ((tmp=reader.readLine())!=null){
|
||||
str.append(tmp);
|
||||
}
|
||||
reader.close();
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
inputStream.close();
|
||||
shipCardId=new JSONArray(str.toString());
|
||||
}catch (Exception e){
|
||||
JSONObject init = new JSONObject(outputStream.toString());
|
||||
Utils.writerFile(Utils.getAppPath() + "/jdata/shipCardWu.json", init.getJSONArray("shipCardWu").toString());
|
||||
Utils.writerFile(Utils.getAppPath() + "/jdata/shipEquipmnt.json", init.getJSONArray("shipEquipmnt").toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void downlaodInit(boolean flag) {
|
||||
if (flag) {
|
||||
if (new File(Utils.getAppPath() + "/getInitConfigs").exists()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
HttpUtils.downloadFile("http://version.jr.moepoint.tw/index/getInitConfigs", Utils.getAppPath() + "/", new DownloadFileInerface() {
|
||||
@Override
|
||||
public boolean downloading(String fileName, int current, long length) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void over(boolean isOver) {
|
||||
new Thread(()->{
|
||||
JianRUtils.reloadJianNiang();
|
||||
JianRUtils.reloadEquipmnts();
|
||||
}).start();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
@ -55,21 +56,30 @@ public class ModUtils {
|
||||
private TMod mod;
|
||||
|
||||
public static ModUtils init(Context context) {
|
||||
if (modUtils == null) {
|
||||
modUtils = new ModUtils();
|
||||
modUtils.database = ModDatabase.init();
|
||||
System.out.println("调用魔改管理器");
|
||||
try {
|
||||
if (modUtils == null) {
|
||||
modUtils = new ModUtils();
|
||||
modUtils.database = ModDatabase.init();
|
||||
}
|
||||
modUtils.setContext(context);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
modUtils.setContext(context);
|
||||
|
||||
return modUtils;
|
||||
}
|
||||
|
||||
private void setContext(Context context) {
|
||||
this.context = context;
|
||||
hud = Utils.showLoading(context, "安装中", "请稍后");
|
||||
handler.post(()->{
|
||||
hud = Utils.showLoading(context, "安装中", "请稍后");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private ModUtils() {
|
||||
handler = new Handler();
|
||||
handler = new Handler(Looper.getMainLooper());
|
||||
}
|
||||
|
||||
public void setMod(TMod mod) {
|
||||
|
358
app/src/main/java/com/yutou/jianr_mg/Tools/SocketTools.java
Normal file
358
app/src/main/java/com/yutou/jianr_mg/Tools/SocketTools.java
Normal file
@ -0,0 +1,358 @@
|
||||
package com.yutou.jianr_mg.Tools;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.kaopiz.kprogresshud.KProgressHUD;
|
||||
import com.yutou.jianr_mg.Application;
|
||||
import com.yutou.jianr_mg.Data.AppData;
|
||||
import com.yutou.jianr_mg.Interfaces.HttpInterface;
|
||||
import com.yutou.jianr_mg.Interfaces.ModInterface;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import me.drakeet.materialdialog.MaterialDialog;
|
||||
|
||||
import static android.content.Context.WIFI_SERVICE;
|
||||
|
||||
/**
|
||||
* Socket客户端,接受模式为服务端,传输模式为客户端
|
||||
*/
|
||||
public class SocketTools {
|
||||
private Context context;
|
||||
private boolean model;
|
||||
private Socket socket;
|
||||
private ServerSocket serverSocket;
|
||||
private HttpInterface httpInterface;
|
||||
private List<Socket> sockets;
|
||||
private static int CODE_SUCCESS = 200;
|
||||
private static int CODE_ERROR = 500;
|
||||
private KProgressHUD hud;
|
||||
|
||||
/**
|
||||
* 初始化客户端
|
||||
*
|
||||
* @param model true为接受模式,false为传输模式
|
||||
*/
|
||||
public SocketTools(Context context, boolean model, HttpInterface httpInterface) {
|
||||
this.context = context;
|
||||
this.model = model;
|
||||
this.httpInterface = httpInterface;
|
||||
this.sockets = new ArrayList<>();
|
||||
hud = Utils.showLoading(context, null, "扫描中");
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
new Thread(() -> {
|
||||
if (model) {
|
||||
try {
|
||||
httpInterface.httpGetData("等待链接", CODE_SUCCESS);
|
||||
startService();
|
||||
httpInterface.httpGetData("链接成功!", CODE_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
AppData.handler.post(() -> hud.show());
|
||||
scanAddress((flag, type) -> {
|
||||
AppData.handler.post(()->hud.setLabel("扫描中..."+type));
|
||||
if(type==0){
|
||||
AppData.handler.post(() -> hud.dismiss());
|
||||
showManualDialog();
|
||||
return;
|
||||
}
|
||||
if (sockets.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if(!flag){
|
||||
|
||||
return;
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
for (Socket socket : sockets) {
|
||||
list.add(socket.getInetAddress().getHostAddress());
|
||||
}
|
||||
AppData.handler.post(() -> {
|
||||
hud.dismiss();
|
||||
showDialog(list);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void showManualDialog() {
|
||||
AppData.handler.post(()->{
|
||||
MaterialDialog dialog=new MaterialDialog(context);
|
||||
TextView textView=new TextView(context);
|
||||
EditText editText=new EditText(context);
|
||||
LinearLayout linearLayout=new LinearLayout(context);
|
||||
textView.setText("请输入IP");
|
||||
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
linearLayout.addView(textView);
|
||||
linearLayout.addView(editText);
|
||||
dialog.setTitle("没有扫描到?");
|
||||
dialog.setContentView(linearLayout);
|
||||
dialog.setPositiveButton("链接",v -> {
|
||||
dialog.dismiss();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
System.out.println("地址:"+editText.getText().toString()+" 端口:2336");
|
||||
Socket socket=new Socket(editText.getText().toString().trim(),2336);
|
||||
linkService(socket);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
dialog.setNegativeButton("取消",v -> {
|
||||
dialog.dismiss();
|
||||
});
|
||||
dialog.show();
|
||||
});
|
||||
}
|
||||
|
||||
private void showDialog(List<String> text) {
|
||||
MaterialDialog dialog = new MaterialDialog(context);
|
||||
ListView listView = new ListView(context);
|
||||
listView.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, text));
|
||||
listView.setOnItemClickListener((parent, view, position, id) -> {
|
||||
Socket socket = sockets.get(position);
|
||||
KProgressHUD dhud=Utils.showLoading(context,null,"传输中");
|
||||
dhud.show();
|
||||
new Thread(() -> {
|
||||
System.out.println("开始传输:");
|
||||
linkService(socket);
|
||||
System.out.println("传输完毕");
|
||||
AppData.handler.post(()->{dhud.dismiss();dialog.dismiss();});
|
||||
dhud.dismiss();
|
||||
}).start();
|
||||
|
||||
});
|
||||
|
||||
dialog.setTitle("扫描到主机");
|
||||
dialog.setContentView(listView);
|
||||
dialog.setPositiveButton("关闭", v -> {
|
||||
dialog.dismiss();
|
||||
});
|
||||
dialog.setCanceledOnTouchOutside(true);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void linkService(Socket socket) {
|
||||
OutputStream outputStream;
|
||||
try {
|
||||
outputStream = socket.getOutputStream();
|
||||
outputStream.write("ok".getBytes());
|
||||
outputStream.flush();
|
||||
String[] data = Utils.Base64Encode(new File("/data/data/" + context.getPackageName() + "/databases/game_data_db"));
|
||||
if (data == null)
|
||||
return;
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("state", 1);
|
||||
json.put("size", new File("/data/data/" + context.getPackageName() + "/databases/game_data_db").length());
|
||||
json.put("path","/data/data/" + context.getPackageName() + "/databases/");
|
||||
json.put("fileName","game_data_db");
|
||||
json.put("length",data.length);
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
json.put("index",i);
|
||||
json.put("data",data[i]);
|
||||
outputStream.write((json.toString()+"\n").getBytes());
|
||||
outputStream.flush();
|
||||
}
|
||||
// json.put("data", data);
|
||||
// outputStream.write(json.toString().getBytes());
|
||||
// outputStream.flush();
|
||||
outputStream.close();
|
||||
socket.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean flag = true;
|
||||
private List<Socket> socketList;
|
||||
|
||||
private void startService() {
|
||||
socketList = new ArrayList<>();
|
||||
|
||||
AppData.handler.post(()->{ hud=Utils.showLoading(context,"本地IP:"+getLocalAddress(),"等待中");hud.show();});
|
||||
while (flag) {
|
||||
try {
|
||||
ServerSocket serverSocket = new ServerSocket(2336);
|
||||
Socket socket = serverSocket.accept();
|
||||
if (!flag) {
|
||||
serverSocket.close();
|
||||
return;
|
||||
}
|
||||
serverSocket.close();
|
||||
socketList.add(socket);
|
||||
testSocket(socket);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void testSocket(Socket socket) {
|
||||
try {
|
||||
InputStream inputStream = socket.getInputStream();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
byte[] bytes = new byte[1024];
|
||||
int len = 0;
|
||||
while ((len = inputStream.read(bytes)) != -1) {
|
||||
baos.write(bytes, 0, len);
|
||||
if (len == 2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
baos.flush();
|
||||
String tmp = baos.toString();
|
||||
baos.close();
|
||||
System.out.println(tmp);
|
||||
if (tmp.equals("ok")) {
|
||||
flag = false;
|
||||
AppData.handler.post(()->hud.dismiss());
|
||||
for (Socket s : socketList) {
|
||||
if (!s.equals(socket)) {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
start(socket, inputStream);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
}
|
||||
|
||||
private void start(Socket socket, InputStream input) {
|
||||
|
||||
AppData.handler.post(()->{ hud=Utils.showLoading(context,null,"接收中");hud.show();});
|
||||
httpInterface.httpGetData("确认为:" + socket.getInetAddress().getHostAddress(), CODE_SUCCESS);
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
byte[] bytes = new byte[2048];
|
||||
int len = 0;
|
||||
while ((len = input.read(bytes)) > -1) {
|
||||
baos.write(bytes, 0, len);
|
||||
baos.flush();
|
||||
}
|
||||
JSONObject json = new JSONObject(baos.toString());
|
||||
File file = new File(json.getString("path")+json.getString("fileName"));
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
String [] list=baos.toString().split("\n");
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String d : list) {
|
||||
if(d.trim().length()==0) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
JSONObject tmp = new JSONObject(d);
|
||||
sb.append(tmp.getString("data")+"\n");
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
}
|
||||
System.out.println("保存路径:"+file.getAbsolutePath());
|
||||
Utils.Base64Decode(sb.toString(), file);
|
||||
AppData.handler.post(()->{hud.dismiss();Utils.toast(context,"重启盒子生效");});
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void scanAddress(ModInterface modInterface) {
|
||||
String mAddress = getLocalAddress();
|
||||
if (mAddress == null) {
|
||||
httpInterface.httpGetData("非局域网环境,请检查WIFI状态", CODE_ERROR);
|
||||
return;
|
||||
}
|
||||
String ipGroup = mAddress.split("\\.")[0] + "." + mAddress.split("\\.")[1] + "." + mAddress.split("\\.")[2];
|
||||
List<Thread> list = new ArrayList<>();
|
||||
for (int i = 1; i < 255; i++) {
|
||||
int finalI = i;
|
||||
|
||||
Thread thread = new Thread(() -> {
|
||||
String address = ipGroup + "." + finalI;
|
||||
if (!address.equals(mAddress)) {
|
||||
try {
|
||||
Socket tSocket = new Socket();
|
||||
tSocket.connect(new InetSocketAddress(address, 2336),1000);
|
||||
sockets.add(tSocket);
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
list.add(thread);
|
||||
thread.start();
|
||||
|
||||
}
|
||||
scan(list, modInterface);
|
||||
}
|
||||
|
||||
private void scan(List<Thread> list, ModInterface modInterface) {
|
||||
if (list.isEmpty()) {
|
||||
modInterface.onAction(true, -1);
|
||||
return;
|
||||
}
|
||||
Iterator<Thread> iterator = list.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Thread thread = iterator.next();
|
||||
|
||||
if (!thread.isAlive()) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
modInterface.onAction(false,list.size());
|
||||
scan(list, modInterface);
|
||||
}
|
||||
|
||||
private String getLocalAddress() {
|
||||
String address = null;
|
||||
try {
|
||||
WifiManager wm = (WifiManager) Application.application.getSystemService(WIFI_SERVICE);
|
||||
int ipAddressInt = wm.getConnectionInfo().getIpAddress();
|
||||
address = String.format(Locale.getDefault(), "%d.%d.%d.%d", (ipAddressInt & 0xff), (ipAddressInt >> 8 & 0xff), (ipAddressInt >> 16 & 0xff), (ipAddressInt >> 24 & 0xff));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return address;
|
||||
}
|
||||
}
|
@ -1,11 +1,16 @@
|
||||
package com.yutou.jianr_mg.Tools;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Base64;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
@ -30,6 +35,7 @@ import com.yutou.jianr_mg.views.WebActivity;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
@ -212,8 +218,9 @@ public class Utils {
|
||||
|
||||
public static boolean writerFile(String srcFile, String data) {
|
||||
File file = new File(srcFile);
|
||||
if (!file.exists()) {
|
||||
return false;
|
||||
File path=new File(file.getAbsolutePath().split(file.getName())[0]);
|
||||
if (!path.exists()) {
|
||||
path.mkdirs();
|
||||
}
|
||||
try {
|
||||
PrintWriter writer = new PrintWriter(file);
|
||||
@ -336,12 +343,13 @@ public class Utils {
|
||||
}
|
||||
return bytesToHexString(digest.digest());
|
||||
}
|
||||
public static String getMD5(String data){
|
||||
try{
|
||||
MessageDigest digest=MessageDigest.getInstance("MD5");
|
||||
|
||||
public static String getMD5(String data) {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("MD5");
|
||||
digest.update(data.getBytes());
|
||||
return bytesToHexString(digest.digest());
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
@ -364,8 +372,8 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static void openWebView(String url) {
|
||||
if(url.equals("#")){
|
||||
Utils.toast(Application.application,"暂无连接");
|
||||
if (url.equals("#")) {
|
||||
Utils.toast(Application.application, "暂无连接");
|
||||
return;
|
||||
}
|
||||
Intent intent;
|
||||
@ -382,4 +390,54 @@ public class Utils {
|
||||
Application.application.startActivity(intent);
|
||||
|
||||
}
|
||||
|
||||
public static String getIMEI() {
|
||||
String imei = "-1";
|
||||
TelephonyManager telephonyManager = (TelephonyManager) Application.application.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (telephonyManager != null && ActivityCompat.checkSelfPermission(Application.application, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
|
||||
imei = telephonyManager.getDeviceId();
|
||||
}
|
||||
return imei;
|
||||
}
|
||||
|
||||
static String[] Base64Encode(File file) {
|
||||
try {
|
||||
DataInputStream inputStream = new DataInputStream(new FileInputStream(file));
|
||||
byte[] b = new byte[inputStream.available()];
|
||||
while ((inputStream.read(b)) != -1) {
|
||||
}
|
||||
inputStream.close();
|
||||
return new String(Base64.encode(b, Base64.DEFAULT)).split("\n");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static void Base64Decode(String base64, File file) {
|
||||
try{
|
||||
byte[] b=Base64.decode(base64,Base64.DEFAULT);
|
||||
if(!file.exists()){
|
||||
file.createNewFile();
|
||||
}
|
||||
FileOutputStream outputStream=new FileOutputStream(file);
|
||||
outputStream.write(b);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getVersion() {
|
||||
String versionName=null;
|
||||
try {
|
||||
PackageManager pm = Application.application.getPackageManager();
|
||||
PackageInfo pi = pm.getPackageInfo(Application.application.getPackageName(), 0);
|
||||
versionName = pi.versionName;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return versionName;
|
||||
}
|
||||
}
|
||||
|
53
app/src/main/java/com/yutou/jianr_mg/Tools/ZipUtils.java
Normal file
53
app/src/main/java/com/yutou/jianr_mg/Tools/ZipUtils.java
Normal file
@ -0,0 +1,53 @@
|
||||
package com.yutou.jianr_mg.Tools;
|
||||
|
||||
import com.kaopiz.kprogresshud.KProgressHUD;
|
||||
import com.yutou.jianr_mg.Data.AppData;
|
||||
|
||||
import net.lingala.zip4j.core.ZipFile;
|
||||
import net.lingala.zip4j.exception.ZipException;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ZipUtils {
|
||||
public static List<File> unzip(File zipFile, String descDir, final KProgressHUD hud) {
|
||||
List<File> _list = new ArrayList<>();
|
||||
byte[] _byte = new byte[1024 * 1024];
|
||||
try {
|
||||
File descDirPath = new File(descDir);
|
||||
if (!descDirPath.exists()) {
|
||||
descDirPath.mkdirs();
|
||||
}
|
||||
System.out.println("文件:" + zipFile.exists());
|
||||
try {
|
||||
ZipFile _zipFile = new ZipFile(zipFile);
|
||||
_zipFile.setFileNameCharset("GBK"); //设置编码格式(支持中文)
|
||||
if (!_zipFile.isValidZipFile()) { //检查输入的zip文件是否是有效的zip文件
|
||||
throw new ZipException("压缩文件不合法,可能被损坏.");
|
||||
}
|
||||
new Thread(() -> {
|
||||
while (true) {
|
||||
int done = _zipFile.getProgressMonitor().getPercentDone();
|
||||
AppData.handler.post(() -> hud.setLabel(done + ""));
|
||||
if(done>=100){
|
||||
break;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
_zipFile.extractAll(descDir); //解压
|
||||
} catch (ZipException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
AppData.handler.post(hud::dismiss);
|
||||
return _list;
|
||||
}
|
||||
}
|
@ -40,9 +40,12 @@ public class BaseActivity extends AppCompatActivity {
|
||||
DexClassLoader dexClassLoader= AppData.plugsin.get(jar);
|
||||
|
||||
try {
|
||||
System.out.println("jar:"+jar);
|
||||
System.out.println("BaseActivity:"+baseActivityName);
|
||||
activityInterface= (BaseActivityInterface) dexClassLoader.loadClass(baseActivityName).newInstance();
|
||||
activityInterface.onCreate(savedInstanceState,main_layut,this,getIntent());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
activityInterface=new NotInter();
|
||||
MaterialDialog dialog=new MaterialDialog(this);
|
||||
dialog.setTitle("下载插件:"+name);
|
||||
|
257
app/src/main/java/com/yutou/jianr_mg/views/GameDataActivity.java
Normal file
257
app/src/main/java/com/yutou/jianr_mg/views/GameDataActivity.java
Normal file
@ -0,0 +1,257 @@
|
||||
package com.yutou.jianr_mg.views;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.kaopiz.kprogresshud.KProgressHUD;
|
||||
import com.leon.lfilepickerlibrary.LFilePicker;
|
||||
import com.qq.e.comm.util.StringUtil;
|
||||
import com.yutou.jianr_mg.Data.AppData;
|
||||
import com.yutou.jianr_mg.Fragments.GameData;
|
||||
import com.yutou.jianr_mg.Interfaces.DownloadFileInerface;
|
||||
import com.yutou.jianr_mg.Interfaces.HttpInterface;
|
||||
import com.yutou.jianr_mg.Network.HttpApi;
|
||||
import com.yutou.jianr_mg.Network.HttpUtils;
|
||||
import com.yutou.jianr_mg.Tools.CDNTools;
|
||||
import com.yutou.jianr_mg.Tools.RootUtils;
|
||||
import com.yutou.jianr_mg.Tools.SocketTools;
|
||||
import com.yutou.jianr_mg.Tools.Utils;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import me.drakeet.materialdialog.MaterialDialog;
|
||||
|
||||
public class GameDataActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
private LinearLayout layout;
|
||||
private Button upload, download, localSocket;
|
||||
private TextView textView;
|
||||
private String token = null;
|
||||
private long credit;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
initView();
|
||||
setContentView(layout);
|
||||
initData();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
layout = new LinearLayout(this);
|
||||
upload = new Button(this);
|
||||
download = new Button(this);
|
||||
localSocket = new Button(this);
|
||||
textView = new TextView(this);
|
||||
|
||||
upload.setLayoutParams(buttonParams);
|
||||
download.setLayoutParams(buttonParams);
|
||||
textView.setLayoutParams(buttonParams);
|
||||
localSocket.setLayoutParams(buttonParams);
|
||||
|
||||
upload.setText("上传");
|
||||
download.setText("下载");
|
||||
localSocket.setText("局域网内设备同步");
|
||||
|
||||
upload.setTag(1);
|
||||
download.setTag(2);
|
||||
localSocket.setTag(3);
|
||||
upload.setOnClickListener(this);
|
||||
download.setOnClickListener(this);
|
||||
localSocket.setOnClickListener(this);
|
||||
|
||||
|
||||
layout.addView(textView);
|
||||
layout.addView(upload);
|
||||
layout.addView(download);
|
||||
layout.addView(localSocket);
|
||||
layout.setOrientation(LinearLayout.VERTICAL);
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
try {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("gameDataSize", new File("/data/data/" + getPackageName() + "/databases/game_data_db").length());
|
||||
HttpUtils.post(HttpApi.HOME_URL + HttpApi.DATA_UP_GAMEDATA, json, new HttpInterface() {
|
||||
@Override
|
||||
public void httpGetData(String string, int code) {
|
||||
try {
|
||||
System.out.println(string);
|
||||
JSONObject json = new JSONObject(string);
|
||||
if (json.getInt("code") == 100) {
|
||||
String token = json.getJSONObject("data").getString("token");
|
||||
credit = json.getLong("credit");
|
||||
if (!Utils.testStringIsNull(token)) {
|
||||
GameDataActivity.this.token = token;
|
||||
} else {
|
||||
Utils.toast(GameDataActivity.this, "无法上传,请检查积分是否足够");
|
||||
}
|
||||
}
|
||||
int upindex = json.getJSONObject("data").getInt("upindex");
|
||||
long uptime = json.getJSONObject("data").getLong("uptime");
|
||||
if (upindex == 0 && uptime == 0) {
|
||||
AppData.handler.post(() -> textView.setText("您还未上传过数据"));
|
||||
} else {
|
||||
AppData.handler.post(() -> textView.setText("最后一次上传时间:" + SimpleDateFormat.getDateTimeInstance(DateFormat.YEAR_FIELD, DateFormat.SHORT).format(new Date(uptime))
|
||||
+ "\n上传次数:" + upindex));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (Integer.parseInt(v.getTag() + "")) {
|
||||
case 1:
|
||||
if (token == null) {
|
||||
Utils.toast(GameDataActivity.this, "无法上传,请检查积分是否足够");
|
||||
return;
|
||||
}
|
||||
|
||||
MaterialDialog upDialog = new MaterialDialog(this);
|
||||
upDialog.setTitle("上传数据");
|
||||
upDialog.setMessage("本次预计消耗积分:" + credit);
|
||||
upDialog.setPositiveButton("确定", v1 -> {
|
||||
CDNTools.getInstance(GameDataActivity.this).upload(new File("/data/data/" + getPackageName() + "/databases/game_data_db"), token);
|
||||
upDialog.dismiss();
|
||||
});
|
||||
upDialog.setNegativeButton("取消", v1 -> {
|
||||
upDialog.dismiss();
|
||||
});
|
||||
upDialog.show();
|
||||
break;
|
||||
case 2:
|
||||
try {
|
||||
JSONObject json = new JSONObject();
|
||||
HttpUtils.post(HttpApi.HOME_URL + HttpApi.DATA_DOWN_GAMEDATA, json, new HttpInterface() {
|
||||
KProgressHUD hd;
|
||||
|
||||
@Override
|
||||
public void httpGetData(String string, int code) {
|
||||
try {
|
||||
JSONObject json = new JSONObject(string);
|
||||
JSONObject data = json.getJSONObject("data");
|
||||
String url = data.getString("url");
|
||||
if (!StringUtil.isEmpty(url)) {
|
||||
AppData.handler.post(() -> {
|
||||
hd = Utils.showLoading(GameDataActivity.this, null, null);
|
||||
hd.show();
|
||||
});
|
||||
File file=new File("/data/data/" + getPackageName() + "/databases/game_data_db");
|
||||
file.delete();
|
||||
file=new File("/data/data/" + getPackageName() + "/databases/game_data_db-shm");
|
||||
file.delete();
|
||||
file=new File("/data/data/" + getPackageName() + "/databases/game_data_db-wal");
|
||||
file.delete();
|
||||
|
||||
HttpUtils.downloadFile(url, "/data/data/" + getPackageName() + "/databases/", new DownloadFileInerface() {
|
||||
@Override
|
||||
public boolean downloading(String fileName, int current, long length) {
|
||||
AppData.handler.post(() -> hd.setLabel("下载中(" + current + ")"));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void over(boolean isOver) {
|
||||
AppData.handler.post(() -> {
|
||||
hd.dismiss();
|
||||
Utils.toast(GameDataActivity.this,"重启生效~");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
MaterialDialog dialog = new MaterialDialog(this);
|
||||
dialog.setTitle("传输模式");
|
||||
dialog.setMessage("请选择传输模式?(请确保在同一个局域网下");
|
||||
dialog.setCanceledOnTouchOutside(true);
|
||||
dialog.setNegativeButton("接受模式", v1 -> {
|
||||
dialog.dismiss();
|
||||
new SocketTools(this, true, new HttpInterface() {
|
||||
@Override
|
||||
public void httpGetData(String string, int code) {
|
||||
System.out.println(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
dialog.setPositiveButton("传输模式", v1 -> {
|
||||
dialog.dismiss();
|
||||
new SocketTools(this, false, new HttpInterface() {
|
||||
@Override
|
||||
public void httpGetData(String string, int code) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
dialog.show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (requestCode == 100) {
|
||||
//如果是文件选择模式,需要获取选择的所有文件的路径集合
|
||||
List<String> list = data.getStringArrayListExtra("paths");
|
||||
Toast.makeText(getApplicationContext(), "选中了" + list.size() + "个文件", Toast.LENGTH_SHORT).show();
|
||||
File file = new File(list.get(0));
|
||||
if (file.exists() && !StringUtil.isEmpty(token)) {
|
||||
CDNTools.getInstance(this).upload(file, token);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -20,12 +20,14 @@ import com.qq.e.ads.banner2.UnifiedBannerADListener;
|
||||
import com.qq.e.ads.banner2.UnifiedBannerView;
|
||||
import com.qq.e.comm.util.AdError;
|
||||
import com.yutou.jianr_mg.Data.AppData;
|
||||
import com.yutou.jianr_mg.Data.MAdConfig;
|
||||
import com.yutou.jianr_mg.Data.MAppHomeConfig;
|
||||
import com.yutou.jianr_mg.Data.MBanner;
|
||||
import com.yutou.jianr_mg.Interfaces.HttpInterface;
|
||||
import com.yutou.jianr_mg.Network.HttpApi;
|
||||
import com.yutou.jianr_mg.Network.HttpUtils;
|
||||
import com.yutou.jianr_mg.R;
|
||||
import com.yutou.jianr_mg.Tools.AdTools;
|
||||
import com.yutou.jianr_mg.Tools.Log;
|
||||
import com.yutou.jianr_mg.Tools.Utils;
|
||||
|
||||
@ -55,6 +57,7 @@ public class HomeHeader {
|
||||
private Timer timer;
|
||||
private boolean isFlash = false;
|
||||
private Handler handler;
|
||||
private MAdConfig ad;
|
||||
|
||||
public static HomeHeader getHome(Context context) {
|
||||
if (header == null) {
|
||||
@ -87,9 +90,34 @@ public class HomeHeader {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
initAd();
|
||||
}
|
||||
private void initAd(){
|
||||
try {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("type", 3);
|
||||
HttpUtils.post(HttpApi.HOME_URL + HttpApi.AD_GET, json, new HttpInterface() {
|
||||
@Override
|
||||
public void httpGetData(String string, int code) {
|
||||
try {
|
||||
JSONObject json = new JSONObject(string);
|
||||
if (json.getInt("code") == 100) {
|
||||
ad = JSON.parseObject(json.getJSONObject("data").toString(), MAdConfig.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
AppData.handler.post(()->showAdBanner());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private void startGameActivity() {
|
||||
timer.schedule(new TimerTask() {
|
||||
private String text;
|
||||
@ -138,11 +166,12 @@ public class HomeHeader {
|
||||
banner.setLayoutParams(params);
|
||||
layout.addView(banner);
|
||||
layout.addView(home);
|
||||
showAdBanner();
|
||||
return layout;
|
||||
}
|
||||
UnifiedBannerView bannerView;
|
||||
private void showAdBanner(){
|
||||
UnifiedBannerView bannerView=new UnifiedBannerView((Activity) context, APPID, POSID, new UnifiedBannerADListener() {
|
||||
AdTools.upload(AdTools.Banner,AdTools.req);
|
||||
bannerView=new UnifiedBannerView((Activity) context, APPID, POSID, new UnifiedBannerADListener() {
|
||||
@Override
|
||||
public void onNoAD(AdError adError) {
|
||||
Utils.toast(getContext(),adError.getErrorMsg());
|
||||
@ -155,7 +184,7 @@ public class HomeHeader {
|
||||
|
||||
@Override
|
||||
public void onADExposure() {
|
||||
|
||||
AdTools.upload(AdTools.Banner,AdTools.show);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -165,7 +194,8 @@ public class HomeHeader {
|
||||
|
||||
@Override
|
||||
public void onADClicked() {
|
||||
|
||||
AdTools.upload(AdTools.Banner,AdTools.click);
|
||||
bannerView.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -184,6 +214,7 @@ public class HomeHeader {
|
||||
}
|
||||
});
|
||||
bannerView.loadAD();
|
||||
|
||||
layout.addView(bannerView);
|
||||
}
|
||||
|
||||
|
@ -68,9 +68,8 @@ public class ModListActivity extends AppCompatActivity{
|
||||
navigationController.addTabItemSelectedListener(new OnTabItemSelectedListener() {
|
||||
@Override
|
||||
public void onSelected(int index, int old) {
|
||||
switch (index) {
|
||||
}
|
||||
viewPager.setCurrentItem(index);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
155
app/src/main/java/com/yutou/jianr_mg/views/NativeAdActivity.java
Normal file
155
app/src/main/java/com/yutou/jianr_mg/views/NativeAdActivity.java
Normal file
@ -0,0 +1,155 @@
|
||||
package com.yutou.jianr_mg.views;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.kaopiz.kprogresshud.KProgressHUD;
|
||||
import com.qq.e.ads.nativ.ADSize;
|
||||
import com.qq.e.ads.nativ.NativeExpressAD;
|
||||
import com.qq.e.ads.nativ.NativeExpressADView;
|
||||
import com.qq.e.comm.util.AdError;
|
||||
import com.yutou.jianr_mg.Interfaces.HttpInterface;
|
||||
import com.yutou.jianr_mg.Network.HttpApi;
|
||||
import com.yutou.jianr_mg.Network.HttpUtils;
|
||||
import com.yutou.jianr_mg.Tools.AdTools;
|
||||
import com.yutou.jianr_mg.Tools.Utils;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NativeAdActivity extends AppCompatActivity {
|
||||
private LinearLayout layout;
|
||||
private KProgressHUD hud;
|
||||
private Handler handler;
|
||||
private String appid,posId;
|
||||
private int index=0;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
layout=new LinearLayout(this);
|
||||
layout.setOrientation(LinearLayout.VERTICAL);
|
||||
setContentView(layout);
|
||||
handler=new Handler();
|
||||
hud= Utils.showLoading(this,null,null);
|
||||
hud.show();
|
||||
init();
|
||||
}
|
||||
public void init() {
|
||||
try {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("type", 4);
|
||||
HttpUtils.post(HttpApi.HOME_URL + HttpApi.AD_GET, json,new HttpInterface() {
|
||||
@Override
|
||||
public void httpGetData(String string, int state) {
|
||||
try {
|
||||
JSONObject json = new JSONObject(string.toString());
|
||||
appid = json.getJSONObject("data").getString("appid");
|
||||
posId = json.getJSONObject("data").getString("posid");
|
||||
handler.post(()->initAd());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Utils.toast(null,"今天恰饱了");
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private void initAd() {
|
||||
if (appid == null || posId == null) {
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
initAd();
|
||||
}
|
||||
}, 300);
|
||||
return;
|
||||
}
|
||||
TextView textView=new TextView(this);
|
||||
textView.setText("点击任意广告均可获取2点积分");
|
||||
layout.addView(textView);
|
||||
startAd();
|
||||
}
|
||||
private void startAd() {
|
||||
AdTools.upload( AdTools.Native, AdTools.req);
|
||||
NativeExpressAD ad = new NativeExpressAD(this, new ADSize(ADSize.FULL_WIDTH, ADSize.AUTO_HEIGHT), appid, posId, new NativeExpressAD.NativeExpressADListener() {
|
||||
@Override
|
||||
public void onADLoaded(List<NativeExpressADView> list) {
|
||||
AdTools.upload(AdTools.Native, AdTools.show);
|
||||
hud.dismiss();
|
||||
for (NativeExpressADView adView : list) {
|
||||
layout.addView(adView);
|
||||
adView.render();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRenderFail(NativeExpressADView nativeExpressADView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRenderSuccess(NativeExpressADView nativeExpressADView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onADExposure(NativeExpressADView nativeExpressADView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onADClicked(NativeExpressADView nativeExpressADView) {
|
||||
if(index==5){
|
||||
Utils.toast(null,"今天恰饱了!谢谢!");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
AdTools.upload( AdTools.Native, AdTools.click);
|
||||
index++;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onADClosed(NativeExpressADView nativeExpressADView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onADLeftApplication(NativeExpressADView nativeExpressADView) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onADOpenOverlay(NativeExpressADView nativeExpressADView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onADCloseOverlay(NativeExpressADView nativeExpressADView) {
|
||||
nativeExpressADView.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNoAD(AdError adError) {
|
||||
hud.dismiss();
|
||||
Toast.makeText(NativeAdActivity.this,"现在并不想恰饭",Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
ad.loadAD(5);
|
||||
}
|
||||
}
|
@ -2,66 +2,101 @@ package com.yutou.jianr_mg.views;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.yutou.jianr_mg.Adapters.GameDataAdapters.WarAdapter;
|
||||
import com.yutou.jianr_mg.Adapters.WarLogAdapter;
|
||||
import com.yutou.jianr_mg.Adapters.ViewPagerAdapter;
|
||||
import com.yutou.jianr_mg.Data.ShipEquipmnt;
|
||||
import com.yutou.jianr_mg.Data.TeamData;
|
||||
import com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments.DaytimeFragment;
|
||||
import com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments.NightFragment;
|
||||
import com.yutou.jianr_mg.R;
|
||||
import com.yutou.jianr_mg.Tools.Utils;
|
||||
import com.yutou.jianr_mg.Tools.JianRUtils;
|
||||
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.lemon.view.RefreshRecyclerView;
|
||||
import me.majiajie.pagerbottomtabstrip.NavigationController;
|
||||
import me.majiajie.pagerbottomtabstrip.PageNavigationView;
|
||||
import me.majiajie.pagerbottomtabstrip.listener.OnTabItemSelectedListener;
|
||||
|
||||
public class WarLogActivity extends AppCompatActivity {
|
||||
List<Map> list;
|
||||
private RefreshRecyclerView recyclerView;
|
||||
private WarLogAdapter adapter;
|
||||
JSONArray array;
|
||||
private PageNavigationView tab;
|
||||
private ViewPager pager;
|
||||
private NavigationController navigationController;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_favorite);
|
||||
setContentView(R.layout.activity_mod_list);
|
||||
initView();
|
||||
try {
|
||||
list = JSON.parseArray(getIntent().getStringExtra("data"), Map.class);
|
||||
array = new JSONArray(getIntent().getStringExtra("data"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(list==null){
|
||||
list=new ArrayList<>();
|
||||
if (array == null) {
|
||||
array = new JSONArray();
|
||||
}
|
||||
try {
|
||||
JSONObject json = array.getJSONObject(0);
|
||||
JSONObject data = json.getJSONObject("DealNode");
|
||||
JSONObject msg = new JSONObject(data.getString("message"));
|
||||
List<TeamData> list = JianRUtils.getUserTeam(msg);
|
||||
List<TeamData> hm=new ArrayList<>();
|
||||
for (TeamData teamData : list) {
|
||||
// if(teamData.getType()>)
|
||||
String name = teamData.getTitle();
|
||||
List<String> equipment = teamData.getEquipments();
|
||||
for (String s : equipment) {
|
||||
ShipEquipmnt equipmnt = JianRUtils.getEquipmnt(Integer.parseInt(s), -1);
|
||||
System.out.println("舰娘:"+name+"装备名字:"+equipmnt.getTitle()+" 类型:"+equipmnt.getType());
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
recyclerView = (RefreshRecyclerView) findViewById(R.id.recyclerView);
|
||||
adapter=new WarLogAdapter(this);
|
||||
recyclerView.setSwipeRefreshColors(0xFF437845, 0xFFE44F98, 0xFF2FAC21);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.dismissSwipeRefresh();
|
||||
recyclerView.addRefreshAction(() -> {
|
||||
try {
|
||||
|
||||
initData();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
tab = (PageNavigationView) findViewById(R.id.tab);
|
||||
pager = (ViewPager) findViewById(R.id.pager);
|
||||
List<Fragment> list = new ArrayList<>();
|
||||
list.add(new DaytimeFragment());
|
||||
list.add(new NightFragment());
|
||||
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager(), list);
|
||||
pager.setAdapter(adapter);
|
||||
pager.setCurrentItem(0);
|
||||
navigationController = tab.material()
|
||||
.addItem(R.drawable.icon_daytime, R.drawable.icon_daytime_select, "昼战")
|
||||
.addItem(R.drawable.icon_night, R.drawable.icon_night_select, "夜战")
|
||||
.build();
|
||||
navigationController.addTabItemSelectedListener(new OnTabItemSelectedListener() {
|
||||
@Override
|
||||
public void onSelected(int index, int old) {
|
||||
pager.setCurrentItem(index);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRepeat(int index) {
|
||||
|
||||
}
|
||||
});
|
||||
initData();
|
||||
}
|
||||
navigationController.setupWithViewPager(pager);
|
||||
navigationController.setSelect(0);
|
||||
|
||||
private void initData() {
|
||||
adapter.clear();
|
||||
adapter.addAll(list);
|
||||
adapter.notifyDataSetChanged();
|
||||
recyclerView.dismissSwipeRefresh();
|
||||
recyclerView.showNoMore();
|
||||
}
|
||||
}
|
||||
|
@ -81,10 +81,10 @@ public class WarView {
|
||||
md5=Utils.getMD5(WarView.this.message.toString());
|
||||
|
||||
if((int)listView.getTag()==1){
|
||||
adapter.setData(getEnemyTeam(message));
|
||||
adapter.setData(JianRUtils.getEnemyTeam(message));
|
||||
listView.setTag(0);
|
||||
}else {
|
||||
adapter.setData(getUserTeam(message));
|
||||
adapter.setData(JianRUtils.getUserTeam(message));
|
||||
listView.setTag(1);
|
||||
}
|
||||
System.out.println("更新数据:"+adapter.getCount()+" "+listView.getTag());
|
||||
@ -100,11 +100,11 @@ public class WarView {
|
||||
if(!nMsg.isNull("extraProgress")){
|
||||
if((int)listView.getTag()==1){
|
||||
System.out.println("夜战,敌舰");
|
||||
adapter.setData(getNightEnemyTeam(nMsg));
|
||||
adapter.setData(JianRUtils.getNightEnemyTeam(nMsg));
|
||||
listView.setTag(0);
|
||||
}else {
|
||||
System.out.println("夜战,己方");
|
||||
adapter.setData(getNightUserTeam(nMsg));
|
||||
adapter.setData(JianRUtils.getNightUserTeam(nMsg));
|
||||
listView.setTag(1);
|
||||
}
|
||||
System.out.println("更新夜战:"+adapter.getCount()+" "+listView.getTag());
|
||||
@ -148,31 +148,32 @@ public class WarView {
|
||||
button.setOnClickListener(view -> {
|
||||
if ((int) listView.getTag() == 1) {
|
||||
if(isNight){
|
||||
adapter.setData(getNightEnemyTeam(nMsg));
|
||||
adapter.setData(JianRUtils.getNightEnemyTeam(nMsg));
|
||||
}else {
|
||||
adapter.setData(getEnemyTeam(message));
|
||||
adapter.setData(JianRUtils.getEnemyTeam(message));
|
||||
}
|
||||
listView.setTag(0);
|
||||
} else {
|
||||
if(isNight){
|
||||
adapter.setData(getNightUserTeam(nMsg));
|
||||
adapter.setData(JianRUtils.getNightUserTeam(nMsg));
|
||||
}else {
|
||||
adapter.setData(getUserTeam(message));
|
||||
adapter.setData(JianRUtils.getUserTeam(message));
|
||||
}
|
||||
listView.setTag(1);
|
||||
}
|
||||
adapter.reload();
|
||||
adapter.notifyDataSetChanged();
|
||||
});
|
||||
linearLayout.addView(button);
|
||||
|
||||
userTeam.setText("剧透");
|
||||
userTeam.setOnCheckedChangeListener((compoundButton, b) -> {
|
||||
adapter.setSpoiler(b);
|
||||
adapter.notifyDataSetChanged();
|
||||
// adapter.setSpoiler(b);
|
||||
// adapter.notifyDataSetChanged();
|
||||
});
|
||||
linearLayout.addView(userTeam);
|
||||
|
||||
adapter = new MagicTeamDataAdapter(getUserTeam(message), context);
|
||||
adapter = new MagicTeamDataAdapter(JianRUtils.getUserTeam(message), context);
|
||||
ViewGroup.LayoutParams listParams=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
listView.setAdapter(adapter);
|
||||
listView.setLayoutParams(listParams);
|
||||
@ -199,101 +200,12 @@ public class WarView {
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<TeamData> getUserTeam(JSONObject json) {
|
||||
List<TeamData> data = new ArrayList<>();
|
||||
try {
|
||||
JSONObject warRepoot = message.getJSONObject("warReport");
|
||||
JSONArray selfShips = warRepoot.getJSONArray("selfShips");
|
||||
for (int i = 0; i < selfShips.length(); i++) {
|
||||
TeamData team = new TeamData();
|
||||
JSONObject js = selfShips.getJSONObject(i);
|
||||
team.setId(i);
|
||||
team.setHpMax(js.get("hpMax").toString());
|
||||
team.setTitle(js.getString("title"));
|
||||
team.setHp(warRepoot.getJSONArray("hpBeforeNightWarSelf").get(i).toString());
|
||||
team.setImageUrl("http://jianr.jianrmod.cn/jianr/ship/S_NORMAL_" + JianRUtils.jianCidToid(js.get("shipCid").toString()) + ".png");
|
||||
try {
|
||||
team.setItem1Url("http://jianr.jianrmod.cn/jianr/equipment/equip_L_" + JianRUtils.equipCidToid(js.getJSONArray("equipment").get(0).toString()) + ".png");
|
||||
team.setItem2Url("http://jianr.jianrmod.cn/jianr/equipment/equip_L_" + JianRUtils.equipCidToid(js.getJSONArray("equipment").get(1).toString()) + ".png");
|
||||
team.setItem3Url("http://jianr.jianrmod.cn/jianr/equipment/equip_L_" + JianRUtils.equipCidToid(js.getJSONArray("equipment").get(2).toString()) + ".png");
|
||||
team.setItem4Url("http://jianr.jianrmod.cn/jianr/equipment/equip_L_" + JianRUtils.equipCidToid(js.getJSONArray("equipment").get(3).toString()) + ".png");
|
||||
} catch (Exception ignored) {
|
||||
|
||||
}
|
||||
team.setUser(true);
|
||||
team.setSrc(json);
|
||||
data.add(team);
|
||||
}
|
||||
return data;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
private List<TeamData> getNightUserTeam(JSONObject json){
|
||||
List<TeamData> data=getUserTeam(message);
|
||||
System.out.println("用户数量:"+data.size());
|
||||
try {
|
||||
JSONObject warRepoot = json.getJSONObject("warResult");
|
||||
JSONArray selfShips = warRepoot.getJSONArray("selfShipResults");
|
||||
for (int i = 0; i < selfShips.length(); i++) {
|
||||
JSONObject js = selfShips.getJSONObject(i);
|
||||
TeamData ut= data.get(i);
|
||||
ut.setHp(js.getInt("hp")+"");
|
||||
data.set(i,ut);
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
private List<TeamData> getNightEnemyTeam(JSONObject json){
|
||||
List<TeamData> data=getEnemyTeam(message);
|
||||
try {
|
||||
JSONObject warRepoot = json.getJSONObject("warResult");
|
||||
JSONArray selfShips = warRepoot.getJSONArray("enemyShipResults");
|
||||
System.out.println("血量参数:"+selfShips.length());
|
||||
for (int i = 0; i < selfShips.length(); i++) {
|
||||
JSONObject js = selfShips.getJSONObject(i);
|
||||
System.out.println("敌方血量:"+js.getInt("hp"));
|
||||
System.out.println("敌方数量:"+data.size());
|
||||
TeamData ut= data.get(i);
|
||||
ut.setHp(js.getInt("hp")+"");
|
||||
data.set(i,ut);
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private List<TeamData> getEnemyTeam(JSONObject json) {
|
||||
List<TeamData> data = new ArrayList<>();
|
||||
try {
|
||||
JSONObject warRepoot = message.getJSONObject("warReport");
|
||||
JSONArray selfShips = warRepoot.getJSONArray("enemyShips");
|
||||
for (int i = 0; i < selfShips.length(); i++) {
|
||||
TeamData team = new TeamData();
|
||||
JSONObject js = selfShips.getJSONObject(i);
|
||||
team.setId(i);
|
||||
team.setHpMax(js.get("hpMax").toString());
|
||||
team.setTitle(js.getString("title"));
|
||||
team.setHp(warRepoot.getJSONArray("hpBeforeNightWarEnemy").get(i).toString());
|
||||
team.setImageUrl("http://jianr.jianrmod.cn/jianr/ship/S_NORMAL_" + JianRUtils.EnemyShipCardId(js.get("shipCid").toString()) + ".png");
|
||||
team.setUser(false);
|
||||
team.setSrc(json);
|
||||
data.add(team);
|
||||
}
|
||||
return data;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
public void close(){
|
||||
timer.cancel();
|
||||
linearLayout.removeAllViews();
|
||||
linearLayout=null;
|
||||
timer=null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ public class WindowsStartActivity extends AppCompatActivity implements View.OnCl
|
||||
private LinearLayout dataConfig;
|
||||
private Button start;
|
||||
private Button help;
|
||||
private Button updata;
|
||||
ArrayAdapter typeAdapter;
|
||||
ArrayAdapter nameAdapter;
|
||||
|
||||
@ -56,6 +57,7 @@ public class WindowsStartActivity extends AppCompatActivity implements View.OnCl
|
||||
dataConfig = findViewById(R.id.dataConfig);
|
||||
start = findViewById(R.id.start);
|
||||
help = findViewById(R.id.help);
|
||||
updata = findViewById(R.id.updata);
|
||||
|
||||
typeAdd.setOnClickListener(this);
|
||||
typeRemove.setOnClickListener(this);
|
||||
@ -63,6 +65,8 @@ public class WindowsStartActivity extends AppCompatActivity implements View.OnCl
|
||||
nameRemove.setOnClickListener(this);
|
||||
start.setOnClickListener(this);
|
||||
help.setOnClickListener(this);
|
||||
updata.setOnClickListener(this);
|
||||
|
||||
|
||||
saveData.setOnCheckedChangeListener((compoundButton, b) -> {
|
||||
if (b) {
|
||||
@ -145,6 +149,10 @@ public class WindowsStartActivity extends AppCompatActivity implements View.OnCl
|
||||
case R.id.nameRemove:
|
||||
removeName();
|
||||
break;
|
||||
case R.id.updata:
|
||||
Intent gameData=new Intent(this,GameDataActivity.class);
|
||||
startActivity(gameData);
|
||||
break;
|
||||
case R.id.start:
|
||||
Intent intent = new Intent(this, WindowsService.class);
|
||||
intent.putExtra("saveData", ((boolean) saveData.getTag()));
|
||||
|
BIN
app/src/main/res/drawable/icon_daytime.png
Normal file
BIN
app/src/main/res/drawable/icon_daytime.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
BIN
app/src/main/res/drawable/icon_daytime_select.png
Normal file
BIN
app/src/main/res/drawable/icon_daytime_select.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.9 KiB |
@ -4,6 +4,7 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:background="@color/white"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
|
@ -120,4 +120,16 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/start"
|
||||
app:layout_constraintTop_toBottomOf="@+id/dataConfig" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/updata"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:text="同步数据"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/start"
|
||||
app:layout_constraintTop_toBottomOf="@+id/help" />
|
||||
</android.support.constraint.ConstraintLayout>
|
@ -7,5 +7,12 @@
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/credit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="积分:0" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
@ -11,9 +11,9 @@
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:max="50"
|
||||
android:progress="20" />
|
||||
android:layout_marginTop="10dp"
|
||||
android:max="100"
|
||||
android:progress="86" />
|
||||
|
||||
|
||||
<LinearLayout
|
||||
@ -60,6 +60,7 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:textColor="@color/black_de"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=" / " />
|
||||
|
||||
|
@ -8,7 +8,7 @@ buildscript {
|
||||
maven { url 'https://dl.bintray.com/umsdk/release' }
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.4.0'
|
||||
classpath 'com.android.tools.build:gradle:3.4.1'
|
||||
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
|
||||
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1"
|
||||
|
||||
|
1
harmony/.gitignore
vendored
Normal file
1
harmony/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
39
harmony/build.gradle
Normal file
39
harmony/build.gradle
Normal file
@ -0,0 +1,39 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 26
|
||||
targetSdkVersion 28
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
implementation 'com.android.support:appcompat-v7:28.0.0'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
//文件选择器
|
||||
implementation 'com.leon:lfilepickerlibrary:1.8.0'
|
||||
//载入界面
|
||||
implementation 'com.kaopiz:kprogresshud:1.1.0'
|
||||
compile 'com.android.support:support-v4:28.0.0'
|
||||
compile 'com.android.support:recyclerview-v7:28.0.0'
|
||||
}
|
21
harmony/proguard-rules.pro
vendored
Normal file
21
harmony/proguard-rules.pro
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
@ -0,0 +1,26 @@
|
||||
package com.jianrmod.plugins.harmony;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||
|
||||
assertEquals("com.jianrmod.plugins.harmony.test", appContext.getPackageName());
|
||||
}
|
||||
}
|
2
harmony/src/main/AndroidManifest.xml
Normal file
2
harmony/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,2 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.jianrmod.plugins.harmony" />
|
31
harmony/src/main/java/Interfaces/BaseActivityInterface.java
Normal file
31
harmony/src/main/java/Interfaces/BaseActivityInterface.java
Normal file
@ -0,0 +1,31 @@
|
||||
package Interfaces;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
|
||||
/**
|
||||
* Created by 58381 on 2018/2/27.
|
||||
*/
|
||||
|
||||
public interface BaseActivityInterface {
|
||||
void onCreate(Bundle savedInstanceState, LinearLayout layout, Context context, Intent intent);
|
||||
void onRestart();
|
||||
void onResume();
|
||||
void onPause();
|
||||
void onDestroy();
|
||||
void getIntent(Intent intent);
|
||||
boolean onKeyDown(int keyCode, KeyEvent event);
|
||||
boolean onKeyUp(int keyCode, KeyEvent event);
|
||||
boolean onTouchEvent(MotionEvent event);
|
||||
Data getData();
|
||||
class Data{
|
||||
private String type;
|
||||
private String url;
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,184 @@
|
||||
package com.jianrmod.plugins.harmony.Activitys;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.jianrmod.plugins.harmony.Tools.ClientUttls;
|
||||
import com.jianrmod.plugins.harmony.Tools.Utils;
|
||||
import com.jianrmod.plugins.harmony.Tools.ZipUtils;
|
||||
import com.kaopiz.kprogresshud.KProgressHUD;
|
||||
import com.yutou.jianr_mg.Interfaces.ModInterface;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import Interfaces.BaseActivityInterface;
|
||||
|
||||
|
||||
public class MainActivity implements BaseActivityInterface {
|
||||
|
||||
|
||||
private Context context;
|
||||
private KProgressHUD hud;
|
||||
public MainActivity() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState, LinearLayout layout, final Context context, Intent intent) {
|
||||
layout.setOrientation(LinearLayout.VERTICAL);
|
||||
this.context=context;
|
||||
Utils.handler=new Handler(Looper.getMainLooper());
|
||||
hud=Utils.showLoading(context,null,"解压中...");
|
||||
layout.addView(getView());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onRestart() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getIntent(Intent intent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Data getData() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private ViewGroup getView(){
|
||||
LinearLayout linearLayout=new LinearLayout(context);
|
||||
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
TextView text1=new TextView(context);
|
||||
Button button=new Button(context);
|
||||
Button button2=new Button(context);
|
||||
final Switch siwtch=new Switch(context);
|
||||
siwtch.setTextOn("覆盖版");
|
||||
siwtch.setTextOff("共存版");
|
||||
text1.setText("请将proj.manifest、Cocos2dxPrefsFile.xml和压缩包放到jianRMG/harmony/文件夹中\n压缩包请重命名为data.zip");
|
||||
button.setText("创建harmony文件夹");
|
||||
button2.setText("开始");
|
||||
|
||||
linearLayout.addView(text1);
|
||||
linearLayout.addView(button);
|
||||
linearLayout.addView(button2);
|
||||
linearLayout.addView(siwtch);
|
||||
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
File file=new File(Utils.getAppPath()+"/harmony/");
|
||||
if(file.exists()){
|
||||
Utils.toast(context,"文件夹已存在");
|
||||
}else {
|
||||
file.mkdirs();
|
||||
}
|
||||
}
|
||||
});
|
||||
button2.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
hud.show();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
File file=new File(Utils.getAppPath()+"/harmony/");
|
||||
if(file.listFiles().length==0){
|
||||
Utils.toast(context,"文件夹内为空,请放入harmony文件夹中");
|
||||
return;
|
||||
}
|
||||
for (File listFile : file.listFiles()) {
|
||||
System.out.println("处理文件:"+listFile.getAbsolutePath());
|
||||
switch (listFile.getName()){
|
||||
case "proj.manifest":
|
||||
|
||||
ClientUttls.install(context, listFile, "/files/", new ModInterface() {
|
||||
@Override
|
||||
public void onAction(boolean flag, int type) {
|
||||
System.out.println("操作manifest文件:"+flag);
|
||||
}
|
||||
});
|
||||
break;
|
||||
case "Cocos2dxPrefsFile.xml":
|
||||
ClientUttls.install(context, listFile, "../shared_prefs/", new ModInterface() {
|
||||
@Override
|
||||
public void onAction(boolean flag, int type) {
|
||||
System.out.println("处理xml:"+flag);
|
||||
}
|
||||
});
|
||||
break;
|
||||
case "data.zip":
|
||||
File path;
|
||||
if(siwtch.isChecked()){
|
||||
path=new File(Utils.getSDCardPath()+"/Android/data/com.huanmeng.zhanjian2/files/res_default/10/");
|
||||
}else {
|
||||
path=new File(Utils.getSDCardPath()+"/Android/data/com.bigzhao.jianrmagicbox/files/res_default/10/");
|
||||
}
|
||||
if(!path.exists()){
|
||||
path.mkdirs();
|
||||
}
|
||||
System.out.println("准备处理zip");
|
||||
ZipUtils.unzip(listFile,path.getAbsolutePath(),hud);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Utils.handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
hud.dismiss();
|
||||
}
|
||||
});
|
||||
Utils.toast(context,"操作完成");
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
});
|
||||
return linearLayout;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.jianrmod.plugins.harmony.Tools;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.yutou.jianr_mg.Interfaces.ModInterface;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ClientUttls {
|
||||
public static void install(Context context, File file, String path, ModInterface modInterface){
|
||||
try{
|
||||
Object modUtils=context.getClassLoader().loadClass("com.yutou.jianr_mg.Tools.ModUtils")
|
||||
.getMethod("init",Context.class).invoke(null,context);
|
||||
modUtils.getClass().getMethod("notRootInstall",File.class,String.class)
|
||||
.invoke(modUtils,file,path);
|
||||
modUtils.getClass().getMethod("notRootInstallStart",ModInterface.class,boolean.class)
|
||||
.invoke(modUtils,modInterface,false);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,316 @@
|
||||
package com.jianrmod.plugins.harmony.Tools;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.util.Base64;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.kaopiz.kprogresshud.KProgressHUD;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Created by 58381 on 2018/1/20.
|
||||
*/
|
||||
|
||||
public class Utils {
|
||||
private static final String TAG = "Utils";
|
||||
public static Handler handler;
|
||||
public static int getPixelsFromDp(Activity activity, int size) {
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
return (size * metrics.densityDpi) / DisplayMetrics.DENSITY_DEFAULT;
|
||||
}
|
||||
|
||||
public static DisplayMetrics getMetrics(Activity activity) {
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
return metrics;
|
||||
}
|
||||
|
||||
public static void toast(Context context, final String str) {
|
||||
final Context finalContext = context;
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(finalContext, str, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public static void setImmersion(Activity activity) {
|
||||
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
}
|
||||
|
||||
public static String getSDCardPath() {
|
||||
String path = Environment.getExternalStorageDirectory().getPath() + "/";
|
||||
return path;
|
||||
}
|
||||
|
||||
public static String getAppPath() {
|
||||
String path = Environment.getExternalStorageDirectory().getPath() + "/jianRMG";
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static <T> List<T> ListRemoveNull(List<T> list) {
|
||||
list.removeAll(Collections.singleton(null));
|
||||
return list;
|
||||
}
|
||||
|
||||
public static KProgressHUD showLoading(Context context, String title, String text) {
|
||||
if (text == null) {
|
||||
text = "载入中";
|
||||
}
|
||||
if (title == null) {
|
||||
title = "请稍后";
|
||||
}
|
||||
KProgressHUD hud = KProgressHUD.create(context)
|
||||
.setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
|
||||
.setLabel(title)
|
||||
.setDetailsLabel(text)
|
||||
.setCancellable(false)
|
||||
.setAnimationSpeed(2)
|
||||
.setDimAmount(0.5f);
|
||||
return hud;
|
||||
}
|
||||
|
||||
public static boolean testStringIsNull(String... strings) {
|
||||
for (String string : strings) {
|
||||
if (null == string || "".equals(string) || string.length() == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制单个文件
|
||||
*
|
||||
* @param srcFileName 待复制的文件名
|
||||
* @param destFileName 目标文件名
|
||||
* @param overlay 如果目标文件存在,是否覆盖
|
||||
* @return 如果复制成功返回true,否则返回false
|
||||
*/
|
||||
public static boolean copyFile(String srcFileName, String destFileName,
|
||||
boolean overlay) {
|
||||
File srcFile = new File(srcFileName);
|
||||
String MESSAGE = "";
|
||||
// 判断源文件是否存在
|
||||
if (!srcFile.exists()) {
|
||||
MESSAGE = "源文件:" + srcFileName + "不存在!";
|
||||
Log.i(TAG, MESSAGE);
|
||||
return false;
|
||||
} else if (!srcFile.isFile()) {
|
||||
MESSAGE = "复制文件失败,源文件:" + srcFileName + "不是一个文件!";
|
||||
Log.i(TAG, MESSAGE);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 判断目标文件是否存在
|
||||
File destFile = new File(destFileName);
|
||||
// 如果目标文件所在目录不存在,则创建目录
|
||||
Log.i(TAG, "目标文件夹:" + destFileName + " exists:" + destFile.exists());
|
||||
if (!destFile.exists()) {
|
||||
// 目标文件所在目录不存在
|
||||
Log.i(TAG, "目标文件所在目录不存在" + destFile.getAbsolutePath());
|
||||
if (!destFile.mkdirs()) {
|
||||
// 复制文件失败:创建目标文件所在目录失败
|
||||
Log.i(TAG, " 复制文件失败:创建目标文件所在目录失败:" + destFileName);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 复制文件
|
||||
int byteread = 0; // 读取的字节数
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
|
||||
try {
|
||||
in = new FileInputStream(srcFile);
|
||||
out = new FileOutputStream(destFile + "/" + srcFile.getName());
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
while ((byteread = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, byteread);
|
||||
}
|
||||
return true;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
if (out != null)
|
||||
out.close();
|
||||
if (in != null)
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean writerFile(String srcFile, String data) {
|
||||
File file = new File(srcFile);
|
||||
File path=new File(file.getAbsolutePath().split(file.getName())[0]);
|
||||
if (!path.exists()) {
|
||||
path.mkdirs();
|
||||
}
|
||||
try {
|
||||
PrintWriter writer = new PrintWriter(file);
|
||||
writer.write(data);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
return true;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String readFile(String srcFile) {
|
||||
File file = new File(srcFile);
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
String tmp, str = "";
|
||||
while ((tmp = reader.readLine()) != null) {
|
||||
str += tmp;
|
||||
}
|
||||
return str;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void deleteFiles(String path) {
|
||||
File files = new File(path);
|
||||
if (files.exists()) {
|
||||
if (files.isDirectory()) {
|
||||
for (File file : files.listFiles()) {
|
||||
deleteFiles(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
files.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean getApplicationPackName(Context context, String packName) {
|
||||
List<PackageInfo> packages = context.getPackageManager().getInstalledPackages(0);
|
||||
for (PackageInfo info : packages) {
|
||||
if (info.packageName.equals(packName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getFileMD5(File file) {
|
||||
if (!file.isFile()) {
|
||||
return null;
|
||||
}
|
||||
MessageDigest digest = null;
|
||||
FileInputStream in = null;
|
||||
byte buffer[] = new byte[1024];
|
||||
int len;
|
||||
try {
|
||||
digest = MessageDigest.getInstance("MD5");
|
||||
in = new FileInputStream(file);
|
||||
while ((len = in.read(buffer, 0, 1024)) != -1) {
|
||||
digest.update(buffer, 0, len);
|
||||
}
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return bytesToHexString(digest.digest());
|
||||
}
|
||||
|
||||
public static String getMD5(String data) {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("MD5");
|
||||
digest.update(data.getBytes());
|
||||
return bytesToHexString(digest.digest());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static String bytesToHexString(byte[] src) {
|
||||
StringBuilder stringBuilder = new StringBuilder("");
|
||||
if (src == null || src.length <= 0) {
|
||||
return null;
|
||||
}
|
||||
for (byte aSrc : src) {
|
||||
int v = aSrc & 0xFF;
|
||||
String hv = Integer.toHexString(v);
|
||||
if (hv.length() < 2) {
|
||||
stringBuilder.append(0);
|
||||
}
|
||||
stringBuilder.append(hv);
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static String[] Base64Encode(File file) {
|
||||
try {
|
||||
DataInputStream inputStream = new DataInputStream(new FileInputStream(file));
|
||||
byte[] b = new byte[inputStream.available()];
|
||||
while ((inputStream.read(b)) != -1) {
|
||||
}
|
||||
inputStream.close();
|
||||
return new String(Base64.encode(b, Base64.DEFAULT)).split("\n");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static void Base64Decode(String base64, File file) {
|
||||
try{
|
||||
byte[] b=Base64.decode(base64,Base64.DEFAULT);
|
||||
if(!file.exists()){
|
||||
file.createNewFile();
|
||||
}
|
||||
FileOutputStream outputStream=new FileOutputStream(file);
|
||||
outputStream.write(b);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.jianrmod.plugins.harmony.Tools;
|
||||
|
||||
import com.kaopiz.kprogresshud.KProgressHUD;
|
||||
|
||||
import com.zip4j.core.ZipFile;
|
||||
import com.zip4j.exception.ZipException;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ZipUtils {
|
||||
public static List<File> unzip(File zipFile, String descDir, final KProgressHUD hud) {
|
||||
|
||||
List<File> _list = new ArrayList<>();
|
||||
byte[] _byte = new byte[1024 * 1024];
|
||||
try {
|
||||
File descDirPath = new File(descDir);
|
||||
if (!descDirPath.exists()) {
|
||||
descDirPath.mkdirs();
|
||||
}
|
||||
|
||||
System.out.println("文件:" + zipFile.exists());
|
||||
try {
|
||||
final ZipFile _zipFile = new ZipFile(zipFile);
|
||||
_zipFile.setFileNameCharset("GBK"); //设置编码格式(支持中文)
|
||||
if (!_zipFile.isValidZipFile()) { //检查输入的zip文件是否是有效的zip文件
|
||||
throw new ZipException("压缩文件不合法,可能被损坏.");
|
||||
}
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
final int done = _zipFile.getProgressMonitor().getPercentDone();
|
||||
Utils.handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
hud.setLabel(done + "%");
|
||||
}
|
||||
});
|
||||
if(done>=100){
|
||||
break;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
_zipFile.extractAll(descDir); //解压
|
||||
} catch (ZipException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Utils.handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
hud.dismiss();
|
||||
}
|
||||
});
|
||||
return _list;
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.yutou.jianr_mg.Interfaces;
|
||||
|
||||
public interface ModInterface {
|
||||
void onAction(boolean flag, int type);
|
||||
}
|
12
harmony/src/main/java/com/yutou/jianr_mg/plugins/Data.java
Normal file
12
harmony/src/main/java/com/yutou/jianr_mg/plugins/Data.java
Normal file
@ -0,0 +1,12 @@
|
||||
package com.yutou.jianr_mg.plugins;
|
||||
|
||||
public class Data {
|
||||
public static String name="harmony";
|
||||
public static String title="专用客户端解卡/反和谐";
|
||||
public static String appId="48B9C440405E442EBE6F5512DE585DBB";
|
||||
public static String url="http://aaa/harmony.jar";
|
||||
public static String image="#";
|
||||
public static String mainFunction="com.jianrmod.plugins.harmony.Activitys.MainActivity#localActivity";
|
||||
public static Integer permission=0;
|
||||
public static String version="1.0";
|
||||
}
|
1120
harmony/src/main/java/com/zip4j/core/HeaderReader.java
Normal file
1120
harmony/src/main/java/com/zip4j/core/HeaderReader.java
Normal file
File diff suppressed because it is too large
Load Diff
977
harmony/src/main/java/com/zip4j/core/HeaderWriter.java
Normal file
977
harmony/src/main/java/com/zip4j/core/HeaderWriter.java
Normal file
@ -0,0 +1,977 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.core;
|
||||
|
||||
import com.zip4j.io.SplitOutputStream;
|
||||
import com.zip4j.model.AESExtraDataRecord;
|
||||
import com.zip4j.model.FileHeader;
|
||||
import com.zip4j.model.LocalFileHeader;
|
||||
import com.zip4j.model.Zip64EndCentralDirLocator;
|
||||
import com.zip4j.model.Zip64EndCentralDirRecord;
|
||||
import com.zip4j.model.ZipModel;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.zip4j.exception.ZipException;
|
||||
import com.zip4j.util.InternalZipConstants;
|
||||
import com.zip4j.util.Raw;
|
||||
import com.zip4j.util.Zip4jUtil;
|
||||
|
||||
public class HeaderWriter {
|
||||
|
||||
private final int ZIP64_EXTRA_BUF = 50;
|
||||
|
||||
public int writeLocalFileHeader(ZipModel zipModel, LocalFileHeader localFileHeader,
|
||||
OutputStream outputStream) throws ZipException {
|
||||
if (localFileHeader == null) {
|
||||
throw new ZipException("input parameters are null, cannot write local file header");
|
||||
}
|
||||
|
||||
try {
|
||||
ArrayList byteArrayList = new ArrayList();
|
||||
|
||||
int headerLength = 0;
|
||||
|
||||
byte[] shortByte = new byte[2];
|
||||
byte[] intByte = new byte[4];
|
||||
byte[] longByte = new byte[8];
|
||||
byte[] emptyLongByte = {0,0,0,0,0,0,0,0};
|
||||
|
||||
Raw.writeIntLittleEndian(intByte, 0, localFileHeader.getSignature());
|
||||
copyByteArrayToArrayList(intByte, byteArrayList);
|
||||
headerLength += 4;
|
||||
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)localFileHeader.getVersionNeededToExtract());
|
||||
copyByteArrayToArrayList(shortByte, byteArrayList);
|
||||
headerLength += 2;
|
||||
|
||||
//General Purpose bit flags
|
||||
copyByteArrayToArrayList(localFileHeader.getGeneralPurposeFlag(), byteArrayList);
|
||||
headerLength += 2;
|
||||
|
||||
//Compression Method
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)localFileHeader.getCompressionMethod());
|
||||
copyByteArrayToArrayList(shortByte, byteArrayList);
|
||||
headerLength += 2;
|
||||
|
||||
//File modified time
|
||||
int dateTime = localFileHeader.getLastModFileTime();
|
||||
Raw.writeIntLittleEndian(intByte, 0, (int)dateTime);
|
||||
copyByteArrayToArrayList(intByte, byteArrayList);
|
||||
headerLength += 4;
|
||||
|
||||
//Skip crc for now - this field will be updated after data is compressed
|
||||
Raw.writeIntLittleEndian(intByte, 0, (int)localFileHeader.getCrc32());
|
||||
copyByteArrayToArrayList(intByte, byteArrayList);
|
||||
headerLength += 4;
|
||||
|
||||
boolean writingZip64Rec = false;
|
||||
|
||||
//compressed & uncompressed size
|
||||
long uncompressedSize = localFileHeader.getUncompressedSize();
|
||||
if (uncompressedSize + ZIP64_EXTRA_BUF >= InternalZipConstants.ZIP_64_LIMIT) {
|
||||
Raw.writeLongLittleEndian(longByte, 0, InternalZipConstants.ZIP_64_LIMIT);
|
||||
System.arraycopy(longByte, 0, intByte, 0, 4);
|
||||
|
||||
//Set the uncompressed size to ZipConstants.ZIP_64_LIMIT as
|
||||
//these values will be stored in Zip64 extra record
|
||||
copyByteArrayToArrayList(intByte, byteArrayList);
|
||||
|
||||
copyByteArrayToArrayList(intByte, byteArrayList);
|
||||
zipModel.setZip64Format(true);
|
||||
writingZip64Rec = true;
|
||||
localFileHeader.setWriteComprSizeInZip64ExtraRecord(true);
|
||||
} else {
|
||||
Raw.writeLongLittleEndian(longByte, 0, localFileHeader.getCompressedSize());
|
||||
System.arraycopy(longByte, 0, intByte, 0, 4);
|
||||
copyByteArrayToArrayList(intByte, byteArrayList);
|
||||
|
||||
Raw.writeLongLittleEndian(longByte, 0, localFileHeader.getUncompressedSize());
|
||||
System.arraycopy(longByte, 0, intByte, 0, 4);
|
||||
//Raw.writeIntLittleEndian(intByte, 0, (int)localFileHeader.getUncompressedSize());
|
||||
copyByteArrayToArrayList(intByte, byteArrayList);
|
||||
|
||||
localFileHeader.setWriteComprSizeInZip64ExtraRecord(false);
|
||||
}
|
||||
headerLength += 8;
|
||||
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)localFileHeader.getFileNameLength());
|
||||
copyByteArrayToArrayList(shortByte, byteArrayList);
|
||||
headerLength += 2;
|
||||
|
||||
// extra field length
|
||||
int extraFieldLength = 0;
|
||||
if (writingZip64Rec) {
|
||||
extraFieldLength += 20;
|
||||
}
|
||||
if (localFileHeader.getAesExtraDataRecord() != null) {
|
||||
extraFieldLength += 11;
|
||||
}
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)(extraFieldLength));
|
||||
copyByteArrayToArrayList(shortByte, byteArrayList);
|
||||
headerLength += 2;
|
||||
|
||||
if (Zip4jUtil.isStringNotNullAndNotEmpty(zipModel.getFileNameCharset())) {
|
||||
byte[] fileNameBytes = localFileHeader.getFileName().getBytes(zipModel.getFileNameCharset());
|
||||
copyByteArrayToArrayList(fileNameBytes, byteArrayList);
|
||||
headerLength += fileNameBytes.length;
|
||||
} else {
|
||||
copyByteArrayToArrayList(Zip4jUtil.convertCharset(localFileHeader.getFileName()), byteArrayList);
|
||||
headerLength += Zip4jUtil.getEncodedStringLength(localFileHeader.getFileName());
|
||||
}
|
||||
|
||||
//Zip64 should be the first extra data record that should be written
|
||||
//This is NOT according to any specification but if this is changed
|
||||
//then take care of updateLocalFileHeader for compressed size
|
||||
if (writingZip64Rec) {
|
||||
|
||||
|
||||
//Zip64 header
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)InternalZipConstants.EXTRAFIELDZIP64LENGTH);
|
||||
copyByteArrayToArrayList(shortByte, byteArrayList);
|
||||
headerLength += 2;
|
||||
|
||||
//Zip64 extra data record size
|
||||
//hardcoded it to 16 for local file header as we will just write
|
||||
//compressed and uncompressed file sizes
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)16);
|
||||
copyByteArrayToArrayList(shortByte, byteArrayList);
|
||||
headerLength += 2;
|
||||
|
||||
//uncompressed size
|
||||
Raw.writeLongLittleEndian(longByte, 0, localFileHeader.getUncompressedSize());
|
||||
copyByteArrayToArrayList(longByte, byteArrayList);
|
||||
headerLength += 8;
|
||||
|
||||
//set compressed size to 0 for now
|
||||
copyByteArrayToArrayList(emptyLongByte, byteArrayList);
|
||||
headerLength += 8;
|
||||
}
|
||||
|
||||
if (localFileHeader.getAesExtraDataRecord() != null) {
|
||||
AESExtraDataRecord aesExtraDataRecord = localFileHeader.getAesExtraDataRecord();
|
||||
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)aesExtraDataRecord.getSignature());
|
||||
copyByteArrayToArrayList(shortByte, byteArrayList);
|
||||
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)aesExtraDataRecord.getDataSize());
|
||||
copyByteArrayToArrayList(shortByte, byteArrayList);
|
||||
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)aesExtraDataRecord.getVersionNumber());
|
||||
copyByteArrayToArrayList(shortByte, byteArrayList);
|
||||
|
||||
copyByteArrayToArrayList(aesExtraDataRecord.getVendorID().getBytes(), byteArrayList);
|
||||
|
||||
byte[] aesStrengthBytes = new byte[1];
|
||||
aesStrengthBytes[0] = (byte)aesExtraDataRecord.getAesStrength();
|
||||
copyByteArrayToArrayList(aesStrengthBytes, byteArrayList);
|
||||
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)aesExtraDataRecord.getCompressionMethod());
|
||||
copyByteArrayToArrayList(shortByte, byteArrayList);
|
||||
}
|
||||
byte[] lhBytes = byteArrayListToByteArray(byteArrayList);
|
||||
outputStream.write(lhBytes);
|
||||
return lhBytes.length;
|
||||
} catch (ZipException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int writeExtendedLocalHeader(LocalFileHeader localFileHeader,
|
||||
OutputStream outputStream) throws ZipException, IOException {
|
||||
if (localFileHeader == null || outputStream == null) {
|
||||
throw new ZipException("input parameters is null, cannot write extended local header");
|
||||
}
|
||||
|
||||
ArrayList byteArrayList = new ArrayList();
|
||||
byte[] intByte = new byte[4];
|
||||
|
||||
//Extended local file header signature
|
||||
Raw.writeIntLittleEndian(intByte, 0, (int)InternalZipConstants.EXTSIG);
|
||||
copyByteArrayToArrayList(intByte, byteArrayList);
|
||||
|
||||
//CRC
|
||||
Raw.writeIntLittleEndian(intByte, 0, (int)localFileHeader.getCrc32());
|
||||
copyByteArrayToArrayList(intByte, byteArrayList);
|
||||
|
||||
//compressed size
|
||||
long compressedSize = localFileHeader.getCompressedSize();
|
||||
if (compressedSize >= Integer.MAX_VALUE) {
|
||||
compressedSize = Integer.MAX_VALUE;
|
||||
}
|
||||
Raw.writeIntLittleEndian(intByte, 0, (int)compressedSize);
|
||||
copyByteArrayToArrayList(intByte, byteArrayList);
|
||||
|
||||
//uncompressed size
|
||||
long uncompressedSize = localFileHeader.getUncompressedSize();
|
||||
if (uncompressedSize >= Integer.MAX_VALUE) {
|
||||
uncompressedSize = Integer.MAX_VALUE;
|
||||
}
|
||||
Raw.writeIntLittleEndian(intByte, 0, (int)uncompressedSize);
|
||||
copyByteArrayToArrayList(intByte, byteArrayList);
|
||||
|
||||
byte[] extLocHdrBytes = byteArrayListToByteArray(byteArrayList);
|
||||
outputStream.write(extLocHdrBytes);
|
||||
return extLocHdrBytes.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes zip header data and writes this data to the zip file
|
||||
* @param zipModel
|
||||
* @param outputStream
|
||||
* @throws ZipException
|
||||
*/
|
||||
public void finalizeZipFile(ZipModel zipModel,
|
||||
OutputStream outputStream) throws ZipException {
|
||||
if (zipModel == null || outputStream == null) {
|
||||
throw new ZipException("input parameters is null, cannot finalize zip file");
|
||||
}
|
||||
|
||||
try {
|
||||
processHeaderData(zipModel, outputStream);
|
||||
|
||||
long offsetCentralDir = zipModel.getEndCentralDirRecord().getOffsetOfStartOfCentralDir();
|
||||
|
||||
List headerBytesList = new ArrayList();
|
||||
|
||||
int sizeOfCentralDir = writeCentralDirectory(zipModel, outputStream, headerBytesList);
|
||||
|
||||
if (zipModel.isZip64Format()) {
|
||||
if (zipModel.getZip64EndCentralDirRecord() == null) {
|
||||
zipModel.setZip64EndCentralDirRecord(new Zip64EndCentralDirRecord());
|
||||
}
|
||||
if (zipModel.getZip64EndCentralDirLocator() == null) {
|
||||
zipModel.setZip64EndCentralDirLocator(new Zip64EndCentralDirLocator());
|
||||
}
|
||||
|
||||
zipModel.getZip64EndCentralDirLocator().setOffsetZip64EndOfCentralDirRec(offsetCentralDir + sizeOfCentralDir);
|
||||
if (outputStream instanceof SplitOutputStream) {
|
||||
zipModel.getZip64EndCentralDirLocator().setNoOfDiskStartOfZip64EndOfCentralDirRec(((SplitOutputStream)outputStream).getCurrSplitFileCounter());
|
||||
zipModel.getZip64EndCentralDirLocator().setTotNumberOfDiscs(((SplitOutputStream)outputStream).getCurrSplitFileCounter() + 1);
|
||||
} else {
|
||||
zipModel.getZip64EndCentralDirLocator().setNoOfDiskStartOfZip64EndOfCentralDirRec(0);
|
||||
zipModel.getZip64EndCentralDirLocator().setTotNumberOfDiscs(1);
|
||||
}
|
||||
|
||||
writeZip64EndOfCentralDirectoryRecord(zipModel, outputStream, sizeOfCentralDir, offsetCentralDir, headerBytesList);
|
||||
|
||||
writeZip64EndOfCentralDirectoryLocator(zipModel, outputStream, headerBytesList);
|
||||
}
|
||||
|
||||
writeEndOfCentralDirectoryRecord(zipModel, outputStream, sizeOfCentralDir, offsetCentralDir, headerBytesList);
|
||||
|
||||
writeZipHeaderBytes(zipModel, outputStream, byteArrayListToByteArray(headerBytesList));
|
||||
} catch (ZipException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes zip header data and writes this data to the zip file without any validations.
|
||||
* This process is not intended to use for normal operations (adding, deleting, etc) of a zip file.
|
||||
* This method is used when certain validations need to be skipped (ex: Merging split zip files,
|
||||
* adding comment to a zip file, etc)
|
||||
* @param zipModel
|
||||
* @param outputStream
|
||||
* @throws ZipException
|
||||
*/
|
||||
public void finalizeZipFileWithoutValidations(ZipModel zipModel, OutputStream outputStream) throws ZipException {
|
||||
if (zipModel == null || outputStream == null) {
|
||||
throw new ZipException("input parameters is null, cannot finalize zip file without validations");
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
List headerBytesList = new ArrayList();
|
||||
|
||||
long offsetCentralDir = zipModel.getEndCentralDirRecord().getOffsetOfStartOfCentralDir();
|
||||
|
||||
int sizeOfCentralDir = writeCentralDirectory(zipModel, outputStream, headerBytesList);
|
||||
|
||||
if (zipModel.isZip64Format()) {
|
||||
if (zipModel.getZip64EndCentralDirRecord() == null) {
|
||||
zipModel.setZip64EndCentralDirRecord(new Zip64EndCentralDirRecord());
|
||||
}
|
||||
if (zipModel.getZip64EndCentralDirLocator() == null) {
|
||||
zipModel.setZip64EndCentralDirLocator(new Zip64EndCentralDirLocator());
|
||||
}
|
||||
|
||||
zipModel.getZip64EndCentralDirLocator().setOffsetZip64EndOfCentralDirRec(offsetCentralDir + sizeOfCentralDir);
|
||||
|
||||
writeZip64EndOfCentralDirectoryRecord(zipModel, outputStream, sizeOfCentralDir, offsetCentralDir, headerBytesList);
|
||||
writeZip64EndOfCentralDirectoryLocator(zipModel, outputStream, headerBytesList);
|
||||
}
|
||||
|
||||
writeEndOfCentralDirectoryRecord(zipModel, outputStream, sizeOfCentralDir, offsetCentralDir, headerBytesList);
|
||||
|
||||
writeZipHeaderBytes(zipModel, outputStream, byteArrayListToByteArray(headerBytesList));
|
||||
} catch(ZipException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the zip header data to the zip file
|
||||
* @param outputStream
|
||||
* @param buff
|
||||
* @throws ZipException
|
||||
*/
|
||||
private void writeZipHeaderBytes(ZipModel zipModel, OutputStream outputStream, byte[] buff) throws ZipException {
|
||||
if (buff == null) {
|
||||
throw new ZipException("invalid buff to write as zip headers");
|
||||
}
|
||||
|
||||
try {
|
||||
if (outputStream instanceof SplitOutputStream) {
|
||||
if (((SplitOutputStream)outputStream).checkBuffSizeAndStartNextSplitFile(buff.length)) {
|
||||
finalizeZipFile(zipModel, outputStream);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
outputStream.write(buff);
|
||||
} catch (IOException e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills the header data in the zip model
|
||||
* @param zipModel
|
||||
* @param outputStream
|
||||
* @throws ZipException
|
||||
*/
|
||||
private void processHeaderData(ZipModel zipModel, OutputStream outputStream) throws ZipException {
|
||||
try {
|
||||
int currSplitFileCounter = 0;
|
||||
if (outputStream instanceof SplitOutputStream) {
|
||||
zipModel.getEndCentralDirRecord().setOffsetOfStartOfCentralDir(
|
||||
((SplitOutputStream)outputStream).getFilePointer());
|
||||
currSplitFileCounter = ((SplitOutputStream)outputStream).getCurrSplitFileCounter();
|
||||
|
||||
}
|
||||
|
||||
if (zipModel.isZip64Format()) {
|
||||
if (zipModel.getZip64EndCentralDirRecord() == null) {
|
||||
zipModel.setZip64EndCentralDirRecord(new Zip64EndCentralDirRecord());
|
||||
}
|
||||
if (zipModel.getZip64EndCentralDirLocator() == null) {
|
||||
zipModel.setZip64EndCentralDirLocator(new Zip64EndCentralDirLocator());
|
||||
}
|
||||
|
||||
zipModel.getZip64EndCentralDirLocator().setNoOfDiskStartOfZip64EndOfCentralDirRec(currSplitFileCounter);
|
||||
zipModel.getZip64EndCentralDirLocator().setTotNumberOfDiscs(currSplitFileCounter + 1);
|
||||
}
|
||||
zipModel.getEndCentralDirRecord().setNoOfThisDisk(currSplitFileCounter);
|
||||
zipModel.getEndCentralDirRecord().setNoOfThisDiskStartOfCentralDir(currSplitFileCounter);
|
||||
} catch (IOException e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes central directory header data to an array list
|
||||
* @param zipModel
|
||||
* @param outputStream
|
||||
* @param headerBytesList
|
||||
* @return size of central directory
|
||||
* @throws ZipException
|
||||
*/
|
||||
private int writeCentralDirectory(ZipModel zipModel,
|
||||
OutputStream outputStream, List headerBytesList) throws ZipException {
|
||||
if (zipModel == null || outputStream == null) {
|
||||
throw new ZipException("input parameters is null, cannot write central directory");
|
||||
}
|
||||
|
||||
if (zipModel.getCentralDirectory() == null ||
|
||||
zipModel.getCentralDirectory().getFileHeaders() == null ||
|
||||
zipModel.getCentralDirectory().getFileHeaders().size() <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sizeOfCentralDir = 0;
|
||||
for (int i = 0; i < zipModel.getCentralDirectory().getFileHeaders().size(); i++) {
|
||||
FileHeader fileHeader = (FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i);
|
||||
int sizeOfFileHeader = writeFileHeader(zipModel, fileHeader, outputStream, headerBytesList);
|
||||
sizeOfCentralDir += sizeOfFileHeader;
|
||||
}
|
||||
return sizeOfCentralDir;
|
||||
}
|
||||
|
||||
private int writeFileHeader(ZipModel zipModel, FileHeader fileHeader,
|
||||
OutputStream outputStream, List headerBytesList) throws ZipException {
|
||||
|
||||
if (fileHeader == null || outputStream == null) {
|
||||
throw new ZipException("input parameters is null, cannot write local file header");
|
||||
}
|
||||
|
||||
try {
|
||||
int sizeOfFileHeader = 0;
|
||||
|
||||
byte[] shortByte = new byte[2];
|
||||
byte[] intByte = new byte[4];
|
||||
byte[] longByte = new byte[8];
|
||||
final byte[] emptyShortByte = {0,0};
|
||||
final byte[] emptyIntByte = {0,0,0,0};
|
||||
|
||||
boolean writeZip64FileSize = false;
|
||||
boolean writeZip64OffsetLocalHeader = false;
|
||||
|
||||
Raw.writeIntLittleEndian(intByte, 0, fileHeader.getSignature());
|
||||
copyByteArrayToArrayList(intByte, headerBytesList);
|
||||
sizeOfFileHeader += 4;
|
||||
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)fileHeader.getVersionMadeBy());
|
||||
copyByteArrayToArrayList(shortByte, headerBytesList);
|
||||
sizeOfFileHeader += 2;
|
||||
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)fileHeader.getVersionNeededToExtract());
|
||||
copyByteArrayToArrayList(shortByte, headerBytesList);
|
||||
sizeOfFileHeader += 2;
|
||||
|
||||
copyByteArrayToArrayList(fileHeader.getGeneralPurposeFlag(), headerBytesList);
|
||||
sizeOfFileHeader += 2;
|
||||
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)fileHeader.getCompressionMethod());
|
||||
copyByteArrayToArrayList(shortByte, headerBytesList);
|
||||
sizeOfFileHeader += 2;
|
||||
|
||||
int dateTime = fileHeader.getLastModFileTime();
|
||||
Raw.writeIntLittleEndian(intByte, 0, dateTime);
|
||||
copyByteArrayToArrayList(intByte, headerBytesList);
|
||||
sizeOfFileHeader += 4;
|
||||
|
||||
Raw.writeIntLittleEndian(intByte, 0, (int)(fileHeader.getCrc32()));
|
||||
copyByteArrayToArrayList(intByte, headerBytesList);
|
||||
sizeOfFileHeader += 4;
|
||||
|
||||
if (fileHeader.getCompressedSize() >= InternalZipConstants.ZIP_64_LIMIT ||
|
||||
fileHeader.getUncompressedSize() + ZIP64_EXTRA_BUF >= InternalZipConstants.ZIP_64_LIMIT) {
|
||||
Raw.writeLongLittleEndian(longByte, 0, InternalZipConstants.ZIP_64_LIMIT);
|
||||
System.arraycopy(longByte, 0, intByte, 0, 4);
|
||||
|
||||
copyByteArrayToArrayList(intByte, headerBytesList);
|
||||
sizeOfFileHeader += 4;
|
||||
|
||||
copyByteArrayToArrayList(intByte, headerBytesList);
|
||||
sizeOfFileHeader += 4;
|
||||
|
||||
writeZip64FileSize = true;
|
||||
} else {
|
||||
Raw.writeLongLittleEndian(longByte, 0, fileHeader.getCompressedSize());
|
||||
System.arraycopy(longByte, 0, intByte, 0, 4);
|
||||
// Raw.writeIntLittleEndian(intByte, 0, (int)fileHeader.getCompressedSize());
|
||||
copyByteArrayToArrayList(intByte, headerBytesList);
|
||||
sizeOfFileHeader += 4;
|
||||
|
||||
Raw.writeLongLittleEndian(longByte, 0, fileHeader.getUncompressedSize());
|
||||
System.arraycopy(longByte, 0, intByte, 0, 4);
|
||||
// Raw.writeIntLittleEndian(intByte, 0, (int)fileHeader.getUncompressedSize());
|
||||
copyByteArrayToArrayList(intByte, headerBytesList);
|
||||
sizeOfFileHeader += 4;
|
||||
}
|
||||
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)fileHeader.getFileNameLength());
|
||||
copyByteArrayToArrayList(shortByte, headerBytesList);
|
||||
sizeOfFileHeader += 2;
|
||||
|
||||
//Compute offset bytes before extra field is written for Zip64 compatibility
|
||||
//NOTE: this data is not written now, but written at a later point
|
||||
byte[] offsetLocalHeaderBytes = new byte[4];
|
||||
if (fileHeader.getOffsetLocalHeader() > InternalZipConstants.ZIP_64_LIMIT) {
|
||||
Raw.writeLongLittleEndian(longByte, 0, InternalZipConstants.ZIP_64_LIMIT);
|
||||
System.arraycopy(longByte, 0, offsetLocalHeaderBytes, 0, 4);
|
||||
writeZip64OffsetLocalHeader = true;
|
||||
} else {
|
||||
Raw.writeLongLittleEndian(longByte, 0, fileHeader.getOffsetLocalHeader());
|
||||
System.arraycopy(longByte, 0, offsetLocalHeaderBytes, 0, 4);
|
||||
}
|
||||
|
||||
// extra field length
|
||||
int extraFieldLength = 0;
|
||||
if (writeZip64FileSize || writeZip64OffsetLocalHeader) {
|
||||
extraFieldLength += 4;
|
||||
if (writeZip64FileSize)
|
||||
extraFieldLength += 16;
|
||||
if (writeZip64OffsetLocalHeader)
|
||||
extraFieldLength += 8;
|
||||
}
|
||||
if (fileHeader.getAesExtraDataRecord() != null) {
|
||||
extraFieldLength += 11;
|
||||
}
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)(extraFieldLength));
|
||||
copyByteArrayToArrayList(shortByte, headerBytesList);
|
||||
sizeOfFileHeader += 2;
|
||||
|
||||
//Skip file comment length for now
|
||||
copyByteArrayToArrayList(emptyShortByte, headerBytesList);
|
||||
sizeOfFileHeader += 2;
|
||||
|
||||
//Skip disk number start for now
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)(fileHeader.getDiskNumberStart()));
|
||||
copyByteArrayToArrayList(shortByte, headerBytesList);
|
||||
sizeOfFileHeader += 2;
|
||||
|
||||
//Skip internal file attributes for now
|
||||
copyByteArrayToArrayList(emptyShortByte, headerBytesList);
|
||||
sizeOfFileHeader += 2;
|
||||
|
||||
//External file attributes
|
||||
if (fileHeader.getExternalFileAttr() != null) {
|
||||
copyByteArrayToArrayList(fileHeader.getExternalFileAttr(), headerBytesList);
|
||||
} else {
|
||||
copyByteArrayToArrayList(emptyIntByte, headerBytesList);
|
||||
}
|
||||
sizeOfFileHeader += 4;
|
||||
|
||||
//offset local header
|
||||
//this data is computed above
|
||||
copyByteArrayToArrayList(offsetLocalHeaderBytes, headerBytesList);
|
||||
sizeOfFileHeader += 4;
|
||||
|
||||
if (Zip4jUtil.isStringNotNullAndNotEmpty(zipModel.getFileNameCharset())) {
|
||||
byte[] fileNameBytes = fileHeader.getFileName().getBytes(zipModel.getFileNameCharset());
|
||||
copyByteArrayToArrayList(fileNameBytes, headerBytesList);
|
||||
sizeOfFileHeader += fileNameBytes.length;
|
||||
} else {
|
||||
copyByteArrayToArrayList(Zip4jUtil.convertCharset(fileHeader.getFileName()), headerBytesList);
|
||||
sizeOfFileHeader += Zip4jUtil.getEncodedStringLength(fileHeader.getFileName());
|
||||
}
|
||||
|
||||
if (writeZip64FileSize || writeZip64OffsetLocalHeader) {
|
||||
zipModel.setZip64Format(true);
|
||||
|
||||
//Zip64 header
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)InternalZipConstants.EXTRAFIELDZIP64LENGTH);
|
||||
copyByteArrayToArrayList(shortByte, headerBytesList);
|
||||
sizeOfFileHeader += 2;
|
||||
|
||||
//Zip64 extra data record size
|
||||
int dataSize = 0;
|
||||
|
||||
if (writeZip64FileSize) {
|
||||
dataSize += 16;
|
||||
}
|
||||
if (writeZip64OffsetLocalHeader) {
|
||||
dataSize += 8;
|
||||
}
|
||||
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)dataSize);
|
||||
copyByteArrayToArrayList(shortByte, headerBytesList);
|
||||
sizeOfFileHeader += 2;
|
||||
|
||||
if (writeZip64FileSize) {
|
||||
Raw.writeLongLittleEndian(longByte, 0, fileHeader.getUncompressedSize());
|
||||
copyByteArrayToArrayList(longByte, headerBytesList);
|
||||
sizeOfFileHeader += 8;
|
||||
|
||||
Raw.writeLongLittleEndian(longByte, 0, fileHeader.getCompressedSize());
|
||||
copyByteArrayToArrayList(longByte, headerBytesList);
|
||||
sizeOfFileHeader += 8;
|
||||
}
|
||||
|
||||
if (writeZip64OffsetLocalHeader) {
|
||||
Raw.writeLongLittleEndian(longByte, 0, fileHeader.getOffsetLocalHeader());
|
||||
copyByteArrayToArrayList(longByte, headerBytesList);
|
||||
sizeOfFileHeader += 8;
|
||||
}
|
||||
}
|
||||
|
||||
if (fileHeader.getAesExtraDataRecord() != null) {
|
||||
AESExtraDataRecord aesExtraDataRecord = fileHeader.getAesExtraDataRecord();
|
||||
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)aesExtraDataRecord.getSignature());
|
||||
copyByteArrayToArrayList(shortByte, headerBytesList);
|
||||
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)aesExtraDataRecord.getDataSize());
|
||||
copyByteArrayToArrayList(shortByte, headerBytesList);
|
||||
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)aesExtraDataRecord.getVersionNumber());
|
||||
copyByteArrayToArrayList(shortByte, headerBytesList);
|
||||
|
||||
copyByteArrayToArrayList(aesExtraDataRecord.getVendorID().getBytes(), headerBytesList);
|
||||
|
||||
byte[] aesStrengthBytes = new byte[1];
|
||||
aesStrengthBytes[0] = (byte)aesExtraDataRecord.getAesStrength();
|
||||
copyByteArrayToArrayList(aesStrengthBytes, headerBytesList);
|
||||
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)aesExtraDataRecord.getCompressionMethod());
|
||||
copyByteArrayToArrayList(shortByte, headerBytesList);
|
||||
|
||||
sizeOfFileHeader += 11;
|
||||
}
|
||||
|
||||
// outputStream.write(byteArrayListToByteArray(headerBytesList));
|
||||
|
||||
return sizeOfFileHeader;
|
||||
} catch (Exception e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeZip64EndOfCentralDirectoryRecord(ZipModel zipModel,
|
||||
OutputStream outputStream, int sizeOfCentralDir,
|
||||
long offsetCentralDir, List headerBytesList) throws ZipException {
|
||||
if (zipModel == null || outputStream == null) {
|
||||
throw new ZipException("zip model or output stream is null, cannot write zip64 end of central directory record");
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
byte[] shortByte = new byte[2];
|
||||
byte[] emptyShortByte = {0,0};
|
||||
byte[] intByte = new byte[4];
|
||||
byte[] longByte = new byte[8];
|
||||
|
||||
//zip64 end of central dir signature
|
||||
Raw.writeIntLittleEndian(intByte, 0, (int)InternalZipConstants.ZIP64ENDCENDIRREC);
|
||||
copyByteArrayToArrayList(intByte, headerBytesList);
|
||||
|
||||
//size of zip64 end of central directory record
|
||||
Raw.writeLongLittleEndian(longByte, 0, (long)44);
|
||||
copyByteArrayToArrayList(longByte, headerBytesList);
|
||||
|
||||
//version made by
|
||||
//version needed to extract
|
||||
if (zipModel.getCentralDirectory() != null &&
|
||||
zipModel.getCentralDirectory().getFileHeaders() != null &&
|
||||
zipModel.getCentralDirectory().getFileHeaders().size() > 0) {
|
||||
Raw.writeShortLittleEndian(shortByte, 0,
|
||||
(short)((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(0)).getVersionMadeBy());
|
||||
copyByteArrayToArrayList(shortByte, headerBytesList);
|
||||
|
||||
Raw.writeShortLittleEndian(shortByte, 0,
|
||||
(short)((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(0)).getVersionNeededToExtract());
|
||||
copyByteArrayToArrayList(shortByte, headerBytesList);
|
||||
} else {
|
||||
copyByteArrayToArrayList(emptyShortByte, headerBytesList);
|
||||
copyByteArrayToArrayList(emptyShortByte, headerBytesList);
|
||||
}
|
||||
|
||||
//number of this disk
|
||||
Raw.writeIntLittleEndian(intByte, 0, zipModel.getEndCentralDirRecord().getNoOfThisDisk());
|
||||
copyByteArrayToArrayList(intByte, headerBytesList);
|
||||
|
||||
//number of the disk with start of central directory
|
||||
Raw.writeIntLittleEndian(intByte, 0, zipModel.getEndCentralDirRecord().getNoOfThisDiskStartOfCentralDir());
|
||||
copyByteArrayToArrayList(intByte, headerBytesList);
|
||||
|
||||
//total number of entries in the central directory on this disk
|
||||
int numEntries = 0;
|
||||
int numEntriesOnThisDisk = 0;
|
||||
if (zipModel.getCentralDirectory() == null ||
|
||||
zipModel.getCentralDirectory().getFileHeaders() == null) {
|
||||
throw new ZipException("invalid central directory/file headers, " +
|
||||
"cannot write end of central directory record");
|
||||
} else {
|
||||
numEntries = zipModel.getCentralDirectory().getFileHeaders().size();
|
||||
if (zipModel.isSplitArchive()) {
|
||||
countNumberOfFileHeaderEntriesOnDisk(zipModel.getCentralDirectory().getFileHeaders(),
|
||||
zipModel.getEndCentralDirRecord().getNoOfThisDisk());
|
||||
} else {
|
||||
numEntriesOnThisDisk = numEntries;
|
||||
}
|
||||
}
|
||||
Raw.writeLongLittleEndian(longByte, 0, numEntriesOnThisDisk);
|
||||
copyByteArrayToArrayList(longByte, headerBytesList);
|
||||
|
||||
//Total number of entries in central directory
|
||||
Raw.writeLongLittleEndian(longByte, 0, numEntries);
|
||||
copyByteArrayToArrayList(longByte, headerBytesList);
|
||||
|
||||
//Size of central directory
|
||||
Raw.writeLongLittleEndian(longByte, 0, sizeOfCentralDir);
|
||||
copyByteArrayToArrayList(longByte, headerBytesList);
|
||||
|
||||
//offset of start of central directory with respect to the starting disk number
|
||||
Raw.writeLongLittleEndian(longByte, 0, offsetCentralDir);
|
||||
copyByteArrayToArrayList(longByte, headerBytesList);
|
||||
|
||||
} catch (ZipException zipException) {
|
||||
throw zipException;
|
||||
} catch (Exception e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeZip64EndOfCentralDirectoryLocator(ZipModel zipModel,
|
||||
OutputStream outputStream, List headerBytesList) throws ZipException {
|
||||
if (zipModel == null || outputStream == null) {
|
||||
throw new ZipException("zip model or output stream is null, cannot write zip64 end of central directory locator");
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
byte[] intByte = new byte[4];
|
||||
byte[] longByte = new byte[8];
|
||||
|
||||
//zip64 end of central dir locator signature
|
||||
Raw.writeIntLittleEndian(intByte, 0, (int)InternalZipConstants.ZIP64ENDCENDIRLOC);
|
||||
copyByteArrayToArrayList(intByte, headerBytesList);
|
||||
|
||||
//number of the disk with the start of the zip64 end of central directory
|
||||
Raw.writeIntLittleEndian(intByte, 0, zipModel.getZip64EndCentralDirLocator().getNoOfDiskStartOfZip64EndOfCentralDirRec());
|
||||
copyByteArrayToArrayList(intByte, headerBytesList);
|
||||
|
||||
//relative offset of the zip64 end of central directory record
|
||||
Raw.writeLongLittleEndian(longByte, 0, zipModel.getZip64EndCentralDirLocator().getOffsetZip64EndOfCentralDirRec());
|
||||
copyByteArrayToArrayList(longByte, headerBytesList);
|
||||
|
||||
//total number of disks
|
||||
Raw.writeIntLittleEndian(intByte, 0, zipModel.getZip64EndCentralDirLocator().getTotNumberOfDiscs());
|
||||
copyByteArrayToArrayList(intByte, headerBytesList);
|
||||
} catch (ZipException zipException) {
|
||||
throw zipException;
|
||||
} catch (Exception e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeEndOfCentralDirectoryRecord(ZipModel zipModel,
|
||||
OutputStream outputStream,
|
||||
int sizeOfCentralDir,
|
||||
long offsetCentralDir,
|
||||
List headrBytesList) throws ZipException {
|
||||
if (zipModel == null || outputStream == null) {
|
||||
throw new ZipException("zip model or output stream is null, cannot write end of central directory record");
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
byte[] shortByte = new byte[2];
|
||||
byte[] intByte = new byte[4];
|
||||
byte[] longByte = new byte[8];
|
||||
|
||||
//End of central directory signature
|
||||
Raw.writeIntLittleEndian(intByte, 0, (int)zipModel.getEndCentralDirRecord().getSignature());
|
||||
copyByteArrayToArrayList(intByte, headrBytesList);
|
||||
|
||||
//number of this disk
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)(zipModel.getEndCentralDirRecord().getNoOfThisDisk()));
|
||||
copyByteArrayToArrayList(shortByte, headrBytesList);
|
||||
|
||||
//number of the disk with start of central directory
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)(zipModel.getEndCentralDirRecord().getNoOfThisDiskStartOfCentralDir()));
|
||||
copyByteArrayToArrayList(shortByte, headrBytesList);
|
||||
|
||||
//Total number of entries in central directory on this disk
|
||||
int numEntries = 0;
|
||||
int numEntriesOnThisDisk = 0;
|
||||
if (zipModel.getCentralDirectory() == null ||
|
||||
zipModel.getCentralDirectory().getFileHeaders() == null) {
|
||||
throw new ZipException("invalid central directory/file headers, " +
|
||||
"cannot write end of central directory record");
|
||||
} else {
|
||||
numEntries = zipModel.getCentralDirectory().getFileHeaders().size();
|
||||
if (zipModel.isSplitArchive()) {
|
||||
numEntriesOnThisDisk = countNumberOfFileHeaderEntriesOnDisk(zipModel.getCentralDirectory().getFileHeaders(),
|
||||
zipModel.getEndCentralDirRecord().getNoOfThisDisk());
|
||||
} else {
|
||||
numEntriesOnThisDisk = numEntries;
|
||||
}
|
||||
}
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)numEntriesOnThisDisk);
|
||||
copyByteArrayToArrayList(shortByte, headrBytesList);
|
||||
|
||||
//Total number of entries in central directory
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)numEntries);
|
||||
copyByteArrayToArrayList(shortByte, headrBytesList);
|
||||
|
||||
//Size of central directory
|
||||
Raw.writeIntLittleEndian(intByte, 0, sizeOfCentralDir);
|
||||
copyByteArrayToArrayList(intByte, headrBytesList);
|
||||
|
||||
//Offset central directory
|
||||
if (offsetCentralDir > InternalZipConstants.ZIP_64_LIMIT) {
|
||||
Raw.writeLongLittleEndian(longByte, 0, InternalZipConstants.ZIP_64_LIMIT);
|
||||
System.arraycopy(longByte, 0, intByte, 0, 4);
|
||||
copyByteArrayToArrayList(intByte, headrBytesList);
|
||||
} else {
|
||||
Raw.writeLongLittleEndian(longByte, 0, offsetCentralDir);
|
||||
System.arraycopy(longByte, 0, intByte, 0, 4);
|
||||
// Raw.writeIntLittleEndian(intByte, 0, (int)offsetCentralDir);
|
||||
copyByteArrayToArrayList(intByte, headrBytesList);
|
||||
}
|
||||
|
||||
//Zip File comment length
|
||||
int commentLength = 0;
|
||||
if (zipModel.getEndCentralDirRecord().getComment() != null) {
|
||||
commentLength = zipModel.getEndCentralDirRecord().getCommentLength();
|
||||
}
|
||||
Raw.writeShortLittleEndian(shortByte, 0, (short)commentLength);
|
||||
copyByteArrayToArrayList(shortByte, headrBytesList);
|
||||
|
||||
//Comment
|
||||
if (commentLength > 0) {
|
||||
copyByteArrayToArrayList(zipModel.getEndCentralDirRecord().getCommentBytes(), headrBytesList);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateLocalFileHeader(LocalFileHeader localFileHeader, long offset,
|
||||
int toUpdate, ZipModel zipModel, byte[] bytesToWrite, int noOfDisk, SplitOutputStream outputStream) throws ZipException {
|
||||
if (localFileHeader == null || offset < 0 || zipModel == null) {
|
||||
throw new ZipException("invalid input parameters, cannot update local file header");
|
||||
}
|
||||
|
||||
try {
|
||||
boolean closeFlag = false;
|
||||
SplitOutputStream currOutputStream = null;
|
||||
|
||||
if (noOfDisk != outputStream.getCurrSplitFileCounter()) {
|
||||
File zipFile = new File(zipModel.getZipFile());
|
||||
String parentFile = zipFile.getParent();
|
||||
String fileNameWithoutExt = Zip4jUtil.getZipFileNameWithoutExt(zipFile.getName());
|
||||
String fileName = parentFile + System.getProperty("file.separator");
|
||||
if (noOfDisk < 9) {
|
||||
fileName += fileNameWithoutExt + ".z0" + (noOfDisk + 1);
|
||||
} else {
|
||||
fileName += fileNameWithoutExt + ".z" + (noOfDisk + 1);
|
||||
}
|
||||
currOutputStream = new SplitOutputStream(new File(fileName));
|
||||
closeFlag = true;
|
||||
} else {
|
||||
currOutputStream = outputStream;
|
||||
}
|
||||
|
||||
long currOffset = currOutputStream.getFilePointer();
|
||||
|
||||
if (currOutputStream == null) {
|
||||
throw new ZipException("invalid output stream handler, cannot update local file header");
|
||||
}
|
||||
|
||||
switch (toUpdate) {
|
||||
case InternalZipConstants.UPDATE_LFH_CRC:
|
||||
currOutputStream.seek(offset + toUpdate);
|
||||
currOutputStream.write(bytesToWrite);
|
||||
break;
|
||||
case InternalZipConstants.UPDATE_LFH_COMP_SIZE:
|
||||
case InternalZipConstants.UPDATE_LFH_UNCOMP_SIZE:
|
||||
updateCompressedSizeInLocalFileHeader(currOutputStream, localFileHeader,
|
||||
offset, toUpdate, bytesToWrite, zipModel.isZip64Format());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (closeFlag) {
|
||||
currOutputStream.close();
|
||||
} else {
|
||||
outputStream.seek(currOffset);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCompressedSizeInLocalFileHeader(SplitOutputStream outputStream, LocalFileHeader localFileHeader,
|
||||
long offset, long toUpdate, byte[] bytesToWrite, boolean isZip64Format) throws ZipException {
|
||||
|
||||
if (outputStream == null) {
|
||||
throw new ZipException("invalid output stream, cannot update compressed size for local file header");
|
||||
}
|
||||
|
||||
try {
|
||||
if (localFileHeader.isWriteComprSizeInZip64ExtraRecord()) {
|
||||
if (bytesToWrite.length != 8) {
|
||||
throw new ZipException("attempting to write a non 8-byte compressed size block for a zip64 file");
|
||||
}
|
||||
|
||||
//4 - compressed size
|
||||
//4 - uncomprssed size
|
||||
//2 - file name length
|
||||
//2 - extra field length
|
||||
//file name length
|
||||
//2 - Zip64 signature
|
||||
//2 - size of zip64 data
|
||||
//8 - crc
|
||||
//8 - compressed size
|
||||
//8 - uncompressed size
|
||||
long zip64CompressedSizeOffset = offset + toUpdate + 4 + 4 + 2 + 2 + localFileHeader.getFileNameLength() + 2 + 2 + 8;
|
||||
if (toUpdate == InternalZipConstants.UPDATE_LFH_UNCOMP_SIZE) {
|
||||
zip64CompressedSizeOffset += 8;
|
||||
}
|
||||
outputStream.seek(zip64CompressedSizeOffset);
|
||||
outputStream.write(bytesToWrite);
|
||||
} else {
|
||||
outputStream.seek(offset + toUpdate);
|
||||
outputStream.write(bytesToWrite);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void copyByteArrayToArrayList(byte[] byteArray, List arrayList) throws ZipException {
|
||||
if (arrayList == null || byteArray == null) {
|
||||
throw new ZipException("one of the input parameters is null, cannot copy byte array to array list");
|
||||
}
|
||||
|
||||
for (int i = 0; i < byteArray.length; i++) {
|
||||
arrayList.add(Byte.toString(byteArray[i]));
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] byteArrayListToByteArray(List arrayList) throws ZipException {
|
||||
if (arrayList == null) {
|
||||
throw new ZipException("input byte array list is null, cannot conver to byte array");
|
||||
}
|
||||
|
||||
if (arrayList.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] retBytes = new byte[arrayList.size()];
|
||||
|
||||
for (int i = 0; i < arrayList.size(); i++) {
|
||||
retBytes[i] = Byte.parseByte((String)arrayList.get(i));
|
||||
}
|
||||
|
||||
return retBytes;
|
||||
}
|
||||
|
||||
private int countNumberOfFileHeaderEntriesOnDisk(ArrayList fileHeaders,
|
||||
int numOfDisk) throws ZipException {
|
||||
if (fileHeaders == null) {
|
||||
throw new ZipException("file headers are null, cannot calculate number of entries on this disk");
|
||||
}
|
||||
|
||||
int noEntries = 0;
|
||||
for (int i = 0; i < fileHeaders.size(); i++) {
|
||||
FileHeader fileHeader = (FileHeader)fileHeaders.get(i);
|
||||
if (fileHeader.getDiskNumberStart() == numOfDisk) {
|
||||
noEntries++;
|
||||
}
|
||||
}
|
||||
return noEntries;
|
||||
}
|
||||
|
||||
}
|
1042
harmony/src/main/java/com/zip4j/core/ZipFile.java
Normal file
1042
harmony/src/main/java/com/zip4j/core/ZipFile.java
Normal file
File diff suppressed because it is too large
Load Diff
227
harmony/src/main/java/com/zip4j/crypto/AESDecrypter.java
Normal file
227
harmony/src/main/java/com/zip4j/crypto/AESDecrypter.java
Normal file
@ -0,0 +1,227 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.crypto;
|
||||
|
||||
import com.zip4j.crypto.PBKDF2.MacBasedPRF;
|
||||
import com.zip4j.crypto.PBKDF2.PBKDF2Engine;
|
||||
import com.zip4j.crypto.PBKDF2.PBKDF2Parameters;
|
||||
import com.zip4j.crypto.engine.AESEngine;
|
||||
import com.zip4j.model.AESExtraDataRecord;
|
||||
import com.zip4j.model.LocalFileHeader;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.zip4j.exception.ZipException;
|
||||
import com.zip4j.exception.ZipExceptionConstants;
|
||||
import com.zip4j.util.InternalZipConstants;
|
||||
import com.zip4j.util.Raw;
|
||||
import com.zip4j.util.Zip4jConstants;
|
||||
|
||||
public class AESDecrypter implements IDecrypter {
|
||||
|
||||
private LocalFileHeader localFileHeader;
|
||||
private AESEngine aesEngine;
|
||||
private MacBasedPRF mac;
|
||||
|
||||
private final int PASSWORD_VERIFIER_LENGTH = 2;
|
||||
private int KEY_LENGTH;
|
||||
private int MAC_LENGTH;
|
||||
private int SALT_LENGTH;
|
||||
|
||||
private byte[] aesKey;
|
||||
private byte[] macKey;
|
||||
private byte[] derivedPasswordVerifier;
|
||||
private byte[] storedMac;
|
||||
|
||||
private int nonce = 1;
|
||||
private byte[] iv;
|
||||
private byte[] counterBlock;
|
||||
private int loopCount = 0;
|
||||
|
||||
public AESDecrypter(LocalFileHeader localFileHeader,
|
||||
byte[] salt, byte[] passwordVerifier) throws ZipException {
|
||||
|
||||
if (localFileHeader == null) {
|
||||
throw new ZipException("one of the input parameters is null in AESDecryptor Constructor");
|
||||
}
|
||||
|
||||
this.localFileHeader = localFileHeader;
|
||||
this.storedMac = null;
|
||||
iv = new byte[InternalZipConstants.AES_BLOCK_SIZE];
|
||||
counterBlock = new byte[InternalZipConstants.AES_BLOCK_SIZE];
|
||||
init(salt, passwordVerifier);
|
||||
}
|
||||
|
||||
private void init(byte[] salt, byte[] passwordVerifier) throws ZipException {
|
||||
if (localFileHeader == null) {
|
||||
throw new ZipException("invalid file header in init method of AESDecryptor");
|
||||
}
|
||||
|
||||
AESExtraDataRecord aesExtraDataRecord = localFileHeader.getAesExtraDataRecord();
|
||||
if (aesExtraDataRecord == null) {
|
||||
throw new ZipException("invalid aes extra data record - in init method of AESDecryptor");
|
||||
}
|
||||
|
||||
switch (aesExtraDataRecord.getAesStrength()) {
|
||||
case Zip4jConstants.AES_STRENGTH_128:
|
||||
KEY_LENGTH = 16;
|
||||
MAC_LENGTH = 16;
|
||||
SALT_LENGTH = 8;
|
||||
break;
|
||||
case Zip4jConstants.AES_STRENGTH_192:
|
||||
KEY_LENGTH = 24;
|
||||
MAC_LENGTH = 24;
|
||||
SALT_LENGTH = 12;
|
||||
break;
|
||||
case Zip4jConstants.AES_STRENGTH_256:
|
||||
KEY_LENGTH = 32;
|
||||
MAC_LENGTH = 32;
|
||||
SALT_LENGTH = 16;
|
||||
break;
|
||||
default:
|
||||
throw new ZipException("invalid aes key strength for file: " + localFileHeader.getFileName());
|
||||
}
|
||||
|
||||
if (localFileHeader.getPassword() == null || localFileHeader.getPassword().length <= 0) {
|
||||
throw new ZipException("empty or null password provided for AES Decryptor");
|
||||
}
|
||||
|
||||
byte[] derivedKey = deriveKey(salt, localFileHeader.getPassword());
|
||||
if (derivedKey == null ||
|
||||
derivedKey.length != (KEY_LENGTH + MAC_LENGTH + PASSWORD_VERIFIER_LENGTH)) {
|
||||
throw new ZipException("invalid derived key");
|
||||
}
|
||||
|
||||
aesKey = new byte[KEY_LENGTH];
|
||||
macKey = new byte[MAC_LENGTH];
|
||||
derivedPasswordVerifier = new byte[PASSWORD_VERIFIER_LENGTH];
|
||||
|
||||
System.arraycopy(derivedKey, 0, aesKey, 0, KEY_LENGTH);
|
||||
System.arraycopy(derivedKey, KEY_LENGTH, macKey, 0, MAC_LENGTH);
|
||||
System.arraycopy(derivedKey, KEY_LENGTH + MAC_LENGTH, derivedPasswordVerifier, 0, PASSWORD_VERIFIER_LENGTH);
|
||||
|
||||
if (derivedPasswordVerifier == null) {
|
||||
throw new ZipException("invalid derived password verifier for AES");
|
||||
}
|
||||
|
||||
if (!Arrays.equals(passwordVerifier, derivedPasswordVerifier)) {
|
||||
throw new ZipException("Wrong Password for file: " + localFileHeader.getFileName(), ZipExceptionConstants.WRONG_PASSWORD);
|
||||
}
|
||||
|
||||
aesEngine = new AESEngine(aesKey);
|
||||
mac = new MacBasedPRF("HmacSHA1");
|
||||
mac.init(macKey);
|
||||
}
|
||||
|
||||
public int decryptData(byte[] buff, int start, int len) throws ZipException {
|
||||
|
||||
if (aesEngine == null) {
|
||||
throw new ZipException("AES not initialized properly");
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
for (int j = start; j < (start + len); j += InternalZipConstants.AES_BLOCK_SIZE) {
|
||||
loopCount = (j + InternalZipConstants.AES_BLOCK_SIZE <= (start + len)) ?
|
||||
InternalZipConstants.AES_BLOCK_SIZE : ((start + len) - j);
|
||||
|
||||
mac.update(buff, j, loopCount);
|
||||
Raw.prepareBuffAESIVBytes(iv, nonce, InternalZipConstants.AES_BLOCK_SIZE);
|
||||
aesEngine.processBlock(iv, counterBlock);
|
||||
|
||||
for (int k = 0; k < loopCount; k++) {
|
||||
buff[j + k] = (byte)(buff[j + k] ^ counterBlock[k]);
|
||||
}
|
||||
|
||||
nonce++;
|
||||
}
|
||||
|
||||
return len;
|
||||
|
||||
} catch (ZipException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int decryptData(byte[] buff) throws ZipException {
|
||||
return decryptData(buff, 0, buff.length);
|
||||
}
|
||||
|
||||
private byte[] deriveKey(byte[] salt, char[] password) throws ZipException {
|
||||
try {
|
||||
PBKDF2Parameters p = new PBKDF2Parameters("HmacSHA1", "ISO-8859-1",
|
||||
salt, 1000);
|
||||
PBKDF2Engine e = new PBKDF2Engine(p);
|
||||
byte[] derivedKey = e.deriveKey(password, KEY_LENGTH + MAC_LENGTH + PASSWORD_VERIFIER_LENGTH);
|
||||
return derivedKey;
|
||||
} catch (Exception e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int getPasswordVerifierLength() {
|
||||
return PASSWORD_VERIFIER_LENGTH;
|
||||
}
|
||||
|
||||
public int getSaltLength() {
|
||||
return SALT_LENGTH;
|
||||
}
|
||||
|
||||
public byte[] getCalculatedAuthenticationBytes() {
|
||||
return mac.doFinal();
|
||||
}
|
||||
|
||||
public void setStoredMac(byte[] storedMac) {
|
||||
this.storedMac = storedMac;
|
||||
}
|
||||
|
||||
public byte[] getStoredMac() {
|
||||
return storedMac;
|
||||
}
|
||||
|
||||
// public byte[] getStoredMac() throws ZipException {
|
||||
// if (raf == null) {
|
||||
// throw new ZipException("attempting to read MAC on closed file handle");
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// byte[] storedMacBytes = new byte[InternalZipConstants.AES_AUTH_LENGTH];
|
||||
// int bytesRead = raf.read(storedMacBytes);
|
||||
// if (bytesRead != InternalZipConstants.AES_AUTH_LENGTH) {
|
||||
// if (zipModel.isSplitArchive()) {
|
||||
//// unzipEngine.startNextSplitFile();
|
||||
// if (bytesRead == -1) bytesRead = 0;
|
||||
// int newlyRead = raf.read(storedMacBytes, bytesRead, InternalZipConstants.AES_AUTH_LENGTH - bytesRead);
|
||||
// bytesRead += newlyRead;
|
||||
// if (bytesRead != InternalZipConstants.AES_AUTH_LENGTH) {
|
||||
// throw new ZipException("invalid number of bytes read for stored MAC after starting split file");
|
||||
// }
|
||||
// } else {
|
||||
// throw new ZipException("invalid number of bytes read for stored MAC");
|
||||
// }
|
||||
// }
|
||||
// return storedMacBytes;
|
||||
// } catch (IOException e) {
|
||||
// throw new ZipException(e);
|
||||
// } catch (Exception e) {
|
||||
// throw new ZipException(e);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
}
|
215
harmony/src/main/java/com/zip4j/crypto/AESEncrpyter.java
Normal file
215
harmony/src/main/java/com/zip4j/crypto/AESEncrpyter.java
Normal file
@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.crypto;
|
||||
|
||||
import com.zip4j.crypto.PBKDF2.MacBasedPRF;
|
||||
import com.zip4j.crypto.PBKDF2.PBKDF2Engine;
|
||||
import com.zip4j.crypto.PBKDF2.PBKDF2Parameters;
|
||||
import com.zip4j.crypto.engine.AESEngine;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.zip4j.exception.ZipException;
|
||||
import com.zip4j.util.InternalZipConstants;
|
||||
import com.zip4j.util.Raw;
|
||||
import com.zip4j.util.Zip4jConstants;
|
||||
|
||||
public class AESEncrpyter implements IEncrypter {
|
||||
|
||||
private char[] password;
|
||||
private int keyStrength;
|
||||
private AESEngine aesEngine;
|
||||
private MacBasedPRF mac;
|
||||
|
||||
private int KEY_LENGTH;
|
||||
private int MAC_LENGTH;
|
||||
private int SALT_LENGTH;
|
||||
private final int PASSWORD_VERIFIER_LENGTH = 2;
|
||||
|
||||
private byte[] aesKey;
|
||||
private byte[] macKey;
|
||||
private byte[] derivedPasswordVerifier;
|
||||
private byte[] saltBytes;
|
||||
|
||||
private boolean finished;
|
||||
|
||||
private int nonce = 1;
|
||||
private int loopCount = 0;
|
||||
|
||||
private byte[] iv;
|
||||
private byte[] counterBlock;
|
||||
|
||||
public AESEncrpyter(char[] password, int keyStrength) throws ZipException {
|
||||
if (password == null || password.length == 0) {
|
||||
throw new ZipException("input password is empty or null in AES encrypter constructor");
|
||||
}
|
||||
if (keyStrength != Zip4jConstants.AES_STRENGTH_128 &&
|
||||
keyStrength != Zip4jConstants.AES_STRENGTH_256) {
|
||||
throw new ZipException("Invalid key strength in AES encrypter constructor");
|
||||
}
|
||||
|
||||
this.password = password;
|
||||
this.keyStrength = keyStrength;
|
||||
this.finished = false;
|
||||
counterBlock = new byte[InternalZipConstants.AES_BLOCK_SIZE];
|
||||
iv = new byte[InternalZipConstants.AES_BLOCK_SIZE];
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() throws ZipException {
|
||||
switch (keyStrength) {
|
||||
case Zip4jConstants.AES_STRENGTH_128:
|
||||
KEY_LENGTH = 16;
|
||||
MAC_LENGTH = 16;
|
||||
SALT_LENGTH = 8;
|
||||
break;
|
||||
case Zip4jConstants.AES_STRENGTH_256:
|
||||
KEY_LENGTH = 32;
|
||||
MAC_LENGTH = 32;
|
||||
SALT_LENGTH = 16;
|
||||
break;
|
||||
default:
|
||||
throw new ZipException("invalid aes key strength, cannot determine key sizes");
|
||||
}
|
||||
|
||||
saltBytes = generateSalt(SALT_LENGTH);
|
||||
byte[] keyBytes = deriveKey(saltBytes, password);
|
||||
|
||||
if (keyBytes == null || keyBytes.length != (KEY_LENGTH + MAC_LENGTH + PASSWORD_VERIFIER_LENGTH)) {
|
||||
throw new ZipException("invalid key generated, cannot decrypt file");
|
||||
}
|
||||
|
||||
aesKey = new byte[KEY_LENGTH];
|
||||
macKey = new byte[MAC_LENGTH];
|
||||
derivedPasswordVerifier = new byte[PASSWORD_VERIFIER_LENGTH];
|
||||
|
||||
System.arraycopy(keyBytes, 0, aesKey, 0, KEY_LENGTH);
|
||||
System.arraycopy(keyBytes, KEY_LENGTH, macKey, 0, MAC_LENGTH);
|
||||
System.arraycopy(keyBytes, KEY_LENGTH + MAC_LENGTH, derivedPasswordVerifier, 0, PASSWORD_VERIFIER_LENGTH);
|
||||
|
||||
aesEngine = new AESEngine(aesKey);
|
||||
mac = new MacBasedPRF("HmacSHA1");
|
||||
mac.init(macKey);
|
||||
}
|
||||
|
||||
private byte[] deriveKey(byte[] salt, char[] password) throws ZipException {
|
||||
try {
|
||||
PBKDF2Parameters p = new PBKDF2Parameters("HmacSHA1", "ISO-8859-1",
|
||||
salt, 1000);
|
||||
PBKDF2Engine e = new PBKDF2Engine(p);
|
||||
byte[] derivedKey = e.deriveKey(password, KEY_LENGTH + MAC_LENGTH + PASSWORD_VERIFIER_LENGTH);
|
||||
return derivedKey;
|
||||
} catch (Exception e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int encryptData(byte[] buff) throws ZipException {
|
||||
|
||||
if (buff == null) {
|
||||
throw new ZipException("input bytes are null, cannot perform AES encrpytion");
|
||||
}
|
||||
return encryptData(buff, 0, buff.length);
|
||||
}
|
||||
|
||||
public int encryptData(byte[] buff, int start, int len) throws ZipException {
|
||||
|
||||
if (finished) {
|
||||
// A non 16 byte block has already been passed to encrypter
|
||||
// non 16 byte block should be the last block of compressed data in AES encryption
|
||||
// any more encryption will lead to corruption of data
|
||||
throw new ZipException("AES Encrypter is in finished state (A non 16 byte block has already been passed to encrypter)");
|
||||
}
|
||||
|
||||
if (len%16!=0) {
|
||||
this.finished = true;
|
||||
}
|
||||
|
||||
for (int j = start; j < (start + len); j += InternalZipConstants.AES_BLOCK_SIZE) {
|
||||
loopCount = (j + InternalZipConstants.AES_BLOCK_SIZE <= (start + len)) ?
|
||||
InternalZipConstants.AES_BLOCK_SIZE : ((start + len) - j);
|
||||
|
||||
Raw.prepareBuffAESIVBytes(iv, nonce, InternalZipConstants.AES_BLOCK_SIZE);
|
||||
aesEngine.processBlock(iv, counterBlock);
|
||||
|
||||
for (int k = 0; k < loopCount; k++) {
|
||||
buff[j + k] = (byte)(buff[j + k] ^ counterBlock[k]);
|
||||
}
|
||||
|
||||
mac.update(buff, j, loopCount);
|
||||
nonce++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
private static byte[] generateSalt(int size) throws ZipException {
|
||||
|
||||
if (size != 8 && size != 16) {
|
||||
throw new ZipException("invalid salt size, cannot generate salt");
|
||||
}
|
||||
|
||||
int rounds = 0;
|
||||
|
||||
if (size == 8)
|
||||
rounds = 2;
|
||||
if (size == 16)
|
||||
rounds = 4;
|
||||
|
||||
byte[] salt = new byte[size];
|
||||
for( int j = 0; j < rounds; j++ ) {
|
||||
Random rand = new Random();
|
||||
int i = rand.nextInt();
|
||||
salt[0+j*4] = (byte)(i>>24);
|
||||
salt[1+j*4] = (byte)(i>>16);
|
||||
salt[2+j*4] = (byte)(i>>8);
|
||||
salt[3+j*4] = (byte)i;
|
||||
}
|
||||
return salt;
|
||||
}
|
||||
|
||||
public byte[] getFinalMac() {
|
||||
byte[] rawMacBytes = mac.doFinal();
|
||||
byte[] macBytes = new byte[10];
|
||||
System.arraycopy(rawMacBytes, 0, macBytes, 0, 10);
|
||||
return macBytes;
|
||||
}
|
||||
|
||||
public byte[] getDerivedPasswordVerifier() {
|
||||
return derivedPasswordVerifier;
|
||||
}
|
||||
|
||||
public void setDerivedPasswordVerifier(byte[] derivedPasswordVerifier) {
|
||||
this.derivedPasswordVerifier = derivedPasswordVerifier;
|
||||
}
|
||||
|
||||
public byte[] getSaltBytes() {
|
||||
return saltBytes;
|
||||
}
|
||||
|
||||
public void setSaltBytes(byte[] saltBytes) {
|
||||
this.saltBytes = saltBytes;
|
||||
}
|
||||
|
||||
public int getSaltLength() {
|
||||
return SALT_LENGTH;
|
||||
}
|
||||
|
||||
public int getPasswordVeriifierLength() {
|
||||
return PASSWORD_VERIFIER_LENGTH;
|
||||
}
|
||||
}
|
27
harmony/src/main/java/com/zip4j/crypto/IDecrypter.java
Normal file
27
harmony/src/main/java/com/zip4j/crypto/IDecrypter.java
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.crypto;
|
||||
|
||||
import com.zip4j.exception.ZipException;
|
||||
|
||||
public interface IDecrypter {
|
||||
|
||||
public int decryptData(byte[] buff, int start, int len) throws ZipException;
|
||||
|
||||
public int decryptData(byte[] buff) throws ZipException;
|
||||
|
||||
}
|
27
harmony/src/main/java/com/zip4j/crypto/IEncrypter.java
Normal file
27
harmony/src/main/java/com/zip4j/crypto/IEncrypter.java
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.crypto;
|
||||
|
||||
import com.zip4j.exception.ZipException;
|
||||
|
||||
public interface IEncrypter {
|
||||
|
||||
public int encryptData(byte[] buff) throws ZipException;
|
||||
|
||||
public int encryptData(byte[] buff, int start, int len) throws ZipException;
|
||||
|
||||
}
|
85
harmony/src/main/java/com/zip4j/crypto/PBKDF2/BinTools.java
Normal file
85
harmony/src/main/java/com/zip4j/crypto/PBKDF2/BinTools.java
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.crypto.PBKDF2;
|
||||
|
||||
/*
|
||||
* Source referred from Matthias Gartner's PKCS#5 implementation -
|
||||
* see http://rtner.de/software/PBKDF2.html
|
||||
*/
|
||||
|
||||
class BinTools
|
||||
{
|
||||
public static final String hex = "0123456789ABCDEF";
|
||||
|
||||
public static String bin2hex(final byte[] b)
|
||||
{
|
||||
if (b == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
StringBuffer sb = new StringBuffer(2 * b.length);
|
||||
for (int i = 0; i < b.length; i++)
|
||||
{
|
||||
int v = (256 + b[i]) % 256;
|
||||
sb.append(hex.charAt((v / 16) & 15));
|
||||
sb.append(hex.charAt((v % 16) & 15));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static byte[] hex2bin(final String s)
|
||||
{
|
||||
String m = s;
|
||||
if (s == null)
|
||||
{
|
||||
// Allow empty input string.
|
||||
m = "";
|
||||
}
|
||||
else if (s.length() % 2 != 0)
|
||||
{
|
||||
// Assume leading zero for odd string length
|
||||
m = "0" + s;
|
||||
}
|
||||
byte r[] = new byte[m.length() / 2];
|
||||
for (int i = 0, n = 0; i < m.length(); n++)
|
||||
{
|
||||
char h = m.charAt(i++);
|
||||
char l = m.charAt(i++);
|
||||
r[n] = (byte) (hex2bin(h) * 16 + hex2bin(l));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public static int hex2bin(char c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
return (c - '0');
|
||||
}
|
||||
if (c >= 'A' && c <= 'F')
|
||||
{
|
||||
return (c - 'A' + 10);
|
||||
}
|
||||
if (c >= 'a' && c <= 'f')
|
||||
{
|
||||
return (c - 'a' + 10);
|
||||
}
|
||||
throw new IllegalArgumentException(
|
||||
"Input string may only contain hex digits, but found '" + c
|
||||
+ "'");
|
||||
}
|
||||
}
|
116
harmony/src/main/java/com/zip4j/crypto/PBKDF2/MacBasedPRF.java
Normal file
116
harmony/src/main/java/com/zip4j/crypto/PBKDF2/MacBasedPRF.java
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.crypto.PBKDF2;
|
||||
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
/*
|
||||
* Source referred from Matthias Gartner's PKCS#5 implementation -
|
||||
* see http://rtner.de/software/PBKDF2.html
|
||||
*/
|
||||
|
||||
public class MacBasedPRF implements PRF
|
||||
{
|
||||
protected Mac mac;
|
||||
|
||||
protected int hLen;
|
||||
|
||||
protected String macAlgorithm;
|
||||
|
||||
public MacBasedPRF(String macAlgorithm)
|
||||
{
|
||||
this.macAlgorithm = macAlgorithm;
|
||||
try
|
||||
{
|
||||
mac = Mac.getInstance(macAlgorithm);
|
||||
hLen = mac.getMacLength();
|
||||
}
|
||||
catch (NoSuchAlgorithmException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public MacBasedPRF(String macAlgorithm, String provider)
|
||||
{
|
||||
this.macAlgorithm = macAlgorithm;
|
||||
try
|
||||
{
|
||||
mac = Mac.getInstance(macAlgorithm, provider);
|
||||
hLen = mac.getMacLength();
|
||||
}
|
||||
catch (NoSuchAlgorithmException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
catch (NoSuchProviderException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] doFinal(byte[] M)
|
||||
{
|
||||
byte[] r = mac.doFinal(M);
|
||||
return r;
|
||||
}
|
||||
|
||||
public byte[] doFinal() {
|
||||
byte[] r = mac.doFinal();
|
||||
return r;
|
||||
}
|
||||
|
||||
public int getHLen()
|
||||
{
|
||||
return hLen;
|
||||
}
|
||||
|
||||
public void init(byte[] P)
|
||||
{
|
||||
try
|
||||
{
|
||||
mac.init(new SecretKeySpec(P, macAlgorithm));
|
||||
}
|
||||
catch (InvalidKeyException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(byte[] U) {
|
||||
|
||||
try {
|
||||
mac.update(U);
|
||||
} catch (IllegalStateException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void update (byte[] U, int start, int len) {
|
||||
try {
|
||||
mac.update(U, start, len);
|
||||
} catch (IllegalStateException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
198
harmony/src/main/java/com/zip4j/crypto/PBKDF2/PBKDF2Engine.java
Normal file
198
harmony/src/main/java/com/zip4j/crypto/PBKDF2/PBKDF2Engine.java
Normal file
@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.crypto.PBKDF2;
|
||||
|
||||
import com.zip4j.util.Raw;
|
||||
|
||||
/*
|
||||
* Source referred from Matthias Gartner's PKCS#5 implementation -
|
||||
* see http://rtner.de/software/PBKDF2.html
|
||||
*/
|
||||
|
||||
public class PBKDF2Engine
|
||||
{
|
||||
protected PBKDF2Parameters parameters;
|
||||
|
||||
protected PRF prf;
|
||||
|
||||
public PBKDF2Engine()
|
||||
{
|
||||
this.parameters = null;
|
||||
prf = null;
|
||||
}
|
||||
|
||||
public PBKDF2Engine(PBKDF2Parameters parameters)
|
||||
{
|
||||
this.parameters = parameters;
|
||||
prf = null;
|
||||
}
|
||||
|
||||
public PBKDF2Engine(PBKDF2Parameters parameters, PRF prf)
|
||||
{
|
||||
this.parameters = parameters;
|
||||
this.prf = prf;
|
||||
}
|
||||
|
||||
public byte[] deriveKey(char[] inputPassword)
|
||||
{
|
||||
return deriveKey(inputPassword, 0);
|
||||
}
|
||||
|
||||
public byte[] deriveKey(char[] inputPassword, int dkLen)
|
||||
{
|
||||
byte[] r = null;
|
||||
byte P[] = null;
|
||||
if (inputPassword == null)
|
||||
{
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
P = Raw.convertCharArrayToByteArray(inputPassword);
|
||||
|
||||
assertPRF(P);
|
||||
if (dkLen == 0)
|
||||
{
|
||||
dkLen = prf.getHLen();
|
||||
}
|
||||
r = PBKDF2(prf, parameters.getSalt(), parameters.getIterationCount(),
|
||||
dkLen);
|
||||
return r;
|
||||
}
|
||||
|
||||
public boolean verifyKey(char[] inputPassword)
|
||||
{
|
||||
byte[] referenceKey = getParameters().getDerivedKey();
|
||||
if (referenceKey == null || referenceKey.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
byte[] inputKey = deriveKey(inputPassword, referenceKey.length);
|
||||
|
||||
if (inputKey == null || inputKey.length != referenceKey.length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < inputKey.length; i++)
|
||||
{
|
||||
if (inputKey[i] != referenceKey[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void assertPRF(byte[] P)
|
||||
{
|
||||
if (prf == null)
|
||||
{
|
||||
prf = new MacBasedPRF(parameters.getHashAlgorithm());
|
||||
}
|
||||
prf.init(P);
|
||||
}
|
||||
|
||||
public PRF getPseudoRandomFunction()
|
||||
{
|
||||
return prf;
|
||||
}
|
||||
|
||||
protected byte[] PBKDF2(PRF prf, byte[] S, int c, int dkLen)
|
||||
{
|
||||
if (S == null)
|
||||
{
|
||||
S = new byte[0];
|
||||
}
|
||||
int hLen = prf.getHLen();
|
||||
int l = ceil(dkLen, hLen);
|
||||
int r = dkLen - (l - 1) * hLen;
|
||||
byte T[] = new byte[l * hLen];
|
||||
int ti_offset = 0;
|
||||
for (int i = 1; i <= l; i++)
|
||||
{
|
||||
_F(T, ti_offset, prf, S, c, i);
|
||||
ti_offset += hLen;
|
||||
}
|
||||
if (r < hLen)
|
||||
{
|
||||
// Incomplete last block
|
||||
byte DK[] = new byte[dkLen];
|
||||
System.arraycopy(T, 0, DK, 0, dkLen);
|
||||
return DK;
|
||||
}
|
||||
return T;
|
||||
}
|
||||
|
||||
protected int ceil(int a, int b)
|
||||
{
|
||||
int m = 0;
|
||||
if (a % b > 0)
|
||||
{
|
||||
m = 1;
|
||||
}
|
||||
return a / b + m;
|
||||
}
|
||||
|
||||
protected void _F(byte[] dest, int offset, PRF prf, byte[] S, int c,
|
||||
int blockIndex)
|
||||
{
|
||||
int hLen = prf.getHLen();
|
||||
byte U_r[] = new byte[hLen];
|
||||
|
||||
// U0 = S || INT (i);
|
||||
byte U_i[] = new byte[S.length + 4];
|
||||
System.arraycopy(S, 0, U_i, 0, S.length);
|
||||
INT(U_i, S.length, blockIndex);
|
||||
|
||||
for (int i = 0; i < c; i++)
|
||||
{
|
||||
U_i = prf.doFinal(U_i);
|
||||
xor(U_r, U_i);
|
||||
}
|
||||
System.arraycopy(U_r, 0, dest, offset, hLen);
|
||||
}
|
||||
|
||||
protected void xor(byte[] dest, byte[] src)
|
||||
{
|
||||
for (int i = 0; i < dest.length; i++)
|
||||
{
|
||||
dest[i] ^= src[i];
|
||||
}
|
||||
}
|
||||
|
||||
protected void INT(byte[] dest, int offset, int i)
|
||||
{
|
||||
dest[offset + 0] = (byte) (i / (256 * 256 * 256));
|
||||
dest[offset + 1] = (byte) (i / (256 * 256));
|
||||
dest[offset + 2] = (byte) (i / (256));
|
||||
dest[offset + 3] = (byte) (i);
|
||||
}
|
||||
|
||||
public PBKDF2Parameters getParameters()
|
||||
{
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void setParameters(PBKDF2Parameters parameters)
|
||||
{
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public void setPseudoRandomFunction(PRF prf)
|
||||
{
|
||||
this.prf = prf;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.crypto.PBKDF2;
|
||||
|
||||
/*
|
||||
* Source referred from Matthias Gartner's PKCS#5 implementation -
|
||||
* see http://rtner.de/software/PBKDF2.html
|
||||
*/
|
||||
|
||||
class PBKDF2HexFormatter
|
||||
{
|
||||
public boolean fromString(PBKDF2Parameters p, String s)
|
||||
{
|
||||
if (p == null || s == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String[] p123 = s.split(":");
|
||||
if (p123 == null || p123.length != 3)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
byte salt[] = BinTools.hex2bin(p123[0]);
|
||||
int iterationCount = Integer.parseInt(p123[1]);
|
||||
byte bDK[] = BinTools.hex2bin(p123[2]);
|
||||
|
||||
p.setSalt(salt);
|
||||
p.setIterationCount(iterationCount);
|
||||
p.setDerivedKey(bDK);
|
||||
return false;
|
||||
}
|
||||
|
||||
public String toString(PBKDF2Parameters p)
|
||||
{
|
||||
String s = BinTools.bin2hex(p.getSalt()) + ":"
|
||||
+ String.valueOf(p.getIterationCount()) + ":"
|
||||
+ BinTools.bin2hex(p.getDerivedKey());
|
||||
return s;
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.crypto.PBKDF2;
|
||||
/*
|
||||
* Source referred from Matthias Gartner's PKCS#5 implementation -
|
||||
* see http://rtner.de/software/PBKDF2.html
|
||||
*/
|
||||
public class PBKDF2Parameters
|
||||
{
|
||||
protected byte[] salt;
|
||||
|
||||
protected int iterationCount;
|
||||
|
||||
protected String hashAlgorithm;
|
||||
|
||||
protected String hashCharset;
|
||||
|
||||
protected byte[] derivedKey;
|
||||
|
||||
public PBKDF2Parameters()
|
||||
{
|
||||
this.hashAlgorithm = null;
|
||||
this.hashCharset = "UTF-8";
|
||||
this.salt = null;
|
||||
this.iterationCount = 1000;
|
||||
this.derivedKey = null;
|
||||
}
|
||||
|
||||
public PBKDF2Parameters(String hashAlgorithm, String hashCharset,
|
||||
byte[] salt, int iterationCount)
|
||||
{
|
||||
this.hashAlgorithm = hashAlgorithm;
|
||||
this.hashCharset = hashCharset;
|
||||
this.salt = salt;
|
||||
this.iterationCount = iterationCount;
|
||||
this.derivedKey = null;
|
||||
}
|
||||
|
||||
public PBKDF2Parameters(String hashAlgorithm, String hashCharset,
|
||||
byte[] salt, int iterationCount, byte[] derivedKey)
|
||||
{
|
||||
this.hashAlgorithm = hashAlgorithm;
|
||||
this.hashCharset = hashCharset;
|
||||
this.salt = salt;
|
||||
this.iterationCount = iterationCount;
|
||||
this.derivedKey = derivedKey;
|
||||
}
|
||||
|
||||
public int getIterationCount()
|
||||
{
|
||||
return iterationCount;
|
||||
}
|
||||
|
||||
public void setIterationCount(int iterationCount)
|
||||
{
|
||||
this.iterationCount = iterationCount;
|
||||
}
|
||||
|
||||
public byte[] getSalt()
|
||||
{
|
||||
return salt;
|
||||
}
|
||||
|
||||
public void setSalt(byte[] salt)
|
||||
{
|
||||
this.salt = salt;
|
||||
}
|
||||
|
||||
public byte[] getDerivedKey()
|
||||
{
|
||||
return derivedKey;
|
||||
}
|
||||
|
||||
public void setDerivedKey(byte[] derivedKey)
|
||||
{
|
||||
this.derivedKey = derivedKey;
|
||||
}
|
||||
|
||||
public String getHashAlgorithm()
|
||||
{
|
||||
return hashAlgorithm;
|
||||
}
|
||||
|
||||
public void setHashAlgorithm(String hashAlgorithm)
|
||||
{
|
||||
this.hashAlgorithm = hashAlgorithm;
|
||||
}
|
||||
|
||||
public String getHashCharset()
|
||||
{
|
||||
return hashCharset;
|
||||
}
|
||||
|
||||
public void setHashCharset(String hashCharset)
|
||||
{
|
||||
this.hashCharset = hashCharset;
|
||||
}
|
||||
}
|
31
harmony/src/main/java/com/zip4j/crypto/PBKDF2/PRF.java
Normal file
31
harmony/src/main/java/com/zip4j/crypto/PBKDF2/PRF.java
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.crypto.PBKDF2;
|
||||
|
||||
/*
|
||||
* Source referred from Matthias Gartner's PKCS#5 implementation -
|
||||
* see http://rtner.de/software/PBKDF2.html
|
||||
*/
|
||||
|
||||
interface PRF
|
||||
{
|
||||
public void init(byte[] P);
|
||||
|
||||
public byte[] doFinal(byte[] M);
|
||||
|
||||
public int getHLen();
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.crypto;
|
||||
|
||||
import com.zip4j.crypto.engine.ZipCryptoEngine;
|
||||
import com.zip4j.model.FileHeader;
|
||||
import com.zip4j.exception.ZipException;
|
||||
import com.zip4j.exception.ZipExceptionConstants;
|
||||
import com.zip4j.util.InternalZipConstants;
|
||||
|
||||
public class StandardDecrypter implements IDecrypter {
|
||||
|
||||
private FileHeader fileHeader;
|
||||
private byte[] crc = new byte[4];
|
||||
private ZipCryptoEngine zipCryptoEngine;
|
||||
|
||||
public StandardDecrypter(FileHeader fileHeader, byte[] headerBytes) throws ZipException{
|
||||
if (fileHeader == null) {
|
||||
throw new ZipException("one of more of the input parameters were null in StandardDecryptor");
|
||||
}
|
||||
|
||||
this.fileHeader = fileHeader;
|
||||
this.zipCryptoEngine = new ZipCryptoEngine();
|
||||
init(headerBytes);
|
||||
}
|
||||
|
||||
public int decryptData(byte[] buff) throws ZipException {
|
||||
return decryptData(buff, 0, buff.length);
|
||||
}
|
||||
|
||||
public int decryptData(byte[] buff, int start, int len) throws ZipException {
|
||||
if (start < 0 || len < 0) {
|
||||
throw new ZipException("one of the input parameters were null in standard decrpyt data");
|
||||
}
|
||||
|
||||
try {
|
||||
for (int i = 0; i < len; i++) {
|
||||
int val = buff[i] & 0xff;
|
||||
val = (val ^ zipCryptoEngine.decryptByte()) & 0xff;
|
||||
zipCryptoEngine.updateKeys((byte) val);
|
||||
buff[i] = (byte)val;
|
||||
}
|
||||
return len;
|
||||
} catch (Exception e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void init(byte[] headerBytes) throws ZipException {
|
||||
byte[] crcBuff = fileHeader.getCrcBuff();
|
||||
crc[3] = (byte) (crcBuff[3] & 0xFF);
|
||||
crc[2] = (byte) ((crcBuff[3] >> 8) & 0xFF);
|
||||
crc[1] = (byte) ((crcBuff[3] >> 16) & 0xFF);
|
||||
crc[0] = (byte) ((crcBuff[3] >> 24) & 0xFF);
|
||||
|
||||
if(crc[2] > 0 || crc[1] > 0 || crc[0] > 0)
|
||||
throw new IllegalStateException("Invalid CRC in File Header");
|
||||
|
||||
if (fileHeader.getPassword() == null || fileHeader.getPassword().length <= 0) {
|
||||
throw new ZipException("Wrong password!", ZipExceptionConstants.WRONG_PASSWORD);
|
||||
}
|
||||
|
||||
zipCryptoEngine.initKeys(fileHeader.getPassword());
|
||||
|
||||
try {
|
||||
int result = headerBytes[0];
|
||||
for (int i = 0; i < InternalZipConstants.STD_DEC_HDR_SIZE; i++) {
|
||||
// Commented this as this check cannot always be trusted
|
||||
// New functionality: If there is an error in extracting a password protected file,
|
||||
// "Wrong Password?" text is appended to the exception message
|
||||
// if(i+1 == InternalZipConstants.STD_DEC_HDR_SIZE && ((byte)(result ^ zipCryptoEngine.decryptByte()) != crc[3]) && !isSplit)
|
||||
// throw new ZipException("Wrong password!", ZipExceptionConstants.WRONG_PASSWORD);
|
||||
|
||||
zipCryptoEngine.updateKeys((byte) (result ^ zipCryptoEngine.decryptByte()));
|
||||
if (i+1 != InternalZipConstants.STD_DEC_HDR_SIZE)
|
||||
result = headerBytes[i+1];
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
134
harmony/src/main/java/com/zip4j/crypto/StandardEncrypter.java
Normal file
134
harmony/src/main/java/com/zip4j/crypto/StandardEncrypter.java
Normal file
@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.crypto;
|
||||
|
||||
import com.zip4j.crypto.engine.ZipCryptoEngine;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.zip4j.exception.ZipException;
|
||||
import com.zip4j.util.InternalZipConstants;
|
||||
|
||||
public class StandardEncrypter implements IEncrypter {
|
||||
|
||||
private ZipCryptoEngine zipCryptoEngine;
|
||||
private byte[] headerBytes;
|
||||
|
||||
public StandardEncrypter(char[] password, int crc) throws ZipException {
|
||||
if (password == null || password.length <= 0) {
|
||||
throw new ZipException("input password is null or empty in standard encrpyter constructor");
|
||||
}
|
||||
|
||||
this.zipCryptoEngine = new ZipCryptoEngine();
|
||||
|
||||
this.headerBytes = new byte[InternalZipConstants.STD_DEC_HDR_SIZE];
|
||||
init(password, crc);
|
||||
}
|
||||
|
||||
private void init(char[] password, int crc) throws ZipException {
|
||||
if (password == null || password.length <= 0) {
|
||||
throw new ZipException("input password is null or empty, cannot initialize standard encrypter");
|
||||
}
|
||||
zipCryptoEngine.initKeys(password);
|
||||
headerBytes = generateRandomBytes(InternalZipConstants.STD_DEC_HDR_SIZE);
|
||||
// Initialize again since the generated bytes were encrypted.
|
||||
zipCryptoEngine.initKeys(password);
|
||||
|
||||
headerBytes[InternalZipConstants.STD_DEC_HDR_SIZE - 1] = (byte)((crc >>> 24));
|
||||
headerBytes[InternalZipConstants.STD_DEC_HDR_SIZE - 2] = (byte)((crc >>> 16));
|
||||
|
||||
if (headerBytes.length < InternalZipConstants.STD_DEC_HDR_SIZE) {
|
||||
throw new ZipException("invalid header bytes generated, cannot perform standard encryption");
|
||||
}
|
||||
|
||||
encryptData(headerBytes);
|
||||
}
|
||||
|
||||
public int encryptData(byte[] buff) throws ZipException {
|
||||
if (buff == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
return encryptData(buff, 0, buff.length);
|
||||
}
|
||||
|
||||
public int encryptData(byte[] buff, int start, int len) throws ZipException {
|
||||
|
||||
if (len < 0) {
|
||||
throw new ZipException("invalid length specified to decrpyt data");
|
||||
}
|
||||
|
||||
try {
|
||||
for (int i = start; i < start + len; i++) {
|
||||
buff[i] = encryptByte(buff[i]);
|
||||
}
|
||||
return len;
|
||||
} catch (Exception e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected byte encryptByte(byte val) {
|
||||
byte temp_val = (byte) (val ^ zipCryptoEngine.decryptByte() & 0xff);
|
||||
zipCryptoEngine.updateKeys(val);
|
||||
return temp_val;
|
||||
}
|
||||
|
||||
protected byte[] generateRandomBytes(int size) throws ZipException {
|
||||
|
||||
if (size <= 0) {
|
||||
throw new ZipException("size is either 0 or less than 0, cannot generate header for standard encryptor");
|
||||
}
|
||||
|
||||
byte[] buff = new byte[size];
|
||||
|
||||
Random rand = new Random();
|
||||
|
||||
for (int i = 0; i < buff.length; i ++) {
|
||||
// Encrypted to get less predictability for poorly implemented
|
||||
// rand functions.
|
||||
buff[i] = encryptByte((byte) rand.nextInt(256));
|
||||
}
|
||||
|
||||
// buff[0] = (byte)87;
|
||||
// buff[1] = (byte)176;
|
||||
// buff[2] = (byte)-49;
|
||||
// buff[3] = (byte)-43;
|
||||
// buff[4] = (byte)93;
|
||||
// buff[5] = (byte)-204;
|
||||
// buff[6] = (byte)-105;
|
||||
// buff[7] = (byte)213;
|
||||
// buff[8] = (byte)-80;
|
||||
// buff[9] = (byte)-8;
|
||||
// buff[10] = (byte)21;
|
||||
// buff[11] = (byte)242;
|
||||
|
||||
// for( int j=0; j<2; j++ ) {
|
||||
// Random rand = new Random();
|
||||
// int i = rand.nextInt();
|
||||
// buff[0+j*4] = (byte)(i>>24);
|
||||
// buff[1+j*4] = (byte)(i>>16);
|
||||
// buff[2+j*4] = (byte)(i>>8);
|
||||
// buff[3+j*4] = (byte)i;
|
||||
// }
|
||||
return buff;
|
||||
}
|
||||
|
||||
public byte[] getHeaderBytes() {
|
||||
return headerBytes;
|
||||
}
|
||||
|
||||
}
|
291
harmony/src/main/java/com/zip4j/crypto/engine/AESEngine.java
Normal file
291
harmony/src/main/java/com/zip4j/crypto/engine/AESEngine.java
Normal file
@ -0,0 +1,291 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.crypto.engine;
|
||||
|
||||
import com.zip4j.exception.ZipException;
|
||||
import com.zip4j.util.InternalZipConstants;
|
||||
|
||||
/**
|
||||
* Core Engine for AES Encryption
|
||||
* @author Srikanth Reddy Lingala
|
||||
*
|
||||
*/
|
||||
public class AESEngine {
|
||||
|
||||
private int rounds;
|
||||
private int[][] workingKey = null;
|
||||
private int C0, C1, C2, C3;
|
||||
|
||||
public AESEngine(byte[] key) throws ZipException {
|
||||
init(key);
|
||||
}
|
||||
|
||||
public void init(byte[] key) throws ZipException {
|
||||
workingKey = generateWorkingKey(key);
|
||||
}
|
||||
|
||||
private int[][] generateWorkingKey(byte[] key) throws ZipException {
|
||||
int kc = key.length / 4;
|
||||
int t;
|
||||
|
||||
if (((kc != 4) && (kc != 6) && (kc != 8)) || ((kc * 4) != key.length))
|
||||
{
|
||||
throw new ZipException("invalid key length (not 128/192/256)");
|
||||
}
|
||||
|
||||
rounds = kc + 6;
|
||||
int[][] W = new int[rounds+1][4];
|
||||
|
||||
t = 0;
|
||||
int i = 0;
|
||||
while (i < key.length)
|
||||
{
|
||||
W[t >> 2][t & 3] = (key[i]&0xff) | ((key[i+1]&0xff) << 8) | ((key[i+2]&0xff) << 16) | (key[i+3] << 24);
|
||||
i+=4;
|
||||
t++;
|
||||
}
|
||||
|
||||
int k = (rounds + 1) << 2;
|
||||
for (i = kc; (i < k); i++)
|
||||
{
|
||||
int temp = W[(i-1)>>2][(i-1)&3];
|
||||
if ((i % kc) == 0)
|
||||
{
|
||||
temp = subWord(shift(temp, 8)) ^ rcon[(i / kc)-1];
|
||||
}
|
||||
else if ((kc > 6) && ((i % kc) == 4))
|
||||
{
|
||||
temp = subWord(temp);
|
||||
}
|
||||
|
||||
W[i>>2][i&3] = W[(i - kc)>>2][(i-kc)&3] ^ temp;
|
||||
}
|
||||
return W;
|
||||
}
|
||||
|
||||
public int processBlock(byte[] in, byte[] out) throws ZipException {
|
||||
return processBlock(in, 0, out, 0);
|
||||
}
|
||||
|
||||
public int processBlock(byte[] in, int inOff, byte[] out, int outOff) throws ZipException {
|
||||
if (workingKey == null)
|
||||
{
|
||||
throw new ZipException("AES engine not initialised");
|
||||
}
|
||||
|
||||
if ((inOff + (32 / 2)) > in.length)
|
||||
{
|
||||
throw new ZipException("input buffer too short");
|
||||
}
|
||||
|
||||
if ((outOff + (32 / 2)) > out.length)
|
||||
{
|
||||
throw new ZipException("output buffer too short");
|
||||
}
|
||||
|
||||
stateIn(in, inOff);
|
||||
encryptBlock(workingKey);
|
||||
stateOut(out, outOff);
|
||||
|
||||
return InternalZipConstants.AES_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
private final void stateIn(byte[] bytes, int off) {
|
||||
int index = off;
|
||||
|
||||
C0 = (bytes[index++] & 0xff);
|
||||
C0 |= (bytes[index++] & 0xff) << 8;
|
||||
C0 |= (bytes[index++] & 0xff) << 16;
|
||||
C0 |= bytes[index++] << 24;
|
||||
|
||||
C1 = (bytes[index++] & 0xff);
|
||||
C1 |= (bytes[index++] & 0xff) << 8;
|
||||
C1 |= (bytes[index++] & 0xff) << 16;
|
||||
C1 |= bytes[index++] << 24;
|
||||
|
||||
C2 = (bytes[index++] & 0xff);
|
||||
C2 |= (bytes[index++] & 0xff) << 8;
|
||||
C2 |= (bytes[index++] & 0xff) << 16;
|
||||
C2 |= bytes[index++] << 24;
|
||||
|
||||
C3 = (bytes[index++] & 0xff);
|
||||
C3 |= (bytes[index++] & 0xff) << 8;
|
||||
C3 |= (bytes[index++] & 0xff) << 16;
|
||||
C3 |= bytes[index++] << 24;
|
||||
}
|
||||
|
||||
private final void stateOut(byte[] bytes, int off) {
|
||||
int index = off;
|
||||
|
||||
bytes[index++] = (byte)C0;
|
||||
bytes[index++] = (byte)(C0 >> 8);
|
||||
bytes[index++] = (byte)(C0 >> 16);
|
||||
bytes[index++] = (byte)(C0 >> 24);
|
||||
|
||||
bytes[index++] = (byte)C1;
|
||||
bytes[index++] = (byte)(C1 >> 8);
|
||||
bytes[index++] = (byte)(C1 >> 16);
|
||||
bytes[index++] = (byte)(C1 >> 24);
|
||||
|
||||
bytes[index++] = (byte)C2;
|
||||
bytes[index++] = (byte)(C2 >> 8);
|
||||
bytes[index++] = (byte)(C2 >> 16);
|
||||
bytes[index++] = (byte)(C2 >> 24);
|
||||
|
||||
bytes[index++] = (byte)C3;
|
||||
bytes[index++] = (byte)(C3 >> 8);
|
||||
bytes[index++] = (byte)(C3 >> 16);
|
||||
bytes[index++] = (byte)(C3 >> 24);
|
||||
}
|
||||
|
||||
private final void encryptBlock(int[][] KW) {
|
||||
int r, r0, r1, r2, r3;
|
||||
|
||||
C0 ^= KW[0][0];
|
||||
C1 ^= KW[0][1];
|
||||
C2 ^= KW[0][2];
|
||||
C3 ^= KW[0][3];
|
||||
|
||||
r = 1;
|
||||
|
||||
while (r < rounds - 1)
|
||||
{
|
||||
r0 = T0[C0&255] ^ shift(T0[(C1>>8)&255], 24) ^ shift(T0[(C2>>16)&255],16) ^ shift(T0[(C3>>24)&255],8) ^ KW[r][0];
|
||||
r1 = T0[C1&255] ^ shift(T0[(C2>>8)&255], 24) ^ shift(T0[(C3>>16)&255], 16) ^ shift(T0[(C0>>24)&255], 8) ^ KW[r][1];
|
||||
r2 = T0[C2&255] ^ shift(T0[(C3>>8)&255], 24) ^ shift(T0[(C0>>16)&255], 16) ^ shift(T0[(C1>>24)&255], 8) ^ KW[r][2];
|
||||
r3 = T0[C3&255] ^ shift(T0[(C0>>8)&255], 24) ^ shift(T0[(C1>>16)&255], 16) ^ shift(T0[(C2>>24)&255], 8) ^ KW[r++][3];
|
||||
C0 = T0[r0&255] ^ shift(T0[(r1>>8)&255], 24) ^ shift(T0[(r2>>16)&255], 16) ^ shift(T0[(r3>>24)&255], 8) ^ KW[r][0];
|
||||
C1 = T0[r1&255] ^ shift(T0[(r2>>8)&255], 24) ^ shift(T0[(r3>>16)&255], 16) ^ shift(T0[(r0>>24)&255], 8) ^ KW[r][1];
|
||||
C2 = T0[r2&255] ^ shift(T0[(r3>>8)&255], 24) ^ shift(T0[(r0>>16)&255], 16) ^ shift(T0[(r1>>24)&255], 8) ^ KW[r][2];
|
||||
C3 = T0[r3&255] ^ shift(T0[(r0>>8)&255], 24) ^ shift(T0[(r1>>16)&255], 16) ^ shift(T0[(r2>>24)&255], 8) ^ KW[r++][3];
|
||||
}
|
||||
|
||||
r0 = T0[C0&255] ^ shift(T0[(C1>>8)&255], 24) ^ shift(T0[(C2>>16)&255], 16) ^ shift(T0[(C3>>24)&255], 8) ^ KW[r][0];
|
||||
r1 = T0[C1&255] ^ shift(T0[(C2>>8)&255], 24) ^ shift(T0[(C3>>16)&255], 16) ^ shift(T0[(C0>>24)&255], 8) ^ KW[r][1];
|
||||
r2 = T0[C2&255] ^ shift(T0[(C3>>8)&255], 24) ^ shift(T0[(C0>>16)&255], 16) ^ shift(T0[(C1>>24)&255], 8) ^ KW[r][2];
|
||||
r3 = T0[C3&255] ^ shift(T0[(C0>>8)&255], 24) ^ shift(T0[(C1>>16)&255], 16) ^ shift(T0[(C2>>24)&255], 8) ^ KW[r++][3];
|
||||
|
||||
C0 = (S[r0&255]&255) ^ ((S[(r1>>8)&255]&255)<<8) ^ ((S[(r2>>16)&255]&255)<<16) ^ (S[(r3>>24)&255]<<24) ^ KW[r][0];
|
||||
C1 = (S[r1&255]&255) ^ ((S[(r2>>8)&255]&255)<<8) ^ ((S[(r3>>16)&255]&255)<<16) ^ (S[(r0>>24)&255]<<24) ^ KW[r][1];
|
||||
C2 = (S[r2&255]&255) ^ ((S[(r3>>8)&255]&255)<<8) ^ ((S[(r0>>16)&255]&255)<<16) ^ (S[(r1>>24)&255]<<24) ^ KW[r][2];
|
||||
C3 = (S[r3&255]&255) ^ ((S[(r0>>8)&255]&255)<<8) ^ ((S[(r1>>16)&255]&255)<<16) ^ (S[(r2>>24)&255]<<24) ^ KW[r][3];
|
||||
|
||||
}
|
||||
|
||||
private int shift(int r, int shift) {
|
||||
return (r >>> shift) | (r << -shift);
|
||||
}
|
||||
|
||||
private int subWord(int x) {
|
||||
return (S[x&255]&255 | ((S[(x>>8)&255]&255)<<8) | ((S[(x>>16)&255]&255)<<16) | S[(x>>24)&255]<<24);
|
||||
}
|
||||
|
||||
private static final byte[] S = {
|
||||
(byte)99, (byte)124, (byte)119, (byte)123, (byte)242, (byte)107, (byte)111, (byte)197,
|
||||
(byte)48, (byte)1, (byte)103, (byte)43, (byte)254, (byte)215, (byte)171, (byte)118,
|
||||
(byte)202, (byte)130, (byte)201, (byte)125, (byte)250, (byte)89, (byte)71, (byte)240,
|
||||
(byte)173, (byte)212, (byte)162, (byte)175, (byte)156, (byte)164, (byte)114, (byte)192,
|
||||
(byte)183, (byte)253, (byte)147, (byte)38, (byte)54, (byte)63, (byte)247, (byte)204,
|
||||
(byte)52, (byte)165, (byte)229, (byte)241, (byte)113, (byte)216, (byte)49, (byte)21,
|
||||
(byte)4, (byte)199, (byte)35, (byte)195, (byte)24, (byte)150, (byte)5, (byte)154,
|
||||
(byte)7, (byte)18, (byte)128, (byte)226, (byte)235, (byte)39, (byte)178, (byte)117,
|
||||
(byte)9, (byte)131, (byte)44, (byte)26, (byte)27, (byte)110, (byte)90, (byte)160,
|
||||
(byte)82, (byte)59, (byte)214, (byte)179, (byte)41, (byte)227, (byte)47, (byte)132,
|
||||
(byte)83, (byte)209, (byte)0, (byte)237, (byte)32, (byte)252, (byte)177, (byte)91,
|
||||
(byte)106, (byte)203, (byte)190, (byte)57, (byte)74, (byte)76, (byte)88, (byte)207,
|
||||
(byte)208, (byte)239, (byte)170, (byte)251, (byte)67, (byte)77, (byte)51, (byte)133,
|
||||
(byte)69, (byte)249, (byte)2, (byte)127, (byte)80, (byte)60, (byte)159, (byte)168,
|
||||
(byte)81, (byte)163, (byte)64, (byte)143, (byte)146, (byte)157, (byte)56, (byte)245,
|
||||
(byte)188, (byte)182, (byte)218, (byte)33, (byte)16, (byte)255, (byte)243, (byte)210,
|
||||
(byte)205, (byte)12, (byte)19, (byte)236, (byte)95, (byte)151, (byte)68, (byte)23,
|
||||
(byte)196, (byte)167, (byte)126, (byte)61, (byte)100, (byte)93, (byte)25, (byte)115,
|
||||
(byte)96, (byte)129, (byte)79, (byte)220, (byte)34, (byte)42, (byte)144, (byte)136,
|
||||
(byte)70, (byte)238, (byte)184, (byte)20, (byte)222, (byte)94, (byte)11, (byte)219,
|
||||
(byte)224, (byte)50, (byte)58, (byte)10, (byte)73, (byte)6, (byte)36, (byte)92,
|
||||
(byte)194, (byte)211, (byte)172, (byte)98, (byte)145, (byte)149, (byte)228, (byte)121,
|
||||
(byte)231, (byte)200, (byte)55, (byte)109, (byte)141, (byte)213, (byte)78, (byte)169,
|
||||
(byte)108, (byte)86, (byte)244, (byte)234, (byte)101, (byte)122, (byte)174, (byte)8,
|
||||
(byte)186, (byte)120, (byte)37, (byte)46, (byte)28, (byte)166, (byte)180, (byte)198,
|
||||
(byte)232, (byte)221, (byte)116, (byte)31, (byte)75, (byte)189, (byte)139, (byte)138,
|
||||
(byte)112, (byte)62, (byte)181, (byte)102, (byte)72, (byte)3, (byte)246, (byte)14,
|
||||
(byte)97, (byte)53, (byte)87, (byte)185, (byte)134, (byte)193, (byte)29, (byte)158,
|
||||
(byte)225, (byte)248, (byte)152, (byte)17, (byte)105, (byte)217, (byte)142, (byte)148,
|
||||
(byte)155, (byte)30, (byte)135, (byte)233, (byte)206, (byte)85, (byte)40, (byte)223,
|
||||
(byte)140, (byte)161, (byte)137, (byte)13, (byte)191, (byte)230, (byte)66, (byte)104,
|
||||
(byte)65, (byte)153, (byte)45, (byte)15, (byte)176, (byte)84, (byte)187, (byte)22,
|
||||
};
|
||||
|
||||
private static final int[] rcon = {
|
||||
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a,
|
||||
0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91 };
|
||||
|
||||
private static final int[] T0 =
|
||||
{
|
||||
0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6, 0x0df2f2ff,
|
||||
0xbd6b6bd6, 0xb16f6fde, 0x54c5c591, 0x50303060, 0x03010102,
|
||||
0xa96767ce, 0x7d2b2b56, 0x19fefee7, 0x62d7d7b5, 0xe6abab4d,
|
||||
0x9a7676ec, 0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa,
|
||||
0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb, 0xecadad41,
|
||||
0x67d4d4b3, 0xfda2a25f, 0xeaafaf45, 0xbf9c9c23, 0xf7a4a453,
|
||||
0x967272e4, 0x5bc0c09b, 0xc2b7b775, 0x1cfdfde1, 0xae93933d,
|
||||
0x6a26264c, 0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83,
|
||||
0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9, 0x937171e2,
|
||||
0x73d8d8ab, 0x53313162, 0x3f15152a, 0x0c040408, 0x52c7c795,
|
||||
0x65232346, 0x5ec3c39d, 0x28181830, 0xa1969637, 0x0f05050a,
|
||||
0xb59a9a2f, 0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df,
|
||||
0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea, 0x1b090912,
|
||||
0x9e83831d, 0x742c2c58, 0x2e1a1a34, 0x2d1b1b36, 0xb26e6edc,
|
||||
0xee5a5ab4, 0xfba0a05b, 0xf65252a4, 0x4d3b3b76, 0x61d6d6b7,
|
||||
0xceb3b37d, 0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413,
|
||||
0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1, 0x60202040,
|
||||
0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6, 0xbe6a6ad4, 0x46cbcb8d,
|
||||
0xd9bebe67, 0x4b393972, 0xde4a4a94, 0xd44c4c98, 0xe85858b0,
|
||||
0x4acfcf85, 0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed,
|
||||
0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511, 0xcf45458a,
|
||||
0x10f9f9e9, 0x06020204, 0x817f7ffe, 0xf05050a0, 0x443c3c78,
|
||||
0xba9f9f25, 0xe3a8a84b, 0xf35151a2, 0xfea3a35d, 0xc0404080,
|
||||
0x8a8f8f05, 0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1,
|
||||
0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142, 0x30101020,
|
||||
0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf, 0x4ccdcd81, 0x140c0c18,
|
||||
0x35131326, 0x2fececc3, 0xe15f5fbe, 0xa2979735, 0xcc444488,
|
||||
0x3917172e, 0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a,
|
||||
0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6, 0xa06060c0,
|
||||
0x98818119, 0xd14f4f9e, 0x7fdcdca3, 0x66222244, 0x7e2a2a54,
|
||||
0xab90903b, 0x8388880b, 0xca46468c, 0x29eeeec7, 0xd3b8b86b,
|
||||
0x3c141428, 0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad,
|
||||
0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14, 0xdb494992,
|
||||
0x0a06060c, 0x6c242448, 0xe45c5cb8, 0x5dc2c29f, 0x6ed3d3bd,
|
||||
0xefacac43, 0xa66262c4, 0xa8919139, 0xa4959531, 0x37e4e4d3,
|
||||
0x8b7979f2, 0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda,
|
||||
0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949, 0xb46c6cd8,
|
||||
0xfa5656ac, 0x07f4f4f3, 0x25eaeacf, 0xaf6565ca, 0x8e7a7af4,
|
||||
0xe9aeae47, 0x18080810, 0xd5baba6f, 0x887878f0, 0x6f25254a,
|
||||
0x722e2e5c, 0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697,
|
||||
0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e, 0xdd4b4b96,
|
||||
0xdcbdbd61, 0x868b8b0d, 0x858a8a0f, 0x907070e0, 0x423e3e7c,
|
||||
0xc4b5b571, 0xaa6666cc, 0xd8484890, 0x05030306, 0x01f6f6f7,
|
||||
0x120e0e1c, 0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969,
|
||||
0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27, 0x38e1e1d9,
|
||||
0x13f8f8eb, 0xb398982b, 0x33111122, 0xbb6969d2, 0x70d9d9a9,
|
||||
0x898e8e07, 0xa7949433, 0xb69b9b2d, 0x221e1e3c, 0x92878715,
|
||||
0x20e9e9c9, 0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5,
|
||||
0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a, 0xdabfbf65,
|
||||
0x31e6e6d7, 0xc6424284, 0xb86868d0, 0xc3414182, 0xb0999929,
|
||||
0x772d2d5a, 0x110f0f1e, 0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d,
|
||||
0x3a16162c};
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.crypto.engine;
|
||||
|
||||
public class ZipCryptoEngine {
|
||||
|
||||
private final int keys[] = new int[3];
|
||||
private static final int[] CRC_TABLE = new int[256];
|
||||
|
||||
static {
|
||||
for (int i = 0; i < 256; i++) {
|
||||
int r = i;
|
||||
for (int j = 0; j < 8; j++) {
|
||||
if ((r & 1) == 1) {
|
||||
r = (r >>> 1) ^ 0xedb88320;
|
||||
} else {
|
||||
r >>>= 1;
|
||||
}
|
||||
}
|
||||
CRC_TABLE[i] = r;
|
||||
}
|
||||
}
|
||||
|
||||
public ZipCryptoEngine() {
|
||||
}
|
||||
|
||||
public void initKeys(char[] password) {
|
||||
keys[0] = 305419896;
|
||||
keys[1] = 591751049;
|
||||
keys[2] = 878082192;
|
||||
for (int i = 0; i < password.length; i++) {
|
||||
updateKeys((byte) (password[i] & 0xff));
|
||||
}
|
||||
}
|
||||
|
||||
public void updateKeys(byte charAt) {
|
||||
keys[0] = crc32(keys[0], charAt);
|
||||
keys[1] += keys[0] & 0xff;
|
||||
keys[1] = keys[1] * 134775813 + 1;
|
||||
keys[2] = crc32(keys[2], (byte) (keys[1] >> 24));
|
||||
}
|
||||
|
||||
private int crc32(int oldCrc, byte charAt) {
|
||||
return ((oldCrc >>> 8) ^ CRC_TABLE[(oldCrc ^ charAt) & 0xff]);
|
||||
}
|
||||
|
||||
public byte decryptByte() {
|
||||
int temp = keys[2] | 2;
|
||||
return (byte) ((temp * (temp ^ 1)) >>> 8);
|
||||
}
|
||||
}
|
59
harmony/src/main/java/com/zip4j/exception/ZipException.java
Normal file
59
harmony/src/main/java/com/zip4j/exception/ZipException.java
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.exception;
|
||||
|
||||
public class ZipException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int code = -1;
|
||||
|
||||
public ZipException() {
|
||||
}
|
||||
|
||||
public ZipException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public ZipException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ZipException(String msg, int code) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public ZipException(String message, Throwable cause, int code) {
|
||||
super(message, cause);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public ZipException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public ZipException(Throwable cause, int code) {
|
||||
super(cause);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.exception;
|
||||
|
||||
public interface ZipExceptionConstants {
|
||||
|
||||
public static int inputZipParamIsNull = 0001;
|
||||
|
||||
public static int constuctorFileNotFoundException = 0002;
|
||||
|
||||
public static int randomAccessFileNull = 0003;
|
||||
|
||||
public static int notZipFile = 0004;
|
||||
|
||||
public static int WRONG_PASSWORD = 0005;
|
||||
|
||||
}
|
25
harmony/src/main/java/com/zip4j/io/BaseInputStream.java
Normal file
25
harmony/src/main/java/com/zip4j/io/BaseInputStream.java
Normal file
@ -0,0 +1,25 @@
|
||||
package com.zip4j.io;
|
||||
|
||||
import com.zip4j.unzip.UnzipEngine;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public abstract class BaseInputStream extends InputStream {
|
||||
|
||||
public int read() throws IOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void seek(long pos) throws IOException {
|
||||
}
|
||||
|
||||
public int available() throws IOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public UnzipEngine getUnzipEngine() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
27
harmony/src/main/java/com/zip4j/io/BaseOutputStream.java
Normal file
27
harmony/src/main/java/com/zip4j/io/BaseOutputStream.java
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public abstract class BaseOutputStream extends OutputStream {
|
||||
|
||||
public void write(int b) throws IOException {
|
||||
}
|
||||
|
||||
}
|
574
harmony/src/main/java/com/zip4j/io/CipherOutputStream.java
Normal file
574
harmony/src/main/java/com/zip4j/io/CipherOutputStream.java
Normal file
@ -0,0 +1,574 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.io;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
import com.zip4j.core.HeaderWriter;
|
||||
import com.zip4j.crypto.AESEncrpyter;
|
||||
import com.zip4j.crypto.IEncrypter;
|
||||
import com.zip4j.crypto.StandardEncrypter;
|
||||
import com.zip4j.exception.ZipException;
|
||||
import com.zip4j.model.AESExtraDataRecord;
|
||||
import com.zip4j.model.CentralDirectory;
|
||||
import com.zip4j.model.EndCentralDirRecord;
|
||||
import com.zip4j.model.FileHeader;
|
||||
import com.zip4j.model.LocalFileHeader;
|
||||
import com.zip4j.model.ZipModel;
|
||||
import com.zip4j.model.ZipParameters;
|
||||
import com.zip4j.util.InternalZipConstants;
|
||||
import com.zip4j.util.Raw;
|
||||
import com.zip4j.util.Zip4jConstants;
|
||||
import com.zip4j.util.Zip4jUtil;
|
||||
|
||||
public class CipherOutputStream extends BaseOutputStream {
|
||||
|
||||
protected OutputStream outputStream;
|
||||
private File sourceFile;
|
||||
protected FileHeader fileHeader;
|
||||
protected LocalFileHeader localFileHeader;
|
||||
private IEncrypter encrypter;
|
||||
protected ZipParameters zipParameters;
|
||||
protected ZipModel zipModel;
|
||||
private long totalBytesWritten;
|
||||
protected CRC32 crc;
|
||||
private long bytesWrittenForThisFile;
|
||||
private byte[] pendingBuffer;
|
||||
private int pendingBufferLength;
|
||||
private long totalBytesRead;
|
||||
|
||||
public CipherOutputStream(OutputStream outputStream, ZipModel zipModel) {
|
||||
this.outputStream = outputStream;
|
||||
initZipModel(zipModel);
|
||||
crc = new CRC32();
|
||||
this.totalBytesWritten = 0;
|
||||
this.bytesWrittenForThisFile = 0;
|
||||
this.pendingBuffer = new byte[InternalZipConstants.AES_BLOCK_SIZE];
|
||||
this.pendingBufferLength = 0;
|
||||
this.totalBytesRead = 0;
|
||||
}
|
||||
|
||||
public void putNextEntry(File file, ZipParameters zipParameters) throws ZipException {
|
||||
if (!zipParameters.isSourceExternalStream() && file == null) {
|
||||
throw new ZipException("input file is null");
|
||||
}
|
||||
|
||||
if (!zipParameters.isSourceExternalStream() && !Zip4jUtil.checkFileExists(file)) {
|
||||
throw new ZipException("input file does not exist");
|
||||
}
|
||||
|
||||
if (zipParameters == null) {
|
||||
zipParameters = new ZipParameters();
|
||||
}
|
||||
|
||||
try {
|
||||
sourceFile = file;
|
||||
|
||||
this.zipParameters = (ZipParameters)zipParameters.clone();
|
||||
|
||||
if (!zipParameters.isSourceExternalStream()) {
|
||||
if (sourceFile.isDirectory()) {
|
||||
this.zipParameters.setEncryptFiles(false);
|
||||
this.zipParameters.setEncryptionMethod(-1);
|
||||
this.zipParameters.setCompressionMethod(Zip4jConstants.COMP_STORE);
|
||||
}
|
||||
} else {
|
||||
if (!Zip4jUtil.isStringNotNullAndNotEmpty(this.zipParameters.getFileNameInZip())) {
|
||||
throw new ZipException("file name is empty for external stream");
|
||||
}
|
||||
if (this.zipParameters.getFileNameInZip().endsWith("/") ||
|
||||
this.zipParameters.getFileNameInZip().endsWith("\\")) {
|
||||
this.zipParameters.setEncryptFiles(false);
|
||||
this.zipParameters.setEncryptionMethod(-1);
|
||||
this.zipParameters.setCompressionMethod(Zip4jConstants.COMP_STORE);
|
||||
}
|
||||
}
|
||||
|
||||
createFileHeader();
|
||||
createLocalFileHeader();
|
||||
|
||||
if (zipModel.isSplitArchive()) {
|
||||
if (zipModel.getCentralDirectory() == null ||
|
||||
zipModel.getCentralDirectory().getFileHeaders() == null ||
|
||||
zipModel.getCentralDirectory().getFileHeaders().size() == 0) {
|
||||
byte[] intByte = new byte[4];
|
||||
Raw.writeIntLittleEndian(intByte, 0, (int)InternalZipConstants.SPLITSIG);
|
||||
outputStream.write(intByte);
|
||||
totalBytesWritten += 4;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.outputStream instanceof SplitOutputStream) {
|
||||
if (totalBytesWritten == 4) {
|
||||
fileHeader.setOffsetLocalHeader(4);
|
||||
} else {
|
||||
fileHeader.setOffsetLocalHeader(((SplitOutputStream)outputStream).getFilePointer());
|
||||
}
|
||||
} else {
|
||||
if (totalBytesWritten == 4) {
|
||||
fileHeader.setOffsetLocalHeader(4);
|
||||
} else {
|
||||
fileHeader.setOffsetLocalHeader(totalBytesWritten);
|
||||
}
|
||||
}
|
||||
|
||||
HeaderWriter headerWriter = new HeaderWriter();
|
||||
totalBytesWritten += headerWriter.writeLocalFileHeader(zipModel, localFileHeader, outputStream);
|
||||
|
||||
if (this.zipParameters.isEncryptFiles()) {
|
||||
initEncrypter();
|
||||
if (encrypter != null) {
|
||||
if (zipParameters.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_STANDARD) {
|
||||
byte[] headerBytes = ((StandardEncrypter)encrypter).getHeaderBytes();
|
||||
outputStream.write(headerBytes);
|
||||
totalBytesWritten += headerBytes.length;
|
||||
bytesWrittenForThisFile += headerBytes.length;
|
||||
} else if (zipParameters.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_AES) {
|
||||
byte[] saltBytes = ((AESEncrpyter)encrypter).getSaltBytes();
|
||||
byte[] passwordVerifier = ((AESEncrpyter)encrypter).getDerivedPasswordVerifier();
|
||||
outputStream.write(saltBytes);
|
||||
outputStream.write(passwordVerifier);
|
||||
totalBytesWritten += saltBytes.length + passwordVerifier.length;
|
||||
bytesWrittenForThisFile += saltBytes.length + passwordVerifier.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
crc.reset();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new ZipException(e);
|
||||
} catch (ZipException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void initEncrypter() throws ZipException {
|
||||
if (!zipParameters.isEncryptFiles()) {
|
||||
encrypter = null;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (zipParameters.getEncryptionMethod()) {
|
||||
case Zip4jConstants.ENC_METHOD_STANDARD:
|
||||
// Since we do not know the crc here, we use the modification time for encrypting.
|
||||
encrypter = new StandardEncrypter(zipParameters.getPassword(), (localFileHeader.getLastModFileTime() & 0x0000ffff) << 16);
|
||||
break;
|
||||
case Zip4jConstants.ENC_METHOD_AES:
|
||||
encrypter = new AESEncrpyter(zipParameters.getPassword(), zipParameters.getAesKeyStrength());
|
||||
break;
|
||||
default:
|
||||
throw new ZipException("invalid encprytion method");
|
||||
}
|
||||
}
|
||||
|
||||
private void initZipModel(ZipModel zipModel) {
|
||||
if (zipModel == null) {
|
||||
this.zipModel = new ZipModel();
|
||||
} else {
|
||||
this.zipModel = zipModel;
|
||||
}
|
||||
|
||||
if (this.zipModel.getEndCentralDirRecord() == null)
|
||||
this.zipModel.setEndCentralDirRecord(new EndCentralDirRecord());
|
||||
|
||||
if (this.zipModel.getCentralDirectory() == null)
|
||||
this.zipModel.setCentralDirectory(new CentralDirectory());
|
||||
|
||||
if (this.zipModel.getCentralDirectory().getFileHeaders() == null)
|
||||
this.zipModel.getCentralDirectory().setFileHeaders(new ArrayList());
|
||||
|
||||
if (this.zipModel.getLocalFileHeaderList() == null)
|
||||
this.zipModel.setLocalFileHeaderList(new ArrayList());
|
||||
|
||||
if (this.outputStream instanceof SplitOutputStream) {
|
||||
if (((SplitOutputStream)outputStream).isSplitZipFile()) {
|
||||
this.zipModel.setSplitArchive(true);
|
||||
this.zipModel.setSplitLength(((SplitOutputStream)outputStream).getSplitLength());
|
||||
}
|
||||
}
|
||||
|
||||
this.zipModel.getEndCentralDirRecord().setSignature(InternalZipConstants.ENDSIG);
|
||||
}
|
||||
|
||||
public void write(int bval) throws IOException {
|
||||
byte[] b = new byte[1];
|
||||
b[0] = (byte) bval;
|
||||
write(b, 0, 1);
|
||||
}
|
||||
|
||||
public void write(byte[] b) throws IOException {
|
||||
if (b == null)
|
||||
throw new NullPointerException();
|
||||
|
||||
if (b.length == 0) return;
|
||||
|
||||
write(b, 0, b.length);
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
if (len == 0) return;
|
||||
|
||||
if (zipParameters.isEncryptFiles() &&
|
||||
zipParameters.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_AES) {
|
||||
if (pendingBufferLength != 0) {
|
||||
if (len >= (InternalZipConstants.AES_BLOCK_SIZE - pendingBufferLength)) {
|
||||
System.arraycopy(b, off, pendingBuffer, pendingBufferLength,
|
||||
(InternalZipConstants.AES_BLOCK_SIZE - pendingBufferLength));
|
||||
encryptAndWrite(pendingBuffer, 0, pendingBuffer.length);
|
||||
off = (InternalZipConstants.AES_BLOCK_SIZE - pendingBufferLength);
|
||||
len = len - off;
|
||||
pendingBufferLength = 0;
|
||||
} else {
|
||||
System.arraycopy(b, off, pendingBuffer, pendingBufferLength,
|
||||
len);
|
||||
pendingBufferLength += len;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (len != 0 && len % 16 != 0) {
|
||||
System.arraycopy(b, (len + off) - (len % 16), pendingBuffer, 0, len % 16);
|
||||
pendingBufferLength = len % 16;
|
||||
len = len - pendingBufferLength;
|
||||
}
|
||||
}
|
||||
if (len != 0)
|
||||
encryptAndWrite(b, off, len);
|
||||
}
|
||||
|
||||
private void encryptAndWrite(byte[] b, int off, int len) throws IOException {
|
||||
if (encrypter != null) {
|
||||
try {
|
||||
encrypter.encryptData(b, off, len);
|
||||
} catch (ZipException e) {
|
||||
throw new IOException(e.getMessage());
|
||||
}
|
||||
}
|
||||
outputStream.write(b, off, len);
|
||||
totalBytesWritten += len;
|
||||
bytesWrittenForThisFile += len;
|
||||
}
|
||||
|
||||
public void closeEntry() throws IOException, ZipException {
|
||||
|
||||
if (this.pendingBufferLength != 0) {
|
||||
encryptAndWrite(pendingBuffer, 0, pendingBufferLength);
|
||||
pendingBufferLength = 0;
|
||||
}
|
||||
|
||||
if (this.zipParameters.isEncryptFiles() &&
|
||||
this.zipParameters.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_AES) {
|
||||
if (encrypter instanceof AESEncrpyter) {
|
||||
outputStream.write(((AESEncrpyter)encrypter).getFinalMac());
|
||||
bytesWrittenForThisFile += 10;
|
||||
totalBytesWritten += 10;
|
||||
} else {
|
||||
throw new ZipException("invalid encrypter for AES encrypted file");
|
||||
}
|
||||
}
|
||||
fileHeader.setCompressedSize(bytesWrittenForThisFile);
|
||||
localFileHeader.setCompressedSize(bytesWrittenForThisFile);
|
||||
|
||||
if (zipParameters.isSourceExternalStream()) {
|
||||
fileHeader.setUncompressedSize(totalBytesRead);
|
||||
if (localFileHeader.getUncompressedSize() != totalBytesRead) {
|
||||
localFileHeader.setUncompressedSize(totalBytesRead);
|
||||
}
|
||||
}
|
||||
|
||||
long crc32 = crc.getValue();
|
||||
if (fileHeader.isEncrypted()) {
|
||||
if (fileHeader.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_AES) {
|
||||
crc32 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (zipParameters.isEncryptFiles() &&
|
||||
zipParameters.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_AES) {
|
||||
fileHeader.setCrc32(0);
|
||||
localFileHeader.setCrc32(0);
|
||||
} else {
|
||||
fileHeader.setCrc32(crc32);
|
||||
localFileHeader.setCrc32(crc32);
|
||||
}
|
||||
|
||||
zipModel.getLocalFileHeaderList().add(localFileHeader);
|
||||
zipModel.getCentralDirectory().getFileHeaders().add(fileHeader);
|
||||
|
||||
HeaderWriter headerWriter = new HeaderWriter();
|
||||
totalBytesWritten += headerWriter.writeExtendedLocalHeader(localFileHeader, outputStream);
|
||||
|
||||
crc.reset();
|
||||
bytesWrittenForThisFile = 0;
|
||||
encrypter = null;
|
||||
totalBytesRead = 0;
|
||||
}
|
||||
|
||||
public void finish() throws IOException, ZipException {
|
||||
zipModel.getEndCentralDirRecord().setOffsetOfStartOfCentralDir(totalBytesWritten);
|
||||
|
||||
HeaderWriter headerWriter = new HeaderWriter();
|
||||
headerWriter.finalizeZipFile(zipModel, outputStream);
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
if (outputStream != null)
|
||||
outputStream.close();
|
||||
}
|
||||
|
||||
private void createFileHeader() throws ZipException {
|
||||
this.fileHeader = new FileHeader();
|
||||
fileHeader.setSignature((int)InternalZipConstants.CENSIG);
|
||||
fileHeader.setVersionMadeBy(20);
|
||||
fileHeader.setVersionNeededToExtract(20);
|
||||
if (zipParameters.isEncryptFiles() &&
|
||||
zipParameters.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_AES) {
|
||||
fileHeader.setCompressionMethod(Zip4jConstants.ENC_METHOD_AES);
|
||||
fileHeader.setAesExtraDataRecord(generateAESExtraDataRecord(zipParameters));
|
||||
} else {
|
||||
fileHeader.setCompressionMethod(zipParameters.getCompressionMethod());
|
||||
}
|
||||
if (zipParameters.isEncryptFiles()) {
|
||||
fileHeader.setEncrypted(true);
|
||||
fileHeader.setEncryptionMethod(zipParameters.getEncryptionMethod());
|
||||
}
|
||||
String fileName = null;
|
||||
if (zipParameters.isSourceExternalStream()) {
|
||||
fileHeader.setLastModFileTime((int) Zip4jUtil.javaToDosTime(System.currentTimeMillis()));
|
||||
if (!Zip4jUtil.isStringNotNullAndNotEmpty(zipParameters.getFileNameInZip())) {
|
||||
throw new ZipException("fileNameInZip is null or empty");
|
||||
}
|
||||
fileName = zipParameters.getFileNameInZip();
|
||||
} else {
|
||||
fileHeader.setLastModFileTime((int) Zip4jUtil.javaToDosTime((Zip4jUtil.getLastModifiedFileTime(
|
||||
sourceFile, zipParameters.getTimeZone()))));
|
||||
fileHeader.setUncompressedSize(sourceFile.length());
|
||||
fileName = Zip4jUtil.getRelativeFileName(
|
||||
sourceFile.getAbsolutePath(), zipParameters.getRootFolderInZip(), zipParameters.getDefaultFolderPath());
|
||||
|
||||
}
|
||||
|
||||
if (!Zip4jUtil.isStringNotNullAndNotEmpty(fileName)) {
|
||||
throw new ZipException("fileName is null or empty. unable to create file header");
|
||||
}
|
||||
|
||||
fileHeader.setFileName(fileName);
|
||||
|
||||
if (Zip4jUtil.isStringNotNullAndNotEmpty(zipModel.getFileNameCharset())) {
|
||||
fileHeader.setFileNameLength(Zip4jUtil.getEncodedStringLength(fileName,
|
||||
zipModel.getFileNameCharset()));
|
||||
} else {
|
||||
fileHeader.setFileNameLength(Zip4jUtil.getEncodedStringLength(fileName));
|
||||
}
|
||||
|
||||
if (outputStream instanceof SplitOutputStream) {
|
||||
fileHeader.setDiskNumberStart(((SplitOutputStream)outputStream).getCurrSplitFileCounter());
|
||||
} else {
|
||||
fileHeader.setDiskNumberStart(0);
|
||||
}
|
||||
|
||||
int fileAttrs = 0;
|
||||
if (!zipParameters.isSourceExternalStream())
|
||||
fileAttrs = getFileAttributes(sourceFile);
|
||||
byte[] externalFileAttrs = {(byte)fileAttrs, 0, 0, 0};
|
||||
fileHeader.setExternalFileAttr(externalFileAttrs);
|
||||
|
||||
if (zipParameters.isSourceExternalStream()) {
|
||||
fileHeader.setDirectory(fileName.endsWith("/") || fileName.endsWith("\\"));
|
||||
} else {
|
||||
fileHeader.setDirectory(this.sourceFile.isDirectory());
|
||||
}
|
||||
if (fileHeader.isDirectory()) {
|
||||
fileHeader.setCompressedSize(0);
|
||||
fileHeader.setUncompressedSize(0);
|
||||
} else {
|
||||
if (!zipParameters.isSourceExternalStream()) {
|
||||
long fileSize = Zip4jUtil.getFileLengh(sourceFile);
|
||||
if (zipParameters.getCompressionMethod() == Zip4jConstants.COMP_STORE) {
|
||||
if (zipParameters.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_STANDARD) {
|
||||
fileHeader.setCompressedSize(fileSize
|
||||
+ InternalZipConstants.STD_DEC_HDR_SIZE);
|
||||
} else if (zipParameters.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_AES) {
|
||||
int saltLength = 0;
|
||||
switch (zipParameters.getAesKeyStrength()) {
|
||||
case Zip4jConstants.AES_STRENGTH_128:
|
||||
saltLength = 8;
|
||||
break;
|
||||
case Zip4jConstants.AES_STRENGTH_256:
|
||||
saltLength = 16;
|
||||
break;
|
||||
default:
|
||||
throw new ZipException("invalid aes key strength, cannot determine key sizes");
|
||||
}
|
||||
fileHeader.setCompressedSize(fileSize + saltLength
|
||||
+ InternalZipConstants.AES_AUTH_LENGTH + 2); //2 is password verifier
|
||||
} else {
|
||||
fileHeader.setCompressedSize(0);
|
||||
}
|
||||
} else {
|
||||
fileHeader.setCompressedSize(0);
|
||||
}
|
||||
fileHeader.setUncompressedSize(fileSize);
|
||||
}
|
||||
}
|
||||
if (zipParameters.isEncryptFiles() &&
|
||||
zipParameters.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_STANDARD) {
|
||||
fileHeader.setCrc32(zipParameters.getSourceFileCRC());
|
||||
}
|
||||
byte[] shortByte = new byte[2];
|
||||
shortByte[0] = Raw.bitArrayToByte(generateGeneralPurposeBitArray(
|
||||
fileHeader.isEncrypted(), zipParameters.getCompressionMethod()));
|
||||
boolean isFileNameCharsetSet = Zip4jUtil.isStringNotNullAndNotEmpty(zipModel.getFileNameCharset());
|
||||
if ((isFileNameCharsetSet &&
|
||||
zipModel.getFileNameCharset().equalsIgnoreCase(InternalZipConstants.CHARSET_UTF8)) ||
|
||||
(!isFileNameCharsetSet &&
|
||||
Zip4jUtil.detectCharSet(fileHeader.getFileName()).equals(InternalZipConstants.CHARSET_UTF8))) {
|
||||
shortByte[1] = 8;
|
||||
} else {
|
||||
shortByte[1] = 0;
|
||||
}
|
||||
fileHeader.setGeneralPurposeFlag(shortByte);
|
||||
}
|
||||
|
||||
private void createLocalFileHeader() throws ZipException {
|
||||
if (fileHeader == null) {
|
||||
throw new ZipException("file header is null, cannot create local file header");
|
||||
}
|
||||
this.localFileHeader = new LocalFileHeader();
|
||||
localFileHeader.setSignature((int)InternalZipConstants.LOCSIG);
|
||||
localFileHeader.setVersionNeededToExtract(fileHeader.getVersionNeededToExtract());
|
||||
localFileHeader.setCompressionMethod(fileHeader.getCompressionMethod());
|
||||
localFileHeader.setLastModFileTime(fileHeader.getLastModFileTime());
|
||||
localFileHeader.setUncompressedSize(fileHeader.getUncompressedSize());
|
||||
localFileHeader.setFileNameLength(fileHeader.getFileNameLength());
|
||||
localFileHeader.setFileName(fileHeader.getFileName());
|
||||
localFileHeader.setEncrypted(fileHeader.isEncrypted());
|
||||
localFileHeader.setEncryptionMethod(fileHeader.getEncryptionMethod());
|
||||
localFileHeader.setAesExtraDataRecord(fileHeader.getAesExtraDataRecord());
|
||||
localFileHeader.setCrc32(fileHeader.getCrc32());
|
||||
localFileHeader.setCompressedSize(fileHeader.getCompressedSize());
|
||||
localFileHeader.setGeneralPurposeFlag((byte[])fileHeader.getGeneralPurposeFlag().clone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the file attributes and returns an integer
|
||||
* @param file
|
||||
* @return
|
||||
* @throws ZipException
|
||||
*/
|
||||
private int getFileAttributes(File file) throws ZipException {
|
||||
if (file == null) {
|
||||
throw new ZipException("input file is null, cannot get file attributes");
|
||||
}
|
||||
|
||||
if (!file.exists()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (file.isDirectory()) {
|
||||
if (file.isHidden()) {
|
||||
return InternalZipConstants.FOLDER_MODE_HIDDEN;
|
||||
} else {
|
||||
return InternalZipConstants.FOLDER_MODE_NONE;
|
||||
}
|
||||
} else {
|
||||
if (!file.canWrite() && file.isHidden()) {
|
||||
return InternalZipConstants.FILE_MODE_READ_ONLY_HIDDEN;
|
||||
} else if (!file.canWrite()) {
|
||||
return InternalZipConstants.FILE_MODE_READ_ONLY;
|
||||
} else if (file.isHidden()) {
|
||||
return InternalZipConstants.FILE_MODE_HIDDEN;
|
||||
} else {
|
||||
return InternalZipConstants.FILE_MODE_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int[] generateGeneralPurposeBitArray(boolean isEncrpyted, int compressionMethod) {
|
||||
|
||||
int[] generalPurposeBits = new int[8];
|
||||
if (isEncrpyted) {
|
||||
generalPurposeBits[0] = 1;
|
||||
} else {
|
||||
generalPurposeBits[0] = 0;
|
||||
}
|
||||
|
||||
if (compressionMethod == Zip4jConstants.COMP_DEFLATE) {
|
||||
// Have to set flags for deflate
|
||||
} else {
|
||||
generalPurposeBits[1] = 0;
|
||||
generalPurposeBits[2] = 0;
|
||||
}
|
||||
|
||||
generalPurposeBits[3] = 1;
|
||||
|
||||
return generalPurposeBits;
|
||||
}
|
||||
|
||||
private AESExtraDataRecord generateAESExtraDataRecord(ZipParameters parameters) throws ZipException {
|
||||
|
||||
if (parameters == null) {
|
||||
throw new ZipException("zip parameters are null, cannot generate AES Extra Data record");
|
||||
}
|
||||
|
||||
AESExtraDataRecord aesDataRecord = new AESExtraDataRecord();
|
||||
aesDataRecord.setSignature(InternalZipConstants.AESSIG);
|
||||
aesDataRecord.setDataSize(7);
|
||||
aesDataRecord.setVendorID("AE");
|
||||
// Always set the version number to 2 as we do not store CRC for any AES encrypted files
|
||||
// only MAC is stored and as per the specification, if version number is 2, then MAC is read
|
||||
// and CRC is ignored
|
||||
aesDataRecord.setVersionNumber(2);
|
||||
if (parameters.getAesKeyStrength() == Zip4jConstants.AES_STRENGTH_128) {
|
||||
aesDataRecord.setAesStrength(Zip4jConstants.AES_STRENGTH_128);
|
||||
} else if (parameters.getAesKeyStrength() == Zip4jConstants.AES_STRENGTH_256) {
|
||||
aesDataRecord.setAesStrength(Zip4jConstants.AES_STRENGTH_256);
|
||||
} else {
|
||||
throw new ZipException("invalid AES key strength, cannot generate AES Extra data record");
|
||||
}
|
||||
aesDataRecord.setCompressionMethod(parameters.getCompressionMethod());
|
||||
|
||||
return aesDataRecord;
|
||||
}
|
||||
|
||||
public void decrementCompressedFileSize(int value) {
|
||||
if (value <= 0) return;
|
||||
|
||||
if (value <= this.bytesWrittenForThisFile) {
|
||||
this.bytesWrittenForThisFile -= value;
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateTotalBytesRead(int toUpdate) {
|
||||
if (toUpdate > 0) {
|
||||
totalBytesRead += toUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
public void setSourceFile(File sourceFile) {
|
||||
this.sourceFile = sourceFile;
|
||||
}
|
||||
|
||||
public File getSourceFile() {
|
||||
return sourceFile;
|
||||
}
|
||||
}
|
115
harmony/src/main/java/com/zip4j/io/DeflaterOutputStream.java
Normal file
115
harmony/src/main/java/com/zip4j/io/DeflaterOutputStream.java
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.io;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
import com.zip4j.exception.ZipException;
|
||||
import com.zip4j.model.ZipModel;
|
||||
import com.zip4j.model.ZipParameters;
|
||||
import com.zip4j.util.InternalZipConstants;
|
||||
import com.zip4j.util.Zip4jConstants;
|
||||
|
||||
public class DeflaterOutputStream extends CipherOutputStream {
|
||||
|
||||
private byte[] buff;
|
||||
protected Deflater deflater;
|
||||
private boolean firstBytesRead;
|
||||
|
||||
public DeflaterOutputStream(OutputStream outputStream, ZipModel zipModel) {
|
||||
super(outputStream, zipModel);
|
||||
deflater = new Deflater();
|
||||
buff = new byte[InternalZipConstants.BUFF_SIZE];
|
||||
firstBytesRead = false;
|
||||
}
|
||||
|
||||
public void putNextEntry(File file, ZipParameters zipParameters)
|
||||
throws ZipException {
|
||||
super.putNextEntry(file, zipParameters);
|
||||
if (zipParameters.getCompressionMethod() == Zip4jConstants.COMP_DEFLATE) {
|
||||
deflater.reset();
|
||||
if ((zipParameters.getCompressionLevel() < 0 || zipParameters
|
||||
.getCompressionLevel() > 9)
|
||||
&& zipParameters.getCompressionLevel() != -1) {
|
||||
throw new ZipException(
|
||||
"invalid compression level for deflater. compression level should be in the range of 0-9");
|
||||
}
|
||||
deflater.setLevel(zipParameters.getCompressionLevel());
|
||||
}
|
||||
}
|
||||
|
||||
public void write(byte[] b) throws IOException {
|
||||
write(b, 0, b.length);
|
||||
}
|
||||
|
||||
private void deflate () throws IOException {
|
||||
int len = deflater.deflate(buff, 0, buff.length);
|
||||
if (len > 0) {
|
||||
if (deflater.finished()) {
|
||||
if (len == 4) return;
|
||||
if (len < 4) {
|
||||
decrementCompressedFileSize(4 - len);
|
||||
return;
|
||||
}
|
||||
len -= 4;
|
||||
}
|
||||
if (!firstBytesRead) {
|
||||
super.write(buff, 2, len - 2);
|
||||
firstBytesRead = true;
|
||||
} else {
|
||||
super.write(buff, 0, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void write(int bval) throws IOException {
|
||||
byte[] b = new byte[1];
|
||||
b[0] = (byte) bval;
|
||||
write(b, 0, 1);
|
||||
}
|
||||
|
||||
public void write(byte[] buf, int off, int len) throws IOException {
|
||||
if (zipParameters.getCompressionMethod() != Zip4jConstants.COMP_DEFLATE) {
|
||||
super.write(buf, off, len);
|
||||
} else {
|
||||
deflater.setInput(buf, off, len);
|
||||
while (!deflater.needsInput()) {
|
||||
deflate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void closeEntry() throws IOException, ZipException {
|
||||
if (zipParameters.getCompressionMethod() == Zip4jConstants.COMP_DEFLATE) {
|
||||
if (!deflater.finished()) {
|
||||
deflater.finish();
|
||||
while (!deflater.finished()) {
|
||||
deflate();
|
||||
}
|
||||
}
|
||||
firstBytesRead = false;
|
||||
}
|
||||
super.closeEntry();
|
||||
}
|
||||
|
||||
public void finish() throws IOException, ZipException {
|
||||
super.finish();
|
||||
}
|
||||
}
|
161
harmony/src/main/java/com/zip4j/io/InflaterInputStream.java
Normal file
161
harmony/src/main/java/com/zip4j/io/InflaterInputStream.java
Normal file
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.io;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
import com.zip4j.unzip.UnzipEngine;
|
||||
import com.zip4j.util.InternalZipConstants;
|
||||
import com.zip4j.util.Zip4jConstants;
|
||||
|
||||
public class InflaterInputStream extends PartInputStream {
|
||||
|
||||
private Inflater inflater;
|
||||
private byte[] buff;
|
||||
private byte[] oneByteBuff = new byte[1];
|
||||
private UnzipEngine unzipEngine;
|
||||
private long bytesWritten;
|
||||
private long uncompressedSize;
|
||||
|
||||
public InflaterInputStream(RandomAccessFile raf, long start, long len, UnzipEngine unzipEngine) {
|
||||
super(raf, start, len, unzipEngine);
|
||||
this.inflater = new Inflater(true);
|
||||
this.buff = new byte[InternalZipConstants.BUFF_SIZE];
|
||||
this.unzipEngine = unzipEngine;
|
||||
bytesWritten = 0;
|
||||
uncompressedSize = unzipEngine.getFileHeader().getUncompressedSize();
|
||||
}
|
||||
|
||||
public int read() throws IOException {
|
||||
return read(oneByteBuff, 0, 1) == -1 ? -1 : oneByteBuff[0] & 0xff;
|
||||
}
|
||||
|
||||
public int read(byte[] b) throws IOException {
|
||||
if (b == null) {
|
||||
throw new NullPointerException("input buffer is null");
|
||||
}
|
||||
|
||||
return read(b, 0, b.length);
|
||||
}
|
||||
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
|
||||
if (b == null) {
|
||||
throw new NullPointerException("input buffer is null");
|
||||
} else if (off < 0 || len < 0 || len > b.length - off) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
} else if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
try {
|
||||
int n;
|
||||
if (bytesWritten >= uncompressedSize)
|
||||
return -1;
|
||||
while ((n = inflater.inflate(b, off, len)) == 0) {
|
||||
if (inflater.finished() || inflater.needsDictionary()) {
|
||||
return -1;
|
||||
}
|
||||
if (inflater.needsInput()) {
|
||||
fill();
|
||||
}
|
||||
}
|
||||
bytesWritten += n;
|
||||
return n;
|
||||
} catch (DataFormatException e) {
|
||||
String s = "Invalid ZLIB data format";
|
||||
if (e.getMessage() != null) {
|
||||
s = e.getMessage();
|
||||
}
|
||||
if (unzipEngine != null) {
|
||||
if (unzipEngine.getLocalFileHeader().isEncrypted() &&
|
||||
unzipEngine.getLocalFileHeader().getEncryptionMethod() == Zip4jConstants.ENC_METHOD_STANDARD) {
|
||||
s += " - Wrong Password?";
|
||||
}
|
||||
}
|
||||
throw new IOException(s);
|
||||
}
|
||||
}
|
||||
|
||||
private void fill() throws IOException {
|
||||
int len = super.read(buff, 0, buff.length);
|
||||
if (len == -1) {
|
||||
throw new EOFException("Unexpected end of ZLIB input stream");
|
||||
}
|
||||
inflater.setInput(buff, 0, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips specified number of bytes of uncompressed data.
|
||||
* @param n the number of bytes to skip
|
||||
* @return the actual number of bytes skipped.
|
||||
* @exception IOException if an I/O error has occurred
|
||||
* @exception IllegalArgumentException if n < 0
|
||||
*/
|
||||
public long skip(long n) throws IOException {
|
||||
if (n < 0) {
|
||||
throw new IllegalArgumentException("negative skip length");
|
||||
}
|
||||
int max = (int)Math.min(n, Integer.MAX_VALUE);
|
||||
int total = 0;
|
||||
byte[] b = new byte[512];
|
||||
while (total < max) {
|
||||
int len = max - total;
|
||||
if (len > b.length) {
|
||||
len = b.length;
|
||||
}
|
||||
len = read(b, 0, len);
|
||||
if (len == -1) {
|
||||
break;
|
||||
}
|
||||
total += len;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
public void seek(long pos) throws IOException {
|
||||
super.seek(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 0 after EOF has been reached, otherwise always return 1.
|
||||
* <p>
|
||||
* Programs should not count on this method to return the actual number
|
||||
* of bytes that could be read without blocking.
|
||||
*
|
||||
* @return 1 before EOF and 0 after EOF.
|
||||
* @exception IOException if an I/O error occurs.
|
||||
*
|
||||
*/
|
||||
public int available() {
|
||||
return inflater.finished() ? 0 : 1;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
inflater.end();
|
||||
super.close();
|
||||
}
|
||||
|
||||
public UnzipEngine getUnzipEngine() {
|
||||
return super.getUnzipEngine();
|
||||
}
|
||||
}
|
172
harmony/src/main/java/com/zip4j/io/PartInputStream.java
Normal file
172
harmony/src/main/java/com/zip4j/io/PartInputStream.java
Normal file
@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
import com.zip4j.crypto.AESDecrypter;
|
||||
import com.zip4j.crypto.IDecrypter;
|
||||
import com.zip4j.exception.ZipException;
|
||||
import com.zip4j.unzip.UnzipEngine;
|
||||
import com.zip4j.util.InternalZipConstants;
|
||||
import com.zip4j.util.Zip4jConstants;
|
||||
|
||||
public class PartInputStream extends BaseInputStream
|
||||
{
|
||||
private RandomAccessFile raf;
|
||||
private long bytesRead, length;
|
||||
private UnzipEngine unzipEngine;
|
||||
private IDecrypter decrypter;
|
||||
private byte[] oneByteBuff = new byte[1];
|
||||
private byte[] aesBlockByte = new byte[16];
|
||||
private int aesBytesReturned = 0;
|
||||
private boolean isAESEncryptedFile = false;
|
||||
private int count = -1;
|
||||
|
||||
public PartInputStream(RandomAccessFile raf, long start, long len, UnzipEngine unzipEngine) {
|
||||
this.raf = raf;
|
||||
this.unzipEngine = unzipEngine;
|
||||
this.decrypter = unzipEngine.getDecrypter();
|
||||
this.bytesRead = 0;
|
||||
this.length = len;
|
||||
this.isAESEncryptedFile = unzipEngine.getFileHeader().isEncrypted() &&
|
||||
unzipEngine.getFileHeader().getEncryptionMethod() == Zip4jConstants.ENC_METHOD_AES;
|
||||
}
|
||||
|
||||
public int available() {
|
||||
long amount = length - bytesRead;
|
||||
if (amount > Integer.MAX_VALUE)
|
||||
return Integer.MAX_VALUE;
|
||||
return (int) amount;
|
||||
}
|
||||
|
||||
public int read() throws IOException {
|
||||
if (bytesRead >= length)
|
||||
return -1;
|
||||
|
||||
if (isAESEncryptedFile) {
|
||||
if (aesBytesReturned == 0 || aesBytesReturned == 16) {
|
||||
if (read(aesBlockByte) == -1) {
|
||||
return -1;
|
||||
}
|
||||
aesBytesReturned = 0;
|
||||
}
|
||||
return aesBlockByte[aesBytesReturned++] & 0xff;
|
||||
} else {
|
||||
return read(oneByteBuff, 0, 1) == -1 ? -1 : oneByteBuff[0] & 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
public int read(byte[] b) throws IOException {
|
||||
return read(b, 0, b.length);
|
||||
}
|
||||
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
if (len > length - bytesRead) {
|
||||
len = (int) (length - bytesRead);
|
||||
if (len == 0) {
|
||||
checkAndReadAESMacBytes();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (unzipEngine.getDecrypter() instanceof AESDecrypter) {
|
||||
if (bytesRead + len < length) {
|
||||
if (len % 16 != 0) {
|
||||
len = len - (len%16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
synchronized (raf) {
|
||||
count = raf.read(b, off, len);
|
||||
if ((count < len) && unzipEngine.getZipModel().isSplitArchive()) {
|
||||
raf.close();
|
||||
raf = unzipEngine.startNextSplitFile();
|
||||
if (count < 0) count = 0;
|
||||
int newlyRead = raf.read(b, count, len-count);
|
||||
if (newlyRead > 0)
|
||||
count += newlyRead;
|
||||
}
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
if (decrypter != null) {
|
||||
try {
|
||||
decrypter.decryptData(b, off, count);
|
||||
} catch (ZipException e) {
|
||||
throw new IOException(e.getMessage());
|
||||
}
|
||||
}
|
||||
bytesRead += count;
|
||||
}
|
||||
|
||||
if (bytesRead >= length) {
|
||||
checkAndReadAESMacBytes();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private void checkAndReadAESMacBytes() throws IOException {
|
||||
if (isAESEncryptedFile) {
|
||||
if (decrypter != null && decrypter instanceof AESDecrypter) {
|
||||
if (((AESDecrypter)decrypter).getStoredMac() != null) {
|
||||
//Stored mac already set
|
||||
return;
|
||||
}
|
||||
byte[] macBytes = new byte[InternalZipConstants.AES_AUTH_LENGTH];
|
||||
int readLen = -1;
|
||||
readLen = raf.read(macBytes);
|
||||
if (readLen != InternalZipConstants.AES_AUTH_LENGTH) {
|
||||
if (unzipEngine.getZipModel().isSplitArchive()) {
|
||||
raf.close();
|
||||
raf = unzipEngine.startNextSplitFile();
|
||||
int newlyRead = raf.read(macBytes, readLen, InternalZipConstants.AES_AUTH_LENGTH - readLen);
|
||||
readLen += newlyRead;
|
||||
} else {
|
||||
throw new IOException("Error occured while reading stored AES authentication bytes");
|
||||
}
|
||||
}
|
||||
|
||||
((AESDecrypter)unzipEngine.getDecrypter()).setStoredMac(macBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public long skip(long amount) throws IOException {
|
||||
if (amount < 0)
|
||||
throw new IllegalArgumentException();
|
||||
if (amount > length - bytesRead)
|
||||
amount = length - bytesRead;
|
||||
bytesRead += amount;
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
raf.close();
|
||||
}
|
||||
|
||||
public void seek(long pos) throws IOException {
|
||||
raf.seek(pos);
|
||||
}
|
||||
|
||||
public UnzipEngine getUnzipEngine() {
|
||||
return this.unzipEngine;
|
||||
}
|
||||
}
|
235
harmony/src/main/java/com/zip4j/io/SplitOutputStream.java
Normal file
235
harmony/src/main/java/com/zip4j/io/SplitOutputStream.java
Normal file
@ -0,0 +1,235 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.io;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
import com.zip4j.exception.ZipException;
|
||||
import com.zip4j.util.InternalZipConstants;
|
||||
import com.zip4j.util.Raw;
|
||||
import com.zip4j.util.Zip4jUtil;
|
||||
|
||||
public class SplitOutputStream extends OutputStream {
|
||||
|
||||
private RandomAccessFile raf;
|
||||
private long splitLength;
|
||||
private File zipFile;
|
||||
private File outFile;
|
||||
private int currSplitFileCounter;
|
||||
private long bytesWrittenForThisPart;
|
||||
|
||||
public SplitOutputStream(String name) throws FileNotFoundException, ZipException {
|
||||
this(Zip4jUtil.isStringNotNullAndNotEmpty(name) ?
|
||||
new File(name) : null);
|
||||
}
|
||||
|
||||
public SplitOutputStream(File file) throws FileNotFoundException, ZipException {
|
||||
this(file, -1);
|
||||
}
|
||||
|
||||
public SplitOutputStream(String name, long splitLength) throws FileNotFoundException, ZipException {
|
||||
this(!Zip4jUtil.isStringNotNullAndNotEmpty(name) ?
|
||||
new File(name) : null, splitLength);
|
||||
}
|
||||
|
||||
public SplitOutputStream(File file, long splitLength) throws FileNotFoundException, ZipException {
|
||||
if (splitLength >= 0 && splitLength < InternalZipConstants.MIN_SPLIT_LENGTH) {
|
||||
throw new ZipException("split length less than minimum allowed split length of " + InternalZipConstants.MIN_SPLIT_LENGTH +" Bytes");
|
||||
}
|
||||
this.raf = new RandomAccessFile(file, InternalZipConstants.WRITE_MODE);
|
||||
this.splitLength = splitLength;
|
||||
this.outFile = file;
|
||||
this.zipFile = file;
|
||||
this.currSplitFileCounter = 0;
|
||||
this.bytesWrittenForThisPart = 0;
|
||||
}
|
||||
|
||||
public void write(int b) throws IOException {
|
||||
byte[] buff = new byte[1];
|
||||
buff[0] = (byte) b;
|
||||
write(buff, 0, 1);
|
||||
}
|
||||
|
||||
public void write(byte[] b) throws IOException {
|
||||
write(b, 0, b.length);
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
if (len <= 0) return;
|
||||
|
||||
if (splitLength != -1) {
|
||||
|
||||
if (splitLength < InternalZipConstants.MIN_SPLIT_LENGTH) {
|
||||
throw new IOException("split length less than minimum allowed split length of " + InternalZipConstants.MIN_SPLIT_LENGTH +" Bytes");
|
||||
}
|
||||
|
||||
if (bytesWrittenForThisPart >= splitLength) {
|
||||
startNextSplitFile();
|
||||
raf.write(b, off, len);
|
||||
bytesWrittenForThisPart = len;
|
||||
} else if (bytesWrittenForThisPart + len > splitLength) {
|
||||
if (isHeaderData(b)) {
|
||||
startNextSplitFile();
|
||||
raf.write(b, off, len);
|
||||
bytesWrittenForThisPart = len;
|
||||
} else {
|
||||
raf.write(b, off, (int)(splitLength - bytesWrittenForThisPart));
|
||||
startNextSplitFile();
|
||||
raf.write(b, off + (int)(splitLength - bytesWrittenForThisPart), (int)(len - (splitLength - bytesWrittenForThisPart)));
|
||||
bytesWrittenForThisPart = len - (splitLength - bytesWrittenForThisPart);
|
||||
}
|
||||
} else {
|
||||
raf.write(b, off, len);
|
||||
bytesWrittenForThisPart += len;
|
||||
}
|
||||
|
||||
} else {
|
||||
raf.write(b, off, len);
|
||||
bytesWrittenForThisPart += len;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void startNextSplitFile() throws IOException {
|
||||
try {
|
||||
String zipFileWithoutExt = Zip4jUtil.getZipFileNameWithoutExt(outFile.getName());
|
||||
File currSplitFile = null;
|
||||
String zipFileName = zipFile.getAbsolutePath();
|
||||
|
||||
if (currSplitFileCounter < 9) {
|
||||
currSplitFile = new File(outFile.getParent() + System.getProperty("file.separator") +
|
||||
zipFileWithoutExt + ".z0" + (currSplitFileCounter + 1));
|
||||
} else {
|
||||
currSplitFile = new File(outFile.getParent() + System.getProperty("file.separator") +
|
||||
zipFileWithoutExt + ".z" + (currSplitFileCounter + 1));
|
||||
}
|
||||
|
||||
raf.close();
|
||||
|
||||
if (currSplitFile.exists()) {
|
||||
throw new IOException("split file: " + currSplitFile.getName() + " already exists in the current directory, cannot rename this file");
|
||||
}
|
||||
|
||||
if (!zipFile.renameTo(currSplitFile)) {
|
||||
throw new IOException("cannot rename newly created split file");
|
||||
}
|
||||
|
||||
zipFile = new File(zipFileName);
|
||||
raf = new RandomAccessFile(zipFile, InternalZipConstants.WRITE_MODE);
|
||||
currSplitFileCounter++;
|
||||
} catch (ZipException e) {
|
||||
throw new IOException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isHeaderData(byte[] buff) {
|
||||
if (buff == null || buff.length < 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int signature = Raw.readIntLittleEndian(buff, 0);
|
||||
long[] allHeaderSignatures = Zip4jUtil.getAllHeaderSignatures();
|
||||
if (allHeaderSignatures != null && allHeaderSignatures.length > 0) {
|
||||
for (int i = 0; i < allHeaderSignatures.length; i++) {
|
||||
//Ignore split signature
|
||||
if (allHeaderSignatures[i] != InternalZipConstants.SPLITSIG &&
|
||||
allHeaderSignatures[i] == signature) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the buffer size is sufficient for the current split file. If not
|
||||
* a new split file will be started.
|
||||
* @param bufferSize
|
||||
* @return true if a new split file was started else false
|
||||
* @throws ZipException
|
||||
*/
|
||||
public boolean checkBuffSizeAndStartNextSplitFile(int bufferSize) throws ZipException {
|
||||
if (bufferSize < 0) {
|
||||
throw new ZipException("negative buffersize for checkBuffSizeAndStartNextSplitFile");
|
||||
}
|
||||
|
||||
if (!isBuffSizeFitForCurrSplitFile(bufferSize)) {
|
||||
try {
|
||||
startNextSplitFile();
|
||||
bytesWrittenForThisPart = 0;
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
throw new ZipException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given buffer size will be fit in the current split file.
|
||||
* If this output stream is a non-split file, then this method always returns true
|
||||
* @param bufferSize
|
||||
* @return true if the buffer size is fit in the current split file or else false.
|
||||
* @throws ZipException
|
||||
*/
|
||||
public boolean isBuffSizeFitForCurrSplitFile(int bufferSize) throws ZipException {
|
||||
if (bufferSize < 0) {
|
||||
throw new ZipException("negative buffersize for isBuffSizeFitForCurrSplitFile");
|
||||
}
|
||||
|
||||
if (splitLength >= InternalZipConstants.MIN_SPLIT_LENGTH) {
|
||||
return (bytesWrittenForThisPart + bufferSize <= splitLength);
|
||||
} else {
|
||||
//Non split zip -- return true
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void seek(long pos) throws IOException {
|
||||
raf.seek(pos);
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
if (raf != null)
|
||||
raf.close();
|
||||
}
|
||||
|
||||
public void flush() throws IOException {
|
||||
}
|
||||
|
||||
public long getFilePointer() throws IOException {
|
||||
return raf.getFilePointer();
|
||||
}
|
||||
|
||||
public boolean isSplitZipFile() {
|
||||
return splitLength!=-1;
|
||||
}
|
||||
|
||||
public long getSplitLength() {
|
||||
return splitLength;
|
||||
}
|
||||
|
||||
public int getCurrSplitFileCounter() {
|
||||
return currSplitFileCounter;
|
||||
}
|
||||
}
|
89
harmony/src/main/java/com/zip4j/io/ZipInputStream.java
Normal file
89
harmony/src/main/java/com/zip4j/io/ZipInputStream.java
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.io;
|
||||
|
||||
import com.zip4j.exception.ZipException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class ZipInputStream extends InputStream {
|
||||
|
||||
private BaseInputStream is;
|
||||
|
||||
public ZipInputStream(BaseInputStream is) {
|
||||
this.is = is;
|
||||
}
|
||||
|
||||
public int read() throws IOException {
|
||||
int readByte = is.read();
|
||||
if (readByte != -1) {
|
||||
is.getUnzipEngine().updateCRC(readByte);
|
||||
}
|
||||
return readByte;
|
||||
}
|
||||
|
||||
public int read(byte[] b) throws IOException {
|
||||
return read(b, 0, b.length);
|
||||
}
|
||||
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
int readLen = is.read(b, off, len);
|
||||
if (readLen > 0 && is.getUnzipEngine() != null) {
|
||||
is.getUnzipEngine().updateCRC(b, off, readLen);
|
||||
}
|
||||
return readLen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the input stream and releases any resources.
|
||||
* This method also checks for the CRC of the extracted file.
|
||||
* If CRC check has to be skipped use close(boolean skipCRCCheck) method
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
close(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the input stream and releases any resources.
|
||||
* If skipCRCCheck flag is set to true, this method skips CRC Check
|
||||
* of the extracted file
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void close(boolean skipCRCCheck) throws IOException {
|
||||
try {
|
||||
is.close();
|
||||
if (!skipCRCCheck && is.getUnzipEngine() != null) {
|
||||
is.getUnzipEngine().checkCRC();
|
||||
}
|
||||
} catch (ZipException e) {
|
||||
throw new IOException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public int available() throws IOException {
|
||||
return is.available();
|
||||
}
|
||||
|
||||
public long skip(long n) throws IOException {
|
||||
return is.skip(n);
|
||||
}
|
||||
|
||||
}
|
33
harmony/src/main/java/com/zip4j/io/ZipOutputStream.java
Normal file
33
harmony/src/main/java/com/zip4j/io/ZipOutputStream.java
Normal file
@ -0,0 +1,33 @@
|
||||
package com.zip4j.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import com.zip4j.model.ZipModel;
|
||||
|
||||
public class ZipOutputStream extends DeflaterOutputStream {
|
||||
|
||||
public ZipOutputStream(OutputStream outputStream) {
|
||||
this(outputStream, null);
|
||||
}
|
||||
|
||||
public ZipOutputStream(OutputStream outputStream, ZipModel zipModel) {
|
||||
super(outputStream, zipModel);
|
||||
}
|
||||
|
||||
public void write(int bval) throws IOException {
|
||||
byte[] b = new byte[1];
|
||||
b[0] = (byte) bval;
|
||||
write(b, 0, 1);
|
||||
}
|
||||
|
||||
public void write(byte[] b) throws IOException {
|
||||
write(b, 0, b.length);
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
crc.update(b, off, len);
|
||||
updateTotalBytesRead(len);
|
||||
super.write(b, off, len);
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.model;
|
||||
|
||||
public class AESExtraDataRecord {
|
||||
|
||||
private long signature;
|
||||
private int dataSize;
|
||||
private int versionNumber;
|
||||
private String vendorID;
|
||||
private int aesStrength;
|
||||
private int compressionMethod;
|
||||
|
||||
public AESExtraDataRecord() {
|
||||
signature = -1;
|
||||
dataSize = -1;
|
||||
versionNumber = -1;
|
||||
vendorID = null;
|
||||
aesStrength = -1;
|
||||
compressionMethod = -1;
|
||||
}
|
||||
|
||||
|
||||
public long getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
|
||||
public void setSignature(long signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
|
||||
public int getDataSize() {
|
||||
return dataSize;
|
||||
}
|
||||
|
||||
|
||||
public void setDataSize(int dataSize) {
|
||||
this.dataSize = dataSize;
|
||||
}
|
||||
|
||||
|
||||
public int getVersionNumber() {
|
||||
return versionNumber;
|
||||
}
|
||||
|
||||
|
||||
public void setVersionNumber(int versionNumber) {
|
||||
this.versionNumber = versionNumber;
|
||||
}
|
||||
|
||||
|
||||
public String getVendorID() {
|
||||
return vendorID;
|
||||
}
|
||||
|
||||
|
||||
public void setVendorID(String vendorID) {
|
||||
this.vendorID = vendorID;
|
||||
}
|
||||
|
||||
|
||||
public int getAesStrength() {
|
||||
return aesStrength;
|
||||
}
|
||||
|
||||
|
||||
public void setAesStrength(int aesStrength) {
|
||||
this.aesStrength = aesStrength;
|
||||
}
|
||||
|
||||
|
||||
public int getCompressionMethod() {
|
||||
return compressionMethod;
|
||||
}
|
||||
|
||||
|
||||
public void setCompressionMethod(int compressionMethod) {
|
||||
this.compressionMethod = compressionMethod;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.model;
|
||||
|
||||
public class ArchiveExtraDataRecord {
|
||||
|
||||
private int signature;
|
||||
|
||||
private int extraFieldLength;
|
||||
|
||||
private String extraFieldData;
|
||||
|
||||
public int getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public void setSignature(int signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public int getExtraFieldLength() {
|
||||
return extraFieldLength;
|
||||
}
|
||||
|
||||
public void setExtraFieldLength(int extraFieldLength) {
|
||||
this.extraFieldLength = extraFieldLength;
|
||||
}
|
||||
|
||||
public String getExtraFieldData() {
|
||||
return extraFieldData;
|
||||
}
|
||||
|
||||
public void setExtraFieldData(String extraFieldData) {
|
||||
this.extraFieldData = extraFieldData;
|
||||
}
|
||||
|
||||
}
|
44
harmony/src/main/java/com/zip4j/model/CentralDirectory.java
Normal file
44
harmony/src/main/java/com/zip4j/model/CentralDirectory.java
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CentralDirectory {
|
||||
|
||||
private ArrayList fileHeaders;
|
||||
|
||||
private DigitalSignature digitalSignature;
|
||||
|
||||
public ArrayList getFileHeaders() {
|
||||
return fileHeaders;
|
||||
}
|
||||
|
||||
public void setFileHeaders(ArrayList fileHeaders) {
|
||||
this.fileHeaders = fileHeaders;
|
||||
}
|
||||
|
||||
public DigitalSignature getDigitalSignature() {
|
||||
return digitalSignature;
|
||||
}
|
||||
|
||||
public void setDigitalSignature(DigitalSignature digitalSignature) {
|
||||
this.digitalSignature = digitalSignature;
|
||||
}
|
||||
|
||||
|
||||
}
|
51
harmony/src/main/java/com/zip4j/model/DataDescriptor.java
Normal file
51
harmony/src/main/java/com/zip4j/model/DataDescriptor.java
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.model;
|
||||
|
||||
public class DataDescriptor {
|
||||
|
||||
private String crc32;
|
||||
|
||||
private int compressedSize;
|
||||
|
||||
private int uncompressedSize;
|
||||
|
||||
public String getCrc32() {
|
||||
return crc32;
|
||||
}
|
||||
|
||||
public void setCrc32(String crc32) {
|
||||
this.crc32 = crc32;
|
||||
}
|
||||
|
||||
public int getCompressedSize() {
|
||||
return compressedSize;
|
||||
}
|
||||
|
||||
public void setCompressedSize(int compressedSize) {
|
||||
this.compressedSize = compressedSize;
|
||||
}
|
||||
|
||||
public int getUncompressedSize() {
|
||||
return uncompressedSize;
|
||||
}
|
||||
|
||||
public void setUncompressedSize(int uncompressedSize) {
|
||||
this.uncompressedSize = uncompressedSize;
|
||||
}
|
||||
|
||||
}
|
51
harmony/src/main/java/com/zip4j/model/DigitalSignature.java
Normal file
51
harmony/src/main/java/com/zip4j/model/DigitalSignature.java
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.model;
|
||||
|
||||
public class DigitalSignature {
|
||||
|
||||
private int headerSignature;
|
||||
|
||||
private int sizeOfData;
|
||||
|
||||
private String signatureData;
|
||||
|
||||
public int getHeaderSignature() {
|
||||
return headerSignature;
|
||||
}
|
||||
|
||||
public void setHeaderSignature(int headerSignature) {
|
||||
this.headerSignature = headerSignature;
|
||||
}
|
||||
|
||||
public int getSizeOfData() {
|
||||
return sizeOfData;
|
||||
}
|
||||
|
||||
public void setSizeOfData(int sizeOfData) {
|
||||
this.sizeOfData = sizeOfData;
|
||||
}
|
||||
|
||||
public String getSignatureData() {
|
||||
return signatureData;
|
||||
}
|
||||
|
||||
public void setSignatureData(String signatureData) {
|
||||
this.signatureData = signatureData;
|
||||
}
|
||||
|
||||
}
|
122
harmony/src/main/java/com/zip4j/model/EndCentralDirRecord.java
Normal file
122
harmony/src/main/java/com/zip4j/model/EndCentralDirRecord.java
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.model;
|
||||
|
||||
public class EndCentralDirRecord {
|
||||
|
||||
private long signature;
|
||||
|
||||
private int noOfThisDisk;
|
||||
|
||||
private int noOfThisDiskStartOfCentralDir;
|
||||
|
||||
private int totNoOfEntriesInCentralDirOnThisDisk;
|
||||
|
||||
private int totNoOfEntriesInCentralDir;
|
||||
|
||||
private int sizeOfCentralDir;
|
||||
|
||||
private long offsetOfStartOfCentralDir;
|
||||
|
||||
private int commentLength;
|
||||
|
||||
private String comment;
|
||||
|
||||
private byte[] commentBytes;
|
||||
|
||||
public long getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public void setSignature(long signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public int getNoOfThisDisk() {
|
||||
return noOfThisDisk;
|
||||
}
|
||||
|
||||
public void setNoOfThisDisk(int noOfThisDisk) {
|
||||
this.noOfThisDisk = noOfThisDisk;
|
||||
}
|
||||
|
||||
public int getNoOfThisDiskStartOfCentralDir() {
|
||||
return noOfThisDiskStartOfCentralDir;
|
||||
}
|
||||
|
||||
public void setNoOfThisDiskStartOfCentralDir(int noOfThisDiskStartOfCentralDir) {
|
||||
this.noOfThisDiskStartOfCentralDir = noOfThisDiskStartOfCentralDir;
|
||||
}
|
||||
|
||||
public int getTotNoOfEntriesInCentralDirOnThisDisk() {
|
||||
return totNoOfEntriesInCentralDirOnThisDisk;
|
||||
}
|
||||
|
||||
public void setTotNoOfEntriesInCentralDirOnThisDisk(
|
||||
int totNoOfEntriesInCentralDirOnThisDisk) {
|
||||
this.totNoOfEntriesInCentralDirOnThisDisk = totNoOfEntriesInCentralDirOnThisDisk;
|
||||
}
|
||||
|
||||
public int getTotNoOfEntriesInCentralDir() {
|
||||
return totNoOfEntriesInCentralDir;
|
||||
}
|
||||
|
||||
public void setTotNoOfEntriesInCentralDir(int totNoOfEntrisInCentralDir) {
|
||||
this.totNoOfEntriesInCentralDir = totNoOfEntrisInCentralDir;
|
||||
}
|
||||
|
||||
public int getSizeOfCentralDir() {
|
||||
return sizeOfCentralDir;
|
||||
}
|
||||
|
||||
public void setSizeOfCentralDir(int sizeOfCentralDir) {
|
||||
this.sizeOfCentralDir = sizeOfCentralDir;
|
||||
}
|
||||
|
||||
public long getOffsetOfStartOfCentralDir() {
|
||||
return offsetOfStartOfCentralDir;
|
||||
}
|
||||
|
||||
public void setOffsetOfStartOfCentralDir(long offSetOfStartOfCentralDir) {
|
||||
this.offsetOfStartOfCentralDir = offSetOfStartOfCentralDir;
|
||||
}
|
||||
|
||||
public int getCommentLength() {
|
||||
return commentLength;
|
||||
}
|
||||
|
||||
public void setCommentLength(int commentLength) {
|
||||
this.commentLength = commentLength;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public byte[] getCommentBytes() {
|
||||
return commentBytes;
|
||||
}
|
||||
|
||||
public void setCommentBytes(byte[] commentBytes) {
|
||||
this.commentBytes = commentBytes;
|
||||
}
|
||||
|
||||
}
|
51
harmony/src/main/java/com/zip4j/model/ExtraDataRecord.java
Normal file
51
harmony/src/main/java/com/zip4j/model/ExtraDataRecord.java
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.model;
|
||||
|
||||
public class ExtraDataRecord {
|
||||
|
||||
private long header;
|
||||
|
||||
private int sizeOfData;
|
||||
|
||||
private byte[] data;
|
||||
|
||||
public long getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
public void setHeader(long header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
public int getSizeOfData() {
|
||||
return sizeOfData;
|
||||
}
|
||||
|
||||
public void setSizeOfData(int sizeOfData) {
|
||||
this.sizeOfData = sizeOfData;
|
||||
}
|
||||
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(byte[] data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
369
harmony/src/main/java/com/zip4j/model/FileHeader.java
Normal file
369
harmony/src/main/java/com/zip4j/model/FileHeader.java
Normal file
@ -0,0 +1,369 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.zip4j.exception.ZipException;
|
||||
import com.zip4j.progress.ProgressMonitor;
|
||||
import com.zip4j.unzip.Unzip;
|
||||
import com.zip4j.util.Zip4jUtil;
|
||||
|
||||
public class FileHeader {
|
||||
|
||||
private int signature;
|
||||
|
||||
private int versionMadeBy;
|
||||
|
||||
private int versionNeededToExtract;
|
||||
|
||||
private byte[] generalPurposeFlag;
|
||||
|
||||
private int compressionMethod;
|
||||
|
||||
private int lastModFileTime;
|
||||
|
||||
private long crc32;
|
||||
|
||||
private byte[] crcBuff;
|
||||
|
||||
private long compressedSize;
|
||||
|
||||
private long uncompressedSize;
|
||||
|
||||
private int fileNameLength;
|
||||
|
||||
private int extraFieldLength;
|
||||
|
||||
private int fileCommentLength;
|
||||
|
||||
private int diskNumberStart;
|
||||
|
||||
private byte[] internalFileAttr;
|
||||
|
||||
private byte[] externalFileAttr;
|
||||
|
||||
private long offsetLocalHeader;
|
||||
|
||||
private String fileName;
|
||||
|
||||
private String fileComment;
|
||||
|
||||
private boolean isDirectory;
|
||||
|
||||
private boolean isEncrypted;
|
||||
|
||||
private int encryptionMethod;
|
||||
|
||||
private char[] password;
|
||||
|
||||
private boolean dataDescriptorExists;
|
||||
|
||||
private Zip64ExtendedInfo zip64ExtendedInfo;
|
||||
|
||||
private AESExtraDataRecord aesExtraDataRecord;
|
||||
|
||||
private ArrayList extraDataRecords;
|
||||
|
||||
private boolean fileNameUTF8Encoded;
|
||||
|
||||
public FileHeader() {
|
||||
encryptionMethod = -1;
|
||||
crc32 = 0;
|
||||
uncompressedSize = 0;
|
||||
}
|
||||
|
||||
public int getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public void setSignature(int signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public int getVersionMadeBy() {
|
||||
return versionMadeBy;
|
||||
}
|
||||
|
||||
public void setVersionMadeBy(int versionMadeBy) {
|
||||
this.versionMadeBy = versionMadeBy;
|
||||
}
|
||||
|
||||
public int getVersionNeededToExtract() {
|
||||
return versionNeededToExtract;
|
||||
}
|
||||
|
||||
public void setVersionNeededToExtract(int versionNeededToExtract) {
|
||||
this.versionNeededToExtract = versionNeededToExtract;
|
||||
}
|
||||
|
||||
public byte[] getGeneralPurposeFlag() {
|
||||
return generalPurposeFlag;
|
||||
}
|
||||
|
||||
public void setGeneralPurposeFlag(byte[] generalPurposeFlag) {
|
||||
this.generalPurposeFlag = generalPurposeFlag;
|
||||
}
|
||||
|
||||
public int getCompressionMethod() {
|
||||
return compressionMethod;
|
||||
}
|
||||
|
||||
public void setCompressionMethod(int compressionMethod) {
|
||||
this.compressionMethod = compressionMethod;
|
||||
}
|
||||
|
||||
public int getLastModFileTime() {
|
||||
return lastModFileTime;
|
||||
}
|
||||
|
||||
public void setLastModFileTime(int lastModFileTime) {
|
||||
this.lastModFileTime = lastModFileTime;
|
||||
}
|
||||
|
||||
public long getCrc32() {
|
||||
return crc32 & 0xffffffffL;
|
||||
}
|
||||
|
||||
public void setCrc32(long crc32) {
|
||||
this.crc32 = crc32;
|
||||
}
|
||||
|
||||
public long getCompressedSize() {
|
||||
return compressedSize;
|
||||
}
|
||||
|
||||
public void setCompressedSize(long compressedSize) {
|
||||
this.compressedSize = compressedSize;
|
||||
}
|
||||
|
||||
public long getUncompressedSize() {
|
||||
return uncompressedSize;
|
||||
}
|
||||
|
||||
public void setUncompressedSize(long uncompressedSize) {
|
||||
this.uncompressedSize = uncompressedSize;
|
||||
}
|
||||
|
||||
public int getFileNameLength() {
|
||||
return fileNameLength;
|
||||
}
|
||||
|
||||
public void setFileNameLength(int fileNameLength) {
|
||||
this.fileNameLength = fileNameLength;
|
||||
}
|
||||
|
||||
public int getExtraFieldLength() {
|
||||
return extraFieldLength;
|
||||
}
|
||||
|
||||
public void setExtraFieldLength(int extraFieldLength) {
|
||||
this.extraFieldLength = extraFieldLength;
|
||||
}
|
||||
|
||||
public int getFileCommentLength() {
|
||||
return fileCommentLength;
|
||||
}
|
||||
|
||||
public void setFileCommentLength(int fileCommentLength) {
|
||||
this.fileCommentLength = fileCommentLength;
|
||||
}
|
||||
|
||||
public int getDiskNumberStart() {
|
||||
return diskNumberStart;
|
||||
}
|
||||
|
||||
public void setDiskNumberStart(int diskNumberStart) {
|
||||
this.diskNumberStart = diskNumberStart;
|
||||
}
|
||||
|
||||
public byte[] getInternalFileAttr() {
|
||||
return internalFileAttr;
|
||||
}
|
||||
|
||||
public void setInternalFileAttr(byte[] internalFileAttr) {
|
||||
this.internalFileAttr = internalFileAttr;
|
||||
}
|
||||
|
||||
public byte[] getExternalFileAttr() {
|
||||
return externalFileAttr;
|
||||
}
|
||||
|
||||
public void setExternalFileAttr(byte[] externalFileAttr) {
|
||||
this.externalFileAttr = externalFileAttr;
|
||||
}
|
||||
|
||||
public long getOffsetLocalHeader() {
|
||||
return offsetLocalHeader;
|
||||
}
|
||||
|
||||
public void setOffsetLocalHeader(long offsetLocalHeader) {
|
||||
this.offsetLocalHeader = offsetLocalHeader;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getFileComment() {
|
||||
return fileComment;
|
||||
}
|
||||
|
||||
public void setFileComment(String fileComment) {
|
||||
this.fileComment = fileComment;
|
||||
}
|
||||
|
||||
public boolean isDirectory() {
|
||||
return isDirectory;
|
||||
}
|
||||
|
||||
public void setDirectory(boolean isDirectory) {
|
||||
this.isDirectory = isDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts file to the specified directory
|
||||
* @param zipModel
|
||||
* @param outPath
|
||||
* @throws ZipException
|
||||
*/
|
||||
public void extractFile(ZipModel zipModel, String outPath,
|
||||
ProgressMonitor progressMonitor, boolean runInThread) throws ZipException {
|
||||
extractFile(zipModel, outPath, null, progressMonitor, runInThread);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts file to the specified directory using any
|
||||
* user defined parameters in UnzipParameters
|
||||
* @param zipModel
|
||||
* @param outPath
|
||||
* @param unzipParameters
|
||||
* @throws ZipException
|
||||
*/
|
||||
public void extractFile(ZipModel zipModel, String outPath,
|
||||
UnzipParameters unzipParameters, ProgressMonitor progressMonitor, boolean runInThread) throws ZipException {
|
||||
extractFile(zipModel, outPath, unzipParameters, null, progressMonitor, runInThread);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts file to the specified directory using any
|
||||
* user defined parameters in UnzipParameters. Output file name
|
||||
* will be overwritten with the value in newFileName. If this
|
||||
* parameter is null, then file name will be the same as in
|
||||
* FileHeader.getFileName
|
||||
* @param zipModel
|
||||
* @param outPath
|
||||
* @param unzipParameters
|
||||
* @throws ZipException
|
||||
*/
|
||||
public void extractFile(ZipModel zipModel, String outPath,
|
||||
UnzipParameters unzipParameters, String newFileName,
|
||||
ProgressMonitor progressMonitor, boolean runInThread) throws ZipException {
|
||||
if (zipModel == null) {
|
||||
throw new ZipException("input zipModel is null");
|
||||
}
|
||||
|
||||
if (!Zip4jUtil.checkOutputFolder(outPath)) {
|
||||
throw new ZipException("Invalid output path");
|
||||
}
|
||||
|
||||
if (this == null) {
|
||||
throw new ZipException("invalid file header");
|
||||
}
|
||||
Unzip unzip = new Unzip(zipModel);
|
||||
unzip.extractFile(this, outPath, unzipParameters, newFileName, progressMonitor, runInThread);
|
||||
}
|
||||
|
||||
public boolean isEncrypted() {
|
||||
return isEncrypted;
|
||||
}
|
||||
|
||||
public void setEncrypted(boolean isEncrypted) {
|
||||
this.isEncrypted = isEncrypted;
|
||||
}
|
||||
|
||||
public int getEncryptionMethod() {
|
||||
return encryptionMethod;
|
||||
}
|
||||
|
||||
public void setEncryptionMethod(int encryptionMethod) {
|
||||
this.encryptionMethod = encryptionMethod;
|
||||
}
|
||||
|
||||
public char[] getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(char[] password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public byte[] getCrcBuff() {
|
||||
return crcBuff;
|
||||
}
|
||||
|
||||
public void setCrcBuff(byte[] crcBuff) {
|
||||
this.crcBuff = crcBuff;
|
||||
}
|
||||
|
||||
public ArrayList getExtraDataRecords() {
|
||||
return extraDataRecords;
|
||||
}
|
||||
|
||||
public void setExtraDataRecords(ArrayList extraDataRecords) {
|
||||
this.extraDataRecords = extraDataRecords;
|
||||
}
|
||||
|
||||
public boolean isDataDescriptorExists() {
|
||||
return dataDescriptorExists;
|
||||
}
|
||||
|
||||
public void setDataDescriptorExists(boolean dataDescriptorExists) {
|
||||
this.dataDescriptorExists = dataDescriptorExists;
|
||||
}
|
||||
|
||||
public Zip64ExtendedInfo getZip64ExtendedInfo() {
|
||||
return zip64ExtendedInfo;
|
||||
}
|
||||
|
||||
public void setZip64ExtendedInfo(Zip64ExtendedInfo zip64ExtendedInfo) {
|
||||
this.zip64ExtendedInfo = zip64ExtendedInfo;
|
||||
}
|
||||
|
||||
public AESExtraDataRecord getAesExtraDataRecord() {
|
||||
return aesExtraDataRecord;
|
||||
}
|
||||
|
||||
public void setAesExtraDataRecord(AESExtraDataRecord aesExtraDataRecord) {
|
||||
this.aesExtraDataRecord = aesExtraDataRecord;
|
||||
}
|
||||
|
||||
public boolean isFileNameUTF8Encoded() {
|
||||
return fileNameUTF8Encoded;
|
||||
}
|
||||
|
||||
public void setFileNameUTF8Encoded(boolean fileNameUTF8Encoded) {
|
||||
this.fileNameUTF8Encoded = fileNameUTF8Encoded;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
261
harmony/src/main/java/com/zip4j/model/LocalFileHeader.java
Normal file
261
harmony/src/main/java/com/zip4j/model/LocalFileHeader.java
Normal file
@ -0,0 +1,261 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LocalFileHeader {
|
||||
|
||||
private int signature;
|
||||
|
||||
private int versionNeededToExtract;
|
||||
|
||||
private byte[] generalPurposeFlag;
|
||||
|
||||
private int compressionMethod;
|
||||
|
||||
private int lastModFileTime;
|
||||
|
||||
private long crc32;
|
||||
|
||||
private byte[] crcBuff;
|
||||
|
||||
private long compressedSize;
|
||||
|
||||
private long uncompressedSize;
|
||||
|
||||
private int fileNameLength;
|
||||
|
||||
private int extraFieldLength;
|
||||
|
||||
private String fileName;
|
||||
|
||||
private byte[] extraField;
|
||||
|
||||
private long offsetStartOfData;
|
||||
|
||||
private boolean isEncrypted;
|
||||
|
||||
private int encryptionMethod;
|
||||
|
||||
private char[] password;
|
||||
|
||||
private ArrayList extraDataRecords;
|
||||
|
||||
private Zip64ExtendedInfo zip64ExtendedInfo;
|
||||
|
||||
private AESExtraDataRecord aesExtraDataRecord;
|
||||
|
||||
private boolean dataDescriptorExists;
|
||||
|
||||
private boolean writeComprSizeInZip64ExtraRecord;
|
||||
|
||||
private boolean fileNameUTF8Encoded;
|
||||
|
||||
public LocalFileHeader() {
|
||||
encryptionMethod = -1;
|
||||
writeComprSizeInZip64ExtraRecord = false;
|
||||
crc32 = 0;
|
||||
uncompressedSize = 0;
|
||||
}
|
||||
|
||||
public int getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public void setSignature(int signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public int getVersionNeededToExtract() {
|
||||
return versionNeededToExtract;
|
||||
}
|
||||
|
||||
public void setVersionNeededToExtract(int versionNeededToExtract) {
|
||||
this.versionNeededToExtract = versionNeededToExtract;
|
||||
}
|
||||
|
||||
public byte[] getGeneralPurposeFlag() {
|
||||
return generalPurposeFlag;
|
||||
}
|
||||
|
||||
public void setGeneralPurposeFlag(byte[] generalPurposeFlag) {
|
||||
this.generalPurposeFlag = generalPurposeFlag;
|
||||
}
|
||||
|
||||
public int getCompressionMethod() {
|
||||
return compressionMethod;
|
||||
}
|
||||
|
||||
public void setCompressionMethod(int compressionMethod) {
|
||||
this.compressionMethod = compressionMethod;
|
||||
}
|
||||
|
||||
public int getLastModFileTime() {
|
||||
return lastModFileTime;
|
||||
}
|
||||
|
||||
public void setLastModFileTime(int lastModFileTime) {
|
||||
this.lastModFileTime = lastModFileTime;
|
||||
}
|
||||
|
||||
public long getCrc32() {
|
||||
return crc32;
|
||||
}
|
||||
|
||||
public void setCrc32(long crc32) {
|
||||
this.crc32 = crc32;
|
||||
}
|
||||
|
||||
public long getCompressedSize() {
|
||||
return compressedSize;
|
||||
}
|
||||
|
||||
public void setCompressedSize(long compressedSize) {
|
||||
this.compressedSize = compressedSize;
|
||||
}
|
||||
|
||||
public long getUncompressedSize() {
|
||||
return uncompressedSize;
|
||||
}
|
||||
|
||||
public void setUncompressedSize(long uncompressedSize) {
|
||||
this.uncompressedSize = uncompressedSize;
|
||||
}
|
||||
|
||||
public int getFileNameLength() {
|
||||
return fileNameLength;
|
||||
}
|
||||
|
||||
public void setFileNameLength(int fileNameLength) {
|
||||
this.fileNameLength = fileNameLength;
|
||||
}
|
||||
|
||||
public int getExtraFieldLength() {
|
||||
return extraFieldLength;
|
||||
}
|
||||
|
||||
public void setExtraFieldLength(int extraFieldLength) {
|
||||
this.extraFieldLength = extraFieldLength;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public byte[] getExtraField() {
|
||||
return extraField;
|
||||
}
|
||||
|
||||
public void setExtraField(byte[] extraField) {
|
||||
this.extraField = extraField;
|
||||
}
|
||||
|
||||
public long getOffsetStartOfData() {
|
||||
return offsetStartOfData;
|
||||
}
|
||||
|
||||
public void setOffsetStartOfData(long offsetStartOfData) {
|
||||
this.offsetStartOfData = offsetStartOfData;
|
||||
}
|
||||
|
||||
public boolean isEncrypted() {
|
||||
return isEncrypted;
|
||||
}
|
||||
|
||||
public void setEncrypted(boolean isEncrypted) {
|
||||
this.isEncrypted = isEncrypted;
|
||||
}
|
||||
|
||||
public int getEncryptionMethod() {
|
||||
return encryptionMethod;
|
||||
}
|
||||
|
||||
public void setEncryptionMethod(int encryptionMethod) {
|
||||
this.encryptionMethod = encryptionMethod;
|
||||
}
|
||||
|
||||
public byte[] getCrcBuff() {
|
||||
return crcBuff;
|
||||
}
|
||||
|
||||
public void setCrcBuff(byte[] crcBuff) {
|
||||
this.crcBuff = crcBuff;
|
||||
}
|
||||
|
||||
public char[] getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(char[] password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public ArrayList getExtraDataRecords() {
|
||||
return extraDataRecords;
|
||||
}
|
||||
|
||||
public void setExtraDataRecords(ArrayList extraDataRecords) {
|
||||
this.extraDataRecords = extraDataRecords;
|
||||
}
|
||||
|
||||
public boolean isDataDescriptorExists() {
|
||||
return dataDescriptorExists;
|
||||
}
|
||||
|
||||
public void setDataDescriptorExists(boolean dataDescriptorExists) {
|
||||
this.dataDescriptorExists = dataDescriptorExists;
|
||||
}
|
||||
|
||||
public Zip64ExtendedInfo getZip64ExtendedInfo() {
|
||||
return zip64ExtendedInfo;
|
||||
}
|
||||
|
||||
public void setZip64ExtendedInfo(Zip64ExtendedInfo zip64ExtendedInfo) {
|
||||
this.zip64ExtendedInfo = zip64ExtendedInfo;
|
||||
}
|
||||
|
||||
public AESExtraDataRecord getAesExtraDataRecord() {
|
||||
return aesExtraDataRecord;
|
||||
}
|
||||
|
||||
public void setAesExtraDataRecord(AESExtraDataRecord aesExtraDataRecord) {
|
||||
this.aesExtraDataRecord = aesExtraDataRecord;
|
||||
}
|
||||
|
||||
public boolean isWriteComprSizeInZip64ExtraRecord() {
|
||||
return writeComprSizeInZip64ExtraRecord;
|
||||
}
|
||||
|
||||
public void setWriteComprSizeInZip64ExtraRecord(
|
||||
boolean writeComprSizeInZip64ExtraRecord) {
|
||||
this.writeComprSizeInZip64ExtraRecord = writeComprSizeInZip64ExtraRecord;
|
||||
}
|
||||
|
||||
public boolean isFileNameUTF8Encoded() {
|
||||
return fileNameUTF8Encoded;
|
||||
}
|
||||
|
||||
public void setFileNameUTF8Encoded(boolean fileNameUTF8Encoded) {
|
||||
this.fileNameUTF8Encoded = fileNameUTF8Encoded;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.model;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import com.zip4j.crypto.IDecrypter;
|
||||
import com.zip4j.unzip.UnzipEngine;
|
||||
|
||||
public class UnzipEngineParameters {
|
||||
|
||||
private ZipModel zipModel;
|
||||
|
||||
private FileHeader fileHeader;
|
||||
|
||||
private LocalFileHeader localFileHeader;
|
||||
|
||||
private IDecrypter iDecryptor;
|
||||
|
||||
private FileOutputStream outputStream;
|
||||
|
||||
private UnzipEngine unzipEngine;
|
||||
|
||||
public ZipModel getZipModel() {
|
||||
return zipModel;
|
||||
}
|
||||
|
||||
public void setZipModel(ZipModel zipModel) {
|
||||
this.zipModel = zipModel;
|
||||
}
|
||||
|
||||
public FileHeader getFileHeader() {
|
||||
return fileHeader;
|
||||
}
|
||||
|
||||
public void setFileHeader(FileHeader fileHeader) {
|
||||
this.fileHeader = fileHeader;
|
||||
}
|
||||
|
||||
public LocalFileHeader getLocalFileHeader() {
|
||||
return localFileHeader;
|
||||
}
|
||||
|
||||
public void setLocalFileHeader(LocalFileHeader localFileHeader) {
|
||||
this.localFileHeader = localFileHeader;
|
||||
}
|
||||
|
||||
public IDecrypter getIDecryptor() {
|
||||
return iDecryptor;
|
||||
}
|
||||
|
||||
public void setIDecryptor(IDecrypter decrypter) {
|
||||
iDecryptor = decrypter;
|
||||
}
|
||||
|
||||
public FileOutputStream getOutputStream() {
|
||||
return outputStream;
|
||||
}
|
||||
|
||||
public void setOutputStream(FileOutputStream outputStream) {
|
||||
this.outputStream = outputStream;
|
||||
}
|
||||
|
||||
public UnzipEngine getUnzipEngine() {
|
||||
return unzipEngine;
|
||||
}
|
||||
|
||||
public void setUnzipEngine(UnzipEngine unzipEngine) {
|
||||
this.unzipEngine = unzipEngine;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
77
harmony/src/main/java/com/zip4j/model/UnzipParameters.java
Normal file
77
harmony/src/main/java/com/zip4j/model/UnzipParameters.java
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.model;
|
||||
|
||||
public class UnzipParameters {
|
||||
|
||||
private boolean ignoreReadOnlyFileAttribute;
|
||||
private boolean ignoreHiddenFileAttribute;
|
||||
private boolean ignoreArchiveFileAttribute;
|
||||
private boolean ignoreSystemFileAttribute;
|
||||
private boolean ignoreAllFileAttributes;
|
||||
private boolean ignoreDateTimeAttributes;
|
||||
|
||||
public boolean isIgnoreReadOnlyFileAttribute() {
|
||||
return ignoreReadOnlyFileAttribute;
|
||||
}
|
||||
|
||||
public void setIgnoreReadOnlyFileAttribute(boolean ignoreReadOnlyFileAttribute) {
|
||||
this.ignoreReadOnlyFileAttribute = ignoreReadOnlyFileAttribute;
|
||||
}
|
||||
|
||||
public boolean isIgnoreHiddenFileAttribute() {
|
||||
return ignoreHiddenFileAttribute;
|
||||
}
|
||||
|
||||
public void setIgnoreHiddenFileAttribute(boolean ignoreHiddenFileAttribute) {
|
||||
this.ignoreHiddenFileAttribute = ignoreHiddenFileAttribute;
|
||||
}
|
||||
|
||||
public boolean isIgnoreArchiveFileAttribute() {
|
||||
return ignoreArchiveFileAttribute;
|
||||
}
|
||||
|
||||
public void setIgnoreArchiveFileAttribute(boolean ignoreArchiveFileAttribute) {
|
||||
this.ignoreArchiveFileAttribute = ignoreArchiveFileAttribute;
|
||||
}
|
||||
|
||||
public boolean isIgnoreSystemFileAttribute() {
|
||||
return ignoreSystemFileAttribute;
|
||||
}
|
||||
|
||||
public void setIgnoreSystemFileAttribute(boolean ignoreSystemFileAttribute) {
|
||||
this.ignoreSystemFileAttribute = ignoreSystemFileAttribute;
|
||||
}
|
||||
|
||||
public boolean isIgnoreAllFileAttributes() {
|
||||
return ignoreAllFileAttributes;
|
||||
}
|
||||
|
||||
public void setIgnoreAllFileAttributes(boolean ignoreAllFileAttributes) {
|
||||
this.ignoreAllFileAttributes = ignoreAllFileAttributes;
|
||||
}
|
||||
|
||||
public boolean isIgnoreDateTimeAttributes() {
|
||||
return ignoreDateTimeAttributes;
|
||||
}
|
||||
|
||||
public void setIgnoreDateTimeAttributes(boolean ignoreDateTimeAttributes) {
|
||||
this.ignoreDateTimeAttributes = ignoreDateTimeAttributes;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.model;
|
||||
|
||||
public class Zip64EndCentralDirLocator {
|
||||
|
||||
private long signature;
|
||||
|
||||
private int noOfDiskStartOfZip64EndOfCentralDirRec;
|
||||
|
||||
private long offsetZip64EndOfCentralDirRec;
|
||||
|
||||
private int totNumberOfDiscs;
|
||||
|
||||
public long getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public void setSignature(long signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public int getNoOfDiskStartOfZip64EndOfCentralDirRec() {
|
||||
return noOfDiskStartOfZip64EndOfCentralDirRec;
|
||||
}
|
||||
|
||||
public void setNoOfDiskStartOfZip64EndOfCentralDirRec(
|
||||
int noOfDiskStartOfZip64EndOfCentralDirRec) {
|
||||
this.noOfDiskStartOfZip64EndOfCentralDirRec = noOfDiskStartOfZip64EndOfCentralDirRec;
|
||||
}
|
||||
|
||||
public long getOffsetZip64EndOfCentralDirRec() {
|
||||
return offsetZip64EndOfCentralDirRec;
|
||||
}
|
||||
|
||||
public void setOffsetZip64EndOfCentralDirRec(long offsetZip64EndOfCentralDirRec) {
|
||||
this.offsetZip64EndOfCentralDirRec = offsetZip64EndOfCentralDirRec;
|
||||
}
|
||||
|
||||
public int getTotNumberOfDiscs() {
|
||||
return totNumberOfDiscs;
|
||||
}
|
||||
|
||||
public void setTotNumberOfDiscs(int totNumberOfDiscs) {
|
||||
this.totNumberOfDiscs = totNumberOfDiscs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright 2010 Srikanth Reddy Lingala
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zip4j.model;
|
||||
|
||||
public class Zip64EndCentralDirRecord {
|
||||
|
||||
private long signature;
|
||||
|
||||
private long sizeOfZip64EndCentralDirRec;
|
||||
|
||||
private int versionMadeBy;
|
||||
|
||||
private int versionNeededToExtract;
|
||||
|
||||
private int noOfThisDisk;
|
||||
|
||||
private int noOfThisDiskStartOfCentralDir;
|
||||
|
||||
private long totNoOfEntriesInCentralDirOnThisDisk;
|
||||
|
||||
private long totNoOfEntriesInCentralDir;
|
||||
|
||||
private long sizeOfCentralDir;
|
||||
|
||||
private long offsetStartCenDirWRTStartDiskNo;
|
||||
|
||||
private byte[] extensibleDataSector;
|
||||
|
||||
public long getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public void setSignature(long signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public long getSizeOfZip64EndCentralDirRec() {
|
||||
return sizeOfZip64EndCentralDirRec;
|
||||
}
|
||||
|
||||
public void setSizeOfZip64EndCentralDirRec(long sizeOfZip64EndCentralDirRec) {
|
||||
this.sizeOfZip64EndCentralDirRec = sizeOfZip64EndCentralDirRec;
|
||||
}
|
||||
|
||||
public int getVersionMadeBy() {
|
||||
return versionMadeBy;
|
||||
}
|
||||
|
||||
public void setVersionMadeBy(int versionMadeBy) {
|
||||
this.versionMadeBy = versionMadeBy;
|
||||
}
|
||||
|
||||
public int getVersionNeededToExtract() {
|
||||
return versionNeededToExtract;
|
||||
}
|
||||
|
||||
public void setVersionNeededToExtract(int versionNeededToExtract) {
|
||||
this.versionNeededToExtract = versionNeededToExtract;
|
||||
}
|
||||
|
||||
public int getNoOfThisDisk() {
|
||||
return noOfThisDisk;
|
||||
}
|
||||
|
||||
public void setNoOfThisDisk(int noOfThisDisk) {
|
||||
this.noOfThisDisk = noOfThisDisk;
|
||||
}
|
||||
|
||||
public int getNoOfThisDiskStartOfCentralDir() {
|
||||
return noOfThisDiskStartOfCentralDir;
|
||||
}
|
||||
|
||||
public void setNoOfThisDiskStartOfCentralDir(int noOfThisDiskStartOfCentralDir) {
|
||||
this.noOfThisDiskStartOfCentralDir = noOfThisDiskStartOfCentralDir;
|
||||
}
|
||||
|
||||
public long getTotNoOfEntriesInCentralDirOnThisDisk() {
|
||||
return totNoOfEntriesInCentralDirOnThisDisk;
|
||||
}
|
||||
|
||||
public void setTotNoOfEntriesInCentralDirOnThisDisk(
|
||||
long totNoOfEntriesInCentralDirOnThisDisk) {
|
||||
this.totNoOfEntriesInCentralDirOnThisDisk = totNoOfEntriesInCentralDirOnThisDisk;
|
||||
}
|
||||
|
||||
public long getTotNoOfEntriesInCentralDir() {
|
||||
return totNoOfEntriesInCentralDir;
|
||||
}
|
||||
|
||||
public void setTotNoOfEntriesInCentralDir(long totNoOfEntriesInCentralDir) {
|
||||
this.totNoOfEntriesInCentralDir = totNoOfEntriesInCentralDir;
|
||||
}
|
||||
|
||||
public long getSizeOfCentralDir() {
|
||||
return sizeOfCentralDir;
|
||||
}
|
||||
|
||||
public void setSizeOfCentralDir(long sizeOfCentralDir) {
|
||||
this.sizeOfCentralDir = sizeOfCentralDir;
|
||||
}
|
||||
|
||||
public long getOffsetStartCenDirWRTStartDiskNo() {
|
||||
return offsetStartCenDirWRTStartDiskNo;
|
||||
}
|
||||
|
||||
public void setOffsetStartCenDirWRTStartDiskNo(
|
||||
long offsetStartCenDirWRTStartDiskNo) {
|
||||
this.offsetStartCenDirWRTStartDiskNo = offsetStartCenDirWRTStartDiskNo;
|
||||
}
|
||||
|
||||
public byte[] getExtensibleDataSector() {
|
||||
return extensibleDataSector;
|
||||
}
|
||||
|
||||
public void setExtensibleDataSector(byte[] extensibleDataSector) {
|
||||
this.extensibleDataSector = extensibleDataSector;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user