Skip to content

Commit 15d38ea

Browse files
fankclaude
andauthored
Fix mod version compatibility checking for major version differences (#575)
This fixes issue #517 where the auto mod updater was downloading the wrong mod versions after updating to Space Age (Factorio 2.0). The problem was that the version checking logic was incorrectly rejecting compatible mod versions. Changes: - Fixed check_game_version() to properly handle major version differences - Game versions can now run mods designed for older major versions (backward compatibility) - Game versions correctly reject mods requiring newer versions - Fixed variable references in check_dependency_version() - Added clarifying comments about the version checking behavior This also addresses issue #468 by ensuring mods requiring newer Factorio versions than currently installed are properly skipped. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent 9464758 commit 15d38ea

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

docker/files/update-mods.sh

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,33 @@ print_failure()
2323
echo "$1"
2424
}
2525

26-
# Checks game version vs version in mod.
27-
# Returns 0 if major version differs or mod minor version is less than game version, 1 if ok
26+
# Checks if the current game version satisfies the mod's minimum required version.
27+
# Returns 1 if the game version is compatible with the mod, 0 if not
2828
check_game_version() {
29-
local game_version="$1"
30-
local mod_version="$2"
29+
local mod_required_version="$1" # The minimum Factorio version required by the mod
30+
local current_game_version="$2" # The current Factorio version
31+
32+
local mod_major mod_minor game_major game_minor
33+
mod_major=$(echo "$mod_required_version" | cut -d '.' -f1)
34+
mod_minor=$(echo "$mod_required_version" | cut -d '.' -f2)
35+
game_major=$(echo "$current_game_version" | cut -d '.' -f1)
36+
game_minor=$(echo "$current_game_version" | cut -d '.' -f2)
3137

32-
local game_major mod_major game_minor mod_minor
33-
game_major=$(echo "$game_version" | cut -d '.' -f1)
34-
game_minor=$(echo "$game_version" | cut -d '.' -f2)
35-
mod_major=$(echo "$mod_version" | cut -d '.' -f1)
36-
mod_minor=$(echo "$mod_version" | cut -d '.' -f2)
38+
# If game major version is greater than mod's required major version, it's compatible
39+
if [[ "$game_major" -gt "$mod_major" ]]; then
40+
echo 1
41+
return
42+
fi
3743

38-
if [[ "$game_major" -ne "$mod_major" ]]; then
44+
# If game major version is less than mod's required major version, it's not compatible
45+
if [[ "$game_major" -lt "$mod_major" ]]; then
3946
echo 0
4047
return
4148
fi
4249

43-
if [[ "$mod_minor" -ge "$game_minor" ]]; then
50+
# Major versions are equal, check minor versions
51+
# Game minor version must be >= mod's required minor version
52+
if [[ "$game_minor" -ge "$mod_minor" ]]; then
4453
echo 1
4554
else
4655
echo 0
@@ -79,7 +88,7 @@ check_dependency_version()
7988
fi
8089
;;
8190
">")
82-
if [[ "$(printf '%s\n%s\n' "$required_version" "$mod_version" | sort -V | head -n1)" == "$required_version" && "$required_version" != "$FACTORIO_VERSION" ]]; then
91+
if [[ "$(printf '%s\n%s\n' "$required_version" "$mod_version" | sort -V | head -n1)" == "$required_version" && "$required_version" != "$mod_version" ]]; then
8392
echo 1
8493
else
8594
echo 0
@@ -93,7 +102,7 @@ check_dependency_version()
93102
fi
94103
;;
95104
"<")
96-
if [[ "$(printf '%s\n%s\n' "$required_version" "$mod_version" | sort -V | tail -n1)" == "$required_version" && "$required_version" != "$FACTORIO_VERSION" ]]; then
105+
if [[ "$(printf '%s\n%s\n' "$required_version" "$mod_version" | sort -V | tail -n1)" == "$required_version" && "$required_version" != "$mod_version" ]]; then
97106
echo 1
98107
else
99108
echo 0
@@ -116,11 +125,15 @@ get_mod_info()
116125
{
117126
local mod_info_json="$1"
118127

128+
# Process mod releases from newest to oldest, looking for a compatible version
119129
while IFS= read -r mod_release_info; do
120130
local mod_version mod_factorio_version
121131
mod_version=$(echo "$mod_release_info" | jq -r ".version")
122132
mod_factorio_version=$(echo "$mod_release_info" | jq -r ".info_json.factorio_version")
123133

134+
# Check if this mod version is compatible with our Factorio version
135+
# This prevents downloading mods that require a newer Factorio version (fixes #468)
136+
# and ensures backward compatibility (e.g., Factorio 2.0 can use 1.x mods) (fixes #517)
124137
if [[ $(check_game_version "$mod_factorio_version" "$FACTORIO_VERSION") == 0 ]]; then
125138
echo " Skipping mod version $mod_version because of factorio version mismatch" >&2
126139
continue

0 commit comments

Comments
 (0)