mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] Performance: Skin/Cloak local load
This commit is contained in:
parent
fecc14010d
commit
b0538abe63
3 changed files with 39 additions and 5 deletions
|
@ -7,12 +7,17 @@
|
|||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class RequestTextureProvider extends TextureProvider {
|
||||
// Instance
|
||||
private String skinURL;
|
||||
private String cloakURL;
|
||||
public String skinURL;
|
||||
public String cloakURL;
|
||||
|
||||
public String skinLocalPath;
|
||||
public String cloakLocalPath;
|
||||
|
||||
public RequestTextureProvider() {
|
||||
}
|
||||
|
@ -30,6 +35,14 @@ private static Texture getTexture(String url, boolean cloak) throws IOException
|
|||
}
|
||||
}
|
||||
|
||||
private static Texture getTexture(String url, Path local, boolean cloak) throws IOException {
|
||||
try {
|
||||
return new Texture(url, local, cloak);
|
||||
} catch (FileNotFoundException ignored) {
|
||||
return null; // Simply not found
|
||||
}
|
||||
}
|
||||
|
||||
private static String getTextureURL(String url, UUID uuid, String username, String client) {
|
||||
return CommonHelper.replace(url, "username", IOHelper.urlEncode(username),
|
||||
"uuid", IOHelper.urlEncode(uuid.toString()), "hash", IOHelper.urlEncode(Launcher.toHash(uuid)),
|
||||
|
@ -43,11 +56,21 @@ public void close() {
|
|||
|
||||
@Override
|
||||
public Texture getCloakTexture(UUID uuid, String username, String client) throws IOException {
|
||||
return getTexture(getTextureURL(cloakURL, uuid, username, client), true);
|
||||
String textureUrl = getTextureURL(cloakURL, uuid, username, client);
|
||||
if (cloakLocalPath == null) {
|
||||
return getTexture(textureUrl, true);
|
||||
} else {
|
||||
return getTexture(textureUrl, Paths.get(cloakLocalPath), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Texture getSkinTexture(UUID uuid, String username, String client) throws IOException {
|
||||
return getTexture(getTextureURL(skinURL, uuid, username, client), false);
|
||||
String textureUrl = getTextureURL(skinURL, uuid, username, client);
|
||||
if (skinLocalPath == null) {
|
||||
return getTexture(textureUrl, false);
|
||||
} else {
|
||||
return getTexture(textureUrl, Paths.get(skinLocalPath), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ public final class PlayerProfile extends StreamObject {
|
|||
public final Texture skin, cloak;
|
||||
|
||||
|
||||
@Deprecated
|
||||
public PlayerProfile(HInput input) throws IOException {
|
||||
uuid = input.readUUID();
|
||||
username = VerifyHelper.verifyUsername(input.readString(64));
|
||||
|
@ -41,6 +42,7 @@ public static UUID offlineUUID(String username) {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void write(HOutput output) throws IOException {
|
||||
output.writeUUID(uuid);
|
||||
output.writeString(username, 64);
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class Texture extends StreamObject {
|
||||
|
@ -22,12 +23,12 @@ public final class Texture extends StreamObject {
|
|||
public final byte[] digest;
|
||||
|
||||
|
||||
@Deprecated
|
||||
public Texture(HInput input) throws IOException {
|
||||
url = IOHelper.verifyURL(input.readASCII(2048));
|
||||
digest = input.readByteArray(-DIGEST_ALGO.bytes);
|
||||
}
|
||||
|
||||
|
||||
public Texture(String url, boolean cloak) throws IOException {
|
||||
this.url = IOHelper.verifyURL(url);
|
||||
|
||||
|
@ -44,6 +45,14 @@ public Texture(String url, boolean cloak) throws IOException {
|
|||
digest = SecurityHelper.digest(DIGEST_ALGO, new URL(url));
|
||||
}
|
||||
|
||||
public Texture(String url, Path local, boolean cloak) throws IOException {
|
||||
this.url = IOHelper.verifyURL(url);
|
||||
try (InputStream input = IOHelper.newInput(local)) {
|
||||
IOHelper.readTexture(input, cloak); // Verify texture
|
||||
}
|
||||
this.digest = Objects.requireNonNull(SecurityHelper.digest(DIGEST_ALGO, local), "digest");
|
||||
}
|
||||
|
||||
|
||||
public Texture(String url, byte[] digest) {
|
||||
this.url = IOHelper.verifyURL(url);
|
||||
|
|
Loading…
Reference in a new issue