From f1ee8f0177abf5294ba15204728d66bc44044d30 Mon Sep 17 00:00:00 2001 From: artdeell Date: Sat, 14 Oct 2023 08:17:11 +0300 Subject: [PATCH] Fix[code]: clearer meanings for some stuff and remove hardcoded -1, -1 for ProgressKeeper --- .../net/kdt/pojavlaunch/mirrors/DownloadMirror.java | 7 +++---- .../prefs/screens/LauncherPreferenceJavaFragment.java | 5 ----- .../pojavlaunch/tasks/AsyncMinecraftDownloader.java | 10 +++++----- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/mirrors/DownloadMirror.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/mirrors/DownloadMirror.java index f50b7cb13..ad95dcfff 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/mirrors/DownloadMirror.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/mirrors/DownloadMirror.java @@ -18,12 +18,12 @@ public class DownloadMirror { public static final int DOWNLOAD_CLASS_METADATA = 1; public static final int DOWNLOAD_CLASS_ASSETS = 2; + private static final String URL_PROTOCOL_TAIL = "://"; private static final String[] MIRROR_BMCLAPI = { "https://bmclapi2.bangbang93.com/maven", "https://bmclapi2.bangbang93.com", "https://bmclapi2.bangbang93.com/assets" }; - private static final String[] MIRROR_MCBBS = { "https://download.mcbbs.net/maven", "https://download.mcbbs.net", @@ -91,15 +91,14 @@ public class DownloadMirror { } private static int getBaseUrlTail(String wholeUrl) throws MalformedURLException{ - int protocolNameEnd = wholeUrl.indexOf("://"); + int protocolNameEnd = wholeUrl.indexOf(URL_PROTOCOL_TAIL); if(protocolNameEnd == -1) throw new MalformedURLException("No protocol, or non path-based URL"); - protocolNameEnd += 3; + protocolNameEnd += URL_PROTOCOL_TAIL.length(); int hostnameEnd = wholeUrl.indexOf('/', protocolNameEnd); if(protocolNameEnd >= wholeUrl.length() || hostnameEnd == protocolNameEnd) throw new MalformedURLException("No hostname"); if(hostnameEnd == -1) hostnameEnd = wholeUrl.length(); - System.out.println(protocolNameEnd +" "+ hostnameEnd); return hostnameEnd; } } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceJavaFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceJavaFragment.java index f5696f0be..1b2ba3f44 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceJavaFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceJavaFragment.java @@ -27,11 +27,6 @@ public class LauncherPreferenceJavaFragment extends LauncherPreferenceFragment { if(data != null) Tools.installRuntimeFromUri(getContext(), data); }); - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - } - @Override public void onCreatePreferences(Bundle b, String str) { int ramAllocation = LauncherPreferences.PREF_RAM_ALLOCATION; diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/AsyncMinecraftDownloader.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/AsyncMinecraftDownloader.java index 770296a9a..8bb1dc640 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/AsyncMinecraftDownloader.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/AsyncMinecraftDownloader.java @@ -92,7 +92,7 @@ public class AsyncMinecraftDownloader { // THIS one function need the activity in the case of an error if(activity != null && !JRE17Util.installNewJreIfNeeded(activity, verInfo)){ - ProgressKeeper.submitProgress(ProgressLayout.DOWNLOAD_MINECRAFT, -1, -1); + ProgressLayout.clearProgress(ProgressLayout.DOWNLOAD_MINECRAFT); throw new DownloaderException(); } @@ -188,11 +188,11 @@ public class AsyncMinecraftDownloader { } } } catch (DownloaderException e) { - ProgressKeeper.submitProgress(ProgressLayout.DOWNLOAD_MINECRAFT, -1, -1); + ProgressLayout.clearProgress(ProgressLayout.DOWNLOAD_MINECRAFT); throw e; } catch (Throwable e) { Log.e("AsyncMcDownloader", e.toString(),e ); - ProgressKeeper.submitProgress(ProgressLayout.DOWNLOAD_MINECRAFT, -1, -1); + ProgressLayout.clearProgress(ProgressLayout.DOWNLOAD_MINECRAFT); throw new DownloaderException(e); } @@ -211,10 +211,10 @@ public class AsyncMinecraftDownloader { downloadAssets(assets, assets.mapToResources ? new File(Tools.OBSOLETE_RESOURCES_PATH) : new File(Tools.ASSETS_PATH)); } catch (Exception e) { Log.e("AsyncMcDownloader", e.toString(), e); - ProgressKeeper.submitProgress(ProgressLayout.DOWNLOAD_MINECRAFT, -1, -1); + ProgressLayout.clearProgress(ProgressLayout.DOWNLOAD_MINECRAFT); throw new DownloaderException(e); } - ProgressKeeper.submitProgress(ProgressLayout.DOWNLOAD_MINECRAFT, -1, -1); + ProgressLayout.clearProgress(ProgressLayout.DOWNLOAD_MINECRAFT); } public void verifyAndDownloadMainJar(String url, String sha1, File destination) throws Exception{