From 995dcd89698aaa167e778b4f58b5726318c49adb Mon Sep 17 00:00:00 2001 From: TheEntropyShard Date: Thu, 9 Mar 2023 20:14:41 +0300 Subject: [PATCH] Changed way of getting time --- src/me/theentropyshard/jdarkroom/Decoder.java | 25 +++++++++++-------- src/me/theentropyshard/jdarkroom/View.java | 6 +++-- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/me/theentropyshard/jdarkroom/Decoder.java b/src/me/theentropyshard/jdarkroom/Decoder.java index b16598e..6bfdeab 100644 --- a/src/me/theentropyshard/jdarkroom/Decoder.java +++ b/src/me/theentropyshard/jdarkroom/Decoder.java @@ -36,6 +36,12 @@ public enum Decoder { } int index = (bytes[15] >> 3) & 0b111; + /*int index = 0; + + String num = Integer.toBinaryString(bytes[15]); + if(num.length() <= 3) num += "000000"; + System.out.println(num); + index = Integer.parseInt(num.substring(0, 4), 2) & 0b111;*/ byte firstRoundKey = DecodingData.KEY[index]; byte secondRoundKey = DecodingData.KEY[DecodingData.KEY.length - 1 - index]; @@ -63,14 +69,7 @@ public enum Decoder { bytes[byteInd] ^= (1 << bitInd); } - return Decoder.getGameInfo(bytes); - } - - public static String getGameInfo(byte[] bytes) { - String resultLabel = I18N.getString("resultLabel"); - String[] internetCodes = Decoder.readCode(bytes).split("_"); - String totalPlaytime = Decoder.readTotalPlaytime(bytes); - return String.format(resultLabel, internetCodes[0], internetCodes[1], totalPlaytime); + return Decoder.readCode(bytes) + "_" + Decoder.readTotalPlaytime(bytes); } public static String readCode(byte[] bytes) { @@ -100,8 +99,12 @@ public enum Decoder { } public static String readTotalPlaytime(byte[] bytes) { - return (bytes[14] < 10 ? "0" + bytes[14] : "" + bytes[14]) + ":" + - (bytes[13] < 10 ? "0" + bytes[13] : "" + bytes[13]) + ":" + - (bytes[15] < 10 ? "0" + bytes[15] : "" + bytes[15]); + int time = ((bytes[14] * 60 + bytes[13]) * 60 + bytes[15]); + int h = (int) Math.floor(time / 3600.0f); + int m = (int) Math.floor(time % 3600 / 60.0f); + int s = (int) Math.floor(time % 3600 % 60); + return (h < 10 ? "0" + h : "" + h) + ":" + + (m < 10 ? "0" + m : "" + m) + ":" + + (s < 10 ? "0" + s : "" + s); } } diff --git a/src/me/theentropyshard/jdarkroom/View.java b/src/me/theentropyshard/jdarkroom/View.java index 4d1e0dd..a964366 100644 --- a/src/me/theentropyshard/jdarkroom/View.java +++ b/src/me/theentropyshard/jdarkroom/View.java @@ -39,7 +39,6 @@ public final class View extends JPanel { private final JLabel resultLabel; - @SuppressWarnings("unchecked") public View() { this.setPreferredSize(new Dimension(View.WIDTH, View.HEIGHT)); @@ -87,6 +86,7 @@ public final class View extends JPanel { public synchronized void drop(DropTargetDropEvent dtde) { dtde.acceptDrop(DnDConstants.ACTION_COPY); try { + @SuppressWarnings("unchecked") List droppedFiles = (List) dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); String code = SaveFileReader.findInSave(droppedFiles.get(0)); @@ -152,7 +152,9 @@ public final class View extends JPanel { if(text.length() != 16) { resultLabel.setText(I18N.getString("incorrectCodeLength")); } else { - resultLabel.setText(Decoder.decodeInternetCode(text)); + String rl = I18N.getString("resultLabel"); + String[] data = Decoder.decodeInternetCode(text).split("_"); + resultLabel.setText(String.format(rl, data[0], data[1], data[2])); } cardLayout.show(View.this, "resultPanel"); });