Skip to content

Commit 3afd46a

Browse files
committed
Optimized current code.
1 parent 9fb7d14 commit 3afd46a

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

Src/Public/Export-ErrorLog.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ Function Export-ErrorLog
33
[CmdletBinding()]
44
Param ()
55

6-
If ($Error.Count -gt 0 -or $OptimizeErrors.Count -gt 0)
6+
If ($Global:Error.Count -gt 0 -or $OptimizeErrors.Count -gt 0)
77
{
88
$Index = 0
9-
($Error + $OptimizeErrors | ForEach-Object -Process {
9+
($Global:Error + $OptimizeErrors | ForEach-Object -Process {
1010
[PSCustomObject]@{
1111
Index = $Index
1212
Exception = $PSItem.Exception.Message

Src/Public/Get-CompressionType.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@ Function Get-CompressionType
1010
}
1111
Process
1212
{
13-
$Form = New-Object -TypeName System.Windows.Forms.Form -ErrorAction:$ErrorActionPreference
13+
$Form = New-Object -TypeName Windows.Forms.Form -ErrorAction:$ErrorActionPreference
1414
$Form.Text = 'Compression Type'
1515
$Form.Width = 258
1616
$Form.Height = 180
1717
$Form.ShowIcon = $false
1818
$Form.TopMost = $true
1919
$Form.MaximizeBox = $false
2020
$Form.MinimizeBox = $false
21-
$Label = New-Object -TypeName System.Windows.Forms.Label -ErrorAction:$ErrorActionPreference
22-
$Label.Size = New-Object -TypeName System.Drawing.Size(185, 20) -ErrorAction:$ErrorActionPreference
21+
$Label = New-Object -TypeName Windows.Forms.Label -ErrorAction:$ErrorActionPreference
22+
$Label.Size = New-Object -TypeName Drawing.Size(185, 20) -ErrorAction:$ErrorActionPreference
2323
$Label.Text = 'Select Final Image Compression.'
2424
$Label.BackColor = 'Transparent'
2525
$Label.AutoSize = $false
2626
$Label.TextAlign = 'MiddleCenter'
2727
$Label.Font = 'Segoe UI, 9pt'
28-
$ListBox = New-Object -TypeName System.Windows.Forms.ListBox -ErrorAction:$ErrorActionPreference
29-
$ListBox.Location = New-Object -TypeName System.Drawing.Size(10, 22) -ErrorAction:$ErrorActionPreference
30-
$ListBox.Size = New-Object -TypeName System.Drawing.Size(220, 20) -ErrorAction:$ErrorActionPreference
28+
$ListBox = New-Object -TypeName Windows.Forms.ListBox -ErrorAction:$ErrorActionPreference
29+
$ListBox.Location = New-Object -TypeName Drawing.Size(10, 22) -ErrorAction:$ErrorActionPreference
30+
$ListBox.Size = New-Object -TypeName Drawing.Size(220, 20) -ErrorAction:$ErrorActionPreference
3131
$ListBox.Height = 80
3232
$ListBox.Font = 'Segoe UI, 9pt'
3333
ForEach ($CompressionType In @('None', 'Fast', 'Maximum', 'Solid')) { [Void]$ListBox.Items.Add($CompressionType) }
3434
$ListBox.SelectedItem = 'Fast'
35-
$OKButton = New-Object -TypeName System.Windows.Forms.Button -ErrorAction:$ErrorActionPreference
36-
$OKButton.Location = New-Object -TypeName System.Drawing.Size(10, 110) -ErrorAction:$ErrorActionPreference
37-
$OKButton.Size = New-Object -TypeName System.Drawing.Size(75, 23) -ErrorAction:$ErrorActionPreference
35+
$OKButton = New-Object -TypeName Windows.Forms.Button -ErrorAction:$ErrorActionPreference
36+
$OKButton.Location = New-Object -TypeName Drawing.Size(10, 110) -ErrorAction:$ErrorActionPreference
37+
$OKButton.Size = New-Object -TypeName Drawing.Size(75, 23) -ErrorAction:$ErrorActionPreference
3838
$OKButton.Text = 'OK'
3939
$OKButton.DialogResult = [Windows.Forms.DialogResult]::OK
4040
$Form.AcceptButton = $OKButton

Src/Public/New-ISOMedia.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Function New-ISOMedia
1010

1111
Begin
1212
{
13-
$CompilerParams = New-Object -TypeName System.CodeDom.Compiler.CompilerParameters -Property @{
13+
$CompilerParams = New-Object -TypeName CodeDom.Compiler.CompilerParameters -Property @{
1414
CompilerOptions = '/unsafe'
1515
WarningLevel = 4
1616
TreatWarningsAsErrors = $true

Src/Public/Start-Executable.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Function Start-Executable
1010

1111
Begin
1212
{
13-
$ProcessInfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo -ErrorAction:$ErrorActionPreference
13+
$ProcessInfo = New-Object -TypeName Diagnostics.ProcessStartInfo -ErrorAction:$ErrorActionPreference
1414
$ProcessInfo.FileName = $Executable.FullName
1515
If (![String]::IsNullOrEmpty($Arguments)) { $ProcessInfo.Arguments = $Arguments }
1616
$ProcessInfo.CreateNoWindow = $true
1717
$ProcessInfo.WindowStyle = 'Hidden'
1818
$ProcessInfo.UseShellExecute = $false
19-
$ProcessRun = New-Object -TypeName System.Diagnostics.Process -ErrorAction:$ErrorActionPreference
19+
$ProcessRun = New-Object -TypeName Diagnostics.Process -ErrorAction:$ErrorActionPreference
2020
$ProcessRun.StartInfo = $ProcessInfo
2121
}
2222
Process

Src/Public/Stop-Optimize.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Function Stop-Optimize
77
Dismount-Images
88
$SaveDirectory = Create -Path (GetPath -Path $OptimizeOffline.Directory -Child Optimize-Offline_$((Get-Date).ToString('yyyy-MM-ddThh.mm.ss'))) -PassThru
99
@($DISMLog, (GetPath -Path $Env:SystemRoot -Child 'Logs\DISM\dism.log')) | Purge -ErrorAction Ignore
10-
If ($OptimizeErrors.Count -gt 0) { Export-ErrorLog -ErrorAction Ignore }
10+
If ($Global:Error.Count -gt 0 -or $OptimizeErrors.Count -gt 0) { Export-ErrorLog -ErrorAction Ignore }
1111
Get-ChildItem -Path $LogFolder -Filter *.log | Move-Item -Destination $SaveDirectory.FullName -Force
1212
$TempDirectory | Purge
1313
$Global:Error.Clear()

0 commit comments

Comments
 (0)