Skip to content

Commit

Permalink
#13
Browse files Browse the repository at this point in the history
  • Loading branch information
CHeuberger committed Mar 15, 2022
1 parent edd71bf commit 4351a37
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Puzzle Test ARG.launch → Puzzle Main ARG.launch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/Puzzle/src/java/cfh/puzzle/Test.java"/>
<listEntry value="/Puzzle/src/java/cfh/puzzle/Main.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
Expand All @@ -10,7 +10,7 @@
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="cfh.puzzle.Test"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="cfh.puzzle.Main"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="${string_prompt}"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="Puzzle"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-splash:cfh/puzzle/resources/splash.png"/>
Expand Down
4 changes: 2 additions & 2 deletions Puzzle Test.launch → Puzzle Main.launch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/Puzzle/src/java/cfh/puzzle/Test.java"/>
<listEntry value="/Puzzle/src/java/cfh/puzzle/Main.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
Expand All @@ -10,7 +10,7 @@
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="cfh.puzzle.Test"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="cfh.puzzle.Main"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="Puzzle"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-splash:cfh/puzzle/resources/splash.png"/>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:Puzzle/build/classes}"/>
Expand Down
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,23 @@ Other then that, you are not allowed to use, change and/or redistribute any User

### Version

- append to JAR file in `docs/puzzle_V<version>.jar`
- `dist/puzzle.jar` ?
- adjust `jar` entry in `src/puzzle.jnlp`
copy to `docs/`
- adjust `Implementation-Version` in `src/manifest.txt`
- adjust in `docs/index.md`
- update `Implementation-Version` in `src/manifest.txt`
- update `version` from `jnlp` tag in `src/puzzle.jnlp`
- create `JAR`
- sign `JAR` using `. src/signjar.sh`

### Java Web Start

- `puzzle.jnlp` is available in `src/`
copy to `docs/`
- copy `src/puzzle.jnlp` to `docs/`
- copy `dist/puzzle.jar` to `docs/`

### ZIP

- copy `dist/` folder to new folder `Puzzle-<version>`
- zip `Puzzle-<version>` folder to `Puzzle-<version>.zip`
- adjust `ZIP` link in `docs/index.md` - two times Version (tag and file)
- `commmit` and `tag -s v<version> -m v<version>`
- `push`, create release for that tag and attach the `ZIP`

### Pictures

Expand Down
Binary file modified dist/puzzle.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Java security needs the installation of 2 certificates to validate the download:

### 2. Java (WIP)

Download the [ZIP file](https://github.com/Heuberger/Puzzle/releases/download/v0.11/Puzzle-0.11.zip) and extract its content. Start any of the included batch file (e.g. `bus.bat`) or just start (double-click) `puzzle.jar` (command line `java -jar puzzle.jar`).
Download the [ZIP file](https://github.com/Heuberger/Puzzle/releases/download/v0.12/Puzzle-0.12.zip) and extract its content. Start any of the included batch file (e.g. `bus.bat`) or just start (double-click) `puzzle.jar` (command line `java -jar puzzle.jar`).



Expand Down
Binary file modified docs/puzzle.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/puzzle.jnlp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
spec="1.0+"
codebase="https://heuberger.github.io/Puzzle/"
href="puzzle.jnlp"
version="0.11">
version="0.12">
<information>
<title>Jigsaw Puzzle</title>
<vendor>Carlos F. Heuberger</vendor>
Expand Down Expand Up @@ -41,6 +41,6 @@

<application-desc
name="Jigsaw Puzzle"
main-class="cfh.puzzle.Test">
main-class="cfh.puzzle.Main">
</application-desc>
</jnlp>
2 changes: 1 addition & 1 deletion puzzle.jardesc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<options buildIfNeeded="true" compress="true" descriptionLocation="/Puzzle/puzzle.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/>
<manifest generateManifest="false" mainClassHandleIdentifier="=Puzzle/src\/java&lt;cfh.puzzle{Test.java[Test" manifestLocation="/Puzzle/src/manifest.txt" manifestVersion="1.0" reuseManifest="false" saveManifest="true" usesManifest="true">
<manifest generateManifest="false" manifestLocation="/Puzzle/src/manifest.txt" manifestVersion="1.0" reuseManifest="false" saveManifest="true" usesManifest="true">
<sealing sealJar="false">
<packagesToSeal/>
<packagesToUnSeal/>
Expand Down
2 changes: 1 addition & 1 deletion src/java/cfh/puzzle/ConstSizeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public int getEdgeColorChange() {
}

@Override
public String getKey() {
public char[] getKey() {
return null;
}
}
39 changes: 22 additions & 17 deletions src/java/cfh/puzzle/Test.java → src/java/cfh/puzzle/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JPopupMenu;
import javax.swing.filechooser.FileNameExtensionFilter;

Expand All @@ -59,11 +60,11 @@
/**
* @author Carlos F. Heuberger
*/
public class Test extends GamePanel {
public class Main extends GamePanel {

private static final String VERSION;
static {
String version = Test.class.getPackage().getImplementationVersion();
String version = Main.class.getPackage().getImplementationVersion();
VERSION = "Puzzle by Carlos F. Heuberger - v" + (version==null ? "?" : version);
}

Expand Down Expand Up @@ -142,9 +143,9 @@ public static void main(String[] args) {
return;
}
} else {
url = Test.class.getResource(arg);
url = Main.class.getResource(arg);
if (url == null && arg.charAt(0) != '/') {
url = Test.class.getResource("resources/" + arg);
url = Main.class.getResource("resources/" + arg);
}
}
if (url == null) {
Expand Down Expand Up @@ -257,7 +258,7 @@ public static void main(String[] args) {
System.out.printf("Size: %s%n", size);

if (size != null) {
new Test(type, image, size, seed, imageName);
new Main(type, image, size, seed, imageName);
}
}

Expand All @@ -274,9 +275,13 @@ private static long randomSeed() {
private static void startJigsaw(File file) {
try (ObjectInputStream input = new ObjectInputStream(new FileInputStream(file))) {
int magic = input.readInt();
String key;
char[] key;
if (magic == MAGIC2) {
key = JOptionPane.showInputDialog("Key?");
JPasswordField field = new JPasswordField(16);
if (JOptionPane.showConfirmDialog(null, field, "Input", JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION) {
return;
}
key = field.getPassword();
} else {
key =null;
}
Expand All @@ -285,7 +290,7 @@ private static void startJigsaw(File file) {
long seed = input.readLong();
Size size = Size.read(input, key);
BufferedImage image = decodeImage(input, key, seed);
Test test = new Test(type, image, size, seed, file.getAbsolutePath());
Main test = new Main(type, image, size, seed, file.getAbsolutePath());
test.load(input, key);
} else {
errorMessage("unable to load ", file.getAbsolutePath());
Expand All @@ -309,7 +314,7 @@ private static void startJigsaw(File file) {

private JFrame frame;

private Test(int type, BufferedImage image, Size size, long seed, String title) {
private Main(int type, BufferedImage image, Size size, long seed, String title) {
super(title, size.getSizeX(), size.getSizeY());

this.puzzleSize = size;
Expand All @@ -329,7 +334,7 @@ private Test(int type, BufferedImage image, Size size, long seed, String title)

frame = new JFrame(String.format("%s - %s - %d (%dx%d)", VERSION, title, size.width()*size.height(), size.width(), size.height()));
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
URL url = Test.class.getResource("resources/icon.png");
URL url = Main.class.getResource("resources/icon.png");
if (url == null) {
System.err.println("unable to load \"resources/icon.png\"");
} else {
Expand Down Expand Up @@ -397,7 +402,7 @@ private void save(ObjectOutputStream output, Size size) throws IOException {
}
}

private void load(ObjectInputStream input, String key) throws IOException {
private void load(ObjectInputStream input, char[] key) throws IOException {
setBackgroundImage(decodeImage(input, key, seed));
Map<?, ?> marks;
try {
Expand Down Expand Up @@ -1024,7 +1029,7 @@ private BufferedImage loadImage(String filename) {
return null;
}

private static void encodeImage(BufferedImage image, ObjectOutputStream output, String key, long seed) throws IOException {
private static void encodeImage(BufferedImage image, ObjectOutputStream output, char[] key, long seed) throws IOException {
if (image == null) {
output.writeInt(0);
} else {
Expand All @@ -1033,7 +1038,7 @@ private static void encodeImage(BufferedImage image, ObjectOutputStream output,
ImageIO.write(image, "PNG", result);
data = result.toByteArray();
}
if (key != null && !key.isEmpty()) {
if (key != null && key.length > 0) {
try {
DESedeKeySpec keySpec = new DESedeKeySpec(spec(key, seed));
SecretKey secret = SecretKeyFactory.getInstance(ALGORITHM).generateSecret(keySpec);
Expand All @@ -1049,13 +1054,13 @@ private static void encodeImage(BufferedImage image, ObjectOutputStream output,
}
}

private static BufferedImage decodeImage(ObjectInputStream input, String key, long seed) throws IOException {
private static BufferedImage decodeImage(ObjectInputStream input, char[] key, long seed) throws IOException {
int length = input.readInt();
if (length == 0)
return null;
byte[] data = new byte[length];
input.readFully(data);
if (key != null && !key.isEmpty()) {
if (key != null && key.length > 0) {
try {
DESedeKeySpec keySpec = new DESedeKeySpec(spec(key, seed));
SecretKey secret = SecretKeyFactory.getInstance(ALGORITHM).generateSecret(keySpec);
Expand All @@ -1071,8 +1076,8 @@ private static BufferedImage decodeImage(ObjectInputStream input, String key, lo
}
}

private static byte[] spec(String key, long seed) {
StringBuilder builder = new StringBuilder(key);
private static byte[] spec(char[] key, long seed) {
StringBuilder builder = new StringBuilder(new String(key));
long s = seed;
while (builder.length() < 24) {
builder.append(s);
Expand Down
4 changes: 2 additions & 2 deletions src/java/cfh/puzzle/Size.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract class Size {
private transient int width;
private transient int height;

public static Size read(ObjectInputStream input, String key) throws IOException {
public static Size read(ObjectInputStream input, char[] key) throws IOException {
String name = input.readUTF();
switch (name) {
case "TemplateSizeImpl": return TemplateSizeImpl.read0(input, key);
Expand Down Expand Up @@ -52,7 +52,7 @@ public final void write(ObjectOutputStream output) throws IOException {

public abstract int getEdgeColorChange();

public abstract String getKey();
public abstract char[] getKey();

protected abstract void write0(ObjectOutputStream out) throws IOException;

Expand Down
7 changes: 5 additions & 2 deletions src/java/cfh/puzzle/SizePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

/**
Expand All @@ -31,7 +32,7 @@ public class SizePanel {
private JTextField message;
private JTextField countField;
private JComboBox<String> templateBox;
private String key = null;
private char[] key = null;

public SizePanel() {
initGUI();
Expand Down Expand Up @@ -97,7 +98,9 @@ public void mouseClicked(MouseEvent e) {

private void doMessageClicked(MouseEvent ev) {
if (ev.getClickCount() == 2 && ev.getButton() == ev.BUTTON1 && ev.getModifiersEx() == ev.CTRL_DOWN_MASK) {
key = JOptionPane.showInputDialog(panel, "Key?", key);
JPasswordField field = new JPasswordField(16);
JOptionPane.showMessageDialog(panel, field, "Password?", JOptionPane.QUESTION_MESSAGE);
key = field.getPassword();
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/java/cfh/puzzle/TemplateSizeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ public class TemplateSizeImpl extends Size {

private final int count;
private final Template template;
private final String key;
private final char[] key;

protected static TemplateSizeImpl read0(ObjectInputStream input, String key) throws IOException {
protected static TemplateSizeImpl read0(ObjectInputStream input, char[] key) throws IOException {
int count = input.readInt();
Template template = Template.read(input);
return new TemplateSizeImpl(count, template, key);
}


TemplateSizeImpl(int count, Template template, String key) {
TemplateSizeImpl(int count, Template template, char[] key) {
this.count = count;
this.template = template;
this.key = key;
Expand Down Expand Up @@ -102,7 +102,7 @@ public int getEdgeColorChange() {
}

@Override
public String getKey() {
public char[] getKey() {
return key;
}

Expand Down
4 changes: 2 additions & 2 deletions src/manifest.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Main-Class: cfh.puzzle.Test
Main-Class: cfh.puzzle.Main
Implementation-Vendor: Carlos F. Heuberger. All rights reserved.
Implementation-Version: 0.11
Implementation-Version: 0.12
SplashScreen-Image: cfh/puzzle/resources/splash.png
Permissions: all-permissions
Application-Name: Jigsaw Puzzle
Expand Down
4 changes: 2 additions & 2 deletions src/puzzle.jnlp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
spec="1.0+"
codebase="https://heuberger.github.io/Puzzle/"
href="puzzle.jnlp"
version="0.11">
version="0.12">
<information>
<title>Jigsaw Puzzle</title>
<vendor>Carlos F. Heuberger</vendor>
Expand Down Expand Up @@ -41,6 +41,6 @@

<application-desc
name="Jigsaw Puzzle"
main-class="cfh.puzzle.Test">
main-class="cfh.puzzle.Main">
</application-desc>
</jnlp>

0 comments on commit 4351a37

Please sign in to comment.