Skip to content

Commit

Permalink
Improved architecture detection
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Apr 9, 2023
1 parent 186d13e commit b060fb6
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 50 deletions.
83 changes: 38 additions & 45 deletions GalaxiAPI/base/src/net/ME1312/Galaxi/Library/Platform.java
Expand Up @@ -4,7 +4,6 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Locale;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -13,8 +12,8 @@
*/
public enum Platform {
WINDOWS("Windows", new File((System.getenv("APPDATALOCAL") != null)?System.getenv("APPDATALOCAL"):System.getenv("APPDATA"), "GalaxiEngine")),
MAC_OS("Mac OS", new File(System.getProperty("user.home"), "Library/Application Support/GalaxiEngine")),
UNIX("Unix-based", new File(System.getProperty("user.home"), ".GalaxiEngine")),
MAC_OS("macOS", new File(System.getProperty("user.home"), "Library/Application Support/GalaxiEngine")),
UNIX("Unix-like", new File(System.getProperty("user.home"), ".GalaxiEngine")),
;
private static final Platform OS;
private static final String OS_NAME;
Expand Down Expand Up @@ -148,7 +147,7 @@ public static String getJavaArchitecture() {
OS_VERSION = osversion;
}

final String[] osarch;
String osarch;
if (OS == WINDOWS) {
String osbuild = null;
try {
Expand All @@ -157,49 +156,50 @@ public static String getJavaArchitecture() {
} catch (IOException e) {}

OS_BUILD = osbuild;
osarch = new String[] {
System.getenv("PROCESSOR_ARCHITEW6432"),
System.getenv("PROCESSOR_ARCHITECTURE")
};
if ((osarch = System.getenv("PROCESSOR_ARCHITEW6432")) == null) {
osarch = System.getenv("PROCESSOR_ARCHITECTURE");
}
} else {
OS_BUILD = null;
osarch = new String[] {
System.getProperty("os.arch")
};
osarch = System.getProperty("os.arch");
}

boolean x86 = false;
if (isArch(osarch, arch -> arch.equals("ia64") || arch.equals("em64t") || arch.equals("amd64") || arch.equals("x86_64"))) {
OS_ARCH = "x64";
x86 = true;
} else if (isArch(osarch, arch -> Pattern.compile("^(?:i\\d|x)86$").matcher(arch).find())) {
OS_ARCH = "x86";
x86 = true;
} else {
int i = -1;
String arch = "unknown";
for (int e = 0; e < osarch.length; ++e) if (osarch[e] != null) {
arch = osarch[e].toLowerCase(Locale.ENGLISH);
i = e;
break;
}

if (i == -1 || arch.equals("arm") || arch.equals("arm64")) {
OS_ARCH = arch;
boolean x86 = false;
if (osarch != null) {
osarch = osarch.replaceAll("[^a-zA-Z0-9]", "").toLowerCase(Locale.ROOT);
if (osarch.matches("^((amd|x86|x)64|em64t|ia32e)$")) {
OS_ARCH = "x64"; x86 = true;
} else if (osarch.matches("^((i[3-6]|x)86|(ia|x86|x)32)$")) {
OS_ARCH = "x86"; x86 = true;
} else if (osarch.equals("aarch64") || osarch.equals("arm64")) {
OS_ARCH = "arm64";
} else if (osarch.equals("aarch32") || osarch.startsWith("arm")) {
OS_ARCH = "arm";
} else {
OS_ARCH = osarch[i];
OS_ARCH = osarch;
}
} else {
OS_ARCH = "unknown";
}

String jarch = System.getProperty("sun.arch.data.model", "unknown");
if (!Try.all.run(() -> Long.parseLong(jarch))) {
JAVA_ARCH = jarch;
} else if (x86 && jarch.equals("32")) {
JAVA_ARCH = "x86";
} else if (x86 && jarch.equals("64")) {
JAVA_ARCH = "x64";
} else {
JAVA_ARCH = jarch + "-bit";
final String jarch = System.getProperty("sun.arch.data.model", "unknown");
for (;;) {
if (x86) {
if (jarch.equals("64")) {
JAVA_ARCH = "x64";
break;
} else if (jarch.equals("32")) {
JAVA_ARCH = "x86";
break;
}
}
if (Try.all.run(() -> Long.parseLong(jarch))) {
JAVA_ARCH = jarch + "-bit";
} else {
JAVA_ARCH = jarch;
}
break;
}

String jversion = System.getProperty("java.specification.version");
Expand All @@ -210,11 +210,4 @@ public static String getJavaArchitecture() {
JAVA_LANG = Integer.MAX_VALUE;
}
}

private static boolean isArch(String[] array, Function<String, Boolean> operation) {
for (String object : array) if (object != null && operation.apply(object.toLowerCase(Locale.ENGLISH))) {
return true;
}
return false;
}
}
Expand Up @@ -5,10 +5,7 @@

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.*;
import java.awt.font.TextAttribute;
import java.util.Map;

Expand Down Expand Up @@ -118,6 +115,14 @@ public void actionPerformed(ActionEvent e) {
dispose();
}
});

getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "esc");
getRootPane().getActionMap().put("esc", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
AboutWindow.this.dispose();
}
});
}

public void open() {
Expand Down
Expand Up @@ -8,6 +8,7 @@
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

public class PlatformInfoWindow extends JDialog {
private JPanel window;
Expand Down Expand Up @@ -70,6 +71,14 @@ public void actionPerformed(ActionEvent e) {
}
});

getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "esc");
getRootPane().getActionMap().put("esc", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
PlatformInfoWindow.this.dispose();
}
});

final StringSelection clipboard = new StringSelection(infoText.toString());
final Container<Timer> timer = new Container<>();
copy.setDefaultCapable(false);
Expand Down
2 changes: 1 addition & 1 deletion GalaxiRT/pom.xml
Expand Up @@ -19,7 +19,7 @@
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline</artifactId>
<version>3.22.0</version>
<version>3.23.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down

0 comments on commit b060fb6

Please sign in to comment.