diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1b58bd7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +# Set default behavior to automatically normalize line endings. +* text=auto + +# Force bash scripts to always use LF line endings so that if a repo is accessed +# in Unix via a file share from Windows, the scripts will work. +*.sh text eol=lf \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f7481d2 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,56 @@ +name: Release Build + +on: + release: + types: [created] + +jobs: + build: + runs-on: windows-latest + + steps: + - uses: actions/checkout@v2 + + - name: Get Version + id: get_version + shell: bash + run: | + echo "Reading version from file:" + cat res/ATCS_latest + echo "" + VERSION=$(tr -d '[:space:]' < "res/ATCS_latest") + echo "Processed version: $VERSION" + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "Environment variable set to: $VERSION" + + - name: Set up JDK + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'temurin' + + - name: Build JAR + shell: bash + run: | + cd packaging + chmod +x package.sh + echo "Building JAR and ZIP for version: ${{ env.VERSION }}" + ./package.sh -windows + echo "Created artifacts:" + ls -la common/ATCS.jar + ls -la ATCS_${{ env.VERSION }}.zip + + - name: Install NSIS + uses: joncloud/makensis-action@v4 + with: + script-file: packaging/Windows/ATCS_Installer.nsi + arguments: /DVERSION="${{ env.VERSION }}" + + - name: Upload Release Assets + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + files: | + ./packaging/ATCS_${{ env.VERSION }}.zip + ./packaging/ATCS_${{ env.VERSION }}_Setup.exe diff --git a/hacked-libtiled/tiled/core/TileSet.java b/hacked-libtiled/tiled/core/TileSet.java index fcacaf7..3551728 100644 --- a/hacked-libtiled/tiled/core/TileSet.java +++ b/hacked-libtiled/tiled/core/TileSet.java @@ -98,7 +98,11 @@ public class TileSet implements Iterable File f = new File(imgFilename); - BufferedImage image = ImageIO.read(f.getCanonicalFile()); + BufferedImage image; + try { + image = ImageIO.read(f.getCanonicalFile()); + } catch (IOException e) { throw new IOException("Failed to load " + imgFilename); + } if (image == null) { throw new IOException("Failed to load " + imgFilename); } diff --git a/packaging/Linux/.gitignore b/packaging/Linux/.gitignore deleted file mode 100644 index 7f160db..0000000 --- a/packaging/Linux/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/ATCS_v*.zip -/ATCS_v*.zip.rename diff --git a/packaging/Linux/ATCS/ATCS.cmd b/packaging/Linux/ATCS/ATCS.cmd deleted file mode 100644 index 8506aed..0000000 --- a/packaging/Linux/ATCS/ATCS.cmd +++ /dev/null @@ -1,20 +0,0 @@ -@echo off - -set "ATCS_DIR=%~dp0" -set "MAX_MEM=512M" -set "CP=%ATCS_DIR%lib\*" -set "JAVA=javaw.exe" -set "JAVA_OPTS=-DFONT_SCALE=1.0 -Dswing.aatext=true" -set "ENV_FILE=%ATCS_DIR%ATCS.env.bat" -set "MAIN_CLASS=com.gpl.rpg.atcontentstudio.ATContentStudio" - -if exist "%ENV_FILE%" ( - call "%ENV_FILE%" -) else ( - echo REM set "MAX_MEM=%MAX_MEM%">"%ENV_FILE%" - echo REM set "JAVA=%JAVA%">>"%ENV_FILE%" - echo REM set "JAVA_OPTS=%JAVA_OPTS%">>"%ENV_FILE%" - echo.>>"%ENV_FILE%" -) - -start "" "%JAVA%" %JAVA_OPTS% -Xmx%MAX_MEM% -cp "%CP%" %MAIN_CLASS% diff --git a/packaging/Linux/ATCS/ATCS.ico b/packaging/Linux/ATCS/ATCS.ico deleted file mode 100644 index 4f829e4..0000000 Binary files a/packaging/Linux/ATCS/ATCS.ico and /dev/null differ diff --git a/packaging/Linux/ATCS/ATCS.sh b/packaging/Linux/ATCS/ATCS.sh deleted file mode 100644 index 16f4398..0000000 --- a/packaging/Linux/ATCS/ATCS.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -ATCS_DIR=$(dirname $(readlink -f "$0" || greadlink -f "$0" || stat -f "$0")) -MAX_MEM=512M -CP=$(find ${ATCS_DIR}/lib/ -name '*.jar' | paste -sd: -) -JAVA=java -JAVA_OPTS='-DFONT_SCALE=1.0 -Dswing.aatext=true' -ENV_FILE=${ATCS_DIR}/ATCS.env -MAIN_CLASS=com.gpl.rpg.atcontentstudio.ATContentStudio - -if [ -f ${ENV_FILE} ] -then - source ${ENV_FILE} -else - echo "#MAX_MEM=${MAX_MEM}" > ${ENV_FILE} - echo "#JAVA=${JAVA}" >> ${ENV_FILE} - echo "#JAVA_OPTS=${JAVA_OPTS}" >> ${ENV_FILE} - echo "" >> ${ENV_FILE} -fi - -export ENV_FILE - -$JAVA ${JAVA_OPTS} -Xmx${MAX_MEM} -cp ${CP} ${MAIN_CLASS} diff --git a/packaging/Linux/ATCS/lib/.gitignore b/packaging/Linux/ATCS/lib/.gitignore deleted file mode 100644 index 0557829..0000000 --- a/packaging/Linux/ATCS/lib/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/*.jar diff --git a/packaging/Windows/ATCS_Installer.nsi b/packaging/Windows/ATCS_Installer.nsi index 8dcfada..b671470 100644 --- a/packaging/Windows/ATCS_Installer.nsi +++ b/packaging/Windows/ATCS_Installer.nsi @@ -1,12 +1,12 @@ !include MUI2.nsh -!define VERSION "0.6.21" +; Version will be passed as /DVERSION=vx.x.x !define TRAINER_VERSION "0.1.5" !define JAVA_BIN "java" -!define ATCS_SOURCE_DIR "C:\ATCS" +!define ATCS_SOURCE_DIR "..\..\" -Name "Andor's Trail Content Studio v${VERSION}" -OutFile "ATCS_v${VERSION}_Setup.exe" +Name "Andor's Trail Content Studio ${VERSION}" +OutFile "..\ATCS_${VERSION}_Setup.exe" InstallDir "$PROGRAMFILES\ATCS\" ;SetCompressor /SOLID /FINAL lzma @@ -14,10 +14,10 @@ InstallDir "$PROGRAMFILES\ATCS\" Var StartMenuFolder !define MUI_WELCOMEPAGE_TITLE "Welcome to Andor's Trail Content Studio installer" -!define MUI_WELCOMEPAGE_TEXT "This will install Andor's Trail Content Studio v${VERSION}" -!define MUI_FINISHPAGE_TEXT "Andor's Trail Content Studio v${VERSION} - Install completed !" +!define MUI_WELCOMEPAGE_TEXT "This will install Andor's Trail Content Studio ${VERSION}" +!define MUI_FINISHPAGE_TEXT "Andor's Trail Content Studio ${VERSION} - Install completed !" !define MUI_STARTMENUPAGE_DEFAULTFOLDER "Andor's Trail Content Studio" -!define MUI_PAGE_HEADER_TEXT "Installing Andor's Trail Content Studio v${VERSION}" +!define MUI_PAGE_HEADER_TEXT "Installing Andor's Trail Content Studio ${VERSION}" ;Start Menu Folder Page Configuration @@ -86,23 +86,23 @@ Section install FileClose $9 WriteUninstaller "$INSTDIR\Uninstall.exe" - - + + !insertmacro MUI_STARTMENU_WRITE_BEGIN "ATCS" - + ;--- Create shortcuts CreateDirectory "$SMPROGRAMS\$StartMenuFolder" CreateShortcut "$SMPROGRAMS\$StartMenuFolder\Andor's Trail Content Studio.lnk" "$INSTDIR\ATCS.cmd" "" "$INSTDIR\ATCS.ico" CreateShortcut "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk" "$INSTDIR\Uninstall.exe" - + !insertmacro MUI_STARTMENU_WRITE_END - + SectionEnd ;------------------------------------------------------------------------------------ Section uninstall - + Delete "$INSTDIR\lib\jide-oss.jar" Delete "$INSTDIR\lib\ui.jar" Delete "$INSTDIR\lib\junit-4.10.jar" @@ -120,13 +120,13 @@ Section uninstall Delete "$INSTDIR\ATCS.jar" Delete "$INSTDIR\Uninstall.exe" RMDir "$INSTDIR" - + !insertmacro MUI_STARTMENU_GETFOLDER "ATCS" $StartMenuFolder - + Delete "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk" Delete "$SMPROGRAMS\$StartMenuFolder\Andor's Trail Content Studio.lnk" RMDir "$SMPROGRAMS\$StartMenuFolder" - + SectionEnd @@ -138,28 +138,28 @@ Function GetJRE ; 2 - in JAVA_HOME environment variable ; 3 - in the registry ; 4 - assume java.exe in current dir or PATH - + Push $R0 Push $R1 - + ;ClearErrors ;StrCpy $R0 "$EXEDIR\jre\bin\java.exe" ;IfFileExists $R0 JreFound ;StrCpy $R0 "" - + ClearErrors ReadEnvStr $R0 "JAVA_HOME" StrCpy $R0 "$R0\bin\${JAVA_BIN}.exe" IfErrors 0 JreFound - + ClearErrors ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion" ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R1" "JavaHome" StrCpy $R0 "$R0\bin\${JAVA_BIN}.exe" - + IfErrors 0 JreFound StrCpy $R0 "${JAVA_BIN}.exe" - + JreFound: Pop $R1 Exch $R0 diff --git a/packaging/common/ATCS.sh b/packaging/common/ATCS.sh index 41d78b2..61086ba 100755 --- a/packaging/common/ATCS.sh +++ b/packaging/common/ATCS.sh @@ -1,21 +1,26 @@ #!/bin/bash -ATCS_DIR=$(dirname $(readlink -f "$0" || greadlink -f "$0" || stat -f "$0")) +ATCS_DIR="$(dirname "$(readlink -f "$0" || greadlink -f "$0" || stat -f "$0")")" +echo "ATCS_DIR: '${ATCS_DIR}'" -MAX_MEM=512M - -JAVA=java +MAX_MEM="512M" +JAVA="java" JAVA_OPTS='-DFONT_SCALE=1.0 -Dswing.aatext=true' -ENV_FILE=${ATCS_DIR}/ATCS.env -if [ -f ${ENV_FILE} ]; then - source ${ENV_FILE} +ENV_FILE="${ATCS_DIR}/ATCS.env" + +if [ -f "${ENV_FILE}" ]; then + source "${ENV_FILE}" else - echo "#MAX_MEM=${MAX_MEM}" >${ENV_FILE} - echo "#JAVA=${JAVA}" >>${ENV_FILE} - echo "#JAVA_OPTS=${JAVA_OPTS}" >>${ENV_FILE} - echo "" >>${ENV_FILE} + { + echo "#MAX_MEM=\"${MAX_MEM}\"" + echo "#JAVA=\"${JAVA}\"" + echo "#JAVA_OPTS=\"${JAVA_OPTS}\"" + echo "" + }>"${ENV_FILE}" fi export ENV_FILE -$JAVA ${JAVA_OPTS} -Xmx${MAX_MEM} -jar ${ATCS_DIR}/ATCS.jar +# shellcheck disable=SC2086 +# (spellchecker is disabled for this line, because we want it to be split into multiple arguments) +$JAVA ${JAVA_OPTS} -Xmx${MAX_MEM} -jar "${ATCS_DIR}/ATCS.jar" diff --git a/packaging/package.sh b/packaging/package.sh index 94fe1f1..0ff0145 100755 --- a/packaging/package.sh +++ b/packaging/package.sh @@ -18,10 +18,9 @@ ATCS_SOURCE_DIR=$(dirname "${PACKAGING_DIR}") TEMP_DIR="${PACKAGING_DIR}/tmp" JAR_LOCATION="${PACKAGING_DIR}/ATCS.jar" # Output JAR location as per script MANIFEST_LOCATION="${PACKAGING_DIR}/Manifest.txt" -VERSION_FILE="${PACKAGING_DIR}/ATCS_latest" +VERSION_FILE="${ATCS_SOURCE_DIR}/res/ATCS_latest" SOURCE_BASE_DIR="${ATCS_SOURCE_DIR}/src" # Base directory for standard source code LIB_BASE_DIR="${ATCS_SOURCE_DIR}/lib" # Base directory for libraries -OUTPUT_JAR_DIR="${PACKAGING_DIR}" # Directory where the final JAR will be placed - as per script # --- **ADDITIONAL SOURCE CODE FOLDERS** --- EXTRA_SOURCE_DIRS=( @@ -30,7 +29,7 @@ EXTRA_SOURCE_DIRS=( "siphash-zackehh/src/main/java" ) -# --- Libraries to include (from IntelliJ artifact definition) --- +# --- Libraries to include --- LIBRARIES=( "AndorsTrainer_v0.1.5.jar" "bsh-2.0b4.jar" @@ -45,7 +44,7 @@ LIBRARIES=( # --- Get version --- echo "Getting version" -VERSION=$(cat "${VERSION_FILE}") +VERSION=$(tr -d '[:space:]' < "${VERSION_FILE}") echo "Got version ${VERSION}" # --- Prepare temporary directory --- @@ -63,7 +62,7 @@ done # --- Set ClassPath --- echo "Getting source files" -# Find all java files in source directories and compile them +# Find all java files in source directories SOURCE_FILES=$(find "${SOURCE_BASE_DIR}" "${EXTRA_SOURCE_DIRS[@]/#/${ATCS_SOURCE_DIR}/}" -name "*.java" -print) #echo "SourceFiles: ${SOURCE_FILES}" echo "" @@ -71,6 +70,8 @@ echo "" # --- Build Java classes --- echo 'Building java classes' +# shellcheck disable=SC2086 +# (we need word splitting here to pass multiple files) javac -cp "${TEMP_DIR}" -d "${TEMP_DIR}" ${SOURCE_FILES} if [ $? -ne 0 ]; then echo "Compilation failed. Please check errors above." @@ -85,6 +86,7 @@ mkdir -p "${TEMP_DIR}/com/gpl/rpg/atcontentstudio/img" mkdir -p "${TEMP_DIR}/tiled/io/resources/" cp -r "${ATCS_SOURCE_DIR}"/src/com/gpl/rpg/atcontentstudio/img/* "${TEMP_DIR}/com/gpl/rpg/atcontentstudio/img/" # some icons cp -r "${ATCS_SOURCE_DIR}"/hacked-libtiled/tiled/io/resources/* "${TEMP_DIR}/tiled/io/resources/" # dtd file for tmx maps +cp "${VERSION_FILE}" "${TEMP_DIR}/" # Copy version file # --- Create JAR file --- echo "" @@ -103,17 +105,22 @@ cd "${PACKAGING_DIR}" || exit # Go back to packaging dir echo '' echo "Done creating jar at ${JAR_LOCATION}" -cp -f "${JAR_LOCATION}" "${OUTPUT_JAR_DIR}/common/ATCS.jar" # Copy JAR to versioned name +cp -f "${JAR_LOCATION}" "${PACKAGING_DIR}/common/ATCS.jar" # Copy JAR to versioned name # --- Create archive --- -if [ "$PLATFORM" = "LINUX" ]; then - cd "${OUTPUT_JAR_DIR}" || exit - echo "Creating archive" - tar caf "ATCS_${VERSION}.tar.gz" common/* # archive the 'common' folder which now contains the JAR and libs - echo "Created archive at ${OUTPUT_JAR_DIR}/ATCS_${VERSION}.tar.gz" - cd "${PACKAGING_DIR}" || exit +cd "${PACKAGING_DIR}" || exit +echo "Creating archive" +if [ "$PLATFORM" = "WINDOWS" ]; then + # Use PowerShell's Compress-Archive which is available by default on Windows + powershell.exe -Command "Compress-Archive -Path './common/*' -DestinationPath './ATCS_${VERSION}.zip' -Force" else - echo "Can't create zip files on windows yet. Please pack the content of the '${OUTPUT_JAR_DIR}/common/' folder yourself" + # Use zip command on Linux + zip -r "ATCS_${VERSION}.zip" common/* # archive the 'common' folder which now contains the JAR and libs fi +if [ $? -ne 0 ]; then + echo "Archive creation failed." + exit 1 +fi +echo "Created archive at ${PACKAGING_DIR}/ATCS_${VERSION}.zip" echo "Script finished." diff --git a/packaging/ATCS_latest b/res/ATCS_latest similarity index 100% rename from packaging/ATCS_latest rename to res/ATCS_latest diff --git a/src/com/gpl/rpg/atcontentstudio/ATContentStudio.java b/src/com/gpl/rpg/atcontentstudio/ATContentStudio.java index 0afa335..3d96057 100644 --- a/src/com/gpl/rpg/atcontentstudio/ATContentStudio.java +++ b/src/com/gpl/rpg/atcontentstudio/ATContentStudio.java @@ -28,7 +28,7 @@ import java.util.logging.Logger; public class ATContentStudio { public static final String APP_NAME = "Andor's Trail Content Studio"; - public static final String APP_VERSION = "v0.6.21"; + public static final String APP_VERSION = readVersionFromFile(); public static final String CHECK_UPDATE_URL = "https://andorstrail.com/static/ATCS_latest"; public static final String DOWNLOAD_URL = "https://andorstrail.com/viewtopic.php?f=6&t=4806"; @@ -218,4 +218,14 @@ public class ATContentStudio { } } } + + private static String readVersionFromFile() { + try (BufferedReader reader = new BufferedReader(new InputStreamReader( + Objects.requireNonNull(ATContentStudio.class.getResourceAsStream("/ATCS_latest"))))) { + return reader.readLine(); + } catch (IOException e) { + e.printStackTrace(); + return "unknown"; + } + } }