Skip to content

Commit f204415

Browse files
committed
fix: Clean up / Update MD5 task did not confirm before running
1 parent 4412652 commit f204415

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

gui/src/main/java/org/mcphackers/mcp/gui/TaskButton.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import org.mcphackers.mcp.MCP;
1010
import org.mcphackers.mcp.main.MainGUI;
11+
import org.mcphackers.mcp.tasks.Task;
1112
import org.mcphackers.mcp.tasks.mode.TaskMode;
1213

1314
public class TaskButton extends JButton {
@@ -32,7 +33,18 @@ public TaskButton(MainGUI owner, TaskMode task, ActionListener defaultActionList
3233
}
3334

3435
public static ActionListener performTask(MCP mcp, TaskMode mode) {
35-
return event -> enqueueRunnable(() -> mcp.performTask(mode, mcp.getOptions().side));
36+
return event -> enqueueRunnable(() -> {
37+
if (mode.equals(TaskMode.CLEANUP) || mode.equals(TaskMode.UPDATE_MD5)) {
38+
String confirmMessage = mode.equals(TaskMode.CLEANUP) ? MCP.TRANSLATOR.translateKey("mcp.confirmCleanup") : MCP.TRANSLATOR.translateKey("mcp.confirmUpdateMD5");
39+
40+
// This should never throw...
41+
MainGUI main = (MainGUI) mcp;
42+
int response = JOptionPane.showConfirmDialog(main.frame, confirmMessage, MCP.TRANSLATOR.translateKey("mcp.confirmAction"), JOptionPane.YES_NO_OPTION);
43+
if (response == JOptionPane.YES_OPTION) {
44+
mcp.performTask(mode, mcp.getOptions().side);
45+
}
46+
}
47+
});
3648
}
3749

3850
public boolean getEnabled() {

gui/src/main/java/org/mcphackers/mcp/main/MainGUI.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
* GUI implementation of MCP
5656
*/
5757
public class MainGUI extends MCP {
58-
public static final TaskMode[] TASKS = {TaskMode.DECOMPILE, TaskMode.RECOMPILE, TaskMode.REOBFUSCATE, TaskMode.BUILD, TaskMode.UPDATE_MD5, TaskMode.CREATE_PATCH};
58+
public static final TaskMode[] TASKS = {TaskMode.DECOMPILE, TaskMode.RECOMPILE, TaskMode.REOBFUSCATE, TaskMode.BUILD, TaskMode.CREATE_PATCH};
5959
public static final String[] TABS = {"task.decompile", "task.recompile", "task.reobfuscate", "task.build", "options.running"};
6060
public static final TaskParameter[][] TAB_PARAMETERS = {
6161
{TaskParameter.PATCHES, TaskParameter.FERNFLOWER_OPTIONS, TaskParameter.IGNORED_PACKAGES, TaskParameter.OUTPUT_SRC, TaskParameter.DECOMPILE_RESOURCES, TaskParameter.GUESS_GENERICS, TaskParameter.STRIP_GENERICS},
@@ -347,22 +347,6 @@ public TaskButton getButton(TaskMode task) {
347347
}
348348
});
349349
button = new TaskButton(this, task, defaultActionListener);
350-
} else if (task == TaskMode.CLEANUP) {
351-
ActionListener defaultActionListener = event -> Util.enqueueRunnable(() -> {
352-
int response = JOptionPane.showConfirmDialog(frame, MCP.TRANSLATOR.translateKey("mcp.confirmCleanup"), MCP.TRANSLATOR.translateKey("mcp.confirmAction"), JOptionPane.YES_NO_OPTION);
353-
if (response == JOptionPane.YES_OPTION) {
354-
performTask(task, Side.ANY);
355-
}
356-
});
357-
button = new TaskButton(this, task, defaultActionListener);
358-
} else if (task == TaskMode.UPDATE_MD5) {
359-
ActionListener defaultActionListener = event -> Util.enqueueRunnable(() -> {
360-
int response = JOptionPane.showConfirmDialog(frame, MCP.TRANSLATOR.translateKey("mcp.confirmUpdateMD5"), MCP.TRANSLATOR.translateKey("mcp.confirmAction"), JOptionPane.YES_NO_OPTION);
361-
if (response == JOptionPane.YES_OPTION) {
362-
performTask(task, getSide());
363-
}
364-
});
365-
button = new TaskButton(this, task, defaultActionListener);
366350
} else {
367351
button = new TaskButton(this, task);
368352
}

0 commit comments

Comments
 (0)