mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-21 03:39:57 -04:00
Leave paths holding % out of the uninstall command line, which cmd.exe would expand.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -222,11 +222,13 @@ def uninstall_plan(layout, remove_game=''):
|
|||||||
|
|
||||||
def uninstall_script(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
|
"""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)."""
|
folders that must be empty with a plain rmdir (which leaves a folder that still holds something). A path holding
|
||||||
|
% is left out: cmd.exe expands %NAME% even inside quotes, so a folder named C:\%HOMEPATH% would delete another."""
|
||||||
steps = ['ping -n 3 127.0.0.1 >nul']
|
steps = ['ping -n 3 127.0.0.1 >nul']
|
||||||
for p in gone:
|
for p in gone:
|
||||||
steps.append(f'(if exist "{p}\\*" (rmdir /s /q "{p}") else if exist "{p}" (del /f /q "{p}"))')
|
if '%' not in str(p):
|
||||||
steps += [f'rmdir "{p}" 2>nul' for p in empty]
|
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 if '%' not in str(p)]
|
||||||
return ' & '.join(steps)
|
return ' & '.join(steps)
|
||||||
|
|
||||||
|
|
||||||
@@ -244,6 +246,9 @@ def uninstall(layout, remove_game='', log=print):
|
|||||||
pass
|
pass
|
||||||
# one command line as cmd.exe reads it: a list would have its quotes escaped as \", which cmd.exe does not
|
# 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
|
# understand, and no rmdir would find its folder
|
||||||
|
kept = [str(p) for p in list(gone) + list(empty) if '%' in str(p) and os.path.exists(p)]
|
||||||
|
if kept:
|
||||||
|
log('uninstall: remove these yourself (their names hold %): ' + ', '.join(kept))
|
||||||
start_detached(f'cmd.exe /c "{uninstall_script(gone, empty)}"', cwd=os.environ.get('TEMP', 'C:\\'))
|
start_detached(f'cmd.exe /c "{uninstall_script(gone, empty)}"', cwd=os.environ.get('TEMP', 'C:\\'))
|
||||||
else:
|
else:
|
||||||
log('uninstall: remove these yourself: ' + ', '.join(str(p) for p in gone if p.exists()))
|
log('uninstall: remove these yourself: ' + ', '.join(str(p) for p in gone if p.exists()))
|
||||||
|
|||||||
@@ -340,6 +340,11 @@ class UninstallTest(Tmp):
|
|||||||
subprocess.run(f'cmd.exe /c "{script.replace("ping -n 3 127.0.0.1 >nul", "echo")}"', capture_output=True)
|
subprocess.run(f'cmd.exe /c "{script.replace("ping -n 3 127.0.0.1 >nul", "echo")}"', capture_output=True)
|
||||||
self.assertFalse(root.exists())
|
self.assertFalse(root.exists())
|
||||||
|
|
||||||
|
def test_script_leaves_out_percent_paths(self):
|
||||||
|
script = winsys.uninstall_script([Path('C:/%HOMEPATH%'), Path('C:/x/a')], [Path('C:/%TEMP%/b')])
|
||||||
|
self.assertNotIn('%', script)
|
||||||
|
self.assertIn('a', script)
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------- toolchain
|
# ---------------------------------------------------------------- toolchain
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user