@@ -16,6 +16,7 @@
import java.net.URL;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
@@ -76,6 +77,7 @@ public void windowClosing(WindowEvent arg0)
optionsPanel.add(labelPanel, "West");
optionsPanel.add(fieldPanel, "Center");

//FORCE UPDATE
final JButton forceButton = new JButton(
launcherFrame.locale.getString("options.forceUpdate"));
if (launcherFrame.getConfig().getString("force-update") != null)
@@ -88,8 +90,69 @@ public void windowClosing(WindowEvent arg0)
labelPanel.add(new JLabel(launcherFrame.locale
.getString("options.forceUpdateLabel") + ": ", 4));
fieldPanel.add(forceButton);

//OFFLINE MODE
labelPanel.add(new JLabel(launcherFrame.locale.getString("options.offlineMode")));
final JCheckBox offlineModeToggle = new JCheckBox(launcherFrame.locale.getString("options.onlineMode"));
final boolean offlineMode = launcherFrame.getConfig().getBoolean("launcher.offlineMode");
if(offlineMode)
{
offlineModeToggle.setSelected(true);
offlineModeToggle.setText(launcherFrame.locale.getString("options.offlineMode"));
}
offlineModeToggle.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e)
{
if(offlineModeToggle.isSelected())
{
offlineModeToggle.setText(launcherFrame.locale.getString("options.offlineMode"));
launcherFrame.getConfig().set("launcher.offlineMode", true);
}
else
{
offlineModeToggle.setText(launcherFrame.locale.getString("options.onlineMode"));
launcherFrame.getConfig().set("launcher.offlineMode", false);
}
}
});
fieldPanel.add(offlineModeToggle);

//HTTP MODE
final boolean httpsMode = launcherFrame.getConfig().getBoolean("launcher.httpsMode");
final JCheckBox httpsModeToggle = new JCheckBox();
if(httpsMode)
{
labelPanel.add(new JLabel(launcherFrame.locale.getString("options.httpsMode")));
httpsModeToggle.setText(launcherFrame.locale.getString("options.httpsMode"));
httpsModeToggle.setSelected(true);
}
else
{
labelPanel.add(new JLabel(launcherFrame.locale.getString("options.httpMode")));
httpsModeToggle.setText(launcherFrame.locale.getString("options.httpMode"));
}
httpsModeToggle.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0)
{
if(httpsModeToggle.isSelected())
{
httpsModeToggle.setText(launcherFrame.locale.getString("options.httpsMode"));
launcherFrame.getConfig().set("launcher.httpsMode", true);
}
else
{
httpsModeToggle.setText(launcherFrame.locale.getString("options.httpMode"));
launcherFrame.getConfig().set("launcher.httpsMode", false);
}
}
});
fieldPanel.add(httpsModeToggle);

//PROFILS
labelPanel.add(new JLabel(launcherFrame.locale
.getString("options.profiles") + ":", 4));
.getString("options.profiles") + ":"));
final JButton profilesButton = new JButton(
launcherFrame.locale.getString("options.profiles"));
profilesButton.addActionListener(new ActionListener() {
@@ -101,8 +164,9 @@ public void actionPerformed(ActionEvent e)
});
fieldPanel.add(profilesButton);

//GAME LOCATION
labelPanel.add(new JLabel(launcherFrame.locale
.getString("options.gameLocationLabel") + ": ", 4));
.getString("options.gameLocationLabel") + ": "));
final TransparentLabel dirLink = new TransparentLabel(Utils
.getWorkingDirectory(launcherFrame).toString()) {
private static final long serialVersionUID = 0L;
@@ -62,7 +62,8 @@ public void actionPerformed(ActionEvent e)
{
case ADD:
launcherFrame.profiles
.createProfile(profileName.getText());
.createProfile(profileName
.getText());
dialog.refreshList();
break;

@@ -26,11 +26,13 @@ public class ProfilesPanel extends JDialog

private final JPanel contentPanel = new JPanel();
private final Profile previousProfile;
private final JList<Object> list;
@SuppressWarnings("rawtypes")
private final JList list;

/**
* Create the dialog.
*/
@SuppressWarnings("rawtypes")
public ProfilesPanel(LauncherFrame parent)
{
super(parent);
@@ -47,15 +49,15 @@ public ProfilesPanel(LauncherFrame parent)
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(null);

list = new JList<Object>();
list = new JList();
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setBorder(new LineBorder(new Color(0, 0, 0)));
list.setBounds(10, 11, 275, 146);
refreshList();
list.setSelectedValue(launcherFrame.profiles.getCurrentProfile(), true);
contentPanel.add(list);

final JButton btnAdd = new JButton("Add");
final JButton btnAdd = new JButton(launcherFrame.locale.getString("profiles.add"));
btnAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
@@ -69,7 +71,7 @@ public void actionPerformed(ActionEvent e)
btnAdd.setBounds(295, 8, 89, 23);
contentPanel.add(btnAdd);

final JButton btnEdit = new JButton("Edit");
final JButton btnEdit = new JButton(launcherFrame.locale.getString("profiles.edit"));
btnEdit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
@@ -84,10 +86,12 @@ public void actionPerformed(ActionEvent e)
btnEdit.setBounds(295, 42, 89, 23);
contentPanel.add(btnEdit);

final JButton btnRemove = new JButton("Remove");
final JButton btnRemove = new JButton(launcherFrame.locale.getString("profiles.remove"));
btnRemove.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
launcherFrame.profiles.deleteProfile((Profile) list.getSelectedValue());
public void actionPerformed(ActionEvent e)
{
launcherFrame.profiles.deleteProfile((Profile) list
.getSelectedValue());
refreshList();
}
});
@@ -126,7 +130,7 @@ public void actionPerformed(ActionEvent arg0)
getRootPane().setDefaultButton(okButton);
}
{
final JButton cancelButton = new JButton("Cancel");
final JButton cancelButton = new JButton(launcherFrame.locale.getString("global.cancel"));
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
@@ -144,9 +148,10 @@ public Profile getSelectedProfile()
return (Profile) list.getSelectedValue();
}

@SuppressWarnings({ "rawtypes", "unchecked" })
public void refreshList()
{
final ListModel<Object> model = new ProfileListModel(launcherFrame);
final ListModel model = new ProfileListModel(launcherFrame);
list.setModel(model);
}
}
@@ -117,7 +117,7 @@ public void merge(Map<String, Object> from, Map<String, Object> to)

public void set(String name, Object value)
{
config.put(name.toLowerCase(), value);
config.put(name, value);
}

public String getString(String name)
@@ -156,37 +156,48 @@ public int getInteger(String name)
@SuppressWarnings("unchecked")
public Object get(String nodeName)
{
if (nodeName.contains("."))
Object result = null;

if(config.containsKey(nodeName))
{
final String[] nodes = nodeName.split("\\.");
Object currentNode = null;

for (final String node : nodes)
result = config.get(nodeName);
}
else
{
if (nodeName.contains("."))
{
if (currentNode == null)
{
currentNode = config.get(node);
}
else
final String[] nodes = nodeName.split("\\.");
Object currentNode = null;

for (final String node : nodes)
{
if (currentNode instanceof Map)
if (currentNode == null)
{
currentNode = ((Map<String, Object>) currentNode)
.get(node);
currentNode = config.get(node);
}
else
{
break;
if (currentNode instanceof Map)
{
currentNode = ((Map<String, Object>) currentNode)
.get(node);
}
else
{
break;
}
}
}

result = currentNode;
}
else
{
result = config.get(nodeName);
}

return currentNode;
}
else
{
return config.get(nodeName.toLowerCase());
}

return result;
}

public Map<String, Object> getConfig()
@@ -28,7 +28,7 @@ public LocalString(LauncherFrame launcherFrame, List<String> langs)
load(Utils.getResourceAsStream("lang/" + lang + ".yml")));
}

lang = Locale.getDefault().toString();
lang = Locale.getDefault().toString(); //Ici on choppe la langue du système. Si on un fichier de langue qui correspond, on le prend. Sinon on laisse à en_US

if (strings.get(lang) == null)
{
@@ -10,19 +10,19 @@
import java.util.logging.Logger;

import com.kokakiwi.mclauncher.utils.java.SystemUtils;
import com.kokakiwi.mclauncher.utils.java.SystemUtils.OS;
import com.kokakiwi.mclauncher.utils.java.Utils;

public class MCLogger
{
private static Configuration config;

// private static Logger global = Logger.getGlobal();
private static Logger logger = Logger.getLogger("MCLauncher");
private static String logDir = Utils.getWorkingDirectory("minecraft", null).getAbsolutePath() + "/";

static
{
try
{
final FileHandler fh = new FileHandler("mclauncher.log");
final FileHandler fh = new FileHandler(logDir + "mclauncher.log");
fh.setFormatter(new MCFormatter());
final ConsoleHandler ch = new ConsoleHandler();
ch.setFormatter(new MCFormatter());
@@ -54,43 +54,46 @@ public static void error(String message)

public static void debug(String message)
{
if (System.getenv("debugMode") != null
|| config.getBoolean("launcher.debugMode"))
{
logger.log(new Debug(), message);
}
logger.log(new Debug(), message);
}

public static void printSystemInfos()
{
Map<String, String> infos = new HashMap<String, String>();
infos.put("OS Name", System.getProperty("os.name") + " (" + SystemUtils.getSystemOS().getName() + ")");
infos.put("OS Arch", System.getProperty("os.arch") + " (" + SystemUtils.getSystemArch() + ")");
final OS os = SystemUtils.getSystemOS();

final Map<String, String> infos = new HashMap<String, String>();
infos.put("OS Name", System.getProperty("os.name") + " ("
+ SystemUtils.getSystemOS().getName() + ")");
infos.put(
"OS Arch",
System.getProperty("os.arch") + " ("
+ SystemUtils.getSystemArch() + ")");
infos.put("Java version", System.getProperty("java.version"));
infos.put("Java API Version", System.getProperty("java.class.version"));
infos.put("Launcher path", SystemUtils.getExecDirectoryPath());
infos.put("LogFile and profiles directory", logDir);

final StringBuffer sb = new StringBuffer();
sb.append("System informations:");
sb.append(System.lineSeparator());
for(String key : infos.keySet())
sb.append(os.getLineSeparator());
for (final String key : infos.keySet())
{
String value = infos.get(key);
final String value = infos.get(key);
sb.append("\t");
sb.append(key);
sb.append(" : ");
sb.append(value);
sb.append(System.lineSeparator());
sb.append(os.getLineSeparator());
}

debug(sb.toString());
}

public static void setConfig(Configuration config)
public static String getLogDir()
{
MCLogger.config = config;
return logDir;
}

public static class MCFormatter extends Formatter
{

@@ -5,7 +5,8 @@

import com.kokakiwi.mclauncher.LauncherFrame;

public class ProfileListModel implements ListModel<Object>
@SuppressWarnings("rawtypes")
public class ProfileListModel implements ListModel
{
private final LauncherFrame launcherFrame;

@@ -9,22 +9,27 @@

public class ProfileManager
{
private final Map<String, Profile> profiles = new HashMap<String, Profile>();
private String currentProfile = "default";
private final Map<String, Profile> profiles = new HashMap<String, Profile>();
private String currentProfile = "default";
private final String profilesParentDir = Utils.getWorkingDirectory("minecraft", null).getAbsolutePath() + "/"; //On règle le launcher pour qu'il aille chercher les profils

public ProfileManager()
{
final File defaultProfileDir = new File("profiles/default");
MCLogger.debug("Load profiles");
final File defaultProfileDir = new File(profilesParentDir
+ "profiles/default");
if (!defaultProfileDir.exists())
{
MCLogger.debug("Create default profile");
defaultProfileDir.mkdirs();
createProfile("Default");
}

final File profilesDir = new File("profiles");
final File profilesDir = new File(profilesParentDir + "profiles");
final String[] profDir = profilesDir.list();
for (final String dir : profDir)
{
MCLogger.info("Load profile with ID '" + dir + "'");
final File profileDir = new File(profilesDir, dir);
if (profileDir.isDirectory())
{
@@ -61,19 +66,19 @@ public void deleteProfile(Profile profile)

public void deleteProfile(String id)
{
File profileDir = new File("profiles/" + id);
final File profileDir = new File(profilesParentDir + "profiles/" + id);
deleteDirectory(profileDir);
profiles.remove(id);
}

public void deleteDirectory(File dir)
{
if(dir.isDirectory())
if (dir.isDirectory())
{
for(String sub : dir.list())
for (final String sub : dir.list())
{
File subElement = new File(dir, sub);
if(subElement.isDirectory())
final File subElement = new File(dir, sub);
if (subElement.isDirectory())
{
deleteDirectory(subElement);
}
@@ -140,7 +145,8 @@ public Profile(String name)
this.name = name;
id = name.toLowerCase().trim();
loadConfig();
final File descFile = new File("profiles/" + id + "/profile.yml");
final File descFile = new File(profilesParentDir + "profiles/" + id
+ "/profile.yml");
if (!descFile.exists())
{
try
@@ -160,7 +166,8 @@ public Profile(String name)
public void loadConfig()
{
config.load(Utils.getResourceAsStream("config/config.yml"), "yaml");
final File confFile = new File("profiles/" + id + "/config.yml");
final File confFile = new File(profilesParentDir + "profiles/" + id
+ "/config.yml");
if (!confFile.exists())
{
try
@@ -173,7 +180,11 @@ public void loadConfig()
MCLogger.info(e.getLocalizedMessage());
}
}
config.load(confFile);

if(System.getenv("debugMode") == null)
{
config.load(confFile);
}
}

public void initDescriptor()
@@ -184,14 +195,16 @@ public void initDescriptor()

public void save() throws Exception
{
final File confFile = new File("profiles/" + id + "/config.yml");
final File confFile = new File(profilesParentDir + "profiles/" + id
+ "/config.yml");
config.save(confFile);
saveDescriptor();
}

public void saveDescriptor() throws Exception
{
final File descFile = new File("profiles/" + id + "/profile.yml");
final File descFile = new File(profilesParentDir + "profiles/" + id
+ "/profile.yml");
descriptor.save(descFile);
}

@@ -66,20 +66,28 @@ public static String getExecDirectoryPath()

public enum OS
{
windows("Windows", "win"), linux("Linux", "linux"), macosx("Mac OS",
"mac"), solaris("Solaris", "sunos", "solaris"), unknown;
windows("Windows", "\r\n", "win"), linux("Linux", "\n", "linux"), macosx(
"Mac OS", "\n", "mac"), solaris("Solaris", "\n", "sunos",
"solaris"), unknown;

private final String name;
private final String[] labels;
private final String lineSeparator;

OS()
{
this("Unknown");
}

OS(String name, String... strings)
OS(String name)
{
this(name, "\n");
}

OS(String name, String lineSeparator, String... strings)
{
this.name = name;
this.lineSeparator = lineSeparator;
labels = strings;
}

@@ -88,6 +96,11 @@ public String getName()
return name;
}

public String getLineSeparator()
{
return lineSeparator;
}

public static OS getOSFromString(String name)
{
for (final OS os : values())
@@ -45,7 +45,7 @@ public static File getWorkingDirectory(String applicationName, String local)

final String userHome = System.getProperty("user.home", ".");
File workingDirectory;
switch (Utils.OS.values()[getPlatform().ordinal()])
switch (SystemUtils.OS.values()[SystemUtils.getSystemOS().ordinal()])
{
case linux:
case solaris:
@@ -65,7 +65,7 @@ public static File getWorkingDirectory(String applicationName, String local)
'.' + applicationName + '/');
}
break;
case macos:
case macosx:
workingDirectory = new File(userHome,
"Library/Application Support/" + applicationName);
break;
@@ -204,39 +204,4 @@ public static void openLink(URI uri)
System.out.println("Failed to open link " + uri.toString());
}
}

public static OS getPlatform()
{
final String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("win"))
{
return OS.windows;
}
if (osName.contains("mac"))
{
return OS.macos;
}
if (osName.contains("solaris"))
{
return OS.solaris;
}
if (osName.contains("sunos"))
{
return OS.solaris;
}
if (osName.contains("linux"))
{
return OS.linux;
}
if (osName.contains("unix"))
{
return OS.linux;
}
return OS.unknown;
}

public static enum OS
{
linux, solaris, windows, macos, unknown;
}
}
@@ -1,7 +1,9 @@
launcher:
windowTitle: 'Minecraft Launcher'
browserHomeURL: 'http://mcupdate.tumblr.com/'
loginURL: 'https://login.minecraft.net/'
loginURLHTTP: 'https://login.minecraft.net/'
loginURLHTTPS: 'https://login.minecraft.net/'
httpsMode: true
loginParameters: 'user={USERNAME}&password={PASSWORD}&version=13'
offlineMode: false
langs:
@@ -19,6 +19,14 @@ options:
gameLocationLabel: "Game location on disk"
profiles: "Profiles"
done: "Done"
offlineMode: "Offline Mode"
onlineMode: "Online Mode"
httpMode: "HTTP Login"
httpsMode: "HTTPS Login"
profiles:
add: "Add"
edit: "Edit"
remove: "Remove"
updater:
retrieving: "Retrieving"
extracting: "Extracting"
@@ -5,7 +5,7 @@ launcher:
loadBrowser: "Chargement de la page des mises a jour"
login:
rememberBox: "Se souvenir du mot de passe"
launchButton: "Login"
launchButton: "Connexion"
optionsButton: "Options"
retryButton: "Re-essayer"
offlineButton: "Jouer hors-ligne"
@@ -19,6 +19,14 @@ options:
gameLocationLabel: "Repertoire d'installation"
profiles : "Profils"
done: "Fini"
offlineMode: "Mode Hors-Ligne"
onlineMode: "Mode En-Ligne"
httpMode: "Connexion par HTTP"
httpsMode: "Connexion par HTTPS"
profiles:
add: "Ajouter"
edit: "Editer"
remove: "Supprimer"
updater:
retrieving: "Telecharge"
extracting: "Extrait"