mirror of
https://github.com/packwiz/packwiz-installer.git
synced 2025-04-19 21:16:30 +02:00
Very fun indeed
This commit is contained in:
parent
320e56e74e
commit
ad79cb3b21
@ -12,25 +12,19 @@ import java.util.List;
|
|||||||
|
|
||||||
class DownloadTask implements IOptionDetails {
|
class DownloadTask implements IOptionDetails {
|
||||||
final IndexFile.File metadata;
|
final IndexFile.File metadata;
|
||||||
|
ManifestFile.File cachedFile = null;
|
||||||
private Exception failure = null;
|
private Exception failure = null;
|
||||||
private boolean complete = false;
|
private boolean alreadyUpToDate = false;
|
||||||
|
private boolean metadataRequired = true;
|
||||||
private boolean invalidated = false;
|
private boolean invalidated = false;
|
||||||
private boolean optionValue = true;
|
|
||||||
// If file is new or isOptional changed to true, the option needs to be presented again
|
// If file is new or isOptional changed to true, the option needs to be presented again
|
||||||
private boolean newOptional = true;
|
private boolean newOptional = true;
|
||||||
|
|
||||||
public DownloadTask(IndexFile.File metadata) {
|
public DownloadTask(IndexFile.File metadata) {
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
if (this.metadata.linkedFile != null) {
|
|
||||||
if (this.metadata.linkedFile.option != null) {
|
|
||||||
// Set option to it's default value
|
|
||||||
optionValue = this.metadata.linkedFile.option.defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefaultHashFormat(String format) {
|
public void setDefaultHashFormat(String format) {
|
||||||
if (failure != null || complete) return;
|
|
||||||
if (metadata.hashFormat == null || metadata.hashFormat.length() == 0) {
|
if (metadata.hashFormat == null || metadata.hashFormat.length() == 0) {
|
||||||
metadata.hashFormat = format;
|
metadata.hashFormat = format;
|
||||||
}
|
}
|
||||||
@ -38,13 +32,15 @@ class DownloadTask implements IOptionDetails {
|
|||||||
|
|
||||||
public void invalidate() {
|
public void invalidate() {
|
||||||
invalidated = true;
|
invalidated = true;
|
||||||
complete = false;
|
alreadyUpToDate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateFromCache(ManifestFile.File cachedFile) {
|
public void updateFromCache(ManifestFile.File cachedFile) {
|
||||||
if (failure != null || complete) return;
|
if (failure != null) return;
|
||||||
if (cachedFile == null) return;
|
if (cachedFile == null) return;
|
||||||
|
|
||||||
|
this.cachedFile = cachedFile;
|
||||||
|
|
||||||
if (!invalidated) {
|
if (!invalidated) {
|
||||||
Hash currHash = null;
|
Hash currHash = null;
|
||||||
try {
|
try {
|
||||||
@ -55,25 +51,41 @@ class DownloadTask implements IOptionDetails {
|
|||||||
}
|
}
|
||||||
if (currHash != null && currHash.equals(cachedFile.hash)) {
|
if (currHash != null && currHash.equals(cachedFile.hash)) {
|
||||||
// Already up to date
|
// Already up to date
|
||||||
complete = true;
|
alreadyUpToDate = true;
|
||||||
|
metadataRequired = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cachedFile.isOptional) {
|
if (cachedFile.isOptional) {
|
||||||
// Set option to the cached value
|
// Because option selection dialog might set this task to true/false, metadata is always needed to download
|
||||||
optionValue = cachedFile.optionValue;
|
// the file, and to show the description and name
|
||||||
if (isOptional()) {
|
metadataRequired = true;
|
||||||
// isOptional didn't change
|
|
||||||
newOptional = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void downloadMetadata(IndexFile parentIndexFile, URI indexUri) {
|
public void downloadMetadata(IndexFile parentIndexFile, URI indexUri) {
|
||||||
if (failure != null || complete) return;
|
if (failure != null) return;
|
||||||
|
if (metadataRequired) {
|
||||||
try {
|
try {
|
||||||
metadata.downloadMeta(parentIndexFile, indexUri);
|
metadata.downloadMeta(parentIndexFile, indexUri);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
failure = e;
|
failure = e;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (metadata.linkedFile != null) {
|
||||||
|
if (metadata.linkedFile.option != null) {
|
||||||
|
if (metadata.linkedFile.option.optional) {
|
||||||
|
if (cachedFile.isOptional) {
|
||||||
|
// isOptional didn't change
|
||||||
|
newOptional = false;
|
||||||
|
} else {
|
||||||
|
// isOptional false -> true, set option to it's default value
|
||||||
|
// TODO: preserve previous option value, somehow??
|
||||||
|
cachedFile.optionValue = this.metadata.linkedFile.option.defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cachedFile.isOptional = isOptional();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +110,7 @@ class DownloadTask implements IOptionDetails {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getOptionValue() {
|
public boolean getOptionValue() {
|
||||||
return this.optionValue;
|
return this.cachedFile.optionValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -110,8 +122,12 @@ class DownloadTask implements IOptionDetails {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setOptionValue(boolean value) {
|
public void setOptionValue(boolean value) {
|
||||||
// TODO: if this is false, ensure the file is deleted in the actual download stage
|
// TODO: if this is false, ensure the file is deleted in the actual download stage (regardless of alreadyUpToDate?)
|
||||||
this.optionValue = value;
|
if (value && !this.cachedFile.optionValue) {
|
||||||
|
// Ensure that an update is done if it changes from false to true
|
||||||
|
alreadyUpToDate = false;
|
||||||
|
}
|
||||||
|
this.cachedFile.optionValue = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<DownloadTask> createTasksFromIndex(IndexFile index) {
|
public static List<DownloadTask> createTasksFromIndex(IndexFile index) {
|
||||||
|
@ -276,9 +276,9 @@ public class UpdateManager {
|
|||||||
List<DownloadTask> failedTasks = tasks.stream().filter(t -> t.getException() != null).collect(Collectors.toList());
|
List<DownloadTask> failedTasks = tasks.stream().filter(t -> t.getException() != null).collect(Collectors.toList());
|
||||||
|
|
||||||
// If options changed, present all options again
|
// If options changed, present all options again
|
||||||
if (tasks.stream().filter(DownloadTask::isNewOptional).count() > 0) {
|
if (tasks.stream().anyMatch(DownloadTask::isNewOptional)) {
|
||||||
List<IOptionDetails> opts = tasks.stream().filter(DownloadTask::isOptional).collect(Collectors.toList());
|
List<IOptionDetails> opts = tasks.stream().filter(DownloadTask::isOptional).collect(Collectors.toList());
|
||||||
// TODO: present options
|
ui.showOptions(opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: different thread pool type?
|
// TODO: different thread pool type?
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
package link.infra.packwiz.installer.metadata;
|
package link.infra.packwiz.installer.metadata;
|
||||||
|
|
||||||
|
import link.infra.packwiz.installer.metadata.hash.Hash;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import link.infra.packwiz.installer.metadata.hash.Hash;
|
|
||||||
|
|
||||||
public class ManifestFile {
|
public class ManifestFile {
|
||||||
|
|
||||||
public Hash packFileHash = null;
|
public Hash packFileHash = null;
|
||||||
public Hash indexFileHash = null;
|
public Hash indexFileHash = null;
|
||||||
public Map<URI, File> cachedFiles;
|
public Map<URI, File> cachedFiles;
|
||||||
|
|
||||||
public static class File {
|
public static class File {
|
||||||
public Hash hash = null;
|
public Hash hash = null;
|
||||||
public boolean isOptional = false;
|
|
||||||
public boolean optionValue = true;
|
|
||||||
public Hash linkedFileHash = null;
|
public Hash linkedFileHash = null;
|
||||||
public String cachedLocation = null;
|
public String cachedLocation = null;
|
||||||
|
|
||||||
|
public boolean isOptional = false;
|
||||||
|
public boolean optionValue = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user