-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cronus.ps1
161 lines (132 loc) · 6.41 KB
/
Cronus.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = "Folder Archiver"
$form.Size = New-Object System.Drawing.Size(550, 300)
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
$labelFolder = New-Object System.Windows.Forms.Label
$labelFolder.Text = "Folder Path:"
$labelFolder.AutoSize = $true
$labelFolder.Location = New-Object System.Drawing.Point(10, 20)
$textboxFolder = New-Object System.Windows.Forms.TextBox
$textboxFolder.Size = New-Object System.Drawing.Size(300, 20)
$textboxFolder.Location = New-Object System.Drawing.Point(120, 20)
$buttonBrowse = New-Object System.Windows.Forms.Button
$buttonBrowse.Text = "Browse..."
$buttonBrowse.AutoSize = $true
$buttonBrowseX = $textboxFolder.Right + 10
$buttonBrowseY = $textboxFolder.Top - 1
$buttonBrowse.Location = New-Object System.Drawing.Point($buttonBrowseX, $buttonBrowseY)
$buttonBrowse.Add_Click({
$folderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
$folderBrowser.RootFolder = [System.Environment+SpecialFolder]::MyComputer
$folderBrowser.SelectedPath = $textboxFolder.Text
$result = $folderBrowser.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
$textboxFolder.Text = $folderBrowser.SelectedPath
}
})
$labelZipName = New-Object System.Windows.Forms.Label
$labelZipName.Text = "Output File Name:"
$labelZipName.AutoSize = $true
$labelZipName.Location = New-Object System.Drawing.Point(10, 50)
$textboxZipName = New-Object System.Windows.Forms.TextBox
$textboxZipName.Size = New-Object System.Drawing.Size(300, 20)
$textboxZipName.Location = New-Object System.Drawing.Point(120, 50)
$progressBar = New-Object System.Windows.Forms.ProgressBar
$progressBar.Style = [System.Windows.Forms.ProgressBarStyle]::Continuous
$progressBar.Value = 0
$progressBar.Size = New-Object System.Drawing.Size(440, 20)
$progressBar.Location = New-Object System.Drawing.Point(10, 110)
$labelChunkSize = New-Object System.Windows.Forms.Label
$labelChunkSize.Text = "Chunk Size (MB):"
$labelChunkSize.AutoSize = $true
$labelChunkSize.Location = New-Object System.Drawing.Point(10, 80)
$dropdownChunkSize = New-Object System.Windows.Forms.ComboBox
$dropdownChunkSize.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$dropdownChunkSize.Size = New-Object System.Drawing.Size(150, 20)
$dropdownChunkSize.Location = New-Object System.Drawing.Point(120, 80)
$dropdownChunkSize.Items.AddRange(@("20M", "100M", "1000M", "650M", "700M", "4092M", "4480M", "8128M", "23040M"))
$dropdownChunkSize.SelectedIndex = 0
$buttonCreate = New-Object System.Windows.Forms.Button
$buttonCreate.Text = "Create Archive"
$buttonCreate.Size = New-Object System.Drawing.Size(150, 30)
$buttonCreate.Location = New-Object System.Drawing.Point(10, 150)
$buttonCreate.Add_Click({
Write-Host "zipPath:"
Write-Host "zipPath after assignment: $zipPath"
$sourcePath = $textboxFolder.Text
$zipPath = $textboxZipName.Text
Write-Host "zipPath after assignment: $zipPath"
# Add checks to ensure $zipPath is not empty or null
if (-not $zipPath) {
[System.Windows.Forms.MessageBox]::Show("Please enter an output file name.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
return
}
if (-not [System.IO.Path]::HasExtension($zipPath)) {
$zipPath += ".exe" # Change extension to .exe for SFX
}
Write-Host "zipPath after extension check: $zipPath"
# Set the output folder path
$outputFolder = Join-Path (Get-Location) "Cronus Output"
# Add debug output to check the value of $outputFolder
Write-Host "Output folder: $outputFolder"
# Check if the output folder exists, if not, create it
if (-not (Test-Path -Path $outputFolder)) {
try {
New-Item -Path $outputFolder -ItemType Directory | Out-Null
}
catch {
[System.Windows.Forms.MessageBox]::Show("Error creating output folder.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
return
}
}
$progressBar.Value = 0
$buttonCreate.Enabled = $false
# Check if 7zip command is available
if (-not (Get-Command "7z.exe" -ErrorAction SilentlyContinue)) {
# 7zip is not in the PATH, check default location
$sevenZipPath = "C:\Program Files\7-Zip\7z.exe"
if (Test-Path $sevenZipPath) {
# 7zip found in default location, add to PATH
$env:Path += ";C:\Program Files\7-Zip"
} else {
# 7zip not found, show error message
[System.Windows.Forms.MessageBox]::Show("7-Zip not found. Please install 7-Zip or add it to the PATH.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
return
}
}
$chunkSize = $dropdownChunkSize.SelectedItem
Create-Zip -sourcePath $sourcePath -zipPath $zipPath -progressBar $progressBar -chunkSize $chunkSize -outputFolder $outputFolder
[System.Windows.Forms.MessageBox]::Show("Archive created successfully.", "Success", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)
$buttonCreate.Enabled = $true
})
$form.Controls.Add($labelFolder)
$form.Controls.Add($textboxFolder)
$form.Controls.Add($buttonBrowse)
$form.Controls.Add($labelZipName)
$form.Controls.Add($textboxZipName)
$form.Controls.Add($progressBar)
$form.Controls.Add($buttonCreate)
$form.Controls.Add($labelChunkSize)
$form.Controls.Add($dropdownChunkSize)
function Create-Zip {
param (
[string]$sourcePath,
[string]$zipPath,
[System.Windows.Forms.ProgressBar]$progressBar,
[string]$chunkSize,
[string]$outputFolder
)
$command = "a -sfx -v$chunkSize `"$zipPath`" `"$sourcePath\*`""
Write-Host "7zip command: $command"
$process = Start-Process "7z.exe" -ArgumentList $command -NoNewWindow -PassThru -Wait -WorkingDirectory $outputFolder
if ($process.ExitCode -ne 0) {
# 7zip command failed, show error message
[System.Windows.Forms.MessageBox]::Show("Error: $($process.StandardError)", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
return
}
$progressBar.Value = 100
}
$form.ShowDialog()