1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2024-11-24 12:16:28 +01:00

Added Javadocs to various classes.

This commit is contained in:
sk89q 2014-03-23 16:28:04 -07:00
parent fae88c17f4
commit 7f5e8672cf
10 changed files with 168 additions and 3 deletions

View File

@ -23,25 +23,57 @@ import java.util.logging.Level;
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
public class AssetsRoot {
@Getter
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;
}
/**
* 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) {
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) {
String hash = asset.getHash();
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 {
String indexId = versionManifest.getAssetsIndex();
File path = getIndexPath(versionManifest);

View File

@ -9,6 +9,14 @@ package com.skcraft.launcher;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
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
@JsonIgnoreProperties(ignoreUnknown = true)
public class Configuration {

View File

@ -16,6 +16,10 @@ import java.io.File;
import java.net.URL;
import java.util.Date;
/**
* An instance is a profile that represents one particular installation
* of the game, with separate files and so on.
*/
@Data
public class Instance implements Comparable<Instance> {
@ -34,31 +38,64 @@ public class Instance implements Comparable<Instance> {
@JsonIgnore private boolean selected;
@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() {
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) {
if (launchModifier != null) {
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
public File getContentDir() {
return new File(dir, "minecraft");
}
/**
* Get the file for the package manifest.
*
* @return the manifest path, which may not exist
*/
@JsonIgnore
public File getManifestPath() {
return new File(dir, "manifest.json");
}
/**
* Get the file for the Minecraft version manfiest file.
*
* @return the version path, which may not exist
*/
@JsonIgnore
public File getVersionPath() {
return new File(dir, "version.json");
}
/**
* Get the file for the custom JAR file.
*
* @return the JAR file, which may not exist
*/
@JsonIgnore
public File getCustomJarPath() {
return new File(getContentDir(), "custom_jar.jar");

View File

@ -29,28 +29,58 @@ import java.util.concurrent.Callable;
import static com.skcraft.launcher.LauncherUtils.concat;
import static com.skcraft.launcher.util.SharedLocale._;
/**
* Stores the list of instances.
*/
@Log
public class InstanceList {
private final Launcher launcher;
@Getter private final List<Instance> instances = new ArrayList<Instance>();
/**
* Create a new instance list.
*
* @param launcher the launcher
*/
public InstanceList(@NonNull 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) {
return instances.get(index);
}
/**
* Get the number of instances.
*
* @return the number of instances
*/
public synchronized int 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() {
return new Enumerator();
}
/**
* Get a list of selected instances.
*
* @return a list of instances
*/
public synchronized List<Instance> getSelected() {
List<Instance> selected = new ArrayList<Instance>();
for (Instance instance : instances) {
@ -62,6 +92,9 @@ public class InstanceList {
return selected;
}
/**
* Sort the list of instances.
*/
public synchronized void sort() {
Collections.sort(instances);
}

View File

@ -11,6 +11,9 @@ import lombok.Data;
import java.io.File;
/**
* The command line arguments that the launcher accepts.
*/
@Data
public class LauncherArguments {

View File

@ -17,6 +17,11 @@ import java.util.List;
import java.util.regex.Matcher;
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
public class JavaProcessBuilder {

View File

@ -19,8 +19,14 @@ import java.util.WeakHashMap;
import java.util.logging.Level;
/**
* Simple persistence framework that can bind an object to a file and later allow for
* code utilizing the object to save it globally.
* Simple persistence framework that can read an object from a file, bind
* 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
public final class Persistence {

View File

@ -11,10 +11,37 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
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)
@Target(ElementType.TYPE)
public @interface Scrambled {
/**
* A key used in scrambling.
* </p>
* The key should not change once deployed.
*
* @return a key
*/
String value();
}

View File

@ -17,6 +17,10 @@ import java.util.concurrent.Callable;
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
public class UpdateChecker implements Callable<URL> {

View File

@ -39,6 +39,16 @@ import static com.skcraft.launcher.LauncherUtils.checkInterrupted;
import static com.skcraft.launcher.LauncherUtils.concat;
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
public abstract class BaseUpdater {