-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowsStorePublisher_3.py
More file actions
1618 lines (1345 loc) · 68.4 KB
/
WindowsStorePublisher_3.py
File metadata and controls
1618 lines (1345 loc) · 68.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Windows Store Packager — Version 2.3 (Auto-Setup & Safe Mode)
Complete GUI tool for Microsoft Store app packaging.
Changelog v2.3:
- Added auto-installer for dependencies (Pillow, pygetwindow, keyring).
- Added robust check for Tkinter installation errors.
"""
import sys
import subprocess
import os
import importlib
# ------------------------------------------------------------
# 0. Auto-Installation fehlender Pakete (Bootstrapper)
# ------------------------------------------------------------
def install_and_import(package_name, import_name=None):
"""
Versucht ein Modul zu importieren. Falls es fehlt, wird es per pip installiert.
"""
if import_name is None:
import_name = package_name
try:
importlib.import_module(import_name)
except ImportError:
print(f"⚠️ Modul '{import_name}' fehlt. Installiere '{package_name}'...")
try:
# sys.executable garantiert, dass wir das pip des aktuellen Interpreters nutzen
subprocess.check_call([sys.executable, "-m", "pip", "install", package_name])
print(f"✅ '{package_name}' erfolgreich installiert.")
except Exception as e:
print(f"❌ Fehler bei der Installation von {package_name}: {e}")
print("Bitte führen Sie das Skript als Administrator aus oder installieren Sie manuell.")
input("Drücken Sie Enter zum Beenden...")
sys.exit(1)
# Cache invalidieren und neu importieren
try:
importlib.invalidate_caches()
importlib.import_module(import_name)
except ImportError:
print(f"❌ Import von '{import_name}' nach Installation immer noch nicht möglich.")
sys.exit(1)
# ------------------------------------------------------------
# 0b. Abhängigkeiten sicherstellen (nur wenn direkt ausgeführt)
# ------------------------------------------------------------
def ensure_dependencies():
"""Prüft und installiert fehlende Abhängigkeiten (nur beim Start als Hauptskript)."""
print("--- Prüfe Abhängigkeiten ---")
install_and_import("Pillow", "PIL") # Für Icon-Resizing
install_and_import("pygetwindow") # Für Screenshots
install_and_import("keyring") # Für sichere Passwort-Speicherung
print("--- Abhängigkeiten OK ---")
# ------------------------------------------------------------
# 1. Imports der nachgeladenen Module & Standard-Libs
# ------------------------------------------------------------
try:
from PIL import Image, ImageGrab
import pygetwindow as gw
import keyring
except ImportError:
Image = ImageGrab = None
gw = None
keyring = None
# Standard Libs
import json
import shutil
import glob
import re
import time
import threading
import html
import hashlib
from pathlib import Path
from project_profile import read_project_profile, write_project_profile
# ------------------------------------------------------------
# 2. Tkinter Sicherheits-Import
# ------------------------------------------------------------
try:
import tkinter as tk
from tkinter import filedialog, messagebox, scrolledtext, ttk
except ImportError:
print("\n❌ KRITISCHER FEHLER: 'tkinter' fehlt.")
print("Tkinter ist für die grafische Oberfläche zwingend erforderlich.")
print("-" * 50)
if os.name == 'nt':
print("LÖSUNG (Windows):")
print("1. Starten Sie den Python-Installer erneut.")
print("2. Wählen Sie 'Modify' (Ändern).")
print("3. Stellen Sie sicher, dass der Haken bei 'tcl/tk and IDLE' gesetzt ist.")
else:
print("LÖSUNG (Linux):")
print("Installieren Sie das Paket python3-tk (z.B. 'sudo apt-get install python3-tk').")
print("-" * 50)
input("Drücken Sie Enter zum Beenden...")
sys.exit(1)
# ---------- Configuration ----------
HAS_KEYRING = True # Jetzt garantiert, da oben installiert
OUTPUT_ROOT = str(Path(__file__).parent / "store_package")
SETTINGS_FILE = str(Path(__file__).parent / "settings_store_packager.json")
ICON_SIZES = [44, 50, 150, 310] # Square sizes
WIDE_ICON_SIZE = (310, 150) # Wide tile
DEFAULT_VERSION = "1.0.0.0"
KEYRING_SERVICE = "WindowsStorePackager"
MANIFEST_TEMPLATE = """<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap rescap">
<Identity Name="{{IDENTITY_NAME}}"
Publisher="{{PUBLISHER}}"
Version="{{VERSION}}" />
<Properties>
<DisplayName>{{APPNAME}}</DisplayName>
<PublisherDisplayName>{{PUBLISHER_DISPLAY}}</PublisherDisplayName>
<Description>{{DESCRIPTION}}</Description>
<Logo>icons\\icon_50x50.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
</Dependencies>
<Capabilities>
{{CAPABILITIES}}
</Capabilities>
<Applications>
<Application Id="{{APPNAME}}App"
Executable="{{EXECUTABLE}}"
EntryPoint="Windows.FullTrustApplication">
<uap:VisualElements DisplayName="{{APPNAME}}"
Description="{{DESCRIPTION}}"
Square150x150Logo="icons\\icon_150x150.png"
Square44x44Logo="icons\\icon_44x44.png"
BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="icons\\icon_310x150.png" />
</uap:VisualElements>
</Application>
</Applications>
</Package>
"""
CATEGORIES = [
"Productivity", "Education", "Entertainment", "Games", "Photo & Video",
"Music", "Business", "Developer Tools", "Utilities", "Social", "Health & Fitness"
]
AGE_RATINGS = ["3+", "7+", "12+", "16+", "18+"]
# -----------------------------------
def which(program):
"""Find executable in PATH"""
paths = os.environ.get("PATH", "").split(os.pathsep)
exts = [""] if os.name != "nt" else os.environ.get("PATHEXT", ".EXE;.BAT;.CMD").split(";")
for p in paths:
for ext in exts:
candidate = os.path.join(p, program + ext)
if os.path.isfile(candidate):
return candidate
return None
def find_windows_sdk_tools():
"""Auto-detect Windows SDK tools"""
makeappx = which("makeappx.exe")
signtool = which("signtool.exe")
appcert = which("appcert.exe")
if makeappx and signtool:
return makeappx, signtool, appcert
return None, None, None
def validate_publisher_cn(publisher):
"""Validate Publisher CN format"""
if not publisher.strip():
return False, "Publisher darf nicht leer sein"
if not publisher.startswith("CN="):
return False, "Publisher muss mit 'CN=' beginnen"
return True, ""
class ProgressDialog(tk.Toplevel):
"""Modal progress dialog for long operations - Thread Safe Fix Applied"""
def __init__(self, parent, title="Verarbeitung..."):
super().__init__(parent)
self.title(title)
self.geometry("400x120")
self.resizable(False, False)
self.transient(parent)
self.grab_set()
ttk.Label(self, text=title, font=("Arial", 10, "bold")).pack(pady=10)
self.progress = ttk.Progressbar(self, mode='indeterminate', length=350)
self.progress.pack(pady=10)
self.progress.start(10)
self.status_label = ttk.Label(self, text="Bitte warten...")
self.status_label.pack(pady=5)
self.protocol("WM_DELETE_WINDOW", lambda: None) # Prevent closing
def update_status(self, text):
"""Thread-safe update of the status label"""
self.after(0, lambda: self.status_label.config(text=text))
def close(self):
"""Thread-safe close"""
self.after(0, self._close_internal)
def _close_internal(self):
self.progress.stop()
self.grab_release()
self.destroy()
class StorePackagerApp(tk.Tk):
def __init__(self):
super().__init__()
app_icon_path = str(Path(__file__).parent / "WinStorePackager.ico")
if os.path.exists(app_icon_path):
try:
self.iconbitmap(default=app_icon_path)
except tk.TclError:
pass
self.title("Windows Store Packager v2.3 (Auto-Setup)")
self.geometry("1200x1000")
# State variables
self.app_name = tk.StringVar()
self.publisher = tk.StringVar()
self.publisher_display = tk.StringVar()
self.identity_name = tk.StringVar()
self.version = tk.StringVar(value=DEFAULT_VERSION)
self.script_path = tk.StringVar()
self.icon_path = tk.StringVar()
self.source_path = tk.StringVar()
self.installer_path = tk.StringVar()
self.output_dir = tk.StringVar(value=OUTPUT_ROOT)
self.exe_name = tk.StringVar()
# MSIX build settings
self.makeappx_path = tk.StringVar()
self.signtool_path = tk.StringVar()
self.appcert_path = tk.StringVar()
self.pfx_path = tk.StringVar()
self.pfx_password = tk.StringVar()
self.timestamp_url = tk.StringVar(value="http://timestamp.digicert.com") # Note: signtool requires http://, not https://
self.msix_name = tk.StringVar()
# External Python (Recursion Fix)
self.python_path = tk.StringVar()
# Store extras
self.capabilities = tk.StringVar(value="internetClient")
self.privacy_url = tk.StringVar()
self.support_url = tk.StringVar()
self.category = tk.StringVar(value="Productivity")
self.age_rating = tk.StringVar(value="3+")
# Changelog
self.changelog_box = None
# License files
self.license_files = []
self.license_text_entries = []
# i18n toggle
self.enable_i18n = tk.BooleanVar(value=True)
# Text widgets
self.readme_box = None
self.license_box = None
self.desc_box = None
self.load_settings()
self.build_gui()
self.autodetect_sdk_tools()
# ---------- Settings ----------
def load_settings(self):
if os.path.exists(SETTINGS_FILE):
try:
with open(SETTINGS_FILE, "r", encoding="utf-8") as f:
data = json.load(f)
self.app_name.set(data.get("app_name", ""))
self.publisher.set(data.get("publisher", ""))
self.publisher_display.set(data.get("publisher_display", ""))
self.identity_name.set(data.get("identity_name", ""))
self.version.set(data.get("version", DEFAULT_VERSION))
self.script_path.set(data.get("script_path", ""))
self.icon_path.set(data.get("icon_path", ""))
self.source_path.set(data.get("source_path", ""))
self.installer_path.set(data.get("installer_path", ""))
self.output_dir.set(data.get("output_dir", OUTPUT_ROOT))
self.exe_name.set(data.get("exe_name", ""))
self.makeappx_path.set(data.get("makeappx_path", ""))
self.signtool_path.set(data.get("signtool_path", ""))
self.appcert_path.set(data.get("appcert_path", ""))
self.pfx_path.set(data.get("pfx_path", ""))
self.timestamp_url.set(data.get("timestamp_url", self.timestamp_url.get()))
self.msix_name.set(data.get("msix_name", ""))
self.python_path.set(data.get("python_path", ""))
self.license_files = data.get("license_files", [])
self.license_text_entries = data.get("license_text_entries", [])
self.enable_i18n.set(data.get("enable_i18n", True))
self.capabilities.set(data.get("capabilities", "internetClient"))
self.privacy_url.set(data.get("privacy_url", ""))
self.support_url.set(data.get("support_url", ""))
self.category.set(data.get("category", "Productivity"))
self.age_rating.set(data.get("age_rating", "3+"))
# Kein Try/Except mehr nötig, da keyring oben installiert wurde
pwd = keyring.get_password(KEYRING_SERVICE, "pfx_password")
if pwd:
self.pfx_password.set(pwd)
except Exception as e:
# Fallback für alte Settings-Files oder Keyring-Fehler
print(f"Warnung: Einstellungen konnten nicht vollständig geladen werden: {e}")
def save_settings(self):
if self.pfx_password.get():
try:
keyring.set_password(KEYRING_SERVICE, "pfx_password", self.pfx_password.get())
except Exception as e:
messagebox.showwarning("Warnung", f"Passwort konnte nicht im Keyring gespeichert werden:\n{e}")
data = {
"app_name": self.app_name.get(),
"publisher": self.publisher.get(),
"publisher_display": self.publisher_display.get(),
"identity_name": self.identity_name.get(),
"version": self.version.get(),
"script_path": self.script_path.get(),
"icon_path": self.icon_path.get(),
"source_path": self.source_path.get(),
"installer_path": self.installer_path.get(),
"output_dir": self.output_dir.get(),
"exe_name": self.exe_name.get(),
"makeappx_path": self.makeappx_path.get(),
"signtool_path": self.signtool_path.get(),
"appcert_path": self.appcert_path.get(),
"pfx_path": self.pfx_path.get(),
"timestamp_url": self.timestamp_url.get(),
"msix_name": self.msix_name.get(),
"python_path": self.python_path.get(),
"license_files": self.license_files,
"license_text_entries": self.license_text_entries,
"enable_i18n": self.enable_i18n.get(),
"capabilities": self.capabilities.get(),
"privacy_url": self.privacy_url.get(),
"support_url": self.support_url.get(),
"category": self.category.get(),
"age_rating": self.age_rating.get()
}
try:
with open(SETTINGS_FILE, "w", encoding="utf-8") as f:
json.dump(data, f, indent=2)
messagebox.showinfo("Gespeichert", "Einstellungen wurden gespeichert.")
except Exception as e:
messagebox.showerror("Fehler", f"Einstellungen konnten nicht gespeichert werden:\n{e}")
def _get_text_widget_value(self, widget):
if widget is None:
return ""
return widget.get("1.0", tk.END).strip()
def _set_text_widget_value(self, widget, value):
if widget is None:
return
widget.delete("1.0", tk.END)
if value:
widget.insert(tk.END, value)
def collect_project_profile_state(self):
return {
"app_name": self.app_name.get(),
"publisher_display": self.publisher_display.get(),
"identity_name": self.identity_name.get(),
"version": self.version.get(),
"script_path": self.script_path.get(),
"icon_path": self.icon_path.get(),
"source_path": self.source_path.get(),
"installer_path": self.installer_path.get(),
"output_dir": self.output_dir.get(),
"exe_name": self.exe_name.get(),
"privacy_url": self.privacy_url.get(),
"support_url": self.support_url.get(),
"capabilities": self.capabilities.get(),
"category": self.category.get(),
"age_rating": self.age_rating.get(),
"description": self._get_text_widget_value(self.desc_box),
"changelog": self._get_text_widget_value(self.changelog_box),
"readme": self._get_text_widget_value(self.readme_box),
"license_files": list(self.license_files),
"license_text_entries": list(self.license_text_entries),
"enable_i18n": self.enable_i18n.get(),
}
def apply_project_profile_state(self, data):
self.app_name.set(data.get("app_name", ""))
self.publisher_display.set(data.get("publisher_display", ""))
self.identity_name.set(data.get("identity_name", ""))
self.version.set(data.get("version", DEFAULT_VERSION))
self.script_path.set(data.get("script_path", ""))
self.icon_path.set(data.get("icon_path", ""))
self.source_path.set(data.get("source_path", ""))
self.installer_path.set(data.get("installer_path", ""))
self.output_dir.set(data.get("output_dir", OUTPUT_ROOT))
self.exe_name.set(data.get("exe_name", ""))
self.privacy_url.set(data.get("privacy_url", ""))
self.support_url.set(data.get("support_url", ""))
self.capabilities.set(data.get("capabilities", ""))
self.category.set(data.get("category", "Productivity"))
self.age_rating.set(data.get("age_rating", "3+"))
self.enable_i18n.set(data.get("enable_i18n", True))
self.license_files = list(data.get("license_files", []))
self.license_text_entries = list(data.get("license_text_entries", []))
self._set_text_widget_value(self.readme_box, data.get("readme", ""))
self._set_text_widget_value(self.desc_box, data.get("description", ""))
changelog = data.get("changelog", "").strip()
if not changelog:
changelog = f"Version {self.version.get()}\n- \n- \n- "
self._set_text_widget_value(self.changelog_box, changelog)
license_preview_parts = []
if self.license_files:
license_preview_parts.append("Lizenzdateien:\n" + "\n".join(self.license_files))
if self.license_text_entries:
license_preview_parts.append("\n\n".join(self.license_text_entries))
self._set_text_widget_value(self.license_box, "\n\n".join(license_preview_parts))
def export_project_profile(self):
path = filedialog.asksaveasfilename(
title="Projektprofil exportieren",
defaultextension=".json",
initialfile="winstorepackager-project-v1.json",
filetypes=[("JSON", "*.json"), ("Alle Dateien", "*.*")],
)
if not path:
return
try:
write_project_profile(path, self.collect_project_profile_state())
messagebox.showinfo(
"Projektprofil exportiert",
"Projektprofil wurde exportiert.\n\n"
"Nicht enthalten sind Publisher-ID, SDK-Pfade, Zertifikatspfade und Passwörter.",
)
except Exception as e:
messagebox.showerror("Fehler", f"Projektprofil konnte nicht exportiert werden:\n{e}")
def import_project_profile(self):
path = filedialog.askopenfilename(
title="Projektprofil importieren",
filetypes=[("JSON", "*.json"), ("Alle Dateien", "*.*")],
)
if not path:
return
try:
profile_state = read_project_profile(path)
self.apply_project_profile_state(profile_state)
messagebox.showinfo(
"Projektprofil importiert",
"Projektprofil wurde geladen.\n\n"
"Bitte Publisher-ID, SDK-Pfade und Zertifikat lokal ergänzen.",
)
except Exception as e:
messagebox.showerror("Fehler", f"Projektprofil konnte nicht importiert werden:\n{e}")
# ---------- GUI ----------
def build_gui(self):
notebook = ttk.Notebook(self)
notebook.pack(fill="both", expand=True, padx=10, pady=10)
tab1 = ttk.Frame(notebook)
notebook.add(tab1, text="Metadaten")
self.build_metadata_tab(tab1)
tab2 = ttk.Frame(notebook)
notebook.add(tab2, text="Build-Einstellungen")
self.build_build_tab(tab2)
tab3 = ttk.Frame(notebook)
notebook.add(tab3, text="Store-Informationen")
self.build_store_tab(tab3)
tab4 = ttk.Frame(notebook)
notebook.add(tab4, text="Aktionen")
self.build_actions_tab(tab4)
def build_metadata_tab(self, parent):
frm = ttk.Frame(parent)
frm.pack(fill="both", expand=True, padx=12, pady=12)
row = 0
def add_row(label, var, browse_cmd=None, width=60):
nonlocal row
ttk.Label(frm, text=label).grid(row=row, column=0, sticky="w", pady=3)
ent = ttk.Entry(frm, textvariable=var, width=width)
ent.grid(row=row, column=1, sticky="we", pady=3, padx=5)
if browse_cmd:
ttk.Button(frm, text="Wählen", command=browse_cmd).grid(row=row, column=2, sticky="w")
row += 1
add_row("App-Name:", self.app_name)
add_row("Publisher (CN=... aus Partner Center):", self.publisher)
add_row("Publisher Display Name:", self.publisher_display)
add_row("Identity Name:", self.identity_name)
add_row("Version (z.B. 1.0.0.0):", self.version)
ttk.Separator(frm, orient='horizontal').grid(row=row, column=0, columnspan=3, sticky='ew', pady=10)
row += 1
add_row("Haupt-Skript (.py):", self.script_path, self.choose_script)
add_row("Icon (PNG, mind. 310x310):", self.icon_path, self.choose_icon)
add_row("Quelltext (ZIP oder Datei):", self.source_path, self.choose_source)
add_row("Installer (EXE oder MSIX):", self.installer_path, self.choose_installer)
add_row("Ausgabeordner:", self.output_dir)
add_row("EXE-Name (z.B. MyApp.exe):", self.exe_name)
ttk.Separator(frm, orient='horizontal').grid(row=row, column=0, columnspan=3, sticky='ew', pady=10)
row += 1
ttk.Label(frm, text="README (Text oder Datei):").grid(row=row, column=0, sticky="nw", pady=5)
readme_frame = ttk.Frame(frm)
readme_frame.grid(row=row, column=1, sticky="we", pady=5, padx=5)
self.readme_box = scrolledtext.ScrolledText(readme_frame, width=70, height=5)
self.readme_box.pack(fill="both", expand=True)
ttk.Button(frm, text="Datei laden", command=self.load_readme_file).grid(row=row, column=2, sticky="nw")
row += 1
ttk.Label(frm, text="Lizenz (Text/Dateien):").grid(row=row, column=0, sticky="nw", pady=5)
license_frame = ttk.Frame(frm)
license_frame.grid(row=row, column=1, sticky="we", pady=5, padx=5)
self.license_box = scrolledtext.ScrolledText(license_frame, width=70, height=5)
self.license_box.pack(fill="both", expand=True)
lic_btns = ttk.Frame(frm)
lic_btns.grid(row=row, column=2, sticky="nw")
ttk.Button(lic_btns, text="Datei +", command=self.add_license_file).pack(anchor="w", pady=2)
ttk.Button(lic_btns, text="Text +", command=self.add_license_text_entry).pack(anchor="w", pady=2)
row += 1
ttk.Label(frm, text="Beschreibung:").grid(row=row, column=0, sticky="nw", pady=5)
desc_frame = ttk.Frame(frm)
desc_frame.grid(row=row, column=1, sticky="we", pady=5, padx=5)
self.desc_box = scrolledtext.ScrolledText(desc_frame, width=70, height=5)
self.desc_box.pack(fill="both", expand=True)
ttk.Button(frm, text="Datei laden", command=self.load_desc_file).grid(row=row, column=2, sticky="nw")
row += 1
frm.columnconfigure(1, weight=1)
def build_build_tab(self, parent):
frm = ttk.Frame(parent)
frm.pack(fill="both", expand=True, padx=12, pady=12)
row = 0
def add_row(label, var, browse_cmd=None, width=60, show=None):
nonlocal row
ttk.Label(frm, text=label).grid(row=row, column=0, sticky="w", pady=3)
ent = ttk.Entry(frm, textvariable=var, width=width, show=show)
ent.grid(row=row, column=1, sticky="we", pady=3, padx=5)
if browse_cmd:
ttk.Button(frm, text="Wählen", command=browse_cmd).grid(row=row, column=2, sticky="w")
row += 1
# NEU: Python Environment für externe Builds
ttk.Label(frm, text="Python Umgebung (für Builds)", font=("Arial", 10, "bold")).grid(row=row, column=0, columnspan=3, sticky="w", pady=(5,10))
row += 1
add_row("Python.exe Pfad:", self.python_path, self.choose_python_exe)
ttk.Label(frm, text="Wichtig, wenn dieses Tool als EXE läuft. Muss 'pip install pyinstaller' haben.", foreground="gray").grid(row=row, column=1, sticky="w")
row += 1
ttk.Separator(frm, orient='horizontal').grid(row=row, column=0, columnspan=3, sticky='ew', pady=10)
row += 1
ttk.Label(frm, text="Windows SDK Tools", font=("Arial", 10, "bold")).grid(row=row, column=0, columnspan=3, sticky="w", pady=(5,10))
row += 1
add_row("MakeAppx.exe:", self.makeappx_path, self.choose_makeappx)
add_row("SignTool.exe:", self.signtool_path, self.choose_signtool)
add_row("AppCert.exe (WACK):", self.appcert_path, self.choose_appcert)
ttk.Separator(frm, orient='horizontal').grid(row=row, column=0, columnspan=3, sticky='ew', pady=10)
row += 1
ttk.Label(frm, text="Zertifikat & Signierung", font=("Arial", 10, "bold")).grid(row=row, column=0, columnspan=3, sticky="w", pady=(5,10))
row += 1
add_row("Zertifikat (.pfx):", self.pfx_path, self.choose_pfx)
add_row("PFX Passwort:", self.pfx_password, show="*")
add_row("Timestamp URL:", self.timestamp_url)
add_row("MSIX Name:", self.msix_name)
ttk.Label(frm, text="✓ Passwort wird sicher im Keyring gespeichert", foreground="green").grid(row=row, column=1, sticky="w", pady=3)
row += 1
ttk.Separator(frm, orient='horizontal').grid(row=row, column=0, columnspan=3, sticky='ew', pady=10)
row += 1
ttk.Checkbutton(frm, text="Sprachmodul automatisch integrieren (i18n)", variable=self.enable_i18n)\
.grid(row=row, column=0, columnspan=3, sticky="w", pady=8)
row += 1
frm.columnconfigure(1, weight=1)
def build_store_tab(self, parent):
frm = ttk.Frame(parent)
frm.pack(fill="both", expand=True, padx=12, pady=12)
row = 0
def add_row(label, var, width=60):
nonlocal row
ttk.Label(frm, text=label).grid(row=row, column=0, sticky="w", pady=3)
ent = ttk.Entry(frm, textvariable=var, width=width)
ent.grid(row=row, column=1, sticky="we", pady=3, padx=5)
row += 1
ttk.Label(frm, text="Store-Pflichtfelder", font=("Arial", 10, "bold")).grid(row=row, column=0, columnspan=2, sticky="w", pady=(5,10))
row += 1
add_row("Privacy Policy URL:", self.privacy_url)
add_row("Support URL:", self.support_url)
add_row("Capabilities (Komma-getrennt):", self.capabilities)
ttk.Label(frm, text="Beispiele: internetClient, microphone, webcam, location").grid(row=row, column=1, sticky="w", pady=2)
row += 1
ttk.Separator(frm, orient='horizontal').grid(row=row, column=0, columnspan=2, sticky='ew', pady=10)
row += 1
ttk.Label(frm, text="Kategorie:").grid(row=row, column=0, sticky="w", pady=3)
cat_combo = ttk.Combobox(frm, textvariable=self.category, values=CATEGORIES, state="readonly", width=57)
cat_combo.grid(row=row, column=1, sticky="w", pady=3, padx=5)
row += 1
ttk.Label(frm, text="Altersfreigabe:").grid(row=row, column=0, sticky="w", pady=3)
age_combo = ttk.Combobox(frm, textvariable=self.age_rating, values=AGE_RATINGS, state="readonly", width=57)
age_combo.grid(row=row, column=1, sticky="w", pady=3, padx=5)
row += 1
ttk.Separator(frm, orient='horizontal').grid(row=row, column=0, columnspan=2, sticky='ew', pady=10)
row += 1
# Changelog-Generator
ttk.Label(frm, text="Changelog (Store-Listing)", font=("Arial", 10, "bold")).grid(row=row, column=0, columnspan=2, sticky="w", pady=(5,10))
row += 1
ttk.Label(frm, text="Changelog-Text:").grid(row=row, column=0, sticky="nw", pady=5)
changelog_frame = ttk.Frame(frm)
changelog_frame.grid(row=row, column=1, sticky="we", pady=5, padx=5)
self.changelog_box = scrolledtext.ScrolledText(changelog_frame, width=60, height=6)
self.changelog_box.pack(fill="both", expand=True)
self.changelog_box.insert(tk.END, f"Version {self.version.get()}\n- \n- \n- ")
row += 1
btn_frame = ttk.Frame(frm)
btn_frame.grid(row=row, column=1, sticky="w", pady=5, padx=5)
ttk.Button(btn_frame, text="Format fuer Store", command=self.format_changelog).pack(side="left", padx=2)
ttk.Button(btn_frame, text="In Zwischenablage", command=self.copy_changelog).pack(side="left", padx=2)
row += 1
frm.columnconfigure(1, weight=1)
def build_actions_tab(self, parent):
frm = ttk.Frame(parent)
frm.pack(fill="both", expand=True, padx=12, pady=12)
ttk.Label(frm, text="Build-Aktionen", font=("Arial", 12, "bold")).pack(anchor="w", pady=(5,15))
actions_frame = ttk.Frame(frm)
actions_frame.pack(fill="x", pady=5)
ttk.Button(actions_frame, text="1. Preflight-Check", command=self.preflight_check, width=25)\
.grid(row=0, column=0, padx=5, pady=5, sticky="ew")
ttk.Label(actions_frame, text="Validiert alle Pflichtfelder").grid(row=0, column=1, sticky="w", padx=10)
ttk.Button(actions_frame, text="2. Paket erzeugen", command=self.build_package, width=25)\
.grid(row=1, column=0, padx=5, pady=5, sticky="ew")
ttk.Label(actions_frame, text="Erstellt Ausgabeordner mit allen Assets").grid(row=1, column=1, sticky="w", padx=10)
ttk.Button(actions_frame, text="3. EXE bauen", command=self.build_exe, width=25)\
.grid(row=2, column=0, padx=5, pady=5, sticky="ew")
ttk.Label(actions_frame, text="PyInstaller-Build mit i18n").grid(row=2, column=1, sticky="w", padx=10)
ttk.Button(actions_frame, text="4. MSIX bauen & signieren", command=self.build_and_sign_msix, width=25)\
.grid(row=3, column=0, padx=5, pady=5, sticky="ew")
ttk.Label(actions_frame, text="Erstellt signiertes Store-Paket").grid(row=3, column=1, sticky="w", padx=10)
ttk.Separator(frm, orient='horizontal').pack(fill='x', pady=15)
ttk.Label(frm, text="Zusätzliche Aktionen", font=("Arial", 12, "bold")).pack(anchor="w", pady=(5,15))
extras_frame = ttk.Frame(frm)
extras_frame.pack(fill="x", pady=5)
ttk.Button(extras_frame, text="Screenshots erzeugen", command=self.run_screenshots, width=25)\
.grid(row=0, column=0, padx=5, pady=5, sticky="ew")
ttk.Label(extras_frame, text="Automatische Store-Screenshots").grid(row=0, column=1, sticky="w", padx=10)
ttk.Button(extras_frame, text="WACK-Test starten", command=self.run_wack_test, width=25)\
.grid(row=1, column=0, padx=5, pady=5, sticky="ew")
ttk.Label(extras_frame, text="Windows App Certification Kit").grid(row=1, column=1, sticky="w", padx=10)
ttk.Button(extras_frame, text="Ausgabeordner öffnen", command=self.open_output_folder, width=25)\
.grid(row=2, column=0, padx=5, pady=5, sticky="ew")
ttk.Label(extras_frame, text="Zeigt erstellte Dateien").grid(row=2, column=1, sticky="w", padx=10)
ttk.Button(extras_frame, text="Projektprofil exportieren", command=self.export_project_profile, width=25)\
.grid(row=3, column=0, padx=5, pady=5, sticky="ew")
ttk.Label(extras_frame, text="Export ohne Publisher- und Zertifikatsgeheimnisse").grid(row=3, column=1, sticky="w", padx=10)
ttk.Button(extras_frame, text="Projektprofil importieren", command=self.import_project_profile, width=25)\
.grid(row=4, column=0, padx=5, pady=5, sticky="ew")
ttk.Label(extras_frame, text="Lädt Web-/Desktop-Vorarbeit aus JSON").grid(row=4, column=1, sticky="w", padx=10)
ttk.Separator(frm, orient='horizontal').pack(fill='x', pady=15)
bottom_frame = ttk.Frame(frm)
bottom_frame.pack(fill="x", pady=5)
ttk.Button(bottom_frame, text="Einstellungen speichern", command=self.save_settings)\
.pack(side="left", padx=5)
ttk.Button(bottom_frame, text="Beenden", command=self.on_quit)\
.pack(side="right", padx=5)
# ---------- SDK autodetect ----------
def autodetect_sdk_tools(self):
if not self.makeappx_path.get() or not self.signtool_path.get() or not self.appcert_path.get():
mk, sg, ac = find_windows_sdk_tools()
if mk and not self.makeappx_path.get():
self.makeappx_path.set(mk)
if sg and not self.signtool_path.get():
self.signtool_path.set(sg)
if ac and not self.appcert_path.get():
self.appcert_path.set(ac)
# ---------- Logic: Determine Interpreter ----------
def get_build_interpreter(self):
"""
Ermittelt den Python-Interpreter für den Build-Prozess.
Priorität:
1. Benutzer-Einstellung (python_path)
2. System PATH (shutil.which)
3. Aktueller sys.executable (nur wenn NICHT als EXE laufend)
"""
user_path = self.python_path.get().strip()
if user_path and os.path.exists(user_path):
return user_path
system_python = shutil.which("python") or shutil.which("python3")
if system_python:
return system_python
if not getattr(sys, 'frozen', False):
return sys.executable
return None
# ---------- File Choosers ----------
def choose_python_exe(self):
path = filedialog.askopenfilename(filetypes=[("Executable", "python.exe"), ("All Files", "*.*")])
if path:
self.python_path.set(path)
def choose_script(self):
path = filedialog.askopenfilename(filetypes=[("Python Files", "*.py")])
if path:
self.script_path.set(path)
def choose_icon(self):
path = filedialog.askopenfilename(filetypes=[("PNG Files", "*.png")])
if path:
self.icon_path.set(path)
def choose_source(self):
path = filedialog.askopenfilename(filetypes=[("Source Files", "*.zip;*.py;*.txt;*.md"), ("All Files", "*.*")])
if path:
self.source_path.set(path)
def choose_installer(self):
path = filedialog.askopenfilename(filetypes=[("Installer", "*.exe;*.msix;*.msixbundle"), ("All Files", "*.*")])
if path:
self.installer_path.set(path)
def load_readme_file(self):
path = filedialog.askopenfilename(filetypes=[("Text Files", "*.txt;*.md"), ("All Files", "*.*")])
if path:
try:
with open(path, "r", encoding="utf-8") as f:
self.readme_box.delete("1.0", tk.END)
self.readme_box.insert(tk.END, f.read())
except Exception as e:
messagebox.showerror("Fehler", f"Datei konnte nicht geladen werden:\n{e}")
def load_desc_file(self):
path = filedialog.askopenfilename(filetypes=[("Text Files", "*.txt;*.md"), ("All Files", "*.*")])
if path:
try:
with open(path, "r", encoding="utf-8") as f:
self.desc_box.delete("1.0", tk.END)
self.desc_box.insert(tk.END, f.read())
except Exception as e:
messagebox.showerror("Fehler", f"Datei konnte nicht geladen werden:\n{e}")
def choose_makeappx(self):
path = filedialog.askopenfilename(filetypes=[("Executable", "*.exe"), ("All Files", "*.*")])
if path:
self.makeappx_path.set(path)
def choose_signtool(self):
path = filedialog.askopenfilename(filetypes=[("Executable", "*.exe"), ("All Files", "*.*")])
if path:
self.signtool_path.set(path)
def choose_appcert(self):
path = filedialog.askopenfilename(filetypes=[("Executable", "*.exe"), ("All Files", "*.*")])
if path:
self.appcert_path.set(path)
def choose_pfx(self):
path = filedialog.askopenfilename(filetypes=[("Certificate", "*.pfx"), ("All Files", "*.*")])
if path:
self.pfx_path.set(path)
def add_license_file(self):
path = filedialog.askopenfilename(filetypes=[("Text Files", "*.txt;*.md"), ("All Files", "*.*")])
if path:
self.license_files.append(path)
messagebox.showinfo("Lizenz hinzugefügt", f"Datei hinzugefügt:\n{path}\n\nGesamt: {len(self.license_files)} Dateien")
def add_license_text_entry(self):
txt = self.license_box.get("1.0", tk.END).strip()
if txt:
self.license_text_entries.append(txt)
self.license_box.delete("1.0", tk.END)
messagebox.showinfo("Lizenz hinzugefügt", f"Text als zusätzliche Lizenz gespeichert.\n\nGesamt: {len(self.license_text_entries)} Texteinträge")
else:
messagebox.showwarning("Hinweis", "Bitte Lizenztext eingeben und erneut klicken.")
def open_output_folder(self):
outdir = self.package_dir()
if os.path.exists(outdir):
if sys.platform == "win32":
os.startfile(outdir)
else:
subprocess.run(["xdg-open", outdir])
else:
messagebox.showwarning("Hinweis", f"Ausgabeordner existiert noch nicht:\n{outdir}")
# ---------- Helpers ----------
def build_icons(self, icon_src, icon_dir):
img = Image.open(icon_src)
os.makedirs(icon_dir, exist_ok=True)
for size in ICON_SIZES:
resized = img.resize((size, size), Image.LANCZOS)
out_path = os.path.join(icon_dir, f"icon_{size}x{size}.png")
resized.save(out_path)
wide = img.resize(WIDE_ICON_SIZE, Image.LANCZOS)
wide.save(os.path.join(icon_dir, "icon_310x150.png"))
def write_text_file(self, path, content):
if content:
with open(path, "w", encoding="utf-8") as f:
f.write(content.strip())
def package_dir(self):
appname = (self.app_name.get().strip() or "MyApp")
outdir_root = os.path.abspath(self.output_dir.get().strip() or OUTPUT_ROOT)
outdir = os.path.join(outdir_root, appname)
return outdir
# ---------- i18n integration ----------
def integrate_i18n(self, outdir, script_to_patch=None):
"""
Create i18n folder and files, and patch the given script.
"""
try:
i18n_dir = os.path.join(outdir, "i18n")
os.makedirs(os.path.join(i18n_dir, "locales"), exist_ok=True)
# translator.py - FIX: Handle frozen path
translator_code = '''import json
import os, sys
class Translator:
def __init__(self, lang="de", file_path="i18n/locales/translations.json"):
# Detect if running as PyInstaller OneFile
if hasattr(sys, '_MEIPASS'):
base_path = sys._MEIPASS
else:
base_path = os.path.abspath(".")
full_path = os.path.join(base_path, file_path)
if os.path.exists(full_path):
with open(full_path, "r", encoding="utf-8") as f:
self.translations = json.load(f)
else:
self.translations = {}
print(f"Warning: Translation file not found at {full_path}")
self.lang = lang
def set_lang(self, lang):
self.lang = lang
def t(self, key: str) -> str:
entry = self.translations.get(key)
if not entry:
return key
return entry.get(self.lang, entry.get("de", key))
'''
with open(os.path.join(i18n_dir, "translator.py"), "w", encoding="utf-8") as f:
f.write(translator_code)
# translator_patch.py
patch_code = '''import tkinter as tk
from tkinter import ttk
def patch_widgets(translator):
def wrap_factory(widget_cls):
class Wrapped(widget_cls):
def __init__(self, master=None, **kw):
if "text" in kw:
kw["text"] = translator.t(kw["text"])
super().__init__(master, **kw)
return Wrapped
tk.Label = wrap_factory(tk.Label)
ttk.Label = wrap_factory(ttk.Label)
ttk.Button = wrap_factory(ttk.Button)
ttk.Checkbutton = wrap_factory(ttk.Checkbutton)
ttk.Radiobutton = wrap_factory(ttk.Radiobutton)
'''
with open(os.path.join(i18n_dir, "translator_patch.py"), "w", encoding="utf-8") as f:
f.write(patch_code)
# translations.json
translations = {
"Sprache": {"de": "Sprache", "en": "Language"},
"Deutsch": {"de": "Deutsch", "en": "German"},
"English": {"de": "Englisch", "en": "English"},
"Wählen": {"de": "Wählen", "en": "Choose"},
"Beenden": {"de": "Beenden", "en": "Quit"},
"Öffnen": {"de": "Öffnen", "en": "Open"},
"Speichern": {"de": "Speichern", "en": "Save"},
"Abbrechen": {"de": "Abbrechen", "en": "Cancel"},
"OK": {"de": "OK", "en": "OK"},
"Fehler": {"de": "Fehler", "en": "Error"},
"Warnung": {"de": "Warnung", "en": "Warning"},
"Info": {"de": "Info", "en": "Info"}
}
with open(os.path.join(i18n_dir, "locales", "translations.json"), "w", encoding="utf-8") as f:
json.dump(translations, f, indent=2, ensure_ascii=False)
# Patch the staged script
if script_to_patch and os.path.isfile(script_to_patch):
with open(script_to_patch, "r", encoding="utf-8") as f:
code = f.read()
needs_import = ("from i18n.translator import Translator" not in code)
needs_enable = ("patch_widgets(" not in code)
class_regex = r"(\nclass\s+\w+(?:\(.*\))?:)"
if needs_import:
if re.search(class_regex, code):
code = re.sub(
class_regex,
"\nfrom i18n.translator import Translator\nfrom i18n.translator_patch import patch_widgets\\1",
code,
count=1
)
else:
code = f"from i18n.translator import Translator\nfrom i18n.translator_patch import patch_widgets\n{code}"
if needs_enable:
if re.search(r"(super\(\)\.__init__\(\))", code):
code = re.sub(