Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ Replacement for the Gameband Launcher
This project is an open source replacement of the Gameband + Minecraft launcher.

# Status
So far it can launch the minecraft launcher on macOS.
So far it can launch the Minecraft launcher on macOS and Windows.
At some point a PixelForge replacement will be implemented, though this requires some reverse engineering effort.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ publishing {
}

task nativePackage(type: PackageTask, dependsOn: build) {
mainClass = 'org.opengameband.OpenGameband'
mainClass = 'org.opengameband.Main'
bundleJre = true
generateInstaller = false
administratorRequired = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@ public class LauncherFailiure extends Exception {
public LauncherFailiure() {
super();
}

public LauncherFailiure(String message) {
super(message);
}

public LauncherFailiure(Throwable cause) {
super(cause);
}
}
50 changes: 39 additions & 11 deletions src/main/java/org/opengameband/launcher/BasicLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Objects;
Expand All @@ -26,20 +27,29 @@ public BasicLauncher() {

@Override
public void start() throws LauncherFailiure {
File installDir = getInstallDir();
File gameDataDir = getGameDataDir();
if (installDir == null || gameDataDir == null) {
throw new LauncherFailiure("Launcher directories are not available");
}
Comment on lines +30 to +34
try {
switch (System.getProperty("os.name").split(" ")[0]) {
switch (getOsFamily()) {
case "Mac": {
Runtime.getRuntime().exec(new String[]{GetMountPoint().getAbsolutePath() + "/Launchers/Official/Minecraft.app/Contents/MacOS/launcher",
Runtime.getRuntime().exec(new String[]{new File(installDir, "Contents/MacOS/launcher").getAbsolutePath(),
"--workDir", getGameDataDir().getAbsolutePath()});
break;
}
case "Windows": {
Runtime.getRuntime().exec(new String[]{getInstallDir().getAbsolutePath() + "\\Minecraft.exe",
Runtime.getRuntime().exec(new String[]{new File(installDir, "Minecraft.exe").getAbsolutePath(),
"--workDir", getGameDataDir().getAbsolutePath()});
break;
Comment on lines +30 to +45
}
default:
throw new LauncherFailiure("Unsupported OS: " + System.getProperty("os.name"));
}
} catch (IOException e) {
System.err.println(e.getMessage());
throw new LauncherFailiure();
throw new LauncherFailiure(e);
}
}

Expand All @@ -61,7 +71,7 @@ public void install() {
}

private void extract(String file) {
switch (System.getProperty("os.name").split(" ")[0]) {
switch (getOsFamily()) {
case "Mac":
try {
Process p = Runtime.getRuntime().exec("hdiutil attach " + file);
Expand All @@ -79,12 +89,14 @@ private void extract(String file) {
break;
case "Linux":
throw new RuntimeException("Not Yet Implemented");
default:
break;
}
}

@Override
public File getLauncherDir() {
return new File(GetMountPoint(), "/Launchers/Official");
return Path.of(GetMountPoint().getAbsolutePath(), "Launchers", "Official").toFile();
}

/**
Expand All @@ -93,11 +105,11 @@ public File getLauncherDir() {
@Override
public File getInstallDir() {
if (GetMountPoint().exists() && GetMountPoint().isDirectory() && GetMountPoint().canRead()) {
switch (System.getProperty("os.name").split(" ")[0]) {
switch (getOsFamily()) {
case "Windows":
return new File(getLauncherDir(), "\\win");
return new File(getLauncherDir(), "win");
case "Mac":
return new File(GetMountPoint(), "/Launchers/Official/Minecraft.app");
return new File(getLauncherDir(), "Minecraft.app");
}
}
return null;
Expand All @@ -106,13 +118,29 @@ public File getInstallDir() {
@Override
public File getGameDataDir() {
if (GetMountPoint().exists() && GetMountPoint().isDirectory()) {
return new File(GetMountPoint(), "/Launchers/Official/Game");
return new File(getLauncherDir(), "Game");
}
return null;
}

@Override
public boolean isInstalled() {
return getInstallDir().exists() && getInstallDir().listFiles().length > 0;
File installDir = getInstallDir();
File[] installFiles = installDir == null ? null : installDir.listFiles();
return installDir != null && installDir.exists() && installFiles != null && installFiles.length > 0;
Comment on lines +129 to +130
}

private String getOsFamily() {
String os = System.getProperty("os.name", "").toLowerCase();
if (os.contains("win")) {
return "Windows";
}
if (os.contains("mac")) {
return "Mac";
}
if (os.contains("linux")) {
return "Linux";
}
return "Unknown";
}
}
6 changes: 3 additions & 3 deletions src/main/java/org/opengameband/util/DownloadURLs.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* @author Zaprit
*/
public enum DownloadURLs {
MAC("https://launcher.mojang.com/download/Minecraft.dmg", "/Minecraft.dmg"),
LIN("https://launcher.mojang.com/download/Minecraft.tar.gz", "/Minecraft.tar.gz"),
WIN("https://launcher.mojang.com/download/Minecraft.exe", "\\Minecraft.exe");
MAC("https://launcher.mojang.com/download/Minecraft.dmg", "Minecraft.dmg"),
LIN("https://launcher.mojang.com/download/Minecraft.tar.gz", "Minecraft.tar.gz"),
WIN("https://launcher.mojang.com/download/Minecraft.exe", "Minecraft.exe");

private String url;
private String file;
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/opengameband/util/MountPoint.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opengameband.util;

import java.io.File;
import java.net.URISyntaxException;

/**
* @author Zaprit
Expand All @@ -14,6 +15,14 @@ public MountPoint() {
* TODO: Add the ability to change this as it may be needed later
*/
public static File GetMountPoint(){
return new File(MountPoint.class.getProtectionDomain().getCodeSource().getLocation().getPath());
try {
File codeSourceLocation = new File(MountPoint.class.getProtectionDomain().getCodeSource().getLocation().toURI());
if (codeSourceLocation.isFile()) {
return codeSourceLocation.getParentFile();
}
return codeSourceLocation;
} catch (URISyntaxException e) {
return new File(MountPoint.class.getProtectionDomain().getCodeSource().getLocation().getPath());
Comment on lines +18 to +25
}
}
}
Loading