forked from glowredman/TX-Loader
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement asset adding via game jars
- Loading branch information
1 parent
bd323d6
commit 1a440d0
Showing
7 changed files
with
307 additions
and
113 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package glowredman.txloader; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
class Asset { | ||
|
||
String resourceLocation; | ||
String resourceLocationOverride; | ||
boolean forceLoad; | ||
String version; | ||
Source source; | ||
transient boolean addedByMod; // ignored by GSON | ||
|
||
Asset(String resourceLocation, String version, Source source) { | ||
this.resourceLocation = resourceLocation; | ||
this.version = version; | ||
this.source = source; | ||
} | ||
|
||
String getResourceLocation() { | ||
return this.resourceLocationOverride == null ? this.resourceLocation : this.resourceLocationOverride; | ||
} | ||
|
||
File getFile() { | ||
File path = this.forceLoad ? TXLoaderCore.forceResourcesDir : TXLoaderCore.resourcesDir; | ||
return new File(path, this.getResourceLocation()); | ||
} | ||
|
||
String getVersion() { | ||
return this.version == null ? RemoteHandler.latestRelease : this.version; | ||
} | ||
|
||
Source getSource() { | ||
return this.source == null ? Source.ASSET : this.source; | ||
} | ||
|
||
enum Source { | ||
|
||
ASSET, | ||
CLIENT, | ||
SERVER; | ||
|
||
static final Iterable<String> NAMES = Arrays.stream(values()).map(Source::name).collect(Collectors.toList()); | ||
|
||
static Source get(String name) { | ||
try { | ||
return valueOf(name); | ||
} catch (Exception e) { | ||
TXLoaderCore.LOGGER.warn("{} is not a valid source identifier!", name); | ||
return ASSET; | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package glowredman.txloader; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
class JarHandler { | ||
|
||
static final Map<String, Path> CACHED_CLIENT_JARS = new HashMap<>(); | ||
static final Map<String, Path> CACHED_SERVER_JARS = new HashMap<>(); | ||
|
||
static Path txloaderCache; | ||
|
||
static void indexJars() { | ||
String userHome = System.getProperty("user.home"); | ||
txloaderCache = Paths.get(userHome, "txloader"); | ||
|
||
List<Pair<Path, String>> clientLocations = new ArrayList<>(); | ||
clientLocations.add(Pair.of(txloaderCache, "client.jar")); | ||
clientLocations.add(Pair.of(Paths.get(userHome, "AppData", "Roaming", ".minecraft", "versions"), "%s.jar")); | ||
clientLocations.add( | ||
Pair.of( | ||
Paths.get(userHome, ".gradle", "caches", "forge_gradle", "minecraft_repo", "versions"), | ||
"client.jar")); | ||
clientLocations.add( | ||
Pair.of( | ||
Paths.get(userHome, ".gradle", "caches", "minecraft", "net", "minecraft", "minecraft"), | ||
"minecraft-%s.jar")); | ||
clientLocations.add( | ||
Pair.of(Paths.get(userHome, ".gradle", "caches", "retro_futura_gradle", "mc-vanilla"), "client.jar")); | ||
|
||
List<Pair<Path, String>> serverLocations = new ArrayList<>(); | ||
clientLocations.add(Pair.of(txloaderCache, "server.jar")); | ||
serverLocations.add( | ||
Pair.of( | ||
Paths.get(userHome, ".gradle", "caches", "forge_gradle", "minecraft_repo", "versions"), | ||
"server.jar")); | ||
serverLocations.add( | ||
Pair.of( | ||
Paths.get(userHome, ".gradle", "caches", "minecraft", "net", "minecraft", "minecraft_server"), | ||
"minecraft_server-%s.jar")); | ||
serverLocations.add( | ||
Pair.of(Paths.get(userHome, ".gradle", "caches", "retro_futura_gradle", "mc-vanilla"), "server.jar")); | ||
|
||
for (String version : RemoteHandler.VERSIONS.keySet()) { | ||
for (Pair<Path, String> location : clientLocations) { | ||
Path jarPath = location.getLeft().resolve(version).resolve(String.format(location.getRight(), version)); | ||
if (Files.exists(jarPath)) { | ||
CACHED_CLIENT_JARS.put(version, jarPath); | ||
TXLoaderCore.LOGGER.debug("Found CLIENT jar for version {} at {}", version, jarPath); | ||
break; | ||
} | ||
} | ||
for (Pair<Path, String> location : serverLocations) { | ||
Path jarPath = location.getLeft().resolve(version).resolve(String.format(location.getRight(), version)); | ||
if (Files.exists(jarPath)) { | ||
CACHED_SERVER_JARS.put(version, jarPath); | ||
TXLoaderCore.LOGGER.debug("Found SERVER jar for version {} at {}", version, jarPath); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.