diff --git a/wingetui/__init__.py b/wingetui/__init__.py index 7c8dd5b22e..499607b9ed 100644 --- a/wingetui/__init__.py +++ b/wingetui/__init__.py @@ -199,7 +199,7 @@ def detectWinget(self): def detectScoop(self): try: self.callInMain.emit(lambda: self.loadingText.setText(_("Locating Scoop..."))) - o = subprocess.run(f"powershell -Command scoop -v", shell=True, stdout=subprocess.PIPE) + o = subprocess.run(f"{scoopHelpers.scoop} -v", shell=True, stdout=subprocess.PIPE) print(o.stdout) print(o.stderr) globals.componentStatus["scoopFound"] = o.returncode == 0 @@ -211,14 +211,13 @@ def detectScoop(self): try: if not getSettings("DisableUpdateIndexes"): self.callInMain.emit(lambda: self.loadingText.setText(_("Clearing Scoop cache..."))) - p = subprocess.Popen(f"powershell -Command scoop cache rm *", shell=True, stdout=subprocess.PIPE) - + p = subprocess.Popen(f"{scoopHelpers.scoop} cache rm *", shell=True, stdout=subprocess.PIPE) p.wait() except Exception as e: print(e) try: if(getSettings("EnableScoopCleanup")): - p2 = subprocess.Popen(f"powershell -Command scoop cleanup --all", shell=True, stdout=subprocess.PIPE) + p2 = subprocess.Popen(f"{scoopHelpers.scoop} cleanup --all", shell=True, stdout=subprocess.PIPE) p2.wait() except Exception as e: report(e) @@ -226,7 +225,7 @@ def detectScoop(self): try: if not getSettings("DisableUpdateIndexes"): self.callInMain.emit(lambda: self.loadingText.setText(_("Updating Scoop sources..."))) - o = subprocess.run(f"powershell -Command scoop update", shell=True, stdout=subprocess.PIPE) + o = subprocess.run(f"{scoopHelpers.scoop} update", shell=True, stdout=subprocess.PIPE) self.callInMain.emit(lambda: self.loadingText.setText(_("Updated Scoop sources"))) except Exception as e: print(e) diff --git a/wingetui/resources/install_scoop.cmd b/wingetui/resources/install_scoop.cmd index 01aa6f2b94..469a8e5057 100644 --- a/wingetui/resources/install_scoop.cmd +++ b/wingetui/resources/install_scoop.cmd @@ -1,10 +1,5 @@ @echo off echo This script will install Scoop and the dependencies required by WingetUI. pause -powershell -NoProfile -Command "Set-ExecutionPolicy RemoteSigned -Scope CurrentUser" -echo Installing scoop... -powershell -NoProfile -Command "iex ""& {$(irm get.scoop.sh)} -RunAsAdmin""" -echo Installing git... -powershell -NoProfile -Command "scoop install git" -echo Done! +powershell -ExecutionPolicy ByPass -File "%~dp0\install_scoop.ps1" pause diff --git a/wingetui/resources/install_scoop.ps1 b/wingetui/resources/install_scoop.ps1 new file mode 100644 index 0000000000..657a9cd343 --- /dev/null +++ b/wingetui/resources/install_scoop.ps1 @@ -0,0 +1,10 @@ +Write-Output "Installing scoop..." + +iex "& {$(irm get.scoop.sh)} -RunAsAdmin" + +If (-Not (Get-Command git -ErrorAction SilentlyContinue)) { + Write-Output "Installing git..." + scoop install git +} + +Write-Output "Done!" diff --git a/wingetui/resources/uninstall_scoop.cmd b/wingetui/resources/uninstall_scoop.cmd index b3489a18fe..c9abc3b9d3 100644 --- a/wingetui/resources/uninstall_scoop.cmd +++ b/wingetui/resources/uninstall_scoop.cmd @@ -2,9 +2,8 @@ echo This script will remove scoop from your machine. echo Removing scoop implies removing all scoop installed packages, buckets and preferences, and might also erase valuable user data related to the affected packages echo|set/p="Press to continue or CLOSE this window to abort this process"&runas/u: "">NUL -echo Installing scoop... -powershell -NoProfile -Command "scoop uninstall -p scoop" -echo Reverting ExecutionPolicy -powershell -NoProfile -Command "Set-ExecutionPolicy Restricted -Scope CurrentUser" +echo. +echo Uninstalling scoop... +powershell -ExecutionPolicy ByPass -Command "scoop uninstall -p scoop" echo Done! pause diff --git a/wingetui/scoopHelpers.py b/wingetui/scoopHelpers.py index 2e7de769c0..7cebd42101 100644 --- a/wingetui/scoopHelpers.py +++ b/wingetui/scoopHelpers.py @@ -6,6 +6,8 @@ ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]') +scoop = "powershell -ExecutionPolicy ByPass -Command scoop" + def searchForPackage(signal: Signal, finishSignal: Signal) -> None: print("🟢 Starting scoop search...") p = subprocess.Popen(' '.join(["powershell", "-Command", "scoop", "search"]), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, cwd=os.getcwd(), env=os.environ, shell=True)