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