gurrgur / er-patcher

Elden Ring enhancement patches (ultrawide support, custom frame rate limits and more) seamlessly integrated with steam.
MIT License
301 stars 25 forks source link

Avoid deleting eldenring.exe while it is running #78

Closed metinc closed 1 month ago

metinc commented 1 month ago

If you pass an --executable arg like when playing the Seamless Co-op mod Elden Ring does crash. The reason is subprocess.run() waits for the passed executable like ersc_launcher.exe to finish but it does not wait for eldenring.exe to finish. The Python script is unaware of eldenring.exe since it was executed by ersc_launcher.exe. Then rmtree() is called and deletes the patched eldenring.exe while it is running. This PR solves this by checking if eldenring.exe can be accessed. If it is locked it won't be deleted. The behavior remains unchanged if --executable is not passed. I tested this on Windows 11. Would be great if someone can test it on Linux aswell.

Fixes #54 Fixes #60 Fixes #61

gurrgur commented 1 month ago

Thanks for your work on this.

The solution looks good but I'm worried about potentially leaving the temp dir as it would lead to steam uninstallation not working properly. We could try an approach where cleanup polls the locked state of eldenring.exe (e.g. every 3 seconds) and proceeds when the lock has ceased.

In any case, I'd like to have this tested on Linux before merging.

metinc commented 1 month ago

@gurrgur I understand your concerns regarding the er-patcher-tmp folder not being deleted. I wasn't aware that this issue was causing the Steam uninstall to no longer work. I have now adjusted my pull request accordingly. If os.remove() fails because eldenring.exe has not been unlocked yet, a retry will be executed every 3 seconds. If a different error occurs, no retry will be performed. In any case, rmtree() will be executed afterward.

Additionally, I have now installed Arch Linux in a dual boot setup. I will test the changes under Linux and provide feedback.

gurrgur commented 1 month ago

Thanks for the update! LGTM

gurrgur commented 1 month ago

Oh and I just tested running seamless coop on linux and it starts up just fine!

env WINE_FULLSCREEN_FSR=1 python er-patcher -ucvs --rate 120 -x ersc_launcher.exe -- %command%