Skip to content

Commit

Permalink
(chocolateyGH-697) Update Code With Documentation
Browse files Browse the repository at this point in the history
Update all of the code with documentation based on what
is needed and what is already available on the wiki. This
will allow documentation to have one source of truth
regarding Commands and PowerShell Helpers.
  • Loading branch information
ferventcoder committed Jun 3, 2016
1 parent 2a9e0ba commit 3ed1f37
Show file tree
Hide file tree
Showing 57 changed files with 2,695 additions and 913 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -82,7 +82,7 @@ If you need the previous behavior, be sure to disable the feature `usePackageExi
* Fix - Logger doesn't clear cached NullLoggers - see [#516](https://github.com/chocolatey/choco/issues/516)
* Fix - DISM "/All" argument in the wrong position - see [#480](https://github.com/chocolatey/choco/issues/480)
* Fix - Pro - Installing/uninstalling extensions should rename files in use - see [#594](https://github.com/chocolatey/choco/issues/594)
* Fix - Running Get-FileName in PowerShell 5 fails and sometimes causes package errors - see [#603](https://github.com/chocolatey/choco/issues/603)
* Fix - Running Get-WebFileName in PowerShell 5 fails and sometimes causes package errors - see [#603](https://github.com/chocolatey/choco/issues/603)
* Fix - Merging assemblies on a machine running .Net 4.5 or higher produces binaries incompatible with .Net 4 - see [#392](https://github.com/chocolatey/choco/issues/392)
* Fix - API - Incorrect log4net version in chocolatey.lib dependencies - see [#390](https://github.com/chocolatey/choco/issues/390)
* [POSH Host] Fix - Message after Download progress is on the same line sometimes - see [#525](https://github.com/chocolatey/choco/issues/525)
Expand Down
2 changes: 1 addition & 1 deletion nuget/chocolatey/chocolatey.nuspec
Expand Up @@ -137,7 +137,7 @@ If you need the previous behavior, be sure to disable the feature `usePackageExi
* Fix - Logger doesn't clear cached NullLoggers - see [#516](https://github.com/chocolatey/choco/issues/516)
* Fix - DISM "/All" argument in the wrong position - see [#480](https://github.com/chocolatey/choco/issues/480)
* Fix - Pro - Installing/uninstalling extensions should rename files in use - see [#594](https://github.com/chocolatey/choco/issues/594)
* Fix - Running Get-FileName in PowerShell 5 fails and sometimes causes package errors - see [#603](https://github.com/chocolatey/choco/issues/603)
* Fix - Running Get-WebFileName in PowerShell 5 fails and sometimes causes package errors - see [#603](https://github.com/chocolatey/choco/issues/603)
* Fix - Merging assemblies on a machine running .Net 4.5 or higher produces binaries incompatible with .Net 4 - see [#392](https://github.com/chocolatey/choco/issues/392)
* Fix - API - Incorrect log4net version in chocolatey.lib dependencies - see [#390](https://github.com/chocolatey/choco/issues/390)
* [POSH Host] Fix - Message after Download progress is on the same line sometimes - see [#525](https://github.com/chocolatey/choco/issues/525)
Expand Down
3 changes: 3 additions & 0 deletions src/chocolatey.resources/chocolatey.resources.csproj
Expand Up @@ -140,6 +140,9 @@
<ItemGroup>
<EmbeddedResource Include="helpers\functions\Set-PowerShellExitCode.ps1" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="helpers\functions\Install-Vsix.ps1" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
61 changes: 48 additions & 13 deletions src/chocolatey.resources/helpers/functions/Format-FileSize.ps1
@@ -1,25 +1,60 @@
# Copyright © 2011 - Present 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.

Function Format-FileSize() {
Param ([double]$size)
Foreach ($unit in @('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB')) {
If ($size -lt 1024) {
return [string]::Format("{0:0.##} {1}", $size, $unit)
}
$size /= 1024
Function Format-FileSize {
<#
.SYNOPSIS
DO NOT USE. Not part of the public API.
.DESCRIPTION
Formats file size into a human readable format.
.NOTES
Available in 0.9.10+.
This function is not part of the API.
.INPUTS
None
.OUTPUTS
Returns a string representation of the file size in a more friendly
format based on the passed in bytes.
.PARAMETER Size
The size of a file in bytes.
.PARAMETER IgnoredArguments
Allows splatting with arguments that do not apply. Do not use directly.
.EXAMPLE
Format-FileSize -Size $fileSizeBytes
.LINK
Get-WebFile
#>
param (
[Parameter(Mandatory=$true)][double]$size
)
Write-Debug "Running 'Format-FileSize' with size: '$size'";

Foreach ($unit in @('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB')) {
If ($size -lt 1024) {
return [string]::Format("{0:0.##} {1}", $size, $unit)
}
return [string]::Format("{0:0.##} YB", $size)
}
$size /= 1024
}

return [string]::Format("{0:0.##} YB", $size)
}
55 changes: 51 additions & 4 deletions src/chocolatey.resources/helpers/functions/Get-CheckSumValid.ps1
Expand Up @@ -12,12 +12,59 @@
# See the License for the specific language governing permissions and
# limitations under the License.


function Get-ChecksumValid {
<#
.SYNOPSIS
Checks a file's checksum versus a passed checksum and checksum type.
.DESCRIPTION
Makes a determination if a file meets an expected checksum. This
function is usually used when comparing a file that is downloaded from
an official distribution point. If the checksum fails to
match, this function throws an error.
.NOTES
This uses the checksum.exe tool available separately at
https://chocolatey.org/packages/checksum.
.INPUTS
None
.OUTPUTS
None
.PARAMETER File
The full path to a binary file that is checksummed and compared to the
passed Checksum parameter value.
.PARAMETER Checksum
The expected checksum hash value of the File resource. The checksum
type is covered by ChecksumType.
.PARAMETER ChecksumType
The type of checkum that the file is validated with - 'md5', 'sha1',
'sha256' or 'sha512' - defaults to 'md5'.
MD5 is not recommended as certain organizations need to use FIPS
compliant algorithms for hashing - see
https://support.microsoft.com/en-us/kb/811833 for more details.
.PARAMETER IgnoredArguments
Allows splatting with arguments that do not apply. Do not use directly.
.EXAMPLE
Get-CheckSumValid -File $fileFullPath -CheckSum $checksum -ChecksumType $checksumType
.LINK
Get-ChocolateyWebFile
.LINK
Install-ChocolateyPackage
#>
param(
[string] $file,
[string] $checksum = '',
[string] $checksumType = 'md5'
[parameter(Mandatory=$true, Position=0)][string] $file,
[parameter(Mandatory=$false, Position=1)][string] $checksum = '',
[parameter(Mandatory=$false, Position=2)][string] $checksumType = 'md5'
)
Write-Debug "Running 'Get-ChecksumValid' with file:`'$file`', checksum: `'$checksum`', checksumType: `'$checksumType`'";
if ($env:chocolateyIgnoreChecksums -eq 'true') {
Expand Down
50 changes: 34 additions & 16 deletions src/chocolatey.resources/helpers/functions/Get-ChocolateyUnzip.ps1
Expand Up @@ -19,10 +19,27 @@ Unzips an archive file and returns the location for further processing.
.DESCRIPTION
This unzips files using the 7-zip standalone command line tool 7za.exe.
Supported archive formats are: 7z, lzma, cab, zip, gzip, bzip2, Z and tar.
Supported archive formats are: 7z, lzma, cab, zip, gzip, bzip2, and tar.
.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.
.PARAMETER FileFullPath
This is the full path to your zip file.
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"`
.PARAMETER Destination
This is a directory where you would like the unzipped files to end up.
Expand All @@ -32,25 +49,26 @@ If it does not exist, it will be created.
OPTIONAL - This is a specific directory within zip file to extract.
.PARAMETER PackageName
OPTIONAL - This will faciliate logging unzip activity for subsequent uninstall
OPTIONAL - This will faciliate logging unzip activity for subsequent
uninstalls
.EXAMPLE
$scriptPath = (Split-Path -parent $MyInvocation.MyCommand.Definition)
Get-ChocolateyUnzip "c:\someFile.zip" $scriptPath somedirinzip\somedirinzip
.OUTPUTS
Returns the passed in $destination.
.PARAMETER IgnoredArguments
Allows splatting with arguments that do not apply. Do not use directly.
.NOTES
This helper reduces the number of lines one would have to write to unzip a file to 1 line.
If extraction fails, an exception is thrown.
.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
#>
param(
[string] $fileFullPath,
[string] $destination,
[string] $specificFolder,
[string] $packageName
[parameter(Mandatory=$true, Position=0)][string] $fileFullPath,
[parameter(Mandatory=$true, Position=1)][string] $destination,
[parameter(Mandatory=$false, Position=2)][string] $specificFolder,
[parameter(Mandatory=$false, Position=3)][string] $packageName
)
$zipfileFullPath=$fileFullPath
if ($specificfolder) {
Expand Down

0 comments on commit 3ed1f37

Please sign in to comment.