Skip to content
This repository has been archived by the owner on Oct 6, 2018. It is now read-only.

Commit

Permalink
Proper export pack format & added warning for misconfigured editors
Browse files Browse the repository at this point in the history
  • Loading branch information
MightyPork committed Sep 5, 2015
1 parent ac50e82 commit 19e2fc8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 30 deletions.
7 changes: 4 additions & 3 deletions resources/data/changelog/421.md
Original file line number Diff line number Diff line change
@@ -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
- Option to use native look&feel
- Warning if configured editor fails
2 changes: 2 additions & 0 deletions src/net/mightypork/rpw/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ protected JComponent buildGui()

vbox.heading("Configure Editors");

vbox.titsep("External Editors");
vbox.titsep("Custom External Editors");

vbox.gapl();

section_vb = new VBox();
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);
Expand All @@ -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();

Expand All @@ -127,15 +127,15 @@ 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);
section_vb.gap();

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();

Expand All @@ -158,15 +158,15 @@ 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);
section_vb.gap();

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();

Expand Down
58 changes: 39 additions & 19 deletions src/net/mightypork/rpw/tasks/sequences/SequenceExportProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

}


Expand Down Expand Up @@ -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);
}
Expand All @@ -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());

Expand Down Expand Up @@ -201,7 +229,6 @@ protected void doBefore()
Alerts.loading(true);

Log.f1("Exporting project \"" + project.getTitle() + "\" to " + target);

}


Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}

}
}
};
}

;
}
19 changes: 18 additions & 1 deletion src/net/mightypork/rpw/utils/files/DesktopApi.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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()) {
Expand All @@ -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;
Expand Down

0 comments on commit 19e2fc8

Please sign in to comment.