Skip to content

Commit d228c77

Browse files
rkeithhilldaviwil
authored andcommitted
Add Compress-LogDir function.
Overall, I don't like exposing such a "general purpose" command from the module. Maybe we have just one command called New-IssueReport that zips the folder and returns an object with the zipPath and version info?
1 parent 58d667f commit d228c77

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

module/PowerShellEditorServices/PowerShellEditorServices.psd1

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Copyright = '(c) 2016 Microsoft. All rights reserved.'
6666
# NestedModules = @()
6767

6868
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
69-
FunctionsToExport = @('Start-EditorServicesHost', 'Get-PowerShellEditorServicesVersion')
69+
FunctionsToExport = @('Start-EditorServicesHost', 'Get-PowerShellEditorServicesVersion', 'Compress-LogDir')
7070

7171
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
7272
CmdletsToExport = @()

module/PowerShellEditorServices/PowerShellEditorServices.psm1

+44
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,50 @@ function Start-EditorServicesHost {
9696
return $editorServicesHost
9797
}
9898

99+
function Compress-LogDir {
100+
[CmdletBinding(SupportsShouldProcess=$true)]
101+
param (
102+
[Parameter(Mandatory=$true, Position=0, HelpMessage="Literal path to a log directory.")]
103+
[ValidateNotNullOrEmpty()]
104+
[string]
105+
$Path
106+
)
107+
108+
begin {
109+
function LegacyZipFolder($Path, $ZipPath) {
110+
if (!(Test-Path($ZipPath))) {
111+
Set-Content -LiteralPath $ZipPath -Value ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
112+
(Get-Item $ZipPath).IsReadOnly = $false
113+
}
114+
115+
$shellApplication = New-Object -ComObject Shell.Application
116+
$zipPackage = $shellApplication.NameSpace($ZipPath)
117+
118+
foreach ($file in (Get-ChildItem -LiteralPath $Path)) {
119+
$zipPackage.CopyHere($file.FullName)
120+
Start-Sleep -MilliSeconds 500
121+
}
122+
}
123+
}
124+
125+
end {
126+
$zipPath = ((Convert-Path $Path) -replace '(\\|/)$','') + ".zip"
127+
128+
if (Get-Command Microsoft.PowerShell.Archive\Compress-Archive) {
129+
if ($PSCmdlet.ShouldProcess($zipPath, "Create ZIP")) {
130+
Microsoft.PowerShell.Archive\Compress-Archive -LiteralPath $Path -DestinationPath $zipPath -Force -CompressionLevel Optimal
131+
$zipPath
132+
}
133+
}
134+
else {
135+
if ($PSCmdlet.ShouldProcess($zipPath, "Create Legacy ZIP")) {
136+
LegacyZipFolder $Path $zipPath
137+
$zipPath
138+
}
139+
}
140+
}
141+
}
142+
99143
function Get-PowerShellEditorServicesVersion {
100144
$nl = [System.Environment]::NewLine
101145

0 commit comments

Comments
 (0)