Skip to content

Commit

Permalink
Added -v arg to pipe server, bumped its version to 1.4.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
bvbohnen committed Jul 6, 2021
1 parent 4533630 commit 06be770
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 18 deletions.
18 changes: 11 additions & 7 deletions X4_Python_Pipe_Server/Classes/Pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ class Pipe_Server(Pipe):
Call Connect to wait for a client to connect to the pipe.
Use Read and Write to interact with the pipe.
'''
def __init__(self, pipe_name, buffer_size = None):
def __init__(self, pipe_name, buffer_size = None, verbose = False):
super().__init__(pipe_name, buffer_size)
self.verbose = verbose


# Note: at least one user had access_denied errors from the x4
Expand All @@ -172,6 +173,7 @@ def __init__(self, pipe_name, buffer_size = None):
# Note: for the person with perm problems, "Everyone" and
# "Administrators" lookups failed (1332 error), but the user lookup
# worked, and just setting read/write for the user was sufficient.
# TODO: a couple others have reported perm problems still; unknown reason.
perms_set = False
for account_name in [win32api.GetUserName()]:
try:
Expand All @@ -181,11 +183,13 @@ def __init__(self, pipe_name, buffer_size = None):
con.FILE_GENERIC_READ | con.FILE_GENERIC_WRITE,
account_id)
perms_set = True
if self.verbose:
print(f'Setting pipe read/write permission for account "{account_name}"')
except win32api.error as ex:
# -Removed; don't really need this print except for debugging.
#print(f'Failed to set read/write permission for account '
# f'"{account_name}"; error code {ex.winerror} in '
# f'{ex.funcname} : {ex.strerror}')
if self.verbose:
print(f'Failed to set pipe read/write permission for account '
f'"{account_name}"; error code {ex.winerror} in '
f'{ex.funcname} : {ex.strerror}')
continue

if perms_set:
Expand All @@ -194,12 +198,12 @@ def __init__(self, pipe_name, buffer_size = None):
sec_desc.SetSecurityDescriptorDacl(1, dacl, 0)
# Leave user/group/etc. at defaults (eg. unspecified).
else:
# If all perms failed, just clear this and used defaults.
# If all perms failed, just clear this and use defaults.
sec_desc = None

# Create the pipe in server mode.
self.pipe_file = win32pipe.CreateNamedPipe(
# Note: for some dumb reason, this doesn't use keyword args,
# Note: for some reason this doesn't use keyword args,
# so arg names included in comments.
# pipeName
self.pipe_path,
Expand Down
18 changes: 9 additions & 9 deletions X4_Python_Pipe_Server/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
temp copy of test args:
-t -x "C:\Steam\steamapps\common\X4 Foundations" -m "extensions\sn_measure_perf\python\Measure_Perf.py"
'''
# Manually list the version for now, since packed exe won't have
# access to the change_log.
version = '1.4'
# Note: version tag set by Make_Executable based on latest version
# in the change_log. This line should always start "version =".
version = '1.4.1'

# Setup include path to this package.
import sys
Expand Down Expand Up @@ -151,13 +151,13 @@ def Main():
help = 'Path to a specific python module to run in test mode,'
' relative to the x4-path.' )

#argparser.add_argument(
# '-v', '--verbose',
# action='store_true',
# help = 'Print extra messages.' )
argparser.add_argument(
'-v', '--verbose',
action='store_true',
help = 'Print extra messages.' )

args = argparser.parse_args(sys.argv[1:])

if args.permissions_path:
global permissions_path
permissions_path = Path.cwd() / (Path(args.permissions_path).resolve())
Expand Down Expand Up @@ -213,7 +213,7 @@ def Main():
# TODO: maybe reuse Server_Thread somehow, though don't actually
# want a separate thread for this.
try:
pipe = Pipe_Server(pipe_name)
pipe = Pipe_Server(pipe_name, verbose = args.verbose)

# For python testing, kick off a client thread.
if test_python_client:
Expand Down
20 changes: 20 additions & 0 deletions X4_Python_Pipe_Server/Make_Executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ def Make(*args):
if dist_folder.exists():
Clear_Dir(dist_folder)

# Check the change_log for the latest version (last * line).
version = ''
for line in reversed(open(This_dir / 'change_log.md', 'r').readlines()):
if line.strip().startswith('*'):
version = line.replace('*','').strip()
break

# Somewhat clumsy, but edit the Main.py file to change its internal
# version global.
main_text = (This_dir / 'Main.py').read_text()
for line in main_text.splitlines():
# Find the version (should be only) version line.
if line.startswith('version ='):
# Only replace it if it changed.
new_line = f"version = '{version}'"
if line != new_line:
main_text = main_text.replace(line, new_line)
(This_dir / 'Main.py').write_text(main_text)
break


# Generate lines for a hook file.
# Not currently used.
Expand Down
2 changes: 2 additions & 0 deletions X4_Python_Pipe_Server/change_log.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ Change Log
- Gave explicit pipe read/write security permission to the current user, to help avoid "access denied" errors on pipe opening in x4 for some users.
* 1.4
- Added configparser module to exe.
* 1.4.1
- Added "-v" ("--verbose") command line arg, which will print pipe access permission messages.
4 changes: 2 additions & 2 deletions extensions/sn_mod_support_apis/python/Send_Keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def main(args):
pipe = Pipe_Server(pipe_name)

# Enable test mode if requested.
global window_title
if args['test']:
# TODO: make more robust, eg. work with cmd.
# TODO: make title more robust, eg. work with cmd.
global window_title
window_title = 'python.exe'
# Set up the reader in another thread.
# Note: if doing this from a console window, pynput prevents ctrl-c
Expand Down
18 changes: 18 additions & 0 deletions extensions/sn_remove_dock_glow/Customizer_Script.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ def Remove_Dock_Glow():
' ...
' <parts>
' <part name="fx_glow">
' <lods>
' <lod index="0">
' <materials>
' <material id="1" ref="p1effects.p1_lightcone_soft"/>
' </materials>
' </lod>
' </lods>
' <size>
' <max x="719.8841" y="717.2308" z="662.7744"/>
' <center x="-3.051758E-05" y="349.1792" z="13.29515"/>
' </size>
' </part>
' </parts>
' ...
In testing:
Glow is the giant blue ball effect.
Expand All @@ -52,6 +66,10 @@ def Remove_Dock_Glow():
Note: terran stations use "dockarea_ter_m...", but do not have glow
effect, so can ignore them here.
TODO: look instead for p1effects.p1_lightcone_soft, which shows up in some
other places. Notably, some landmarks and piers. Maybe check the size
being above some threshold.
'''
# Find every "dockarea" file.
dock_files = Load_Files('*dockarea_arg_m_station*.xml')
Expand Down

0 comments on commit 06be770

Please sign in to comment.