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.
Change the name of Kitten Thoughts to Catculator
- Loading branch information
Showing
34 changed files
with
155 additions
and
157 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
22 changes: 11 additions & 11 deletions
22
projects/kitten-thoughts/Cargo.lock → projects/catculator/Cargo.lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
projects/kitten-thoughts/Cargo.toml → projects/catculator/Cargo.toml
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
name = "kitten_thoughts" | ||
name = "catculator" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
projects/kitten-thoughts/gradle.properties → projects/catculator/gradle.properties
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Mod properties | ||
mod_id = kitten_thoughts | ||
mod_id = catculator | ||
|
||
description = A Rust library to add some features, such as a HTTP server for scrobbler setup and music file parsing |
9 changes: 9 additions & 0 deletions
9
projects/catculator/src/main/java/net/pixaurora/catculator/impl/Catculator.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.catculator.impl; | ||
|
||
import net.pixaurora.catculator.impl.util.NativeUtil; | ||
|
||
public class Catculator { | ||
public static void init() { | ||
NativeUtil.load(); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...urora/kitten_thoughts/impl/Constants.java → .../pixaurora/catculator/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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package net.pixaurora.kitten_thoughts.impl; | ||
package net.pixaurora.catculator.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 MOD_ID = "catculator"; | ||
|
||
public static final String NATIVES_VERSION = "0.1.0"; | ||
public static final String NATIVES_DIRECTORY_PROPERTY = "kitten_thoughts.natives_path"; | ||
public static final String NATIVES_DIRECTORY_PROPERTY = "catculator.natives_path"; | ||
|
||
public static final Path NATIVES_CACHE_DIR = QuiltLoader.getCacheDir().resolve(MOD_ID); | ||
} |
2 changes: 1 addition & 1 deletion
2
...thoughts/impl/error/LibraryLoadError.java → ...tculator/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
2 changes: 1 addition & 1 deletion
2
...ten_thoughts/impl/http/server/Server.java → ...a/catculator/impl/http/server/Server.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
2 changes: 1 addition & 1 deletion
2
...thoughts/impl/http/server/ServerImpl.java → ...tculator/impl/http/server/ServerImpl.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
39 changes: 39 additions & 0 deletions
39
projects/catculator/src/main/java/net/pixaurora/catculator/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,39 @@ | ||
package net.pixaurora.catculator.impl.util; | ||
|
||
import java.io.IOException; | ||
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(); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
projects/catculator/src/main/java/net/pixaurora/catculator/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,65 @@ | ||
package net.pixaurora.catculator.impl.util; | ||
|
||
import org.quiltmc.loader.api.ModMetadata; | ||
import org.quiltmc.loader.api.QuiltLoader; | ||
|
||
import net.pixaurora.catculator.impl.Constants; | ||
|
||
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); | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
4 changes: 2 additions & 2 deletions
4
projects/kitten-heart/src/main/java/net/pixaurora/kitten_heart/impl/network/Encryption.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
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
9 changes: 0 additions & 9 deletions
9
...ects/kitten-thoughts/src/main/java/net/pixaurora/kitten_thoughts/impl/KittenThoughts.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.