generated from QuiltMC/quilt-template-mod
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from LostLuma/feature/native-development-builds
Improve native dev workflow, make natives work in production
- Loading branch information
Showing
16 changed files
with
313 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
...kitten-thoughts/src/main/headers/net_pixaurora_kitten_thoughts_scrobbler_ScrobblerSetup.h
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
projects/kitten-thoughts/src/main/java/net/pixaurora/kitten_thoughts/KittenThoughts.java
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
projects/kitten-thoughts/src/main/java/net/pixaurora/kitten_thoughts/impl/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package net.pixaurora.kitten_thoughts.impl; | ||
|
||
import org.quiltmc.loader.api.QuiltLoader; | ||
|
||
import java.nio.file.Path; | ||
|
||
public class Constants { | ||
public static final String MOD_ID = "kitten_thoughts"; | ||
|
||
public static final String NATIVES_VERSION = "0.1.0"; | ||
public static final String NATIVES_DIRECTORY_PROPERTY = "kitten_thoughts.natives_path"; | ||
|
||
public static final Path NATIVES_CACHE_DIR = QuiltLoader.getCacheDir().resolve(MOD_ID); | ||
} |
9 changes: 9 additions & 0 deletions
9
...ects/kitten-thoughts/src/main/java/net/pixaurora/kitten_thoughts/impl/KittenThoughts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.pixaurora.kitten_thoughts.impl; | ||
|
||
import net.pixaurora.kitten_thoughts.impl.util.NativeUtil; | ||
|
||
public class KittenThoughts { | ||
public static void init() { | ||
NativeUtil.load(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ten-thoughts/src/main/java/net/pixaurora/kitten_thoughts/impl/error/LibraryLoadError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package net.pixaurora.kitten_thoughts.impl.error; | ||
|
||
public class LibraryLoadError extends Error { | ||
public LibraryLoadError(String message) { | ||
super(message); | ||
} | ||
|
||
public LibraryLoadError(Throwable exception) { | ||
super(exception); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...en_thoughts/scrobbler/ScrobblerSetup.java → ...oughts/impl/scrobbler/ScrobblerSetup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...cts/kitten-thoughts/src/main/java/net/pixaurora/kitten_thoughts/impl/util/CryptoUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package net.pixaurora.kitten_thoughts.impl.util; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
public class CryptoUtil { | ||
public static String sha512(Path path) throws IOException { | ||
return sha512(Files.readAllBytes(path)); | ||
} | ||
|
||
public static String sha512(byte[] data) { | ||
MessageDigest digest; | ||
|
||
try { | ||
digest = MessageDigest.getInstance("SHA-512"); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new RuntimeException("No SHA512 algorithm found.", e); | ||
} | ||
|
||
digest.update(data); | ||
return toHex(digest.digest()); | ||
} | ||
|
||
public static String toHex(byte[] data) { | ||
StringBuilder builder = new StringBuilder(data.length * 2); | ||
|
||
for (byte value : data) { | ||
int number = Byte.toUnsignedInt(value); | ||
|
||
builder.append(Integer.toHexString(number >> 0b100)); // Former four bits | ||
builder.append(Integer.toHexString(number & 0b1111)); // Latter four bits | ||
} | ||
|
||
return builder.toString(); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
projects/kitten-thoughts/src/main/java/net/pixaurora/kitten_thoughts/impl/util/HttpUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package net.pixaurora.kitten_thoughts.impl.util; | ||
|
||
import net.pixaurora.kitten_thoughts.impl.Constants; | ||
import org.quiltmc.loader.api.ModMetadata; | ||
import org.quiltmc.loader.api.QuiltLoader; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.time.Duration; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
public class HttpUtil { | ||
private static final Duration TIMEOUT = Duration.of(2, ChronoUnit.MINUTES); | ||
|
||
public static void download(URL url, Path into) throws IOException { | ||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
|
||
connection.setReadTimeout((int) TIMEOUT.toMillis()); | ||
connection.setRequestProperty("User-Agent", buildUserAgent()); | ||
|
||
connection.connect(); | ||
int status = connection.getResponseCode(); | ||
|
||
if (status != 200) { | ||
throw new IOException("Library download error: " + status); | ||
} | ||
|
||
int size; | ||
String length = connection.getHeaderField("Content-Length"); | ||
|
||
try { | ||
size = Integer.parseInt(length); | ||
} catch (NumberFormatException e) { | ||
throw new IOException("Received invalid Content-Length header!"); | ||
} | ||
|
||
try (InputStream stream = connection.getInputStream()) { | ||
int input; | ||
int index = 0; | ||
|
||
byte[] data = new byte[size]; | ||
|
||
while ((input = stream.read()) != -1) { | ||
data[index] = (byte) input; | ||
index ++; | ||
} | ||
|
||
Files.write(into, data); | ||
} | ||
} | ||
|
||
private static String buildUserAgent() { | ||
ModMetadata metadata = QuiltLoader.getModContainer(Constants.MOD_ID).get().metadata(); | ||
|
||
String version = metadata.version().raw(); | ||
String homepage = metadata.getContactInfo("homepage"); | ||
|
||
return String.format("Kit Tunes/%s (+%s)", version, homepage); | ||
} | ||
} |
Oops, something went wrong.