fix gonzo executing same fscript, remove incomplete korean and chinese translations from being processed by suggs, 'fix' fscript XML new-line processing, add new xml create-at that inserts before index

This commit is contained in:
Wirlaburla 2024-07-22 17:15:18 -05:00
parent a91ba62bf8
commit 6e292212fd
5 changed files with 8755 additions and 137 deletions

View File

@ -17,7 +17,7 @@ configurations {
dependencies { dependencies {
implementation group: 'net.lingala.zip4j', name: 'zip4j', version: '2.11.5' implementation group: 'net.lingala.zip4j', name: 'zip4j', version: '2.11.5'
implementation group: 'org.json', name: 'json', version: '20240303' implementation group: 'org.json', name: 'json', version: '20240303'
implementation "io.github.java-diff-utils:java-diff-utils:4.12" implementation group: 'io.github.java-diff-utils', name: 'java-diff-utils', version: '4.12'
implementation 'com.jetbrains.intellij.java:java-gui-forms-rt:203.7148.30' implementation 'com.jetbrains.intellij.java:java-gui-forms-rt:203.7148.30'
antTask 'com.jetbrains.intellij.java:java-compiler-ant-tasks:203.7148.30' antTask 'com.jetbrains.intellij.java:java-compiler-ant-tasks:203.7148.30'

View File

@ -171,6 +171,7 @@ public class Gonzo {
File fscript = new File(Main.inpath + "temp/fscript"); File fscript = new File(Main.inpath + "temp/fscript");
if (fscript.exists()) { if (fscript.exists()) {
new Rizzo(new FileInputStream(fscript), Main.inpath + "temp/"); // Lets rizz this mod up new Rizzo(new FileInputStream(fscript), Main.inpath + "temp/"); // Lets rizz this mod up
fscript.delete();
} }
if (new File(System.getProperty("user.home") + "/.firestar/temp/delete.txt").isFile()) { if (new File(System.getProperty("user.home") + "/.firestar/temp/delete.txt").isFile()) {

View File

@ -31,6 +31,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.StringWriter; import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -76,9 +77,9 @@ public class Rizzo {
} }
private boolean parseArgs(String[] args, Object context) throws FirescriptFormatException { private boolean parseArgs(String[] args, Object context) throws FirescriptFormatException {
System.out.println("Parsing Command: " + Arrays.toString(args));
if (args.length > 0) { if (args.length > 0) {
if (context == null) { if (context == null) {
System.out.println("Parsing Command: " + Arrays.toString(args));
if (args[0].equalsIgnoreCase("fscript")) { if (args[0].equalsIgnoreCase("fscript")) {
ver = Integer.parseInt(args[1]); // We'll do shit with this later ver = Integer.parseInt(args[1]); // We'll do shit with this later
if (ver > maxVer) throw new FirescriptFormatException(args[0], "script too new"); if (ver > maxVer) throw new FirescriptFormatException(args[0], "script too new");
@ -88,15 +89,15 @@ public class Rizzo {
parseArgs(Arrays.copyOfRange(args, 2, args.length), newCtx); parseArgs(Arrays.copyOfRange(args, 2, args.length), newCtx);
} else throw new FirescriptFormatException("fscript", "unknown command '" + args[0] + "'"); } else throw new FirescriptFormatException("fscript", "unknown command '" + args[0] + "'");
} else { } else {
System.out.println("Parsing Command: " + Arrays.toString(args) + " with context: " + context.getClass().getName() + "@" + context.hashCode()); System.out.println("Using context: " + context.getClass().getName() + "@" + context.hashCode());
if (args[0].equals("{")) { if (args[0].equals("{")) {
System.out.println("New context parse: " + context.getClass().getName() + "@" + context.hashCode()); System.out.println("New context block: " + context.getClass().getName() + "@" + context.hashCode());
parseScript(context); parseScript(context);
} else if (args[0].equals("}")) { } else if (args[0].equals("}")) {
System.out.println("Ending context block: " + context.getClass().getName() + "@" + context.hashCode()); System.out.println("Ending context block: " + context.getClass().getName() + "@" + context.hashCode());
return false; return false;
} else if (context instanceof File file) { } else if (context instanceof File file) {
if (!file.exists()) return true; if (file.exists()) {
if (args[0].equalsIgnoreCase("delete")) { if (args[0].equalsIgnoreCase("delete")) {
System.out.println("Deleting: " + file.getPath()); System.out.println("Deleting: " + file.getPath());
if (file.getAbsolutePath().startsWith(workingDir)) { if (file.getAbsolutePath().startsWith(workingDir)) {
@ -107,10 +108,9 @@ public class Rizzo {
try { try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
// Mmmm, love me some INVALID XML corrections // Mmmm, love me some INVALID XML corrections.
ReplacingInputStream ris = new ReplacingInputStream(new ReplacingInputStream(new FileInputStream(file), "&", "&"), "\n", "
"); ReplacingInputStream ris = new ReplacingInputStream(new ReplacingInputStream(new ReplacingInputStream(new FileInputStream(file), "\r\n", ""), "&", "&"), "\n", "
");
Document doc = docBuilder.parse(ris); Document doc = docBuilder.parse(ris);
Node n = doc.createProcessingInstruction(StreamResult.PI_DISABLE_OUTPUT_ESCAPING, "\n");
parseArgs(Arrays.copyOfRange(args, 1, args.length), doc); parseArgs(Arrays.copyOfRange(args, 1, args.length), doc);
try { try {
FileOutputStream output = new FileOutputStream(file); FileOutputStream output = new FileOutputStream(file);
@ -203,6 +203,7 @@ public class Rizzo {
Logger.getLogger(Rizzo.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(Rizzo.class.getName()).log(Level.SEVERE, null, ex);
} }
} else throw new FirescriptFormatException("file", "unknown command '" + args[0] + "'"); } else throw new FirescriptFormatException("file", "unknown command '" + args[0] + "'");
} else System.out.println("fscript: file context not found, skipping.");
} else if (context instanceof Document document) { } else if (context instanceof Document document) {
if (args[0].equalsIgnoreCase("modify")) { if (args[0].equalsIgnoreCase("modify")) {
Element elem = (Element)traverse(document, args[1]); Element elem = (Element)traverse(document, args[1]);
@ -226,8 +227,7 @@ public class Rizzo {
try { try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
ReplacingInputStream ris = new ReplacingInputStream(new ReplacingInputStream(new ReplacingInputStream(new FileInputStream(new File(workingDir + args[1])), "\r\n", ""), "&", "&"), "\n", "
");
ReplacingInputStream ris = new ReplacingInputStream(new FileInputStream(new File(workingDir + args[1])), "&", "&");
Document outDoc = docBuilder.parse(ris); Document outDoc = docBuilder.parse(ris);
NamedNodeMap nnm = outDoc.getDocumentElement().getAttributes(); NamedNodeMap nnm = outDoc.getDocumentElement().getAttributes();
@ -253,17 +253,44 @@ public class Rizzo {
else if (args[1].equalsIgnoreCase("value")) else if (args[1].equalsIgnoreCase("value"))
element.setNodeValue(args[2]); element.setNodeValue(args[2]);
} else if (args[0].equalsIgnoreCase("create")) { } else if (args[0].equalsIgnoreCase("create")) {
String newTag = args[1].substring(args[1].lastIndexOf(".")+1); String finalTag = args[1];
String newID = ""; String path = "";
if (newTag.contains("#")) { if (finalTag.lastIndexOf(".") > 0) {
newID = newTag.substring(newTag.indexOf("#")+1); path = args[1].substring(0, finalTag.lastIndexOf("."));
newTag = newTag.substring(0, newTag.indexOf("#")); finalTag = args[1].substring(finalTag.lastIndexOf(".")+1);
} }
Element newElem = element.getOwnerDocument().createElement(newTag); String id = "";
if (newID != null && newID.length() > 0) newElem.setAttribute("id", newID); String name = "";
traverse(element, args[1].substring(0, args[1].lastIndexOf("."))).appendChild(newElem); if (finalTag.contains("#")) {
parseArgs(Arrays.copyOfRange(args, 2, args.length), newElem); id = finalTag.substring(finalTag.indexOf("#")+1);
} else throw new FirescriptFormatException(""); finalTag = finalTag.substring(0, finalTag.indexOf("#"));
} else if (finalTag.contains("$")) {
name = finalTag.substring(finalTag.indexOf("$")+1);
finalTag = finalTag.substring(0, finalTag.indexOf("$"));
}
Element finalElem = element.getOwnerDocument().createElement(finalTag);
if (id != null && id.length() > 0) finalElem.setAttribute("id", id);
if (name != null && name.length() > 0) finalElem.setAttribute("name", name);
traverse(element, path).appendChild(finalElem);
parseArgs(Arrays.copyOfRange(args, 2, args.length), finalElem);
} else if (args[0].equalsIgnoreCase("create-at")) {
int index = Integer.parseInt(args[1]);
String finalTag = args[2];
String id = "";
String name = "";
if (finalTag.contains("#")) {
id = finalTag.substring(finalTag.indexOf("#")+1);
finalTag = finalTag.substring(0, finalTag.indexOf("#"));
} else if (finalTag.contains("$")) {
name = finalTag.substring(finalTag.indexOf("$")+1);
finalTag = finalTag.substring(0, finalTag.indexOf("$"));
}
Element finalElem = element.getOwnerDocument().createElement(finalTag);
if (id != null && id.length() > 0) finalElem.setAttribute("id", id);
if (name != null && name.length() > 0) finalElem.setAttribute("name", name);
element.insertBefore(finalElem, element.getChildNodes().item(index));
parseArgs(Arrays.copyOfRange(args, 3, args.length), finalElem);
} else throw new FirescriptFormatException("xml", "unknown element command '" + args[0] + "'");
} else throw new FirescriptFormatException("context is unknown"); } else throw new FirescriptFormatException("context is unknown");
} }
} }
@ -272,7 +299,7 @@ public class Rizzo {
private Node traverse(Node owner, String selector) throws FirescriptFormatException { private Node traverse(Node owner, String selector) throws FirescriptFormatException {
if (selector == null || selector.length() == 0 || owner == null) { if (selector == null || selector.length() == 0 || owner == null) {
return null; return owner;
} }
String[] elems = selector.split("\\."); String[] elems = selector.split("\\.");
Node parent = owner; Node parent = owner;
@ -302,6 +329,7 @@ public class Rizzo {
ns = ((Element)parent).getElementsByTagName(tag); ns = ((Element)parent).getElementsByTagName(tag);
for (int i = 0; i < ns.getLength(); i++) { for (int i = 0; i < ns.getLength(); i++) {
Node n = ns.item(i); Node n = ns.item(i);
if (n.getNodeName().equals("#text")) continue;
if (((Element)n).getAttribute("id").equals(id)) { if (((Element)n).getAttribute("id").equals(id)) {
newParent = (Element)n; newParent = (Element)n;
break; break;
@ -315,6 +343,7 @@ public class Rizzo {
ns = ((Element)parent).getChildNodes(); ns = ((Element)parent).getChildNodes();
for (int i = 0; i < ns.getLength(); i++) { for (int i = 0; i < ns.getLength(); i++) {
Node n = ns.item(i); Node n = ns.item(i);
if (n.getNodeName().equals("#text")) continue;
if (((Element)n).getAttribute("name").equals(name)) { if (((Element)n).getAttribute("name").equals(name)) {
newParent = (Element)n; newParent = (Element)n;
break; break;

View File

@ -453,31 +453,31 @@ public class Suggs implements ActionListener, ListSelectionListener {
oArtistLine = ""; oArtistLine = "";
} }
int i2 = 0; int i2 = 0;
while (i2 < 17 /*17 languages*/) { while (i2 < 15 /*17 languages*/) {
String language = "INTERNAL_ERROR"; String language = "INTERNAL_ERROR";
switch (i2) { switch (i2) {
case 0: language = "american"; break; case 0 -> language = "american";
case 1: language = "danish"; break; case 1 -> language = "danish";
case 2: language = "dutch"; break; case 2 -> language = "dutch";
case 3: language = "english"; break; case 3 -> language = "english";
case 4: language = "finnish"; break; case 4 -> language = "finnish";
case 5: language = "french"; break; case 5 -> language = "french";
case 6: language = "german"; break; case 6 -> language = "german";
case 7: language = "italian"; break; case 7 -> language = "italian";
case 8: language = "japanese"; break; case 8 -> language = "japanese";
case 9: language = "korean"; break; case 9 -> language = "norwegian";
case 10: language = "norwegian"; break; case 10 -> language = "polish";
case 11: language = "polish"; break; case 11 -> language = "portuguese";
case 12: language = "portuguese"; break; case 12 -> language = "russian";
case 13: language = "russian"; break; case 13 -> language = "spanish";
case 14: language = "spanish"; break; case 14 -> language = "swedish";
case 15: language = "swedish"; break; default -> {
case 16: language = "traditionalchinese"; break;
default:
int result = JOptionPane.showConfirmDialog(frame, "Firestar encountered an internal error.\nString 'language' exported to FSCRIPT was blank.", "Fatal Error", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); int result = JOptionPane.showConfirmDialog(frame, "Firestar encountered an internal error.\nString 'language' exported to FSCRIPT was blank.", "Fatal Error", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
if (result == JOptionPane.OK_OPTION) {System.exit(1);} //user safety if (result == JOptionPane.OK_OPTION) {System.exit(1);} //user safety
break;
} }
}
//case 9: language = "korean"; break;
//case 16: language = "traditionalchinese"; break;
ps.println("file \"data/plugins/languages/"+language+"/entries.xml\" xml "+ocmd+" StringTable.entry#MT_"+trackno+" set attribute \"string\" \""+oArtistLine+oTitle.replace("\"", "\\\"")+"\""); ps.println("file \"data/plugins/languages/"+language+"/entries.xml\" xml "+ocmd+" StringTable.entry#MT_"+trackno+" set attribute \"string\" \""+oArtistLine+oTitle.replace("\"", "\\\"")+"\"");
i2++; i2++;
} }
@ -596,7 +596,7 @@ public class Suggs implements ActionListener, ListSelectionListener {
progressDialog.destroyDialog(); progressDialog.destroyDialog();
frame.dispose(); frame.dispose();
//Main.deleteDir(new File(Main.inpath + "temp/ffmpeg/")); Main.deleteDir(new File(Main.inpath + "temp/ffmpeg/"));
Clifford saveDialog = new Clifford(); Clifford saveDialog = new Clifford();
saveDialog.isSoundtrack = true; saveDialog.isSoundtrack = true;
saveDialog.Action(frame, new File(Main.inpath + "temp/")); saveDialog.Action(frame, new File(Main.inpath + "temp/"));

File diff suppressed because it is too large Load Diff