|
|
|
|
@@ -19,21 +19,28 @@
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
import javax.swing.event.ListSelectionListener;
|
|
|
|
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
import java.io.BufferedWriter;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileWriter;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
import java.nio.file.*;
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
import net.lingala.zip4j.*;
|
|
|
|
|
import net.lingala.zip4j.exception.ZipException;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
import static java.nio.file.StandardCopyOption.*;
|
|
|
|
|
|
|
|
|
|
import static javax.swing.WindowConstants.EXIT_ON_CLOSE;
|
|
|
|
|
|
|
|
|
|
@@ -62,10 +69,12 @@ public class MissPiggy implements ActionListener {
|
|
|
|
|
private JButton deployButton;
|
|
|
|
|
private JTextPane descriptionField;
|
|
|
|
|
|
|
|
|
|
private int selectedItem;
|
|
|
|
|
//private int selectedItem;
|
|
|
|
|
|
|
|
|
|
public String priorityList;
|
|
|
|
|
|
|
|
|
|
public boolean listenersAlreadySet = false; // was written to troubleshoot a bug but this wasn't actually the cause
|
|
|
|
|
|
|
|
|
|
// Initialize the main window
|
|
|
|
|
public void Action(/*Main entryPoint*/) {
|
|
|
|
|
System.out.println("Main window created");
|
|
|
|
|
@@ -111,41 +120,16 @@ public class MissPiggy implements ActionListener {
|
|
|
|
|
toolsMenu.getItem(0).addActionListener(this);
|
|
|
|
|
toolsMenu.getItem(1).addActionListener(this);
|
|
|
|
|
helpMenu.getItem(0).addActionListener(this);
|
|
|
|
|
|
|
|
|
|
deployButton.addActionListener(this);
|
|
|
|
|
importButton.addActionListener(this);
|
|
|
|
|
deleteButton1.addActionListener(this);
|
|
|
|
|
optionsButton.addActionListener(this);
|
|
|
|
|
moveUpButton.addActionListener(this);
|
|
|
|
|
moveDownButton.addActionListener(this);
|
|
|
|
|
toggleButton.addActionListener(this);
|
|
|
|
|
|
|
|
|
|
descriptionField.getDocument().putProperty("filterNewlines", Boolean.FALSE);
|
|
|
|
|
modList.addListSelectionListener(e -> {
|
|
|
|
|
String authorDisplay;
|
|
|
|
|
File pathReference = new File(System.getProperty("user.home") + "/.firestar/mods/" + Main.Mods.get(modList.getSelectedIndex()).path);
|
|
|
|
|
DecimalFormat df = new DecimalFormat("##.##");
|
|
|
|
|
df.setRoundingMode(RoundingMode.UP);
|
|
|
|
|
float modFileSize = pathReference.length(); //precise units
|
|
|
|
|
String modFileSizeStr = String.valueOf(modFileSize);
|
|
|
|
|
String modFileSizeUnits = "bytes"; //todo: don't show decimals for bytes
|
|
|
|
|
if (pathReference.length() >= 1024) {
|
|
|
|
|
modFileSizeStr = String.valueOf(df.format(modFileSize / 1024));
|
|
|
|
|
modFileSizeUnits = "Kilobytes";
|
|
|
|
|
}
|
|
|
|
|
if (pathReference.length() >= 1024 * 1024) {
|
|
|
|
|
modFileSizeStr = String.valueOf(df.format(modFileSize / (1024 * 1024)));
|
|
|
|
|
modFileSizeUnits = "Megabytes";
|
|
|
|
|
}
|
|
|
|
|
if (pathReference.length() >= 1024 * 1024 * 1024) {
|
|
|
|
|
modFileSizeStr = String.valueOf(df.format(modFileSize / (1024 * 1024 * 1024)));
|
|
|
|
|
modFileSizeUnits = "Gigabytes";
|
|
|
|
|
}
|
|
|
|
|
if (Main.Mods.get(modList.getSelectedIndex()).author == null) {
|
|
|
|
|
authorDisplay = "an Unknown Author";
|
|
|
|
|
} else {
|
|
|
|
|
authorDisplay = Main.Mods.get(modList.getSelectedIndex()).author;
|
|
|
|
|
}
|
|
|
|
|
descriptionField.setText(
|
|
|
|
|
"\"" + Main.Mods.get(modList.getSelectedIndex()).friendlyName + "\"\n" +
|
|
|
|
|
"by " + authorDisplay + "\n\n" +
|
|
|
|
|
"Version " + Main.Mods.get(modList.getSelectedIndex()).version + "\n" +
|
|
|
|
|
modFileSizeStr + " " + modFileSizeUnits + " in size" +
|
|
|
|
|
"\n\n" + Main.Mods.get(modList.getSelectedIndex()).description
|
|
|
|
|
);});
|
|
|
|
|
|
|
|
|
|
// display window
|
|
|
|
|
try {
|
|
|
|
|
@@ -194,8 +178,11 @@ public class MissPiggy implements ActionListener {
|
|
|
|
|
Do nothing if the index number is not valid.
|
|
|
|
|
there probably is not a practical reason to do this, but I want to eliminate any undefined behaviors while we're here.
|
|
|
|
|
we'll also eliminate any syntax errors caused by the lack of a = sign
|
|
|
|
|
|
|
|
|
|
06/29/24 - also skip files that were manually removed but remain in the list
|
|
|
|
|
*/
|
|
|
|
|
if (s.split("=")[0].matches("[0-9]+=*")) {
|
|
|
|
|
if (s.split("=")[0].matches("[0-9]+=*") &&
|
|
|
|
|
new File(System.getProperty("user.home") + "/.firestar/mods/" + s.substring(s.indexOf("=") + 1)).exists()) {
|
|
|
|
|
//append mod to list from substring
|
|
|
|
|
Main.Mod m = new Main().new Mod();
|
|
|
|
|
m.path = s.substring(s.indexOf("=") + 1);
|
|
|
|
|
@@ -205,24 +192,27 @@ public class MissPiggy implements ActionListener {
|
|
|
|
|
JSONObject metadata;
|
|
|
|
|
try {
|
|
|
|
|
metadata = new JSONObject(new ZipFile(System.getProperty("user.home") + "/.firestar/mods/" + m.path).getComment());
|
|
|
|
|
} catch (ZipException e) {
|
|
|
|
|
throw new RuntimeException(e); //todo: fault tolerance
|
|
|
|
|
}
|
|
|
|
|
if (metadata.has("friendlyName")) {m.friendlyName = metadata.get("friendlyName").toString();} else {m.friendlyName = m.path;}
|
|
|
|
|
if (metadata.has("description")) {m.description = metadata.get("description").toString();}
|
|
|
|
|
if (metadata.has("version")) {m.version = Integer.parseInt(metadata.get("version").toString());}
|
|
|
|
|
if (metadata.has("author")) {m.author = metadata.get("author").toString();}
|
|
|
|
|
if (metadata.has("loaderversion")) {m.loaderversion = Integer.parseInt(metadata.get("loaderversion").toString());}
|
|
|
|
|
if (metadata.has("game")) {m.game = metadata.get("game").toString();}
|
|
|
|
|
if (metadata.has("friendlyName")) {m.friendlyName = metadata.get("friendlyName").toString();} else {m.friendlyName = m.path;}
|
|
|
|
|
if (metadata.has("description")) {m.description = metadata.get("description").toString();}
|
|
|
|
|
if (metadata.has("version")) {m.version = Integer.parseInt(metadata.get("version").toString());}
|
|
|
|
|
if (metadata.has("author")) {m.author = metadata.get("author").toString();}
|
|
|
|
|
if (metadata.has("loaderversion")) {m.loaderversion = Integer.parseInt(metadata.get("loaderversion").toString());}
|
|
|
|
|
if (metadata.has("game")) {m.game = metadata.get("game").toString();}
|
|
|
|
|
|
|
|
|
|
//send to list
|
|
|
|
|
Main.Mods.add(m);
|
|
|
|
|
//send to list
|
|
|
|
|
Main.Mods.add(m);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.out.println("WARNING: mod entry for " + s + " was found but does not contain valid JSON metadata. skipping");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!s.isEmpty()) {System.out.println("WARNING: mod entry for " + s + " doesn't actually exist. skipping");}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void InitializeModListInGUI() { // i really wanted this to be "lights, camera, action" but the code organizing kept getting stupider and stupider so i gave up
|
|
|
|
|
public void InitializeModListInGUI() {
|
|
|
|
|
// cleanup
|
|
|
|
|
if (listenersAlreadySet) {modList.removeListSelectionListener(modList.getListSelectionListeners()[0]);} // was written to troubleshoot a bug but this wasn't actually the cause
|
|
|
|
|
descriptionField.setText("Select a mod from the list on the right to view more details, or to make changes to your installation.");
|
|
|
|
|
modList.clearSelection();
|
|
|
|
|
modList.removeAll();
|
|
|
|
|
@@ -244,6 +234,7 @@ public class MissPiggy implements ActionListener {
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
modList.setListData(contents);
|
|
|
|
|
createSelectionEventListener();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ListSelectionListener whenItemSelected() {
|
|
|
|
|
@@ -255,9 +246,18 @@ public class MissPiggy implements ActionListener {
|
|
|
|
|
if (actionEvent.getSource() == fileMenu.getItem(5)) {System.exit(0);} else
|
|
|
|
|
if (actionEvent.getSource() == fileMenu.getItem(0)) {deployModGUI();} else
|
|
|
|
|
if (actionEvent.getSource() == deployButton) {deployModGUI();} else
|
|
|
|
|
if (actionEvent.getSource() == importButton) {importModGUI();} else
|
|
|
|
|
if (actionEvent.getSource() == fileMenu.getItem(1)) {importModGUI();} else
|
|
|
|
|
if (actionEvent.getSource() == fileMenu.getItem(2)) {removeAllGUI();} else
|
|
|
|
|
if (actionEvent.getSource() == optionsButton) {optionsGUI();} else
|
|
|
|
|
if (actionEvent.getSource() == fileMenu.getItem(4)) {optionsGUI();} else
|
|
|
|
|
|
|
|
|
|
if (actionEvent.getSource() == moveUpButton) {moveUp(modList.getSelectedIndex());} else
|
|
|
|
|
if (actionEvent.getSource() == moveDownButton) {moveDown(modList.getSelectedIndex());} else
|
|
|
|
|
|
|
|
|
|
if (actionEvent.getSource() == toggleButton) {throwUnimplemented();} else // todo
|
|
|
|
|
if (actionEvent.getSource() == deleteButton1) {deleteSelected();} else
|
|
|
|
|
|
|
|
|
|
if (actionEvent.getSource() == helpMenu.getItem(0)) {new Rowlf().displayAboutScreen();}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -279,9 +279,12 @@ public class MissPiggy implements ActionListener {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void importModGUI() {
|
|
|
|
|
// todo call system shell to request file picker
|
|
|
|
|
JFileChooser fileChooser = new JFileChooser();
|
|
|
|
|
fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
|
|
|
|
|
//fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("All", "zip", "agr", "agrc", "agrf", "fstar"));
|
|
|
|
|
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("ZIP Archive", "zip"));
|
|
|
|
|
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Firestar Mod Package", "agr", "agrc", "agrf", "fstar")); //what about fstar?
|
|
|
|
|
|
|
|
|
|
int result = fileChooser.showOpenDialog(frame);
|
|
|
|
|
|
|
|
|
|
if (result == JFileChooser.APPROVE_OPTION) {
|
|
|
|
|
@@ -290,31 +293,172 @@ public class MissPiggy implements ActionListener {
|
|
|
|
|
|
|
|
|
|
ZipFile zipImporterHandler = new ZipFile(selectedFile.getPath());
|
|
|
|
|
if (zipImporterHandler.isValidZipFile()) {
|
|
|
|
|
try {
|
|
|
|
|
Path importDestination = Paths.get(System.getProperty("user.home") + "/.firestar/mods/"
|
|
|
|
|
+ selectedFile.getName() + "_" + Main.Mods.size() + ".zip");
|
|
|
|
|
Files.copy(Paths.get(selectedFile.getPath()), importDestination, StandardCopyOption.REPLACE_EXISTING);
|
|
|
|
|
String importDestinationName = importDestination.toFile().getName();
|
|
|
|
|
|
|
|
|
|
BufferedWriter bw = new BufferedWriter(new FileWriter(System.getProperty("user.home") + "/.firestar/mods/index", true));
|
|
|
|
|
bw.write(Main.Mods.size() + "=" + importDestinationName);
|
|
|
|
|
bw.newLine();
|
|
|
|
|
bw.close();
|
|
|
|
|
|
|
|
|
|
InitializeModListStructure();
|
|
|
|
|
InitializeModListInGUI();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.out.println(e.getMessage());
|
|
|
|
|
JOptionPane.showMessageDialog(frame, "An error has occured.\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("ERROR: File is not a valid ZIP archive. Aborting.");
|
|
|
|
|
JOptionPane.showMessageDialog(frame, "Whoops, that's not a valid ZIP archive.\nMod files should be in .zip, .agr, .agrc or .agrf.", "Error", JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
JOptionPane.showMessageDialog(frame, "Whoops, that's not a valid ZIP archive.", "Error", JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removeAllGUI() {
|
|
|
|
|
// todo warning dialog that nukes list when Yes is clicked
|
|
|
|
|
int result = JOptionPane.showConfirmDialog(frame, "Do you really want to delete all mods?", "Remove All", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
|
|
|
|
|
|
|
|
|
|
if (result == JOptionPane.YES_OPTION) {
|
|
|
|
|
for (Main.Mod entry : Main.Mods) {
|
|
|
|
|
new File(System.getProperty("user.home") + "/.firestar/mods/" + entry.path).delete();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
new File(System.getProperty("user.home") + "/.firestar/mods/index").delete();
|
|
|
|
|
Main.Mods.clear();
|
|
|
|
|
|
|
|
|
|
InitializeModListStructure();
|
|
|
|
|
InitializeModListInGUI();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void optionsGUI() {
|
|
|
|
|
// todo settings page w/ reset switch
|
|
|
|
|
throwUnimplemented();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void deleteSelected() {
|
|
|
|
|
File file = new File(System.getProperty("user.home") + "/.firestar/mods/" + Main.Mods.get(modList.getSelectedIndex()).path);
|
|
|
|
|
file.delete();
|
|
|
|
|
System.out.println("Deleted " + Main.Mods.get(modList.getSelectedIndex()).friendlyName); //debug
|
|
|
|
|
Main.Mods.remove(modList.getSelectedIndex());
|
|
|
|
|
regenerateModIndex(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void generatorGUI() {
|
|
|
|
|
// todo mod packer
|
|
|
|
|
throwUnimplemented();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void metaEditorGUI() {
|
|
|
|
|
// todo tag editor
|
|
|
|
|
throwUnimplemented();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void aboutGUI() {
|
|
|
|
|
// todo about page
|
|
|
|
|
private void moveUp(int index) {
|
|
|
|
|
if (index > 0) {
|
|
|
|
|
Collections.swap(Main.Mods, index, index - 1);
|
|
|
|
|
System.out.println("Items moved, redeploying list");
|
|
|
|
|
InitializeModListInGUI();
|
|
|
|
|
regenerateModIndex(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void moveDown(int index) {
|
|
|
|
|
if (index < (Main.Mods.size() - 1)) {
|
|
|
|
|
Collections.swap(Main.Mods, index, index + 1);
|
|
|
|
|
System.out.println("Items moved, redeploying list");
|
|
|
|
|
InitializeModListInGUI();
|
|
|
|
|
regenerateModIndex(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void throwUnimplemented() {
|
|
|
|
|
JOptionPane.showMessageDialog(frame, "Unimplemented.\nSee README at https://git.worlio.com/bonkmaykr/firestar", "Unimplemented", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void createSelectionEventListener() { // moved incase needs to be removed and re-added
|
|
|
|
|
listenersAlreadySet = true; // was written to troubleshoot a bug but this wasn't actually the cause
|
|
|
|
|
modList.addListSelectionListener(e -> {
|
|
|
|
|
if (modList.getSelectedIndex() >= 0 && modList.getModel().getSize() >= 1) { // avoid race OOB when reinitializing mod list
|
|
|
|
|
String authorDisplay;
|
|
|
|
|
|
|
|
|
|
try { //debug
|
|
|
|
|
|
|
|
|
|
File pathReference = new File(System.getProperty("user.home") + "/.firestar/mods/" + Main.Mods.get(modList.getSelectedIndex()).path);
|
|
|
|
|
DecimalFormat df = new DecimalFormat("##.##");
|
|
|
|
|
df.setRoundingMode(RoundingMode.UP);
|
|
|
|
|
float modFileSize = pathReference.length(); //precise units
|
|
|
|
|
String modFileSizeStr = String.valueOf(modFileSize);
|
|
|
|
|
String modFileSizeUnits = "bytes"; //todo: don't show decimals for bytes
|
|
|
|
|
if (pathReference.length() >= 1024) {
|
|
|
|
|
modFileSizeStr = String.valueOf(df.format(modFileSize / 1024));
|
|
|
|
|
modFileSizeUnits = "Kilobytes";
|
|
|
|
|
}
|
|
|
|
|
if (pathReference.length() >= 1024 * 1024) {
|
|
|
|
|
modFileSizeStr = String.valueOf(df.format(modFileSize / (1024 * 1024)));
|
|
|
|
|
modFileSizeUnits = "Megabytes";
|
|
|
|
|
}
|
|
|
|
|
if (pathReference.length() >= 1024 * 1024 * 1024) {
|
|
|
|
|
modFileSizeStr = String.valueOf(df.format(modFileSize / (1024 * 1024 * 1024)));
|
|
|
|
|
modFileSizeUnits = "Gigabytes";
|
|
|
|
|
}
|
|
|
|
|
if (Main.Mods.get(modList.getSelectedIndex()).author == null) {
|
|
|
|
|
authorDisplay = "an Unknown Author";
|
|
|
|
|
} else {
|
|
|
|
|
authorDisplay = Main.Mods.get(modList.getSelectedIndex()).author;
|
|
|
|
|
}
|
|
|
|
|
descriptionField.setText(
|
|
|
|
|
"\"" + Main.Mods.get(modList.getSelectedIndex()).friendlyName + "\"\n" +
|
|
|
|
|
"by " + authorDisplay + "\n\n" +
|
|
|
|
|
"Version " + Main.Mods.get(modList.getSelectedIndex()).version + "\n" +
|
|
|
|
|
modFileSizeStr + " " + modFileSizeUnits + " in size" +
|
|
|
|
|
"\n\n" + Main.Mods.get(modList.getSelectedIndex()).description
|
|
|
|
|
);}
|
|
|
|
|
|
|
|
|
|
catch (IndexOutOfBoundsException ex) {
|
|
|
|
|
System.out.println(ex.getMessage());
|
|
|
|
|
System.out.println("mods " + Main.Mods.size());
|
|
|
|
|
System.out.println("mod display " + modList.getModel().getSize());
|
|
|
|
|
System.out.println("selection index " + modList.getSelectedIndex());
|
|
|
|
|
|
|
|
|
|
int result = JOptionPane.showConfirmDialog(frame, "Firestar encountered an internal error.\n" + ex.getMessage(), "Fatal Error", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
if (result == JOptionPane.OK_OPTION) {System.exit(1);} //user safety
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void regenerateModIndex(boolean reload) {
|
|
|
|
|
try {
|
|
|
|
|
System.out.println("Regenerating index..."); //debug
|
|
|
|
|
|
|
|
|
|
new File(System.getProperty("user.home") + "/.firestar/mods/index").delete();
|
|
|
|
|
File priorityListFileHandle = new File(System.getProperty("user.home") + "/.firestar/mods/index");
|
|
|
|
|
priorityListFileHandle.createNewFile();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BufferedWriter bw = new BufferedWriter(new FileWriter(System.getProperty("user.home") + "/.firestar/mods/index", true));
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (Main.Mod m : Main.Mods) {
|
|
|
|
|
bw.write(i + "=" + m.path);
|
|
|
|
|
bw.newLine();
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
bw.close();
|
|
|
|
|
|
|
|
|
|
if(reload) {
|
|
|
|
|
Main.Mods.clear(); //cleanup
|
|
|
|
|
priorityList = "";
|
|
|
|
|
InitializeModListStructure();
|
|
|
|
|
InitializeModListInGUI();
|
|
|
|
|
}
|
|
|
|
|
System.out.println("Mod index file regenerated.");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.out.println(e.getMessage());
|
|
|
|
|
JOptionPane.showMessageDialog(frame, "An error has occured.\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|