diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java index 641bed5142..30247cb61c 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java @@ -41,7 +41,7 @@ import net.kdt.pojavlaunch.tasks.AsyncMinecraftDownloader; import net.kdt.pojavlaunch.tasks.AsyncVersionList; import net.kdt.pojavlaunch.lifecycle.ContextAwareDoneListener; -import net.kdt.pojavlaunch.tasks.NewMinecraftDownloader; +import net.kdt.pojavlaunch.tasks.MinecraftDownloader; import net.kdt.pojavlaunch.utils.NotificationUtils; import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles; import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile; @@ -133,7 +133,7 @@ public void onFragmentResumed(@NonNull FragmentManager fm, @NonNull Fragment f) } String normalizedVersionId = AsyncMinecraftDownloader.normalizeVersionId(prof.lastVersionId); JMinecraftVersionList.Version mcVersion = AsyncMinecraftDownloader.getListedVersion(normalizedVersionId); - new NewMinecraftDownloader().start( + new MinecraftDownloader().start( this, mcVersion, normalizedVersionId, diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/modloaders/OptiFineDownloadTask.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/modloaders/OptiFineDownloadTask.java index 762beddd52..91e396ac3f 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/modloaders/OptiFineDownloadTask.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/modloaders/OptiFineDownloadTask.java @@ -7,7 +7,7 @@ import net.kdt.pojavlaunch.Tools; import net.kdt.pojavlaunch.progresskeeper.ProgressKeeper; import net.kdt.pojavlaunch.tasks.AsyncMinecraftDownloader; -import net.kdt.pojavlaunch.tasks.NewMinecraftDownloader; +import net.kdt.pojavlaunch.tasks.MinecraftDownloader; import net.kdt.pojavlaunch.utils.DownloadUtils; import java.io.File; @@ -89,7 +89,7 @@ public boolean downloadMinecraft(String minecraftVersion) { if(minecraftJsonVersion == null) return false; try { synchronized (mMinecraftDownloadLock) { - new NewMinecraftDownloader().start(null, minecraftJsonVersion, minecraftVersion, this); + new MinecraftDownloader().start(null, minecraftJsonVersion, minecraftVersion, this); mMinecraftDownloadLock.wait(); } }catch (InterruptedException e) { diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/NewMinecraftDownloader.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/MinecraftDownloader.java similarity index 96% rename from app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/NewMinecraftDownloader.java rename to app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/MinecraftDownloader.java index 4c6fc49788..167c165382 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/NewMinecraftDownloader.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/MinecraftDownloader.java @@ -36,7 +36,7 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; -public class NewMinecraftDownloader { +public class MinecraftDownloader { public static final String MINECRAFT_RES = "https://resources.download.minecraft.net/"; private AtomicReference mDownloaderThreadException; private ArrayList mScheduledDownloadTasks; @@ -231,14 +231,15 @@ private void growDownloadList(int addedElementCount) { } private void scheduleDownload(File targetFile, int downloadClass, String url, String sha1, - long size, boolean skipIfFailed) { + long size, boolean skipIfFailed) throws IOException { + FileUtils.ensureParentDirectory(targetFile); mDownloadFileCount++; mScheduledDownloadTasks.add( new DownloaderTask(targetFile, downloadClass, url, sha1, size, skipIfFailed) ); } - private void scheduleLibraryDownloads(DependentLibrary[] dependentLibraries) { + private void scheduleLibraryDownloads(DependentLibrary[] dependentLibraries) throws IOException { Tools.preProcessLibraries(dependentLibraries); growDownloadList(dependentLibraries.length); for(DependentLibrary dependentLibrary : dependentLibraries) { @@ -276,7 +277,7 @@ private void scheduleLibraryDownloads(DependentLibrary[] dependentLibraries) { } } - private void scheduleAssetDownloads(JAssets assets) { + private void scheduleAssetDownloads(JAssets assets) throws IOException { Map assetObjects = assets.objects; if(assetObjects == null) return; Set assetNames = assetObjects.keySet(); @@ -286,10 +287,11 @@ private void scheduleAssetDownloads(JAssets assets) { if(assetInfo == null) continue; File targetFile; String hashedPath = assetInfo.hash.substring(0, 2) + File.separator + assetInfo.hash; + String basePath = assets.mapToResources ? Tools.OBSOLETE_RESOURCES_PATH : Tools.ASSETS_PATH; if(assets.virtual || assets.mapToResources) { - targetFile = new File(Tools.OBSOLETE_RESOURCES_PATH, asset); + targetFile = new File(basePath, asset); } else { - targetFile = new File(Tools.ASSETS_PATH, "objects" + File.separator + hashedPath); + targetFile = new File(basePath, "objects" + File.separator + hashedPath); } String sha1 = LauncherPreferences.PREF_CHECK_LIBRARY_SHA ? assetInfo.hash : null; scheduleDownload(targetFile, @@ -301,7 +303,7 @@ private void scheduleAssetDownloads(JAssets assets) { } } - private void scheduleLoggingAssetDownloadIfNeeded(JMinecraftVersionList.LoggingConfig loggingConfig) { + private void scheduleLoggingAssetDownloadIfNeeded(JMinecraftVersionList.LoggingConfig loggingConfig) throws IOException { if(loggingConfig.client == null || loggingConfig.client.file == null) return; JMinecraftVersionList.FileProperties loggingFileProperties = loggingConfig.client.file; File internalLoggingConfig = new File(Tools.DIR_DATA + File.separator + "security", @@ -316,7 +318,7 @@ private void scheduleLoggingAssetDownloadIfNeeded(JMinecraftVersionList.LoggingC false); } - private void scheduleGameJarDownload(MinecraftClientInfo minecraftClientInfo, String versionName) { + private void scheduleGameJarDownload(MinecraftClientInfo minecraftClientInfo, String versionName) throws IOException { File clientJar = createGameJarPath(versionName); String clientSha1 = LauncherPreferences.PREF_CHECK_LIBRARY_SHA ? minecraftClientInfo.sha1 : null; @@ -335,12 +337,12 @@ private void scheduleGameJarDownload(MinecraftClientInfo minecraftClientInfo, St private static byte[] getLocalBuffer() { byte[] tlb = sThreadLocalDownloadBuffer.get(); if(tlb != null) return tlb; - tlb = new byte[65535]; + tlb = new byte[32768]; sThreadLocalDownloadBuffer.set(tlb); return tlb; } - class DownloaderTask implements Runnable, Tools.DownloaderFeedback { + private final class DownloaderTask implements Runnable, Tools.DownloaderFeedback { private final File mTargetPath; private final String mTargetUrl; private String mTargetSha1; @@ -369,7 +371,6 @@ public void run() { } private void runCatching() throws Exception { - FileUtils.ensureParentDirectory(mTargetPath); if(Tools.isValidString(mTargetSha1)) { verifyFileSha1(); }else {