forked from chocolatey/choco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stuff that's still a bit busted - RemoteDownloader - WebHelper - GetPackageParameterCommand (maybe?)
- Loading branch information
Showing
45 changed files
with
5,324 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/Chocolatey.PowerShell/Commands/AddChocolateyPinnedTaskbarItemCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
using System.Text; | ||
using Chocolatey.PowerShell.Helpers; | ||
using Chocolatey.PowerShell.Shared; | ||
|
||
namespace Chocolatey.PowerShell.Commands | ||
{ | ||
[Cmdlet(VerbsCommon.Add, "ChocolateyPinnedTaskbarItem")] | ||
public class AddChocolateyPinnedTaskbarItemCommand : ChocolateyCmdlet | ||
{ | ||
/* | ||
.SYNOPSIS | ||
Creates an item in the task bar linking to the provided path. | ||
.NOTES | ||
Does not work with SYSTEM, but does not error. It warns with the error | ||
message. | ||
.INPUTS | ||
None | ||
.OUTPUTS | ||
None | ||
.PARAMETER TargetFilePath | ||
The path to the application that should be launched when clicking on the | ||
task bar icon. | ||
.PARAMETER IgnoredArguments | ||
Allows splatting with arguments that do not apply. Do not use directly. | ||
.EXAMPLE | ||
> | ||
# This will create a Visual Studio task bar icon. | ||
Install-ChocolateyPinnedTaskBarItem -TargetFilePath "${env:ProgramFiles(x86)}\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe" | ||
.LINK | ||
Install-ChocolateyShortcut | ||
.LINK | ||
Install-ChocolateyExplorerMenuItem | ||
*/ | ||
|
||
[Parameter(Mandatory = true, Position = 0)] | ||
[Alias("TargetFilePath")] | ||
public string Path { get; set; } = string.Empty; | ||
|
||
protected override void End() | ||
{ | ||
const string verb = "Pin To Taskbar"; | ||
var targetFolder = PSHelper.GetParentDirectory(this, Path); | ||
var targetItem = PSHelper.GetFileName(Path); | ||
|
||
try | ||
{ | ||
if (!PSHelper.ItemExists(this, Path)) | ||
{ | ||
WriteWarning($"'{Path}' does not exist, not able to pin to task bar"); | ||
return; | ||
} | ||
|
||
dynamic shell = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application")); | ||
var folder = shell.NameSpace(targetFolder); | ||
var item = folder.ParseName(targetItem); | ||
|
||
bool verbFound = false; | ||
foreach (var itemVerb in item.Verbs()) | ||
{ | ||
var name = (string)itemVerb.Name; | ||
if (name.Replace("&", string.Empty) == verb) | ||
{ | ||
verbFound = true; | ||
itemVerb.DoIt(); | ||
break; | ||
} | ||
} | ||
|
||
if (!verbFound) | ||
{ | ||
WriteHost($"TaskBar verb not found for {targetItem}. It may have already been pinned"); | ||
} | ||
|
||
WriteHost($"'{Path}' has been pinned to the task bar on your desktop"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
WriteWarning($"Unable to create pin. Error captured was {ex.Message}."); | ||
} | ||
|
||
base.EndProcessing(); | ||
} | ||
} | ||
} |
139 changes: 139 additions & 0 deletions
139
src/Chocolatey.PowerShell/Commands/ExpandChocolateyArchiveCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Management.Automation; | ||
using System.Net.NetworkInformation; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
using Chocolatey.PowerShell.Helpers; | ||
using Chocolatey.PowerShell.Shared; | ||
|
||
namespace Chocolatey.PowerShell.Commands | ||
{ | ||
[Cmdlet(VerbsData.Expand, "ChocolateyArchive", DefaultParameterSetName = "Path")] | ||
[OutputType(typeof(string))] | ||
public class ExpandChocolateyArchiveCommand : ChocolateyCmdlet | ||
{ | ||
/* | ||
.SYNOPSIS | ||
Unzips an archive file and returns the location for further processing. | ||
.DESCRIPTION | ||
This unzips files using the 7-zip command line tool 7z.exe. | ||
Supported archive formats are listed at: | ||
https://sevenzip.osdn.jp/chm/general/formats.htm | ||
.INPUTS | ||
None | ||
.OUTPUTS | ||
Returns the passed in $destination. | ||
.NOTES | ||
If extraction fails, an exception is thrown. | ||
If you are embedding files into a package, ensure that you have the | ||
rights to redistribute those files if you are sharing this package | ||
publicly (like on the community feed). Otherwise, please use | ||
Install-ChocolateyZipPackage to download those resources from their | ||
official distribution points. | ||
Will automatically call Set-PowerShellExitCode to set the package exit code | ||
based on 7-zip's exit code. | ||
.PARAMETER FileFullPath | ||
This is the full path to the zip file. If embedding it in the package | ||
next to the install script, the path will be like | ||
`"$(Split-Path -Parent $MyInvocation.MyCommand.Definition)\\file.zip"` | ||
`File` is an alias for FileFullPath. | ||
This can be a 32-bit or 64-bit file. This is mandatory in earlier versions | ||
of Chocolatey, but optional if FileFullPath64 has been provided. | ||
.PARAMETER FileFullPath64 | ||
Full file path to a 64-bit native installer to run. | ||
If embedding in the package, you can get it to the path with | ||
`"$(Split-Path -parent $MyInvocation.MyCommand.Definition)\\INSTALLER_FILE"` | ||
Provide this when you want to provide both 32-bit and 64-bit | ||
installers or explicitly only a 64-bit installer (which will cause a package | ||
install failure on 32-bit systems). | ||
.PARAMETER Destination | ||
This is a directory where you would like the unzipped files to end up. | ||
If it does not exist, it will be created. | ||
.PARAMETER SpecificFolder | ||
OPTIONAL - This is a specific directory within zip file to extract. The | ||
folder and its contents will be extracted to the destination. | ||
.PARAMETER PackageName | ||
OPTIONAL - This will facilitate logging unzip activity for subsequent | ||
uninstalls | ||
.PARAMETER DisableLogging | ||
OPTIONAL - This disables logging of the extracted items. It speeds up | ||
extraction of archives with many files. | ||
Usage of this parameter will prevent Uninstall-ChocolateyZipPackage | ||
from working, extracted files will have to be cleaned up with | ||
Remove-Item or a similar command instead. | ||
.PARAMETER IgnoredArguments | ||
Allows splatting with arguments that do not apply. Do not use directly. | ||
.EXAMPLE | ||
> | ||
# Path to the folder where the script is executing | ||
$toolsDir = (Split-Path -parent $MyInvocation.MyCommand.Definition) | ||
Get-ChocolateyUnzip -FileFullPath "c:\someFile.zip" -Destination $toolsDir | ||
.LINK | ||
Install-ChocolateyZipPackage | ||
*/ | ||
|
||
[Alias("File", "FileFullPath")] | ||
[Parameter(Mandatory = true, Position = 0, ParameterSetName = "Path")] | ||
public string Path { get; set; } = string.Empty; | ||
|
||
[Alias("UnzipLocation")] | ||
[Parameter(Mandatory = true, Position = 1)] | ||
public string Destination { get; set; } = string.Empty; | ||
|
||
[Parameter(Position = 2)] | ||
public string SpecificFolder { get; set; } | ||
|
||
[Parameter(Position = 3)] | ||
public string PackageName { get; set; } | ||
|
||
[Alias("File64", "FileFullPath64")] | ||
[Parameter(Mandatory = true, ParameterSetName = "Path64")] | ||
[Parameter(ParameterSetName = "Path")] | ||
public string Path64 { get; set; } | ||
|
||
[Parameter] | ||
public SwitchParameter DisableLogging { get; set; } | ||
|
||
protected override void End() | ||
{ | ||
// This case should be prevented by the parameter set definitions, | ||
// but it doesn't hurt to make absolutely sure here as well. | ||
if (!(BoundParameters.ContainsKey(nameof(Path)) || BoundParameters.ContainsKey(nameof(Path64)))) | ||
{ | ||
ThrowTerminatingError(new RuntimeException("Parameters are incorrect; either -Path or -Path64 must be specified.").ErrorRecord); | ||
} | ||
|
||
var helper = new SevenZipHelper(this, PipelineStopToken); | ||
helper.Run7zip(Path, Path64, PackageName, Destination, SpecificFolder, DisableLogging); | ||
|
||
WriteObject(Destination); | ||
|
||
base.EndProcessing(); | ||
} | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
src/Chocolatey.PowerShell/Commands/GetChocolateyConfigValueCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using chocolatey; | ||
using Chocolatey.PowerShell; | ||
using Chocolatey.PowerShell.Helpers; | ||
using Chocolatey.PowerShell.Shared; | ||
using System; | ||
using System.Collections; | ||
using System.Linq; | ||
using System.Management.Automation; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Xml; | ||
|
||
namespace Chocolatey.PowerShell.Commands | ||
{ | ||
[Cmdlet(VerbsCommon.Get, "ChocolateyConfigValue")] | ||
public class GetChocolateyConfigValueCommand : ChocolateyCmdlet | ||
{ | ||
[Parameter(Mandatory = true)] | ||
public string ConfigKey { get; set; } | ||
|
||
protected override void End() | ||
{ | ||
var result = GetConfigValue(ConfigKey); | ||
|
||
WriteObject(result); | ||
} | ||
|
||
private string GetConfigValue(string key) | ||
{ | ||
if (key is null) | ||
{ | ||
return null; | ||
} | ||
|
||
string configString = null; | ||
Exception error = null; | ||
foreach (var reader in InvokeProvider.Content.GetReader(ApplicationParameters.GlobalConfigFileLocation)) | ||
{ | ||
try | ||
{ | ||
var results = reader.Read(1); | ||
if (results.Count > 0) | ||
{ | ||
configString = PSHelper.ConvertTo<string>(results[0]); | ||
break; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
WriteWarning($"Could not read configuration file: {ex.Message}"); | ||
} | ||
} | ||
|
||
if (configString is null) | ||
{ | ||
// TODO: Replace RuntimeException | ||
var exception = error is null | ||
? new RuntimeException("Config file is missing or empty.") | ||
: new RuntimeException($"Config file is missing or empty. Error reading configuration file: {error.Message}", error); | ||
ThrowTerminatingError(exception.ErrorRecord); | ||
} | ||
|
||
var xmlConfig = new XmlDocument(); | ||
xmlConfig.LoadXml(configString); | ||
|
||
foreach (XmlNode configEntry in xmlConfig.SelectNodes("chocolatey/config/add")) | ||
{ | ||
var nodeKey = configEntry.Attributes["key"]; | ||
if (nodeKey is null || !IsEqual(nodeKey.Value, ConfigKey)) | ||
{ | ||
continue; | ||
} | ||
|
||
var value = configEntry.Attributes["value"]; | ||
if (!(value is null)) | ||
{ | ||
// We don't support duplicate config entries; once found, we're done here. | ||
return value.Value; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.