From 022c1ade391793b8eb0019b6ee6abd39679dbea4 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Thu, 30 Jul 2015 08:53:52 +0800 Subject: [PATCH] reconstruct the codes. --- .../launch/AbstractMinecraftLoader.java | 4 +- .../launcher/launch/IMinecraftProvider.java | 79 ++++++++++++++++++- .../launcher/launch/MinecraftLoader.java | 10 +-- .../version/MinecraftVersionManager.java | 2 +- 4 files changed, 82 insertions(+), 13 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/AbstractMinecraftLoader.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/AbstractMinecraftLoader.java index 981a51b97..81df32357 100644 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/AbstractMinecraftLoader.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/AbstractMinecraftLoader.java @@ -41,16 +41,14 @@ import org.jackhuang.hellominecraft.utils.Utils; */ public abstract class AbstractMinecraftLoader implements IMinecraftLoader { - protected File minecraftJar; protected Profile v; protected UserProfileProvider lr; protected File gameDir; protected IMinecraftProvider provider; - public AbstractMinecraftLoader(Profile ver, IMinecraftProvider provider, UserProfileProvider lr, File minecraftJar) { + public AbstractMinecraftLoader(Profile ver, IMinecraftProvider provider, UserProfileProvider lr) { this.lr = lr; - this.minecraftJar = minecraftJar; v = ver; this.provider = provider; gameDir = v.getCanonicalGameDirFile(); diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/IMinecraftProvider.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/IMinecraftProvider.java index a92cb68cc..2b31a36e9 100644 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/IMinecraftProvider.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/IMinecraftProvider.java @@ -25,7 +25,8 @@ import org.jackhuang.hellominecraft.launcher.settings.Profile; import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion; /** - * + * Provide everything of the Minecraft of a Profile. + * @see org.jackhuang.hellominecraft.launcher.version.MinecraftVersionManager * @author huangyuhui */ public abstract class IMinecraftProvider { @@ -36,8 +37,18 @@ public abstract class IMinecraftProvider { this.profile = profile; } + /** + * Get the run directory of given version. + * @param id the given version name + * @return the run directory + */ public abstract File getRunDirectory(String id); + /** + * Get the libraries that need to download. + * @param type where to download + * @return the library collection + */ public abstract List getDownloadLibraries(DownloadType type); public abstract void openSelf(String version); @@ -46,47 +57,107 @@ public abstract class IMinecraftProvider { public abstract File getAssets(); + /** + * Returns the thing like ".minecraft/resourcepacks". + * @return the thing + */ public abstract File getResourcePacks(); public abstract GameLauncher.DecompressLibraryJob getDecompressLibraries(); public abstract File getDecompressNativesToLocation(); + /** + * @return the Minecraft jar of selected version. + */ public abstract File getMinecraftJar(); + /** + * @return the base folder of the profile. + */ public abstract File getBaseFolder(); /** - * Launch + * Provide the Minecraft Loader to generate the launching command. * + * @see org.jackhuang.hellominecraft.launcher.launch.IMinecraftLoader * @param p player informations, including username & auth_token - * @param type according to the class name 233 + * @param type where to download * @return what you want * @throws IllegalStateException circular denpendency versions */ public abstract IMinecraftLoader provideMinecraftLoader(UserProfileProvider p, DownloadType type) throws IllegalStateException; - // Versions + /** + * Rename version + * @param from The old name + * @param to The new name + * @return Is the action successful? + */ public abstract boolean renameVersion(String from, String to); + /** + * Remove the given version from disk. + * @param a the version name + * @return Is the action successful? + */ public abstract boolean removeVersionFromDisk(String a); + /** + * Redownload the Minecraft json of the given version. + * @param a the given version name + * @return Is the action successful? + */ public abstract boolean refreshJson(String a); + /** + * Redownload the Asset index json of the given version. + * @param a the given version name + * @return Is the action successful? + */ public abstract boolean refreshAssetsIndex(String a); + /** + * Choose a version randomly. + * @return the version + */ public abstract MinecraftVersion getOneVersion(); + /** + * All Minecraft version in this profile. + * @return the collection of all Minecraft version + */ public abstract Collection getVersions(); + /** + * Get the Minecraft json instance of given version. + * @param id the given version name + * @return the Minecraft json instance + */ public abstract MinecraftVersion getVersionById(String id); + /** + * getVersions().size() + * @return getVersions().size() + */ public abstract int getVersionCount(); + /** + * Refind the versions in this profile. + */ public abstract void refreshVersions(); + /** + * Install a new version to this profile. + * @param version the new version name + * @param type where to download + * @return Is the action successful? + */ public abstract boolean install(String version, DownloadType type); + /** + * When GameLauncher launches the Minecraft, this function will be called. + */ public abstract void onLaunch(); } diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/MinecraftLoader.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/MinecraftLoader.java index 1be991ec8..590e97035 100644 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/MinecraftLoader.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/MinecraftLoader.java @@ -44,12 +44,12 @@ public class MinecraftLoader extends AbstractMinecraftLoader { private MinecraftVersion version; String text; - public MinecraftLoader(Profile ver, IMinecraftProvider provider, UserProfileProvider lr, File minecraftJar) throws IllegalStateException { - this(ver, provider, lr, minecraftJar, DownloadType.Mojang); + public MinecraftLoader(Profile ver, IMinecraftProvider provider, UserProfileProvider lr) throws IllegalStateException { + this(ver, provider, lr, DownloadType.Mojang); } - public MinecraftLoader(Profile ver, IMinecraftProvider provider, UserProfileProvider lr, File minecraftJar, DownloadType downloadtype) throws IllegalStateException { - super(ver, provider, lr, minecraftJar); + public MinecraftLoader(Profile ver, IMinecraftProvider provider, UserProfileProvider lr, DownloadType downloadtype) throws IllegalStateException { + super(ver, provider, lr); version = ver.getSelectedMinecraftVersion().resolve(provider, downloadtype); } @@ -61,7 +61,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader { if (l.allow()) library += l.getFilePath(gameDir).getAbsolutePath() + File.pathSeparator; } - library += IOUtils.tryGetCanonicalFilePath(minecraftJar) + File.pathSeparator; + library += IOUtils.tryGetCanonicalFilePath(provider.getMinecraftJar()) + File.pathSeparator; library = library.substring(0, library.length() - File.pathSeparator.length()); if (v.isCanceledWrapper()) res.add("-cp"); res.add(library); diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/version/MinecraftVersionManager.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/version/MinecraftVersionManager.java index 341e11216..123ced5ac 100644 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/version/MinecraftVersionManager.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/version/MinecraftVersionManager.java @@ -286,7 +286,7 @@ public final class MinecraftVersionManager extends IMinecraftProvider { @Override public IMinecraftLoader provideMinecraftLoader(UserProfileProvider p, DownloadType type) throws IllegalStateException { - return new MinecraftLoader(profile, this, p, getMinecraftJar(), type); + return new MinecraftLoader(profile, this, p, type); } @Override