diff --git a/.gitignore b/.gitignore
index a9da931..a631af5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
/bin
-/build
\ No newline at end of file
+/build
+/.idea
+*.iml
\ No newline at end of file
diff --git a/.idea/dictionaries/kieron.xml b/.idea/dictionaries/kieron.xml
new file mode 100644
index 0000000..5fa1ad4
--- /dev/null
+++ b/.idea/dictionaries/kieron.xml
@@ -0,0 +1,7 @@
+
+
+
+ mozilla
+
+
+
\ No newline at end of file
diff --git a/src/net/soartex/texture_patcher/Texture_Patcher.java b/src/net/soartex/texture_patcher/Texture_Patcher.java
index 94b954a..a8b71c6 100644
--- a/src/net/soartex/texture_patcher/Texture_Patcher.java
+++ b/src/net/soartex/texture_patcher/Texture_Patcher.java
@@ -6,11 +6,8 @@
import java.awt.Insets;
import java.awt.Toolkit;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
+import java.awt.image.BufferedImage;
+import java.io.*;
import java.net.URL;
import java.net.URLConnection;
@@ -51,15 +48,14 @@
* Texture_Patcher main class.
*
* @author REDX36
- * @version 1.1
+ * @version 2.3
*
*/
public final class Texture_Patcher implements Runnable {
// Program variables.
-
- protected final static float VERSION = 1.2F;
- protected static boolean debug = false;
+ protected final static float VERSION = 2.3F;
+ protected static boolean debug = true;
protected final Preferences prefsnode = Preferences.userNodeForPackage(getClass());
protected final Logger logger = Logger.getLogger(getClass().getName() + "." + System.currentTimeMillis());
@@ -74,7 +70,6 @@ public final class Texture_Patcher implements Runnable {
protected Object[][] tableData;
// Swing objects.
-
protected JFrame frame;
protected JFrame loadingFrame;
@@ -94,82 +89,57 @@ public final class Texture_Patcher implements Runnable {
public static void main (final String[] args) {
// Set certain properties specific to Mac OSX Cocoa.
-
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Texture-Patcher v." + VERSION);
- // Check if the patcher is being run in debug mode.
-
- debug = Boolean.parseBoolean(args.length > 0 ? args[0] : "");
-
// Start the patcher in its own thread.
-
new Thread(new Texture_Patcher()).start();
}
@Override public void run () {
-
- try {
+ try {
// Set the native look ad feel for before the skin in the config is loaded.
-
try {
-
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
-
- } catch (final Exception e1) {
-
+ } catch (final Exception e1) {
e1.printStackTrace();
-
}
// Initialize the logger.
-
initializeLogger();
// Load the branch configuration.
-
String url = loadModBranch();
// Load the configuration.
-
loadConfig(url);
// Initialize the window.
-
initializeWindow();
// Load the files.
-
loadFiles();
// Initialize the components.
-
initializeComponents();
// Open the window.
-
frame.setVisible(true);
// Check for updates.
-
checkUpdate();
} catch (final Texture_Patcher_Exception e) {
// Happens in the event of a caught but fatal error.
-
logger.log(Level.SEVERE, e.getMessage());
if (e.getType() != ErrorType.WINDOW_CLOSED) {
-
e.printStackTrace();
-
e.showDialog("Error!", JOptionPane.ERROR_MESSAGE);
-
createCrashLog();
-
}
if (frame != null) frame.dispose();
@@ -178,30 +148,20 @@ public static void main (final String[] args) {
} catch (final Throwable t) {
// Happens in the event of an uncaught error.
-
final Texture_Patcher_Exception t_p_e = new Texture_Patcher_Exception(this, ErrorType.UNEXPECTED_EXCEPTION, t);
-
logger.log(Level.SEVERE, t_p_e.getMessage());
-
t_p_e.printStackTrace();
-
t_p_e.showDialog("Error!", JOptionPane.ERROR_MESSAGE);
-
if (frame != null) frame.dispose();
if (loadingFrame != null) loadingFrame.dispose();
-
createCrashLog();
-
}
-
}
// Protected methods.
-
protected void initializeLogger () {
- // Initialize the logger with the custom handlers and formatters.
-
+ // Initialize the logger with the custom handlers and formatter.
logger.setLevel(Level.INFO);
final Logging.LoggingHandler handler = new Logging.LoggingHandler(this);
@@ -238,7 +198,11 @@ else if (!debug) {
}
// Loads the JSON file for branch
- config = (JSONObject) new JSONParser().parse(new InputStreamReader(new URL(readLine2).openStream()));
+ URLConnection connection = new URL(readLine2).openConnection();
+ connection.setRequestProperty("User-Agent","Mozilla/5.0 ( compatible ) ");
+ connection.setRequestProperty("Accept","*/*");
+ config = (JSONObject) new JSONParser().parse(new InputStreamReader(connection.getInputStream()));
+
branches = (JSONObject) config.get("branches");
// If branch file does not have branches default
@@ -286,17 +250,14 @@ else if (!debug) {
return branchUrl.get(selectedBranch)[1];
// Determine errors.
-
} catch (final Texture_Patcher_Exception e) {
// Happens for TPE's thrown in the method body for if statements.
-
throw e;
} catch (final Exception e) {
// Happens for all other errors.
-
throw new Texture_Patcher_Exception(this, ErrorType.CONFIG_LOADING_FAILED, e);
}
@@ -304,166 +265,106 @@ else if (!debug) {
@SuppressWarnings("unchecked")
protected void loadConfig (final String branch) throws Texture_Patcher_Exception {
-
try {
-
String readLine = branch;
// Checks if the externalconfig.txt is the default.
-
if (readLine.startsWith("#")) {
-
throw new Texture_Patcher_Exception(this, ErrorType.EXTERNAL_CONFIG_DEFAULT, null);
-
}
// Loads the JSON file.
-
- config = (JSONObject) new JSONParser().parse(new InputStreamReader(new URL(readLine).openStream()));
-
+ URLConnection connection = new URL(readLine).openConnection();
+ connection.setRequestProperty("User-Agent","Mozilla/5.0 ( compatible ) ");
+ connection.setRequestProperty("Accept","*/*");
+ config = (JSONObject) new JSONParser().parse(new InputStreamReader(connection.getInputStream()));
options = (JSONObject) config.get("options");
mods = (JSONObject) config.get("mods");
modpacks = (JSONObject) config.get("modpacks");
// Checks if the root or zips URLs are missing.
-
if (options.get("zipsurl") == null) {
-
throw new Texture_Patcher_Exception(this, ErrorType.CONFIG_INCOMPLETE, null);
-
}
-
if (options.get("name") == null) options.put("name", "Texture Patcher");
-
// Determine errors.
-
} catch (final Texture_Patcher_Exception e) {
-
// Happens for TPE's thrown in the method body for if statements.
-
throw e;
-
} catch (final Exception e) {
-
// Happens for all other errors.
-
throw new Texture_Patcher_Exception(this, ErrorType.CONFIG_LOADING_FAILED, e);
-
}
-
}
protected void initializeWindow () throws Texture_Patcher_Exception {
-
// Set the skin from the configuration.
-
try {
-
if ((String) options.get("skin") != null) {
-
if (options.get("skin").equals("native")) {
-
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
-
} else {
-
for (final LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
-
if (info.getName().equalsIgnoreCase((String) options.get("skin"))) {
-
UIManager.setLookAndFeel(info.getClassName());
-
break;
-
}
-
}
-
}
-
}
-
} catch (final Exception e) {
-
// Happens if the skin cannot be found, or if an error occurs while setting it.
-
final Texture_Patcher_Exception t_p_e = new Texture_Patcher_Exception(this, ErrorType.SKIN_SETTING_FAILED, e);
-
logger.log(Level.WARNING, t_p_e.getMessage());
-
t_p_e.printStackTrace();
-
t_p_e.showDialog("Warning!", JOptionPane.WARNING_MESSAGE);
-
}
-
try {
-
// Configure the frame.
-
frame = new JFrame((String) options.get("name") + (options.get("name").equals("Texture Patcher") ? " v." : " Patcher v." ) + VERSION);
frame.setLayout(new GridBagLayout());
-
frame.setSize(prefsnode.getInt("width", 500), prefsnode.getInt("height", 600));
-
if (prefsnode.getInt("x", -1000) != -1000 && prefsnode.getInt("y", -1000) != -1000) {
-
frame.setLocation(prefsnode.getInt("x", 50), prefsnode.getInt("y", 50));
-
} else {
-
frame.setLocationRelativeTo(null);
-
}
-
frame.setExtendedState(prefsnode.getInt("max", Frame.NORMAL));
-
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new Listeners.ExitListener(this));
-
} catch (final Exception e) {
-
// Happens if an error occurs while initializing the window.
-
throw new Texture_Patcher_Exception(this, ErrorType.WINDOW_INITIALIZATION_FAILED, e);
-
}
// Load the frame icon.
-
try {
-
- final URL iconurl = new URL(options.get("iconurl") == null ? "http://soartex.net/texture-patcher/icon.png" : (String) options.get("iconurl"));
-
- frame.setIconImage(Toolkit.getDefaultToolkit().createImage(iconurl));
-
+ URLConnection connection = new URL(options.get("iconurl") == null ? "http://soartex.net/texture-patcher/data/icon.png" : (String) options.get("iconurl")).openConnection();
+ connection.setRequestProperty("User-Agent","Mozilla/5.0 ( compatible ) ");
+ connection.setRequestProperty("Accept","*/*");
+ BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
+ ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
+ int c;
+ while ((c = in.read()) != -1) {
+ byteArrayOut.write(c);
+ }
+ frame.setIconImage(Toolkit.getDefaultToolkit().createImage(byteArrayOut.toByteArray()));
} catch (final Exception e) {
-
// Happens if an error occurs while setting the icon.
-
final Texture_Patcher_Exception t_p_e = new Texture_Patcher_Exception(this, ErrorType.ICON_SETTING_FAILED, e);
-
logger.log(Level.WARNING, t_p_e.getMessage());
-
t_p_e.printStackTrace();
-
t_p_e.showDialog("Warning!", JOptionPane.WARNING_MESSAGE);
-
}
}
protected void loadFiles () throws Texture_Patcher_Exception {
-
try {
-
// Initialize the loading dialog.
-
loadingFrame = new JFrame("Loading files...");
loadingFrame.setLayout(new GridBagLayout());
-
final Insets insets = new Insets(2, 2, 1, 2);
-
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
@@ -476,12 +377,9 @@ protected void loadFiles () throws Texture_Patcher_Exception {
gbc.insets = insets;
// Initialize the progress bar.
-
final JProgressBar progress = new JProgressBar(SwingConstants.HORIZONTAL);
-
progress.setIndeterminate(true);
loadingFrame.add(progress, gbc);
-
gbc = new GridBagConstraints();
gbc.gridx = 0;
@@ -494,10 +392,8 @@ protected void loadFiles () throws Texture_Patcher_Exception {
gbc.insets = insets;
// Initialize the static message label.
-
final JLabel label = new JLabel("Please wait patiently while we load your files...", SwingConstants.CENTER);
loadingFrame.add(label, gbc);
-
gbc = new GridBagConstraints();
gbc.gridx = 0;
@@ -510,10 +406,8 @@ protected void loadFiles () throws Texture_Patcher_Exception {
gbc.insets = insets;
// Initialize the loading mod number label.
-
final JLabel message = new JLabel("--", SwingConstants.CENTER);
loadingFrame.add(message, gbc);
-
gbc = new GridBagConstraints();
gbc.gridx = 0;
@@ -526,228 +420,131 @@ protected void loadFiles () throws Texture_Patcher_Exception {
gbc.insets = insets;
// Initialize the the loading mod name label.
-
final JLabel name = new JLabel("--", SwingConstants.CENTER);
loadingFrame.add(name,gbc);
-
loadingFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
loadingFrame.addWindowListener(new Listeners.ExitListener(this));
-
loadingFrame.setIconImage(frame.getIconImage());
-
loadingFrame.pack();
loadingFrame.setResizable(false);
-
loadingFrame.setLocationRelativeTo(null);
loadingFrame.setVisible(true);
// Load the mods from the config file.
-
tableData = loadMods(message, name);
-
// Happens in the window is closed.
-
if (!loadingFrame.isVisible()) throw new Texture_Patcher_Exception(this, ErrorType.WINDOW_CLOSED, null);
-
// Load the modpacks from the config file.
-
loadModpacks(message, name);
-
// Happens in the window is closed.
-
if (!loadingFrame.isVisible()) throw new Texture_Patcher_Exception(this, ErrorType.WINDOW_CLOSED, null);
-
// Return to the frame.
-
loadingFrame.dispose();
-
frame.requestFocus();
-
} catch (final Texture_Patcher_Exception e) {
-
// Happens for TPE's thrown during mod loading or modpack loading.
-
throw e;
-
} catch (final Exception e) {
-
// Happens if an error occurs while loading the mods.
-
throw new Texture_Patcher_Exception(this, ErrorType.FILE_LOADING_FAILED, e);
-
}
-
}
protected Object[][] loadMods (final JLabel message, final JLabel title) throws Texture_Patcher_Exception {
-
try {
-
// Stores each row as an array of the column values.
-
final ArrayList