2016-08-22 21:18:28 +00:00
package com.topjohnwu.magisk.utils ;
2016-08-22 19:50:46 +00:00
2016-08-22 08:09:36 +00:00
import java.util.List ;
2016-08-20 15:26:49 +00:00
public class Utils {
2016-08-24 21:58:15 +00:00
public static boolean fileExist ( String path ) {
List < String > ret ;
ret = Shell . sh ( " if [ -f " + path + " ]; then echo true; else echo false; fi " ) ;
if ( ! Boolean . parseBoolean ( ret . get ( 0 ) ) & & Shell . rootAccess ( ) ) ret = Shell . su ( " if [ -f " + path + " ]; then echo true; else echo false; fi " ) ;
return Boolean . parseBoolean ( ret . get ( 0 ) ) ;
2016-08-22 17:44:34 +00:00
}
2016-08-24 21:58:15 +00:00
public static boolean createFile ( String path ) {
if ( ! Shell . rootAccess ( ) ) {
return false ;
} else {
return Boolean . parseBoolean ( Shell . su ( " touch " + path + " 2>/dev/null; if [ -f " + path + " ]; then echo true; else echo false; fi " ) . get ( 0 ) ) ;
}
}
2016-08-20 15:26:49 +00:00
2016-08-24 21:58:15 +00:00
public static boolean removeFile ( String path ) {
if ( ! Shell . rootAccess ( ) ) {
return false ;
} else {
return Boolean . parseBoolean ( Shell . su ( " rm -f " + path + " 2>/dev/null; if [ -f " + path + " ]; then echo false; else echo true; fi " ) . get ( 0 ) ) ;
2016-08-20 15:26:49 +00:00
}
2016-08-24 21:58:15 +00:00
}
2016-08-22 08:09:36 +00:00
2016-08-24 21:58:15 +00:00
public static List < String > getModList ( String path ) {
List < String > ret ;
ret = Shell . sh ( " find " + path + " -type d -maxdepth 1 | while read ITEM ; do if [ -f $ITEM/module.prop ]; then echo $ITEM; fi; done " ) ;
if ( ret . isEmpty ( ) & & Shell . rootAccess ( ) ) ret = Shell . su ( " find " + path + " -type d -maxdepth 1 | while read ITEM ; do if [ -f $ITEM/module.prop ]; then echo $ITEM; fi; done " ) ;
return ret ;
2016-08-20 15:26:49 +00:00
}
2016-08-24 21:58:15 +00:00
public static List < String > readFile ( String path ) {
List < String > ret ;
ret = Shell . sh ( " cat " + path ) ;
if ( ret . isEmpty ( ) & & Shell . rootAccess ( ) ) ret = Shell . su ( " cat " + path , " echo \ ' \ ' " ) ;
return ret ;
2016-08-22 17:44:34 +00:00
}
2016-08-24 21:58:15 +00:00
2016-08-20 15:26:49 +00:00
}