mirror of
https://github.com/SKCraft/Launcher.git
synced 2025-02-16 01:41:22 +01:00
Added Javadocs to various classes.
This commit is contained in:
parent
fae88c17f4
commit
7f5e8672cf
@ -23,25 +23,57 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
import static com.skcraft.launcher.util.SharedLocale._;
|
import static com.skcraft.launcher.util.SharedLocale._;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a directory that stores assets for Minecraft. The class has
|
||||||
|
* various methods that abstract operations involving the assets (such
|
||||||
|
* as getting the path to a certain object).
|
||||||
|
*/
|
||||||
@Log
|
@Log
|
||||||
public class AssetsRoot {
|
public class AssetsRoot {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final File dir;
|
private final File dir;
|
||||||
|
|
||||||
public AssetsRoot(File dir) {
|
/**
|
||||||
|
* Create a new instance.
|
||||||
|
*
|
||||||
|
* @param dir the directory to the assets folder
|
||||||
|
*/
|
||||||
|
public AssetsRoot(@NonNull File dir) {
|
||||||
this.dir = dir;
|
this.dir = dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the path to the index .json file for a version manfiest.
|
||||||
|
*
|
||||||
|
* @param versionManifest the version manifest
|
||||||
|
* @return the file, which may not exist
|
||||||
|
*/
|
||||||
public File getIndexPath(VersionManifest versionManifest) {
|
public File getIndexPath(VersionManifest versionManifest) {
|
||||||
return new File(dir, "indexes/" + versionManifest.getAssetsIndex() + ".json");
|
return new File(dir, "indexes/" + versionManifest.getAssetsIndex() + ".json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the local path for a given asset.
|
||||||
|
*
|
||||||
|
* @param asset the asset
|
||||||
|
* @return the file, which may not exist
|
||||||
|
*/
|
||||||
public File getObjectPath(Asset asset) {
|
public File getObjectPath(Asset asset) {
|
||||||
String hash = asset.getHash();
|
String hash = asset.getHash();
|
||||||
return new File(dir, "objects/" + hash.substring(0, 2) + "/" + hash);
|
return new File(dir, "objects/" + hash.substring(0, 2) + "/" + hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an instance of the assets tree builder, which copies the indexed
|
||||||
|
* assets (identified by hashes) into a directory where the assets
|
||||||
|
* have been renamed and moved to their real names and locations
|
||||||
|
* (i.e. sounds/whatever.ogg).
|
||||||
|
*
|
||||||
|
* @param versionManifest the version manifest
|
||||||
|
* @return the builder
|
||||||
|
* @throws LauncherException
|
||||||
|
*/
|
||||||
public AssetsTreeBuilder createAssetsBuilder(@NonNull VersionManifest versionManifest) throws LauncherException {
|
public AssetsTreeBuilder createAssetsBuilder(@NonNull VersionManifest versionManifest) throws LauncherException {
|
||||||
String indexId = versionManifest.getAssetsIndex();
|
String indexId = versionManifest.getAssetsIndex();
|
||||||
File path = getIndexPath(versionManifest);
|
File path = getIndexPath(versionManifest);
|
||||||
|
@ -9,6 +9,14 @@ package com.skcraft.launcher;
|
|||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The configuration for the launcher.
|
||||||
|
* </p>
|
||||||
|
* Default values are stored as field values. Note that if a default
|
||||||
|
* value is changed after the launcher has been deployed, it may not take effect
|
||||||
|
* for users who have already used the launcher because the old default
|
||||||
|
* values would have been written to disk.
|
||||||
|
*/
|
||||||
@Data
|
@Data
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class Configuration {
|
public class Configuration {
|
||||||
|
@ -16,6 +16,10 @@ import java.io.File;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An instance is a profile that represents one particular installation
|
||||||
|
* of the game, with separate files and so on.
|
||||||
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class Instance implements Comparable<Instance> {
|
public class Instance implements Comparable<Instance> {
|
||||||
|
|
||||||
@ -34,31 +38,64 @@ public class Instance implements Comparable<Instance> {
|
|||||||
@JsonIgnore private boolean selected;
|
@JsonIgnore private boolean selected;
|
||||||
@JsonIgnore private boolean local;
|
@JsonIgnore private boolean local;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tile of the instance, which might be the same as the
|
||||||
|
* instance name if no title is set.
|
||||||
|
*
|
||||||
|
* @return a title
|
||||||
|
*/
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title != null ? title : name;
|
return title != null ? title : name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the given process builder with launch settings that are
|
||||||
|
* specific to this instance.
|
||||||
|
*
|
||||||
|
* @param builder the process builder
|
||||||
|
*/
|
||||||
public void modify(JavaProcessBuilder builder) {
|
public void modify(JavaProcessBuilder builder) {
|
||||||
if (launchModifier != null) {
|
if (launchModifier != null) {
|
||||||
launchModifier.modify(builder);
|
launchModifier.modify(builder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the file for the directory where Minecraft's game files are
|
||||||
|
* stored, including user files (screenshots, etc.).
|
||||||
|
*
|
||||||
|
* @return the content directory, which may not exist
|
||||||
|
*/
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public File getContentDir() {
|
public File getContentDir() {
|
||||||
return new File(dir, "minecraft");
|
return new File(dir, "minecraft");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the file for the package manifest.
|
||||||
|
*
|
||||||
|
* @return the manifest path, which may not exist
|
||||||
|
*/
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public File getManifestPath() {
|
public File getManifestPath() {
|
||||||
return new File(dir, "manifest.json");
|
return new File(dir, "manifest.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the file for the Minecraft version manfiest file.
|
||||||
|
*
|
||||||
|
* @return the version path, which may not exist
|
||||||
|
*/
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public File getVersionPath() {
|
public File getVersionPath() {
|
||||||
return new File(dir, "version.json");
|
return new File(dir, "version.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the file for the custom JAR file.
|
||||||
|
*
|
||||||
|
* @return the JAR file, which may not exist
|
||||||
|
*/
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public File getCustomJarPath() {
|
public File getCustomJarPath() {
|
||||||
return new File(getContentDir(), "custom_jar.jar");
|
return new File(getContentDir(), "custom_jar.jar");
|
||||||
|
@ -29,28 +29,58 @@ import java.util.concurrent.Callable;
|
|||||||
import static com.skcraft.launcher.LauncherUtils.concat;
|
import static com.skcraft.launcher.LauncherUtils.concat;
|
||||||
import static com.skcraft.launcher.util.SharedLocale._;
|
import static com.skcraft.launcher.util.SharedLocale._;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the list of instances.
|
||||||
|
*/
|
||||||
@Log
|
@Log
|
||||||
public class InstanceList {
|
public class InstanceList {
|
||||||
|
|
||||||
private final Launcher launcher;
|
private final Launcher launcher;
|
||||||
@Getter private final List<Instance> instances = new ArrayList<Instance>();
|
@Getter private final List<Instance> instances = new ArrayList<Instance>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance list.
|
||||||
|
*
|
||||||
|
* @param launcher the launcher
|
||||||
|
*/
|
||||||
public InstanceList(@NonNull Launcher launcher) {
|
public InstanceList(@NonNull Launcher launcher) {
|
||||||
this.launcher = launcher;
|
this.launcher = launcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the instance at a particular index.
|
||||||
|
*
|
||||||
|
* @param index the index
|
||||||
|
* @return the instance
|
||||||
|
*/
|
||||||
public synchronized Instance get(int index) {
|
public synchronized Instance get(int index) {
|
||||||
return instances.get(index);
|
return instances.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of instances.
|
||||||
|
*
|
||||||
|
* @return the number of instances
|
||||||
|
*/
|
||||||
public synchronized int size() {
|
public synchronized int size() {
|
||||||
return instances.size();
|
return instances.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a worker that loads the list of instances from disk and from
|
||||||
|
* the remote list of packages.
|
||||||
|
*
|
||||||
|
* @return the worker
|
||||||
|
*/
|
||||||
public Enumerator createEnumerator() {
|
public Enumerator createEnumerator() {
|
||||||
return new Enumerator();
|
return new Enumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of selected instances.
|
||||||
|
*
|
||||||
|
* @return a list of instances
|
||||||
|
*/
|
||||||
public synchronized List<Instance> getSelected() {
|
public synchronized List<Instance> getSelected() {
|
||||||
List<Instance> selected = new ArrayList<Instance>();
|
List<Instance> selected = new ArrayList<Instance>();
|
||||||
for (Instance instance : instances) {
|
for (Instance instance : instances) {
|
||||||
@ -62,6 +92,9 @@ public class InstanceList {
|
|||||||
return selected;
|
return selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort the list of instances.
|
||||||
|
*/
|
||||||
public synchronized void sort() {
|
public synchronized void sort() {
|
||||||
Collections.sort(instances);
|
Collections.sort(instances);
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,9 @@ import lombok.Data;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The command line arguments that the launcher accepts.
|
||||||
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class LauncherArguments {
|
public class LauncherArguments {
|
||||||
|
|
||||||
|
@ -17,6 +17,11 @@ import java.util.List;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A tool to build the entire command line used to launch a Java process.
|
||||||
|
* It combines flags, memory settings, arguments, the class path, and
|
||||||
|
* the main class.
|
||||||
|
*/
|
||||||
@ToString
|
@ToString
|
||||||
public class JavaProcessBuilder {
|
public class JavaProcessBuilder {
|
||||||
|
|
||||||
|
@ -19,8 +19,14 @@ import java.util.WeakHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple persistence framework that can bind an object to a file and later allow for
|
* Simple persistence framework that can read an object from a file, bind
|
||||||
* code utilizing the object to save it globally.
|
* that object to that file, and allow any code having a reference to the
|
||||||
|
* object make changes to the object and save those changes back to disk.
|
||||||
|
* </p>
|
||||||
|
* For example:
|
||||||
|
* <pre>config = Persistence.load(file, Configuration.class);
|
||||||
|
* config.changeSomething();
|
||||||
|
* Persistence.commit(config);</pre>
|
||||||
*/
|
*/
|
||||||
@Log
|
@Log
|
||||||
public final class Persistence {
|
public final class Persistence {
|
||||||
|
@ -11,10 +11,37 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classes that are annotated with this will be saved <em>scrambled</em>
|
||||||
|
* to disk when saved using {@link com.skcraft.launcher.persistence.Persistence}.
|
||||||
|
* </p>
|
||||||
|
* The data may be scrambled using an encryption algorithm, but it's not
|
||||||
|
* done with security in mind. Decryption requires a key, and that
|
||||||
|
* key would either have to be stored in the source code, defeating the
|
||||||
|
* purpose of encryption, or the user would have to be prompted with a
|
||||||
|
* password every time (possibly through an OS key ring service).
|
||||||
|
* That creates extra hassle, so it is not done here.
|
||||||
|
* </p>
|
||||||
|
* Therefore , you should not depend on data that is scrambled to
|
||||||
|
* be secure. It does, however, make it impossible for most people
|
||||||
|
* to just read the file's contents, which is "better than nothing"
|
||||||
|
* Documentation should not indicate to the user that the data is
|
||||||
|
* protected however, because that would provide a false sense of
|
||||||
|
* security.
|
||||||
|
* </p>
|
||||||
|
* Account data is scrambled to make it harder to extract passwords.
|
||||||
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
public @interface Scrambled {
|
public @interface Scrambled {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A key used in scrambling.
|
||||||
|
* </p>
|
||||||
|
* The key should not change once deployed.
|
||||||
|
*
|
||||||
|
* @return a key
|
||||||
|
*/
|
||||||
String value();
|
String value();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,10 @@ import java.util.concurrent.Callable;
|
|||||||
|
|
||||||
import static com.skcraft.launcher.util.SharedLocale._;
|
import static com.skcraft.launcher.util.SharedLocale._;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A worker that checks for an update to the launcher. A URL is returned
|
||||||
|
* if there is an update to be downloaded.
|
||||||
|
*/
|
||||||
@Log
|
@Log
|
||||||
public class UpdateChecker implements Callable<URL> {
|
public class UpdateChecker implements Callable<URL> {
|
||||||
|
|
||||||
|
@ -39,6 +39,16 @@ import static com.skcraft.launcher.LauncherUtils.checkInterrupted;
|
|||||||
import static com.skcraft.launcher.LauncherUtils.concat;
|
import static com.skcraft.launcher.LauncherUtils.concat;
|
||||||
import static com.skcraft.launcher.util.SharedLocale._;
|
import static com.skcraft.launcher.util.SharedLocale._;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base implementation of the various routines involved in downloading
|
||||||
|
* and updating Minecraft (including the launcher's modpacks), such as asset
|
||||||
|
* downloading, .jar downloading, and so on.
|
||||||
|
* </p>
|
||||||
|
* Updating actually starts in {@link com.skcraft.launcher.update.Updater},
|
||||||
|
* which is the update worker. This class exists to allow updaters that don't
|
||||||
|
* use the launcher's default modpack format to reuse these update
|
||||||
|
* routines. (It also makes the size of the <code>Updater</code> class smaller.)
|
||||||
|
*/
|
||||||
@Log
|
@Log
|
||||||
public abstract class BaseUpdater {
|
public abstract class BaseUpdater {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user