Skip to content

Commit

Permalink
Add support for Linux user builds
Browse files Browse the repository at this point in the history
  • Loading branch information
epinter committed Aug 6, 2023
1 parent 39c3159 commit d22ee6b
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 21 deletions.
24 changes: 19 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,20 @@ if (!file(javafxSdkDir).directory) {
if (project.hasProperty('buildVersion')) {
project.version = project.properties.get("buildVersion")
}
if (osArch == "amd64") {
ext.appArchiveName = "${distAppName}-${project.version}.zip"
} else {
ext.appArchiveName = "${distAppName}-${project.version}_${osArch}.zip"

ext.appArchiveOs = ""
ext.appArchiveArch = ""

if(!OS.isWindows()) {
ext.appArchiveOs = String.format("-%s",OS.toFamilyName().toLowerCase())
}

if (osArch != "amd64") {
ext.appArchiveArch = String.format("-%s",ext.osArch)
}

ext.appArchiveName = "${distAppName}-${project.version}${ext.appArchiveOs}${ext.appArchiveArch}.zip"

repositories {
mavenCentral()
}
Expand Down Expand Up @@ -379,7 +387,7 @@ task appimage(type: Exec) {
into "$buildDir/app-image/${distAppName}/runtime/bin"
} else {
from javafxSdkLibDir.listFiles().findAll { it.getName().toLowerCase().endsWith('.so') }.collect()
into "$buildDir/app-image/${distAppName}"
into "$buildDir/app-image/${distAppName}/lib/runtime/lib"
}
}
new File(buildDir, "app-image/${distAppName}").listFiles().findAll {
Expand All @@ -396,6 +404,12 @@ task appimage(type: Exec) {
from "${projectDir}/README.md"
into new File(buildDir, "app-image/${distAppName}")
}
copy {
if (OS.isLinux()) {
from "${projectDir}/src/dist/TQRespec.sh"
into new File(buildDir, "app-image/${distAppName}")
}
}
new File(buildDir, "app-image/${distAppName}/savedata").mkdir()
new File(buildDir, "app-image/${distAppName}/gamedata").mkdir()
new File(buildDir, "jre-image").deleteDir()
Expand Down
4 changes: 4 additions & 0 deletions src/dist/TQRespec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
MYDIR=$(realpath "${0%/*}")
cd "$MYDIR"
exec ./bin/TQRespec
5 changes: 1 addition & 4 deletions src/main/java/br/com/pinter/tqrespec/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,7 @@ protected Void call() {
contextMenu.getItems().add(unarchive);

explore.setOnAction(event -> {
try {
Runtime.getRuntime().exec(Constants.EXPLORER_COMMAND + " "
+ charactersTable.getSelectionModel().getSelectedItem().getPath().toString());
} catch (IOException e) {
logger.log(System.Logger.Level.WARNING, "unable to open explorer: ", e);
}
UIUtils.fileExplorer(charactersTable.getSelectionModel().getSelectedItem().getPath().toString());
});
archive.setOnAction(event -> archiveAction(false));
unarchive.setOnAction(event -> archiveAction(true));
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/br/com/pinter/tqrespec/gui/UIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@
package br.com.pinter.tqrespec.gui;

import br.com.pinter.tqrespec.core.State;
import br.com.pinter.tqrespec.logging.Log;
import br.com.pinter.tqrespec.util.Build;
import br.com.pinter.tqrespec.util.Constants;
import javafx.application.Platform;
import javafx.scene.control.Alert;
import javafx.scene.control.Tooltip;
import javafx.stage.Modality;
import javafx.util.Duration;
import org.apache.commons.lang3.SystemUtils;

import java.io.IOException;

public class UIUtils {
private static final System.Logger logger = Log.getLogger(UIUtils.class.getName());

public void showError(String message, String contentText) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.initModality(Modality.APPLICATION_MODAL);
Expand Down Expand Up @@ -73,4 +79,15 @@ public void closeApplication() {
alert.showAndWait();
}

public static void fileExplorer(String path) {
try {
if(SystemUtils.IS_OS_WINDOWS) {
Runtime.getRuntime().exec(new String[]{Constants.EXPLORER_COMMAND,path});
} else {
Runtime.getRuntime().exec(new String[]{Constants.XDGOPEN_COMMAND,path});
}
} catch (IOException e) {
logger.log(System.Logger.Level.WARNING, "unable to open file explorer: ", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ protected FileDataHolder getSaveData() {
@SuppressWarnings("SameParameterValue")
private boolean backupSaveGame(String fileName, String playerName) throws IOException {
File backupDirectory = new File(gameInfo.getSavePath(), Constants.BACKUP_DIRECTORY);
logger.log(System.Logger.Level.INFO, "creating backup at "+backupDirectory.getAbsolutePath());
Path player = Paths.get(fileName);
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HH");
String ts = df.format(new Date());
Expand All @@ -86,7 +87,7 @@ private boolean backupSaveGame(String fileName, String playerName) throws IOExce
}

if (!backupDirectory.exists() && !backupDirectory.mkdir()) {
throw new IOException("Unable to create backup directory");
throw new IOException("Unable to create backup directory at "+backupDirectory.getAbsolutePath());
}

if (backupDirectory.canWrite()) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/br/com/pinter/tqrespec/tqdata/Db.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public void initialize() {
&& !Path.of(gameInfo.getGamePath(), "FORCE_WINDOWS.txt").toFile().exists()
&& (recordExists("Records\\InGameUI\\Player Character\\Mobile\\CharStatsMobile.dbr")
|| recordExists("Records\\xpack\\ui\\hud\\hud_mobile.dbr"))) {
logger.log(System.Logger.Level.INFO, "Mobile database detected. If this database is from Windows version, create the file to force detection: " + Path.of(gameInfo.getGamePath(), "FORCE_WINDOWS.txt").toFile());
logger.log(System.Logger.Level.INFO,
"Mobile database detected. If this database is from Windows version, create the file to force detection: "
+ Path.of(gameInfo.getGamePath(), "FORCE_WINDOWS.txt").toFile());
platform = Platform.MOBILE;
}
}
Expand Down
28 changes: 25 additions & 3 deletions src/main/java/br/com/pinter/tqrespec/tqdata/GameInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,24 @@ private void searchGamepathResources() throws GameNotFoundException {
}
}

private void prepareDevGameSaveData() {
File gamedataSavePath = Paths.get(Constants.DEV_GAMEDATA, Constants.SAVEDATA).toFile();
if(!gamedataSavePath.exists()) {
try {
//noinspection ResultOfMethodCallIgnored
gamedataSavePath.mkdir();
} catch (SecurityException e) {
logger.log(System.Logger.Level.INFO, "unable to create SaveData directory at "+gamedataSavePath.getAbsolutePath());
}
}
}

public String getSavePath() {
String userHome = System.getProperty("user.home");
logger.log(System.Logger.Level.DEBUG, "SavePath: user.home is ''{0}''", userHome);

if (!SystemUtils.IS_OS_WINDOWS) {
prepareDevGameSaveData();
return Constants.DEV_GAMEDATA;
}

Expand Down Expand Up @@ -721,7 +734,10 @@ public String getSaveDataUserArchivedPath() {
}

public String getSaveDataMainPath() {
if (!SystemUtils.IS_OS_WINDOWS) return Paths.get(Constants.DEV_GAMEDATA, Constants.SAVEDATA, "Main").toString();
if (!SystemUtils.IS_OS_WINDOWS) {
prepareDevGameSaveData();
return Paths.get(Constants.DEV_GAMEDATA, Constants.SAVEDATA, "Main").toString();
}
String savePath = getSavePath();
if (StringUtils.isNotEmpty(savePath)) {
return Paths.get(savePath, Constants.SAVEDATA, "Main").toString();
Expand All @@ -730,7 +746,10 @@ public String getSaveDataMainPath() {
}

public String getSaveDataUserPath() {
if (!SystemUtils.IS_OS_WINDOWS) return Paths.get(Constants.DEV_GAMEDATA, Constants.SAVEDATA, "User").toString();
if (!SystemUtils.IS_OS_WINDOWS) {
prepareDevGameSaveData();
return Paths.get(Constants.DEV_GAMEDATA, Constants.SAVEDATA, "User").toString();
}
String savePath = getSavePath();
if (StringUtils.isNotEmpty(savePath)) {
return Paths.get(savePath, Constants.SAVEDATA, "User").toString();
Expand All @@ -739,7 +758,10 @@ public String getSaveDataUserPath() {
}

public String getSaveSetingsPath() {
if (!SystemUtils.IS_OS_WINDOWS) return Paths.get(Constants.DEV_GAMEDATA, Constants.SETTINGS).toString();
if (!SystemUtils.IS_OS_WINDOWS) {
return Paths.get(Constants.DEV_GAMEDATA, Constants.SETTINGS).toString();
}

String savePath = getSavePath();
if (StringUtils.isNotEmpty(savePath)) {
return Paths.get(savePath, Constants.SETTINGS).toString();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/br/com/pinter/tqrespec/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Constants {
public static final int MAX_CHARACTER_NAME_LENGTH = 14;
public static final String ARCHIVE_DIR="ArchivedCharacters";
public static final String EXPLORER_COMMAND="explorer.exe";
public static final String XDGOPEN_COMMAND="xdg-open";
/**
* Maps Game Options language to i18n locale
*/
Expand Down
2 changes: 1 addition & 1 deletion tqdatabase

0 comments on commit d22ee6b

Please sign in to comment.