From 19e2fc88cf769b0826ef4fbdb6f46f1feba0652a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sat, 5 Sep 2015 18:16:44 +0200 Subject: [PATCH] Proper export pack format & added warning for misconfigured editors --- resources/data/changelog/421.md | 7 ++- src/net/mightypork/rpw/App.java | 2 + .../dialogs/DialogConfigureEditors.java | 14 ++--- .../sequences/SequenceExportProject.java | 58 +++++++++++++------ .../rpw/utils/files/DesktopApi.java | 19 +++++- 5 files changed, 70 insertions(+), 30 deletions(-) diff --git a/resources/data/changelog/421.md b/resources/data/changelog/421.md index d7a46f2..1be9b37 100644 --- a/resources/data/changelog/421.md +++ b/resources/data/changelog/421.md @@ -1,4 +1,5 @@ -- Fixed some Windows bugs on first startup +- Fancy Tree categories 1.9 (snapshot) stuff +- Fixed Windows bugs on first startup - Added splash screen -- Categories for 1.9 stuff -- Option to use native look&feel \ No newline at end of file +- Option to use native look&feel +- Warning if configured editor fails diff --git a/src/net/mightypork/rpw/App.java b/src/net/mightypork/rpw/App.java index a3d5d04..e678c73 100644 --- a/src/net/mightypork/rpw/App.java +++ b/src/net/mightypork/rpw/App.java @@ -3,6 +3,8 @@ import java.io.File; import java.io.RandomAccessFile; import java.nio.channels.FileLock; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import net.mightypork.rpw.gui.Gui; import net.mightypork.rpw.gui.Icons; diff --git a/src/net/mightypork/rpw/gui/windows/dialogs/DialogConfigureEditors.java b/src/net/mightypork/rpw/gui/windows/dialogs/DialogConfigureEditors.java index f72b3ed..12493b6 100644 --- a/src/net/mightypork/rpw/gui/windows/dialogs/DialogConfigureEditors.java +++ b/src/net/mightypork/rpw/gui/windows/dialogs/DialogConfigureEditors.java @@ -87,7 +87,7 @@ protected JComponent buildGui() vbox.heading("Configure Editors"); - vbox.titsep("External Editors"); + vbox.titsep("Custom External Editors"); vbox.gapl(); @@ -95,7 +95,7 @@ protected JComponent buildGui() section_vb.padding(0, Gui.GAPL, 0, Gui.GAPL); hb = new HBox(); - hb.add(ckI = new JCheckBox("External Image Editor")); + hb.add(ckI = new JCheckBox("Custom Image Editor")); ckI.setForeground(Gui.SUBHEADING_COLOR); hb.glue(); section_vb.add(hb); @@ -104,7 +104,7 @@ protected JComponent buildGui() boxI = new HBox(); boxI.padding(0, Gui.GAPL, 0, 0); - boxI.add(labelExI = new JLabel("Executable:")); + boxI.add(labelExI = new JLabel("Exec. file:")); labelExI.setHorizontalAlignment(SwingConstants.RIGHT); boxI.gap(); @@ -127,7 +127,7 @@ protected JComponent buildGui() section_vb.gapl(); hb = new HBox(); - hb.add(ckT = new JCheckBox("External Text Editor")); + hb.add(ckT = new JCheckBox("Custom Text Editor")); ckT.setForeground(Gui.SUBHEADING_COLOR); hb.glue(); section_vb.add(hb); @@ -135,7 +135,7 @@ protected JComponent buildGui() boxT = new HBox(); boxT.padding(0, Gui.GAPL, 0, 0); - boxT.add(labelExT = new JLabel("Executable:")); + boxT.add(labelExT = new JLabel("Exec. file:")); labelExT.setHorizontalAlignment(SwingConstants.RIGHT); boxT.gap(); @@ -158,7 +158,7 @@ protected JComponent buildGui() section_vb.gapl(); hb = new HBox(); - hb.add(ckA = new JCheckBox("External Audio Editor")); + hb.add(ckA = new JCheckBox("Custom Audio Editor")); ckA.setForeground(Gui.SUBHEADING_COLOR); hb.glue(); section_vb.add(hb); @@ -166,7 +166,7 @@ protected JComponent buildGui() boxA = new HBox(); boxA.padding(0, Gui.GAPL, 0, 0); - boxA.add(labelExA = new JLabel("Executable:")); + boxA.add(labelExA = new JLabel("Exec. file:")); labelExA.setHorizontalAlignment(SwingConstants.RIGHT); boxA.gap(); diff --git a/src/net/mightypork/rpw/tasks/sequences/SequenceExportProject.java b/src/net/mightypork/rpw/tasks/sequences/SequenceExportProject.java index 5e7fe1d..c3481bc 100644 --- a/src/net/mightypork/rpw/tasks/sequences/SequenceExportProject.java +++ b/src/net/mightypork/rpw/tasks/sequences/SequenceExportProject.java @@ -7,6 +7,8 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import net.mightypork.rpw.App; import net.mightypork.rpw.Config; @@ -37,12 +39,12 @@ public class SequenceExportProject extends AbstractMonitoredSequence private final Runnable successRunnable; - public SequenceExportProject(File target, Runnable onSuccess) { + public SequenceExportProject(File target, Runnable onSuccess) + { this.target = target; this.successRunnable = onSuccess; this.project = Projects.getActive(); - } @@ -155,7 +157,6 @@ private boolean stepAddConfigFiles() throws IOException in = FileUtils.getResource("/data/export/pack.png"); } zb.addStream("pack.png", in); - } finally { Utils.close(in); } @@ -173,7 +174,34 @@ private boolean stepAddConfigFiles() throws IOException final String desc = project.getTitle(); final PackMcmeta pim = new PackMcmeta(); - pim.setPackInfo(new PackInfo(1, desc)); + + String vers = Config.LIBRARY_VERSION.split("\\+")[0]; + int format = 1; + + // Determine format from version + + Pattern p = Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+).*"); + Matcher m = p.matcher(vers); + + if (m.find()) { + // Regular release + int vers_numeric = Integer.valueOf(m.group(1))*10000 + Integer.valueOf(m.group(2))*100 + Integer.valueOf(m.group(3)); + if (vers_numeric > 10900) format = 2; + } else { + p = Pattern.compile("^(\\d{2}w\\d{2}).*"); + m = p.matcher(vers); + + if(m.find()) { + // Snapshot + if (m.group(1).compareTo("15w31") >= 0) format = 2; + } else { + Log.e("Unexpected MC version name, cannot determine pack format."); + } + } + + Log.i("Using resource pack format: " + format); + + pim.setPackInfo(new PackInfo(format, desc)); zb.addString("pack.mcmeta", pim.toJson()); @@ -201,7 +229,6 @@ protected void doBefore() Alerts.loading(true); Log.f1("Exporting project \"" + project.getTitle() + "\" to " + target); - } @@ -251,7 +278,7 @@ private void addDirectoryToZip(File dir, String pathPrefix) throws IOException String path = file.getAbsolutePath(); path = pathPrefix + path.replace(dir.getAbsolutePath(), ""); - + path = path.replace('\\', '/'); // Windoze shit FileInputStream in = null; @@ -265,7 +292,6 @@ private void addDirectoryToZip(File dir, String pathPrefix) throws IOException if (Config.LOG_EXPORT_FILES) Log.f3("+ " + path); } - } private class ExportProcessor implements AssetTreeProcessor @@ -277,7 +303,7 @@ public void process(AssetTreeNode node) if (node instanceof AssetTreeLeaf) { final AssetTreeLeaf leaf = (AssetTreeLeaf) node; - String logEntry = null; + String logEntry = ""; // file boolean fileSaved = false; @@ -294,20 +320,18 @@ public void process(AssetTreeNode node) if (data == null) break; final String path = leaf.getAssetEntry().getPath(); - - logEntry = "+ " + path; + + logEntry += "+ " + path; zb.addStream(path, data); logEntry += " <- \"" + srcName + "\""; fileSaved = true; - } catch (final IOException e) { Log.e("Error getting asset stream.", e); } finally { Utils.close(data); } - } while (false); if (!fileSaved) return; @@ -332,23 +356,19 @@ public void process(AssetTreeNode node) zb.addStream(path, data); logEntry += ", m: \"" + srcName + "\""; - } catch (final IOException e) { Log.e("Error getting asset meta stream.", e); } finally { Utils.close(data); } - } while (false); if (Config.LOG_EXPORT_FILES) { - if (logEntry != null) { - Log.f3(logEntry); - } + Log.f3(logEntry); } - } } - }; + } + ; } diff --git a/src/net/mightypork/rpw/utils/files/DesktopApi.java b/src/net/mightypork/rpw/utils/files/DesktopApi.java index 56b5a55..8133585 100644 --- a/src/net/mightypork/rpw/utils/files/DesktopApi.java +++ b/src/net/mightypork/rpw/utils/files/DesktopApi.java @@ -1,13 +1,15 @@ package net.mightypork.rpw.utils.files; -import java.awt.Desktop; +import java.awt.*; import java.io.File; import java.io.IOException; import java.net.URI; import java.util.ArrayList; import java.util.List; +import net.mightypork.rpw.App; import net.mightypork.rpw.Config; +import net.mightypork.rpw.gui.windows.messages.Alerts; import net.mightypork.rpw.utils.files.OsUtils.EnumOS; import net.mightypork.rpw.utils.logging.Log; @@ -39,6 +41,11 @@ public static boolean editText(File file) { if (Config.USE_TEXT_EDITOR) { if (runCommand(Config.TEXT_EDITOR, Config.TEXT_EDITOR_ARGS, file.getPath())) return true; + Alerts.warning(App.getFrame(), + "Your configured text editor \"" + Config.IMAGE_EDITOR + "\" could not be launched.\n" + + "Please review your settings in [Options > Configure editors].\n\n" + + "RPW will now try to use your system default editor." + ); } if (openSystemSpecific(file.getPath())) return true; @@ -53,6 +60,11 @@ public static boolean editImage(File file) { if (Config.USE_IMAGE_EDITOR) { if (runCommand(Config.IMAGE_EDITOR, Config.IMAGE_EDITOR_ARGS, file.getPath())) return true; + Alerts.warning(App.getFrame(), + "Your configured image editor \"" + Config.IMAGE_EDITOR + "\" could not be launched.\n" + + "Please review your settings in [Options > Configure editors].\n\n" + + "RPW will now try to use your system default editor." + ); } if (OsUtils.isWindows()) { @@ -71,6 +83,11 @@ public static boolean editAudio(File file) { if (Config.USE_AUDIO_EDITOR) { if (runCommand(Config.AUDIO_EDITOR, Config.AUDIO_EDITOR_ARGS, file.getPath())) return true; + Alerts.warning(App.getFrame(), + "Your configured audio editor \"" + Config.IMAGE_EDITOR + "\" could not be launched.\n" + + "Please review your settings in [Options > Configure editors].\n\n" + + "RPW will now try to use your system default editor." + ); } if (openSystemSpecific(file.getPath())) return true;