mirror of
https://github.com/derrod/legendary.git
synced 2024-12-22 17:55:27 +00:00
[cli/utils] Open CMD when exe is double-clicked (#436)
This opens up CMD if - the exe file was double-clicked - no arguments are provided - we're on Windows
This commit is contained in:
parent
594e60e850
commit
9e145278d5
|
@ -28,6 +28,7 @@ from legendary.utils.env import is_windows_mac_or_pyi
|
||||||
from legendary.utils.eos import add_registry_entries, query_registry_entries, remove_registry_entries
|
from legendary.utils.eos import add_registry_entries, query_registry_entries, remove_registry_entries
|
||||||
from legendary.utils.lfs import validate_files, clean_filename
|
from legendary.utils.lfs import validate_files, clean_filename
|
||||||
from legendary.utils.selective_dl import get_sdl_appname
|
from legendary.utils.selective_dl import get_sdl_appname
|
||||||
|
from legendary.utils.windows_helpers import double_clicked
|
||||||
from legendary.utils.wine_helpers import read_registry, get_shell_folders
|
from legendary.utils.wine_helpers import read_registry, get_shell_folders
|
||||||
|
|
||||||
# todo custom formatter for cli logger (clean info, highlighted error/warning)
|
# todo custom formatter for cli logger (clean info, highlighted error/warning)
|
||||||
|
@ -2903,6 +2904,10 @@ def main():
|
||||||
continue
|
continue
|
||||||
print(f'\nCommand: {choice}')
|
print(f'\nCommand: {choice}')
|
||||||
print(subparser.format_help())
|
print(subparser.format_help())
|
||||||
|
elif os.name == 'nt' and double_clicked():
|
||||||
|
print('Please note that this is not the intended way to run Legendary.')
|
||||||
|
print('Follow https://github.com/derrod/legendary/wiki/Setup-Instructions to set it up properly')
|
||||||
|
subprocess.Popen(['cmd', '/K', 'echo>nul'])
|
||||||
return
|
return
|
||||||
|
|
||||||
cli = LegendaryCLI(override_config=args.config_file, api_timeout=args.api_timeout)
|
cli = LegendaryCLI(override_config=args.config_file, api_timeout=args.api_timeout)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
import winreg
|
import winreg
|
||||||
|
import ctypes
|
||||||
|
|
||||||
_logger = logging.getLogger('WindowsHelpers')
|
_logger = logging.getLogger('WindowsHelpers')
|
||||||
|
|
||||||
|
@ -80,3 +81,16 @@ def set_registry_value(hive, key, value, data, reg_type=winreg.REG_SZ, use_32bit
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_logger.debug(f'Setting "{key}":"{value}" to "{data}" failed with {repr(e)}')
|
_logger.debug(f'Setting "{key}":"{value}" to "{data}" failed with {repr(e)}')
|
||||||
winreg.CloseKey(k)
|
winreg.CloseKey(k)
|
||||||
|
|
||||||
|
|
||||||
|
def double_clicked() -> bool:
|
||||||
|
# Thanks https://stackoverflow.com/a/55476145
|
||||||
|
|
||||||
|
# Load kernel32.dll
|
||||||
|
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
|
||||||
|
# Create an array to store the processes in. This doesn't actually need to
|
||||||
|
# be large enough to store the whole process list since GetConsoleProcessList()
|
||||||
|
# just returns the number of processes if the array is too small.
|
||||||
|
process_array = (ctypes.c_uint * 1)()
|
||||||
|
num_processes = kernel32.GetConsoleProcessList(process_array, 1)
|
||||||
|
return num_processes < 3
|
||||||
|
|
Loading…
Reference in a new issue