10

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?

11
  • 1
    I think this belongs in superuser or linux. Commented Apr 18, 2014 at 5:42
  • I never tried, but I would try at least SHGetFolderPath with CSIDL_PROFILE. Commented Apr 18, 2014 at 5: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. Commented Apr 18, 2014 at 5:50
  • does any of this help? winehq.org/docs/wineusr-guide/environment-variables Commented Apr 18, 2014 at 5: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). Commented Apr 18, 2014 at 5:55

2 Answers 2

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:\).

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.

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.