mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-09 03:46:18 -04:00
update
This commit is contained in:
parent
43c8234675
commit
310717d877
@ -37,8 +37,6 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReadWriteLock;
|
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
|
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
|
||||||
@ -46,7 +44,6 @@ import static org.jackhuang.hmcl.util.logging.Logger.LOG;
|
|||||||
public class DefaultCacheRepository extends CacheRepository {
|
public class DefaultCacheRepository extends CacheRepository {
|
||||||
private Path librariesDir;
|
private Path librariesDir;
|
||||||
private Path indexFile;
|
private Path indexFile;
|
||||||
private final ReadWriteLock lock = new ReentrantReadWriteLock();
|
|
||||||
private Index index = null;
|
private Index index = null;
|
||||||
|
|
||||||
public DefaultCacheRepository() {
|
public DefaultCacheRepository() {
|
||||||
@ -67,9 +64,13 @@ public class DefaultCacheRepository extends CacheRepository {
|
|||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
if (Files.isRegularFile(indexFile)) {
|
if (Files.isRegularFile(indexFile)) {
|
||||||
index = JsonUtils.fromNonNullJson(Files.readString(indexFile), Index.class);
|
index = JsonUtils.fromJsonFile(indexFile, Index.class);
|
||||||
} else
|
if (index == null) {
|
||||||
|
throw new JsonParseException("Index file is empty or invalid");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
index = new Index();
|
index = new Index();
|
||||||
|
}
|
||||||
} catch (IOException | JsonParseException e) {
|
} catch (IOException | JsonParseException e) {
|
||||||
LOG.warning("Unable to read index file", e);
|
LOG.warning("Unable to read index file", e);
|
||||||
index = new Index();
|
index = new Index();
|
||||||
@ -215,13 +216,13 @@ public class DefaultCacheRepository extends CacheRepository {
|
|||||||
/// ```json
|
/// ```json
|
||||||
/// "libraries": {
|
/// "libraries": {
|
||||||
/// // allow a library has multiple hash code.
|
/// // allow a library has multiple hash code.
|
||||||
/// [
|
/// [
|
||||||
/// "name": "net.minecraftforge:forge:1.11.2-13.20.0.2345",
|
/// "name": "net.minecraftforge:forge:1.11.2-13.20.0.2345",
|
||||||
/// "hash": "blablabla",
|
/// "hash": "blablabla",
|
||||||
/// "type": "forge"
|
/// "type": "forge"
|
||||||
/// ]
|
/// ]
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
///```
|
||||||
/// assets and versions will not be included in index.
|
/// assets and versions will not be included in index.
|
||||||
private static final class Index implements Validation {
|
private static final class Index implements Validation {
|
||||||
private final Set<LibraryIndex> libraries;
|
private final Set<LibraryIndex> libraries;
|
||||||
|
@ -53,7 +53,7 @@ public class CacheRepository {
|
|||||||
private Path indexFile;
|
private Path indexFile;
|
||||||
private FileTime indexFileLastModified;
|
private FileTime indexFileLastModified;
|
||||||
private LinkedHashMap<URI, ETagItem> index;
|
private LinkedHashMap<URI, ETagItem> index;
|
||||||
private final ReadWriteLock lock = new ReentrantReadWriteLock();
|
protected final ReadWriteLock lock = new ReentrantReadWriteLock();
|
||||||
|
|
||||||
public void changeDirectory(Path commonDir) {
|
public void changeDirectory(Path commonDir) {
|
||||||
commonDirectory = commonDir;
|
commonDirectory = commonDir;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user