Skip to content

Commit

Permalink
fix: fail if launcher folders can't be created or accessed
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyker committed Oct 28, 2024
1 parent c2e7db6 commit c568522
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
5 changes: 1 addition & 4 deletions src/main/java/net/technicpack/launcher/LauncherMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,7 @@ private static void checkIfRunningInsideOneDrive(File launcherRoot) {
private static void setupLogging(LauncherDirectories directories, ResourceLoader resources) {
System.out.println("Setting up logging");
final Logger logger = Utils.getLogger();
File logDirectory = new File(directories.getLauncherDirectory(), "logs");
if (!logDirectory.exists()) {
logDirectory.mkdir();
}
File logDirectory = directories.getLogsDirectory();
File logs = new File(logDirectory, "techniclauncher_%D.log");
RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import net.technicpack.launchercore.install.LauncherDirectories;

import javax.swing.JOptionPane;
import java.io.File;

public class TechnicLauncherDirectories implements LauncherDirectories {
Expand All @@ -29,46 +30,67 @@ public TechnicLauncherDirectories(File rootDir) {
workDir = rootDir;
}

private void ensureDirectory(File dir) {
if (dir.exists() && dir.isDirectory()) {
return;
}

if (dir.exists() && !dir.isDirectory()) {
if (!dir.delete()) {
JOptionPane.showMessageDialog(null, "Failed to create directory " + dir.getAbsolutePath() + ".\nThis is a critical error, the launcher will terminate now.", "Critical error - Technic Launcher", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
}

if (!dir.mkdirs()) {
JOptionPane.showMessageDialog(null, "Failed to create directory " + dir.getAbsolutePath() + ".\nThis is a critical error, the launcher will terminate now.", "Critical error - Technic Launcher", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
}

public File getLauncherDirectory() {
if (!workDir.exists())
workDir.mkdirs();
ensureDirectory(workDir);

return workDir;
}

public File getCacheDirectory() {
File cache = new File(getLauncherDirectory(), "cache");
if (!cache.exists()) {
cache.mkdirs();
}

ensureDirectory(cache);

return cache;
}

public File getAssetsDirectory() {
File assets = new File(getLauncherDirectory(), "assets");

if (!assets.exists()) {
assets.mkdirs();
}
ensureDirectory(assets);

return assets;
}

public File getModpacksDirectory() {
File modpacks = new File(getLauncherDirectory(), "modpacks");

if (!modpacks.exists())
modpacks.mkdirs();
ensureDirectory(modpacks);

return modpacks;
}

public File getRuntimesDirectory() {
File runtimes = new File(getLauncherDirectory(), "runtimes");

if (!runtimes.exists())
runtimes.mkdirs();
ensureDirectory(runtimes);

return runtimes;
}

public File getLogsDirectory() {
File logs = new File(getLauncherDirectory(), "logs");

ensureDirectory(logs);

return logs;
}
}

0 comments on commit c568522

Please sign in to comment.