mirror of
https://github.com/packwiz/packwiz-installer.git
synced 2025-10-17 00:14:33 +02:00
Compare commits
3 Commits
v0.0.6-pre
...
v0.0.9-pre
Author | SHA1 | Date | |
---|---|---|---|
|
794b817eff | ||
|
a5ff63c587 | ||
|
34a86ffb7d |
@@ -146,7 +146,24 @@ 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<>();
|
||||||
|
if (manifest.cachedFiles != null) {
|
||||||
|
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;
|
||||||
@@ -156,7 +173,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);
|
||||||
}
|
}
|
||||||
@@ -177,8 +194,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;
|
||||||
}
|
}
|
||||||
@@ -212,25 +229,19 @@ public class UpdateManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ui.submitProgress(new InstallProgress("Checking local files..."));
|
ui.submitProgress(new InstallProgress("Checking local files..."));
|
||||||
List<URI> invalidatedUris = new ArrayList<>();
|
|
||||||
Iterator<Map.Entry<URI, ManifestFile.File>> it = manifest.cachedFiles.entrySet().iterator();
|
Iterator<Map.Entry<URI, ManifestFile.File>> it = manifest.cachedFiles.entrySet().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Map.Entry<URI, ManifestFile.File> entry = it.next();
|
Map.Entry<URI, ManifestFile.File> entry = it.next();
|
||||||
if (entry.getValue().cachedLocation != null) {
|
if (entry.getValue().cachedLocation != null) {
|
||||||
Path filePath = Paths.get(opts.packFolder, entry.getValue().cachedLocation);
|
if (!indexFile.files.stream().anyMatch(f -> f.file.equals(entry.getKey()))) {
|
||||||
URI fileUri = entry.getKey();
|
|
||||||
|
|
||||||
if (!indexFile.files.stream().anyMatch(f -> f.file.equals(fileUri))) {
|
|
||||||
// File has been removed from the index
|
// File has been removed from the index
|
||||||
try {
|
try {
|
||||||
Files.deleteIfExists(filePath);
|
Files.deleteIfExists(Paths.get(opts.packFolder, entry.getValue().cachedLocation));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO: should this be shown to the user in some way?
|
// TODO: should this be shown to the user in some way?
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
it.remove();
|
it.remove();
|
||||||
} else if (!Files.exists(filePath)) {
|
|
||||||
invalidatedUris.add(fileUri);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -302,9 +313,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -326,8 +339,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());
|
||||||
@@ -335,6 +348,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;
|
||||||
|
Reference in New Issue
Block a user