Merge pull request #182 from duncathan/auto-version

Automatically update in-game version on release
This commit is contained in:
duncathan salt 2024-12-18 15:23:01 -06:00 committed by GitHub
commit 08f0c555f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 128 additions and 14 deletions

17
.gitignore vendored
View file

@ -1,12 +1,6 @@
data/*
notes/*
pre_edited_cs/Doukutsu\.exe\.blbkp
pre_edited_cs/Profile*
pre_edited_cs/window\.rect
*Copy/
venv/
@ -17,5 +11,12 @@ dist/
cave_story_randomizer.egg-info/
*/__pycache__
caver/version.py
**/__pycache__
pre_edited_cs/**/Doukutsu\.exe\.blbkp
pre_edited_cs/**/Profile*
pre_edited_cs/**/window\.rect
pre_edited_cs/data/version.txt
pre_edited_cs/freeware/Doukutsu_backup.exe

View file

@ -29,8 +29,6 @@ if typing.TYPE_CHECKING:
MapName,
)
CSVERSION = 5
class CaverException(Exception):
pass
@ -100,8 +98,16 @@ def patch_files(
def ensure_base_files_exist(platform: CSPlatform, output_dir: Path) -> None:
internal_copy = pre_edited_cs.get_path()
version = output_dir.joinpath("data", "Stage", "_version.txt")
keep_existing_files = version.exists() and int(version.read_text()) >= CSVERSION
with internal_copy.joinpath("data", "version.txt").open() as version_file:
latest_version = version_file.readline()
version = output_dir.joinpath("data", "version.txt")
current_version = "v0.0.0.0"
if version.exists():
with version.open() as version_file:
current_version = version_file.readline()
keep_existing_files = current_version >= latest_version
def should_ignore(path: str, names: list[str]) -> list[str]:
base = ["__init__.py", "__pycache__", "ScriptSource", "__pyinstaller"]

View file

@ -0,0 +1,103 @@
; Reads version number from data\version.txt
; The file must start with the version string in the format shown at the bottom of this file
; Made by periwinkle
#define
gDataPath=49E220
gVersionString=48C2BC
sprintf=481010
fopen=480FFD
rb=48C28C
fread=480F55
fclose=480E1B
sscanf=4817E8
call VirtualProtect=data ff 15 84 c0 48 00
filePath=[ebp-114]
bufchk=[ebp-10]
tmp=[ebp-c]
oldProtect=[ebp-8]
fp=[ebp-4]
v1=[ebp+8]
v2=[ebp+c]
v3=[ebp+10]
v4=[ebp+14]
#enddefine
offset 410990 ; GetCompileVersion
push ebp
mov ebp, esp
sub esp, 114
mov eax, [498B20]
mov bufchk, eax
; Get path to data\version.txt file
push gDataPath
push :VersionPath ; "%s\version.txt"
lea edx, filePath
push edx
call sprintf
add esp, c
; Open file
push rb ; "rb"
lea ecx, filePath
push ecx
call fopen
add esp, 8
test eax, eax
jz :ReadVersion
mov fp, eax
; Mark gVersionString as read/write (it's normally in a read-only segment)
lea eax, oldProtect
push eax
push 4 ; PAGE_READWRITE
push 40 ; Max size of gVersionString (including null character)
push gVersionString
call VirtualProtect
test eax, eax
jz :CloseFile
; Read contents of file into gVersionString
push fp
push 3F ; count (excluding null character)
push 1 ; size
push gVersionString
call fread
add esp, 10
mov byte [eax+gVersionString], 0 ; Write null terminator
; Restore previous protection status
lea eax, tmp
push eax
push oldProtect
push 40
push gVersionString
call VirtualProtect
:CloseFile
push fp
call fclose
pop ecx
:ReadVersion
; Parse the version string
push v4
push v3
push v2
push v1
push :VersionString
push gVersionString
call sscanf
add esp, 18
mov ecx, bufchk
call 480DC1
leave
retn
:VersionPath
data 25 73 5C 76 65 72 73 69 6F 6E 2E 74 78 74 00 00 ; "%s\version.txt"
:VersionString
data 76 25 64 2E 25 64 2E 25 64 2E 25 64 00 ; "v%d.%d.%d.%d"

View file

@ -1 +0,0 @@
3

Binary file not shown.

View file

@ -0,0 +1,3 @@
v0.0.0.0
2019/03/07 - ????/??/??
duncathan_salt

View file

@ -3,8 +3,10 @@ requires = ["setuptools>=44.0.0", "setuptools_scm[toml]>=3.4.3"]
build-backend = "setuptools.build_meta"
[tool.setuptools_scm]
version_file_template = "v{scm_version.tag}.{scm_version.distance}\n2019/03/07 - {scm_version.node_date.year:04}/{scm_version.node_date.month:02}/{scm_version.node_date.day:02}\nduncathan_salt"
local_scheme = "no-local-version"
write_to = "caver/version.py"
version_scheme = "no-guess-dev"
version_file = "pre_edited_cs/data/version.txt"
[tool.ruff]
line-length = 120