|
|
|
|
@ -16,10 +16,8 @@ import java.io.File; |
|
|
|
|
import java.io.FileInputStream; |
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
import java.io.InputStreamReader; |
|
|
|
|
import java.math.BigInteger; |
|
|
|
|
import java.net.URLConnection; |
|
|
|
|
import java.security.MessageDigest; |
|
|
|
|
import java.security.NoSuchAlgorithmException; |
|
|
|
|
|
|
|
|
|
public class FileUtil { |
|
|
|
|
|
|
|
|
|
@ -42,7 +40,7 @@ public class FileUtil { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static File getJar(String fileName) { |
|
|
|
|
return getCacheFile(getMD5(fileName).concat(".jar")); |
|
|
|
|
return getCacheFile(Utils.getMD5(fileName).concat(".jar")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static File getLocal(String path) { |
|
|
|
|
@ -80,17 +78,7 @@ public class FileUtil { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static String convert(String text) { |
|
|
|
|
if (TextUtils.isEmpty(text)) return ""; |
|
|
|
|
if (text.startsWith("clan")) return text.replace("clan", "file"); |
|
|
|
|
if (text.startsWith(".")) text = text.substring(1); |
|
|
|
|
if (text.startsWith("/")) text = text.substring(1); |
|
|
|
|
Uri uri = Uri.parse(Prefers.getUrl()); |
|
|
|
|
if (uri.getLastPathSegment() == null) return uri.getScheme() + "://" + text; |
|
|
|
|
return uri.toString().replace(uri.getLastPathSegment(), text); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static String getMd5(File file) { |
|
|
|
|
public static String getMd5(File file) { |
|
|
|
|
try { |
|
|
|
|
MessageDigest digest = MessageDigest.getInstance("MD5"); |
|
|
|
|
FileInputStream fis = new FileInputStream(file); |
|
|
|
|
@ -107,20 +95,6 @@ public class FileUtil { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static String getMD5(String src) { |
|
|
|
|
try { |
|
|
|
|
if (TextUtils.isEmpty(src)) return ""; |
|
|
|
|
MessageDigest md = MessageDigest.getInstance("MD5"); |
|
|
|
|
byte[] messageDigest = md.digest(src.getBytes()); |
|
|
|
|
BigInteger no = new BigInteger(1, messageDigest); |
|
|
|
|
StringBuilder sb = new StringBuilder(no.toString(16)); |
|
|
|
|
while (sb.length() < 32) sb.insert(0, "0"); |
|
|
|
|
return sb.toString().toLowerCase(); |
|
|
|
|
} catch (NoSuchAlgorithmException e) { |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static boolean equals(String jar, String md5) { |
|
|
|
|
return getMd5(getJar(jar)).equalsIgnoreCase(md5); |
|
|
|
|
} |
|
|
|
|
|