Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chocolatey support (#56) #628

Merged
merged 16 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ APIKEY.txt
*.pyc
WebBasedData/screenshot_database.xlsx
WebBasedData/screenshot-database.json.backup
wingetui/choco-cli/
25 changes: 22 additions & 3 deletions wingetui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self):

def loadStuffThread(self):
try:
self.loadStatus = 0 # There are 8 items (preparation threads)
self.loadStatus = 0 # There are 9 items (preparation threads)

# Preparation threads
Thread(target=self.checkForRunningInstances, daemon=True).start()
Expand All @@ -115,6 +115,12 @@ def loadStuffThread(self):
self.loadStatus += 2
globals.componentStatus["wingetFound"] = False
globals.componentStatus["wingetVersion"] = _("{0} is disabled").format("Winget")
if not getSettings("DisableChocolatey"):
Thread(target=self.detectChocolatey, daemon=True).start()
else:
self.loadStatus += 1
globals.componentStatus["chocoFound"] = False
globals.componentStatus["chocoVersion"] = _("{0} is disabled").format("Chocolatey")
if not getSettings("DisableScoop"):
Thread(target=self.detectScoop, daemon=True).start()
else:
Expand All @@ -127,7 +133,7 @@ def loadStuffThread(self):
Thread(target=self.instanceThread, daemon=True).start()
Thread(target=self.updateIfPossible, daemon=True).start()

while self.loadStatus < 8:
while self.loadStatus < 9:
time.sleep(0.01)
except Exception as e:
print(e)
Expand Down Expand Up @@ -190,7 +196,20 @@ def detectWinget(self):
except Exception as e:
print(e)
self.loadStatus += 1


def detectChocolatey(self):
try:
self.callInMain.emit(lambda: self.loadingText.setText(_("Locating Chocolatey...")))
o = subprocess.run(f"{chocoHelpers.choco} -v", shell=True, stdout=subprocess.PIPE)
print(o.stdout)
print(o.stderr)
globals.componentStatus["chocoFound"] = o.returncode == 0
globals.componentStatus["chocoVersion"] = o.stdout.decode('utf-8').replace("\n", "")
self.callInMain.emit(lambda: self.loadingText.setText(_("Chocolatey found: {0}").format(globals.componentStatus['chocoFound'])))
except Exception as e:
print(e)
self.loadStatus += 1

def detectScoop(self):
try:
self.callInMain.emit(lambda: self.loadingText.setText(_("Locating Scoop...")))
Expand Down
857 changes: 857 additions & 0 deletions wingetui/choco-cli/CREDITS.txt

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions wingetui/choco-cli/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Copyright (c) 2017 Chocolatey Software, Inc.
Copyright (c) 2011 - 2017 RealDimensions Software, LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
67 changes: 67 additions & 0 deletions wingetui/choco-cli/bin/RefreshEnv.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
@echo off
::
:: RefreshEnv.cmd
::
:: Batch file to read environment variables from registry and
:: set session variables to these values.
::
:: With this batch file, there should be no need to reload command
:: environment every time you want environment changes to propagate

::echo "RefreshEnv.cmd only works from cmd.exe, please install the Chocolatey Profile to take advantage of refreshenv from PowerShell"
echo | set /p dummy="Refreshing environment variables from registry for cmd.exe. Please wait..."

goto main

:: Set one environment variable from registry key
:SetFromReg
"%WinDir%\System32\Reg" QUERY "%~1" /v "%~2" > "%TEMP%\_envset.tmp" 2>NUL
for /f "usebackq skip=2 tokens=2,*" %%A IN ("%TEMP%\_envset.tmp") do (
echo/set "%~3=%%B"
)
goto :EOF

:: Get a list of environment variables from registry
:GetRegEnv
"%WinDir%\System32\Reg" QUERY "%~1" > "%TEMP%\_envget.tmp"
for /f "usebackq skip=2" %%A IN ("%TEMP%\_envget.tmp") do (
if /I not "%%~A"=="Path" (
call :SetFromReg "%~1" "%%~A" "%%~A"
)
)
goto :EOF

:main
echo/@echo off >"%TEMP%\_env.cmd"

:: Slowly generating final file
call :GetRegEnv "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" >> "%TEMP%\_env.cmd"
call :GetRegEnv "HKCU\Environment">>"%TEMP%\_env.cmd" >> "%TEMP%\_env.cmd"

:: Special handling for PATH - mix both User and System
call :SetFromReg "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" Path Path_HKLM >> "%TEMP%\_env.cmd"
call :SetFromReg "HKCU\Environment" Path Path_HKCU >> "%TEMP%\_env.cmd"

:: Caution: do not insert space-chars before >> redirection sign
echo/set "Path=%%Path_HKLM%%;%%Path_HKCU%%" >> "%TEMP%\_env.cmd"

:: Cleanup
del /f /q "%TEMP%\_envset.tmp" 2>nul
del /f /q "%TEMP%\_envget.tmp" 2>nul

:: capture user / architecture
SET "OriginalUserName=%USERNAME%"
SET "OriginalArchitecture=%PROCESSOR_ARCHITECTURE%"

:: Set these variables
call "%TEMP%\_env.cmd"

:: Cleanup
del /f /q "%TEMP%\_env.cmd" 2>nul

:: reset user / architecture
SET "USERNAME=%OriginalUserName%"
SET "PROCESSOR_ARCHITECTURE=%OriginalArchitecture%"

echo | set /p dummy="Finished."
echo .
1 change: 1 addition & 0 deletions wingetui/choco-cli/bin/_processed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
01/10/2023 00:00:00
Binary file added wingetui/choco-cli/bin/choco.exe
Binary file not shown.
Binary file added wingetui/choco-cli/bin/chocolatey.exe
Binary file not shown.
Binary file added wingetui/choco-cli/bin/cinst.exe
Binary file not shown.
Binary file added wingetui/choco-cli/bin/clist.exe
Binary file not shown.
Binary file added wingetui/choco-cli/bin/cpush.exe
Binary file not shown.
Binary file added wingetui/choco-cli/bin/cuninst.exe
Binary file not shown.
Binary file added wingetui/choco-cli/bin/cup.exe
Binary file not shown.
Binary file added wingetui/choco-cli/choco.exe
Binary file not shown.
Empty file.
57 changes: 57 additions & 0 deletions wingetui/choco-cli/choco.exe.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="choco.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
Specifying requestedExecutionLevel node (below) will disable file and
registry virtualization.

Set level to "asInvoker" when you want choco to run under the context
of the user invoking. This is the same as Chocolatey behavior prior
to 0.10.4 and after 0.10.7.

Set level to "requireAdministrator" to only allow administrators to
run Chocolatey.

Set level to "highestAvailable" to allow non-admins to run in
non-administrative context, but require administrators to always run
with administrative privileges. This is the recommended and default
behavior of Chocolatey v0.10.4-0.10.6.1.

NOTE: Currently you will need to make this change every time
Chocolatey is re-installed or upgraded (every new version). At least
for now - https://github.com/chocolatey/choco/issues/1206

The following is an unsupported use case: If you want to utilize File
and Registry Virtualization for backward compatibility then delete
the requestedExecutionLevel node.

NOTE: If you do change this file, make sure that you change the
modification date on choco.exe that this sits next to. Windows
caches manifests based on path and last modified date. So you'll
need to change the modification date on choco.exe for the manifest
change to take effect.
Details: https://github.com/chocolatey/choco/issues/1292#issuecomment-304068121
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 / Windows Server 2016 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
<!-- Windows 8.1 / Windows Server 2012 R2 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows 8 / Windows Server 2012 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!-- Windows 7 / Windows Server 2008 R2 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Windows Vista / Windows Server 2008 -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
</application>
</compatibility>
</asmv1:assembly>
49 changes: 49 additions & 0 deletions wingetui/choco-cli/config/chocolatey.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<chocolatey xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<config>
<add key="cacheLocation" value="" description="Cache location if not TEMP folder. Replaces `$env:TEMP` value for choco.exe process. It is highly recommended this be set to make Chocolatey more deterministic in cleanup." />
<add key="containsLegacyPackageInstalls" value="true" description="Install has packages installed prior to 0.9.9 series." />
<add key="commandExecutionTimeoutSeconds" value="2700" description="Default timeout for command execution. '0' for infinite (starting in 0.10.4)." />
<add key="proxy" value="" description="Explicit proxy location. Available in 0.9.9.9+." />
<add key="proxyUser" value="" description="Optional proxy user. Available in 0.9.9.9+." />
<add key="proxyPassword" value="" description="Optional proxy password. Encrypted. Available in 0.9.9.9+." />
<add key="webRequestTimeoutSeconds" value="30" description="Default timeout for web requests. Available in 0.9.10+." />
<add key="proxyBypassList" value="" description="Optional proxy bypass list. Comma separated. Available in 0.10.4+." />
<add key="proxyBypassOnLocal" value="true" description="Bypass proxy for local connections. Available in 0.10.4+." />
<add key="upgradeAllExceptions" value="" description="A comma-separated list of package names that should not be upgraded when running `choco upgrade all'. Defaults to empty. Available in 0.10.14+." />
<add key="defaultTemplateName" value="" description="Default template name used when running 'choco new' command. Available in 0.12.0+." />
</config>
<sources>
<source id="chocolatey" value="https://community.chocolatey.org/api/v2/" disabled="false" bypassProxy="false" selfService="false" adminOnly="false" priority="0" />
</sources>
<features>
<feature name="checksumFiles" enabled="true" setExplicitly="false" description="Checksum files when pulled in from internet (based on package)." />
<feature name="autoUninstaller" enabled="true" setExplicitly="false" description="Uninstall from programs and features without requiring an explicit uninstall script." />
<feature name="allowGlobalConfirmation" enabled="false" setExplicitly="false" description="Prompt for confirmation in scripts or bypass." />
<feature name="failOnAutoUninstaller" enabled="false" setExplicitly="false" description="Fail if automatic uninstaller fails." />
<feature name="failOnStandardError" enabled="false" setExplicitly="false" description="Fail if install provider writes to stderr. Not recommended for use. Available in 0.9.10+." />
<feature name="allowEmptyChecksums" enabled="false" setExplicitly="false" description="Allow packages to have empty/missing checksums for downloaded resources from non-secure locations (HTTP, FTP). Enabling is not recommended if using sources that download resources from the internet. Available in 0.10.0+." />
<feature name="allowEmptyChecksumsSecure" enabled="true" setExplicitly="false" description="Allow packages to have empty/missing checksums for downloaded resources from secure locations (HTTPS). Available in 0.10.0+." />
<feature name="powershellHost" enabled="true" setExplicitly="false" description="Use Chocolatey's built-in PowerShell host. Available in 0.9.10+." />
<feature name="logEnvironmentValues" enabled="false" setExplicitly="false" description="Log Environment Values - will log values of environment before and after install (could disclose sensitive data). Available in 0.9.10+." />
<feature name="virusCheck" enabled="false" setExplicitly="false" description="Virus Check - perform virus checking on downloaded files. Available in 0.9.10+. Licensed versions only." />
<feature name="failOnInvalidOrMissingLicense" enabled="false" setExplicitly="false" description="Fail On Invalid Or Missing License - allows knowing when a license is expired or not applied to a machine. Available in 0.9.10+." />
<feature name="ignoreInvalidOptionsSwitches" enabled="true" setExplicitly="false" description="Ignore Invalid Options/Switches - If a switch or option is passed that is not recognized, should choco fail? Available in 0.9.10+." />
<feature name="usePackageExitCodes" enabled="true" setExplicitly="false" description="Use Package Exit Codes - Package scripts can provide exit codes. With this on, package exit codes will be what choco uses for exit when non-zero (this value can come from a dependency package). Chocolatey defines valid exit codes as 0, 1605, 1614, 1641, 3010. With this feature off, choco will exit with 0, 1, or -1 (matching previous behavior). Available in 0.9.10+." />
<feature name="useEnhancedExitCodes" enabled="false" setExplicitly="false" description="Use Enhanced Exit Codes - Chocolatey is able to provide enhanced exit codes surrounding list, search, info, outdated and other commands that don't deal directly with package operations. To see enhanced exit codes and their meanings, please run `choco [cmdname] -?`. With this feature off, choco will exit with 0, 1, or -1 (matching previous behavior). Available in 0.10.12+." />
<feature name="exitOnRebootDetected" enabled="false" setExplicitly="false" description="Exit On Reboot Detected - Stop running install, upgrade, or uninstall when a reboot request is detected. Requires 'usePackageExitCodes' feature to be turned on. Will exit with either 350 or 1604. When it exits with 350, it means pending reboot discovered prior to running operation. When it exits with 1604, it means some work completed prior to reboot request being detected. Available in 0.10.12+." />
<feature name="useFipsCompliantChecksums" enabled="false" setExplicitly="false" description="Use FIPS Compliant Checksums - Ensure checksumming done by choco uses FIPS compliant algorithms. Not recommended unless required by FIPS Mode. Enabling on an existing installation could have unintended consequences related to upgrades/uninstalls. Available in 0.9.10+." />
<feature name="showNonElevatedWarnings" enabled="true" setExplicitly="false" description="Show Non-Elevated Warnings - Display non-elevated warnings. Available in 0.10.4+." />
<feature name="showDownloadProgress" enabled="true" setExplicitly="false" description="Show Download Progress - Show download progress percentages in the CLI. Available in 0.10.4+." />
<feature name="stopOnFirstPackageFailure" enabled="false" setExplicitly="false" description="Stop On First Package Failure - Stop running install, upgrade or uninstall on first package failure instead of continuing with others. As this will affect upgrade all, it is normally recommended to leave this off. Available in 0.10.4+." />
<feature name="useRememberedArgumentsForUpgrades" enabled="false" setExplicitly="false" description="Use Remembered Arguments For Upgrades - When running upgrades, use arguments for upgrade that were used for installation ('remembered'). This is helpful when running upgrade for all packages. Available in 0.10.4+. This is considered in preview for 0.10.4 and will be flipped to on by default in a future release." />
<feature name="ignoreUnfoundPackagesOnUpgradeOutdated" enabled="false" setExplicitly="false" description="Ignore Unfound Packages On Upgrade Outdated - When checking outdated or upgrades, if a package is not found against sources specified, don't report the package at all. Available in 0.10.9+." />
<feature name="skipPackageUpgradesWhenNotInstalled" enabled="false" setExplicitly="false" description="Skip Packages Not Installed During Upgrade - if a package is not installed, do not install it during the upgrade process. Available in 0.10.12+." />
<feature name="removePackageInformationOnUninstall" enabled="false" setExplicitly="false" description="Remove Stored Package Information On Uninstall - When a package is uninstalled, should the stored package information also be removed? Available in 0.10.9+." />
<feature name="logWithoutColor" enabled="false" setExplicitly="false" description="Log without color - Do not show colorization in logging output. Available in 0.10.9+." />
<feature name="logValidationResultsOnWarnings" enabled="true" setExplicitly="false" description="Log validation results on warnings - Should the validation results be logged if there are warnings? Available in 0.10.12+." />
<feature name="usePackageRepositoryOptimizations" enabled="true" setExplicitly="false" description="Use Package Repository Optimizations - Turn on optimizations for reducing bandwidth with repository queries during package install/upgrade/outdated operations. Should generally be left enabled, unless a repository needs to support older methods of query. When disabled, this makes queries similar to the way they were done in Chocolatey v0.10.11 and before. Available in 0.10.14+." />
<feature name="disableCompatibilityChecks" enabled="false" setExplicitly="false" description="Disable Compatibility Checks - Should a warning we shown, before and after command execution, when a runtime compatibility check determines that there is an incompatibility between Chocolatey and Chocolatey Licensed Extension. Available in 1.1.0+" />
</features>
<apiKeys />
</chocolatey>
21 changes: 21 additions & 0 deletions wingetui/choco-cli/config/chocolatey.config.backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<chocolatey>
<config>
<add key="cacheLocation" value="" />
<add key="containsLegacyPackageInstalls" value="true" />
<add key="commandExecutionTimeoutSeconds" value="2700" />
<add key="proxy" value="" />
<add key="proxyUser" value="" />
<add key="proxyPassword" value="" />
</config>
<sources>
<source id="chocolatey" value="https://community.chocolatey.org/api/v2/" />
</sources>
<features>
<feature name="checksumFiles" enabled="true" />
<feature name="autoUninstaller" enabled="false" />
<feature name="allowGlobalConfirmation" enabled="false" />
<feature name="failOnAutoUninstaller" enabled="false" />
<feature name="failOnStandardError" enabled="false" />
</features>
</chocolatey>