mirror of
https://github.com/packwiz/packwiz-installer.git
synced 2025-10-17 08:24:32 +02:00
Compare commits
3 Commits
v0.0.5-pre
...
v0.0.8-pre
Author | SHA1 | Date | |
---|---|---|---|
|
a5ff63c587 | ||
|
34a86ffb7d | ||
|
780efe2c9f |
@@ -7,10 +7,14 @@ import java.io.IOException;
|
|||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.CompletionService;
|
import java.util.concurrent.CompletionService;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
@@ -142,7 +146,22 @@ public class UpdateManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (manifest.packFileHash != null && packFileSource.hashIsEqual(manifest.packFileHash)) {
|
ui.submitProgress(new InstallProgress("Checking local files..."));
|
||||||
|
|
||||||
|
List<URI> invalidatedUris = new ArrayList<>();
|
||||||
|
Iterator<Map.Entry<URI, ManifestFile.File>> it = manifest.cachedFiles.entrySet().iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Map.Entry<URI, ManifestFile.File> entry = it.next();
|
||||||
|
if (entry.getValue().cachedLocation != null) {
|
||||||
|
if (!Files.exists(Paths.get(opts.packFolder, entry.getValue().cachedLocation))) {
|
||||||
|
URI fileUri = entry.getKey();
|
||||||
|
System.out.println("File " + fileUri.toString() + " invalidated, marked for redownloading");
|
||||||
|
invalidatedUris.add(fileUri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (manifest.packFileHash != null && packFileSource.hashIsEqual(manifest.packFileHash) && invalidatedUris.size() == 0) {
|
||||||
System.out.println("Modpack is already up to date!");
|
System.out.println("Modpack is already up to date!");
|
||||||
// todo: --force?
|
// todo: --force?
|
||||||
return;
|
return;
|
||||||
@@ -152,7 +171,7 @@ public class UpdateManager {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
processIndex(HandlerManager.getNewLoc(opts.downloadURI, pf.index.file),
|
processIndex(HandlerManager.getNewLoc(opts.downloadURI, pf.index.file),
|
||||||
HashUtils.getHash(pf.index.hashFormat, pf.index.hash), pf.index.hashFormat, manifest);
|
HashUtils.getHash(pf.index.hashFormat, pf.index.hash), pf.index.hashFormat, manifest, invalidatedUris);
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
ui.handleExceptionAndExit(e1);
|
ui.handleExceptionAndExit(e1);
|
||||||
}
|
}
|
||||||
@@ -173,8 +192,8 @@ public class UpdateManager {
|
|||||||
// TODO: implement
|
// TODO: implement
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void processIndex(URI indexUri, Hash indexHash, String hashFormat, ManifestFile manifest) {
|
protected void processIndex(URI indexUri, Hash indexHash, String hashFormat, ManifestFile manifest, List<URI> invalidatedUris) {
|
||||||
if (manifest.indexFileHash != null && manifest.indexFileHash.equals(indexHash)) {
|
if (manifest.indexFileHash != null && manifest.indexFileHash.equals(indexHash) && invalidatedUris.size() == 0) {
|
||||||
System.out.println("Modpack files are already up to date!");
|
System.out.println("Modpack files are already up to date!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -207,6 +226,25 @@ public class UpdateManager {
|
|||||||
manifest.cachedFiles = new HashMap<URI, ManifestFile.File>();
|
manifest.cachedFiles = new HashMap<URI, ManifestFile.File>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui.submitProgress(new InstallProgress("Checking local files..."));
|
||||||
|
Iterator<Map.Entry<URI, ManifestFile.File>> it = manifest.cachedFiles.entrySet().iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Map.Entry<URI, ManifestFile.File> entry = it.next();
|
||||||
|
if (entry.getValue().cachedLocation != null) {
|
||||||
|
if (!indexFile.files.stream().anyMatch(f -> f.file.equals(entry.getKey()))) {
|
||||||
|
// File has been removed from the index
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(Paths.get(opts.packFolder, entry.getValue().cachedLocation));
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO: should this be shown to the user in some way?
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ui.submitProgress(new InstallProgress("Comparing new files..."));
|
||||||
|
|
||||||
// TODO: progress bar
|
// TODO: progress bar
|
||||||
ConcurrentLinkedQueue<Exception> exceptionQueue = new ConcurrentLinkedQueue<Exception>();
|
ConcurrentLinkedQueue<Exception> exceptionQueue = new ConcurrentLinkedQueue<Exception>();
|
||||||
List<IndexFile.File> newFiles = indexFile.files.stream().map(f -> {
|
List<IndexFile.File> newFiles = indexFile.files.stream().map(f -> {
|
||||||
@@ -215,6 +253,9 @@ public class UpdateManager {
|
|||||||
}
|
}
|
||||||
return f;
|
return f;
|
||||||
}).filter(f -> {
|
}).filter(f -> {
|
||||||
|
if (invalidatedUris.contains(f.file)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
ManifestFile.File cachedFile = manifest.cachedFiles.get(f.file);
|
ManifestFile.File cachedFile = manifest.cachedFiles.get(f.file);
|
||||||
Hash newHash;
|
Hash newHash;
|
||||||
try {
|
try {
|
||||||
@@ -270,9 +311,11 @@ public class UpdateManager {
|
|||||||
} catch (Exception e) {}
|
} catch (Exception e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Path destPath = Paths.get(opts.packFolder, f.getDestURI().toString());
|
||||||
|
|
||||||
// Don't update files marked with preserve if they already exist on disk
|
// Don't update files marked with preserve if they already exist on disk
|
||||||
if (f.preserve) {
|
if (f.preserve) {
|
||||||
if (Files.exists(Paths.get(opts.packFolder, f.getDestURI().toString()))) {
|
if (Files.exists(destPath)) {
|
||||||
return dc;
|
return dc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -294,8 +337,8 @@ public class UpdateManager {
|
|||||||
Okio.buffer(fileSource).readAll(data);
|
Okio.buffer(fileSource).readAll(data);
|
||||||
|
|
||||||
if (fileSource.hashIsEqual(hash)) {
|
if (fileSource.hashIsEqual(hash)) {
|
||||||
Files.createDirectories(Paths.get(opts.packFolder, f.getDestURI().toString()).getParent());
|
Files.createDirectories(destPath.getParent());
|
||||||
Files.copy(data.inputStream(), Paths.get(opts.packFolder, f.getDestURI().toString()), StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(data.inputStream(), destPath, StandardCopyOption.REPLACE_EXISTING);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Invalid hash for " + f.getDestURI().toString());
|
System.out.println("Invalid hash for " + f.getDestURI().toString());
|
||||||
System.out.println("Calculated: " + fileSource.getHash());
|
System.out.println("Calculated: " + fileSource.getHash());
|
||||||
@@ -303,6 +346,11 @@ public class UpdateManager {
|
|||||||
dc.err = new Exception("Hash invalid!");
|
dc.err = new Exception("Hash invalid!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cachedFile != null && !destPath.equals(Paths.get(opts.packFolder, cachedFile.cachedLocation))) {
|
||||||
|
// Delete old file if location changes
|
||||||
|
Files.delete(Paths.get(opts.packFolder, cachedFile.cachedLocation));
|
||||||
|
}
|
||||||
|
|
||||||
return dc;
|
return dc;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
dc.err = e;
|
dc.err = e;
|
||||||
@@ -343,6 +391,7 @@ public class UpdateManager {
|
|||||||
ret.err = e;
|
ret.err = e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
newCachedFile.cachedLocation = ret.file.getDestURI().toString();
|
||||||
manifest.cachedFiles.put(ret.file.file, newCachedFile);
|
manifest.cachedFiles.put(ret.file.file, newCachedFile);
|
||||||
}
|
}
|
||||||
// TODO: show errors properly?
|
// TODO: show errors properly?
|
||||||
|
@@ -16,5 +16,6 @@ public class ManifestFile {
|
|||||||
public boolean isOptional = false;
|
public boolean isOptional = false;
|
||||||
public boolean optionValue = true;
|
public boolean optionValue = true;
|
||||||
public Hash linkedFileHash = null;
|
public Hash linkedFileHash = null;
|
||||||
|
public String cachedLocation = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user