Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.

Commit f8d7acf

Browse files
authored
Merge pull request #12 from Enaium/develop
Develop
2 parents 246deb3 + c233281 commit f8d7acf

36 files changed

+875
-268
lines changed

build.gradle

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group 'cn.enaium'
10-
version '0.10.0'
10+
version '1.0.0'
1111

1212
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
1313

@@ -27,6 +27,7 @@ new File(System.getProperty("user.dir"), "run").mkdir()
2727
repositories {
2828
mavenCentral()
2929
maven { url 'https://jitpack.io' }
30+
maven { url 'https://maven.quiltmc.org/repository/release' }
3031
}
3132

3233
dependencies {
@@ -38,14 +39,15 @@ dependencies {
3839
implementation 'com.github.bobbylight:RSyntaxTextArea:3.2.0'
3940
implementation 'org.ow2.asm:asm-tree:9.3'
4041
implementation 'org.ow2.asm:asm-util:9.3'
42+
implementation 'org.ow2.asm:asm-commons:9.3'
4143
implementation 'org.benf:cfr:0.152'
4244
implementation 'com.github.mstrobel.procyon:procyon-decompiler:v0.6.0'
43-
implementation 'com.github.java-decompiler:jd-core:v1.1.3'
45+
implementation 'org.quiltmc:quiltflower:1.8.1'
4446
implementation 'org.javassist:javassist:3.29.0-GA'
4547
implementation 'com.google.code.gson:gson:2.9.0'
46-
implementation 'org.tinylog:tinylog-api:2.4.1'
47-
implementation 'org.tinylog:tinylog-impl:2.4.1'
48-
48+
implementation 'org.tinylog:tinylog-api:2.5.0'
49+
implementation 'org.tinylog:tinylog-impl:2.5.0'
50+
implementation 'com.github.FabricMC:mapping-io:597f0722d6'
4951
}
5052

5153
test {
@@ -59,10 +61,11 @@ shadowJar {
5961
include(dependency('org.ow2.asm:.*'))
6062
include(dependency('org.benf:cfr'))
6163
include(dependency('com.github.mstrobel.procyon:procyon-decompiler'))
62-
include(dependency('com.github.java-decompiler:jd-core'))
6364
include(dependency('org.javassist:javassist'))
6465
include(dependency('com.google.code.gson:gson'))
6566
include(dependency('org.tinylog:.*'))
67+
include(dependency('org.quiltmc:quiltflower'))
68+
include(dependency('com.github.FabricMC:mapping-io'))
6669
}
6770
archiveClassifier.set('')
6871
}

src/main/java/cn/enaium/joe/JavaOctetEditor.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
import cn.enaium.joe.gui.panel.LeftPanel;
2222
import cn.enaium.joe.gui.panel.file.tabbed.FileTabbedPanel;
2323
import cn.enaium.joe.gui.panel.file.tree.FileTreePanel;
24-
import cn.enaium.joe.gui.panel.menu.ConfigMenu;
25-
import cn.enaium.joe.gui.panel.menu.FileMenu;
26-
import cn.enaium.joe.gui.panel.menu.HelpMenu;
27-
import cn.enaium.joe.gui.panel.menu.SearchMenu;
24+
import cn.enaium.joe.gui.panel.menu.*;
2825
import cn.enaium.joe.jar.Jar;
2926
import cn.enaium.joe.task.TaskManager;
3027
import cn.enaium.joe.util.LangUtil;
@@ -47,7 +44,7 @@ public class JavaOctetEditor {
4744

4845
public JFrame window = new JFrame(TITLE);
4946

50-
public Jar jar;
47+
private Jar jar;
5148

5249
public FileTabbedPanel fileTabbedPanel;
5350

@@ -80,6 +77,7 @@ public void run() {
8077
window.setJMenuBar(new JMenuBar() {{
8178
add(new FileMenu());
8279
add(new SearchMenu());
80+
add(new MappingMenu());
8381
add(new ConfigMenu());
8482
add(new HelpMenu());
8583
}});
@@ -110,6 +108,15 @@ public void windowClosing(WindowEvent e) {
110108
window.setVisible(true);
111109
}
112110

111+
public Jar getJar() {
112+
return jar;
113+
}
114+
115+
public void setJar(Jar jar) {
116+
this.jar = jar;
117+
fileTreePanel.refresh(jar);
118+
}
119+
113120
public static JavaOctetEditor getInstance() {
114121
return instance;
115122
}

src/main/java/cn/enaium/joe/config/ConfigManager.java

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import cn.enaium.joe.config.extend.CFRConfig;
2121
import cn.enaium.joe.config.value.Value;
2222
import cn.enaium.joe.util.MessageUtil;
23-
import com.google.gson.Gson;
24-
import com.google.gson.GsonBuilder;
25-
import org.tinylog.Logger;
23+
import cn.enaium.joe.util.ReflectUtil;
24+
import com.google.gson.*;
25+
import com.google.gson.annotations.Expose;
2626

2727
import java.io.File;
2828
import java.io.IOException;
@@ -44,6 +44,7 @@ public ConfigManager() {
4444
setByClass(new CFRConfig());
4545
}
4646

47+
@SuppressWarnings("unchecked")
4748
public <T> T getByClass(Class<T> klass) {
4849
if (configMap.containsKey(klass)) {
4950
return (T) configMap.get(klass);
@@ -79,15 +80,49 @@ public Map<String, String> getConfigMap(Class<? extends Config> config) {
7980
return map;
8081
}
8182

83+
private Gson gson() {
84+
return new GsonBuilder().setPrettyPrinting().create();
85+
}
86+
8287
public void load() {
83-
for (Config value : configMap.values()) {
88+
for (Map.Entry<Class<? extends Config>, Config> classConfigEntry : configMap.entrySet()) {
89+
90+
Class<? extends Config> klass = classConfigEntry.getKey();
91+
Config config = classConfigEntry.getValue();
8492
try {
85-
Gson gson = new GsonBuilder().setPrettyPrinting().create();
86-
File file = new File(System.getProperty("."), value.getName() + ".json");
93+
File file = new File(System.getProperty("."), config.getName() + ".json");
8794
if (file.exists()) {
88-
configMap.put(value.getClass(), gson.fromJson(new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8), value.getClass()));
95+
//Step.1 get json object
96+
JsonObject jsonObject = gson().fromJson(new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8), JsonObject.class);
97+
98+
//Step.2 get all field of the config
99+
for (Field configField : klass.getDeclaredFields()) {
100+
configField.setAccessible(true);
101+
if (!jsonObject.has(configField.getName())) {
102+
continue;
103+
}
104+
105+
//Step.3 deserialize
106+
Object setting = gson().fromJson(jsonObject.get(configField.getName()).toString(), configField.getType());
107+
108+
//Step.3.1 get all field of the setting
109+
for (Field settingField : setting.getClass().getDeclaredFields()) {
110+
settingField.setAccessible(true);
111+
112+
if (settingField.isAnnotationPresent(Expose.class)) {
113+
if (!settingField.getAnnotation(Expose.class).deserialize()) {
114+
Field declaredField = ReflectUtil.getField(setting.getClass(), settingField.getName());
115+
//Step.3.2 use the value from config to set the value of setting
116+
declaredField.set(setting, ReflectUtil.getFieldValue(ReflectUtil.getFieldValue(config, configField.getName()), settingField.getName()));
117+
}
118+
}
119+
}
120+
121+
//Step.4 use the value from step 3 to set the value of config
122+
configField.set(config, setting);
123+
}
89124
}
90-
} catch (IOException e) {
125+
} catch (Throwable e) {
91126
MessageUtil.error(e);
92127
}
93128
}
@@ -96,8 +131,7 @@ public void load() {
96131
public void save() {
97132
for (Config value : configMap.values()) {
98133
try {
99-
Gson gson = new GsonBuilder().setPrettyPrinting().create();
100-
Files.write(new File(System.getProperty("."), value.getName() + ".json").toPath(), gson.toJson(value).getBytes(StandardCharsets.UTF_8));
134+
Files.write(new File(System.getProperty("."), value.getName() + ".json").toPath(), gson().toJson(value).getBytes(StandardCharsets.UTF_8));
101135
} catch (IOException e) {
102136
MessageUtil.error(e);
103137
}

src/main/java/cn/enaium/joe/config/extend/ApplicationConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
* @since 0.7.0
3131
*/
3232
public class ApplicationConfig extends Config {
33-
public final ModeValue decompilerMode = new ModeValue("Decompiler", "CFR", "Java Decompiler", Arrays.asList("CFR", "Procyon", "JD-Core"));
34-
public final ModeValue language = new ModeValue("Language", "System", "UI language", Arrays.asList("System", "zh_CN", "en_US"));
33+
public ModeValue decompilerMode = new ModeValue("Decompiler", "CFR", "Java Decompiler", Arrays.asList("CFR", "Procyon", "FernFlower"));
34+
public ModeValue language = new ModeValue("Language", "System", "UI language", Arrays.asList("System", "zh_CN", "en_US"));
3535
@NoUI
3636
public final StringSetValue loadRecent = new StringSetValue("Load Recent", new HashSet<>(), "");
3737

src/main/java/cn/enaium/joe/config/value/ModeValue.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package cn.enaium.joe.config.value;
1818

19+
import com.google.gson.annotations.Expose;
20+
1921
import java.util.List;
2022

2123
/**
@@ -24,7 +26,8 @@
2426
*/
2527
public class ModeValue extends Value<String> {
2628

27-
private final List<String> mode;
29+
@Expose(deserialize = false)
30+
private List<String> mode;
2831

2932
public ModeValue(String name, String value, String description, List<String> mode) {
3033
super(name, value, description);
@@ -34,4 +37,8 @@ public ModeValue(String name, String value, String description, List<String> mod
3437
public List<String> getMode() {
3538
return mode;
3639
}
40+
41+
public void setMode(List<String> mode) {
42+
this.mode = mode;
43+
}
3744
}

src/main/java/cn/enaium/joe/config/value/Value.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
* @since 0.7.0
2222
*/
2323
public class Value<T> {
24-
private final String name;
24+
private String name;
2525
private T value;
26-
private final String description;
26+
private String description;
2727

2828
public Value(String name, T value, String description) {
2929
this.name = name;

src/main/java/cn/enaium/joe/dialog/search/SearchFieldDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public SearchFieldDialog() {
5555
((DefaultListModel<ResultNode>) resultList.getModel()).clear();
5656

5757
JavaOctetEditor.getInstance().task
58-
.submit(new SearchFieldTask(JavaOctetEditor.getInstance().jar, owner.getText(), name.getText(), description.getText()))
58+
.submit(new SearchFieldTask(JavaOctetEditor.getInstance().getJar(), owner.getText(), name.getText(), description.getText()))
5959
.thenAccept(it -> {
6060
for (ResultNode resultNode : it) {
6161
((DefaultListModel<ResultNode>) resultList.getModel()).addElement(resultNode);

src/main/java/cn/enaium/joe/dialog/search/SearchLdcDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public SearchLdcDialog() {
4242
if (!text.getText().isEmpty()) {
4343
((DefaultListModel<ResultNode>) resultList.getModel()).clear();
4444
JavaOctetEditor.getInstance().task
45-
.submit(new SearchLdcTask(JavaOctetEditor.getInstance().jar, text.getText()))
45+
.submit(new SearchLdcTask(JavaOctetEditor.getInstance().getJar(), text.getText()))
4646
.thenAccept(it -> {
4747
resultList.removeAll();
4848
for (ResultNode resultNode : it) {

src/main/java/cn/enaium/joe/dialog/search/SearchMethodDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public SearchMethodDialog() {
6060

6161

6262
JavaOctetEditor.getInstance().task
63-
.submit(new SearchMethodTask(JavaOctetEditor.getInstance().jar, owner.getText(), name.getText(), description.getText(), anInterface.isSelected()))
63+
.submit(new SearchMethodTask(JavaOctetEditor.getInstance().getJar(), owner.getText(), name.getText(), description.getText(), anInterface.isSelected()))
6464
.thenAccept(it -> {
6565
((DefaultListModel<ResultNode>) resultList.getModel()).clear();
6666
for (ResultNode resultNode : it) {

src/main/java/cn/enaium/joe/gui/panel/BottomPanel.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@
1919
import cn.enaium.joe.JavaOctetEditor;
2020
import cn.enaium.joe.annotation.Indeterminate;
2121
import cn.enaium.joe.task.AbstractTask;
22-
import cn.enaium.joe.task.DecompileTask;
23-
import org.benf.cfr.reader.bytecode.analysis.parse.utils.Pair;
22+
import cn.enaium.joe.util.Pair;
2423

2524
import javax.swing.*;
2625
import javax.swing.border.EmptyBorder;
2726
import java.awt.*;
28-
import java.awt.event.MouseAdapter;
29-
import java.awt.event.MouseEvent;
3027
import java.util.List;
3128
import java.util.concurrent.CompletableFuture;
3229
import java.util.concurrent.Executors;
@@ -60,14 +57,14 @@ public BottomPanel() {
6057
} else {
6158
Pair<AbstractTask<?>, CompletableFuture<?>> classCompletableFuturePair = task.get(task.size() - 1);
6259
SwingUtilities.invokeLater(() -> {
63-
int progress = classCompletableFuturePair.getFirst().getProgress();
64-
if (!classCompletableFuturePair.getFirst().getClass().isAnnotationPresent(Indeterminate.class)) {
60+
int progress = classCompletableFuturePair.getKey().getProgress();
61+
if (!classCompletableFuturePair.getKey().getClass().isAnnotationPresent(Indeterminate.class)) {
6562
jProgressBar.setValue(progress);
6663
jProgressBar.setStringPainted(true);
6764
jProgressBar.setIndeterminate(false);
68-
jProgressBar.setString(String.format("%s:%s", classCompletableFuturePair.getFirst().getName(), progress) + "%");
65+
jProgressBar.setString(String.format("%s:%s", classCompletableFuturePair.getKey().getName(), progress) + "%");
6966
} else {
70-
jProgressBar.setString(classCompletableFuturePair.getFirst().getName());
67+
jProgressBar.setString(classCompletableFuturePair.getKey().getName());
7168
jProgressBar.setIndeterminate(true);
7269
}
7370
jProgressBar.repaint();

0 commit comments

Comments
 (0)