Skip to content
This repository was archived by the owner on Aug 18, 2024. It is now read-only.

Commit 67e2823

Browse files
committed
0.2 update
1 parent 7c115af commit 67e2823

File tree

6 files changed

+170
-48
lines changed

6 files changed

+170
-48
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group 'com.redlimerl'
7-
version '0.1.1'
7+
version '0.2'
88
repositories {
99
mavenCentral()
1010
}

src/main/java/com/pistacium/modcheck/ModCheck.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
import com.pistacium.modcheck.util.ModCheckStatus;
88
import com.pistacium.modcheck.util.ModCheckUtils;
99

10+
import javax.swing.*;
11+
import java.awt.*;
12+
import java.awt.datatransfer.Clipboard;
13+
import java.awt.datatransfer.StringSelection;
14+
import java.io.PrintWriter;
15+
import java.io.StringWriter;
1016
import java.util.ArrayList;
1117
import java.util.Objects;
1218
import java.util.concurrent.ExecutorService;
@@ -32,9 +38,10 @@ public static void setStatus(ModCheckStatus status) {
3238

3339

3440
public static void main(String[] args) {
35-
FRAME_INSTANCE = new ModCheckFrame();
3641
THREAD_EXECUTOR.submit(() -> {
3742
try {
43+
FRAME_INSTANCE = new ModCheckFrame();
44+
3845
// Get available versions
3946
setStatus(ModCheckStatus.LOADING_AVAILABLE_VERSIONS);
4047
JsonElement availableElement = JsonParser.parseString(Objects.requireNonNull(ModCheckUtils.getUrlRequest("https://redlime.github.io/MCSRMods/mod_versions.json")));
@@ -56,17 +63,30 @@ public static void main(String[] args) {
5663
FRAME_INSTANCE.getProgressBar().setString("Loading information of "+jsonElement.getAsJsonObject().get("name"));
5764
ModData modData = new ModData(jsonElement.getAsJsonObject());
5865
AVAILABLE_MODS.add(modData);
59-
FRAME_INSTANCE.getProgressBar().setValue((int) (10 + (((++count * 1f) / maxCount) * 90)));
6066
}
6167
} catch (Throwable e) {
6268
LOGGER.log(Level.WARNING, "Failed to init " + jsonElement.getAsJsonObject().get("name").getAsString() + "!", e);
69+
} finally {
70+
FRAME_INSTANCE.getProgressBar().setValue((int) (10 + (((++count * 1f) / maxCount) * 90)));
6371
}
6472
}
6573
FRAME_INSTANCE.getProgressBar().setValue(100);
6674
setStatus(ModCheckStatus.IDLE);
6775
FRAME_INSTANCE.updateVersionList();
6876
} catch (Throwable e) {
69-
LOGGER.log(Level.WARNING, "Exception in Initializing!", e);
77+
StringWriter sw = new StringWriter();
78+
PrintWriter pw = new PrintWriter(sw);
79+
e.printStackTrace(pw);
80+
int result = JOptionPane.showOptionDialog(null, sw.toString(), "Error exception!",
81+
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null,
82+
new String[] { "Copy to Clipboard", "Cancel" }, "Copy to Clipboard");
83+
if (result == 0) {
84+
StringSelection selection = new StringSelection(sw.toString());
85+
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
86+
clipboard.setContents(selection, selection);
87+
}
88+
89+
System.exit(0);
7090
}
7191
});
7292
//System.out.println(new Gson().toJson(ModCheckUtils.getFabricJsonFileInJar(new File("D:/MultiMC/instances/1.16-1/.minecraft/mods/SpeedRunIGT-10.0+1.16.1.jar"))));

src/main/java/com/pistacium/modcheck/ModCheckConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
public class ModCheckConstants {
44

5-
public static final String APPLICATION_VERSION = "0.1";
5+
public static final String APPLICATION_VERSION = "0.2";
66

77
}

src/main/java/com/pistacium/modcheck/ModCheckFrame.java

Lines changed: 132 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
package com.pistacium.modcheck;
22

3+
import com.google.gson.JsonObject;
4+
import com.google.gson.JsonParser;
35
import com.pistacium.modcheck.mod.ModData;
46
import com.pistacium.modcheck.mod.resource.ModResource;
57
import com.pistacium.modcheck.mod.version.ModVersion;
68
import com.pistacium.modcheck.util.ModCheckStatus;
9+
import com.pistacium.modcheck.util.ModCheckUtils;
710

811
import javax.swing.*;
912
import javax.swing.border.EmptyBorder;
13+
import javax.swing.plaf.FontUIResource;
1014
import java.awt.*;
1115
import java.io.File;
1216
import java.net.URI;
13-
import java.nio.file.InvalidPathException;
1417
import java.nio.file.Path;
1518
import java.nio.file.Paths;
16-
import java.util.ArrayList;
17-
import java.util.HashMap;
18-
import java.util.Map;
19-
import java.util.Objects;
19+
import java.util.*;
2020

21+
@SuppressWarnings("ResultOfMethodCallIgnored")
2122
public class ModCheckFrame extends JFrame {
2223

24+
private static final FontUIResource font = new FontUIResource("SansSerif", Font.BOLD, 15);
25+
2326
private final JPanel mainPanel;
2427
private JProgressBar progressBar;
2528
private JComboBox<ModVersion> versionSelection;
@@ -35,6 +38,7 @@ public JProgressBar getProgressBar() {
3538

3639
ModCheckFrame() {
3740
super("ModCheck v"+ ModCheckConstants.APPLICATION_VERSION + " by RedLime");
41+
setUIFont();
3842

3943
mainPanel = new JPanel(new BorderLayout());
4044

@@ -48,13 +52,23 @@ public JProgressBar getProgressBar() {
4852

4953
getContentPane().add(mainPanel);
5054

51-
setSize(800, 550);
55+
setSize(1100, 700);
5256
setResizable(false);
5357
setVisible(true);
5458
setLocationRelativeTo(null);
5559
setDefaultCloseOperation(EXIT_ON_CLOSE);
5660
}
5761

62+
private static void setUIFont(){
63+
Enumeration<?> keys = UIManager.getLookAndFeelDefaults().keys();
64+
while (keys.hasMoreElements()) {
65+
Object key = keys.nextElement();
66+
Object value = UIManager.get(key);
67+
if (value instanceof FontUIResource)
68+
UIManager.put(key, ModCheckFrame.font);
69+
}
70+
}
71+
5872
private void initHeaderLayout() {
5973
JPanel instanceSelectPanel = new JPanel();
6074

@@ -82,52 +96,71 @@ private void initBottomLayout() {
8296
progressBar = new JProgressBar();
8397
progressBar.setStringPainted(true);
8498
progressBar.setString("Idle...");
85-
progressBar.setPreferredSize(new Dimension(300, 20));
99+
progressBar.setPreferredSize(new Dimension(500, 30));
86100

87101
JPanel buttonPanel = new JPanel(new GridLayout(2, 1));
88102
JCheckBox jCheckBox = new JCheckBox("Delete all old .jar files");
89103
downloadButton = new JButton("Download");
90104
downloadButton.addActionListener(e -> {
91105
downloadButton.setEnabled(false);
92106

93-
Path instancePath;
107+
Stack<Path> instancePathStack = new Stack<>();
94108
try {
95-
instancePath = Paths.get(pathField.getText());
96-
} catch (InvalidPathException exception) {
109+
String[] pathArr = pathField.getText().split(String.format("\\%s", File.separator));
110+
String lastPath = pathArr[pathArr.length - 1];
111+
if (lastPath.contains("*") && lastPath.chars().filter(c -> c == '*').count() == 1) {
112+
pathArr[pathArr.length - 1] = "";
113+
File[] pathFiles = Paths.get(String.join(File.separator, pathArr)).toFile().listFiles();
114+
if (pathFiles == null) {
115+
throw new IllegalAccessException();
116+
}
117+
118+
if (lastPath.equals("*")) {
119+
for (File pathFile : pathFiles) {
120+
if (pathFile.isDirectory()) instancePathStack.push(pathFile.toPath());
121+
}
122+
} else if (lastPath.startsWith("*")) {
123+
for (File pathFile : pathFiles) {
124+
if (pathFile.isDirectory() && pathFile.getName().endsWith(lastPath.replace("*", ""))) instancePathStack.push(pathFile.toPath());
125+
}
126+
} else if (lastPath.endsWith("*")) {
127+
for (File pathFile : pathFiles) {
128+
if (pathFile.isDirectory() && pathFile.getName().startsWith(lastPath.replace("*", ""))) instancePathStack.push(pathFile.toPath());
129+
}
130+
} else {
131+
String[] split = lastPath.split("\\*");
132+
for (File pathFile : pathFiles) {
133+
if (pathFile.isDirectory() && pathFile.getName().startsWith(split[0]) && pathFile.getName().endsWith(split[1])) instancePathStack.push(pathFile.toPath());
134+
}
135+
}
136+
} else {
137+
instancePathStack.push(Paths.get(String.join(File.separator, pathArr)));
138+
}
139+
} catch (Exception exception) {
140+
exception.printStackTrace();
97141
JOptionPane.showMessageDialog(this, "Failed to parsing Instance path!", "Please try again", JOptionPane.ERROR_MESSAGE);
98142
downloadButton.setEnabled(true);
99143
return;
100144
}
101-
if (!instancePath.toString().endsWith("mods")) instancePath = instancePath.resolve("mods");
102-
File instanceDir = instancePath.toFile();
103-
if (!instanceDir.isDirectory()) {
104-
JOptionPane.showMessageDialog(this, "Please select a instance path(directory)!", "Please try again", JOptionPane.ERROR_MESSAGE);
105-
downloadButton.setEnabled(true);
106-
return;
107-
}
108145

109-
if (jCheckBox.isSelected()) {
110-
File[] modFiles = instanceDir.listFiles();
111-
if (modFiles == null) return;
112-
for (File file : modFiles) {
113-
if (file.getName().endsWith(".jar"))
114-
//noinspection ResultOfMethodCallIgnored
115-
file.delete();
146+
Stack<File> modsFileStack = new Stack<>();
147+
for (Path instancePath : instancePathStack) {
148+
Path modsPath = instancePath.resolve("mods");
149+
File instanceDir = modsPath.toFile();
150+
if (!instanceDir.isDirectory()) {
151+
JOptionPane.showMessageDialog(this, "Please select a instance path(directory)!", "Please try again", JOptionPane.ERROR_MESSAGE);
152+
downloadButton.setEnabled(true);
153+
return;
116154
}
155+
modsFileStack.push(instanceDir);
117156
}
118157

119-
120158
if (this.versionSelection.getSelectedItem() == null) {
121159
JOptionPane.showMessageDialog(this, "??? What are you doing");
122160
downloadButton.setEnabled(true);
123161
return;
124162
}
125163

126-
ModVersion mcVersion = (ModVersion) this.versionSelection.getSelectedItem();
127-
this.progressBar.setValue(0);
128-
ModCheck.setStatus(ModCheckStatus.DOWNLOADING_MOD_FILE);
129-
130-
Path finalInstancePath = instancePath;
131164
ArrayList<ModData> targetMods = new ArrayList<>();
132165
int maxCount = 0;
133166
for (Map.Entry<ModData, JCheckBox> modEntry : modCheckBoxes.entrySet()) {
@@ -136,14 +169,39 @@ private void initBottomLayout() {
136169
maxCount++;
137170
}
138171
}
172+
ModVersion mcVersion = (ModVersion) this.versionSelection.getSelectedItem();
173+
174+
for (File instanceDir : modsFileStack) {
175+
File[] modFiles = instanceDir.listFiles();
176+
if (modFiles == null) return;
177+
for (File file : modFiles) {
178+
if (file.getName().endsWith(".jar")) {
179+
if (jCheckBox.isSelected()) {
180+
file.delete();
181+
} else {
182+
String modFileName = file.getName().split(ModVersion.versionRegex.pattern())[0]
183+
.split(ModVersion.snapshotRegex.pattern())[0];
184+
for (ModData targetMod : targetMods) {
185+
String targetModFileName = targetMod.getLatestVersionResource(mcVersion).getFileName();
186+
if (targetModFileName.startsWith(modFileName)) {
187+
file.delete();
188+
}
189+
}
190+
}
191+
}
192+
}
193+
}
194+
195+
this.progressBar.setValue(0);
196+
ModCheck.setStatus(ModCheckStatus.DOWNLOADING_MOD_FILE);
139197

140198
int finalMaxCount = maxCount;
141199
ModCheck.THREAD_EXECUTOR.submit(() -> {
142200
int count = 0;
143201
ArrayList<ModData> failedMods = new ArrayList<>();
144202
for (ModData targetMod : targetMods) {
145203
this.progressBar.setString("Downloading '" + targetMod.getName() + "'");
146-
if (!targetMod.downloadModJarFile(mcVersion, finalInstancePath)) {
204+
if (!targetMod.downloadModJarFile(mcVersion, modsFileStack)) {
147205
failedMods.add(targetMod);
148206
}
149207
this.progressBar.setValue((int) ((++count / (finalMaxCount * 1f)) * 100));
@@ -179,7 +237,7 @@ private void initCenterLayout() {
179237
versionJPanel = new JPanel();
180238
versionJPanel.setLayout(new BoxLayout(versionJPanel, BoxLayout.Y_AXIS));
181239
versionScrollPane = new JScrollPane(versionJPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
182-
versionScrollPane.setPreferredSize(new Dimension(600, 300));
240+
versionScrollPane.setPreferredSize(new Dimension(1000, 500));
183241
versionScrollPane.getVerticalScrollBar().setUnitIncrement(16);
184242

185243
JPanel selectButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
@@ -206,21 +264,59 @@ private void initCenterLayout() {
206264
centerPanel.add(versionSelectPanel);
207265
centerPanel.add(selectButtonPanel);
208266
centerPanel.add(versionScrollPane);
267+
centerPanel.setBorder(BorderFactory.createEmptyBorder(0, 30, 0, 30));
209268
mainPanel.add(centerPanel, BorderLayout.CENTER);
210269
}
211270

212271
public void initMenuBar() {
213272
JMenuBar menuBar = new JMenuBar();
214273

215-
JMenu source = new JMenu("Source...");
216-
JMenuItem githubSource = new JMenuItem("Github");
274+
JMenu source = new JMenu("Info");
275+
276+
JMenuItem githubSource = new JMenuItem("Github...");
217277
githubSource.addActionListener(e -> {
218278
try {
219279
Desktop.getDesktop().browse(new URI("https://github.com/RedLime/ModCheck"));
220280
} catch (Exception ignored) {
221281
}
222282
});
223283
source.add(githubSource);
284+
285+
JMenuItem donateSource = new JMenuItem("Support...");
286+
donateSource.addActionListener(e -> {
287+
try {
288+
Desktop.getDesktop().browse(new URI("https://ko-fi.com/redlimerl"));
289+
} catch (Exception ignored) {
290+
}
291+
});
292+
source.add(donateSource);
293+
294+
JMenuItem checkChangeLogSource = new JMenuItem("Changelog...");
295+
checkChangeLogSource.addActionListener(e -> {
296+
try {
297+
Desktop.getDesktop().browse(new URI("https://github.com/RedLime/ModCheck/releases/tag/"+ModCheckConstants.APPLICATION_VERSION));
298+
} catch (Exception ignored) {
299+
}
300+
});
301+
source.add(checkChangeLogSource);
302+
303+
JMenuItem updateCheckSource = new JMenuItem("Check new update");
304+
updateCheckSource.addActionListener(e -> {
305+
try {
306+
JsonObject jsonObject = JsonParser.parseString(ModCheckUtils.getUrlRequest("https://api.github.com/repos/RedLime/ModCheck/releases/latest")).getAsJsonObject();
307+
if (ModVersion.of(jsonObject.get("tag_name").getAsString()).compareTo(ModVersion.of(ModCheckConstants.APPLICATION_VERSION)) > 0) {
308+
int result = JOptionPane.showOptionDialog(null, "<html><body>Found new ModCheck update!<br><br>Current Version : " + ModCheckConstants.APPLICATION_VERSION + "<br>Updated Version : " + jsonObject.get("tag_name").getAsString() + "</body></html>","Update Checker", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, new String[] { "Download", "Cancel" }, "Download");
309+
if (result == 0) {
310+
Desktop.getDesktop().browse(new URI("https://github.com/RedLime/ModCheck/releases/latest"));
311+
}
312+
} else {
313+
JOptionPane.showMessageDialog(this, "You are using latest version!");
314+
}
315+
} catch (Exception ignored) {
316+
}
317+
});
318+
source.add(updateCheckSource);
319+
224320
menuBar.add(source);
225321

226322
this.setJMenuBar(menuBar);
@@ -266,14 +362,14 @@ public void updateModList() {
266362
});
267363

268364
JLabel description = new JLabel("<html><body>" + modData.getDescription().replace("\n", "<br>") + "</body></html>");
269-
description.setMaximumSize(new Dimension(500, 60));
365+
description.setMaximumSize(new Dimension(800, 60));
270366
description.setBorder(new EmptyBorder(0, 15,0, 0));
271367
Font f = description.getFont();
272368
description.setFont(f.deriveFont(f.getStyle() & ~Font.BOLD));
273369

274370
modPanel.add(checkBox);
275371
modPanel.add(description);
276-
modPanel.setMaximumSize(new Dimension(600, 60));
372+
modPanel.setMaximumSize(new Dimension(950, 60));
277373
modPanel.setBorder(new EmptyBorder(0, 10,10, 0));
278374

279375
versionJPanel.add(modPanel);

src/main/java/com/pistacium/modcheck/mod/ModData.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
import com.pistacium.modcheck.mod.version.VersionPick;
88
import com.pistacium.modcheck.util.ModCheckUtils;
99

10+
import java.io.File;
1011
import java.nio.file.Path;
11-
import java.util.ArrayList;
12-
import java.util.List;
13-
import java.util.Locale;
14-
import java.util.Objects;
12+
import java.util.*;
1513

1614
public class ModData {
1715
private final String name;
@@ -118,7 +116,7 @@ public ModResource getLatestVersionResource(ModVersion minecraftVersion) {
118116
return resource;
119117
}
120118

121-
public boolean downloadModJarFile(ModVersion minecraftVersion, Path instancePath) {
119+
public boolean downloadModJarFile(ModVersion minecraftVersion, Stack<File> instancePath) {
122120
ModResource resource = getLatestVersionResource(minecraftVersion);
123121
if (resource != null) {
124122
try {

0 commit comments

Comments
 (0)