diff --git a/app/src/main/java/com/github/catvod/crawler/JarLoader.java b/app/src/main/java/com/github/catvod/crawler/JarLoader.java index 8d45365e..daf07be6 100644 --- a/app/src/main/java/com/github/catvod/crawler/JarLoader.java +++ b/app/src/main/java/com/github/catvod/crawler/JarLoader.java @@ -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.get(jar).execute(); diff --git a/app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java b/app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java index 5e4cecda..e39caa50 100644 --- a/app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java +++ b/app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java @@ -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 getMyHost() { return myHosts; } + + public void clearJarLoader() + { + jarLoader.clear(); + } } diff --git a/app/src/main/java/com/github/tvbox/osc/ui/activity/HomeActivity.java b/app/src/main/java/com/github/tvbox/osc/ui/activity/HomeActivity.java index de871dd1..ede0441b 100644 --- a/app/src/main/java/com/github/tvbox/osc/ui/activity/HomeActivity.java +++ b/app/src/main/java/com/github/tvbox/osc/ui/activity/HomeActivity.java @@ -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() { diff --git a/app/src/main/java/com/github/tvbox/osc/ui/fragment/ModelSettingFragment.java b/app/src/main/java/com/github/tvbox/osc/ui/fragment/ModelSettingFragment.java index 927e836b..ed6a4b05 100644 --- a/app/src/main/java/com/github/tvbox/osc/ui/fragment/ModelSettingFragment.java +++ b/app/src/main/java/com/github/tvbox/osc/ui/fragment/ModelSettingFragment.java @@ -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; } diff --git a/app/src/main/java/com/github/tvbox/osc/util/FileUtils.java b/app/src/main/java/com/github/tvbox/osc/util/FileUtils.java index 5c08dfe3..e72cbba5 100644 --- a/app/src/main/java/com/github/tvbox/osc/util/FileUtils.java +++ b/app/src/main/java/com/github/tvbox/osc/util/FileUtils.java @@ -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; diff --git a/gradle.properties b/gradle.properties index 8b1a2183..e86424f0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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