常驻jar缓存,可手动清理(自带md5无需清理);

pull/144/head
21561 1 year ago
parent bff0dba4ed
commit 10c3ff3ab3
  1. 7
      app/src/main/java/com/github/catvod/crawler/JarLoader.java
  2. 16
      app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java
  3. 25
      app/src/main/java/com/github/tvbox/osc/ui/activity/HomeActivity.java
  4. 12
      app/src/main/java/com/github/tvbox/osc/ui/fragment/ModelSettingFragment.java
  5. 3
      app/src/main/java/com/github/tvbox/osc/util/FileUtils.java
  6. 2
      gradle.properties

@ -120,12 +120,17 @@ public class JarLoader {
Log.i("JarLoader", "echo-loadJarInternal jar缓存: " + key);
return classLoaders.get(key);
}
File cache = new File(App.getInstance().getFilesDir().getAbsolutePath() + "/" + key + ".jar");
File cache = new File(App.getInstance().getFilesDir().getAbsolutePath() + "/csp/" + key + ".jar");
if (!md5.isEmpty()) {
if (cache.exists() && MD5.getFileMd5(cache).equalsIgnoreCase(md5)) {
loadClassLoader(cache.getAbsolutePath(), key);
return classLoaders.get(key);
}
}else {
if (cache.exists()) {
loadClassLoader(cache.getAbsolutePath(), key);
return classLoaders.get(key);
}
}
try {
Response response = OkGo.<File>get(jar).execute();

@ -309,7 +309,7 @@ public class ApiConfig {
String[] urls = spider.split(";md5;");
String jarUrl = urls[0];
String md5 = urls.length > 1 ? urls[1].trim() : "";
File cache = new File(App.getInstance().getFilesDir().getAbsolutePath() + "/csp.jar");
File cache = new File(App.getInstance().getFilesDir().getAbsolutePath() + "/csp/"+MD5.string2MD5(jarUrl)+".jar");
if (!md5.isEmpty() || useCache) {
if (cache.exists() && (useCache || MD5.getFileMd5(cache).equalsIgnoreCase(md5))) {
@ -320,6 +320,15 @@ public class ApiConfig {
}
return;
}
}else {
if (cache.exists()) {
if (jarLoader.load(cache.getAbsolutePath())) {
callback.success();
} else {
callback.error("");
}
return;
}
}
boolean isJarInImg = jarUrl.startsWith("img+");
@ -998,4 +1007,9 @@ public class ApiConfig {
public Map<String,String> getMyHost() {
return myHosts;
}
public void clearJarLoader()
{
jarLoader.clear();
}
}

@ -49,8 +49,11 @@ import com.github.tvbox.osc.ui.tv.widget.NoScrollViewPager;
import com.github.tvbox.osc.ui.tv.widget.ViewObj;
import com.github.tvbox.osc.util.AppManager;
import com.github.tvbox.osc.util.DefaultConfig;
import com.github.tvbox.osc.util.FastClickCheckUtil;
import com.github.tvbox.osc.util.FileUtils;
import com.github.tvbox.osc.util.HawkConfig;
import com.github.tvbox.osc.util.LOG;
import com.github.tvbox.osc.util.MD5;
import com.github.tvbox.osc.viewmodel.SourceViewModel;
import com.orhanobut.hawk.Hawk;
import com.owen.tvrecyclerview.widget.TvRecyclerView;
@ -62,6 +65,7 @@ import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -227,11 +231,24 @@ public class HomeActivity extends BaseActivity {
tvName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(dataInitOk && jarInitOk){
showSiteSwitch();
}else {
jumpActivity(SettingActivity.class);
FastClickCheckUtil.check(v);
String cspCachePath = FileUtils.getFilePath()+"/csp/";
String jar=ApiConfig.get().getHomeSourceBean().getJar();
String jarUrl=!jar.isEmpty()?jar:ApiConfig.get().getSpider();
File cspCacheDir = new File(cspCachePath + MD5.string2MD5(jarUrl)+".jar");
if (!cspCacheDir.exists()){
Toast.makeText(mContext, "jar缓存已清除", Toast.LENGTH_LONG).show();
return;
}
new Thread(() -> {
try {
FileUtils.deleteFile(cspCacheDir);
} catch (Exception e) {
e.printStackTrace();
}
}).start();
ApiConfig.get().clearJarLoader();
Toast.makeText(mContext, "jar缓存已清除", Toast.LENGTH_LONG).show();
}
});
tvName.setOnLongClickListener(new View.OnLongClickListener() {

@ -739,15 +739,21 @@ public class ModelSettingFragment extends BaseLazyFragment {
FastClickCheckUtil.check(v);
String cachePath = FileUtils.getCachePath();
File cacheDir = new File(cachePath);
if (!cacheDir.exists()) return;
String cspCachePath = FileUtils.getFilePath()+"/csp/";
File cspCacheDir = new File(cspCachePath);
if (!cacheDir.exists() && !cspCacheDir.exists()) return;
new Thread(() -> {
try {
FileUtils.cleanDirectory(cacheDir);
if(cacheDir.exists())FileUtils.cleanDirectory(cacheDir);
if(cspCacheDir.exists()){
ApiConfig.get().clearJarLoader();
FileUtils.cleanDirectory(cspCacheDir);
}
} catch (Exception e) {
e.printStackTrace();
}
}).start();
Toast.makeText(getContext(), "缓存已清空", Toast.LENGTH_LONG).show();
Toast.makeText(getContext(), "播放&JAR缓存已清空", Toast.LENGTH_LONG).show();
return;
}

@ -115,6 +115,9 @@ public class FileUtils {
public static String getCachePath() {
return getCacheDir().getAbsolutePath();
}
public static String getFilePath() {
return App.getInstance().getFilesDir().getAbsolutePath();
}
public static void cleanDirectory(File dir) {
if (!dir.exists()) return;

@ -17,4 +17,4 @@ android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
IsDebug=true
#org.gradle.jvmargs=-Xmx2048m --add-opens java.base/java.io=ALL-UNNAMED
org.gradle.jvmargs=-Xmx2048m --add-opens java.base/java.io=ALL-UNNAMED

Loading…
Cancel
Save