Somehow I didn't run into this with testing *this* invocation of
`win32gui.EnumWindows()`, but then I did over in EDMarketConnector.py. So,
as I had to handle the exception there, let's also do it here.
This is something the old code *didn't actually do*.
Tested with a 'pseudo ed' process (same MainWindowTitle) running as myself
(test matches), and via `runas` as another user (doesn't match).
Both the current `develop` code and this PR's new code share this behaviour.
What the code does is look for windows/processes *in the current Windows
session*, no matter if they're owned by the session user or not.
Neither version will find a process, that would match, if it's running in
another session, i.e. you'd need to switch to it via the windows Login screen.
* All of the implementation of the EnumWindows callback.
The documentation for pywin32 isn't great, in terms of finding the call
convention and necessary form of parameters, but once you do this is *much*
cleaner than using ctypes directly.
I'm not 100% certain that `win32api.OpenProcess()` has the same semantic as
the previous `GetProcessHandleFromHwnd()`, i.e. only getting the `handle`
back if the process is owned by the current user. If the user has
Windows Administrator rights they can probably kill other users' processes ?
After over an hour's struggle trying to get the win32/user32
`GetWindowTextW()` prototyped properly, and running into problem after problem:
1. Once you properly prototype this, including defining the 2nd `lpString`
parameter as 'out', ctypes wants to just *return* that.
2. This leads to then implementing a `.errcheck` property so that you
can *also* check the INT result for errors.
3. But then you just run into another error.
I finally found <https://stackoverflow.com/a/10905155> which pointed out
you can simply use `win32gui.GetWindowText()` from `pywin32`. Tested, it
simply works, no errors/exceptions.
This is actually to do with a reported issue around the ctypes code in
`EDLogs.gamerunning()` causing:
```python
exception ignored on calling ctypes callback function: <function EDLogs.game_running.<locals>.callback at 0x0000020E9C9D0EA0>
Traceback (most recent call last):
File "monitor.pyc", line 2041, in callback
File "monitor.pyc", line 2034, in WindowTitle
ctypes.ArgumentError: argument 1: OverflowError: int too long to convert
```
Although I can't personally get this to trigger at all under 64-bit python,
either in PyCharm *or* with the 5.7.1-alpha1 64-bit pre-release.
`game_running()` is only used in a few places, and the key things it
malfunctioning might cause are lack of the synthetic `ShutDown` (already
has an INFO logging) and `StartUp` events.
* Because the archive is a new file in the root it causes:
`tar: EDMarketConnector: file changed as we read it`
Verified on Linux/Debian, and also verified that this fix works.
thedoctor0/zip-release has a bug where only the first word in `exclusions`
has `--exclude=` pre-pended to it, the other words being treated as input
filenames/globs/paths. So, let's do this manually.
* On windows specifying only filenames to exclusions causes things like
`tar: .editorconfig: Cannot stat: No such file or directory`
But putting `EDMarketConnector/` prefix on such means they don't work.
* Testing with 'git bash' GNU tar 1.34:
`tar -c -v -z -f edmc-test.tar.gz --exclude=.editorconfig --exclude=.git\* EDMarketConnector`
works, with empty output from:
`tar tfvz edmc-test.tar.gz | grep editorconfig`
* I'd missed copying the `directory` line from zip to tar step.
* There's no reason we can't perform these steps *before* the build, or
even the python setup, so move them up there. That has the near side-effect
of not needing to exclude so much stuff.
* Move the definition of archive excludes to a global variable.
* Add another step to create a tar(.gz) archive as well.
* Add .tar.gz to the `Built files` handling.
It *seems* we don't need to specify both a directory and its contents.
Also, hopefully this will fix the:
Creating zip archive...
Command Line Error:
Unknown switch:
-
which the last run got. That was where the 'root' directory prefix was
added to all exclusions. Maybe the commandline got too long ?
zip-release does indeed create this in `directory`, so we need to specify
it should be *in* the 'root' directory that we're including *in* the zip file.
This *should* allow for easy setup to work on any XDG-compliant desktop
environment. Just run `scripts/linux-setup.sh` and it will:
1. Determine the 'root' directory of the EDMarketConnector source you're
using.
2. Check you have `${HOME}/bin` in PATH and it exists as a directory.
3. Copy `scripts/edmarketconnector.sh` to there, replacing the string
`EDMC_PATH` with the 'root' directory.
4. Copy .png (icon) and .desktop files into ~/.local/share/... locations.
Then the desktop environment should have a menu entry for
"E:D Market Connector", which attempts to run `edmarketconnector`, which
should now be the shell script present in ${HOME}/bin.
1. `io.edcd.EDMarketConnector.desktop` based on the flathub one, but with
reference to v1.5 of the spec (linked in a file comment).
2. As the Icon is specified using `io.edcd.EDMarketConnector`, not only
`EDMarketConnector`, renamed the .png file and updated the single code
reference to it.