make DefaultGameRepositoy.readVersionJson nonnull.

This commit is contained in:
huanghongxun 2019-02-10 10:51:04 +08:00
parent e8f5088049
commit 9a6f07d7c9
7 changed files with 11 additions and 25 deletions

View File

@ -80,13 +80,6 @@ public class HMCLGameRepository extends DefaultGameRepository {
}
}
@Override
public void refreshVersions() {
EventBus.EVENT_BUS.fireEvent(new RefreshingVersionsEvent(this));
refreshVersionsImpl();
EventBus.EVENT_BUS.fireEvent(new RefreshedVersionsEvent(this));
}
public void changeDirectory(File newDirectory) {
setBaseDirectory(newDirectory);
refreshVersionsAsync().start();

View File

@ -117,7 +117,7 @@ public class DefaultGameRepository implements GameRepository {
}
public Version readVersionJson(File file) throws IOException, JsonParseException {
return JsonUtils.GSON.fromJson(FileUtils.readText(file), Version.class);
return JsonUtils.fromNonNullJson(FileUtils.readText(file), Version.class);
}
@Override
@ -221,7 +221,7 @@ public class DefaultGameRepository implements GameRepository {
Version version;
try {
version = Objects.requireNonNull(readVersionJson(json));
version = readVersionJson(json);
} catch (Exception e) {
LOG.log(Level.WARNING, "Malformed version json " + id, e);
// JsonSyntaxException or IOException or NullPointerException(!!)
@ -229,7 +229,7 @@ public class DefaultGameRepository implements GameRepository {
return Stream.empty();
try {
version = Objects.requireNonNull(readVersionJson(json));
version = readVersionJson(json);
} catch (Exception e2) {
LOG.log(Level.SEVERE, "User corrected version json is still malformed", e2);
return Stream.empty();

View File

@ -45,13 +45,13 @@ public class Library implements Comparable<Library> {
private final String classifier;
private final String url;
private final LibrariesDownloadInfo downloads;
private final LibraryDownloadInfo download;
private transient final LibraryDownloadInfo download;
private final ExtractRules extract;
private final Map<OperatingSystem, String> natives;
private final List<CompatibilityRule> rules;
private final List<String> checksums;
private final String path;
private transient final String path;
public Library(String groupId, String artifactId, String version) {
this(groupId, artifactId, version, null, null, null);

View File

@ -40,7 +40,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
@ -133,7 +132,7 @@ public final class MultiMCModpackInstallTask extends Task {
@Override
public void execute() throws Exception {
Version version = Objects.requireNonNull(repository.readVersionJson(name));
Version version = repository.readVersionJson(name);
try (FileSystem fs = CompressingUtils.createReadOnlyZipFileSystem(zipFile.toPath())) {
Path root = Files.list(fs.getPath("/")).filter(Files::isDirectory).findAny()

View File

@ -17,14 +17,15 @@
*/
package org.jackhuang.hmcl.util;
import org.jackhuang.hmcl.util.function.ExceptionalRunnable;
import org.jackhuang.hmcl.util.function.ExceptionalSupplier;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import org.jackhuang.hmcl.util.function.ExceptionalRunnable;
import org.jackhuang.hmcl.util.function.ExceptionalSupplier;
/**
*
@ -203,14 +204,6 @@ public final class Lang {
}
}
public static Double toDoubleOrNull(Object string) {
try {
return Double.parseDouble(string.toString());
} catch (NumberFormatException e) {
return null;
}
}
/**
* Find the first non-null reference in given list.
* @param t nullable references list.

View File

@ -25,6 +25,7 @@ import java.util.*;
/**
* Copied from org.apache.maven.artifact.versioning.ComparableVersion
* Apache License 2.0
* @see <a href="http://maven.apache.org/pom.html#Version_Order_Specification">Specification</a>
*/
public class VersionNumber implements Comparable<VersionNumber> {

View File

@ -20,7 +20,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
if (ERROR_SUCCESS != MyGetModuleFileName(NULL, exeName))
return 1;
// TODO: check whether the bundled JRE is valid.
// First try the Java packaged together.
bool is64Bit = false;
GetArch(is64Bit); // if failed to determine architecture of operating system, consider 32-bit.