SFTtech / openage

Free (as in freedom) open source clone of the Age of Empires II engine 🚀
http://openage.dev
Other
12.73k stars 1.12k forks source link

Use wine to determine original game path #347

Closed TheJJ closed 8 years ago

TheJJ commented 9 years ago

The convert script could use wine to read the registry key where the original game is installed. This should work for both HD and AoC.

This is of course an optional step, we don't want to depend on wine.

When media conversion is required, the user could be prompted to "use wine?" or enter the path directly.

Currently favored idea:

A simple readline-based interface:

…Media needs to be converted…
Select an Age of Kings installation directory [or a setup folder]:
(0) Use previously used path "..."
(1) Insert manually
(2) $WINEPREFIX/drive_c/Program Files (x86)/Microsoft Games/Age of Empires II/
(3) $HOME/.wine/drive_c/Program Files (x86)/Microsoft Games/Age of Empires II/
[default: 0] > _

The list could be populated programmatically:

charego commented 9 years ago

I tried querying for the installation directory using the following command. Unfortunately reg query does not seem to be implemented in wine yet: https://bugs.winehq.org/show_bug.cgi?id=24017, it is just a stub implementation.

$ wine reg query "HKLM\Software\Microsoft\Microsoft Games\Age of Empires\2.0"
STUB QUERY - HKLM\Software\Microsoft\Microsoft Games\Age of Empires\2.0 0 0

The value could be read directly from the text file ~/.wine/system.reg, with a little bit of parsing.

To be precise, if you search for [Software\\Wow6432Node\\Microsoft\\Microsoft Games\\Age of Empires\\2.0], the InstallationDirectory key-value pair is a few lines below it. Other users might not have the Wow6432Node in there.

TheJJ commented 9 years ago

Hmm kay, wine does support registry keys though, i can't imagine they don't have a working query function. If they just don't have a cli program supporting this, we either ship a program to query via winapi function xor implement this reg query upstream for them (yaaay).

charego commented 9 years ago

I'll give the first option a try, i.e. write codez to use RegQueryValueEx or similar.

TheJJ commented 9 years ago

You can use Python ctypes for that, might be totally easy with that.

TheJJ commented 9 years ago

Btw we have to watch out that many users use custom wineprefixes. if we can't find the registry entry in the default prefix (used by empty WINEPREFIX=), we still have to ask the user what the path of the correct wineprefix is. We can of course also honor the already-set WINEPREFIX env variable.

azrdev commented 8 years ago

I think a more simple, still useful change would be to propose $WINEPREFIX/drive_c/Program Files (x86)/Microsoft Games/Age of Empires II/ That way, you can keep/configure a custom wineprefix. I'd assume most people don't change an installation path if installing on wine.

TheJJ commented 8 years ago

Good idea! Ideally we should launch a simple gtk3 gui that lets a user select the path with the gtk-file-chooser and also offers to just select a predefined path.

The "standard" path can be checked if it's a valid age2 dir then, a green mark says wheee it'll probably work.

azrdev commented 8 years ago

@TheJJ when you introduce a launcher, merge this selection into the GUI - until then, I'd advise against using such a single-spot GUI. It will only confuse people and break the current CLI-only workflow. I imagine a simple readline-based interface:

…Media needs to be converted…
Select an Age of Kings installation directory [or a setup folder]:
(0) Insert manually
(1) $WINEPREFIX/drive_c/Program Files (x86)/Microsoft Games/Age of Empires II/
(2) $HOME/.wine/drive_c/Program Files (x86)/Microsoft Games/Age of Empires II/
[default: 0] > _

The list could be populated programmatically:

Maybe I'll submit a patch for this later.

TheJJ commented 8 years ago

Yea, good thoughts, that seems to be a user-friendly variant for now. Do you think it'd be hard implementing some tab completion for the path entry? I have never done that before :)

azrdev commented 8 years ago

Do you think it'd be hard implementing some tab completion for the path entry?

Yes, I wouldn't even try to do this by hand. Maybe we could get something here if we'd move the whole CLI user interaction to a library like ncurses, but idk and details.

I imagined in my proposal that you could copy from the displayed proposals if they only fit you partially.

TheJJ commented 8 years ago

I copied your idea, a bit changed, to the top post now.

azrdev commented 8 years ago

thx. Also, we should support/evaluate environment variables in the user-supplied path. Currently both of these die with a traceback:

$HOME/.wine/drive_c/Program Files (x86)/Microsoft Games/Age of Empires II/
~/.wine/drive_c/Program Files (x86)/Microsoft Games/Age of Empires II/
jamesmcm commented 8 years ago

I think it would be cool if it checked this (if ~/.wine exists) and suggests it, otherwise the user can choose to launch a zenity file dialogue or just type the path in? (if people don't mind adding a zenity dependency?)

TheJJ commented 8 years ago

Mind there should be multiple wine prefixes that are not named ~/.wine.

My advice here is to use https://docs.python.org/3/library/curses.html for now and do this within our rendered GUI frontend once it's in place.

So you can select between:

in some interactive terminal selection.

azrdev commented 8 years ago

@TheJJ implemented proposals based on ~/.wine and $WINEPREFIX. Expansion of ~ and $VARIABLE already worked, I added paths relative to the current working directory.

I had a quick look on curses, it seems way too low-level. In doubt, I'd settle with zenity (you call zenity --file-selection --directory, it opens a GTK dialog & prints the selected dir). However, the current interface seems good to me.


What's left for future work from this issue:

idleberg commented 8 years ago

Sorry for re-opening this, I came across this through a Google search. Have you thought about using regedit?

wine regedit /E aoe.reg "HKLM\Software\Microsoft\Microsoft Games\Age of Empires\2.0"

You should then be able to parse aoe.reg using ConfigParser.

TheJJ commented 8 years ago

Cool idea, we should add this additionally.

azrdev commented 8 years ago

Implemented it, but didn't test. Please do before merging https://github.com/SFTtech/openage/pull/528