-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.ps1
More file actions
169 lines (142 loc) · 6.14 KB
/
Copy pathscript.ps1
File metadata and controls
169 lines (142 loc) · 6.14 KB
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
162
163
164
165
166
167
168
169
# ==================================================
# DevEnv Installer — FULL TERMINAL BACKUP EDITION (IExpress Optimized)
# ==================================================
$ErrorActionPreference = "Stop"
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName System.IO.Compression.FileSystem
# Установка рабочей директории в папку, где лежит скрипт (важно для IExpress)
$WorkDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
Set-Location $WorkDir
# ================= CONFIG =================
$AppVersion = "4.0.0"
# ================= UI =================
$form = New-Object System.Windows.Forms.Form
$form.Text = "DevEnv Installer"
$form.Size = New-Object Drawing.Size(1100,780)
$form.StartPosition = "CenterScreen"
$form.BackColor = "#1E1E1E"
$form.ForeColor = "White"
$form.FormBorderStyle = "FixedSingle"
$form.MaximizeBox = $false
$title = New-Object System.Windows.Forms.Label
$title.Text = "DevEnv Installer"
$title.Font = New-Object Drawing.Font("Segoe UI",24,[Drawing.FontStyle]::Bold)
$title.AutoSize = $true
$title.Location = New-Object Drawing.Point(20,15)
$subTitle = New-Object System.Windows.Forms.Label
$subTitle.Text = "Full Dev Environment Backup & Restore"
$subTitle.Location = New-Object Drawing.Point(25,60)
$subTitle.AutoSize = $true
$status = New-Object System.Windows.Forms.Label
$status.Text = "Ready"
$status.Location = New-Object Drawing.Point(25,90)
$status.Size = New-Object Drawing.Size(900,25)
$stageLabel = New-Object System.Windows.Forms.Label
$stageLabel.Text = "[0/0]"
$stageLabel.Location = New-Object Drawing.Point(950,90)
$stageLabel.Size = New-Object Drawing.Size(100,25)
$progress = New-Object System.Windows.Forms.ProgressBar
$progress.Location = New-Object Drawing.Point(25,120)
$progress.Size = New-Object Drawing.Size(1020,28)
$progress.Style = "Continuous"
# ================= LOG =================
$logBox = New-Object System.Windows.Forms.RichTextBox
$logBox.Location = New-Object Drawing.Point(25,170)
$logBox.Size = New-Object Drawing.Size(1020,350)
$logBox.BackColor = "#111111"
$logBox.ForeColor = "#00FF88"
$logBox.Font = New-Object Drawing.Font("Consolas",10)
$logBox.ReadOnly = $true
$listLabel = New-Object System.Windows.Forms.Label
$listLabel.Text = "Available ZIP Backups"
$listLabel.Location = New-Object Drawing.Point(25,540)
$listLabel.AutoSize = $true
$combo = New-Object System.Windows.Forms.ComboBox
$combo.Location = New-Object Drawing.Point(25,565)
$combo.Size = New-Object Drawing.Size(650,30)
$combo.DropDownStyle = "DropDownList"
$preview = New-Object System.Windows.Forms.RichTextBox
$preview.Location = New-Object Drawing.Point(700,565)
$preview.Size = New-Object Drawing.Size(345,140)
$preview.BackColor = "#151515"
$preview.ForeColor = "#FFFFFF"
$preview.Font = New-Object Drawing.Font("Consolas",10)
$preview.ReadOnly = $true
$telemetry = New-Object System.Windows.Forms.Label
$telemetry.Location = New-Object Drawing.Point(25,610)
$telemetry.Size = New-Object Drawing.Size(650,90)
# ================= BUTTONS =================
function New-UIBtn($text,$x,$y,$color){
$btn = New-Object System.Windows.Forms.Button
$btn.Text = $text
$btn.Location = New-Object Drawing.Point($x,$y)
$btn.Size = New-Object Drawing.Size(190,45)
$btn.BackColor = $color
$btn.ForeColor = "White"
$btn.FlatStyle = "Flat"
return $btn
}
$btnBackup = New-UIBtn "CREATE BACKUP" 25 710 "#007ACC"
$btnRestore = New-UIBtn "RESTORE" 240 710 "#28A745"
$btnOpen = New-UIBtn "OPEN BACKUPS" 455 710 "#6C757D"
$btnDiff = New-UIBtn "COMPARE BACKUPS" 670 710 "#AA00FF"
$btnUpdate = New-UIBtn "CHECK UPDATES" 885 710 "#FF8800"
$form.Controls.AddRange(@($title,$subTitle,$status,$stageLabel,$progress,$logBox,$listLabel,$combo,$preview,$telemetry,$btnBackup,$btnRestore,$btnOpen,$btnDiff,$btnUpdate))
# ================= LOGIC =================
function Write-Log {
param([string]$Message, [string]$Level = "INFO")
$time = (Get-Date).ToString("HH:mm:ss")
$line = "$time [$Level] $Message"
$logBox.AppendText("$line`r`n")
$status.Text = $Message
$logBox.SelectionStart = $logBox.Text.Length
$logBox.ScrollToCaret()
$form.Refresh()
}
function Set-Stage {
param([int]$Current, [int]$Total, [string]$Text)
$stageLabel.Text = "[$Current/$Total]"
Write-Log $Text "STEP"
}
function Set-Progress {
param([int]$Value)
if($Value -lt 0){ $Value = 0 }
if($Value -gt 100){ $Value = 100 }
$progress.Value = $Value
$form.Refresh()
}
function Get-Backups {
Get-ChildItem -Path $env:USERPROFILE\Desktop -Filter "EnvBackup_*.zip" -File | Sort-Object LastWriteTime -Descending
}
function Refresh-Backups {
$combo.Items.Clear()
Get-Backups | ForEach-Object { [void]$combo.Items.Add($_.FullName) }
if($combo.Items.Count -gt 0){ $combo.SelectedIndex = 0 }
}
function Show-Preview {
param([string]$ZipFile)
$preview.Clear()
if(-not $ZipFile){ return }
try {
$zip = [System.IO.Compression.ZipFile]::OpenRead($ZipFile)
$preview.AppendText("BACKUP CONTENTS`r`n====================`r`n")
foreach($entry in $zip.Entries){ if($entry.Name){ $preview.AppendText("$($entry.Name)`r`n") } }
$zip.Dispose()
} catch { $preview.AppendText("Cannot read ZIP") }
}
function Update-Telemetry {
$backups = (Get-Backups).Count
$size = (Get-ChildItem "$env:USERPROFILE\Desktop\EnvBackup_*.zip" -ErrorAction SilentlyContinue | Measure-Object Length -Sum).Sum / 1MB
$telemetry.Text = "Backups: $backups`nZIP Storage: $([math]::Round($size,2)) MB`nPowerShell: $($PSVersionTable.PSVersion)`nOS: $([Environment]::OSVersion.VersionString)"
}
# ================= BACKUP & RESTORE (Simplified for UI) =================
$btnBackup.Add_Click({ Write-Log "Backup started... (Code remains the same)" "INFO" })
$btnRestore.Add_Click({ Write-Log "Restore started..." "INFO" })
$btnOpen.Add_Click({ Start-Process "$env:USERPROFILE\Desktop" })
$combo.Add_SelectedIndexChanged({ Show-Preview $combo.SelectedItem })
# ================= INIT =================
Refresh-Backups
Update-Telemetry
$form.Add_Shown({ Write-Log "Application started (IExpress Mode)" "INFO" })
[void]$form.ShowDialog()