Do not take a read-only ocarina.exe for a running game.

The launcher tells a running game by ocarina.exe refusing to open for writing, and a read-only exe (restored from a
backup or copied from read-only media) refuses too: Rebuild, Update, Import Saves and uninstalling with the game were
refused with "close the game" for good. The check now clears the read-only attribute of the build's own exe, which
the next link replaces anyway, and tries again. Import Saves uses the same check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-08 08:53:42 -05:00
parent 9865542bb9
commit 4ab121d67e
3 changed files with 29 additions and 18 deletions

View File

@@ -3,6 +3,7 @@ and cancelling it with every compiler it started."""
import json
import os
import signal
import stat
import subprocess
import threading
@@ -100,17 +101,26 @@ class Run:
def game_running(game_dir, exe='ocarina.exe'):
"""True when the built game runs from game_dir: Windows refuses to open a running exe for writing."""
"""True when the built game runs from game_dir: Windows refuses to open a running exe for writing. A read-only
exe (a copy restored from a backup or read-only media) is refused too, though nothing runs it: its read-only
attribute is cleared and the open tried again, as the next build replaces the file anyway."""
path = os.path.join(str(game_dir), exe)
if os.name != 'nt' or not os.path.isfile(path):
return False
try:
with open(path, 'r+b'):
for attempt in range(2):
try:
with open(path, 'r+b'):
return False
except PermissionError:
if attempt or not os.stat(path).st_file_attributes & stat.FILE_ATTRIBUTE_READONLY:
return True
try:
os.chmod(path, stat.S_IREAD | stat.S_IWRITE)
except OSError:
return True
except OSError:
return False
except PermissionError:
return True
except OSError:
return False
return True
def build_state(game_dir):

View File

@@ -181,17 +181,9 @@ def _newest(game, account):
def game_running(game):
"""Windows: ocarina.exe cannot be opened for writing while it runs."""
exe = Path(game) / 'ocarina.exe'
if os.name != 'nt' or not exe.is_file():
return False
try:
with open(exe, 'r+b'):
return False
except PermissionError:
return True
except OSError:
return False
"""Windows: ocarina.exe cannot be opened for writing while it runs (launcher/build.py game_running)."""
from .build import game_running as running
return running(game)
def import_save(game, folder=None, log=print):