Skip to content

Commit

Permalink
Change the name of Kitten Thoughts to Catculator
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixaurora committed Sep 24, 2024
1 parent 36ffc46 commit 4d86795
Show file tree
Hide file tree
Showing 34 changed files with 155 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public enum ModIcon {
KIT_TUNES(),
KIT_TUNES_API(),
KITTEN_HEART(),
KITTEN_THOUGHTS(),
CATCULATOR(),
KITTEN_SQUARE(),
KITTEN_SOUNDS();

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod {
dependencies {
include(project(":projects:kit-tunes-api"))
include(project(":projects:kitten-heart"))
include(project(":projects:kitten-thoughts"))
include(project(":projects:catculator"))

include(project(":projects:kitten-sounds:r1.17.0"))
include(project(":projects:kitten-sounds:r1.20.3"))
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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"

Expand Down
File renamed without changes.
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
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();
}
}
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);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.pixaurora.kitten_thoughts.impl.error;
package net.pixaurora.catculator.impl.error;

public class LibraryLoadError extends Error {
public LibraryLoadError(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.pixaurora.kitten_thoughts.impl.http.server;
package net.pixaurora.catculator.impl.http.server;

import java.io.Closeable;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.pixaurora.kitten_thoughts.impl.http.server;
package net.pixaurora.catculator.impl.http.server;

public class ServerImpl implements Server {
private final long pointer;
Expand Down
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();
}
}
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
package net.pixaurora.kitten_thoughts.impl.util;

import net.pixaurora.kitten_thoughts.impl.Constants;
import net.pixaurora.kitten_thoughts.impl.error.LibraryLoadError;
package net.pixaurora.catculator.impl.util;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -11,11 +8,15 @@
import java.nio.file.Paths;
import java.util.Properties;

import net.pixaurora.catculator.impl.Constants;
import net.pixaurora.catculator.impl.error.LibraryLoadError;

public class NativeUtil {
private static boolean isLoaded = false;

private static final String METADATA = "/kitten_thoughts.natives.properties";
private static final String BASE_URL = "https://files.lostluma.net/kitten-thoughts-jni/" + Constants.NATIVES_VERSION + "/";
private static final String BASE_URL = "https://files.lostluma.net/kitten-thoughts-jni/" + Constants.NATIVES_VERSION
+ "/";

public static void load() throws LibraryLoadError {
if (isLoaded) {
Expand Down Expand Up @@ -55,11 +56,11 @@ private static String getDevLibraryName() {
String name = System.getProperty("os.name").toLowerCase();

if (name.contains("win")) {
return "kitten_thoughts.dll";
return "catculator.dll";
} else if (name.contains("mac")) {
return "libkitten_thoughts.dylib";
return "libcatculator.dylib";
} else {
return "libkitten_thoughts.so";
return "libcatculator.so";
}
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@ fn drop<'local>(object: &JObject<'local>, env: &mut JNIEnv<'local>) -> Result<()
}

#[no_mangle]
pub extern "system" fn Java_net_pixaurora_kitten_1thoughts_impl_http_server_ServerImpl_create<
'local,
>(
pub extern "system" fn Java_net_pixaurora_catculator_impl_http_server_ServerImpl_create<'local>(
mut _env: JNIEnv<'local>,
_class: JClass<'local>,
) -> jlong {
create()
}

#[no_mangle]
pub extern "system" fn Java_net_pixaurora_kitten_1thoughts_impl_http_server_ServerImpl_runServer0<
pub extern "system" fn Java_net_pixaurora_catculator_impl_http_server_ServerImpl_runServer0<
'local,
>(
mut env: JNIEnv<'local>,
Expand All @@ -63,9 +61,7 @@ pub extern "system" fn Java_net_pixaurora_kitten_1thoughts_impl_http_server_Serv
}

#[no_mangle]
pub extern "system" fn Java_net_pixaurora_kitten_1thoughts_impl_http_server_ServerImpl_drop<
'local,
>(
pub extern "system" fn Java_net_pixaurora_catculator_impl_http_server_ServerImpl_drop<'local>(
mut env: JNIEnv<'local>,
object: JObject<'local>,
) -> () {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions projects/kitten-heart/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ mod {
required("kit_tunes_api")
required("kitten_square")
required("kitten_sounds")
required("kitten_thoughts")
required("catculator")
}
}

dependencies {
implementation(project(":projects:kit-tunes-api"))
implementation(project(":projects:kitten-thoughts"))
implementation(project(":projects:catculator"))

implementation(libs.annotations)
implementation(libs.quilt.loader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import net.pixaurora.kitten_heart.impl.resource.ResourcePathImpl;
import net.pixaurora.kitten_heart.impl.service.MinecraftUICompat;
import net.pixaurora.kitten_heart.impl.service.ServiceLoading;
import net.pixaurora.kitten_thoughts.impl.KittenThoughts;
import net.pixaurora.catculator.impl.Catculator;

public class KitTunes {
public static final Logger LOGGER = LoggerFactory.getLogger(Constants.MOD_ID);
Expand All @@ -43,7 +43,7 @@ public static void init() {
MusicMetadata.init(MusicMetadataLoader.albumFiles(), MusicMetadataLoader.artistFiles(),
MusicMetadataLoader.trackFiles());

KittenThoughts.init();
Catculator.init();
}

public static void tick() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package net.pixaurora.kitten_heart.impl.network;

import net.pixaurora.kitten_thoughts.impl.util.CryptoUtil;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import net.pixaurora.catculator.impl.util.CryptoUtil;

public class Encryption {
public static String signMd5(String input) {
return CryptoUtil.toHex(getMd5Digest(input));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

import net.pixaurora.kitten_thoughts.impl.http.server.Server;
import net.pixaurora.catculator.impl.http.server.Server;

public class ScrobblerSetup<T extends Scrobbler> implements Closeable {
private final Server server;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import net.pixaurora.catculator.impl.http.server.Server;
import net.pixaurora.kitten_heart.impl.config.dispatch.DispatchType;
import net.pixaurora.kitten_heart.impl.error.KitTunesException;
import net.pixaurora.kitten_thoughts.impl.http.server.Server;

public class ScrobblerType<T extends Scrobbler> implements DispatchType<Scrobbler> {
private final String name;
Expand Down

This file was deleted.

Loading

0 comments on commit 4d86795

Please sign in to comment.