From 9e6e1d936deac5d0d9444b76163d65bb280a50bd Mon Sep 17 00:00:00 2001 From: Zukero Date: Mon, 5 Feb 2018 18:15:18 +0100 Subject: [PATCH] Fixed a bug in loadresources.xml generation. Enhanced custom command handling for desktop tools integration. --- .../rpg/atcontentstudio/model/Project.java | 8 ++-- .../atcontentstudio/model/maps/TMXMapSet.java | 2 +- .../utils/DesktopIntegration.java | 45 ++++++++++++++++++- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/com/gpl/rpg/atcontentstudio/model/Project.java b/src/com/gpl/rpg/atcontentstudio/model/Project.java index ab177f3..5e49808 100644 --- a/src/com/gpl/rpg/atcontentstudio/model/Project.java +++ b/src/com/gpl/rpg/atcontentstudio/model/Project.java @@ -1232,18 +1232,17 @@ public class Project implements ProjectTreeNode, Serializable { String jsonResPrefix = "@raw/"; String tmxResPrefix = "@xml/"; String jsonFileSuffix = ".json"; - String tmxFileSuffix = ".xml"; + String tmxFileSuffix = ".tmx"; if (!xmlFile.exists()) return; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document doc; try { - factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); factory.setExpandEntityReferences(false); DocumentBuilder builder = factory.newDocumentBuilder(); + InputSource insrc = new InputSource(new FileInputStream(xmlFile)); - // insrc.setSystemId("http://worldmap/"); insrc.setEncoding("UTF-8"); doc = builder.parse(insrc); @@ -1296,8 +1295,9 @@ public class Project implements ProjectTreeNode, Serializable { Result output = new StreamResult(new FileOutputStream(outputFile)); Source input = new DOMSource(doc); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2"); + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.transform(input, output); } catch (SAXException e) { e.printStackTrace(); diff --git a/src/com/gpl/rpg/atcontentstudio/model/maps/TMXMapSet.java b/src/com/gpl/rpg/atcontentstudio/model/maps/TMXMapSet.java index 00af523..b85354e 100644 --- a/src/com/gpl/rpg/atcontentstudio/model/maps/TMXMapSet.java +++ b/src/com/gpl/rpg/atcontentstudio/model/maps/TMXMapSet.java @@ -92,7 +92,7 @@ public class TMXMapSet implements ProjectTreeNode { }); if (source.type == GameSource.Type.created | source.type == GameSource.Type.altered) { final Path folderPath = Paths.get(mapFolder.getAbsolutePath()); - Thread watcher = new Thread("Map folder watcher for "+source.type) { + Thread watcher = new Thread("Map folder watcher for "+getProject().name+"/"+source.type) { public void run() { WatchService watchService; diff --git a/src/com/gpl/rpg/atcontentstudio/utils/DesktopIntegration.java b/src/com/gpl/rpg/atcontentstudio/utils/DesktopIntegration.java index 91ae199..cd229ff 100644 --- a/src/com/gpl/rpg/atcontentstudio/utils/DesktopIntegration.java +++ b/src/com/gpl/rpg/atcontentstudio/utils/DesktopIntegration.java @@ -3,6 +3,9 @@ package com.gpl.rpg.atcontentstudio.utils; import java.awt.Desktop; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Locale; import com.gpl.rpg.atcontentstudio.model.Workspace; @@ -18,7 +21,7 @@ public class DesktopIntegration { } } else { try { - Runtime.getRuntime().exec(Workspace.activeWorkspace.settings.mapEditorCommand.getCurrentValue()+" \""+f.getAbsolutePath()+"\""); + Runtime.getRuntime().exec(tokenize(Workspace.activeWorkspace.settings.mapEditorCommand.getCurrentValue()+" \""+f.getAbsolutePath()+"\"")); } catch (IOException e) { e.printStackTrace(); } @@ -40,7 +43,7 @@ public class DesktopIntegration { } } else { try { - Runtime.getRuntime().exec(Workspace.activeWorkspace.settings.imageEditorCommand.getCurrentValue()+" \""+f.getAbsolutePath()+"\""); + Runtime.getRuntime().exec(tokenize(Workspace.activeWorkspace.settings.imageEditorCommand.getCurrentValue()+" \""+f.getAbsolutePath()+"\"")); } catch (IOException e) { e.printStackTrace(); } @@ -63,5 +66,43 @@ public class DesktopIntegration { return OSType.Other; } + + private static List quotes = Arrays.asList(new Character[]{'\'', '"'}); + private static List delims = Arrays.asList(new Character[]{' ', '\r', '\n', '\t'}); + + private static String[] tokenize(String command) { + List tokens = new ArrayList(); + boolean inQuote = false; + char usedQuote = '\0'; + StringBuilder sb = new StringBuilder(); + + for (char c : command.toCharArray()) { + if (inQuote) { + if (c == usedQuote) { + inQuote = false; + continue; + } else { + sb.append(c); + } + } else { + if (quotes.contains(c)) { + inQuote = true; + usedQuote = c; + } else if (delims.contains(c)) { + if (sb.length() > 0) { + tokens.add(sb.toString()); + sb = new StringBuilder(); + } + } else { + sb.append(c); + } + } + } + if (sb.length() > 0) { + tokens.add(sb.toString()); + } + return tokens.toArray(new String[tokens.size()]); + } + }