mirror of
https://github.com/packwiz/packwiz-installer.git
synced 2025-10-17 08:24:32 +02:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
92b44352b3 | ||
|
1d5a787b02 | ||
|
b5983800e8 | ||
|
4b3c279e71 | ||
|
b413371306 | ||
|
1d2ec61232 | ||
|
a0da889a02 | ||
|
432bb4e25f |
6
.idea/compiler.xml
generated
Normal file
6
.idea/compiler.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<bytecodeTargetLevel target="1.8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
2
.idea/packwiz-installer.iml
generated
Normal file
2
.idea/packwiz-installer.iml
generated
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4" />
|
@@ -1,2 +1,2 @@
|
|||||||
# packwiz-installer
|
# packwiz-installer
|
||||||
An installer for launching packwiz modpacks with MultiMC.
|
An installer for launching packwiz modpacks with MultiMC. You'll need [the bootstrapper](https://github.com/comp500/packwiz-installer-bootstrap/releases) to actually use this.
|
||||||
|
@@ -74,13 +74,13 @@ public class Murmur2Lib {
|
|||||||
int left = length - len_m;
|
int left = length - len_m;
|
||||||
if (left != 0) {
|
if (left != 0) {
|
||||||
if (left >= 3) {
|
if (left >= 3) {
|
||||||
h ^= (int) data[length - 3] << 16;
|
h ^= (int) data[length - (left - 2)] << 16;
|
||||||
}
|
}
|
||||||
if (left >= 2) {
|
if (left >= 2) {
|
||||||
h ^= (int) data[length - 2] << 8;
|
h ^= (int) data[length - (left - 1)] << 8;
|
||||||
}
|
}
|
||||||
if (left >= 1) {
|
if (left >= 1) {
|
||||||
h ^= (int) data[length - 1];
|
h ^= data[length - left];
|
||||||
}
|
}
|
||||||
|
|
||||||
h *= M_32;
|
h *= M_32;
|
||||||
@@ -152,7 +152,7 @@ public class Murmur2Lib {
|
|||||||
case 2:
|
case 2:
|
||||||
h ^= (long) (data[tailStart + 1] & 0xff) << 8;
|
h ^= (long) (data[tailStart + 1] & 0xff) << 8;
|
||||||
case 1:
|
case 1:
|
||||||
h ^= (long) (data[tailStart] & 0xff);
|
h ^= data[tailStart] & 0xff;
|
||||||
h *= M_64;
|
h *= M_64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
@file:JvmName("Main")
|
||||||
|
|
||||||
package link.infra.packwiz.installer
|
package link.infra.packwiz.installer
|
||||||
|
|
||||||
import link.infra.packwiz.installer.metadata.SpaceSafeURI
|
import link.infra.packwiz.installer.metadata.SpaceSafeURI
|
||||||
@@ -84,6 +86,7 @@ class Main(args: Array<String>) {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
// Called by packwiz-installer-bootstrap to set up the help command
|
// Called by packwiz-installer-bootstrap to set up the help command
|
||||||
|
@JvmStatic
|
||||||
fun addNonBootstrapOptions(options: Options) {
|
fun addNonBootstrapOptions(options: Options) {
|
||||||
options.addOption("s", "side", true, "Side to install mods from (client/server, defaults to client)")
|
options.addOption("s", "side", true, "Side to install mods from (client/server, defaults to client)")
|
||||||
options.addOption(null, "title", true, "Title of the installer window")
|
options.addOption(null, "title", true, "Title of the installer window")
|
||||||
@@ -92,6 +95,7 @@ class Main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: link these somehow so they're only defined once?
|
// TODO: link these somehow so they're only defined once?
|
||||||
|
@JvmStatic
|
||||||
private fun addBootstrapOptions(options: Options) {
|
private fun addBootstrapOptions(options: Options) {
|
||||||
options.addOption(null, "bootstrap-update-url", true, "Github API URL for checking for updates")
|
options.addOption(null, "bootstrap-update-url", true, "Github API URL for checking for updates")
|
||||||
options.addOption(null, "bootstrap-update-token", true, "Github API Access Token, for private repositories")
|
options.addOption(null, "bootstrap-update-token", true, "Github API Access Token, for private repositories")
|
||||||
|
@@ -126,7 +126,6 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
|
|||||||
|
|
||||||
ui.submitProgress(InstallProgress("Loading pack file..."))
|
ui.submitProgress(InstallProgress("Loading pack file..."))
|
||||||
val packFileSource = try {
|
val packFileSource = try {
|
||||||
Objects.requireNonNull(opts.downloadURI)
|
|
||||||
val src = getFileSource(opts.downloadURI!!)
|
val src = getFileSource(opts.downloadURI!!)
|
||||||
getHasher("sha256").getHashingSource(src)
|
getHasher("sha256").getHashingSource(src)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -191,12 +190,16 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
|
|||||||
handleCancellation()
|
handleCancellation()
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// This is badly written, I'll probably heavily refactor it at some point
|
val index = pf.index!!
|
||||||
// The port to Kotlin made this REALLY messy!!!!
|
getNewLoc(opts.downloadURI, index.file)?.let { newLoc ->
|
||||||
getNewLoc(opts.downloadURI, Objects.requireNonNull(pf.index)!!.file)?.let {
|
index.hashFormat?.let { hashFormat ->
|
||||||
pf.index!!.hashFormat?.let { it1 ->
|
processIndex(
|
||||||
processIndex(it,
|
newLoc,
|
||||||
getHash(Objects.requireNonNull(pf.index!!.hashFormat)!!, Objects.requireNonNull(pf.index!!.hash)!!), it1, manifest, invalidatedUris)
|
getHash(index.hashFormat!!, index.hash!!),
|
||||||
|
hashFormat,
|
||||||
|
manifest,
|
||||||
|
invalidatedUris
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e1: Exception) {
|
} catch (e1: Exception) {
|
||||||
|
@@ -10,7 +10,7 @@ class Murmur2Hasher : IHasher {
|
|||||||
val tempBuffer = Buffer()
|
val tempBuffer = Buffer()
|
||||||
|
|
||||||
override val hash: Hash by lazy(LazyThreadSafetyMode.NONE) {
|
override val hash: Hash by lazy(LazyThreadSafetyMode.NONE) {
|
||||||
val data = computeNormalizedArray(internalBuffer.readByteArray())
|
val data = internalBuffer.readByteArray()
|
||||||
Murmur2Hash(Murmur2Lib.hash32(data, data.size, 1))
|
Murmur2Hash(Murmur2Lib.hash32(data, data.size, 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,27 +19,42 @@ class Murmur2Hasher : IHasher {
|
|||||||
val out = delegate.read(tempBuffer, byteCount)
|
val out = delegate.read(tempBuffer, byteCount)
|
||||||
if (out > -1) {
|
if (out > -1) {
|
||||||
sink.write(tempBuffer.clone(), out)
|
sink.write(tempBuffer.clone(), out)
|
||||||
internalBuffer.write(tempBuffer, out)
|
computeNormalizedBufferFaster(tempBuffer, internalBuffer)
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// Credit to https://github.com/modmuss50/CAV2/blob/master/murmur.go
|
// Credit to https://github.com/modmuss50/CAV2/blob/master/murmur.go
|
||||||
private fun computeNormalizedArray(input: ByteArray): ByteArray {
|
// private fun computeNormalizedArray(input: ByteArray): ByteArray {
|
||||||
val output = ByteArray(input.size)
|
// val output = ByteArray(input.size)
|
||||||
|
// var index = 0
|
||||||
|
// for (b in input) {
|
||||||
|
// when (b) {
|
||||||
|
// 9.toByte(), 10.toByte(), 13.toByte(), 32.toByte() -> {}
|
||||||
|
// else -> {
|
||||||
|
// output[index] = b
|
||||||
|
// index++
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// val outputTrimmed = ByteArray(index)
|
||||||
|
// System.arraycopy(output, 0, outputTrimmed, 0, index)
|
||||||
|
// return outputTrimmed
|
||||||
|
// }
|
||||||
|
|
||||||
|
private fun computeNormalizedBufferFaster(input: Buffer, output: Buffer) {
|
||||||
var index = 0
|
var index = 0
|
||||||
for (b in input) {
|
val arr = input.readByteArray()
|
||||||
when (b.toInt()) {
|
for (b in arr) {
|
||||||
9, 10, 13, 32 -> {}
|
when (b) {
|
||||||
|
9.toByte(), 10.toByte(), 13.toByte(), 32.toByte() -> {}
|
||||||
else -> {
|
else -> {
|
||||||
output[index] = b
|
arr[index] = b
|
||||||
index++
|
index++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val outputTrimmed = ByteArray(index)
|
output.write(arr, 0, index)
|
||||||
System.arraycopy(output, 0, outputTrimmed, 0, index)
|
|
||||||
return outputTrimmed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package link.infra.packwiz.installer.request
|
package link.infra.packwiz.installer.request
|
||||||
|
|
||||||
import link.infra.packwiz.installer.metadata.SpaceSafeURI
|
import link.infra.packwiz.installer.metadata.SpaceSafeURI
|
||||||
|
import link.infra.packwiz.installer.request.handlers.RequestHandlerFile
|
||||||
import link.infra.packwiz.installer.request.handlers.RequestHandlerGithub
|
import link.infra.packwiz.installer.request.handlers.RequestHandlerGithub
|
||||||
import link.infra.packwiz.installer.request.handlers.RequestHandlerHTTP
|
import link.infra.packwiz.installer.request.handlers.RequestHandlerHTTP
|
||||||
import okio.Source
|
import okio.Source
|
||||||
@@ -9,7 +10,8 @@ object HandlerManager {
|
|||||||
|
|
||||||
private val handlers: List<IRequestHandler> = listOf(
|
private val handlers: List<IRequestHandler> = listOf(
|
||||||
RequestHandlerGithub(),
|
RequestHandlerGithub(),
|
||||||
RequestHandlerHTTP()
|
RequestHandlerHTTP(),
|
||||||
|
RequestHandlerFile()
|
||||||
)
|
)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@@ -0,0 +1,18 @@
|
|||||||
|
package link.infra.packwiz.installer.request.handlers
|
||||||
|
|
||||||
|
import link.infra.packwiz.installer.metadata.SpaceSafeURI
|
||||||
|
import link.infra.packwiz.installer.request.IRequestHandler
|
||||||
|
import okio.Source
|
||||||
|
import okio.source
|
||||||
|
import java.nio.file.Paths
|
||||||
|
|
||||||
|
open class RequestHandlerFile : IRequestHandler {
|
||||||
|
override fun matchesHandler(loc: SpaceSafeURI): Boolean {
|
||||||
|
return "file" == loc.scheme
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getFileSource(loc: SpaceSafeURI): Source? {
|
||||||
|
val path = Paths.get(loc.toURL().toURI())
|
||||||
|
return path.source()
|
||||||
|
}
|
||||||
|
}
|
@@ -65,7 +65,7 @@ class RequestHandlerGithub : RequestHandlerZip(true) {
|
|||||||
if (!("http" == scheme || "https" == scheme)) {
|
if (!("http" == scheme || "https" == scheme)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return "github.com" == loc.host
|
// TODO: more match testing?
|
||||||
// TODO: sanity checks, support for more github urls
|
return "github.com" == loc.host && branchMatcherPattern.matcher(loc.path).matches()
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user