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

Commit 537730b

Browse files
committed
fix some bugs
1 parent ef33365 commit 537730b

File tree

5 files changed

+54
-30
lines changed

5 files changed

+54
-30
lines changed

.idea/vcs.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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.2'
7+
version '0.2.1'
88
repositories {
99
mavenCentral()
1010
}

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.2";
5+
public static final String APPLICATION_VERSION = "0.2.1";
66

77
}

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

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,16 @@ private void initBottomLayout() {
119119

120120
Stack<Path> instancePathStack = new Stack<>();
121121
try {
122-
String[] pathArr = pathField.getText().split(String.format("\\%s", File.separator));
122+
String pathSeparator = String.format("\\%s", File.separator);
123+
String[] pathArr = (pathField.getText().endsWith(pathSeparator) ?
124+
pathField.getText().substring(0, pathField.getText().lastIndexOf(pathSeparator)-1) :
125+
pathField.getText()
126+
).split(pathSeparator);
127+
System.out.println("Selected Path : " + String.join(pathSeparator, pathArr));
123128
String lastPath = pathArr[pathArr.length - 1];
124129
if (lastPath.contains("*") && lastPath.chars().filter(c -> c == '*').count() == 1) {
125130
pathArr[pathArr.length - 1] = "";
126-
File[] pathFiles = Paths.get(String.join(File.separator, pathArr)).toFile().listFiles();
131+
File[] pathFiles = Paths.get(String.join(pathSeparator, pathArr)).toFile().listFiles();
127132
if (pathFiles == null) {
128133
throw new IllegalAccessException();
129134
}
@@ -147,7 +152,7 @@ private void initBottomLayout() {
147152
}
148153
}
149154
} else {
150-
instancePathStack.push(Paths.get(String.join(File.separator, pathArr)));
155+
instancePathStack.push(Paths.get(String.join(pathSeparator, pathArr)));
151156
}
152157
} catch (Exception exception) {
153158
exception.printStackTrace();
@@ -157,15 +162,21 @@ private void initBottomLayout() {
157162
}
158163

159164
Stack<File> modsFileStack = new Stack<>();
160-
for (Path instancePath : instancePathStack) {
165+
for (Path ip : instancePathStack) {
166+
Path instancePath = ip;
167+
File dotMinecraft = instancePath.resolve(".minecraft").toFile();
168+
if (dotMinecraft.isDirectory()) {
169+
instancePath = instancePath.resolve(".minecraft");
170+
}
171+
161172
Path modsPath = instancePath.resolve("mods");
162-
File instanceDir = modsPath.toFile();
163-
if (!instanceDir.isDirectory()) {
173+
File modsDir = modsPath.toFile();
174+
if (!modsDir.isDirectory()) {
164175
JOptionPane.showMessageDialog(this, "Please select a instance path(directory)!", "Please try again", JOptionPane.ERROR_MESSAGE);
165176
downloadButton.setEnabled(true);
166177
return;
167178
}
168-
modsFileStack.push(instanceDir);
179+
modsFileStack.push(modsDir);
169180
}
170181

171182
if (this.versionSelection.getSelectedItem() == null) {
@@ -178,6 +189,7 @@ private void initBottomLayout() {
178189
int maxCount = 0;
179190
for (Map.Entry<ModData, JCheckBox> modEntry : modCheckBoxes.entrySet()) {
180191
if (modEntry.getValue().isSelected() && modEntry.getValue().isEnabled()) {
192+
System.out.println("Selected "+modEntry.getKey().getName());
181193
targetMods.add(modEntry.getKey());
182194
maxCount++;
183195
}
@@ -214,18 +226,29 @@ private void initBottomLayout() {
214226
ArrayList<ModData> failedMods = new ArrayList<>();
215227
for (ModData targetMod : targetMods) {
216228
this.progressBar.setString("Downloading '" + targetMod.getName() + "'");
217-
if (!targetMod.downloadModJarFile(mcVersion, modsFileStack)) {
229+
System.out.println("Downloading "+targetMod.getName());
230+
Stack<File> downloadFiles = new Stack<>();
231+
downloadFiles.addAll(modsFileStack);
232+
if (!targetMod.downloadModJarFile(mcVersion, downloadFiles)) {
233+
System.out.println("Failed to downloading "+targetMod.getName());
218234
failedMods.add(targetMod);
219235
}
220236
this.progressBar.setValue((int) ((++count / (finalMaxCount * 1f)) * 100));
221237
}
222238
this.progressBar.setValue(100);
223239
ModCheck.setStatus(ModCheckStatus.IDLE);
224240

225-
for (ModData failedMod : failedMods) {
226-
JOptionPane.showMessageDialog(this, "Failed to download '" + failedMod.getName() +"'.", "Please try again", JOptionPane.ERROR_MESSAGE);
241+
System.out.println("Done with download mods");
242+
243+
if (failedMods.size() > 0) {
244+
StringBuilder failedModString = new StringBuilder();
245+
for (ModData failedMod : failedMods) {
246+
failedModString.append(failedMod.getName()).append(", ");
247+
}
248+
JOptionPane.showMessageDialog(this, "Failed to download " + failedModString.substring(0, failedModString.length() - 2) +".", "Please try again", JOptionPane.ERROR_MESSAGE);
249+
} else {
250+
JOptionPane.showMessageDialog(this, "All selected mods have been downloaded!");
227251
}
228-
JOptionPane.showMessageDialog(this, "All selected mods have been downloaded!");
229252
downloadButton.setEnabled(true);
230253
});
231254
});
@@ -374,15 +397,16 @@ public void updateModList() {
374397
}
375398
});
376399

400+
int line = modData.getDescription().split("\n").length;
377401
JLabel description = new JLabel("<html><body>" + modData.getDescription().replace("\n", "<br>") + "</body></html>");
378-
description.setMaximumSize(new Dimension(800, 60));
402+
description.setMaximumSize(new Dimension(800, 60 * line));
379403
description.setBorder(new EmptyBorder(0, 15,0, 0));
380404
Font f = description.getFont();
381405
description.setFont(f.deriveFont(f.getStyle() & ~Font.BOLD));
382406

383407
modPanel.add(checkBox);
384408
modPanel.add(description);
385-
modPanel.setMaximumSize(new Dimension(950, 60));
409+
modPanel.setMaximumSize(new Dimension(950, 60 * line));
386410
modPanel.setBorder(new EmptyBorder(0, 10,10, 0));
387411

388412
versionJPanel.add(modPanel);

src/main/java/com/pistacium/modcheck/mod/resource/ModResource.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.File;
66
import java.io.FileOutputStream;
77
import java.io.IOException;
8+
import java.net.MalformedURLException;
89
import java.net.URL;
910
import java.net.URLConnection;
1011
import java.nio.channels.Channels;
@@ -44,25 +45,24 @@ public String getDownloadUrl() {
4445
return downloadUrl;
4546
}
4647

47-
public void downloadFile(Stack<File> modsPaths) {
48+
public void downloadFile(Stack<File> modsPaths) throws IOException {
4849
if (modsPaths.size() < 1) return;
49-
try {
50-
URL url = new URL(downloadUrl);
50+
URL url = new URL(downloadUrl);
5151

52-
URLConnection con = url.openConnection();
52+
URLConnection con = url.openConnection();
5353

54-
File download = modsPaths.pop().toPath().resolve(fileName).toFile();
54+
File download = modsPaths.pop().toPath().resolve(fileName).toFile();
5555

56-
ReadableByteChannel rbc = Channels.newChannel(con.getInputStream());
57-
try (FileOutputStream fos = new FileOutputStream(download)) {
58-
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
59-
}
56+
ReadableByteChannel rbc = Channels.newChannel(con.getInputStream());
57+
try (FileOutputStream fos = new FileOutputStream(download)) {
58+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
59+
}
60+
System.out.println("Downloaded "+fileName+" in "+download.getPath());
6061

61-
while (modsPaths.size() > 0) {
62-
Files.copy(download.toPath(), modsPaths.pop().toPath().resolve(fileName));
63-
}
64-
} catch (IOException e) {
65-
e.printStackTrace();
62+
while (modsPaths.size() > 0) {
63+
Path copyPath = modsPaths.pop().toPath().resolve(fileName);
64+
Files.copy(download.toPath(), copyPath);
65+
System.out.println("Copied to " + copyPath);
6666
}
6767
}
6868

0 commit comments

Comments
 (0)