reconstruct the codes.

This commit is contained in:
huanghongxun 2015-07-30 08:53:52 +08:00
parent bfcad25dee
commit 022c1ade39
4 changed files with 82 additions and 13 deletions

View File

@ -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();

View File

@ -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<GameLauncher.DownloadLibraryJob> 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<MinecraftVersion> 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();
}

View File

@ -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);

View File

@ -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