getting core 4

This commit is contained in:
huangyuhui
2016-01-19 23:16:13 +08:00
parent ec5bb40758
commit ab08a8d3f5
18 changed files with 68 additions and 58 deletions

View File

@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.settings;
package org.jackhuang.hellominecraft.launcher.core;
/**
*

View File

@@ -28,7 +28,6 @@ import java.util.zip.ZipFile;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.views.SwingUtils;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
/**
@@ -55,11 +54,6 @@ public class ModInfo implements Comparable<ModInfo> {
location = newf;
}
public void showURL() {
if (url != null)
SwingUtils.openLink(url);
}
@Override
public int compareTo(ModInfo o) {
return getFileName().toLowerCase().compareTo(o.getFileName().toLowerCase());

View File

@@ -21,10 +21,7 @@ import java.io.File;
import org.jackhuang.hellominecraft.launcher.api.PluginManager;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.jackhuang.hellominecraft.launcher.core.MCUtils;
import org.jackhuang.hellominecraft.launcher.core.version.GameDirType;
import org.jackhuang.hellominecraft.launcher.settings.LauncherVisibility;
import org.jackhuang.hellominecraft.launcher.settings.Settings;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.Utils;
import org.jackhuang.hellominecraft.utils.EventHandler;
@@ -112,7 +109,7 @@ public final class Profile {
public void setSelectedMinecraftVersion(String selectedMinecraftVersion) {
this.selectedMinecraftVersion = selectedMinecraftVersion;
Settings.save();
propertyChanged.execute("selectedMinecraftVersion");
selectedVersionChangedEvent.execute(selectedMinecraftVersion);
}
@@ -163,13 +160,13 @@ public final class Profile {
}
public Java getJava() {
return Settings.JAVA.get(getJavaIndexInAllJavas());
return Java.JAVA.get(getJavaIndexInAllJavas());
}
public int getJavaIndexInAllJavas() {
if (StrUtils.isBlank(java) && StrUtils.isNotBlank(javaDir))
java = "Custom";
int idx = Settings.JAVA.indexOf(new Java(java, null));
int idx = Java.JAVA.indexOf(new Java(java, null));
if (idx == -1) {
java = "Default";
idx = 0;
@@ -179,9 +176,9 @@ public final class Profile {
public void setJava(Java java) {
if (java == null)
this.java = Settings.JAVA.get(0).getName();
this.java = Java.JAVA.get(0).getName();
else {
int idx = Settings.JAVA.indexOf(java);
int idx = Java.JAVA.indexOf(java);
if (idx == -1)
return;
this.java = java.getName();

View File

@@ -24,7 +24,6 @@ import java.util.Map;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftProvider;
import org.jackhuang.hellominecraft.tasks.Task;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
import org.jackhuang.hellominecraft.utils.system.IOUtils;

View File

@@ -44,4 +44,17 @@ public enum DownloadType {
public String getName() {
return name;
}
private static DownloadType suggestedDownloadType = Mojang;
public static DownloadType getSuggestedDownloadType() {
return suggestedDownloadType;
}
public static void setSuggestedDownloadType(DownloadType suggestedDownloadType) {
if (suggestedDownloadType == null)
throw new IllegalArgumentException("download type should not be null.");
DownloadType.suggestedDownloadType = suggestedDownloadType;
}
}

View File

@@ -19,7 +19,6 @@ package org.jackhuang.hellominecraft.launcher.core.installers;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftInstallerService;
import java.io.File;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftBasicService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList.InstallerVersion;
import org.jackhuang.hellominecraft.launcher.core.installers.forge.ForgeInstaller;

View File

@@ -23,7 +23,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.launcher.settings.Settings;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionNewerComparator;
@@ -51,7 +51,7 @@ public class MinecraftForgeVersionList extends InstallerVersionList {
public void refreshList(String[] needed) throws Exception {
if (root != null)
return;
String s = NetUtils.get(Settings.getInstance().getDownloadSource().getProvider().getParsedLibraryDownloadURL(C.URL_FORGE_LIST));
String s = NetUtils.get(DownloadType.getSuggestedDownloadType().getProvider().getParsedLibraryDownloadURL(C.URL_FORGE_LIST));
root = C.gson.fromJson(s, MinecraftForgeVersionRoot.class);
@@ -70,7 +70,7 @@ public class MinecraftForgeVersionList extends InstallerVersionList {
if (!StrUtils.isBlank(v.branch))
ver = ver + "-" + v.branch;
String filename = root.artifact + "-" + ver + "-" + f[1] + "." + f[0];
String url = Settings.getInstance().getDownloadSource().getProvider().getParsedLibraryDownloadURL(root.webpath + ver + "/" + filename);
String url = DownloadType.getSuggestedDownloadType().getProvider().getParsedLibraryDownloadURL(root.webpath + ver + "/" + filename);
switch (f[1]) {
case "installer":
iv.installer = url;

View File

@@ -37,7 +37,7 @@ public abstract class IMinecraftService {
}
public DownloadType getDownloadType() {
return Settings.getInstance().getDownloadSource();
return DownloadType.getSuggestedDownloadType();
}
public abstract IMinecraftAssetService asset();

View File

@@ -29,14 +29,13 @@ import java.util.Map;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.Main;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
import org.jackhuang.hellominecraft.utils.CollectionUtils;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.utils.UpdateChecker;
import org.jackhuang.hellominecraft.utils.VersionNumber;
import org.jackhuang.hellominecraft.utils.system.Java;
import org.jackhuang.hellominecraft.utils.system.OS;
/**
*
@@ -51,7 +50,6 @@ public final class Settings {
private static final Config SETTINGS;
public static final UpdateChecker UPDATE_CHECKER = new UpdateChecker(new VersionNumber(Main.VERSION_FIRST, Main.VERSION_SECOND, Main.VERSION_THIRD),
"hmcl");
public static final List<Java> JAVA;
public static Config getInstance() {
return SETTINGS;
@@ -59,6 +57,11 @@ public final class Settings {
static {
SETTINGS = initSettings();
SETTINGS.downloadTypeChangedEvent.register((s, t) -> {
DownloadType.setSuggestedDownloadType(t);
return true;
});
DownloadType.setSuggestedDownloadType(SETTINGS.getDownloadSource());
if (!getProfiles().containsKey(DEFAULT_PROFILE))
getProfiles().put(DEFAULT_PROFILE, new Profile());
@@ -69,15 +72,6 @@ public final class Settings {
return true;
});
}
List<Java> temp = new ArrayList<>();
temp.add(new Java("Default", System.getProperty("java.home")));
temp.add(new Java("Custom", null));
if (OS.os() == OS.WINDOWS)
temp.addAll(Java.queryAllJavaHomeInWindowsByReg());
if (OS.os() == OS.OSX)
temp.addAll(Java.queryAllJDKInMac());
JAVA = Collections.unmodifiableList(temp);
}
private static Config initSettings() {

View File

@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.core.version;
package org.jackhuang.hellominecraft.launcher.utils;
import java.io.File;
import java.util.ArrayList;

View File

@@ -43,7 +43,7 @@ import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableModel;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.settings.LauncherVisibility;
import org.jackhuang.hellominecraft.launcher.core.LauncherVisibility;
import org.jackhuang.hellominecraft.launcher.core.Profile;
import org.jackhuang.hellominecraft.launcher.settings.Settings;
import org.jackhuang.hellominecraft.launcher.utils.FileNameFilter;
@@ -91,7 +91,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
initExternalModsTable();
initTabs();
for (Java j : Settings.JAVA)
for (Java j : Java.JAVA)
cboJava.addItem(j.getLocalizedName());
dropTarget = new DropTarget(lstExternalMods, DnDConstants.ACTION_COPY_OR_MOVE, this);
@@ -1045,7 +1045,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
return;
int idx = cboJava.getSelectedIndex();
if (idx != -1) {
Java j = Settings.JAVA.get(idx);
Java j = Java.JAVA.get(idx);
getProfile().setJava(j);
txtJavaDir.setEnabled(idx == 1);
txtJavaDir.setText(j.getHome() == null ? getProfile().getSettingsJavaDir() : j.getJava());
@@ -1080,7 +1080,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
private void lblModInfoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblModInfoMouseClicked
int idx = lstExternalMods.getSelectedRow();
if (idx > 0 && idx < getProfile().service().mod().getMods().size())
getProfile().service().mod().getMods().get(idx).showURL();
SwingUtils.openLink(getProfile().service().mod().getMods().get(idx).url);
}//GEN-LAST:event_lblModInfoMouseClicked
private void btnChoosingGameDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChoosingGameDirActionPerformed

View File

@@ -38,7 +38,7 @@ import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher;
import org.jackhuang.hellominecraft.launcher.settings.LauncherVisibility;
import org.jackhuang.hellominecraft.launcher.core.LauncherVisibility;
import org.jackhuang.hellominecraft.launcher.settings.Settings;
import org.jackhuang.hellominecraft.launcher.core.auth.AuthenticationException;
import org.jackhuang.hellominecraft.lookandfeel.GraphicsUtils;

View File

@@ -20,6 +20,7 @@ package org.jackhuang.hellominecraft.utils.system;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
@@ -30,6 +31,19 @@ import org.jackhuang.hellominecraft.HMCLog;
*/
public class Java {
public static final List<Java> JAVA;
static {
List<Java> temp = new ArrayList<>();
temp.add(new Java("Default", System.getProperty("java.home")));
temp.add(new Java("Custom", null));
if (OS.os() == OS.WINDOWS)
temp.addAll(Java.queryAllJavaHomeInWindowsByReg());
if (OS.os() == OS.OSX)
temp.addAll(Java.queryAllJDKInMac());
JAVA = Collections.unmodifiableList(temp);
}
String name, home;
public Java(String name, String home) {

View File

@@ -100,9 +100,11 @@ public class SwingUtils {
/**
* Open URL by java.awt.Desktop
*
* @param link
* @param link null is allowed but will be ignored
*/
public static void openLink(String link) {
if (link == null)
return;
try {
java.awt.Desktop.getDesktop().browse(new URI(link));
} catch (Throwable e) {

View File

@@ -18,17 +18,17 @@
package org.jackhuang.hellominecraft.launcher.servers;
import org.jackhuang.hellominecraft.launcher.api.IPlugin;
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.Profile;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.servers.mfcraft.MFCraftAuthenticator;
import org.jackhuang.hellominecraft.launcher.servers.mfcraft.MFCraftMinecraftService;
import org.jackhuang.hellominecraft.launcher.servers.mfcraft.Servers;
import org.jackhuang.hellominecraft.launcher.settings.Profile;
import org.jackhuang.hellominecraft.launcher.settings.Settings;
import org.jackhuang.hellominecraft.launcher.utils.auth.AuthenticationException;
import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.utils.auth.YggdrasilAuthenticator;
import org.jackhuang.hellominecraft.launcher.version.ServerInfo;
import org.jackhuang.hellominecraft.launcher.core.auth.AuthenticationException;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.core.auth.YggdrasilAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.version.ServerInfo;
import org.jackhuang.hellominecraft.launcher.views.MainFrame;
import org.jackhuang.hellominecraft.launcher.views.ServerListView;
import org.jackhuang.hellominecraft.utils.functions.Consumer;

View File

@@ -19,11 +19,10 @@ package org.jackhuang.hellominecraft.launcher.servers.mfcraft;
import java.io.IOException;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.servers.ServerPlugin;
import org.jackhuang.hellominecraft.launcher.settings.Profile;
import org.jackhuang.hellominecraft.launcher.version.MinecraftModService;
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersionManager;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftModService;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersionManager;
import org.jackhuang.hellominecraft.utils.ArrayUtils;
/**

View File

@@ -20,12 +20,11 @@ package org.jackhuang.hellominecraft.launcher.servers.mfcraft;
import com.google.gson.JsonSyntaxException;
import java.io.IOException;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.launcher.utils.auth.AuthenticationException;
import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.utils.auth.LoginInfo;
import static org.jackhuang.hellominecraft.launcher.utils.auth.OfflineAuthenticator.getUUIDFromUserName;
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.version.ServerInfo;
import org.jackhuang.hellominecraft.launcher.core.auth.AuthenticationException;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo;
import static org.jackhuang.hellominecraft.launcher.core.auth.OfflineAuthenticator.getUUIDFromUserName;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.utils.NetUtils;
/**

View File

@@ -18,7 +18,7 @@
package org.jackhuang.hellominecraft.launcher.servers.mfcraft;
import java.util.ArrayList;
import org.jackhuang.hellominecraft.launcher.version.ServerInfo;
import org.jackhuang.hellominecraft.launcher.core.version.ServerInfo;
/**
*