Winepath on Mac

Questions about Wine on macOS.
Locked
tpatko
Level 2
Level 2
Posts: 32
Joined: Thu Aug 06, 2009 12:29 am

Winepath on Mac

Post by tpatko »

I am trying to use winepath to convert between the WINE native file path and the normal Mac native filepath. Unfortunately, I do not seem to be able to return the logical Mac UNIX path when using winepath:

Macintosh:~ tpatko$ /Applications/Firefly/WINE/bin/wine winepath -u Z:\Applications\Firefly\BENCH1.out
/Users/tpatko/.wine/dosdevices/z:/Users/tpatko/ApplicationsFireflyBENCH1.out
Macintosh:~ tpatko$

When making this call, for example, the correct Mac UNIX native filepath should be:

/Applications/Firefly/Bench1.out

Is there some options that I am missing or are there some changes to the source code required to make this work?

http://wiki.winehq.org/winepath

My build is from source code version 1.1.33 (I know that there are newer version but it they do not address this issue then the difference are moot).

If anyone has some good ideas I would be appreciate.

Cheers,

Thomas
Thunderbird
Level 5
Level 5
Posts: 336
Joined: Mon Nov 24, 2008 8:10 am

Post by Thunderbird »

The behavior you are seeing is normal. Conversion from unix -> wine always works fine but the backwards conversion doesn't result in the shortest possible path. I looked into it a while ago but forgot what it was. I think it had something to do with some knowledge about the drive symlinks which doesn't know about (the code is in kernel32).
tpatko
Level 2
Level 2
Posts: 32
Joined: Thu Aug 06, 2009 12:29 am

Post by tpatko »

Well actually the issue is not just that it is not the "shortest possible" path returned but rather that the path is altogether useless for calling any native Mac apps or passing a file path as a parameter using this utility.

In addition, even accounting for the oddities that winepath does in the WINE to UNIX filesystem conversion, it seems that even if the things in front of the true UNIX filesystem path were somehow removed (as they should be), the proper forward slashes seem to have be mysteriously removed. For example:

/Users/tpatko/.wine/dosdevices/z:/Users/tpatko/ApplicationsFireflyBENCH1.out

should a the VERY least be:

/Users/tpatko/.wine/dosdevices/z:/Users/tpatko/Applications/Firefly/BENCH1.out

Which ultimately should really be:

/Applications/Firefly/Bench1.out

Is there any way to modify the WINE source so that this winepath program works properly for the WINE -> UNIX conversion?

Regards,

Thomas
Charles Davis

Winepath on Mac

Post by Charles Davis »

Did you quote the path? Remember, the backslash character is special to
the shell. It's the "escape character". So the shell will strip the
backslashes away unless you either escape them:

winepath -u Z:\\Applications\\Firefly\\BENCH1.out

or put the path in *single* quotes:

winepath -u 'Z:\Applications\Firefly\BENCH1.out'

Double quotes don't work because the shell still interprets backslashes
inside of them.

Chip
tpatko
Level 2
Level 2
Posts: 32
Joined: Thu Aug 06, 2009 12:29 am

Post by tpatko »

Dear Charles:

Thank you very much for the advise regarding the blackslash issue. This advice will get me to the proper:

/Users/tpatko/.wine/dosdevices/z:/Users/tpatko/Applications/Firefly/BENCH1.out

versus the stripped

/Users/tpatko/.wine/dosdevices/z:/Users/tpatko/ApplicationsFireflyBENCH1.out

That is certainly a step in the right direction. I appreciate the tip.

Is there a way to get all the way to the correct path shown below?

/Applications/Firefly/Bench1.out

In sort, is there an option in the winepath call or a change to the source that will automatically drop the preceding wine portion of the path that is not needed for Mac systems calls. How did I strip:

/Users/tpatko/.wine/dosdevices/z:/Users/tpatko

out of the returned path?

I am working on something that will be used by other users besides myself, so it would need to systematically strip out this preceding portion on any given user's machine.

Thanks,

Thomas
tpatko
Level 2
Level 2
Posts: 32
Joined: Thu Aug 06, 2009 12:29 am

Post by tpatko »

Can anyone direct me to the part of the code that would build the winepath binary in WINE? It would seem to me that the cwd path for the wine installation (/Users/tpatko/.wine/dosdevices/z:/Users/tpatko in my example case) and the path to the actual file (/Applications/Firefly/BENCH1.out) must actually be concatenated together so there should be a way to modify the code to simply drop the preceding cwd portion. Any tips would be greatly appreciated.

Thanks,

Thomas
doh123
Level 8
Level 8
Posts: 1227
Joined: Tue Jul 14, 2009 1:21 pm

Post by doh123 »

I dont understand why its important.

I have tested it multiple ways, and the Z: symlink just goes back to your root... the winepath you get looks long but will function perfectly normal... I've tried it several times.

I have no idea why you are saying yours is going to your user applications folder instead of the main one, it doesn't for me, tested on OSX 10.4 and 10.6.

winepath 'Z:\Applications\Folder\File.txt'

gives me...

/Users/doh123/.wine/dosdevices/z:/Applications/Folder/File.txt

which works perfectly fine... its just annoying to have that on the front when looking at it, but it still works.
tpatko
Level 2
Level 2
Posts: 32
Joined: Thu Aug 06, 2009 12:29 am

Post by tpatko »

I need to have the wine portion of the path stripped from the front *because* when I perform a system call such as

open -a /Application/Application.app $ABSOLUTEPATH

and I need a CLEAN $ABSOLUTEPATH without the wine portion that is altogether meaningless to a native Mac application (and more important causes it to not be able to properly address the file path). In short, the current winepath on Mac when used to return native UNIX path is not very useful for anything as it does not give you back something that a normal program can accept as path input.

The path that you find acceptable:

/Users/doh123/.wine/dosdevices/z:/Applications/Folder/File.txt

is NOT acceptable when trying to pass this string as a file path parameter to a native Mac program (see above). I need the wine part in the front STRIPPED out (there is no doubt about this). My question is how best to modify the code used to build winepath to do this.

I hope this helps to explain my requirement and why the current winepath build does not work for me. Recall that I am NOT trying to call this filepath from a program running through WINE, but rather a NATIVE Mac program. I assume that the same issue would actually present themselves under LINUX actually.

Thanks,

Thomas
doh123
Level 8
Level 8
Posts: 1227
Joined: Tue Jul 14, 2009 1:21 pm

Post by doh123 »

tpatko wrote:
The path that you find acceptable:

/Users/doh123/.wine/dosdevices/z:/Applications/Folder/File.txt

is NOT acceptable when trying to pass this string as a file path parameter to a native Mac program (see above).
sure it works fine command line as a path.... if you escape the colon, or use single quotes... otherwise the colon will throw it off.

if your like getting that string, and pulling it into a string variable, you can do some simple string manipulation to add a \ in front of the :'s .. or just add single quotes tot he front and back, which would be easier, since you need to already quote it.

What are you actually doing though? there might be a much better way to find the location you want and not use Winepath at all.
tpatko
Level 2
Level 2
Posts: 32
Joined: Thu Aug 06, 2009 12:29 am

Post by tpatko »

if your like getting that string, and pulling it into a string variable, you can do some simple string manipulation to add a \ in front of the :'s .. or just add single quotes tot he front and back, which would be easier, since you need to already quote it.

Yes, I understand that I could write a script to do this manipulation but the point here is that it seems to me that calling winepath with -u commandline switch should really return a PROPER native UNIX path, and not one that has to be further processed with a script. I am just asking any of the WINE developers if this can be implemented or how the source code can be modified to do this directly rather than having to use a secondary script to accomplish this. That is all.

Hopefully there is some reasonably simple way to accomplish this. Any advice to reach this goal is appreciated.

--Thomas
doh123
Level 8
Level 8
Posts: 1227
Joined: Tue Jul 14, 2009 1:21 pm

Post by doh123 »

tpatko wrote:if your like getting that string, and pulling it into a string variable, you can do some simple string manipulation to add a \ in front of the :'s .. or just add single quotes tot he front and back, which would be easier, since you need to already quote it.

Yes, I understand that I could write a script to do this manipulation but the point here is that it seems to me that calling winepath with -u commandline switch should really return a PROPER native UNIX path, and not one that has to be further processed with a script. I am just asking any of the WINE developers if this can be implemented or how the source code can be modified to do this directly rather than having to use a secondary script to accomplish this. That is all.

Hopefully there is some reasonably simple way to accomplish this. Any advice to reach this goal is appreciated.

--Thomas
I guess I'm missing how you are using this.. your not already scripting it, just typing it manually?

I just recommend never changing source code for such simple little fixes... it hurts you in the long run when you want to change Wine versions and make sure you do it again.

if your using like open -a ... you can just change it then in the same line

if $ABSOLUTEPATH was "/Users/doh123/.wine/dosdevices/z:/Applications/Chess.app/Contents/Info.plist"

and I wrote it as... ${ABSOLUTEPATH#${ABSOLUTEPATH%:*}:} it would be "/Applications/Chess.app/Contents/Info.plist" just simple Bash string manipulation... well maybe not so simple if you don't know Bash well.

open -a "/Developer/Applications/Utilities/Propert List Editor.app" "${ABSOLUTEPATH#${ABSOLUTEPATH%:*}:}"

is like saying

open -a "/Developer/Applications/Utilities/Propert List Editor.app" "/Applications/Chess.app/Contents/Info.plist"

If you don;t want to remember it every time in every place you need to use it, you could make a winepath launcher bash script that calls winepath and fixes it for you and comes out with the right answer always, without modifying any source code.
doh123
Level 8
Level 8
Posts: 1227
Joined: Tue Jul 14, 2009 1:21 pm

Post by doh123 »

assuming you have Wine installed to /usr/local ... change things here as needed. This will make a winepathOSX script to give the answer you want.

type in...

Code: Select all

sudo touch /usr/local/bin/winepathOSX
sudo chmod 755 /usr/local/bin/winepathOSX
sudo nano /usr/local/bin/winepathOSX
in the text editor that comes up...
copy and paste in this code

Code: Select all

#!/bin/bash
TEMPVAR=$(/usr/local/bin/winepath "$@")
echo ${TEMPVAR#${TEMPVAR%:*}:}
hit Ctrl X and answer Y to save.

from that point on if you type in as a command...

winepathOSX z:\Applications\folder\whatever.txt

it would come up as
/Applications/folder/whatever.txt
tpatko
Level 2
Level 2
Posts: 32
Joined: Thu Aug 06, 2009 12:29 am

Post by tpatko »

Dear doh123:

Thank you very much for the script sample. I have written the simple script that you described:

---------------
#!/bin/bash
# Convert from WINE to native Mac UNIX filepath
TEMPVAR=$(/Applications/Firefly/WINE/bin/winepath "$@")
UNIXFILEPATH=$(echo ${TEMPVAR#${TEMPVAR%:*}:})
# Test if UNIXFILEPATH was properly assigned
echo "$UNIXFILEPATH"
exit 0
---------------

Unfortunately, I cannot get it to work properly without using the single quotes when calling it. For example:

winepathOSX Z:\Applications\Firefly\BENCH1.out

returns:

/Applications/Firefly/RUN-FIREFLY-JOBS/ApplicationsFireflyBENCH1.out

whereas

winepathOSX 'Z:\Applications\Firefly\BENCH1.out'

returns:

/Applications/Firefly/BENCH1.out

Obviously the latter is what I want, but the file parameter that I will be passed will look like the former (without the single quotes on either side). For some reason I could not modify your script to make it work without having the single quotes on either side of the parameter that is to be passed to it (this is coming from the Windows program running through WINE so I cannot change this). Is there a way to do this in BASH? I will then use the UNIXFILEPATH variable to call various Mac native programs for a variety of purposes.

I still think that this should all be done by winepath automatically from calling the -u switch (or at least designate a new switch for what seems to be the normal intuitive UNIX path).

Thank you kindly for all of the assistance.

Cheers,

Thomas
doh123
Level 8
Level 8
Posts: 1227
Joined: Tue Jul 14, 2009 1:21 pm

Post by doh123 »

yes... was just a quick thought without some testing and debugging... its still going to suffer from the same problem without the single quotes that way.... but that makes it not work right when passing in a variable... cuz it takes the $ literally.

I'm guessing your wanting to pass it a variable....

if you want to pass a variable to it... try this...

Code: Select all

#!/bin/bash
THESTRING="$@"
THESTRING="${THESTRING//\\/\\\\}"
TEMPVAR="$(/usr/local/bin/winepath "$THESTRING")"
echo "${TEMPVAR#${TEMPVAR%:*}:}"
same thing basically, but it switches out all the single \ in the path its passing to be escaped as \\ before calling winepath with it.

you still have to use single quotes around the string if you type it in manually... such as
winepathOSX 'Z:\Applications\Firefly\BENCH1.out'

but this way if you pass it a variable and have it work right...
TEST='Z:\Applications\Firefly\BENCH1.out'
winepathOSX $TEST
will display
/Applications/Firefly/BENCH1.out


If your variable is getting set and really contains "Z:\Applications\Firefly\BENCH1.out" exactly as seen and passed in with a variable, the extra lines I added above should take care of it.

Winepath in wine is actually functioning correctly. The problem is the command line itself... when you type
winepath Z:\Applications\Firefly\BENCH1.out
it is not sending the string as you see it to winepath, winepath is getting the wrong information.... there is nothing winepath can do to change that.... you have to single quote it, or escape all the reserved characters.
you can see this if you type...
TEST=Z:\Applications\Firefly\BENCH1.out
with no quotes like that.. then see what actually got read...
echo $TEST
and it will NOT be what your wanting it to be, because the \ is not read literally, its a reserved character.
TEST=Z:\\Applications\\Firefly\\BENCH1.out
this would work though, as a \ is telling it the next character is a literal character to take, so \\ would become a single \ in the string.
the extra 2 lines I added above is basically turning all the \ in the string to \\ so when its passed to winepath, its correct.
tpatko
Level 2
Level 2
Posts: 32
Joined: Thu Aug 06, 2009 12:29 am

Post by tpatko »

Thank you for the assistance. That final modified script worked perfectly when the file path was passed as a parameter from a Windows program running through WINE.

Cheers,

Thomas

:D
Locked