adamrehn / ue4cli

Command-line interface for Unreal Engine 4
https://docs.adamrehn.com/ue4cli/
MIT License
249 stars 45 forks source link

Bug: setroot breaks with trailing backslash #27

Closed siennathesane closed 3 years ago

siennathesane commented 3 years ago

I don't have UE4 installed on my C drive, so I needed to manually pass the root directory. I ran into a bug with the text parsing when it comes to passing in the root.

Replication

Given an installed path at F:\Program Files\Epic Games\UE_4.26, When a user runs ue4 setroot F:\Program Files\Epic Games\UE_4.26\, Then the tool throws this error: Warning: the specified directory does not appear to contain a valid version of the Unreal Engine.

Fix

The fix is super easy, just don't pass a backslash for the value of setroot. I dug into the code a bit, but I didn't see a 5m, platform-specific fix that I could contribute.

nmetrock commented 3 years ago

hello. not sure if this is related but i want to add that i was getting the same error with

ue4 setroot "C:/Program Files/Epic Games/UE4.26"

and fixed it by removing the drive letter

ue4 setroot "/Program Files/Epic Games/UE4.26"

this may be working as intended, i got the idea to try this based on the documentation not having a drive letter either, but it's not entirely clear. maybe a note that specifically says not to include drive letter? but then it also threw me off that mxplusb here was able to use drive F successfully? so it took me a moment to even try it this way.

thanks for your time

adamrehn commented 3 years ago

@mxplusb the issue you're encountering is actually related to the shell itself, rather than ue4cli. If your argument is wrapped in double quotes (because it contains spaces) and ends with \" then the shell actually escapes the trailing quote character and includes it in the value passed to ue4cli. So what ue4cli will actually see is F:\Program Files\Epic Games\UE_4.26" rather than F:\Program Files\Epic Games\UE_4.26 as expected. You can test this for yourself by removing the trailing quote, which will result in the backslash actually getting passed to ue4cli, where os.path.abspath() will strip it. There's nothing that I can do to prevent this in ue4cli itself, since the issue occurs before my code ever runs.

@nmetrock the examples in the documentation are based on Unix filesystem paths, which do not have drive letters. Under Windows it is expected that you will include the drive letter when specifying a path. The fact that it still works without a drive letter is due to os.path.abspath() automatically prepending C:\ to the path it receives when it detects the absence of a drive letter under Windows.

adamrehn commented 3 years ago

I've updated the ue4 setroot command in commit 170c894 (live in ue4cli version 0.0.51) to print the path that ue4cli has received from the shell, which should hopefully make it easier for people to spot escaping-related issues like this one. (You technically already get this from the Using user-specified engine root: output, but people often tend to ignore that or get confused about whether it refers to the new root override or a previous one.) It should also make it easier for people to spot when they've passed a path with spaces in it but forgot to wrap it in quotes, which is another common problem that people run into with this command.