Fixed NPE downloading assets and there is no version

This commit is contained in:
huangyuhui 2017-01-25 18:07:22 +08:00
parent 74ad750d1d
commit 574532f10c
4 changed files with 44 additions and 31 deletions

View File

@ -15,29 +15,16 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
buildscript {
repositories {
mavenCentral();
dependencies {
classpath 'net.sf.proguard:proguard-gradle:4.10'
classpath 'edu.sc.seis.gradle:launch4j:1.0.6'
classpath 'me.tatarka:gradle-retrolambda:3.4.0'
}
}
}
plugins {
id "edu.sc.seis.macAppBundle" version "2.1.6"
id "me.tatarka.retrolambda" version "3.5.0"
id 'edu.sc.seis.launch4j' version '2.3.0'
}
import java.util.jar.JarOutputStream
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
apply plugin: 'launch4j'
apply plugin: 'me.tatarka.retrolambda'
if (!hasProperty('mainClass')) {
ext.mainClass = 'org.jackhuang.hellominecraft.launcher.Main'
}
@ -46,7 +33,7 @@ def buildnumber = System.getenv("TRAVIS_BUILD_NUMBER")
if (buildnumber == null)
buildnumber = System.getenv("BUILD_NUMBER")
if (buildnumber == null)
buildnumber = "2"
buildnumber = "3"
def versionroot = System.getenv("VERSION_ROOT")
if (versionroot == null)
@ -142,8 +129,6 @@ jar {
}
launch4j {
launch4jCmd = 'D:\\Develop\\Java\\Launch4j\\launch4j.exe'
//launch4jCmd = '/home/huangyuhui/softwares/launch4j/launch4j'
supportUrl = 'http://www.mcbbs.net/thread-142335-1-1.html'
jreMinVersion = '1.6.0'

View File

@ -24,13 +24,13 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.launch.IAssetProvider;
import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.version.AssetIndexDownloadInfo;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.util.MessageBox;
import org.jackhuang.hellominecraft.util.func.BiFunction;
import org.jackhuang.hellominecraft.util.logging.HMCLog;
import org.jackhuang.hellominecraft.util.tasks.Task;
import org.jackhuang.hellominecraft.util.tasks.TaskWindow;
@ -51,21 +51,21 @@ public class MinecraftAssetService extends IMinecraftAssetService {
@Override
public Task downloadAssets(final String mcVersion) throws GameException {
return downloadAssets(service.version().getVersionById(mcVersion).resolve(service.version()));
return downloadAssets(service.version().getVersionById(mcVersion));
}
public Task downloadAssets(final MinecraftVersion mv) {
public Task downloadAssets(final MinecraftVersion mv) throws GameException {
if (mv == null)
return null;
return IAssetsHandler.ASSETS_HANDLER.getList(mv, service.asset()).after(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(service.getDownloadType().getProvider()));
return IAssetsHandler.ASSETS_HANDLER.getList(mv.resolve(service.version()), service.asset()).after(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(service.getDownloadType().getProvider()));
}
@Override
public boolean refreshAssetsIndex(String id) throws GameException {
MinecraftVersion mv = service.version().getVersionById(id).resolve(service.version());
MinecraftVersion mv = service.version().getVersionById(id);
if (mv == null)
return false;
return downloadMinecraftAssetsIndexAsync(mv.getAssetsIndex());
return downloadMinecraftAssetsIndexAsync(mv.resolve(service.version()).getAssetsIndex());
}
@Override
@ -205,7 +205,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
return virtualRoot;
}
public final BiFunction<MinecraftVersion, Boolean, String> ASSET_PROVIDER_IMPL = (t, allow) -> {
public final IAssetProvider ASSET_PROVIDER_IMPL = (t, allow) -> {
if (allow && !checkAssetsExistance(t.getAssetsIndex()))
if (MessageBox.show(C.i18n("assets.no_assets"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
TaskWindow.factory().execute(downloadAssets(t));

View File

@ -0,0 +1,30 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.core.launch;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
/**
*
* @author huang
*/
public interface IAssetProvider {
String provide(MinecraftVersion mv, Boolean allowChecking) throws GameException;
}

View File

@ -29,9 +29,7 @@ import org.jackhuang.hellominecraft.util.system.OS;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.util.func.BiFunction;
/**
*
@ -76,7 +74,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
throw new GameException(new NullPointerException("Minecraft Arguments can not be null."));
String[] splitted = StrUtils.tokenize(version.minecraftArguments);
String game_assets = assetProvider.apply(version, !options.isNotCheckGame());
String game_assets = assetProvider.provide(version, !options.isNotCheckGame());
for (String t : splitted) {
t = t.replace("${auth_player_name}", lr.getUserName());
@ -115,13 +113,13 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
}
}
private final BiFunction<MinecraftVersion, Boolean, String> DEFAULT_ASSET_PROVIDER = (t, allow) -> {
private final IAssetProvider DEFAULT_ASSET_PROVIDER = (t, allow) -> {
return new File(service.baseDirectory(), "assets").getAbsolutePath();
};
private BiFunction<MinecraftVersion, Boolean, String> assetProvider = DEFAULT_ASSET_PROVIDER;
private IAssetProvider assetProvider = DEFAULT_ASSET_PROVIDER;
public void setAssetProvider(BiFunction<MinecraftVersion, Boolean, String> assetProvider) {
public void setAssetProvider(IAssetProvider assetProvider) {
if (assetProvider == null)
this.assetProvider = DEFAULT_ASSET_PROVIDER;
else