mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 16:49:58 -04:00
Uninstall only what the launcher put in its folder, so a kept game folder inside it stays.
Uninstall ran rmdir /s on the whole launcher folder, which holds the default game folder (<launcher>\game) and, with the setup's --dest, whatever else the player keeps there: "Remove the Built Game" Off would have deleted the game and its saves. It now deletes NX2navi.exe, python, app, pydeps, data, toolchain and python.old-*, then the folder only when that left it empty, and for a toolchain in C:\NX2navi that toolchain, then C:\NX2navi only when empty. The command also never ran: it went to cmd.exe as a list, whose quotes Python escapes as \", which cmd.exe does not understand, so every rmdir failed and nothing was removed. It is now one command line. tests/launcher_test.py runs it on a folder with spaces and a character outside ASCII. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -198,23 +198,55 @@ def keep_awake(on):
|
||||
pass
|
||||
|
||||
|
||||
# What the launcher puts in its folder (launcher/paths.py, the stub's python.next and python.old-<n>). Uninstall deletes
|
||||
# only these: the default game folder is <root>\game, and a folder given to the setup with --dest may hold other things.
|
||||
OWNED = ('NX2navi.exe', 'app', 'python', 'python.next', 'pydeps', 'data', 'toolchain')
|
||||
|
||||
|
||||
def uninstall_plan(layout, remove_game=''):
|
||||
"""(paths to delete with all they hold, folders to delete only when that left them empty), in order. A kept game
|
||||
folder stays whether or not it lies inside the launcher's folder."""
|
||||
root = Path(layout.root)
|
||||
gone = [Path(remove_game)] if remove_game else []
|
||||
gone += [root / n for n in OWNED]
|
||||
try:
|
||||
gone += sorted(p for p in root.glob('python.old-*'))
|
||||
except OSError:
|
||||
pass
|
||||
empty = [root]
|
||||
if Path(layout.toolchain).parent != root: # the toolchain went to C:\NX2navi (launcher/paths.py ansi_safe)
|
||||
gone.append(Path(layout.toolchain))
|
||||
empty.append(Path(layout.toolchain).parent)
|
||||
return gone, empty
|
||||
|
||||
|
||||
def uninstall_script(gone, empty):
|
||||
"""The cmd.exe line that deletes them once the launcher has exited: a file with del, a folder with rmdir /s, the
|
||||
folders that must be empty with a plain rmdir (which leaves a folder that still holds something)."""
|
||||
steps = ['ping -n 3 127.0.0.1 >nul']
|
||||
for p in gone:
|
||||
steps.append(f'(if exist "{p}\\*" (rmdir /s /q "{p}") else if exist "{p}" (del /f /q "{p}"))')
|
||||
steps += [f'rmdir "{p}" 2>nul' for p in empty]
|
||||
return ' & '.join(steps)
|
||||
|
||||
|
||||
def uninstall(layout, remove_game='', log=print):
|
||||
"""Remove the shortcuts, the uninstall entry and, once this process has exited, the launcher's folder (and the
|
||||
game folder when remove_game names it). Saves inside a kept game folder stay."""
|
||||
"""Remove the shortcuts, the uninstall entry and, once this process has exited, what the launcher put in its folder
|
||||
(and the game folder when remove_game names it). A kept game folder and its saves stay, also when it lies inside
|
||||
the launcher's folder."""
|
||||
stub_run(layout, ['--shortcuts', 'off'])
|
||||
gone, empty = uninstall_plan(layout, remove_game)
|
||||
if os.name == 'nt':
|
||||
try:
|
||||
import winreg
|
||||
winreg.DeleteKey(winreg.HKEY_CURRENT_USER, UNINSTALL_KEY)
|
||||
except OSError:
|
||||
pass
|
||||
targets = [str(layout.root)] + ([str(remove_game)] if remove_game else [])
|
||||
if layout.toolchain.parent != layout.root:
|
||||
targets.append(str(layout.toolchain.parent))
|
||||
script = 'ping -n 3 127.0.0.1 >nul & ' + ' & '.join(f'rmdir /s /q "{t}"' for t in targets)
|
||||
start_detached(['cmd.exe', '/c', script], cwd=os.environ.get('TEMP', 'C:\\'))
|
||||
# one command line as cmd.exe reads it: a list would have its quotes escaped as \", which cmd.exe does not
|
||||
# understand, and no rmdir would find its folder
|
||||
start_detached(f'cmd.exe /c "{uninstall_script(gone, empty)}"', cwd=os.environ.get('TEMP', 'C:\\'))
|
||||
else:
|
||||
log('uninstall: remove these folders yourself: ' + ', '.join([str(layout.root), str(remove_game)]))
|
||||
log('uninstall: remove these yourself: ' + ', '.join(str(p) for p in gone if p.exists()))
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- gamepad (XInput)
|
||||
|
||||
Reference in New Issue
Block a user