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
|
package link.infra.packwiz.installer.target
|
||||||
|
|
||||||
import link.infra.packwiz.installer.metadata.SpaceSafeURI
|
import link.infra.packwiz.installer.target.path.PackwizPath
|
||||||
import link.infra.packwiz.installer.metadata.hash.Hash
|
|
||||||
import java.nio.file.Path
|
// 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.
|
* Token interface for types used to compare Target identity. Implementations should use equals to indicate that
|
||||||
* Often equal to the name of the metadata file for this target, and can be displayed to the user in progress UI.
|
* 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?,
|
@JvmInline
|
||||||
val src: SpaceSafeURI,
|
value class PathIdentityToken(val path: String): IdentityToken
|
||||||
val dest: Path,
|
|
||||||
val hash: Hash,
|
val ident: IdentityToken
|
||||||
val side: Side,
|
get() = PathIdentityToken(dest.path)
|
||||||
val optional: Boolean,
|
|
||||||
val optionalDefaultValue: Boolean,
|
|
||||||
val optionalDescription: String,
|
|
||||||
/**
|
/**
|
||||||
* 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
|
val name: String
|
||||||
) {
|
get() = dest.path
|
||||||
fun Iterable<Target>.filterForSide(side: Side) = this.filter {
|
val side: Side
|
||||||
it.side.hasSide(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