9

My Windows application is frequently used on *nix using Wine.

As it is a file-centric application, it frequently uses (and presents to an user) Windows "documents" folder (as resolved using CSIDL_PERSONAL). Unfortunately under Wine that points to fake Wine/Windows directory that's usually empty and unused. I'd like to point user to his Unix home folder instead.

Is there any reliable way to find out its location under Wine?

I was hoping I can read HOME environment variable, but it's not exported (contrary to most other variables) to Windows environment.

Currently I'm guessing the home using Z:\home\%USERNAME%. But that does not look robust to me.

If there's no way to find home directory, is there at least a way to detect Wine root drive (Z: by default), so I do not need to hard-code at least a drive-part of path?

Kara
  • 5,650
  • 15
  • 48
  • 55
Martin Prikryl
  • 147,050
  • 42
  • 335
  • 704
  • 1
    I think this belongs in superuser or linux. – PressingOnAlways Apr 18 '14 at 05:42
  • I never tried, but I would try at least SHGetFolderPath with CSIDL_PROFILE. – Matteo Italia Apr 18 '14 at 05:42
  • @PressingOnAlways I'm pretty sure I cannot detect it from environment (or other power-user-level interface). So I'm hoping for some API. As such it belongs here, afaik. – Martin Prikryl Apr 18 '14 at 05:50
  • does any of this help? http://www.winehq.org/docs/wineusr-guide/environment-variables – PressingOnAlways Apr 18 '14 at 05:53
  • @Martin: CSIDL_PROFILE != CSIDL_PERSONAL. The "My Documents" folder has no standardized Unix equivalent, but the profile directory on Unix is ~. Maybe it returns some fake directory anyway, but I would give it a try (another possibility is that it returns a "strange" directory that is actually a symlink to the home). – Matteo Italia Apr 18 '14 at 05:55
  • @PressingOnAlways I've seen this before. Though not sure how this helps. It made me believe that `HOME` is propagated (not being on black list like `PATH`, `SYSTEM` and `TEMP`). But it's not. – Martin Prikryl Apr 18 '14 at 05:59
  • @MartinPrikryl is other variables propagated? If so, can you just do export CUSTOM_HOME = $HOME or something like this in a bash script before you launch wine? – PressingOnAlways Apr 18 '14 at 06:01
  • @PressingOnAlways Yes of course. That's a hack I'm using atm, but I'd like my application to work on it's own, without need for Wine-specific wrapping script – Martin Prikryl Apr 18 '14 at 06:06
  • @MatteoItalia Sorry, I didn't notice you refer to different `CSIDL*`. But as expected `CSIDL_PROFILE` refers to `C:\users\%USERNAME%`. – Martin Prikryl Apr 18 '14 at 06:13
  • I have a few games installed in different directories, and all of them have $WINE_PREFIX/drive_c/windows/profiles//{Desktop,Documents,Music,...} a symlink to those in my $HOME (while the "All Users" directories are fake). Do you see anything different? – loreb Apr 22 '14 at 13:22
  • @loreb That's true. But the "My Documents" link is hidden on WinAPI level for some reason. ("My Music", "Desktop" and others are not). By hidden I mean absent (not hidden attribute). What makes it even worse actually as when `CSIDL_PERSONAL` resolves to kind-of non-existing folder, applications do not behave nicely. Even native Wine "Windows Explorer" gets confused, when you manually type in "My Documents" path. – Martin Prikryl Apr 23 '14 at 07:06

2 Answers2

9

For a lack of better answer, I'm sharing my current workaround/hack:

For *nix platforms, where I have deployment under control (OS X particularly), I copy the HOME environment variable to another variable from a startup script (say the WINE_HOME). Most environment variables (with notable exception of the HOME) are exported to Windows/Wine environment. So I can read the WINE_HOME from my application, prepend Z:\ and convert slashes to backslashes.

For platforms, where I do not have deployment under control, I can use the USERNAME variable only to guess the home as Z:\home\%USERNAME%. This particularly does not work on OS X, where the home is in the /users not the /home.

EDIT: I found a question Get Wine path of file that helps a bit. In *nix you can use the winepath -w ~ to get Z:\home\username. But running the same from Windows environment does not resolve the ~. You can at least run the winepath -w /home/username to get Z:\home\username to find out a drive of the Wine root (in case it's not the default Z:\).

Community
  • 1
  • 1
Martin Prikryl
  • 147,050
  • 42
  • 335
  • 704
2

In Wine drive Z: always maps to the root (/) hence your way of detecting is cool. But if the user does

rm ~/.wine/dosdevices/z\:

this won't work of course. In wine mailing this there was a discussion about the security implications of Z: mapping.

ismail
  • 41,546
  • 8
  • 79
  • 92
  • 1
    You can actually map `/` to any drive you want using `winecfg`. See https://wiki.winehq.org/Wine_User%27s_Guide#Drive_Settings *(comment re-posted with an updated link - originally posted in April 2014)* – Martin Prikryl Sep 16 '19 at 06:53