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 {
implementation group: 'net.lingala.zip4j', name: 'zip4j', version: '2.11.5'
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'
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");
if (fscript.exists()) {
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()) {

View File

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

View File

@ -453,31 +453,31 @@ public class Suggs implements ActionListener, ListSelectionListener {
oArtistLine = "";
}
int i2 = 0;
while (i2 < 17 /*17 languages*/) {
while (i2 < 15 /*17 languages*/) {
String language = "INTERNAL_ERROR";
switch (i2) {
case 0: language = "american"; break;
case 1: language = "danish"; break;
case 2: language = "dutch"; break;
case 3: language = "english"; break;
case 4: language = "finnish"; break;
case 5: language = "french"; break;
case 6: language = "german"; break;
case 7: language = "italian"; break;
case 8: language = "japanese"; break;
case 9: language = "korean"; break;
case 10: language = "norwegian"; break;
case 11: language = "polish"; break;
case 12: language = "portuguese"; break;
case 13: language = "russian"; break;
case 14: language = "spanish"; break;
case 15: language = "swedish"; break;
case 16: language = "traditionalchinese"; break;
default:
case 0 -> language = "american";
case 1 -> language = "danish";
case 2 -> language = "dutch";
case 3 -> language = "english";
case 4 -> language = "finnish";
case 5 -> language = "french";
case 6 -> language = "german";
case 7 -> language = "italian";
case 8 -> language = "japanese";
case 9 -> language = "norwegian";
case 10 -> language = "polish";
case 11 -> language = "portuguese";
case 12 -> language = "russian";
case 13 -> language = "spanish";
case 14 -> language = "swedish";
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);
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("\"", "\\\"")+"\"");
i2++;
}
@ -596,7 +596,7 @@ public class Suggs implements ActionListener, ListSelectionListener {
progressDialog.destroyDialog();
frame.dispose();
//Main.deleteDir(new File(Main.inpath + "temp/ffmpeg/"));
Main.deleteDir(new File(Main.inpath + "temp/ffmpeg/"));
Clifford saveDialog = new Clifford();
saveDialog.isSoundtrack = true;
saveDialog.Action(frame, new File(Main.inpath + "temp/"));

File diff suppressed because it is too large Load Diff