Settings.s() -> Settings.getInstance()

This commit is contained in:
huanghongxun 2015-06-25 23:08:05 +08:00
parent fb7bbbcaaf
commit bee81fd6d9
11 changed files with 87 additions and 63 deletions

View File

@ -1,3 +1,8 @@
import java.util.jar.JarOutputStream
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
@ -86,6 +91,28 @@ task proguard(type: proguard.gradle.ProGuardTask, dependsOn: jar) {
configuration 'proguard.pro'
}
task makeExecutable(dependsOn: jar) {
ext {
def re = jar.classifier
injar = jar.archivePath
jar.classifier = ''
outjar = jar.archivePath
jar.classifier = re
}
def fos = new FileOutputStream(outjar)
def is = new FileInputStream('')
def read
def bytes = new byte[8192]
while((read = is.read(bytes)) != -1)
fos.write(bytes, 0, read);
is.close()
is = new FileInputStream(injar)
while((read = is.read(bytes)) != -1)
fos.write(bytes, 0, read);
is.close()
fos.close()
}
launch4j {
launch4jCmd = 'D:\\Develop\\Java\\Launch4j\\launch4j.exe'
supportUrl = 'http://www.mcbbs.net/thread-142335-1-1.html'
@ -108,4 +135,5 @@ processResources {
}
}
build.dependsOn proguard
//build.dependsOn proguard
build.dependsOn makeExecutable

View File

@ -102,14 +102,14 @@ public final class Main implements DoneListener0 {
Settings.UPDATE_CHECKER.start();
if (StrUtils.isNotBlank(Settings.s().getProxyHost()) && StrUtils.isNotBlank(Settings.s().getProxyPort())) {
System.setProperty("http.proxyHost", Settings.s().getProxyHost());
System.setProperty("http.proxyPort", Settings.s().getProxyPort());
if (StrUtils.isNotBlank(Settings.s().getProxyUserName()) && StrUtils.isNotBlank(Settings.s().getProxyPassword()))
if (StrUtils.isNotBlank(Settings.getInstance().getProxyHost()) && StrUtils.isNotBlank(Settings.getInstance().getProxyPort())) {
System.setProperty("http.proxyHost", Settings.getInstance().getProxyHost());
System.setProperty("http.proxyPort", Settings.getInstance().getProxyPort());
if (StrUtils.isNotBlank(Settings.getInstance().getProxyUserName()) && StrUtils.isNotBlank(Settings.getInstance().getProxyPassword()))
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(Settings.s().getProxyUserName(), Settings.s().getProxyPassword().toCharArray());
return new PasswordAuthentication(Settings.getInstance().getProxyUserName(), Settings.getInstance().getProxyPassword().toCharArray());
}
});
}
@ -137,11 +137,11 @@ public final class Main implements DoneListener0 {
MessageBox.Show(C.i18n("update.no_browser"));
}
else
Settings.s().setCheckUpdate(false);
Settings.getInstance().setCheckUpdate(false);
}
public static void invokeUpdate() {
if (Settings.s().isCheckUpdate()) update();
if (Settings.getInstance().isCheckUpdate()) update();
MainFrame.instance.invokeUpdate();
}

View File

@ -52,7 +52,7 @@ public class AssetsMojangLoader extends IAssetsHandler {
File assets = mp.getAssets();
HMCLog.log("Get index: " + assetsId);
File f = IOUtils.tryGetCanonicalFile(new File(assets, "indexes/" + assetsId + ".json"));
if (!f.exists() && !MCUtils.downloadMinecraftAssetsIndex(assets, assetsId, Settings.s().getDownloadSource())) {
if (!f.exists() && !MCUtils.downloadMinecraftAssetsIndex(assets, assetsId, Settings.getInstance().getDownloadSource())) {
dl.accept(null);
return;
}

View File

@ -35,21 +35,17 @@ public abstract class IAuthenticator {
public static final List<IAuthenticator> logins;
static {
String clientToken = Settings.s().getClientToken();
String clientToken = Settings.getInstance().getClientToken();
logins = new ArrayList<>();
logins.add(offlineLogin = new OfflineAuthenticator(clientToken));
logins.add(yggdrasilLogin = new YggdrasilAuthenticator(clientToken));
logins.add(skinmeLogin = new SkinmeAuthenticator(clientToken));
//logins.add(bestLogin = new BestLogin(clientToken));
yggdrasilLogin.onLoadSettings(Settings.s().getYggdrasilConfig());
yggdrasilLogin.onLoadSettings(Settings.getInstance().getYggdrasilConfig());
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
Settings.s().setYggdrasilConfig(yggdrasilLogin.onSaveSettings());
}
});
Runtime.getRuntime().addShutdownHook(new Thread(() ->
Settings.getInstance().setYggdrasilConfig(yggdrasilLogin.onSaveSettings())
));
}
protected String clientToken;

View File

@ -66,7 +66,7 @@ public class ForgeInstaller extends Task {
File from = new File(gameDir, "versions" + File.separator + profile.install.minecraft);
if(!from.exists()) {
if(MessageBox.Show(C.i18n("install.no_version_if_intall")) == MessageBox.YES_OPTION) {
if(!mp.install(profile.install.minecraft, Settings.s().getDownloadSource())) {
if(!mp.install(profile.install.minecraft, Settings.getInstance().getDownloadSource())) {
setFailReason(new RuntimeException(C.i18n("install.no_version")));
}
} else {

View File

@ -44,7 +44,7 @@ public final class Settings {
private static final Config settings;
public static final UpdateChecker UPDATE_CHECKER;
public static Config s() {
public static Config getInstance() {
return settings;
}

View File

@ -193,14 +193,14 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
@Override
public boolean refreshJson(String id) {
return MCUtils.downloadMinecraftVersionJson(baseFolder, id, Settings.s().getDownloadSource());
return MCUtils.downloadMinecraftVersionJson(baseFolder, id, Settings.getInstance().getDownloadSource());
}
@Override
public boolean refreshAssetsIndex(String id) {
MinecraftVersion mv = getVersionById(id);
if (mv == null) return false;
return MCUtils.downloadMinecraftAssetsIndex(new File(baseFolder, "assets"), mv.assets, Settings.s().getDownloadSource());
return MCUtils.downloadMinecraftAssetsIndex(new File(baseFolder, "assets"), mv.assets, Settings.getInstance().getDownloadSource());
}
@Override
@ -226,7 +226,7 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
@Override
public List<GameLauncher.DownloadLibraryJob> getDownloadLibraries(DownloadType downloadType) {
ArrayList<DownloadLibraryJob> downloadLibraries = new ArrayList<>();
MinecraftVersion v = profile.getSelectedMinecraftVersion().resolve(this, Settings.s().getDownloadSource());
MinecraftVersion v = profile.getSelectedMinecraftVersion().resolve(this, Settings.getInstance().getDownloadSource());
for (IMinecraftLibrary l : v.libraries) {
l.init();
if (l.allow()) {
@ -259,7 +259,7 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
@Override
public GameLauncher.DecompressLibraryJob getDecompressLibraries() {
MinecraftVersion v = profile.getSelectedMinecraftVersion().resolve(this, Settings.s().getDownloadSource());
MinecraftVersion v = profile.getSelectedMinecraftVersion().resolve(this, Settings.getInstance().getDownloadSource());
ArrayList<File> unzippings = new ArrayList<>();
ArrayList<String[]> extractRules = new ArrayList<>();
for (IMinecraftLibrary l : v.libraries) {

View File

@ -1020,12 +1020,12 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
}//GEN-LAST:event_btnRetryLiteLoaderActionPerformed
private void btnDownloadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadActionPerformed
downloadMinecraft(Settings.s().getDownloadSource());
downloadMinecraft(Settings.getInstance().getDownloadSource());
refreshVersions();
}//GEN-LAST:event_btnDownloadActionPerformed
private void btnRefreshGameDownloadsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshGameDownloadsActionPerformed
refreshDownloads(Settings.s().getDownloadSource());
refreshDownloads(Settings.getInstance().getDownloadSource());
}//GEN-LAST:event_btnRefreshGameDownloadsActionPerformed
private void btnExploreMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnExploreMouseClicked
@ -1158,7 +1158,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
for (Profile s : Settings.getProfiles()) {
if (firstProfile == null) firstProfile = s;
cboProfiles.addItem(s.getName());
if (Settings.s().getLast() != null && Settings.s().getLast().equals(s.getName())) {
if (Settings.getInstance().getLast() != null && Settings.getInstance().getLast().equals(s.getName())) {
index = i;
selectedProfile = s;
}
@ -1250,7 +1250,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
if (mcVersion == null || profile == null) return;
type.getList((value) -> {
if (value != null)
TaskWindow.getInstance().addTask(type.getDownloadTask(Settings.s().getDownloadSource().getProvider())).start();
TaskWindow.getInstance().addTask(type.getDownloadTask(Settings.getInstance().getDownloadSource().getProvider())).start();
});
}
@ -1297,7 +1297,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
void downloadMinecraft(DownloadType index) {
if (profile == null) return;
if (lstDownloads.getSelectedRow() < 0)
refreshDownloads(Settings.s().getDownloadSource());
refreshDownloads(Settings.getInstance().getDownloadSource());
if (lstDownloads.getSelectedRow() < 0) {
MessageBox.Show(C.i18n("gamedownload.not_refreshed"));
return;
@ -1328,7 +1328,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
}
void refreshVersions() {
list = Settings.s().getDownloadSource().getProvider().getInstallerByType(id);
list = Settings.getInstance().getDownloadSource().getProvider().getInstallerByType(id);
if (TaskWindow.getInstance().addTask(new TaskRunnableArg1<>(C.i18n("install." + id + ".get_list"), list)
.registerPreviousResult(new DefaultPreviousResult<>(new String[]{getMinecraftVersionFormatted()})))
.start())

View File

@ -38,14 +38,14 @@ public class LauncherSettingsPanel extends javax.swing.JPanel {
public LauncherSettingsPanel() {
initComponents();
txtBackgroundPath.setText(Settings.s().getBgpath());
txtProxyHost.setText(Settings.s().getProxyHost());
txtProxyPort.setText(Settings.s().getProxyPort());
txtProxyUsername.setText(Settings.s().getProxyUserName());
txtProxyPassword.setText(Settings.s().getProxyPassword());
cboDownloadSource.setSelectedIndex(Settings.s().getDownloadType());
cboTheme.setSelectedIndex(Settings.s().getTheme());
chkEnableShadow.setSelected(Settings.s().isEnableShadow());
txtBackgroundPath.setText(Settings.getInstance().getBgpath());
txtProxyHost.setText(Settings.getInstance().getProxyHost());
txtProxyPort.setText(Settings.getInstance().getProxyPort());
txtProxyUsername.setText(Settings.getInstance().getProxyUserName());
txtProxyPassword.setText(Settings.getInstance().getProxyPassword());
cboDownloadSource.setSelectedIndex(Settings.getInstance().getDownloadType());
cboTheme.setSelectedIndex(Settings.getInstance().getTheme());
chkEnableShadow.setSelected(Settings.getInstance().isEnableShadow());
setBackground(Color.white);
setOpaque(true);
@ -250,7 +250,7 @@ public class LauncherSettingsPanel extends javax.swing.JPanel {
}// </editor-fold>//GEN-END:initComponents
private void cboDownloadSourceItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboDownloadSourceItemStateChanged
Settings.s().setDownloadType(cboDownloadSource.getSelectedIndex());
Settings.getInstance().setDownloadType(cboDownloadSource.getSelectedIndex());
}//GEN-LAST:event_cboDownloadSourceItemStateChanged
private void btnSelBackgroundPathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelBackgroundPathActionPerformed
@ -266,7 +266,7 @@ public class LauncherSettingsPanel extends javax.swing.JPanel {
String path = fc.getSelectedFile().getCanonicalPath();
path = IOUtils.removeLastSeparator(path);
txtBackgroundPath.setText(path);
Settings.s().setBgpath(path);
Settings.getInstance().setBgpath(path);
MainFrame.instance.loadBackground();
} catch (IOException e) {
HMCLog.warn("Failed to set background path.", e);
@ -275,7 +275,7 @@ public class LauncherSettingsPanel extends javax.swing.JPanel {
}//GEN-LAST:event_btnSelBackgroundPathActionPerformed
private void txtBackgroundPathFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtBackgroundPathFocusLost
Settings.s().setBgpath(txtBackgroundPath.getText());
Settings.getInstance().setBgpath(txtBackgroundPath.getText());
MainFrame.instance.loadBackground();
}//GEN-LAST:event_txtBackgroundPathFocusLost
@ -284,29 +284,29 @@ public class LauncherSettingsPanel extends javax.swing.JPanel {
}//GEN-LAST:event_btnCheckUpdateActionPerformed
private void chkEnableShadowFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkEnableShadowFocusLost
Settings.s().setEnableShadow(chkEnableShadow.isSelected());
Settings.getInstance().setEnableShadow(chkEnableShadow.isSelected());
}//GEN-LAST:event_chkEnableShadowFocusLost
private void cboThemeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboThemeItemStateChanged
Settings.s().setTheme(cboTheme.getSelectedIndex());
Settings.getInstance().setTheme(cboTheme.getSelectedIndex());
if(MainFrame.instance != null)
MainFrame.instance.reloadColor();
}//GEN-LAST:event_cboThemeItemStateChanged
private void txtProxyHostFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtProxyHostFocusLost
Settings.s().setProxyHost(txtProxyHost.getText());
Settings.getInstance().setProxyHost(txtProxyHost.getText());
}//GEN-LAST:event_txtProxyHostFocusLost
private void txtProxyPortFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtProxyPortFocusLost
Settings.s().setProxyPort(txtProxyPort.getText());
Settings.getInstance().setProxyPort(txtProxyPort.getText());
}//GEN-LAST:event_txtProxyPortFocusLost
private void txtProxyUsernameFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtProxyUsernameFocusLost
Settings.s().setProxyUserName(txtProxyUsername.getText());
Settings.getInstance().setProxyUserName(txtProxyUsername.getText());
}//GEN-LAST:event_txtProxyUsernameFocusLost
private void txtProxyPasswordFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtProxyPasswordFocusLost
Settings.s().setProxyPassword(txtProxyPassword.getText());
Settings.getInstance().setProxyPassword(txtProxyPassword.getText());
}//GEN-LAST:event_txtProxyPasswordFocusLost
// Variables declaration - do not modify//GEN-BEGIN:variables

View File

@ -70,7 +70,7 @@ public final class MainFrame extends DraggableFrame {
MainFrame() {
defaultTitle = Main.makeTitle();
enableShadow = Settings.s().isEnableShadow();
enableShadow = Settings.getInstance().isEnableShadow();
if (enableShadow)
setSize(834, 542);
else
@ -89,7 +89,7 @@ public final class MainFrame extends DraggableFrame {
getRootPane().setBorder(border = new DropShadowBorder(borderColor, 4));
} catch (Throwable ex) {
HMCLog.err("Failed to set window transparent.", ex);
Settings.s().setEnableShadow(false);
Settings.getInstance().setEnableShadow(false);
setSize(802, 511);
}
@ -97,8 +97,8 @@ public final class MainFrame extends DraggableFrame {
}
private void initComponents() {
borderColor = BasicColors.bgcolors[Settings.s().getTheme()];
borderColorDarker = BasicColors.bgcolors_darker[Settings.s().getTheme()];
borderColor = BasicColors.bgcolors[Settings.getInstance().getTheme()];
borderColorDarker = BasicColors.bgcolors_darker[Settings.getInstance().getTheme()];
realPanel = new JPanel();
realPanel.setLayout(null);
@ -265,7 +265,7 @@ public final class MainFrame extends DraggableFrame {
ImageIcon background;
public void loadBackground() {
background = Utils.searchBackgroundImage(Main.getIcon("background.jpg"), Settings.s().getBgpath(), 800, 480);
background = Utils.searchBackgroundImage(Main.getIcon("background.jpg"), Settings.getInstance().getBgpath(), 800, 480);
if (background != null) {
if (backgroundLabel == null) {
backgroundLabel = new JLabel(background);
@ -316,8 +316,8 @@ public final class MainFrame extends DraggableFrame {
Color borderColorDarker = BasicColors.COLOR_BLUE_DARKER;
public void reloadColor() {
borderColor = BasicColors.bgcolors[Settings.s().getTheme()];
borderColorDarker = BasicColors.bgcolors_darker[Settings.s().getTheme()];
borderColor = BasicColors.bgcolors[Settings.getInstance().getTheme()];
borderColorDarker = BasicColors.bgcolors_darker[Settings.getInstance().getTheme()];
if (border != null)
border.setColor(borderColor);
header.setBackground(borderColor);

View File

@ -293,7 +293,7 @@ public class MainPagePanel extends javax.swing.JPanel {
}//GEN-LAST:event_txtPlayerNameFocusGained
private void txtPlayerNameFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPlayerNameFocusLost
Settings.s().setUsername(txtPlayerName.getText());
Settings.getInstance().setUsername(txtPlayerName.getText());
}//GEN-LAST:event_txtPlayerNameFocusLost
private void cboLoginModeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboLoginModeItemStateChanged
@ -313,15 +313,15 @@ public class MainPagePanel extends javax.swing.JPanel {
CardLayout cl = (CardLayout) pnlPassword.getLayout();
if (l.isLoggedIn()) cl.last(pnlPassword);
else cl.first(pnlPassword);
String username = Settings.s().getUsername();
String username = Settings.getInstance().getUsername();
if (StrUtils.isNotBlank(username)) txtPlayerName.setText(username);
Settings.s().setLoginType(index);
Settings.getInstance().setLoginType(index);
}//GEN-LAST:event_cboLoginModeItemStateChanged
private void cboProfilesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboProfilesItemStateChanged
if (!isLoading && cboProfiles.getSelectedIndex() != -1 && !StrUtils.isBlank((String) cboProfiles.getSelectedItem())) {
Settings.s().setLast((String) cboProfiles.getSelectedItem());
Settings.getInstance().setLast((String) cboProfiles.getSelectedItem());
loadMinecraftVersions();
}
}//GEN-LAST:event_cboProfilesItemStateChanged
@ -401,12 +401,12 @@ public class MainPagePanel extends javax.swing.JPanel {
}
final int index = cboLoginMode.getSelectedIndex();
final IAuthenticator l = IAuthenticator.logins.get(index);
final LoginInfo li = new LoginInfo(Settings.s().getUsername(), l.isLoggedIn() || l.isHidePasswordBox() ? null : new String(txtPassword.getPassword()));
final LoginInfo li = new LoginInfo(Settings.getInstance().getUsername(), l.isLoggedIn() || l.isHidePasswordBox() ? null : new String(txtPassword.getPassword()));
Thread t = new Thread() {
@Override
public void run() {
Thread.currentThread().setName("Game Launcher");
DefaultGameLauncher gl = new DefaultGameLauncher(getCurrentProfile(), li, l, Settings.s().getDownloadSource());
DefaultGameLauncher gl = new DefaultGameLauncher(getCurrentProfile(), li, l, Settings.getInstance().getDownloadSource());
gl.failEvent.register((sender, s) -> {
if (s != null) MessageBox.Show(s);
MainFrame.instance.closeMessage();
@ -431,9 +431,9 @@ public class MainPagePanel extends javax.swing.JPanel {
} catch (Exception ex) {
HMCLog.warn("Failed to get login name", ex);
}
if (Settings.s().getLoginType() < list.size()) {
if (Settings.getInstance().getLoginType() < list.size()) {
preaparingAuth = false;
cboLoginMode.setSelectedIndex(Settings.s().getLoginType());
cboLoginMode.setSelectedIndex(Settings.getInstance().getLoginType());
cboLoginModeItemStateChanged(null);
}
@ -526,7 +526,7 @@ public class MainPagePanel extends javax.swing.JPanel {
}
public void onSelected() {
refreshMinecrafts(Settings.s().getLast());
refreshMinecrafts(Settings.getInstance().getLast());
}
// Variables declaration - do not modify//GEN-BEGIN:variables