mirror of
https://github.com/packwiz/packwiz-installer.git
synced 2025-04-19 13:06:30 +02:00
Rework target into interface; add overwrite mode and validity/identity tokens
This commit is contained in:
parent
89bdfd9c98
commit
07af6046c1
@ -0,0 +1,13 @@
|
||||
package link.infra.packwiz.installer.target
|
||||
|
||||
enum class OverwriteMode {
|
||||
/**
|
||||
* Overwrite the destination with the source file, if the source file has changed.
|
||||
*/
|
||||
IF_SRC_CHANGED,
|
||||
|
||||
/**
|
||||
* Never overwrite the destination; if it exists, it should not be written to.
|
||||
*/
|
||||
NEVER
|
||||
}
|
@ -1,32 +1,45 @@
|
||||
package link.infra.packwiz.installer.target
|
||||
|
||||
import link.infra.packwiz.installer.metadata.SpaceSafeURI
|
||||
import link.infra.packwiz.installer.metadata.hash.Hash
|
||||
import java.nio.file.Path
|
||||
import link.infra.packwiz.installer.target.path.PackwizPath
|
||||
|
||||
// TODO: rename to avoid conflicting with @Target
|
||||
interface Target {
|
||||
val src: PackwizPath
|
||||
val dest: PackwizPath
|
||||
val validityToken: ValidityToken
|
||||
|
||||
data class Target(
|
||||
/**
|
||||
* The name that uniquely identifies this target.
|
||||
* Often equal to the name of the metadata file for this target, and can be displayed to the user in progress UI.
|
||||
* Token interface for types used to compare Target identity. Implementations should use equals to indicate that
|
||||
* these tokens represent the same file; used to preserve optional target choices between file renames.
|
||||
*/
|
||||
val name: String,
|
||||
interface IdentityToken
|
||||
|
||||
/**
|
||||
* An optional user-friendly name.
|
||||
* Default implementation of IdentityToken that assumes files are not renamed; so optional choices do not need to
|
||||
* be preserved across renames.
|
||||
*/
|
||||
val userFriendlyName: String?,
|
||||
val src: SpaceSafeURI,
|
||||
val dest: Path,
|
||||
val hash: Hash,
|
||||
val side: Side,
|
||||
val optional: Boolean,
|
||||
val optionalDefaultValue: Boolean,
|
||||
val optionalDescription: String,
|
||||
@JvmInline
|
||||
value class PathIdentityToken(val path: String): IdentityToken
|
||||
|
||||
val ident: IdentityToken
|
||||
get() = PathIdentityToken(dest.path)
|
||||
|
||||
/**
|
||||
* If this is true, don't update a target when the file already exists.
|
||||
* A user-friendly name; defaults to the destination path of the file.
|
||||
*/
|
||||
val noOverwrite: Boolean
|
||||
) {
|
||||
fun Iterable<Target>.filterForSide(side: Side) = this.filter {
|
||||
it.side.hasSide(side)
|
||||
val name: String
|
||||
get() = dest.path
|
||||
val side: Side
|
||||
get() = Side.BOTH
|
||||
val overwriteMode: OverwriteMode
|
||||
get() = OverwriteMode.IF_SRC_CHANGED
|
||||
|
||||
interface Optional: Target {
|
||||
val optional: Boolean
|
||||
val optionalDefaultValue: Boolean
|
||||
}
|
||||
|
||||
interface OptionalDescribed: Optional {
|
||||
val optionalDescription: String
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package link.infra.packwiz.installer.target
|
||||
|
||||
import link.infra.packwiz.installer.metadata.hash.Hash
|
||||
|
||||
/**
|
||||
* A token used to determine if the source or destination file is changed, and ensure that the destination file is valid.
|
||||
*/
|
||||
interface ValidityToken {
|
||||
// TODO: functions to allow validating this from file metadata, from file, or during the download process
|
||||
|
||||
/**
|
||||
* Default implementation of ValidityToken based on a single hash.
|
||||
*/
|
||||
@JvmInline
|
||||
value class HashValidityToken(val hash: Hash): ValidityToken
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user