Repository navigation
Expand file tree
/
Copy pathDriveUpdateV3.ps1
More file actions
2125 lines (1908 loc) · 82.5 KB
/
Copy pathDriveUpdateV3.ps1
File metadata and controls
2125 lines (1908 loc) · 82.5 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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Driver Updater by CHARITH - v3.0
# Run as Administrator
# Usage: irm https://raw.githubusercontent.com/The CHARITH/DriverUpdate/main/DriverUpdatev2.ps1 | iex
# Silent mode: .\updateAllDrivers.ps1 -Silent -Task "CheckDriverUpdates"
param(
[switch]$Silent,
[string]$Task = "",
[string]$Language = "en",
[string]$ProxyAddress = "",
[string]$FilterClass = "",
[string]$FilterManufacturer = ""
)
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# -------------------------
# Multi-Language Support
# -------------------------
$global:Languages = @{
"en" = @{
AppTitle = "Driver Updater by The CHARITH"
BtnWU = "Check Windows Update"
BtnCheckUpdates = "Check Driver Updates"
BtnScan = "Scan Installed Drivers"
BtnBackup = "Backup Drivers"
BtnInstall = "Install From Folder"
BtnCancel = "Cancel Task"
BtnOpenLogs = "Open Logs"
BtnDarkMode = "Dark Mode"
BtnLightMode = "Light Mode"
BtnSchedule = "Schedule Updates"
BtnRestorePoint = "Create Restore Point"
BtnHistory = "Update History"
BtnSettings = "Settings"
BtnFilters = "Filters"
TaskRunning = "A task is already running. Cancel it first."
PermissionError = "Please run this script as Administrator."
BackupCanceled = "Backup canceled by user."
InstallCanceled = "Install canceled by user."
NoTaskToCancel = "No running task to cancel."
TaskCancelled = "[CANCELLED] Task cancelled by user."
LogFolderMissing = "Log folder missing."
StartingTask = "-> Starting task:"
TaskFinished = "=== Task finished:"
SelectBackupFolder = "Select folder to save driver backup"
SelectDriverFolder = "Select folder containing driver .inf files"
ScheduleCreated = "Scheduled task created successfully!"
ScheduleRemoved = "Scheduled task removed."
RestorePointCreated = "System restore point created successfully!"
RestorePointFailed = "Failed to create restore point."
ProxyConfigured = "Proxy configured:"
ProxyCleared = "Proxy settings cleared."
FilterApplied = "Filter applied:"
FilterCleared = "Filters cleared."
LanguageChanged = "Language changed to:"
HistoryEmpty = "No update history found."
SettingsTitle = "Settings"
ScheduleTitle = "Schedule Updates"
FilterTitle = "Driver Filters"
HistoryTitle = "Update History"
Daily = "Daily"
Weekly = "Weekly"
Monthly = "Monthly"
Time = "Time:"
ProxyLabel = "Proxy Address:"
ClassFilter = "Filter by Class:"
ManufacturerFilter = "Filter by Manufacturer:"
Apply = "Apply"
Clear = "Clear"
Close = "Close"
Enable = "Enable"
Disable = "Disable"
Remove = "Remove Schedule"
}
"es" = @{
AppTitle = "Actualizador de Controladores por The CHARITH"
BtnWU = "Buscar Windows Update"
BtnCheckUpdates = "Buscar Controladores"
BtnScan = "Escanear Controladores"
BtnBackup = "Respaldar Controladores"
BtnInstall = "Instalar desde Carpeta"
BtnCancel = "Cancelar Tarea"
BtnOpenLogs = "Abrir Registros"
BtnDarkMode = "Modo Oscuro"
BtnLightMode = "Modo Claro"
BtnSchedule = "Programar Actualizaciones"
BtnRestorePoint = "Crear Punto Restauracion"
BtnHistory = "Historial"
BtnSettings = "Configuracion"
BtnFilters = "Filtros"
TaskRunning = "Ya hay una tarea en ejecucion. Cancelela primero."
PermissionError = "Ejecute este script como Administrador."
BackupCanceled = "Respaldo cancelado por el usuario."
InstallCanceled = "Instalacion cancelada por el usuario."
NoTaskToCancel = "No hay tarea para cancelar."
TaskCancelled = "[CANCELADO] Tarea cancelada por el usuario."
LogFolderMissing = "Carpeta de registros no encontrada."
StartingTask = "-> Iniciando tarea:"
TaskFinished = "=== Tarea finalizada:"
SelectBackupFolder = "Seleccione carpeta para guardar respaldo"
SelectDriverFolder = "Seleccione carpeta con archivos .inf"
ScheduleCreated = "Tarea programada creada!"
ScheduleRemoved = "Tarea programada eliminada."
RestorePointCreated = "Punto de restauracion creado!"
RestorePointFailed = "Error al crear punto de restauracion."
ProxyConfigured = "Proxy configurado:"
ProxyCleared = "Configuracion de proxy eliminada."
FilterApplied = "Filtro aplicado:"
FilterCleared = "Filtros eliminados."
LanguageChanged = "Idioma cambiado a:"
HistoryEmpty = "No hay historial de actualizaciones."
SettingsTitle = "Configuracion"
ScheduleTitle = "Programar Actualizaciones"
FilterTitle = "Filtros de Controladores"
HistoryTitle = "Historial de Actualizaciones"
Daily = "Diario"
Weekly = "Semanal"
Monthly = "Mensual"
Time = "Hora:"
ProxyLabel = "Direccion Proxy:"
ClassFilter = "Filtrar por Clase:"
ManufacturerFilter = "Filtrar por Fabricante:"
Apply = "Aplicar"
Clear = "Limpiar"
Close = "Cerrar"
Enable = "Habilitar"
Disable = "Deshabilitar"
Remove = "Eliminar Programacion"
}
"fr" = @{
AppTitle = "Mise a jour des pilotes par The CHARITH"
BtnWU = "Windows Update"
BtnCheckUpdates = "Verifier les Pilotes"
BtnScan = "Analyser les Pilotes"
BtnBackup = "Sauvegarder"
BtnInstall = "Installer depuis Dossier"
BtnCancel = "Annuler"
BtnOpenLogs = "Ouvrir Journaux"
BtnDarkMode = "Mode Sombre"
BtnLightMode = "Mode Clair"
BtnSchedule = "Planifier"
BtnRestorePoint = "Point de Restauration"
BtnHistory = "Historique"
BtnSettings = "Parametres"
BtnFilters = "Filtres"
TaskRunning = "Une tache est deja en cours. Annulez-la d'abord."
PermissionError = "Executez ce script en tant qu'Administrateur."
BackupCanceled = "Sauvegarde annulee."
InstallCanceled = "Installation annulee."
NoTaskToCancel = "Aucune tache a annuler."
TaskCancelled = "[ANNULE] Tache annulee."
LogFolderMissing = "Dossier des journaux manquant."
StartingTask = "-> Demarrage de la tache:"
TaskFinished = "=== Tache terminee:"
SelectBackupFolder = "Selectionnez le dossier de sauvegarde"
SelectDriverFolder = "Selectionnez le dossier avec les fichiers .inf"
ScheduleCreated = "Tache planifiee creee!"
ScheduleRemoved = "Tache planifiee supprimee."
RestorePointCreated = "Point de restauration cree!"
RestorePointFailed = "Echec de creation du point de restauration."
ProxyConfigured = "Proxy configure:"
ProxyCleared = "Parametres proxy effaces."
FilterApplied = "Filtre applique:"
FilterCleared = "Filtres effaces."
LanguageChanged = "Langue changee en:"
HistoryEmpty = "Aucun historique trouve."
SettingsTitle = "Parametres"
ScheduleTitle = "Planifier les Mises a Jour"
FilterTitle = "Filtres des Pilotes"
HistoryTitle = "Historique des Mises a Jour"
Daily = "Quotidien"
Weekly = "Hebdomadaire"
Monthly = "Mensuel"
Time = "Heure:"
ProxyLabel = "Adresse Proxy:"
ClassFilter = "Filtrer par Classe:"
ManufacturerFilter = "Filtrer par Fabricant:"
Apply = "Appliquer"
Clear = "Effacer"
Close = "Fermer"
Enable = "Activer"
Disable = "Desactiver"
Remove = "Supprimer Planification"
}
"de" = @{
AppTitle = "Treiber-Updater von The CHARITH"
BtnWU = "Windows Update"
BtnCheckUpdates = "Treiber pruefen"
BtnScan = "Treiber scannen"
BtnBackup = "Sicherung"
BtnInstall = "Aus Ordner installieren"
BtnCancel = "Abbrechen"
BtnOpenLogs = "Protokolle"
BtnDarkMode = "Dunkelmodus"
BtnLightMode = "Hellmodus"
BtnSchedule = "Zeitplan"
BtnRestorePoint = "Wiederherstellungspunkt"
BtnHistory = "Verlauf"
BtnSettings = "Einstellungen"
BtnFilters = "Filter"
TaskRunning = "Eine Aufgabe laeuft bereits."
PermissionError = "Fuehren Sie dieses Skript als Administrator aus."
BackupCanceled = "Sicherung abgebrochen."
InstallCanceled = "Installation abgebrochen."
NoTaskToCancel = "Keine Aufgabe zum Abbrechen."
TaskCancelled = "[ABGEBROCHEN] Aufgabe abgebrochen."
LogFolderMissing = "Protokollordner fehlt."
StartingTask = "-> Starte Aufgabe:"
TaskFinished = "=== Aufgabe beendet:"
SelectBackupFolder = "Sicherungsordner auswaehlen"
SelectDriverFolder = "Ordner mit .inf-Dateien auswaehlen"
ScheduleCreated = "Geplante Aufgabe erstellt!"
ScheduleRemoved = "Geplante Aufgabe entfernt."
RestorePointCreated = "Wiederherstellungspunkt erstellt!"
RestorePointFailed = "Fehler beim Erstellen des Wiederherstellungspunkts."
ProxyConfigured = "Proxy konfiguriert:"
ProxyCleared = "Proxy-Einstellungen geloescht."
FilterApplied = "Filter angewendet:"
FilterCleared = "Filter geloescht."
LanguageChanged = "Sprache geaendert zu:"
HistoryEmpty = "Kein Verlauf gefunden."
SettingsTitle = "Einstellungen"
ScheduleTitle = "Updates planen"
FilterTitle = "Treiberfilter"
HistoryTitle = "Update-Verlauf"
Daily = "Taeglich"
Weekly = "Woechentlich"
Monthly = "Monatlich"
Time = "Zeit:"
ProxyLabel = "Proxy-Adresse:"
ClassFilter = "Nach Klasse filtern:"
ManufacturerFilter = "Nach Hersteller filtern:"
Apply = "Anwenden"
Clear = "Loeschen"
Close = "Schliessen"
Enable = "Aktivieren"
Disable = "Deaktivieren"
Remove = "Zeitplan entfernen"
}
"pt" = @{
AppTitle = "Atualizador de Drivers por The CHARITH"
BtnWU = "Windows Update"
BtnCheckUpdates = "Verificar Drivers"
BtnScan = "Escanear Drivers"
BtnBackup = "Backup"
BtnInstall = "Instalar da Pasta"
BtnCancel = "Cancelar"
BtnOpenLogs = "Abrir Logs"
BtnDarkMode = "Modo Escuro"
BtnLightMode = "Modo Claro"
BtnSchedule = "Agendar"
BtnRestorePoint = "Ponto de Restauracao"
BtnHistory = "Historico"
BtnSettings = "Configuracoes"
BtnFilters = "Filtros"
TaskRunning = "Uma tarefa ja esta em execucao."
PermissionError = "Execute este script como Administrador."
BackupCanceled = "Backup cancelado."
InstallCanceled = "Instalacao cancelada."
NoTaskToCancel = "Nenhuma tarefa para cancelar."
TaskCancelled = "[CANCELADO] Tarefa cancelada."
LogFolderMissing = "Pasta de logs nao encontrada."
StartingTask = "-> Iniciando tarefa:"
TaskFinished = "=== Tarefa concluida:"
SelectBackupFolder = "Selecione a pasta de backup"
SelectDriverFolder = "Selecione a pasta com arquivos .inf"
ScheduleCreated = "Tarefa agendada criada!"
ScheduleRemoved = "Tarefa agendada removida."
RestorePointCreated = "Ponto de restauracao criado!"
RestorePointFailed = "Falha ao criar ponto de restauracao."
ProxyConfigured = "Proxy configurado:"
ProxyCleared = "Configuracoes de proxy limpas."
FilterApplied = "Filtro aplicado:"
FilterCleared = "Filtros limpos."
LanguageChanged = "Idioma alterado para:"
HistoryEmpty = "Nenhum historico encontrado."
SettingsTitle = "Configuracoes"
ScheduleTitle = "Agendar Atualizacoes"
FilterTitle = "Filtros de Drivers"
HistoryTitle = "Historico de Atualizacoes"
Daily = "Diario"
Weekly = "Semanal"
Monthly = "Mensal"
Time = "Hora:"
ProxyLabel = "Endereco Proxy:"
ClassFilter = "Filtrar por Classe:"
ManufacturerFilter = "Filtrar por Fabricante:"
Apply = "Aplicar"
Clear = "Limpar"
Close = "Fechar"
Enable = "Habilitar"
Disable = "Desabilitar"
Remove = "Remover Agendamento"
}
"it" = @{
AppTitle = "Aggiornamento Driver di The CHARITH"
BtnWU = "Windows Update"
BtnCheckUpdates = "Verifica Driver"
BtnScan = "Scansiona Driver"
BtnBackup = "Backup"
BtnInstall = "Installa da Cartella"
BtnCancel = "Annulla"
BtnOpenLogs = "Apri Log"
BtnDarkMode = "Modalita Scura"
BtnLightMode = "Modalita Chiara"
BtnSchedule = "Pianifica"
BtnRestorePoint = "Punto di Ripristino"
BtnHistory = "Cronologia"
BtnSettings = "Impostazioni"
BtnFilters = "Filtri"
TaskRunning = "Un'attivita e gia in esecuzione."
PermissionError = "Esegui questo script come Amministratore."
BackupCanceled = "Backup annullato."
InstallCanceled = "Installazione annullata."
NoTaskToCancel = "Nessuna attivita da annullare."
TaskCancelled = "[ANNULLATO] Attivita annullata."
LogFolderMissing = "Cartella log mancante."
StartingTask = "-> Avvio attivita:"
TaskFinished = "=== Attivita completata:"
SelectBackupFolder = "Seleziona cartella di backup"
SelectDriverFolder = "Seleziona cartella con file .inf"
ScheduleCreated = "Attivita pianificata creata!"
ScheduleRemoved = "Attivita pianificata rimossa."
RestorePointCreated = "Punto di ripristino creato!"
RestorePointFailed = "Errore nella creazione del punto di ripristino."
ProxyConfigured = "Proxy configurato:"
ProxyCleared = "Impostazioni proxy cancellate."
FilterApplied = "Filtro applicato:"
FilterCleared = "Filtri cancellati."
LanguageChanged = "Lingua cambiata in:"
HistoryEmpty = "Nessuna cronologia trovata."
SettingsTitle = "Impostazioni"
ScheduleTitle = "Pianifica Aggiornamenti"
FilterTitle = "Filtri Driver"
HistoryTitle = "Cronologia Aggiornamenti"
Daily = "Giornaliero"
Weekly = "Settimanale"
Monthly = "Mensile"
Time = "Ora:"
ProxyLabel = "Indirizzo Proxy:"
ClassFilter = "Filtra per Classe:"
ManufacturerFilter = "Filtra per Produttore:"
Apply = "Applica"
Clear = "Cancella"
Close = "Chiudi"
Enable = "Abilita"
Disable = "Disabilita"
Remove = "Rimuovi Pianificazione"
}
}
# Get localized string
function Get-LocalizedString([string]$key) {
$lang = $global:CurrentLanguage
if (-not $global:Languages.ContainsKey($lang)) { $lang = "en" }
if ($global:Languages[$lang].ContainsKey($key)) {
return $global:Languages[$lang][$key]
}
return $global:Languages["en"][$key]
}
$global:CurrentLanguage = $Language
# -------------------------
# Require Admin
# -------------------------
function Assert-AdminPrivilege {
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
if (-not $Silent) {
[System.Windows.Forms.MessageBox]::Show((Get-LocalizedString "PermissionError"), "Permission Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
}
exit 1
}
}
Assert-AdminPrivilege
# -------------------------
# Globals and paths
# -------------------------
$AppTitle = Get-LocalizedString "AppTitle"
$LogBase = Join-Path $env:USERPROFILE "Documents\The CHARITH_DriverUpdater"
$HistoryFile = Join-Path $LogBase "UpdateHistory.json"
$SettingsFile = Join-Path $LogBase "Settings.json"
if (!(Test-Path $LogBase)) { New-Item -ItemType Directory -Path $LogBase -Force | Out-Null }
$global:CurrentJob = $null
$global:CurrentTaskLog = $null
$global:ProxySettings = @{ Enabled = $false; Address = "" }
$global:FilterSettings = @{ Class = ""; Manufacturer = "" }
$global:DarkModeEnabled = $false
# -------------------------
# Settings Management
# -------------------------
function Import-Settings {
if (Test-Path $SettingsFile) {
try {
$settings = Get-Content -Path $SettingsFile -Raw | ConvertFrom-Json
if ($settings.Language) { $global:CurrentLanguage = $settings.Language }
if ($settings.Proxy) {
$global:ProxySettings.Enabled = $settings.Proxy.Enabled
$global:ProxySettings.Address = $settings.Proxy.Address
}
if ($settings.Filters) {
$global:FilterSettings.Class = $settings.Filters.Class
$global:FilterSettings.Manufacturer = $settings.Filters.Manufacturer
}
if ($null -ne $settings.DarkMode) { $global:DarkModeEnabled = $settings.DarkMode }
} catch {}
}
}
function Export-Settings {
$settings = @{
Language = $global:CurrentLanguage
Proxy = $global:ProxySettings
Filters = $global:FilterSettings
DarkMode = $global:DarkModeEnabled
}
$settings | ConvertTo-Json -Depth 3 | Set-Content -Path $SettingsFile -Encoding UTF8
}
Import-Settings
# Apply command-line parameters
if ($ProxyAddress) {
$global:ProxySettings.Enabled = $true
$global:ProxySettings.Address = $ProxyAddress
}
if ($FilterClass) { $global:FilterSettings.Class = $FilterClass }
if ($FilterManufacturer) { $global:FilterSettings.Manufacturer = $FilterManufacturer }
# -------------------------
# Update History Logging
# -------------------------
function Add-HistoryEntry {
param(
[string]$TaskName,
[string]$Status,
[string]$Details
)
$history = @()
if (Test-Path $HistoryFile) {
try {
$content = Get-Content -Path $HistoryFile -Raw
if ($content) {
$parsed = $content | ConvertFrom-Json
if ($parsed -is [array]) {
$history = $parsed
} else {
$history = @($parsed)
}
}
} catch { $history = @() }
}
$entry = [PSCustomObject]@{
Timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
Task = $TaskName
Status = $Status
Details = $Details
}
$history = @($entry) + $history
# Keep last 100 entries
if ($history.Count -gt 100) { $history = $history[0..99] }
$history | ConvertTo-Json -Depth 3 | Set-Content -Path $HistoryFile -Encoding UTF8
}
function Get-UpdateHistory {
if (Test-Path $HistoryFile) {
try {
$content = Get-Content -Path $HistoryFile -Raw
if ($content) {
return $content | ConvertFrom-Json
}
} catch {}
}
return @()
}
# -------------------------
# Network Proxy Support
# -------------------------
function Set-ProxySettings {
param([string]$ProxyAddr, [bool]$Enable)
$global:ProxySettings.Address = $ProxyAddr
$global:ProxySettings.Enabled = $Enable
if ($Enable -and $ProxyAddr) {
[System.Net.WebRequest]::DefaultWebProxy = New-Object System.Net.WebProxy($ProxyAddr, $true)
$env:HTTP_PROXY = $ProxyAddr
$env:HTTPS_PROXY = $ProxyAddr
} else {
[System.Net.WebRequest]::DefaultWebProxy = [System.Net.WebRequest]::GetSystemWebProxy()
Remove-Item Env:\HTTP_PROXY -ErrorAction SilentlyContinue
Remove-Item Env:\HTTPS_PROXY -ErrorAction SilentlyContinue
}
Export-Settings
}
# Apply proxy if configured
if ($global:ProxySettings.Enabled -and $global:ProxySettings.Address) {
Set-ProxySettings -ProxyAddr $global:ProxySettings.Address -Enable $true
}
# -------------------------
# System Restore Point
# -------------------------
function New-RestorePoint {
param([string]$Description = "Driver Updater Restore Point")
try {
# Enable System Restore on system drive if not already enabled
Enable-ComputerRestore -Drive "$env:SystemDrive\" -ErrorAction SilentlyContinue
# Create the restore point
Checkpoint-Computer -Description $Description -RestorePointType "MODIFY_SETTINGS" -ErrorAction Stop
Add-HistoryEntry -TaskName "RestorePoint" -Status "Success" -Details $Description
return $true
} catch {
Add-HistoryEntry -TaskName "RestorePoint" -Status "Failed" -Details $_.Exception.Message
return $false
}
}
# -------------------------
# Scheduled Updates
# -------------------------
$ScheduledTaskName = "DriverUpdater_ScheduledCheck"
function Get-ScheduledUpdateTask {
try {
return Get-ScheduledTask -TaskName $ScheduledTaskName -ErrorAction SilentlyContinue
} catch { return $null }
}
function Set-ScheduledUpdate {
param(
[ValidateSet("Daily", "Weekly", "Monthly")]
[string]$Frequency,
[string]$Time = "03:00"
)
try {
# Remove existing task if any
Remove-ScheduledUpdate
$scriptPath = $PSCommandPath
if (-not $scriptPath) { $scriptPath = $MyInvocation.PSCommandPath }
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -WindowStyle Hidden -File `"$scriptPath`" -Silent -Task CheckDriverUpdates"
switch ($Frequency) {
"Daily" { $trigger = New-ScheduledTaskTrigger -Daily -At $Time }
"Weekly" { $trigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Monday -At $Time }
"Monthly" { $trigger = New-ScheduledTaskTrigger -Monthly -DaysOfMonth 1 -At $Time }
}
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable
Register-ScheduledTask -TaskName $ScheduledTaskName -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force | Out-Null
Add-HistoryEntry -TaskName "ScheduleUpdate" -Status "Created" -Details "$Frequency at $Time"
return $true
} catch {
Add-HistoryEntry -TaskName "ScheduleUpdate" -Status "Failed" -Details $_.Exception.Message
return $false
}
}
function Remove-ScheduledUpdate {
try {
Unregister-ScheduledTask -TaskName $ScheduledTaskName -Confirm:$false -ErrorAction SilentlyContinue
return $true
} catch { return $false }
}
# -------------------------
# Silent Mode Operation
# -------------------------
if ($Silent -and $Task) {
$logFile = Join-Path $LogBase "$Task`_$(Get-Date -Format 'yyyyMMdd_HHmmss').log"
function Write-SilentLog($msg) {
$timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
Add-Content -Path $logFile -Value "$timestamp - $msg"
}
Write-SilentLog "Starting silent mode: $Task"
switch ($Task) {
"WindowsUpdate" {
Write-SilentLog "Running Windows Update..."
try {
& wuauclt.exe /detectnow 2>&1 | Out-Null
Start-Sleep -Seconds 2
Start-Process -FilePath "usoclient.exe" -ArgumentList "StartScan" -NoNewWindow -Wait
Start-Process -FilePath "usoclient.exe" -ArgumentList "StartDownload" -NoNewWindow -Wait
Start-Process -FilePath "usoclient.exe" -ArgumentList "StartInstall" -NoNewWindow -Wait
Write-SilentLog "Windows Update completed"
Add-HistoryEntry -TaskName "WindowsUpdate" -Status "Completed" -Details "Silent mode"
} catch {
Write-SilentLog "Error: $_"
Add-HistoryEntry -TaskName "WindowsUpdate" -Status "Failed" -Details $_.Exception.Message
}
}
"CheckDriverUpdates" {
Write-SilentLog "Checking for driver updates..."
try {
$UpdateSession = New-Object -ComObject Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
$SearchResult = $UpdateSearcher.Search("IsInstalled=0 and Type='Driver'")
if ($SearchResult.Updates.Count -eq 0) {
Write-SilentLog "No driver updates available"
Add-HistoryEntry -TaskName "CheckDriverUpdates" -Status "Completed" -Details "No updates found"
} else {
Write-SilentLog "Found $($SearchResult.Updates.Count) driver updates"
foreach ($Update in $SearchResult.Updates) {
Write-SilentLog " - $($Update.Title)"
}
Add-HistoryEntry -TaskName "CheckDriverUpdates" -Status "Completed" -Details "Found $($SearchResult.Updates.Count) updates"
}
} catch {
Write-SilentLog "Error: $_"
Add-HistoryEntry -TaskName "CheckDriverUpdates" -Status "Failed" -Details $_.Exception.Message
}
}
"ScanDrivers" {
Write-SilentLog "Scanning installed drivers..."
try {
$drivers = Get-CimInstance Win32_PnPSignedDriver | Select-Object DeviceName, Manufacturer, DriverVersion, InfName, Class, DriverDate
# Apply filters
if ($global:FilterSettings.Class) {
$drivers = $drivers | Where-Object { $_.Class -like "*$($global:FilterSettings.Class)*" }
}
if ($global:FilterSettings.Manufacturer) {
$drivers = $drivers | Where-Object { $_.Manufacturer -like "*$($global:FilterSettings.Manufacturer)*" }
}
Write-SilentLog "Found $($drivers.Count) drivers"
$csvPath = Join-Path $LogBase "InstalledDrivers_$(Get-Date -Format 'yyyyMMdd_HHmmss').csv"
$drivers | Export-Csv -Path $csvPath -NoTypeInformation -Encoding UTF8
Write-SilentLog "Exported to: $csvPath"
Add-HistoryEntry -TaskName "ScanDrivers" -Status "Completed" -Details "Found $($drivers.Count) drivers"
} catch {
Write-SilentLog "Error: $_"
Add-HistoryEntry -TaskName "ScanDrivers" -Status "Failed" -Details $_.Exception.Message
}
}
default {
Write-SilentLog "Unknown task: $Task"
Add-HistoryEntry -TaskName $Task -Status "Failed" -Details "Unknown task"
}
}
Write-SilentLog "Silent mode completed"
exit 0
}
# -------------------------
# Helper Functions
# -------------------------
function New-TaskLog([string]$taskName) {
$ts = (Get-Date).ToString("yyyyMMdd_HHmmss")
$logFile = Join-Path $LogBase "$($taskName)_$ts.log"
New-Item -Path $logFile -ItemType File -Force | Out-Null
return $logFile
}
function Add-StatusUI {
param($form, $statusControl, $text)
if ($form -and $statusControl) {
$method = [System.Windows.Forms.MethodInvoker]{
$statusControl.AppendText("$text`r`n")
$statusControl.ScrollToCaret()
}
$form.Invoke($method)
}
}
# -------------------------
# Modern UI Color Scheme
# -------------------------
$global:UIColors = @{
# Dark Theme
Dark = @{
Background = [System.Drawing.Color]::FromArgb(18, 18, 18)
Surface = [System.Drawing.Color]::FromArgb(30, 30, 30)
SurfaceHover = [System.Drawing.Color]::FromArgb(45, 45, 45)
Primary = [System.Drawing.Color]::FromArgb(0, 150, 136) # Teal accent
PrimaryHover = [System.Drawing.Color]::FromArgb(0, 180, 165)
Secondary = [System.Drawing.Color]::FromArgb(66, 66, 66)
Text = [System.Drawing.Color]::FromArgb(240, 240, 240)
TextSecondary = [System.Drawing.Color]::FromArgb(170, 170, 170)
Border = [System.Drawing.Color]::FromArgb(60, 60, 60)
Success = [System.Drawing.Color]::FromArgb(76, 175, 80)
Warning = [System.Drawing.Color]::FromArgb(255, 152, 0)
Error = [System.Drawing.Color]::FromArgb(244, 67, 54)
MenuBar = [System.Drawing.Color]::FromArgb(25, 25, 25)
StatusBar = [System.Drawing.Color]::FromArgb(0, 120, 108)
}
# Light Theme
Light = @{
Background = [System.Drawing.Color]::FromArgb(255, 255, 255)
Surface = [System.Drawing.Color]::FromArgb(245, 247, 250)
SurfaceHover = [System.Drawing.Color]::FromArgb(235, 238, 242)
Primary = [System.Drawing.Color]::FromArgb(0, 137, 123) # Teal accent
PrimaryHover = [System.Drawing.Color]::FromArgb(0, 150, 136)
Secondary = [System.Drawing.Color]::FromArgb(224, 224, 224)
Text = [System.Drawing.Color]::FromArgb(33, 33, 33)
TextSecondary = [System.Drawing.Color]::FromArgb(117, 117, 117)
Border = [System.Drawing.Color]::FromArgb(224, 224, 224)
Success = [System.Drawing.Color]::FromArgb(67, 160, 71)
Warning = [System.Drawing.Color]::FromArgb(251, 140, 0)
Error = [System.Drawing.Color]::FromArgb(229, 57, 53)
MenuBar = [System.Drawing.Color]::FromArgb(255, 255, 255)
StatusBar = [System.Drawing.Color]::FromArgb(0, 137, 123)
}
}
function Get-ThemeColors {
if ($global:DarkModeEnabled) { return $global:UIColors.Dark }
return $global:UIColors.Light
}
# -------------------------
# Build Form
# -------------------------
$form = New-Object Windows.Forms.Form
$form.Text = $AppTitle
$form.Size = '1050,720'
$form.MinimumSize = '1050,720'
$form.StartPosition = "CenterScreen"
$form.Font = New-Object Drawing.Font("Segoe UI", 9.5)
# -------------------------
# Menu Strip
# -------------------------
$menuStrip = New-Object Windows.Forms.MenuStrip
$menuStrip.Padding = '6,2,0,2'
# File Menu
$menuFile = New-Object Windows.Forms.ToolStripMenuItem
$menuFile.Text = "&File"
$menuOpenLogs = New-Object Windows.Forms.ToolStripMenuItem
$menuOpenLogs.Text = (Get-LocalizedString "BtnOpenLogs")
$menuOpenLogs.ShortcutKeys = [System.Windows.Forms.Keys]::Control -bor [System.Windows.Forms.Keys]::L
$menuSeparator1 = New-Object Windows.Forms.ToolStripSeparator
$menuExit = New-Object Windows.Forms.ToolStripMenuItem
$menuExit.Text = "Exit"
$menuExit.ShortcutKeys = [System.Windows.Forms.Keys]::Alt -bor [System.Windows.Forms.Keys]::F4
$menuFile.DropDownItems.AddRange(@($menuOpenLogs, $menuSeparator1, $menuExit))
# Actions Menu
$menuActions = New-Object Windows.Forms.ToolStripMenuItem
$menuActions.Text = "&Actions"
$menuWU = New-Object Windows.Forms.ToolStripMenuItem
$menuWU.Text = (Get-LocalizedString "BtnWU")
$menuWU.ShortcutKeys = [System.Windows.Forms.Keys]::F5
$menuCheckUpdates = New-Object Windows.Forms.ToolStripMenuItem
$menuCheckUpdates.Text = (Get-LocalizedString "BtnCheckUpdates")
$menuCheckUpdates.ShortcutKeys = [System.Windows.Forms.Keys]::F6
$menuScan = New-Object Windows.Forms.ToolStripMenuItem
$menuScan.Text = (Get-LocalizedString "BtnScan")
$menuScan.ShortcutKeys = [System.Windows.Forms.Keys]::F7
$menuSeparator2 = New-Object Windows.Forms.ToolStripSeparator
$menuBackup = New-Object Windows.Forms.ToolStripMenuItem
$menuBackup.Text = (Get-LocalizedString "BtnBackup")
$menuBackup.ShortcutKeys = [System.Windows.Forms.Keys]::Control -bor [System.Windows.Forms.Keys]::B
$menuInstall = New-Object Windows.Forms.ToolStripMenuItem
$menuInstall.Text = (Get-LocalizedString "BtnInstall")
$menuInstall.ShortcutKeys = [System.Windows.Forms.Keys]::Control -bor [System.Windows.Forms.Keys]::I
$menuSeparator3 = New-Object Windows.Forms.ToolStripSeparator
$menuCancel = New-Object Windows.Forms.ToolStripMenuItem
$menuCancel.Text = (Get-LocalizedString "BtnCancel")
$menuCancel.ShortcutKeys = [System.Windows.Forms.Keys]::Control -bor [System.Windows.Forms.Keys]::Q
$menuActions.DropDownItems.AddRange(@($menuWU, $menuCheckUpdates, $menuScan, $menuSeparator2, $menuBackup, $menuInstall, $menuSeparator3, $menuCancel))
# Tools Menu
$menuTools = New-Object Windows.Forms.ToolStripMenuItem
$menuTools.Text = "&Tools"
$menuRestorePoint = New-Object Windows.Forms.ToolStripMenuItem
$menuRestorePoint.Text = (Get-LocalizedString "BtnRestorePoint")
$menuSchedule = New-Object Windows.Forms.ToolStripMenuItem
$menuSchedule.Text = (Get-LocalizedString "BtnSchedule")
$menuFilters = New-Object Windows.Forms.ToolStripMenuItem
$menuFilters.Text = (Get-LocalizedString "BtnFilters")
$menuSeparator4 = New-Object Windows.Forms.ToolStripSeparator
$menuHistory = New-Object Windows.Forms.ToolStripMenuItem
$menuHistory.Text = (Get-LocalizedString "BtnHistory")
$menuHistory.ShortcutKeys = [System.Windows.Forms.Keys]::Control -bor [System.Windows.Forms.Keys]::H
$menuTools.DropDownItems.AddRange(@($menuRestorePoint, $menuSchedule, $menuFilters, $menuSeparator4, $menuHistory))
# View Menu
$menuView = New-Object Windows.Forms.ToolStripMenuItem
$menuView.Text = "&View"
$menuToggleTheme = New-Object Windows.Forms.ToolStripMenuItem
$menuToggleTheme.Text = (Get-LocalizedString "BtnDarkMode")
$menuToggleTheme.ShortcutKeys = [System.Windows.Forms.Keys]::Control -bor [System.Windows.Forms.Keys]::T
$menuSeparator5 = New-Object Windows.Forms.ToolStripSeparator
# Language submenu
$menuLanguage = New-Object Windows.Forms.ToolStripMenuItem
$menuLanguage.Text = "Language"
$langItems = @("English (en)", "Español (es)", "Français (fr)", "Deutsch (de)", "Português (pt)", "Italiano (it)")
$langCodes = @("en", "es", "fr", "de", "pt", "it")
for ($i = 0; $i -lt $langItems.Count; $i++) {
$langMenuItem = New-Object Windows.Forms.ToolStripMenuItem
$langMenuItem.Text = $langItems[$i]
$langMenuItem.Tag = $langCodes[$i]
if ($langCodes[$i] -eq $global:CurrentLanguage) {
$langMenuItem.Checked = $true
}
$menuLanguage.DropDownItems.Add($langMenuItem) | Out-Null
}
$menuView.DropDownItems.AddRange(@($menuToggleTheme, $menuSeparator5, $menuLanguage))
# Settings Menu
$menuSettingsTop = New-Object Windows.Forms.ToolStripMenuItem
$menuSettingsTop.Text = "&Settings"
$menuSettingsTop.ShortcutKeys = [System.Windows.Forms.Keys]::Control -bor [System.Windows.Forms.Keys]::Oemcomma
$menuStrip.Items.AddRange(@($menuFile, $menuActions, $menuTools, $menuView, $menuSettingsTop))
# -------------------------
# Toolbar Panel
# -------------------------
$toolbarPanel = New-Object Windows.Forms.Panel
$toolbarPanel.Dock = 'Top'
$toolbarPanel.Height = 56
# Note: toolbarPanel and menuStrip are added later for correct dock order
# FlowLayoutPanel for centered buttons
$buttonContainer = New-Object Windows.Forms.FlowLayoutPanel
$buttonContainer.Dock = 'Fill'
$buttonContainer.FlowDirection = 'LeftToRight'
$buttonContainer.WrapContents = $false
$buttonContainer.AutoSize = $false
$buttonContainer.Padding = '0,8,0,8'
$toolbarPanel.Controls.Add($buttonContainer)
# Function to center buttons when form resizes
function Update-ButtonContainerPadding {
$totalButtonWidth = 155 + 155 + 155 + 120 + 140 + 110 + (5 * 12) # buttons + gaps
$availableWidth = $toolbarPanel.ClientSize.Width
$leftPadding = [Math]::Max(0, [int](($availableWidth - $totalButtonWidth) / 2))
$buttonContainer.Padding = "$leftPadding,8,0,8"
}
# Modern Button Style
function New-RoundedRegion {
param([int]$Width, [int]$Height, [int]$Radius = 8)
$path = New-Object System.Drawing.Drawing2D.GraphicsPath
$r = $Radius
$w = $Width
$h = $Height
# Top-left arc
$path.AddArc(0, 0, $r * 2, $r * 2, 180, 90)
# Top-right arc
$path.AddArc($w - $r * 2, 0, $r * 2, $r * 2, 270, 90)
# Bottom-right arc
$path.AddArc($w - $r * 2, $h - $r * 2, $r * 2, $r * 2, 0, 90)
# Bottom-left arc
$path.AddArc(0, $h - $r * 2, $r * 2, $r * 2, 90, 90)
$path.CloseFigure()
return New-Object System.Drawing.Region($path)
}
function New-ModernButton {
param(
[string]$Text,
[int]$Width = 130,
[bool]$Primary = $false,
[string]$IconChar = ""
)
$btn = New-Object System.Windows.Forms.Button
$btn.Text = if ($IconChar) { "$IconChar $Text" } else { $Text }
$btn.Width = $Width
$btn.Height = 38
$btn.FlatStyle = "Flat"
$btn.FlatAppearance.BorderSize = 0
$btn.Cursor = [System.Windows.Forms.Cursors]::Hand
$btn.Font = New-Object Drawing.Font("Segoe UI Semibold", 9)
$btn.Tag = $Primary
$btn.TextAlign = 'MiddleCenter'
# Apply rounded corners
$btn.Region = New-RoundedRegion -Width $Width -Height 38 -Radius 6
return $btn
}
# Create toolbar buttons with margins for spacing
$btnWU = New-ModernButton -Text (Get-LocalizedString "BtnWU") -Width 155 -Primary $true
$btnWU.Margin = '0,0,12,0'
$btnCheckUpdates = New-ModernButton -Text (Get-LocalizedString "BtnCheckUpdates") -Width 155 -Primary $true
$btnCheckUpdates.Margin = '0,0,12,0'
$btnScan = New-ModernButton -Text (Get-LocalizedString "BtnScan") -Width 155 -Primary $true
$btnScan.Margin = '0,0,12,0'
$btnBackup = New-ModernButton -Text (Get-LocalizedString "BtnBackup") -Width 120
$btnBackup.Margin = '0,0,12,0'
$btnInstall = New-ModernButton -Text (Get-LocalizedString "BtnInstall") -Width 140
$btnInstall.Margin = '0,0,12,0'
$btnCancel = New-ModernButton -Text (Get-LocalizedString "BtnCancel") -Width 110
$btnCancel.Margin = '0,0,0,0'
# Add buttons to centered container
$buttonContainer.Controls.AddRange(@($btnWU, $btnCheckUpdates, $btnScan, $btnBackup, $btnInstall, $btnCancel))
# -------------------------
# Toolbar Separator (created here, added later for correct dock order)
# -------------------------
$toolbarSeparator = New-Object Windows.Forms.Panel
$toolbarSeparator.Dock = 'Top'
$toolbarSeparator.Height = 1
# -------------------------
# Status Bar
# -------------------------
$statusBar = New-Object Windows.Forms.Panel
$statusBar.Dock = 'Bottom'
$statusBar.Height = 28
$statusLabel = New-Object Windows.Forms.Label
$statusLabel.Text = " Ready"
$statusLabel.Dock = 'Left'
$statusLabel.Width = 600
$statusLabel.TextAlign = 'MiddleLeft'
$statusLabel.Font = New-Object Drawing.Font("Segoe UI", 9)
$statusBar.Controls.Add($statusLabel)
$versionLabel = New-Object Windows.Forms.Label
$versionLabel.Text = "v3.0 "
$versionLabel.Dock = 'Right'
$versionLabel.Width = 60
$versionLabel.TextAlign = 'MiddleRight'
$versionLabel.Font = New-Object Drawing.Font("Segoe UI", 8.5)
$statusBar.Controls.Add($versionLabel)
# -------------------------
# Main Content Container
# -------------------------
$contentPanel = New-Object Windows.Forms.Panel
$contentPanel.Dock = 'Fill'
$contentPanel.Padding = '16,16,16,8'
# Add controls in correct order for docking
# Windows Forms docks controls in reverse order (last added = first docked)
# Order: Fill first, then Bottom, then Top (in reverse visual order)
$form.Controls.Add($contentPanel) # Fill - takes remaining space
$form.Controls.Add($statusBar) # Bottom
$form.Controls.Add($toolbarSeparator) # Top - appears below toolbar
$form.Controls.Add($toolbarPanel) # Top - appears below menu
$form.Controls.Add($menuStrip) # Top - appears at very top
$form.MainMenuStrip = $menuStrip
# Status container panel (acts as border)
$statusBorderPanel = New-Object Windows.Forms.Panel
$statusBorderPanel.Dock = 'Fill'
$statusBorderPanel.Padding = '1,1,1,1'
$contentPanel.Controls.Add($statusBorderPanel)
# Status RichTextBox with modern styling
$status = New-Object Windows.Forms.RichTextBox
$status.Multiline = $true
$status.ReadOnly = $true
$status.Dock = 'Fill'
$status.ScrollBars = 'Vertical'
$status.BorderStyle = 'None'
$status.Font = New-Object Drawing.Font("Cascadia Code, Consolas, Courier New", 9.5)
$statusBorderPanel.Controls.Add($status)
# Progress Panel (Dock Bottom - add after Fill so it appears at bottom)