Skip to content

Commit

Permalink
no more null!!
Browse files Browse the repository at this point in the history
  • Loading branch information
not-coded committed May 25, 2024
1 parent 29209c4 commit e344203
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/nexia/installer/util/InstallerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public JPanel setPanel(InstallerGUI gui) {
installLocation = new JTextField(20),
selectFolderButton = new JButton());
selectFolderButton.setText("...");
// It looks better when the width is set to height, so.....
selectFolderButton.setPreferredSize(new Dimension(installLocation.getPreferredSize().height, installLocation.getPreferredSize().height));
selectFolderButton.addActionListener(e -> InstallerGUI.selectInstallLocation(() -> installLocation.getText(), s -> installLocation.setText(s)));

Expand Down Expand Up @@ -109,8 +110,8 @@ public void addRow(Container parent, GridBagConstraints c, boolean last, String
}

public void launch() throws IOException {

String stringGameVersion = (String) gameVersionComboBox.getSelectedItem();
assert stringGameVersion != null;
VersionHandler.GameVersion gameVersion = VersionHandler.identifyGameVersion(stringGameVersion);
if(gameVersion == null) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.List;
import java.util.Objects;

public class FabricInstallerHelper extends InstallerHelper {
public static JButton buttonInstall;
Expand Down Expand Up @@ -52,6 +53,7 @@ public JPanel setPanel(InstallerGUI gui) {
installLocation = new JTextField(20),
selectFolderButton = new JButton());
selectFolderButton.setText("...");
// It looks better when the width is set to height, so.....
selectFolderButton.setPreferredSize(new Dimension(installLocation.getPreferredSize().height, installLocation.getPreferredSize().height));
selectFolderButton.addActionListener(e -> InstallerGUI.selectInstallLocation(() -> installLocation.getText(), s -> installLocation.setText(s)));

Expand All @@ -76,7 +78,7 @@ public JPanel setPanel(InstallerGUI gui) {
buttonFabric = new JButton(Main.BUNDLE.getString("installer.button.fabric")));
buttonFabric.addActionListener(e -> {
try {
Process process = Runtime.getRuntime().exec("java -jar cache/" + getJarFile().getName());
Process process = Runtime.getRuntime().exec("java -jar cache/" + Objects.requireNonNull(getJarFile()).getName());
while(process.isAlive()) {
buttonFabric.setEnabled(false);
}
Expand All @@ -91,8 +93,8 @@ public JPanel setPanel(InstallerGUI gui) {

@Override
public void launch() throws IOException {

String stringGameVersion = (String) gameVersionComboBox.getSelectedItem();
assert stringGameVersion != null;
FabricVersionHandler.GameVersion gameVersion = FabricVersionHandler.identifyGameVersion(stringGameVersion);
if(gameVersion == null) return;

Expand All @@ -104,7 +106,7 @@ public void launch() throws IOException {
}

System.out.println("Installing Fabric " + gameVersion.getVersion() + " (" + gameVersion.getCodeName() + ")");
String[] cmd2 = new String[]{"java", "-jar", "cache/" + getJarFile().getName(), "client", "-dir" + "\"" + mcPath.toAbsolutePath() + "\"", "-mcversion", gameVersion.codeName};
String[] cmd2 = new String[]{"java", "-jar", "cache/" + Objects.requireNonNull(getJarFile()).getName(), "client", "-dir" + "\"" + mcPath.toAbsolutePath() + "\"", "-mcversion", gameVersion.codeName};


try {
Expand Down Expand Up @@ -153,12 +155,12 @@ private File getJarFile() throws IOException {
return new File(cacheDir.toFile(), fileName);
}

if(cacheDir.toFile().listFiles().length == 0) {
if(Objects.requireNonNull(cacheDir.toFile().listFiles()).length == 0) {
Files.delete(cacheDir);
return getJarFile();
}

for(File file : cacheDir.toFile().listFiles()) {
for(File file : Objects.requireNonNull(cacheDir.toFile().listFiles())) {
if(file.getName().equals(fileName)) {
return file;
} else {
Expand Down

0 comments on commit e344203

Please sign in to comment.