diff --git a/.gitignore b/.gitignore index 73410d5..8b110c2 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,9 @@ $RECYCLE.BIN/ *.msm *.msp +# IDE specific +.idea/ + # Windows shortcuts *.lnk diff --git a/README.md b/README.md index dfa47ae..fcc435e 100644 --- a/README.md +++ b/README.md @@ -321,7 +321,8 @@ quit by running `px --quit`. When running in the foreground, use `CTRL-C`. Px can also be setup to automatically run on startup on Windows with the `--install` flag. This is done by adding an entry into the Window registry which -can be removed with `--uninstall`. +can be removed with `--uninstall`. You can provide `--force` to the install command +in order to always write the key, even if an existing one is there. NOTE: Command line parameters passed with `--install` are not saved for use on startup. The `--save` flag or manual editing of `px.ini` is required to provide @@ -344,8 +345,8 @@ Actions: Values specified on CLI override any values in existing config file Values not specified on CLI or config file are set to defaults - --install - Add Px to the Windows registry to run on startup + --install [--force] + Add Px to the Windows registry to run on startup. Use '--force' to overwrite a possible existing key. --uninstall Remove Px from the Windows registry diff --git a/px/config.py b/px/config.py index 2b93331..aa5fd5a 100644 --- a/px/config.py +++ b/px/config.py @@ -823,7 +823,7 @@ def parse_config(self): if sys.platform == "win32": if "--install" in sys.argv: - windows.install(get_script_cmd()) + windows.install(get_script_cmd(), '--force' in sys.argv) elif "--uninstall" in sys.argv: windows.uninstall() diff --git a/px/help.py b/px/help.py index a646f02..3e6069b 100644 --- a/px/help.py +++ b/px/help.py @@ -18,8 +18,8 @@ Values specified on CLI override any values in existing config file Values not specified on CLI or config file are set to defaults - --install - Add Px to the Windows registry to run on startup + --install [--force] + Add Px to the Windows registry to run on startup. Use '--force' to overwrite a possible existing key. --uninstall Remove Px from the Windows registry diff --git a/px/windows.py b/px/windows.py index 0883d51..22f1085 100644 --- a/px/windows.py +++ b/px/windows.py @@ -17,22 +17,21 @@ ### # Install Px to startup -def check_installed(): +def is_installed(): "Check if Px is already installed in the Windows registry" - ret = True runkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Run", 0, winreg.KEY_READ) try: winreg.QueryValueEx(runkey, "Px") except FileNotFoundError: - ret = False - winreg.CloseKey(runkey) - - return ret + return False + finally: + winreg.CloseKey(runkey) + return True -def install(script_cmd): +def install(script_cmd, force_overwrite): "Install Px to Windows registry if not already" - if check_installed() is False: + if not is_installed() or force_overwrite: runkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Run", 0, winreg.KEY_WRITE) @@ -47,7 +46,7 @@ def install(script_cmd): def uninstall(): "Uninstall Px from Windows registry if installed" - if check_installed() is True: + if is_installed() is True: runkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Run", 0, winreg.KEY_WRITE)