From f34ddc8d9b6486430b8917b3b56a65e47d8910df Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 16 Feb 2026 12:27:10 -0500 Subject: [PATCH] Earlier version and logging initialization --- core/src/mindustry/Vars.java | 14 ++++++++++++-- core/src/mindustry/core/Version.java | 3 +++ .../src/mindustry/desktop/DesktopLauncher.java | 17 ++++------------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/core/src/mindustry/Vars.java b/core/src/mindustry/Vars.java index 2063cbacf7..e75d82bf83 100644 --- a/core/src/mindustry/Vars.java +++ b/core/src/mindustry/Vars.java @@ -441,8 +441,18 @@ public class Vars implements Loadable{ settings.setAppName(appName); + loadFileLogger(settings.getDataDirectory().child("last_log.txt")); + } + + public static void loadFileLogger(Fi file){ + if(loadedFileLogger) return; + + if(!file.parent().exists()){ + file.parent().mkdirs(); + } + try{ - Writer writer = settings.getDataDirectory().child("last_log.txt").writer(false); + Writer writer = file.writer(false); LogHandler log = Log.logger; Log.logger = (level, text) -> { log.log(level, text); @@ -467,7 +477,7 @@ public class Vars implements Loadable{ settings.setJson(JsonIO.json); settings.setAppName(appName); - if(steam || (Version.modifier != null && Version.modifier.contains("steam"))){ + if(steam || Version.isSteam){ settings.setDataDirectory(Core.files.local("saves/")); } diff --git a/core/src/mindustry/core/Version.java b/core/src/mindustry/core/Version.java index d8981d42c9..b2b59ddafc 100644 --- a/core/src/mindustry/core/Version.java +++ b/core/src/mindustry/core/Version.java @@ -22,6 +22,8 @@ public class Version{ public static int build = 0; /** Revision number. Used for hotfixes. Does not affect server compatibility. */ public static int revision = 0; + /** Whether the Steam version of the game is requested. This is different from Vars.steam (Steam initialization can fail) */ + public static boolean isSteam = false; /** Whether version loading is enabled. */ public static boolean enabled = true; @@ -38,6 +40,7 @@ public class Version{ modifier = map.get("modifier"); commitHash = map.get("commitHash", "unknown"); buildDate = map.get("buildDate", "unknown"); + isSteam = modifier.contains("steam"); if(map.get("build").contains(".")){ String[] split = map.get("build").split("\\."); try{ diff --git a/desktop/src/mindustry/desktop/DesktopLauncher.java b/desktop/src/mindustry/desktop/DesktopLauncher.java index 7cd8c20239..df11bfa846 100644 --- a/desktop/src/mindustry/desktop/DesktopLauncher.java +++ b/desktop/src/mindustry/desktop/DesktopLauncher.java @@ -42,10 +42,11 @@ public class DesktopLauncher extends ClientLauncher{ public static void main(String[] arg){ try{ + Version.init(); Vars.loadLogger(); + Vars.loadFileLogger(new Fi(Version.isSteam ? "saves" : OS.getAppDataDirectoryString(appName)).child("last_log.txt")); check32Bit(); - checkJavaVersion(); new SdlApplication(new DesktopLauncher(arg), new SdlConfig(){{ @@ -129,15 +130,9 @@ public class DesktopLauncher extends ClientLauncher{ static void check32Bit(){ if(OS.isWindows && !OS.is64Bit){ - try{ - Version.init(); - }catch(Throwable ignored){ - } - - boolean steam = Version.modifier != null && Version.modifier.contains("steam"); String versionWarning = ""; - if(steam){ + if(Version.isSteam){ versionWarning = "\n\nIf you are unable to upgrade, consider switching to the legacy v7 branch on Steam, which is the last release that supported 32-bit windows:\n(properties -> betas -> select version-7.0 in the drop-down box)."; }else if(OS.javaVersion.equals("1.8.0_151-1-ojdkbuild")){ //version string of JVM packaged with the 32-bit version of the game on itch/steam versionWarning = "\n\nMake sure you have downloaded the 64-bit version of the game, not the 32-bit one."; @@ -153,9 +148,6 @@ public class DesktopLauncher extends ClientLauncher{ public DesktopLauncher(String[] args){ this.args = args; - Version.init(); - boolean useSteam = Version.modifier.contains("steam"); - if(useDiscord){ Threads.daemon(() -> { try{ @@ -172,8 +164,7 @@ public class DesktopLauncher extends ClientLauncher{ }); } - if(useSteam){ - + if(Version.isSteam){ Events.on(ClientLoadEvent.class, event -> { if(steamError != null){ Core.app.post(() -> Core.app.post(() -> Core.app.post(() -> {