-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwinrep.py
More file actions
1074 lines (923 loc) · 36.4 KB
/
winrep.py
File metadata and controls
1074 lines (923 loc) · 36.4 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
from __future__ import annotations
import locale
import os
import socket
import subprocess
import sys
import threading
from dataclasses import dataclass
from pathlib import Path
from typing import Dict, List
import webbrowser
from tkinter import messagebox
import tkinter as tk
import customtkinter as ctk
from PIL import Image
# =============================================================================
# Basis-Konfiguration
# =============================================================================
APP_TITLE = "SD TechTools – Windows Repair Toolbox"
WINDOW_SIZE = "1120x620"
BG_WINDOW = "#F3F4F6"
BG_CARD = "#FFFFFF"
BG_CARD_SELECTED = "#E7F1FF"
BORDER_CARD = "#E5E7EB"
BORDER_CARD_SELECTED = "#3B82F6"
BG_RIGHT_PANEL = "#EFF4FF"
TEXT_MUTED = "#6B7280"
ACCENT = "#3B82F6"
CMD_ENCODING = "cp850" # kannst du für andere Dinge behalten
PS_ENCODING = "cp850"
README_URL = "https://github.com/SD-ITLab/SD-TechTools"
LOGO_URL = "https://sd-itlab.de"
BRAND_URL = "https://sd-itlab.de"
def resource_path(rel: str) -> str:
"""Pfad-Helfer (PyInstaller-kompatibel)."""
base = getattr(sys, "_MEIPASS", str(Path(__file__).resolve().parent))
return str(Path(base) / rel)
# =============================================================================
# Aktionen
# =============================================================================
@dataclass(frozen=True)
class WinRepAction:
key: str
title: str
description: str
category: str
ps_command: str | None = None # nur informativ, Logik liegt in PS1
ACTIONS: Dict[str, WinRepAction] = {
"dism_scanhealth": WinRepAction(
"dism_scanhealth",
"Windows Komponentenspeicher auf Fehler prüfen [ScanHealth]",
"Prüft den Komponentenstore auf Beschädigungen.",
"Systemdateien / DISM",
ps_command="DISM /Online /Cleanup-Image /ScanHealth",
),
"dism_checkhealth": WinRepAction(
"dism_checkhealth",
"Prüfen, ob Windows als beschädigt markiert ist [CheckHealth]",
"Zeigt an, ob Windows als beschädigt markiert wurde.",
"Systemdateien / DISM",
ps_command="DISM /Online /Cleanup-Image /CheckHealth",
),
"dism_restorehealth": WinRepAction(
"dism_restorehealth",
"Automatische Reparaturvorgänge durchführen [RestoreHealth]",
"Versucht, beschädigte Dateien zu reparieren.",
"Systemdateien / DISM",
ps_command="DISM /Online /Cleanup-Image /RestoreHealth",
),
"dism_componentcleanup": WinRepAction(
"dism_componentcleanup",
"Abgelöste Startkomponenten bereinigen [ComponentCleanup]",
"Bereinigt den Komponentenstore und entfernt veraltete Komponenten.",
"Systemdateien / DISM",
ps_command="DISM /Online /Cleanup-Image /StartComponentCleanup",
),
"sfc_scannow": WinRepAction(
"sfc_scannow",
"Systemdateien prüfen & reparieren [sfc /scannow]",
"Prüft Systemdateien und stellt Originale wieder her.",
"Systemdateien / DISM",
ps_command="sfc /scannow",
),
"net_reset": WinRepAction(
"net_reset",
"Netzwerkeinstellungen zurücksetzen [FlushDNS usw.]",
"Setzt DNS-Cache, Winsock und wichtige Netzwerk-Stacks zurück.",
"Netzwerk",
),
"wu_reset": WinRepAction(
"wu_reset",
"Windows Updates zurücksetzen / Cache bereinigen",
"Bereinigt den Update-Cache und setzt Windows Update Komponenten zurück.",
"Cleanup / Updates",
),
"temp_cleanup": WinRepAction(
"temp_cleanup",
"Temporäre Dateien bereinigen",
"Löscht TEMP-Ordner & unnötige Dateien.",
"Cleanup / Updates",
),
"upgrade_pro": WinRepAction(
"upgrade_pro",
"Upgrade von Windows Home auf Windows Pro",
"Setzt den Product Key für das Upgrade auf Windows Pro.",
"Leistung / Tuning",
),
"power_high": WinRepAction(
"power_high",
"Windows Höchstleistungsmodus aktivieren",
"Aktiviert den Windows-Höchstleistungsmodus, sofern verfügbar.",
"Leistung / Tuning",
),
"sysinfo": WinRepAction(
"sysinfo",
"Systeminformationen anzeigen",
"Zeigt ausführliche Systeminformationen an.",
"Info & Tools",
ps_command="systeminfo",
),
"chkdsk_c": WinRepAction(
"chkdsk_c",
"Dateisystem von C: prüfen [chkdsk]",
"Führt eine Dateisystemprüfung von Laufwerk C: (online /scan) durch.",
"Systemdateien / DISM",
),
"bitlocker_disable": WinRepAction(
"bitlocker_disable",
"BitLocker auf Laufwerk C: deaktivieren",
"Deaktiviert BitLocker auf C:. Achtung: Entschlüsselung kann lange dauern!",
"Info & Tools",
),
"battery_info": WinRepAction(
"battery_info",
"Akkuinformationen anzeigen",
"Zeigt Informationen zum Akku (Ladestand, Status usw.), falls vorhanden.",
"Info & Tools",
),
"sysinfo": WinRepAction(
"sysinfo",
"Systeminformationen anzeigen",
"Zeigt ausführliche Systeminformationen an.",
"Info & Tools",
ps_command="systeminfo",
),
}
ACTION_ORDER: List[str] = [
"dism_scanhealth",
"dism_checkhealth",
"dism_restorehealth",
"dism_componentcleanup",
"sfc_scannow",
"chkdsk_c",
"net_reset",
"wu_reset",
"temp_cleanup",
"upgrade_pro",
"power_high",
"bitlocker_disable",
"battery_info",
"sysinfo",
]
def sorted_action_keys(keys: List[str]) -> List[str]:
def order_index(k: str) -> int:
try:
return ACTION_ORDER.index(k)
except ValueError:
return len(ACTION_ORDER) + 1
return sorted(keys, key=order_index)
# =============================================================================
# UI: ActionRow
# =============================================================================
class ActionRow(ctk.CTkFrame):
def __init__(self, master, action_key: str, on_click, width: int = 540, height: int = 80):
super().__init__(
master,
fg_color=BG_CARD,
corner_radius=14,
width=width,
height=height,
)
self.grid_propagate(False)
self.action_key = action_key
self.on_click = on_click
self.selected = False
self.configure(border_width=1, border_color=BORDER_CARD)
self.grid_columnconfigure(0, weight=1)
action = ACTIONS[action_key]
self.title_lbl = ctk.CTkLabel(
self,
text=action.title,
font=ctk.CTkFont(size=12, weight="bold"),
anchor="w",
)
self.title_lbl.grid(row=0, column=0, sticky="w", padx=12, pady=(8, 0))
self.desc_lbl = ctk.CTkLabel(
self,
text=action.description,
font=ctk.CTkFont(size=10),
text_color=TEXT_MUTED,
anchor="w",
justify="left",
wraplength=width - 40,
)
self.desc_lbl.grid(row=1, column=0, sticky="w", padx=12, pady=(0, 8))
for w in (self, self.title_lbl, self.desc_lbl):
w.bind("<Button-1>", self._on_click_internal)
def _on_click_internal(self, _event=None):
if callable(self.on_click):
self.on_click(self.action_key)
def set_selected(self, selected: bool):
self.selected = selected
try:
if selected:
self.configure(fg_color=BG_CARD_SELECTED, border_color=BORDER_CARD_SELECTED)
else:
self.configure(fg_color=BG_CARD, border_color=BORDER_CARD)
except tk.TclError:
pass
def set_width(self, width: int):
self.configure(width=width)
self.desc_lbl.configure(wraplength=max(180, width - 40))
# =============================================================================
# Main-App
# =============================================================================
class WinRepApp(ctk.CTk):
def __init__(self):
super().__init__()
ctk.set_appearance_mode("light")
ctk.set_default_color_theme("blue")
self.title(APP_TITLE)
self.geometry(WINDOW_SIZE)
self.minsize(1120, 620)
self.resizable(False, False) # bewusst fix
self.configure(fg_color=BG_WINDOW)
self._set_window_icon()
self.category_var = tk.StringVar(value="Alle")
self.selected_action: str | None = None
self.rows: Dict[str, ActionRow] = {}
self._list_resize_after_id: str | None = None
self.sys_computer = tk.StringVar(value="-")
self.sys_os = tk.StringVar(value="-")
self.sys_ip = tk.StringVar(value="-")
self.sys_cpu = tk.StringVar(value="-")
self.sys_boot = tk.StringVar(value="-")
self.sys_bitlocker = tk.StringVar(value="-")
self.sys_disk = tk.StringVar(value="-")
self.bottom_logo = None # Referenz für CTkImage
self._build_layout()
self.after(0, self._initial_render)
self.after(200, self._load_system_info_async)
def _open_url(self, url: str):
try:
webbrowser.open(url, new=2)
except Exception as exc:
messagebox.showinfo(
"Info",
f"Link konnte nicht geöffnet werden:\n{exc}"
)
# -------------------------------------------------------------------------
# Icon
# -------------------------------------------------------------------------
def _set_window_icon(self):
candidates = ["winrep.ico", "WinRep.ico", "icon.ico"]
for name in candidates:
path = Path(resource_path(name))
if path.exists():
try:
self.iconbitmap(str(path))
except Exception:
pass
break
# -------------------------------------------------------------------------
# Layout
# -------------------------------------------------------------------------
def _build_layout(self):
# Root: 2 Zeilen (Hauptbereich + Footer), 2 Spalten (links + Hauptbereich)
self.grid_rowconfigure(0, weight=1)
self.grid_rowconfigure(1, weight=0)
self.grid_columnconfigure(0, weight=0) # linke Spalte
self.grid_columnconfigure(1, weight=1) # Mitte + Rechts + Footer
# --------------------------- Linke Spalte -----------------------------
LEFT_PANEL_WIDTH = 190
left = ctk.CTkFrame(self, fg_color=BG_WINDOW, width=LEFT_PANEL_WIDTH)
left.grid(row=0, column=0, rowspan=2, sticky="nsw", padx=(16, 8), pady=8)
left.grid_propagate(False)
left.grid_columnconfigure(0, weight=1)
ctk.CTkLabel(
left,
text="Kategorien",
font=ctk.CTkFont(size=13, weight="bold"),
).grid(row=0, column=0, sticky="w", padx=4, pady=(4, 6))
cats = ["Alle"] + sorted({a.category for a in ACTIONS.values()})
self.cat_buttons: List[ctk.CTkButton] = []
for i, cat in enumerate(cats, start=1):
btn = ctk.CTkButton(
left,
text=cat,
width=170,
height=34,
fg_color=BG_CARD_SELECTED if cat == "Alle" else BG_CARD,
border_width=1,
border_color=(BORDER_CARD_SELECTED if cat == "Alle" else BORDER_CARD),
text_color="#111827",
hover_color="#E5E7EB",
command=lambda c=cat: self._set_category(c),
)
btn.grid(row=i, column=0, sticky="ew", padx=4, pady=4)
self.cat_buttons.append(btn)
spacer_row = len(cats) + 1
left.grid_rowconfigure(spacer_row, weight=1)
logo_box = ctk.CTkFrame(
left,
fg_color=BG_CARD,
corner_radius=18,
border_width=1,
border_color=BORDER_CARD,
width=LEFT_PANEL_WIDTH,
height=120,
)
logo_box.grid(row=spacer_row + 1, column=0, sticky="sew", padx=4, pady=(0, 4))
logo_box.grid_propagate(False)
self.logo_label = ctk.CTkLabel(logo_box, text="")
self.logo_label.place(relx=0.5, rely=0.5, anchor="center")
self.logo_label.configure(cursor="hand2")
self.logo_label.bind("<Button-1>", lambda e: self._open_url(LOGO_URL))
self._load_bottom_logo()
# -------------------------- Hauptbereich ------------------------------
main = ctk.CTkFrame(self, fg_color=BG_WINDOW)
main.grid(row=0, column=1, sticky="nsew", padx=(0, 16), pady=(8, 0))
main.grid_rowconfigure(0, weight=1)
main.grid_columnconfigure(0, weight=1) # Mitte
main.grid_columnconfigure(1, weight=0) # Rechts
# Mitte: Aktionen
mid = ctk.CTkFrame(main, fg_color=BG_WINDOW, width=540)
mid.grid(row=0, column=0, sticky="nsw", padx=(8, 4), pady=(0, 8))
mid.grid_propagate(False)
mid.grid_columnconfigure(0, weight=1)
mid.grid_rowconfigure(1, weight=1)
ctk.CTkLabel(
mid,
text="Aktionen auswählen",
font=ctk.CTkFont(size=17, weight="bold"),
).grid(row=0, column=0, sticky="w", padx=4, pady=(4, 8))
list_wrapper = ctk.CTkFrame(mid, fg_color=BG_WINDOW)
list_wrapper.grid(row=1, column=0, sticky="nsew", padx=4, pady=(0, 4))
list_wrapper.grid_columnconfigure(0, weight=1)
list_wrapper.grid_rowconfigure(0, weight=1)
self.list_scroll = ctk.CTkScrollableFrame(
list_wrapper,
fg_color=BG_WINDOW,
corner_radius=0,
)
self.list_scroll.grid(row=0, column=0, sticky="nsew")
self.list_scroll.grid_columnconfigure(0, weight=1)
canvas = getattr(self.list_scroll, "_parent_canvas", None)
if canvas is not None:
canvas.bind("<Configure>", self._on_list_canvas_configure)
# Rechts: Systeminfos + Log
right = ctk.CTkFrame(main, fg_color=BG_WINDOW, width=400)
right.grid(row=0, column=1, sticky="nse", padx=(1, 0), pady=(0, 8))
right.grid_propagate(False)
right.grid_columnconfigure(0, weight=1)
right.grid_rowconfigure(3, weight=1)
header = ctk.CTkFrame(right, fg_color="transparent")
header.grid(row=0, column=0, sticky="ew", padx=6, pady=(4, 6))
header.grid_columnconfigure(0, weight=1)
ctk.CTkLabel(
header,
text="SD - TechTools",
font=ctk.CTkFont(size=18, weight="bold"),
).grid(row=0, column=0, sticky="w")
sys_box = ctk.CTkFrame(
right,
fg_color=BG_RIGHT_PANEL,
corner_radius=18,
border_width=1,
border_color=BORDER_CARD,
)
sys_box.grid(row=1, column=0, sticky="ew", padx=4, pady=(4, 6))
sys_box.grid_columnconfigure(0, weight=0)
sys_box.grid_columnconfigure(1, weight=1)
def add_row(r: int, label: str, var: ctk.StringVar):
ctk.CTkLabel(
sys_box,
text=label,
text_color=TEXT_MUTED,
anchor="w",
font=ctk.CTkFont(size=10),
).grid(row=r, column=0, sticky="w", padx=12, pady=(1, 1))
ctk.CTkLabel(
sys_box,
textvariable=var,
anchor="w",
justify="left",
wraplength=230,
font=ctk.CTkFont(size=11),
).grid(row=r, column=1, sticky="w", padx=12, pady=(1, 1))
add_row(0, "Betriebssystem:", self.sys_os)
add_row(1, "Boot:", self.sys_boot)
add_row(2, "BitLocker:", self.sys_bitlocker)
add_row(3, "Netzwerk-IP:", self.sys_ip)
add_row(4, "Systemlaufwerk C:\\", self.sys_disk)
add_row(5, "Prozessor:", self.sys_cpu)
ctk.CTkLabel(
right,
text="Aktuelles Log:",
font=ctk.CTkFont(size=11, weight="bold"),
).grid(row=2, column=0, sticky="w", padx=6, pady=(6, 2))
self.log_text = ctk.CTkTextbox(
right,
height=260,
fg_color=BG_CARD,
text_color="#111827",
wrap="word",
font=ctk.CTkFont(size=10),
)
self.log_text.grid(row=3, column=0, sticky="nsew", padx=6, pady=(0, 8))
self.log_text.insert("end", "Hier erscheinen Ausgaben von WinRep-Aktionen …")
self.log_text.configure(state="disabled")
# ------------------------------ Footer -------------------------------
footer = ctk.CTkFrame(self, corner_radius=0, fg_color=BG_WINDOW)
footer.grid(row=1, column=1, sticky="ew", padx=(0, 16), pady=(4, 8))
footer.grid_columnconfigure(0, weight=1)
footer.grid_columnconfigure(1, weight=0)
footer.grid_columnconfigure(2, weight=0)
footer.grid_columnconfigure(3, weight=0)
self.progress = ctk.CTkProgressBar(
footer,
progress_color=ACCENT,
fg_color="#E5E7EB",
height=10,
corner_radius=999,
)
self.progress.grid(row=0, column=0, columnspan=4, sticky="ew", padx=(8, 0), pady=(4, 8))
self.progress.set(0.0)
self.status_lbl = ctk.CTkLabel(
footer,
text="Bereit.",
text_color=TEXT_MUTED,
font=ctk.CTkFont(size=10),
)
self.status_lbl.grid(row=1, column=0, sticky="w", padx=8, pady=(0, 8))
self.footer_brand = ctk.CTkLabel(
footer,
text="© 2026 SD-ITLab – MIT licensed",
font=ctk.CTkFont(size=10),
text_color=TEXT_MUTED,
cursor="hand2",
)
self.footer_brand.grid(row=1, column=1, sticky="e", padx=(0, 10), pady=(0, 8))
self.footer_brand.bind("<Button-1>", lambda e: self._open_url(BRAND_URL))
self.footer_brand.bind("<Enter>", lambda e: self.footer_brand.configure(text_color=ACCENT))
self.footer_brand.bind("<Leave>", lambda e: self.footer_brand.configure(text_color=TEXT_MUTED))
self.btn_readme = ctk.CTkButton(
footer,
text="Readme",
width=100,
command=lambda: self._open_url(README_URL),
)
self.btn_readme.grid(row=1, column=2, padx=6, pady=(0, 8))
self.btn_run = ctk.CTkButton(
footer,
text="Aktion ausführen",
width=130,
command=self._run_selected_action,
)
self.btn_run.grid(row=1, column=3, padx=6, pady=(0, 8))
self.btn_close = ctk.CTkButton(
footer,
text="Schließen",
width=110,
command=self.destroy,
)
self.btn_close.grid(row=1, column=4, padx=(6, 0), pady=(0, 8))
# -------------------------------------------------------------------------
# Logo
# -------------------------------------------------------------------------
def _load_bottom_logo(self):
try:
logo_path = resource_path("logo1.png")
img = Image.open(logo_path).convert("RGBA")
except Exception:
self.logo_label.configure(
text="SD-ITLAB",
text_color=TEXT_MUTED,
font=ctk.CTkFont(size=11, weight="bold"),
)
return
max_width, max_height = 190, 100
ratio = img.width / img.height
if ratio > (max_width / max_height):
new_w = max_width
new_h = int(max_width / ratio)
else:
new_h = max_height
new_w = int(max_height * ratio)
img = img.resize((new_w, new_h), Image.LANCZOS)
self.bottom_logo = ctk.CTkImage(
light_image=img,
dark_image=img,
size=(new_w, new_h),
)
self.logo_label.configure(image=self.bottom_logo, text="")
# -------------------------------------------------------------------------
# Rendering / Filter
# -------------------------------------------------------------------------
def _get_row_width(self) -> int:
try:
canvas = getattr(self.list_scroll, "_parent_canvas", None)
if canvas is not None:
w = int(canvas.winfo_width() or 0)
if w > 50:
return max(1, w - 28)
except Exception:
pass
return 520 - 24
def _on_list_canvas_configure(self, _event=None):
if self._list_resize_after_id is not None:
try:
self.after_cancel(self._list_resize_after_id)
except Exception:
pass
self._list_resize_after_id = self.after(50, self._resize_rows_to_canvas)
def _resize_rows_to_canvas(self):
self._list_resize_after_id = None
if not self.rows:
return
new_w = self._get_row_width()
if not new_w:
return
for r in self.rows.values():
r.set_width(new_w)
def _initial_render(self):
self._render_action_list()
self.after(80, self._resize_rows_to_canvas)
def _set_category(self, cat: str):
self.category_var.set(cat)
for b in self.cat_buttons:
if b.cget("text") == cat:
b.configure(fg_color=BG_CARD_SELECTED, border_color=BORDER_CARD_SELECTED)
else:
b.configure(fg_color=BG_CARD, border_color=BORDER_CARD)
self._render_action_list()
def _filtered_keys(self) -> List[str]:
cat = self.category_var.get()
keys = list(ACTIONS.keys())
if cat and cat != "Alle":
keys = [k for k in keys if ACTIONS[k].category == cat]
return sorted_action_keys(keys)
def _render_action_list(self):
for child in self.list_scroll.winfo_children():
child.destroy()
self.rows.clear()
keys = self._filtered_keys()
row_width = self._get_row_width()
for i, k in enumerate(keys):
r = ActionRow(self.list_scroll, k, on_click=self._on_action_clicked, width=row_width)
r.grid(row=i, column=0, sticky="ew", padx=4, pady=4)
self.rows[k] = r
def _on_action_clicked(self, action_key: str):
self.selected_action = action_key
for k, row in self.rows.items():
row.set_selected(k == action_key)
# -------------------------------------------------------------------------
# PowerShell Helper
# -------------------------------------------------------------------------
def _run_ps1_action(self, action: WinRepAction):
"""
Führt eine Aktion über die externe winrep_actions.ps1 aus.
Die PS1 bekommt den Parameter -Action <action_key>.
Ausgabe-Kodierung: CP850 (damit Umlaute von DISM/SFC korrekt sind).
"""
script_path = Path(resource_path("winrep_actions.ps1"))
if not script_path.exists():
self._append_log(
"winrep_actions.ps1 wurde nicht gefunden.\n"
"Bitte die Datei im gleichen Verzeichnis wie WinRep ablegen.\n"
)
self.after(
0,
self.status_lbl.configure,
{"text": f"Aktion fehlgeschlagen: {action.title} (PS1 fehlt)"},
)
self.after(1200, lambda: self.progress.set(0.0))
return
self._clear_log()
self._append_log(f"Starte Aktion: {action.title}\n")
self._append_log(f"Script: {script_path.name}\n\n")
ps_cmd = (
"[Console]::OutputEncoding=[System.Text.Encoding]::GetEncoding(850); "
"$OutputEncoding=[System.Text.Encoding]::GetEncoding(850); "
f"& '{script_path}' -Action '{action.key}'"
)
cmd = [
"powershell.exe",
"-NoProfile",
"-NonInteractive",
"-WindowStyle", "Hidden",
"-ExecutionPolicy", "Bypass",
"-Command", ps_cmd,
]
# PowerShell-Fenster verstecken (auch bei PyInstaller-Onefile)
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
try:
proc = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
encoding=PS_ENCODING, # cp850
errors="replace",
startupinfo=startupinfo,
creationflags=subprocess.CREATE_NO_WINDOW,
)
except Exception as exc:
self._append_log(f"[Fehler beim Start von PowerShell] {exc}\n")
self.after(
0,
self.status_lbl.configure,
{"text": f"Fehler bei Aktion: {action.title}"},
)
self.after(1200, lambda: self.progress.set(0.0))
return
self.progress.set(0.2)
for line in proc.stdout:
self._append_log(line)
rc = proc.wait()
self.after(0, self.progress.set, 1.0)
if rc == 0:
self.after(
0,
self.status_lbl.configure,
{"text": f"Fertig: {action.title} (OK)"},
)
# Spezielles Verhalten für CHKDSK: Neustart anbieten
if action.key == "chkdsk_c":
def ask_restart():
from tkinter import messagebox
if messagebox.askyesno(
"Neustart für CHKDSK",
"Die Reparatur von Laufwerk C: wurde mit CHKDSK /F "
"für den nächsten Systemstart eingeplant.\n\n"
"Möchten Sie den Computer jetzt neu starten?",
):
self._append_log(
"\nNeustart wird vorbereitet ...\n"
"Windows führt CHKDSK vor dem Hochfahren aus.\n"
)
try:
subprocess.Popen(
["shutdown", "/r", "/t", "0"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
except Exception as exc:
self._append_log(
f"[Fehler beim Neustart] {exc}\n"
)
else:
self._append_log(
"\nNeustart wurde vom Benutzer abgebrochen. "
"CHKDSK wird beim nächsten manuellen Neustart "
"trotzdem ausgeführt.\n"
)
# Dialog im GUI-Thread anzeigen
self.after(0, ask_restart)
else:
self._append_log(f"\nScript Rückgabecode: {rc}\n")
self.after(
0,
self.status_lbl.configure,
{"text": f"Fertig: {action.title} (Fehlercode {rc})"},
)
self.after(1500, lambda: self.progress.set(0.0))
# -------------------------------------------------------------------------
# Aktionen ausführen – alles über winrep_actions.ps1
# -------------------------------------------------------------------------
def _run_selected_action(self):
if not self.selected_action:
self._append_log("Bitte zuerst eine Aktion auswählen.\n")
return
action = ACTIONS[self.selected_action]
if action.key == "upgrade_pro":
from tkinter import messagebox
if not messagebox.askyesno(
"Windows-Edition upgraden",
"Diese Aktion versucht, ein Windows Home auf Windows Pro zu upgraden.\n"
"Nur auf Systemen ausführen, auf denen du das wirklich möchtest.\n\n"
"Fortfahren?",
):
return
self.status_lbl.configure(text=f"Führe Aktion aus: {action.title}")
self.progress.set(0.1)
def worker():
try:
self._run_ps1_action(action)
except Exception as exc:
self._append_log(f"\n[Fehler] {exc}\n")
self.after(
0,
self.status_lbl.configure,
{"text": f"Fehler bei Aktion: {action.title}"},
)
self.after(1200, lambda: self.progress.set(0.0))
threading.Thread(target=worker, daemon=True).start()
# -------------------------------------------------------------------------
# Log Helpers
# -------------------------------------------------------------------------
def _clear_log(self):
self.log_text.configure(state="normal")
self.log_text.delete("1.0", "end")
self.log_text.configure(state="disabled")
def _append_log(self, text: str):
self.log_text.configure(state="normal")
self.log_text.insert("end", text)
self.log_text.see("end")
self.log_text.configure(state="disabled")
# -------------------------------------------------------------------------
# Systeminfo
# -------------------------------------------------------------------------
def _run_powershell(self, ps: str) -> str:
prefixed = (
"[Console]::OutputEncoding=[System.Text.Encoding]::GetEncoding(850); "
"$OutputEncoding=[System.Text.Encoding]::GetEncoding(850); "
+ ps
)
try:
# PowerShell-Fenster verstecken
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
out = subprocess.check_output(
[
"powershell.exe",
"-NoProfile",
"-NonInteractive",
"-WindowStyle", "Hidden",
"-ExecutionPolicy", "Bypass",
"-Command", prefixed,
],
text=True,
encoding=PS_ENCODING, # cp850
errors="replace",
stderr=subprocess.STDOUT,
startupinfo=startupinfo,
creationflags=subprocess.CREATE_NO_WINDOW,
)
return (out or "").strip()
except Exception:
return ""
def _get_system_info_bundle(self) -> dict[str, str]:
ps = r"""
$ErrorActionPreference = 'SilentlyContinue'
# Betriebssystem
$os = Get-CimInstance Win32_OperatingSystem
$cv = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -ErrorAction SilentlyContinue
$cap = $os.Caption
$edition = $cap -replace '^Microsoft\s+', ''
$arch = $os.OSArchitecture
if ($arch) {
$arch = $arch -replace 'bit','Bit'
$arch = $arch -replace '-', ' '
}
$disp = $cv.DisplayVersion
if (-not $disp -and $cv.ReleaseId) { $disp = $cv.ReleaseId }
if (-not $disp) { $disp = $os.Version }
if ($arch) {
$osStr = "$edition - $arch ($disp)"
} else {
$osStr = "$edition ($disp)"
}
# Boot-Modus und Partitionsstil
$boot = 'Unbekannt'
try {
$fw = (Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control' -Name 'PEFirmwareType' -ErrorAction SilentlyContinue).PEFirmwareType
if ($fw) {
$boot = switch ($fw) {
1 { 'Legacy / BIOS' }
2 { 'UEFI' }
Default { 'Unbekannt' }
}
}
} catch {}
if ($boot -eq 'Unbekannt') {
try {
if (Test-Path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecureBoot\State') {
$boot = 'UEFI'
} else {
$boot = 'Legacy / BIOS'
}
} catch {}
}
$style = $null
try {
$diskObj = Get-Partition -DriveLetter C -ErrorAction SilentlyContinue | Get-Disk
$style = $diskObj.PartitionStyle
} catch {}
if ($style) {
$bootStr = "$boot ($style)"
} else {
$bootStr = $boot
}
# BitLocker-Status
$blStr = 'BitLocker: Unbekannt'
try {
if (Get-Command -Name Get-BitLockerVolume -ErrorAction SilentlyContinue) {
$vol = Get-BitLockerVolume -MountPoint 'C:' -ErrorAction SilentlyContinue
if ($vol) {
$prot = [int]$vol.ProtectionStatus
$protText = switch ($prot) {
0 { 'Aus' }
1 { 'Aktiv' }
2 { 'Ausgesetzt' }
default { "Unbekannt ($prot)" }
}
$vs = $vol.VolumeStatus
if ($vs) {
$blStr = "BitLocker: $protText – VolumeStatus: $vs"
} else {
$blStr = "BitLocker: $protText"
}
} else {
$blStr = 'BitLocker: Kein Volume gefunden'
}
} else {
$blStr = 'BitLocker-Cmdlets nicht vorhanden'
}
} catch {}
# IP-Adresse (primäre IPv4)
$ipv4 = '-'
try {
$adapters = Get-NetIPAddress -AddressFamily IPv4 -PrefixOrigin Dhcp,Manual -ErrorAction SilentlyContinue |
Where-Object { $_.IPAddress -notlike '169.254.*' -and $_.IPAddress -ne '127.0.0.1' } |
Sort-Object -Property InterfaceMetric, AddressFamily
if ($adapters) {
$ipv4 = $adapters[0].IPAddress
}
} catch {}
# CPU
$cpuName = '-'
try {
$cpu = Get-CimInstance Win32_Processor | Select-Object -First 1
if ($cpu -and $cpu.Name) { $cpuName = $cpu.Name.Trim() }
} catch {}
# Systemlaufwerk C:
$diskStr = 'Nicht verfügbar'
try {
$drive = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID='C:'" -ErrorAction SilentlyContinue
if ($drive -and $drive.Size) {
function Format-Size([double]$bytes) {
if ($bytes -ge 1TB) {
$tb = [math]::Round($bytes / 1TB, 0)
"{0} TB" -f $tb
}
elseif ($bytes -ge 1GB) {
$gb = [math]::Round($bytes / 1GB, 0)
"{0} GB" -f $gb
}