@@ -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 ( m odUtils= = null ) {
modUtils = new ModUtils ( ) ;
public static M odUtils init ( Context context ) {
if ( modUtils = = null ) {
modUtils = new ModUtils ( ) ;
}
modUtils . setContext ( context ) ;
return modUtils ;
return modUtils ;
}
private void setContext ( Context context ) {
this . c ontext = context ;
hud = Utils . showLoading ( context , " 安装中 " , " 请稍后 " ) ;
private void setContext ( C ontext context ) {
this . context = context ;
hud = Utils . showLoading ( context , " 安装中 " , " 请稍后 " ) ;
}
private ModUtils ( ) {
handler = new Handler ( ) ;
private ModUtils ( ) {
handler = new Handler ( ) ;
}
public void setMod ( TMod mod ) {
this . m od = mod ;
public void setMod ( TM od mod ) {
this . mod = mod ;
getModDownloadInfo ( ) ;
}
public List < TModfile > getModfiles ( ) {
public List < TModfile > getModfiles ( ) {
return modfiles ;
}
public void installMod ( TMod mod ) {
this . m od = mod ;
public void installMod ( TM od 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 . setMessag e ( " 未获取到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 . setTitl e ( " 错误 " ) ;
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( m od, " " ) ;
public static File getModPath( TM od mod ) {
return getModPath ( mod , " " ) ;
}
public static File getModPath ( TMod mod , String name ) {
File path = new File ( Utils . getSDCar dPath ( ) + " / " + mod . getId ( ) + " / " + name ) ;
if ( ! path . exists ( ) ) {
public static File getMo dPath ( 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 ] ) ;
}
}