ProjectSynchro / powershell-wrapper-for-wine

pwsh wrapper for wine
GNU General Public License v2.0
1 stars 0 forks source link

quotes... #3

Open PietJankbal opened 2 months ago

PietJankbal commented 2 months ago

Hi, first: nice that you got this into winetricks!

I see in your issue 2 that you ran into trouble with quotes in the powershell command, just as I had recently with a script that failed for that reason.

So I decided to completely rewrite the wrapper, to avoid usage of CommandLineToArgvW. Background: CommandLineToArgvW removes quotes and double quotes from args (in a peculiar way, see source in wine/dlls/shcore/main.c) so we lost them when we rejoin the arguments, causing trouble.

The trouble I had was with a command trying to read from a file with a comma in it's name (surrounded by double quotes) and by removing the quotes powershell got confused

The fully rewritten wrapper can be found here: https://github.com/PietJankbal/Chocolatey-for-wine/blob/main/mainv1.c

Basically , just as in the current wrapper, it looks for the last option meanwhile concatenating them again, but the important difference is in line 63: After last option found it just concatenates the whole rest of the commandline in one lump, thus preserving quotes and double quotes.

You could try if it works for your command too; You can just copy/paste code and rip out line 49 -52 (you don't need them for your wrapper) and adjust line 83. Also as you can see I simplified the part of reading pipe: I found it was overcomplicated in previous version. Also, for fun I read commandline from Peb, but for better readability you might want to change that (just add before line 47 WCHAR* clbuf = GetCommandLineW(); and remove peb stuff)

At last, I fixed up some quick tests, most just found with google, to test this new wrapper, and they all pass now. Test here: https://github.com/PietJankbal/Chocolatey-for-wine/blob/main/EXTRAS/tests/test.c

If you could add your failing command line or paste it here that would be nice. Note: the command that failed for me is (a bit simplified) in line 29.

ProjectSynchro commented 1 month ago

Hi, first: nice that you got this into winetricks!

Thanks :) Glad I was able to get something in, I can see why the last couple attempts stalled after a while.

I see in your issue 2 that you ran into trouble with quotes in the powershell command, just as I had recently with a script that failed for that reason.

So I decided to completely rewrite the wrapper, to avoid usage of CommandLineToArgvW. Background: CommandLineToArgvW removes quotes and double quotes from args (in a peculiar way, see source in wine/dlls/shcore/main.c) so we lost them when we rejoin the arguments, causing trouble.

Interesting, that would explain what was going on. I did see with some debugging that they did "appear" to work. But kept throwing things at the wall until my bodge worked.

The trouble I had was with a command trying to read from a file with a comma in it's name (surrounded by double quotes) and by removing the quotes powershell got confused

The fully rewritten wrapper can be found here: https://github.com/PietJankbal/Chocolatey-for-wine/blob/main/mainv1.c

Basically , just as in the current wrapper, it looks for the last option meanwhile concatenating them again, but the important difference is in line 63: After last option found it just concatenates the whole rest of the commandline in one lump, thus preserving quotes and double quotes.

You could try if it works for your command too; You can just copy/paste code and rip out line 49 -52 (you don't need them for your wrapper) and adjust line 83. Also as you can see I simplified the part of reading pipe: I found it was overcomplicated in previous version. Also, for fun I read commandline from Peb, but for better readability you might want to change that (just add before line 47 WCHAR* clbuf = GetCommandLineW(); and remove peb stuff)

Thanks! I can give adapting your solution a go when I get the chance and see how it goes, fixing this correctly is definitely a better solution compared to my brute force solution :)

At last, I fixed up some quick tests, most just found with google, to test this new wrapper, and they all pass now. Test here: https://github.com/PietJankbal/Chocolatey-for-wine/blob/main/EXTRAS/tests/test.c

Sweet, I may joink those tests and add it to CI here, definitely would be a nice insurance policy :)

If you could add your failing command line or paste it here that would be nice. Note: the command that failed for me is (a bit simplified) in line 29.

Here's the invokation in the source code I extracted from the misbehaving launcher:

powershell.exe Start-Process -Verb RunAs -FilePath "C:\Program Files\Roberts Space Industries\StarCitizen\LIVE\EasyAntiCheat\EasyAntiCheat_EOS_Setup.exe" -ArgumentList "install 54540c7a80fe48ea92ead64506b4ff53"
PietJankbal commented 1 month ago

Hi, I did some tests in powershell 5.1 (in a windows VM) and apparently there too it's rather a mess with handling quotes. I was only able to get a working command by surrounding the "argumentlist" options with one single quote and three double quotes.. Maybe that's how the game invoked that powershellcommand as well, because other variants on windows didn't work out. I added a test for it , line 45, in the testfile here: https://github.com/PietJankbal/Chocolatey-for-wine/blob/main/EXTRAS/tests/test.c

That command passes test on windows and in my current wrapper, so I would guess the wrapper also might handle also the command your game invokes.