Commit f25498417fa3102d6ca7a8f45fa2d03c4423ab44
1 parent
792cf5b9
removing jarfile.ref functionality since it's no longer needed
Showing
1 changed file
with
37 additions
and
101 deletions
java/common/com/mumfrey/liteloader/launch/LiteLoaderTweaker.java
| 1 | 1 | package com.mumfrey.liteloader.launch; |
| 2 | 2 | |
| 3 | 3 | import java.io.File; |
| 4 | -import java.io.IOException; | |
| 5 | -import java.io.InputStream; | |
| 6 | -import java.io.InputStreamReader; | |
| 7 | 4 | import java.lang.reflect.Constructor; |
| 8 | 5 | import java.lang.reflect.Method; |
| 9 | 6 | import java.net.URL; |
| ... | ... | @@ -26,9 +23,6 @@ import net.minecraft.launchwrapper.Launch; |
| 26 | 23 | import net.minecraft.launchwrapper.LaunchClassLoader; |
| 27 | 24 | |
| 28 | 25 | import com.google.common.base.Throwables; |
| 29 | -import com.google.gson.Gson; | |
| 30 | -import com.google.gson.JsonIOException; | |
| 31 | -import com.google.gson.JsonSyntaxException; | |
| 32 | 26 | import com.mumfrey.liteloader.util.SortableValue; |
| 33 | 27 | import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
| 34 | 28 | |
| ... | ... | @@ -52,7 +46,7 @@ public class LiteLoaderTweaker implements ITweaker |
| 52 | 46 | */ |
| 53 | 47 | enum StartupState |
| 54 | 48 | { |
| 55 | - CONSTRUCT, | |
| 49 | + PREPARE, | |
| 56 | 50 | PREINIT, |
| 57 | 51 | BEGINGAME, |
| 58 | 52 | INIT, |
| ... | ... | @@ -62,7 +56,7 @@ public class LiteLoaderTweaker implements ITweaker |
| 62 | 56 | /** |
| 63 | 57 | * Current state |
| 64 | 58 | */ |
| 65 | - private static StartupState currentState = StartupState.CONSTRUCT.gotoState(); | |
| 59 | + private static StartupState currentState = StartupState.PREPARE.gotoState(); | |
| 66 | 60 | |
| 67 | 61 | /** |
| 68 | 62 | * Whether this state is active |
| ... | ... | @@ -102,7 +96,7 @@ public class LiteLoaderTweaker implements ITweaker |
| 102 | 96 | if (otherState.canGotoState(this)) |
| 103 | 97 | otherState.leaveState(); |
| 104 | 98 | else |
| 105 | - throw new IllegalStateException(String.format("Cannot go to state \"%s\" as %s %s", this.name(), otherState, otherState.getNextState() == this ? "" : "and expects \"" + otherState.getNextState().name() + "\" instead"), LiteLoaderLogger.getLastThrowable()); | |
| 99 | + throw new IllegalStateException(String.format("Cannot go to state <%s> as %s %s", this.name(), otherState, otherState.getNextState() == this ? "" : "and expects \"" + otherState.getNextState().name() + "\" instead"), LiteLoaderLogger.getLastThrowable()); | |
| 106 | 100 | } |
| 107 | 101 | } |
| 108 | 102 | |
| ... | ... | @@ -121,7 +115,7 @@ public class LiteLoaderTweaker implements ITweaker |
| 121 | 115 | @Override |
| 122 | 116 | public String toString() |
| 123 | 117 | { |
| 124 | - return String.format("\"%s\" is %s %s", this.name(), this.inState ? "[ACTIVE]" : "[INACTIVE]", this.completed ? "and [COMPLETED]" : "but [INCOMPLETE]"); | |
| 118 | + return String.format("<%s> is %s %s", this.name(), this.inState ? "[ACTIVE]" : "[INACTIVE]", this.completed ? "and [COMPLETED]" : "but [INCOMPLETE]"); | |
| 125 | 119 | } |
| 126 | 120 | |
| 127 | 121 | /** |
| ... | ... | @@ -181,7 +175,6 @@ public class LiteLoaderTweaker implements ITweaker |
| 181 | 175 | private List<String> singularLaunchArgs = new ArrayList<String>(); |
| 182 | 176 | private Map<String, String> launchArgs; |
| 183 | 177 | |
| 184 | - private ArgumentAcceptingOptionSpec<String> jarOption; | |
| 185 | 178 | private ArgumentAcceptingOptionSpec<String> modsOption; |
| 186 | 179 | private ArgumentAcceptingOptionSpec<String> apisOption; |
| 187 | 180 | private OptionSet parsedOptions; |
| ... | ... | @@ -216,30 +209,11 @@ public class LiteLoaderTweaker implements ITweaker |
| 216 | 209 | LiteLoaderTweaker.instance = this; |
| 217 | 210 | |
| 218 | 211 | this.initArgs(args, gameDirectory, assetsDirectory); |
| 219 | - | |
| 212 | + | |
| 220 | 213 | List<String> modsToLoad = this.getModFilterList(); |
| 221 | 214 | List<String> apisToLoad = this.getAPIsToLoad(); |
| 222 | 215 | |
| 223 | - this.registerCoreAPIs(apisToLoad); | |
| 224 | - | |
| 225 | - if (this.parsedOptions.has(this.jarOption)) | |
| 226 | - { | |
| 227 | - this.initJarUsing(this.jarOption.value(this.parsedOptions)); | |
| 228 | - } | |
| 229 | - else | |
| 230 | - { | |
| 231 | - this.initJar(); | |
| 232 | - } | |
| 233 | - | |
| 234 | - LiteLoaderLogger.info("Bootstrapping LiteLoader " + LiteLoaderTweaker.VERSION); | |
| 235 | - | |
| 236 | - this.bootstrap = this.spawnBootstrap(LiteLoaderTweaker.bootstrapClassName, Launch.classLoader, gameDirectory, assetsDirectory, profile, apisToLoad); | |
| 237 | - this.properties = this.bootstrap instanceof LoaderProperties ? (LoaderProperties)this.bootstrap : null; | |
| 238 | - | |
| 239 | - this.transformerManager = new ClassTransformerManager(this.bootstrap.getRequiredTransformers()); | |
| 240 | - this.transformerManager.injectTransformers(this.bootstrap.getPacketTransformers()); | |
| 241 | - | |
| 242 | - StartupState.CONSTRUCT.completed(); | |
| 216 | + this.prepare(gameDirectory, assetsDirectory, profile, apisToLoad); | |
| 243 | 217 | |
| 244 | 218 | this.preInit(modsToLoad); |
| 245 | 219 | } |
| ... | ... | @@ -272,79 +246,13 @@ public class LiteLoaderTweaker implements ITweaker |
| 272 | 246 | apisToLoad.add(0, "com.mumfrey.liteloader.client.api.LiteLoaderCoreAPIClient"); |
| 273 | 247 | } |
| 274 | 248 | |
| 275 | - /** | |
| 276 | - * | |
| 277 | - */ | |
| 278 | - private void initJarUsing(String jarPath) | |
| 249 | + private void initJar() | |
| 279 | 250 | { |
| 280 | - try | |
| 281 | - { | |
| 282 | - if (jarPath.matches("^[0-9\\.]+$")) jarPath = String.format("versions/%1$s/%1$s.jar", jarPath); | |
| 283 | - LiteLoaderLogger.info("Version jar '%s' was specified on the command line", jarPath); | |
| 284 | - File jarFile = new File(jarPath); | |
| 285 | - this.jarUrl = jarFile.toURI().toURL(); | |
| 286 | - this.injectVersionJar(jarFile); | |
| 287 | - } | |
| 288 | - catch (Exception ex) | |
| 289 | - { | |
| 290 | - ex.printStackTrace(); | |
| 291 | - } | |
| 292 | - } | |
| 293 | - | |
| 294 | - /** | |
| 295 | - * @throws JsonSyntaxException | |
| 296 | - * @throws JsonIOException | |
| 297 | - */ | |
| 298 | - private void initJar() throws JsonSyntaxException, JsonIOException | |
| 299 | - { | |
| 300 | - String resource = "/jarfile.ref"; | |
| 301 | - InputStream refResource = LiteLoaderTweaker.class.getResourceAsStream(resource); | |
| 302 | - File refContainer = ClassPathUtilities.getPathToResource(LiteLoaderTweaker.class, resource); | |
| 303 | - if (refResource != null && refContainer != null) | |
| 304 | - { | |
| 305 | - InputStreamReader refReader = new InputStreamReader(refResource); | |
| 306 | - | |
| 307 | - try | |
| 308 | - { | |
| 309 | - @SuppressWarnings("unchecked") | |
| 310 | - Map<String, String> refMap = new Gson().fromJson(refReader, HashMap.class); | |
| 311 | - if (refMap.containsKey("jarfile")) | |
| 312 | - { | |
| 313 | - String jarPath = refMap.get("jarfile"); | |
| 314 | - LiteLoaderLogger.info("Version jar '%s' specified via jarfile.ref", jarPath); | |
| 315 | - File jarFile = new File(refContainer.getParentFile(), jarPath); | |
| 316 | - this.jarUrl = jarFile.toURI().toURL(); | |
| 317 | - this.injectVersionJar(jarFile); | |
| 318 | - return; | |
| 319 | - } | |
| 320 | - } | |
| 321 | - catch (IOException ex) {} | |
| 322 | - finally | |
| 323 | - { | |
| 324 | - try | |
| 325 | - { | |
| 326 | - refReader.close(); | |
| 327 | - refResource.close(); | |
| 328 | - } | |
| 329 | - catch (IOException ex) {} | |
| 330 | - } | |
| 331 | - } | |
| 332 | - | |
| 333 | 251 | URL[] urls = Launch.classLoader.getURLs(); |
| 334 | 252 | this.jarUrl = urls[urls.length - 1]; // probably? |
| 335 | 253 | } |
| 336 | 254 | |
| 337 | 255 | /** |
| 338 | - * @param jarFile | |
| 339 | - */ | |
| 340 | - private void injectVersionJar(File jarFile) | |
| 341 | - { | |
| 342 | - LiteLoaderLogger.info("Injecting version jar '%s'", jarFile.getAbsolutePath()); | |
| 343 | - Launch.classLoader.addURL(this.jarUrl); | |
| 344 | - LiteLoaderTweaker.addURLToParentClassLoader(this.jarUrl); | |
| 345 | - } | |
| 346 | - | |
| 347 | - /** | |
| 348 | 256 | * @param args |
| 349 | 257 | * @param gameDirectory |
| 350 | 258 | * @param assetsDirectory |
| ... | ... | @@ -353,7 +261,6 @@ public class LiteLoaderTweaker implements ITweaker |
| 353 | 261 | public void initArgs(List<String> args, File gameDirectory, File assetsDirectory) |
| 354 | 262 | { |
| 355 | 263 | OptionParser optionParser = new OptionParser(); |
| 356 | - this.jarOption = optionParser.accepts("versionJar", "Minecraft version jar to use").withRequiredArg().ofType(String.class); | |
| 357 | 264 | this.modsOption = optionParser.accepts("mods", "Comma-separated list of mods to load").withRequiredArg().ofType(String.class).withValuesSeparatedBy(','); |
| 358 | 265 | this.apisOption = optionParser.accepts("api", "Additional API classes to load").withRequiredArg().ofType(String.class); |
| 359 | 266 | optionParser.allowsUnrecognizedOptions(); |
| ... | ... | @@ -580,7 +487,7 @@ public class LiteLoaderTweaker implements ITweaker |
| 580 | 487 | |
| 581 | 488 | protected LoaderBootstrap spawnBootstrap(String bootstrapClassName, ClassLoader classLoader, File gameDirectory, File assetsDirectory, String profile, List<String> apisToLoad) |
| 582 | 489 | { |
| 583 | - if (!StartupState.CONSTRUCT.isInState()) | |
| 490 | + if (!StartupState.PREPARE.isInState()) | |
| 584 | 491 | { |
| 585 | 492 | throw new IllegalStateException("spawnBootstrap is not valid outside constructor"); |
| 586 | 493 | } |
| ... | ... | @@ -608,6 +515,35 @@ public class LiteLoaderTweaker implements ITweaker |
| 608 | 515 | } |
| 609 | 516 | |
| 610 | 517 | /** |
| 518 | + * @param gameDirectory | |
| 519 | + * @param assetsDirectory | |
| 520 | + * @param profile | |
| 521 | + * @param apisToLoad | |
| 522 | + */ | |
| 523 | + private void prepare(File gameDirectory, File assetsDirectory, String profile, List<String> apisToLoad) | |
| 524 | + { | |
| 525 | + LiteLoaderLogger.info("Bootstrapping LiteLoader " + LiteLoaderTweaker.VERSION); | |
| 526 | + | |
| 527 | + try | |
| 528 | + { | |
| 529 | + this.registerCoreAPIs(apisToLoad); | |
| 530 | + this.initJar(); | |
| 531 | + | |
| 532 | + this.bootstrap = this.spawnBootstrap(LiteLoaderTweaker.bootstrapClassName, Launch.classLoader, gameDirectory, assetsDirectory, profile, apisToLoad); | |
| 533 | + this.properties = this.bootstrap instanceof LoaderProperties ? (LoaderProperties)this.bootstrap : null; | |
| 534 | + | |
| 535 | + this.transformerManager = new ClassTransformerManager(this.bootstrap.getRequiredTransformers()); | |
| 536 | + this.transformerManager.injectTransformers(this.bootstrap.getPacketTransformers()); | |
| 537 | + | |
| 538 | + StartupState.PREPARE.completed(); | |
| 539 | + } | |
| 540 | + catch (Throwable th) | |
| 541 | + { | |
| 542 | + LiteLoaderLogger.severe(th, "Error during LiteLoader PREPARE: %s %s", th.getClass().getName(), th.getMessage()); | |
| 543 | + } | |
| 544 | + } | |
| 545 | + | |
| 546 | + /** | |
| 611 | 547 | * Do the first stage of loader startup, which enumerates mod sources and finds tweakers |
| 612 | 548 | */ |
| 613 | 549 | private void preInit(List<String> modsToLoad) | ... | ... |