备份,准备回滚为无插件化

This commit is contained in:
Yutousama 2018-05-07 15:22:02 +08:00
parent 58c306dafd
commit 6194d1c46f
13 changed files with 331 additions and 156 deletions

View File

@ -25,7 +25,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -5,11 +5,12 @@ package com.yutou.jianrmg_v2.basemodel.Network;
*/
public class HttpApi {
// public static final String HOME_URL="http://192.168.31.240:8088/android/"; //zzz_gz wifi
// public static final String HOME_URL="http://192.168.31.240:8088/android/"; //zzz_gz wifi
public static final String HOME_URL="http://192.168.137.1:8088/android/"; //笔记本本身WIFI
// public static final String HOME_URL="http://game.yutou233.cn/android/"; //服务器
public static final String MOD_ALL="mod/all.do";
public static final String MOD_MODS="mod/getMods.do";
public static final String MOD_TYPE="mod/getType.do";
public static final String MOD_REMOD="mod/remod.do";
public static final String MOD_USER_LIST="mod/user.do";

View File

@ -126,9 +126,9 @@ public class HttpUtils {
sum += len;
int progress = (int) (sum * 1.0f / total * 100);
// 下载中
while (!downloadFileInerface.downloading(getNameFromUrl(url),progress,total)){
/* while (!downloadFileInerface.downloading(getNameFromUrl(url),progress,total)){
Thread.sleep(10);
}
}*/
}
fos.flush();

View File

@ -1,5 +1,6 @@
package com.yutou.jianrmg_v2.basemodel.Tools;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
@ -78,6 +79,7 @@ public class ActivitysManager {
/**
* 退出应用程序
*/
@SuppressLint("MissingPermission")
public static void AppExit(Context context) {
try {
finishAllActivity();

View File

@ -14,6 +14,7 @@ import android.widget.Toast;
import com.alibaba.fastjson.JSON;
import com.kaopiz.kprogresshud.KProgressHUD;
import com.yutou.jianrmg_v2.basemodel.Application;
import com.yutou.jianrmg_v2.basemodel.Data.AppData;
import com.yutou.jianrmg_v2.basemodel.Data.MGamePackname;
import com.yutou.jianrmg_v2.basemodel.Data.TMod;
@ -46,43 +47,50 @@ public class ModUtils {
private List<TModfile> modfiles;
private KProgressHUD hud;
private TMod mod;
public static ModUtils init(Context context){
if(modUtils==null){
modUtils=new ModUtils();
public static ModUtils init(Context context) {
if (modUtils == null) {
modUtils = new ModUtils();
}
modUtils.setContext(context);
return modUtils;
return modUtils;
}
private void setContext(Context context){
this.context=context;
hud=Utils.showLoading(context,"安装中","请稍后");
private void setContext(Context context) {
this.context = context;
hud = Utils.showLoading(context, "安装中", "请稍后");
}
private ModUtils(){
handler=new Handler();
private ModUtils() {
handler = new Handler();
}
public void setMod(TMod mod){
this.mod=mod;
public void setMod(TMod mod) {
this.mod = mod;
getModDownloadInfo();
}
public List<TModfile> getModfiles(){
public List<TModfile> getModfiles() {
return modfiles;
}
public void installMod(TMod mod){
this.mod=mod;
public void installMod(TMod mod) {
this.mod = mod;
install();
}
private void install(){
if(modfiles==null){
Toast.makeText(context,"正在加载数据,请稍后再试",Toast.LENGTH_LONG).show();
private void install() {
if (modfiles == null) {
Toast.makeText(context, "正在加载数据,请稍后再试", Toast.LENGTH_LONG).show();
getModDownloadInfo();
return;
}
Log.i("安装mod",changeMod(mod,modfiles)+"");
if(!isInstallMod(mod)&&changeMod(mod,modfiles)){
Log.i("安装mod", (!isInstallMod(mod)) + " " + changeMod(mod, modfiles) + "");
if (!isInstallMod(mod) && changeMod(mod, modfiles)) {
install(mod);
}else{
if(getModPath(mod).listFiles().length>0&&!changeMod(mod,modfiles)){
final MaterialDialog dialog=new MaterialDialog(context);
} else {
if (getModPath(mod).listFiles().length > 0 && !changeMod(mod, modfiles)) {
final MaterialDialog dialog = new MaterialDialog(context);
dialog.setTitle("mod已损失");
dialog.setMessage("当前mod文件有缺失是否重新下载");
dialog.setPositiveButton("确定", new View.OnClickListener() {
@ -99,42 +107,43 @@ public class ModUtils {
}
});
dialog.show();
}else {
} else {
downloadMod();
}
}
}
private void install(final TMod mod){
List<String> clientList=new ArrayList<>();
private void install(final TMod mod) {
List<String> clientList = new ArrayList<>();
for (MGamePackname packname : AppData.packnames) {
clientList.add(packname.getZhname()+"("+packname.getPackname()+")");
clientList.add(packname.getZhname() + "(" + packname.getPackname() + ")");
}
final MaterialDialog dialog=new MaterialDialog(context);
final MaterialDialog dialog = new MaterialDialog(context);
dialog.setTitle("选择安装客户端");
ListView listView=new ListView(context);
listView.setAdapter(new ArrayAdapter<String>(context,android.R.layout.simple_list_item_1,clientList));
ListView listView = new ListView(context);
listView.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, clientList));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
MGamePackname packname=AppData.packnames.get(i);
MGamePackname packname = AppData.packnames.get(i);
hud.show();
for (TModfile modfile : modfiles) {
File file=getModPath(mod,modfile.getFilename());
if(packname.getZhname().contains("[ROOT]")){
backupOrRoot(file,"/data/data/"+packname.getPackname()+modfile.getInstallpathid(),packname.getPackname(),mod);
rootInstall(file,"/data/data/"+packname.getPackname()+modfile.getInstallpathid());
}else{
File file = getModPath(mod, modfile.getFilename());
if (packname.getZhname().contains("[ROOT]")) {
backupOrRoot(file, "/data/data/" + packname.getPackname() + modfile.getInstallpathid(), packname.getPackname(), mod);
rootInstall(file, "/data/data/" + packname.getPackname() + modfile.getInstallpathid());
} else {
}
}
try {
new File(getModInstallPath(mod)+packname.getPackname()+".lock").createNewFile();
new File(getModInstallPath(mod) + packname.getPackname() + ".lock").createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
hud.dismiss();
dialog.dismiss();
Toast.makeText(context,"安装成功,重启游戏生效",Toast.LENGTH_LONG).show();
Toast.makeText(context, "安装成功,重启游戏生效", Toast.LENGTH_LONG).show();
}
});
dialog.setContentView(listView);
@ -147,48 +156,51 @@ public class ModUtils {
dialog.show();
}
private void notRootInstall(File src,String path){
private void notRootInstall(File src, String path) {
}
private void rootInstall(File src,String path){
RootUtils root=RootUtils.init(context);
if(RootUtils.su()){
root.exec("\\cp -f "+src.getAbsolutePath()+" "+path);
root.exec("chmod 777 "+src.getAbsolutePath()+" "+path+src.getName());
}else {
final MaterialDialog dialog=new MaterialDialog(context);
dialog.setTitle("错误");
dialog.setMessage("未获取到ROOT权限\n提示魔改专用端可免ROOT使用魔改以及更多功能");
dialog.setPositiveButton("确定", new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.setNegativeButton("下载魔改专用客户端", new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.show();
}
private void rootInstall(File src, String path) {
RootUtils root = RootUtils.init(context);
if (RootUtils.su()) {
root.exec("\\cp -f " + src.getAbsolutePath() + " " + path);
root.exec("chmod 777 " + src.getAbsolutePath() + " " + path + src.getName());
} else {
final MaterialDialog dialog = new MaterialDialog(context);
dialog.setTitle("错误");
dialog.setMessage("未获取到ROOT权限\n提示魔改专用端可免ROOT使用魔改以及更多功能");
dialog.setPositiveButton("确定", new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.setNegativeButton("下载魔改专用客户端", new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.show();
}
}
public void reBackMod(TMod tMod) {
final MaterialDialog dialog=new MaterialDialog(context);
dialog.setTitle("将还原 "+tMod.getTitle());
final List<String> clientList=getInstallClens();
ListView listView=new ListView(context);
listView.setAdapter(new ArrayAdapter<String>(context,android.R.layout.simple_list_item_1,clientList));
final MaterialDialog dialog = new MaterialDialog(context);
dialog.setTitle("将还原 " + tMod.getTitle());
final List<String> clientList = getInstallClens();
ListView listView = new ListView(context);
listView.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, clientList));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
RootUtils root=RootUtils.init(context);
RootUtils root = RootUtils.init(context);
for (TModfile modfile : modfiles) {
if(getModPath(mod,"backup/"+clientList.get(i)+"/"+modfile.getFilename()).exists()){
root.exec("\\cp -f "+getModInstallPath(mod)+"backup/"+clientList.get(i)+"/"+modfile.getFilename()+" "+"/data/data/"+clientList.get(i)+modfile.getInstallpathid());
}else{
root.exec("rm -f "+"/data/data/"+clientList.get(i)+modfile.getInstallpathid()+modfile.getFilename());
if (getModPath(mod, "backup/" + clientList.get(i) + "/" + modfile.getFilename()).exists()) {
root.exec("\\cp -f " + getModInstallPath(mod) + "backup/" + clientList.get(i) + "/" + modfile.getFilename() + " " + "/data/data/" + clientList.get(i) + modfile.getInstallpathid());
} else {
root.exec("rm -f " + "/data/data/" + clientList.get(i) + modfile.getInstallpathid() + modfile.getFilename());
}
}
dialog.dismiss();
@ -198,94 +210,98 @@ public class ModUtils {
dialog.setNegativeButton("放弃", new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();;
dialog.dismiss();
;
}
});
dialog.show();
}
private void backupOrRoot(File srcFile,String srcPath,String backupClient,TMod mod){
private void backupOrRoot(File srcFile, String srcPath, String backupClient, TMod mod) {
RootUtils root = RootUtils.init(context);
if(RootUtils.su()) {
File backup = getModPath(mod, "backup/"+backupClient);
File file=new File(backup.getAbsolutePath()+"/"+srcFile.getName());
if(file.exists()){
if (RootUtils.su()) {
File backup = getModPath(mod, "backup/" + backupClient);
File file = new File(backup.getAbsolutePath() + "/" + srcFile.getName());
if (file.exists()) {
return;
}
if (!backup.exists()) {
Log.i("获取ROOT","2");
Log.i("获取ROOT", "2");
backup.mkdirs();
}
root.exec("chmod 777 "+srcPath+srcFile.getName());
root.exec("\\cp -f"+srcPath+srcFile.getName()+" "+backup+"/");
}else{
root.exec("chmod 777 " + srcPath + srcFile.getName());
root.exec("\\cp -f" + srcPath + srcFile.getName() + " " + backup + "/");
} else {
}
}
private void downloadMod(){
Toast.makeText(context,"开始下载",Toast.LENGTH_LONG).show();
Intent intent=new Intent(context.getApplicationContext(), DownloadService.class);
private void downloadMod() {
Toast.makeText(context, "开始下载", Toast.LENGTH_LONG).show();
Intent intent = new Intent(context.getApplicationContext(), DownloadService.class);
intent.setPackage(context.getPackageName());
boolean isBindService=context.getApplicationContext().bindService(intent, new ServiceConnection() {
boolean isBindService = context.getApplicationContext().bindService(intent, new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
DownloadService.ServiceBinder binder=(DownloadService.ServiceBinder)iBinder;
DownloadService service=binder.getService(new DownloadInterface() {
@Override
public void getDownloadList(int size) {
DownloadService.ServiceBinder binder = (DownloadService.ServiceBinder) iBinder;
DownloadService service = binder.getService(new DownloadInterface() {
@Override
public void getDownloadList(int size) {
}
}
@Override
public void getDownloadFile(TModfile modfile) {
@Override
public void getDownloadFile(TModfile modfile) {
}
}
@Override
public void getDownloadFileSize(int size) {
@Override
public void getDownloadFileSize(int size) {
}
}
@Override
public void getCurrent(int current) {
@Override
public void getCurrent(int current) {
}
}
@Override
public void over() {
@Override
public void over() {
Utils.toast(context, "下载完成");
}
}
@Override
public void start() {
}
});
service.start(modfiles);
@Override
public void start() {
Utils.toast(context, "开始下载");
}
});
service.start(modfiles);
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
Log.i("下载服务","绑定失败:"+componentName);
Log.i("下载服务", "绑定失败:" + componentName);
}
},Context.BIND_AUTO_CREATE);
Log.i("绑定下载:",isBindService+"");
}, Context.BIND_AUTO_CREATE);
Log.i("绑定下载:", isBindService + "");
}
private void getModDownloadInfo(){
modfiles=null;
try{
JSONObject json=new JSONObject();
json.put("mid",mod.getId());
private void getModDownloadInfo() {
modfiles = null;
try {
JSONObject json = new JSONObject();
json.put("mid", mod.getId());
json.put("uid", AppData.user.getId());
HttpUtils.post(HttpApi.HOME_URL + HttpApi.MOD_DOWNLOAD, json, new HttpInterface() {
@Override
public void httpGetData(String string, int code) {
try{
JSONObject json=new JSONObject(string);
if(json.getInt("code")==100){
modfiles= JSON.parseArray(json.getJSONArray("data").toString(),TModfile.class);
try {
JSONObject json = new JSONObject(string);
if (json.getInt("code") == 100) {
modfiles = JSON.parseArray(json.getJSONArray("data").toString(), TModfile.class);
}
}catch (Exception e){
} catch (Exception e) {
}
}
@ -295,53 +311,59 @@ public class ModUtils {
}
});
}catch (Exception e){
} catch (Exception e) {
}
}
public static String getModInstallPath(TMod mod){
return Utils.getSDCardPath()+"/"+mod.getId()+"/";
public static String getModInstallPath(TMod mod) {
return Utils.getSDCardPath() + "/" + mod.getId() + "/";
}
public static boolean isInstallMod(TMod mod){
File modPath=new File(Utils.getSDCardPath()+"/"+mod.getId()+"/");
public static boolean isInstallMod(TMod mod) {
File modPath = new File(Utils.getSDCardPath() + "/" + mod.getId() + "/");
for (int i = 0; i < modPath.listFiles().length; i++) {
Log.i("检测mod是否安装","位置:"+modPath.listFiles()[i].getAbsolutePath()+" exists:"+modPath.listFiles()[i].exists()+" .lock="+(modPath.listFiles()[i].getName().contains(".lock")));
if(modPath.listFiles()[i].getName().contains(".lock")){
Log.i("检测mod是否安装", "位置:" + modPath.listFiles()[i].getAbsolutePath() + " exists:" + modPath.listFiles()[i].exists() + " .lock=" + (modPath.listFiles()[i].getName().contains(".lock")));
if (modPath.listFiles()[i].getName().contains(".lock")) {
return true;
}
}
return false;
}
public static boolean changeMod(TMod mod, List<TModfile> modfiles){
File modPath=new File(Utils.getSDCardPath()+"/"+mod.getId()+"/");
Log.i("检测mod是否完整","位置:"+Utils.getSDCardPath()+"/"+mod.getId()+"/"+" exists:"+modPath.exists());
public static boolean changeMod(TMod mod, List<TModfile> modfiles) {
File modPath = new File(Utils.getSDCardPath() + "/" + mod.getId() + "/");
Log.i("检测mod是否完整", "位置:" + Utils.getSDCardPath() + "/" + mod.getId() + "/" + " exists:" + modPath.exists());
for (TModfile modfile : modfiles) {
if(!new File(Utils.getSDCardPath()+"/"+mod.getId()+"/"+modfile.getFilename()).exists()){
return false;
}
if (new File(Utils.getSDCardPath() + "/" + mod.getId() + "/" + modfile.getFilename()).isFile())
if (!new File(Utils.getSDCardPath() + "/" + mod.getId() + "/" + modfile.getFilename()).exists()) {
Log.i("不完整的", "位置:" + Utils.getSDCardPath() + "/" + mod.getId() + "/" + " exists:" + modPath.exists());
return false;
}
}
return true;
}
public static File getModPath(TMod mod){
return getModPath(mod,"");
public static File getModPath(TMod mod) {
return getModPath(mod, "");
}
public static File getModPath(TMod mod,String name){
File path=new File(Utils.getSDCardPath()+"/"+mod.getId()+"/"+name);
if(!path.exists()){
public static File getModPath(TMod mod, String name) {
File path = new File(Utils.getSDCardPath() + "/" + mod.getId() + "/" + name);
if (!path.exists()) {
path.mkdirs();
}
return path;
return path;
}
public List<String> getInstallClens() {
List<String> installClens=new ArrayList<>();
File modPath=getModPath(mod);
if(modPath.exists()){
List<String> installClens = new ArrayList<>();
File modPath = getModPath(mod);
if (modPath.exists()) {
for (int i = 0; i < modPath.listFiles().length; i++) {
if(modPath.listFiles()[i].getName().contains(".lock")){
if (modPath.listFiles()[i].getName().contains(".lock")) {
installClens.add(modPath.listFiles()[i].getName().split("\\.")[0]);
}
}

View File

@ -68,6 +68,7 @@ public class DownloadService extends Service {
puase=false;
list.addAll(addList);
downloadInterface.start();
startNotification();
download= new Download(this);
}
@ -126,7 +127,6 @@ public class DownloadService extends Service {
if(!download.isAlive||!download.isAlive()||!download.isInterrupted())
{
this.service=service;
service.startNotification();
start();
}
}

View File

@ -2,5 +2,8 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView"></ListView>
</LinearLayout>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="horizontal">
<ImageView
android:id="@+id/image"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="20dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/title"
android:layout_margin="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="标题"
android:textSize="18sp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginTop="10dp">
android:layout_height="80dp"
android:layout_marginTop="20dp">
<LinearLayout
android:id="@+id/download"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:background="@color/white"
android:orientation="horizontal">

View File

@ -0,0 +1,54 @@
package com.jianrmg_v2.usermodel.Adapters;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
public class DownloadItemAdapter extends BaseAdapter {
private Context context;
private List<?> list;
public DownloadItemAdapter(Context context, List<?> list) {
this.context = context;
this.list = list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int i) {
return list.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
Items items;
if(view==null){
view= LayoutInflater.from(context).inflate(com.yutou.jianrmg_v2.resmodl.R.layout.item_download,null);
items=new Items();
view.setTag(items);
}else{
items= (Items) view.getTag();
}
return view;
}
private class Items{
ImageView icon;
TextView title;
}
}

View File

@ -4,20 +4,80 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import com.yutou.jianrmg_v2.basemodel.Interfaces.HttpInterface;
import com.yutou.jianrmg_v2.basemodel.Network.HttpApi;
import com.yutou.jianrmg_v2.basemodel.Network.HttpUtils;
import com.yutou.jianrmg_v2.basemodel.Tools.Utils;
import com.yutou.jianrmg_v2.resmodl.R;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import Interfaces.BaseActivityInterface;
public class DownloadListActivity implements BaseActivityInterface ,Serializable {
private Context context;
private LinearLayout layout;
private View view;
private ListView listView;
@Override
public void onCreate(Bundle savedInstanceState, LinearLayout layout, Context context, Intent intent) {
this.context=context;
this.layout=layout;
this.view= LayoutInflater.from(context).inflate(R.layout.activity_download_list,null);
getDownloadFileList();
initViews();
layout.addView(view);
}
private void getDownloadFileList(){
JSONObject json=new JSONObject();
File rootPath=new File(Utils.getSDCardPath());
try{
JSONArray array=new JSONArray();
for (File path : rootPath.listFiles()) {
if (path.isDirectory()){
try {
array.put(Integer.valueOf(path.getName())+"");
}catch (Exception e){}
}
}
json.put("ids",array);
HttpUtils.post(HttpApi.HOME_URL + HttpApi.MOD_MODS, json, new HttpInterface() {
@Override
public void httpGetData(String string, int code) {
try {
JSONObject json=new JSONObject(string);
if(json.getInt("code")!=100){
return;
}
JSONArray dataList=json.getJSONArray("data");
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void httpError(Exception e) {
}
});
}catch (Exception e){}
return;
}
private void initViews(){
listView=view.findViewById(R.id.listView);
}
@Override

View File

@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0"