This repository was archived by the owner on Jun 18, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathscript.ps1
More file actions
371 lines (342 loc) · 10.9 KB
/
Copy pathscript.ps1
File metadata and controls
371 lines (342 loc) · 10.9 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
param (
[string[]]$SkipApps = @(),
[string[]]$SkipFolders = @()
)
$Title = 'Cleanup Utility'
$VersionFile = Join-Path -Path $PSScriptRoot -ChildPath 'version.json'
$Version = (Get-Content -Path $VersionFile -Raw | ConvertFrom-Json).version
$Host.UI.RawUI.WindowTitle = "$Title - $Version"
$logFile = Join-Path -Path $PSScriptRoot -ChildPath 'debug.log'
if (Test-Path -Path $logFile -PathType Leaf)
{
Remove-Item -Path $logFile -Force
}
function Write-Log
{
param (
[string]$message,
[ValidateSet('INFO', 'WARNING', 'ERROR', 'DEBUG')]
[string]$level = 'INFO'
)
$timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
$logEntry = "[$timestamp] [$level] $message"
Add-Content -Path $logFile -Value $logEntry -Encoding UTF8
}
$programs = @(
@{
Name = 'Steam'
Process = @('Steam', 'steamwebhelper')
Path = Join-Path -Path (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Valve\Steam').InstallPath -ChildPath 'config\loginusers.vdf'
},
@{
Name = 'SteamBrowser'
Process = @('steamwebhelper')
Path = Join-Path -Path $env:localappdata -ChildPath 'Steam\htmlcache\Default'
},
@{
Name = 'EA'
Process = @('EADesktop', 'EABackgroundService')
Path = Join-Path -Path $env:localappdata -ChildPath 'Electronic Arts\EA Desktop'
},
@{
Name = 'Battle.net'
Process = @('Battle.net')
Path = Join-Path -Path $env:appdata -ChildPath 'Battle.net\Battle.net.config'
FileType = 'json'
KeysToRemove = @('AutoLogin', 'SavedAccountNames')
},
@{
Name = 'VK Play'
Process = @('GameCenter')
Path = Join-Path -Path $env:localappdata -ChildPath 'GameCenter\GameCenter.ini'
FileType = 'ini'
KeysToRemove = @('LastAGSTime', 'LastAUITime', 'MyComUserMagic', 'cLastLoginTime', 'MyComUserMagic4', 'FirstAuth', 'LastAUITime', 'MyComUserMagic2', 'MyComUserLogin', 'MyComUserUid', 'CurrentUserName', 'CurrentUserNick', 'CurrentUserAvatarFileName')
},
@{
Name = 'Riot Games'
Process = @('RiotClientServices')
Path = Join-Path -Path $env:localappdata -ChildPath 'Riot Games\Riot Client\Data\RiotGamesPrivateSettings.yaml'
},
@{
Name = 'Lesta'
Process = @('lgc')
Path = Join-Path -Path $env:appdata -ChildPath 'Lesta\GameCenter\user_info.xml'
},
@{
Name = 'Wargaming'
Process = @('wgc')
Path = Join-Path -Path $env:appdata -ChildPath 'Wargaming.net\GameCenter\user_info.xml'
},
@{
Name = 'Ubisoft'
Process = @('upc')
Path = Join-Path -Path $env:localappdata -ChildPath 'Ubisoft Game Launcher\user.dat'
},
@{
Name = 'Epic Games'
Process = @('EpicGamesLauncher', 'EpicWebHelper')
Path = Join-Path -Path $env:localappdata -ChildPath 'EpicGamesLauncher\Saved\Config\WindowsEditor\GameUserSettings.ini'
},
@{
Name = 'BSGLauncher'
Process = @('BsgLauncher')
Path = Join-Path -Path $env:appdata -ChildPath 'Battlestate Games\BsgLauncher\settings'
},
@{
Name = 'Arena Breakout'
Process = @('arena_breakout_infinite_launcher')
Path = Join-Path -Path $env:appdata -ChildPath 'arena_breakout_infinite_launcher\last_user.dat'
},
@{
Name = 'Rockstar Games'
Process = @('Launcher')
Path = Join-Path -Path $env:userprofile -ChildPath 'Documents\Rockstar Games\Social Club\Profiles'
},
@{
Name = 'Roblox'
Process = @('RobloxPlayerBeta')
Path = Join-Path -Path $env:localappdata -ChildPath 'Roblox\LocalStorage\RobloxCookies.dat'
},
@{
Name = 'Discord'
Process = @('discord')
Path = Join-Path -Path $env:appdata -ChildPath 'discord'
},
@{
Name = 'Telegram'
Process = @('Telegram')
Path = Join-Path -Path $env:appdata -ChildPath 'Telegram Desktop\tdata'
},
@{
Name = 'TeamSpeak 3'
Process = @('ts3client_win64')
Path = Join-Path -Path $env:appdata -ChildPath 'TS3Client\settings.db'
},
@{
Name = 'TeamSpeak 6'
Process = @('TeamSpeak')
Path = Join-Path -Path $env:appdata -ChildPath 'TeamSpeak\Default'
},
@{
Name = 'WhatsApp'
Process = @('WhatsApp')
Path = Join-Path -Path $env:localappdata -ChildPath 'Packages\5319275A.WhatsAppDesktop_cv1g1gvanyjgm\LocalState'
},
@{
Name = 'Chrome'
Process = @('chrome')
Path = Join-Path -Path $env:localappdata -ChildPath 'Google\Chrome\User Data'
},
@{
Name = 'Firefox'
Process = @('firefox')
Path = Join-Path -Path $env:appdata -ChildPath 'Mozilla\Firefox'
},
@{
Name = 'Opera'
Process = @('opera')
Path = Join-Path -Path $env:appdata -ChildPath 'Opera Software\Opera GX Stable'
},
@{
Name = 'Edge'
Process = @('msedge')
Path = Join-Path -Path $env:localappdata -ChildPath 'Microsoft\Edge\User Data'
},
@{
Name = 'Yandex'
Process = @('browser')
Path = Join-Path -Path $env:localappdata -ChildPath 'Yandex\YandexBrowser\User Data'
},
@{
Name = 'FACEIT'
Process = @('FACEIT')
Path = Join-Path -Path $env:appdata -ChildPath 'FACEIT'
},
@{
Name = 'MarketApp'
Process = @('MarketApp')
Path = Join-Path -Path $env:appdata -ChildPath 'marketapp'
}
)
$systemFolders = @(
@{
Name = 'Downloads'
Path = [Environment]::GetFolderPath('UserProfile') + '\Downloads'
},
@{
Name = 'Images'
Path = [Environment]::GetFolderPath('MyPictures')
},
@{
Name = 'Video'
Path = [Environment]::GetFolderPath('MyVideos')
},
@{
Name = 'Music'
Path = [Environment]::GetFolderPath('MyMusic')
},
@{
Name = 'Temp'
Path = $env:TEMP
},
@{
Name = 'SystemTemp'
Path = "$env:SystemRoot\Temp"
},
@{
Name = 'CrashDumps'
Path = "$env:localappdata\CrashDumps"
},
@{
Name = 'Thumbnails'
Path = "$env:localappdata\Microsoft\Windows\Explorer"
}
)
function Stop-Processes
{
$allProcessNames = $programs.Process | Select-Object -Unique
$runningProcesses = Get-Process -Name $allProcessNames -ErrorAction SilentlyContinue
foreach ($program in $programs)
{
if ($SkipApps -contains $program.Name)
{
Write-Log -message "$($program.Name) исключен, пропускаем."
continue
}
$processStopped = $false
foreach ($processName in $program.Process)
{
$procs = $runningProcesses | Where-Object -FilterScript {$_.Name -eq $processName}
if ($procs)
{
$procs | Stop-Process -Force
Write-Log -message "Процесс $processName завершен."
$processStopped = $true
}
}
if ($processStopped)
{Write-Log -message "Все процессы $($program.Name) остановлены."}
}
}
function Remove-CredentialsFromConfig
{
param (
[string]$FilePath,
[string]$FileType,
[string[]]$KeysToRemove
)
if (!(Test-Path $FilePath))
{
Write-Log -level 'ERROR' -message "Файл конфигурации не найден: `"$FilePath`""
return
}
try
{
switch ($FileType.ToLower()) {
'json'
{
$content = Get-Content $FilePath -Raw | ConvertFrom-Json
foreach ($key in $KeysToRemove)
{
if ($content.Client.PSObject.Properties.Name -contains $key)
{$content.Client.PSObject.Properties.Remove($key)}
}
Write-Log -level 'DEBUG' -message "Файл конфигурации изменен: `"$FilePath`""
$content |
ConvertTo-Json -Depth 10 |
Out-File $FilePath -Encoding UTF8
}
'ini'
{
$lines = Get-Content $FilePath
$filtered = $lines | Where-Object -FilterScript {
$line = $_
-not ($KeysToRemove | Where-Object -FilterScript {$line -match "^\s*$_\s*="})
}
$filtered | Set-Content -Path $FilePath -Encoding UTF8
Write-Log -level 'DEBUG' -message "Файл конфигурации изменен: `"$FilePath`""
}
}
}
catch
{
Write-Log -level 'ERROR' -message "Ошибка при очистке ${FilePath}: $_"
}
}
function Clear-Data
{
foreach ($program in $programs)
{
if ($SkipApps -contains $program.Name)
{
Write-Log -message "$($program.Name) исключен, пропускаем."
continue
}
if (-not (Test-Path -Path $program.Path))
{
Write-Log -message "Путь $($program.Path) не найден."
continue
}
if ($program.ContainsKey('FileType') -and $program.ContainsKey('KeysToRemove'))
{Remove-CredentialsFromConfig -FilePath $program.Path -FileType $program.FileType -KeysToRemove $program.KeysToRemove}
else
{
Remove-Item -Path $program.Path -Recurse -Force -ErrorAction SilentlyContinue
Write-Log -message "Данные $($program.Name) удалены."
}
}
}
function Clear-SystemFolders
{
foreach ($folder in $systemFolders)
{
if ($SkipFolders -contains $folder.Name)
{
Write-Log -message "Папка $($folder.Name) исключена."
continue
}
if (-not (Test-Path -Path $folder.Path))
{
Write-Log -message "Папка $($folder.Path) не найдена."
continue
}
try
{
Get-ChildItem -Path $folder.Path -Recurse -Force | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
Write-Log -message "Очищено: $($folder.Name) ($($folder.Path))"
} catch
{Write-Log -level 'ERROR' -message "Ошибка при очистке $($folder.Path): $_"}
}
}
Write-Host -Object "$Title - $Version" -ForegroundColor Cyan
Write-Log -message "$Title - $Version"
Write-Log -level 'DEBUG' -message '========== Завершение процессов =========='
Stop-Processes
Start-Sleep -Seconds 1
Write-Log -level 'DEBUG' -message '========== Очистка данных приложений =========='
Clear-Data
Start-Sleep -Seconds 1
Write-Log -level 'DEBUG' -message '========== Очистка системных папок =========='
Clear-SystemFolders
Clear-RecycleBin -Force -ErrorAction SilentlyContinue
Write-Log -message 'Корзина очищена'
Write-Host -Object 'Очистка успешно завершена!' -ForegroundColor Green
Write-Log -message '========== Очистка успешно завершена =========='
Write-Log -level 'DEBUG' -message 'Скрипт завершил работу'
try
{
Add-Type -AssemblyName System.Windows.Forms
$global:balmsg = New-Object -TypeName System.Windows.Forms.NotifyIcon
$path = (Get-Process -Id $pid).Path
$balmsg.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
$balmsg.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Info
$balmsg.BalloonTipText = 'Очистка завершена!'
$balmsg.BalloonTipTitle = 'Cleanup Utility'
$balmsg.Visible = $true
$balmsg.ShowBalloonTip(3000)
Start-Sleep -Seconds 3
}
catch
{
Write-Log -level 'ERROR' -message "Не удалось показать уведомление: $_"
}