-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstaller.py
More file actions
1134 lines (1034 loc) · 50.9 KB
/
installer.py
File metadata and controls
1134 lines (1034 loc) · 50.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
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
"""PDFApps — Cross-platform Installer (Windows / macOS / Linux)"""
import os, sys, shutil, subprocess, threading, urllib.request, time, locale, hashlib, hmac
import tkinter as tk
from tkinter import ttk, filedialog, messagebox
APP_NAME = "PDFApps"
APP_VERSION = "1.13.9"
BG = "#FFFFFF"
HEADER_BG = "#1E3A5F"
ACCENT = "#3B82F6"
TEXT = "#1E293B"
TEXT_L = "#64748B"
# ── i18n ──────────────────────────────────────────────────────────────────────
_INSTALLER_STRINGS = {
"en": {
"loading": "Loading…",
"title": "Install {app} {ver}",
"folder": "Installation folder:",
"browse": " Browse ",
"desktop": "Create Desktop shortcut",
"startmenu": "Create Start Menu shortcut",
"appmenu": "Register in application menu",
"ocr": "Install OCR engine — Tesseract",
"gs": "Install compression engine — Ghostscript (better PDF compression)",
"tess_ok": "Tesseract already installed.",
"gs_ok": "Ghostscript already installed.",
"ready": "Ready to install.",
"install": " Install ",
"installing": " Installing… ",
"cancel": " Cancel ",
"finish": " Finish ",
"creating_folder": "Creating installation folder…",
"copying_app": "Copying {app}…",
"copying_files": "Copying files…",
"creating_bundle": "Creating .app bundle…",
"desktop_shortcut": "Creating Desktop shortcut…",
"startmenu_shortcut": "Creating Start Menu shortcut…",
"registering_menu": "Registering in application menu…",
"registering": "Registering in the system…",
"complete": "Installation complete!",
"done_title": "Installation complete",
"done_msg": "{app} was installed successfully at:\n{path}\n\nOpen now?",
"dl_tesseract": "Downloading Tesseract OCR (~6 MB)…",
"inst_tesseract": "Installing Tesseract OCR…",
"inst_tess_brew": "Installing Tesseract via Homebrew…",
"inst_tess_pkg": "Installing Tesseract via package manager…",
"dl_lang": "Downloading OCR language: {lang} (~15 MB)…",
"dl_gs": "Downloading Ghostscript (~35 MB)…",
"inst_gs": "Installing Ghostscript…",
"inst_gs_brew": "Installing Ghostscript via Homebrew…",
"inst_gs_pkg": "Installing Ghostscript via package manager…",
"verify_failed": "Download verification failed for {name} — file may be corrupted or tampered with.",
"banner_title": "Install {app} {ver}",
"banner_subtitle": "Choose your installation options below.",
"status_label": "Status:",
},
"pt": {
"loading": "A carregar…",
"title": "Instalar {app} {ver}",
"folder": "Pasta de instalação:",
"browse": " Procurar ",
"desktop": "Criar atalho no Ambiente de Trabalho",
"startmenu": "Criar atalho no Menu Iniciar",
"appmenu": "Registar no menu de aplicações",
"ocr": "Instalar motor OCR — Tesseract",
"gs": "Instalar motor de compressão — Ghostscript (melhor compressão PDF)",
"tess_ok": "Tesseract já instalado.",
"gs_ok": "Ghostscript já instalado.",
"ready": "Pronto para instalar.",
"install": " Instalar ",
"installing": " A instalar… ",
"cancel": " Cancelar ",
"finish": " Concluir ",
"creating_folder": "A criar pasta de instalação…",
"copying_app": "A copiar {app}…",
"copying_files": "A copiar ficheiros…",
"creating_bundle": "A criar pacote .app…",
"desktop_shortcut": "A criar atalho no Ambiente de Trabalho…",
"startmenu_shortcut": "A criar atalho no Menu Iniciar…",
"registering_menu": "A registar no menu de aplicações…",
"registering": "A registar no sistema…",
"complete": "Instalação concluída!",
"done_title": "Instalação concluída",
"done_msg": "{app} foi instalado com sucesso em:\n{path}\n\nAbrir agora?",
"dl_tesseract": "A transferir Tesseract OCR (~6 MB)…",
"inst_tesseract": "A instalar Tesseract OCR…",
"inst_tess_brew": "A instalar Tesseract via Homebrew…",
"inst_tess_pkg": "A instalar Tesseract via gestor de pacotes…",
"dl_lang": "A transferir idioma OCR: {lang} (~15 MB)…",
"dl_gs": "A transferir Ghostscript (~35 MB)…",
"inst_gs": "A instalar Ghostscript…",
"inst_gs_brew": "A instalar Ghostscript via Homebrew…",
"inst_gs_pkg": "A instalar Ghostscript via gestor de pacotes…",
"verify_failed": "Verificação do download falhou para {name} — o ficheiro pode estar corrompido ou alterado.",
"banner_title": "Instalar {app} {ver}",
"banner_subtitle": "Escolhe as opções de instalação abaixo.",
"status_label": "Estado:",
},
"es": {
"loading": "Cargando…",
"title": "Instalar {app} {ver}",
"folder": "Carpeta de instalación:",
"browse": " Examinar ",
"desktop": "Crear acceso directo en el Escritorio",
"startmenu": "Crear acceso directo en el Menú Inicio",
"appmenu": "Registrar en el menú de aplicaciones",
"ocr": "Instalar motor OCR — Tesseract",
"gs": "Instalar motor de compresión — Ghostscript (mejor compresión PDF)",
"tess_ok": "Tesseract ya instalado.",
"gs_ok": "Ghostscript ya instalado.",
"ready": "Listo para instalar.",
"install": " Instalar ",
"installing": " Instalando… ",
"cancel": " Cancelar ",
"finish": " Finalizar ",
"creating_folder": "Creando carpeta de instalación…",
"copying_app": "Copiando {app}…",
"copying_files": "Copiando archivos…",
"creating_bundle": "Creando paquete .app…",
"desktop_shortcut": "Creando acceso directo en el Escritorio…",
"startmenu_shortcut": "Creando acceso directo en el Menú Inicio…",
"registering_menu": "Registrando en el menú de aplicaciones…",
"registering": "Registrando en el sistema…",
"complete": "¡Instalación completada!",
"done_title": "Instalación completada",
"done_msg": "{app} se instaló correctamente en:\n{path}\n\n¿Abrir ahora?",
"dl_tesseract": "Descargando Tesseract OCR (~6 MB)…",
"inst_tesseract": "Instalando Tesseract OCR…",
"inst_tess_brew": "Instalando Tesseract via Homebrew…",
"inst_tess_pkg": "Instalando Tesseract via gestor de paquetes…",
"dl_lang": "Descargando idioma OCR: {lang} (~15 MB)…",
"dl_gs": "Descargando Ghostscript (~35 MB)…",
"inst_gs": "Instalando Ghostscript…",
"inst_gs_brew": "Instalando Ghostscript via Homebrew…",
"inst_gs_pkg": "Instalando Ghostscript via gestor de paquetes…",
"verify_failed": "La verificación de la descarga falló para {name} — el archivo puede estar dañado o alterado.",
"banner_title": "Instalar {app} {ver}",
"banner_subtitle": "Elige las opciones de instalación a continuación.",
"status_label": "Estado:",
},
"fr": {
"loading": "Chargement…",
"title": "Installer {app} {ver}",
"folder": "Dossier d'installation :",
"browse": " Parcourir ",
"desktop": "Créer un raccourci sur le Bureau",
"startmenu": "Créer un raccourci dans le Menu Démarrer",
"appmenu": "Enregistrer dans le menu des applications",
"ocr": "Installer le moteur OCR — Tesseract",
"gs": "Installer le moteur de compression — Ghostscript (meilleure compression PDF)",
"tess_ok": "Tesseract déjà installé.",
"gs_ok": "Ghostscript déjà installé.",
"ready": "Prêt à installer.",
"install": " Installer ",
"installing": " Installation… ",
"cancel": " Annuler ",
"finish": " Terminer ",
"creating_folder": "Création du dossier d'installation…",
"copying_app": "Copie de {app}…",
"copying_files": "Copie des fichiers…",
"creating_bundle": "Création du paquet .app…",
"desktop_shortcut": "Création du raccourci Bureau…",
"startmenu_shortcut": "Création du raccourci Menu Démarrer…",
"registering_menu": "Enregistrement dans le menu des applications…",
"registering": "Enregistrement dans le système…",
"complete": "Installation terminée !",
"done_title": "Installation terminée",
"done_msg": "{app} a été installé avec succès dans :\n{path}\n\nOuvrir maintenant ?",
"dl_tesseract": "Téléchargement de Tesseract OCR (~6 Mo)…",
"inst_tesseract": "Installation de Tesseract OCR…",
"inst_tess_brew": "Installation de Tesseract via Homebrew…",
"inst_tess_pkg": "Installation de Tesseract via le gestionnaire de paquets…",
"dl_lang": "Téléchargement de la langue OCR : {lang} (~15 Mo)…",
"dl_gs": "Téléchargement de Ghostscript (~35 Mo)…",
"inst_gs": "Installation de Ghostscript…",
"inst_gs_brew": "Installation de Ghostscript via Homebrew…",
"inst_gs_pkg": "Installation de Ghostscript via le gestionnaire de paquets…",
"verify_failed": "Échec de la vérification du téléchargement pour {name} — le fichier peut être corrompu ou altéré.",
"banner_title": "Installer {app} {ver}",
"banner_subtitle": "Choisissez les options d'installation ci-dessous.",
"status_label": "Statut :",
},
"de": {
"loading": "Laden…",
"title": "{app} {ver} installieren",
"folder": "Installationsordner:",
"browse": " Durchsuchen ",
"desktop": "Desktopverknüpfung erstellen",
"startmenu": "Startmenüverknüpfung erstellen",
"appmenu": "Im Anwendungsmenü registrieren",
"ocr": "OCR-Engine installieren — Tesseract",
"gs": "Komprimierungs-Engine installieren — Ghostscript (bessere PDF-Komprimierung)",
"tess_ok": "Tesseract bereits installiert.",
"gs_ok": "Ghostscript bereits installiert.",
"ready": "Bereit zur Installation.",
"install": " Installieren ",
"installing": " Wird installiert… ",
"cancel": " Abbrechen ",
"finish": " Fertig ",
"creating_folder": "Installationsordner wird erstellt…",
"copying_app": "{app} wird kopiert…",
"copying_files": "Dateien werden kopiert…",
"creating_bundle": ".app-Paket wird erstellt…",
"desktop_shortcut": "Desktopverknüpfung wird erstellt…",
"startmenu_shortcut": "Startmenüverknüpfung wird erstellt…",
"registering_menu": "Im Anwendungsmenü registrieren…",
"registering": "Im System registrieren…",
"complete": "Installation abgeschlossen!",
"done_title": "Installation abgeschlossen",
"done_msg": "{app} wurde erfolgreich installiert in:\n{path}\n\nJetzt öffnen?",
"dl_tesseract": "Tesseract OCR wird heruntergeladen (~6 MB)…",
"inst_tesseract": "Tesseract OCR wird installiert…",
"inst_tess_brew": "Tesseract wird über Homebrew installiert…",
"inst_tess_pkg": "Tesseract wird über Paketmanager installiert…",
"dl_lang": "OCR-Sprache wird heruntergeladen: {lang} (~15 MB)…",
"dl_gs": "Ghostscript wird heruntergeladen (~35 MB)…",
"inst_gs": "Ghostscript wird installiert…",
"inst_gs_brew": "Ghostscript wird über Homebrew installiert…",
"inst_gs_pkg": "Ghostscript wird über Paketmanager installiert…",
"verify_failed": "Download-Überprüfung fehlgeschlagen für {name} — die Datei könnte beschädigt oder manipuliert sein.",
"banner_title": "{app} {ver} installieren",
"banner_subtitle": "Wähle die Installationsoptionen unten.",
"status_label": "Status:",
},
"zh": {
"loading": "加载中…",
"title": "安装 {app} {ver}",
"folder": "安装文件夹:",
"browse": " 浏览 ",
"desktop": "创建桌面快捷方式",
"startmenu": "创建开始菜单快捷方式",
"appmenu": "注册到应用程序菜单",
"ocr": "安装 OCR 引擎 — Tesseract",
"gs": "安装压缩引擎 — Ghostscript(更好的 PDF 压缩)",
"tess_ok": "Tesseract 已安装。",
"gs_ok": "Ghostscript 已安装。",
"ready": "准备安装。",
"install": " 安装 ",
"installing": " 正在安装… ",
"cancel": " 取消 ",
"finish": " 完成 ",
"creating_folder": "正在创建安装文件夹…",
"copying_app": "正在复制 {app}…",
"copying_files": "正在复制文件…",
"creating_bundle": "正在创建 .app 包…",
"desktop_shortcut": "正在创建桌面快捷方式…",
"startmenu_shortcut": "正在创建开始菜单快捷方式…",
"registering_menu": "正在注册到应用程序菜单…",
"registering": "正在注册到系统…",
"complete": "安装完成!",
"done_title": "安装完成",
"done_msg": "{app} 已成功安装到:\n{path}\n\n现在打开?",
"dl_tesseract": "正在下载 Tesseract OCR (~6 MB)…",
"inst_tesseract": "正在安装 Tesseract OCR…",
"inst_tess_brew": "正在通过 Homebrew 安装 Tesseract…",
"inst_tess_pkg": "正在通过包管理器安装 Tesseract…",
"dl_lang": "正在下载 OCR 语言:{lang} (~15 MB)…",
"dl_gs": "正在下载 Ghostscript (~35 MB)…",
"inst_gs": "正在安装 Ghostscript…",
"inst_gs_brew": "正在通过 Homebrew 安装 Ghostscript…",
"inst_gs_pkg": "正在通过包管理器安装 Ghostscript…",
"verify_failed": "{name} 下载校验失败 — 文件可能已损坏或被篡改。",
"banner_title": "安装 {app} {ver}",
"banner_subtitle": "请在下方选择安装选项。",
"status_label": "状态:",
},
"it": {
"loading": "Caricamento…",
"title": "Installa {app} {ver}",
"folder": "Cartella di installazione:",
"browse": " Sfoglia ",
"desktop": "Crea collegamento sul Desktop",
"startmenu": "Crea collegamento nel Menu Start",
"appmenu": "Registra nel menu applicazioni",
"ocr": "Installa motore OCR — Tesseract",
"gs": "Installa motore di compressione — Ghostscript (migliore compressione PDF)",
"tess_ok": "Tesseract già installato.",
"gs_ok": "Ghostscript già installato.",
"ready": "Pronto per l'installazione.",
"install": " Installa ",
"installing": " Installazione… ",
"cancel": " Annulla ",
"finish": " Fine ",
"creating_folder": "Creazione cartella di installazione…",
"copying_app": "Copia di {app}…",
"copying_files": "Copia dei file…",
"creating_bundle": "Creazione pacchetto .app…",
"desktop_shortcut": "Creazione collegamento Desktop…",
"startmenu_shortcut": "Creazione collegamento Menu Start…",
"registering_menu": "Registrazione nel menu applicazioni…",
"registering": "Registrazione nel sistema…",
"complete": "Installazione completata!",
"done_title": "Installazione completata",
"done_msg": "{app} è stato installato con successo in:\n{path}\n\nAprire ora?",
"dl_tesseract": "Download di Tesseract OCR (~6 MB)…",
"inst_tesseract": "Installazione di Tesseract OCR…",
"inst_tess_brew": "Installazione di Tesseract via Homebrew…",
"inst_tess_pkg": "Installazione di Tesseract via gestore pacchetti…",
"dl_lang": "Download lingua OCR: {lang} (~15 MB)…",
"dl_gs": "Download di Ghostscript (~35 MB)…",
"inst_gs": "Installazione di Ghostscript…",
"inst_gs_brew": "Installazione di Ghostscript via Homebrew…",
"inst_gs_pkg": "Installazione di Ghostscript via gestore pacchetti…",
"verify_failed": "Verifica del download fallita per {name} — il file potrebbe essere danneggiato o alterato.",
"banner_title": "Installa {app} {ver}",
"banner_subtitle": "Scegli le opzioni di installazione qui sotto.",
"status_label": "Stato:",
},
"nl": {
"loading": "Laden…",
"title": "{app} {ver} installeren",
"folder": "Installatiemap:",
"browse": " Bladeren ",
"desktop": "Snelkoppeling op bureaublad maken",
"startmenu": "Snelkoppeling in Startmenu maken",
"appmenu": "Registreren in toepassingsmenu",
"ocr": "OCR-engine installeren — Tesseract",
"gs": "Compressie-engine installeren — Ghostscript (betere PDF-compressie)",
"tess_ok": "Tesseract al geïnstalleerd.",
"gs_ok": "Ghostscript al geïnstalleerd.",
"ready": "Klaar om te installeren.",
"install": " Installeren ",
"installing": " Bezig met installeren… ",
"cancel": " Annuleren ",
"finish": " Voltooien ",
"creating_folder": "Installatiemap aanmaken…",
"copying_app": "{app} kopiëren…",
"copying_files": "Bestanden kopiëren…",
"creating_bundle": ".app-pakket aanmaken…",
"desktop_shortcut": "Bureaublad-snelkoppeling aanmaken…",
"startmenu_shortcut": "Startmenu-snelkoppeling aanmaken…",
"registering_menu": "Registreren in toepassingsmenu…",
"registering": "Registreren in het systeem…",
"complete": "Installatie voltooid!",
"done_title": "Installatie voltooid",
"done_msg": "{app} is succesvol geïnstalleerd in:\n{path}\n\nNu openen?",
"dl_tesseract": "Tesseract OCR downloaden (~6 MB)…",
"inst_tesseract": "Tesseract OCR installeren…",
"inst_tess_brew": "Tesseract installeren via Homebrew…",
"inst_tess_pkg": "Tesseract installeren via pakketbeheerder…",
"dl_lang": "OCR-taal downloaden: {lang} (~15 MB)…",
"dl_gs": "Ghostscript downloaden (~35 MB)…",
"inst_gs": "Ghostscript installeren…",
"inst_gs_brew": "Ghostscript installeren via Homebrew…",
"inst_gs_pkg": "Ghostscript installeren via pakketbeheerder…",
"verify_failed": "Download-verificatie mislukt voor {name} — het bestand is mogelijk beschadigd of gemanipuleerd.",
"banner_title": "{app} {ver} installeren",
"banner_subtitle": "Kies hieronder de installatie-opties.",
"status_label": "Status:",
},
}
def _detect_lang() -> str:
try:
if sys.platform == "win32":
import ctypes
lang_id = ctypes.windll.kernel32.GetUserDefaultUILanguage()
primary = lang_id & 0x03FF
_map = {0x16: "pt", 0x0A: "es", 0x0C: "fr", 0x07: "de",
0x04: "zh", 0x10: "it", 0x13: "nl"}
lang = _map.get(primary)
if lang:
return lang
loc = locale.getlocale()[0] or ""
for code in ("pt", "es", "fr", "de", "zh", "it", "nl"):
if loc.startswith(code):
return code
except Exception:
pass
return "en"
_LANG = _detect_lang()
# Close PyInstaller splash and show animated tkinter splash
try:
import pyi_splash
pyi_splash.close()
except ImportError:
pass
_loading_text = _INSTALLER_STRINGS.get(_LANG, {}).get("loading", "Loading…").rstrip("…").rstrip(".")
def _show_loading_splash(root: tk.Tk):
"""Show a small centered splash with animated dots while the main UI builds."""
splash = tk.Toplevel(root)
splash.overrideredirect(True)
splash.configure(bg="#1E3A5F")
sw, sh = 400, 200
x = (root.winfo_screenwidth() - sw) // 2
y = (root.winfo_screenheight() - sh) // 2
splash.geometry(f"{sw}x{sh}+{x}+{y}")
splash.attributes("-topmost", True)
tk.Label(splash, text="PDFApps", bg="#1E3A5F", fg="#FFFFFF",
font=("Segoe UI", 28, "bold")).pack(pady=(40, 10))
line = tk.Frame(splash, bg="#3B82F6", height=3, width=160)
line.pack(pady=(0, 20))
loading_var = tk.StringVar(value=_loading_text + ".")
tk.Label(splash, textvariable=loading_var, bg="#1E3A5F", fg="#94A3B8",
font=("Segoe UI", 11)).pack()
splash._dots = 1
splash._loading_var = loading_var
def _animate():
try:
splash._dots = (splash._dots % 3) + 1
loading_var.set(_loading_text + "." * splash._dots)
splash.after(400, _animate)
except Exception:
pass
splash.after(400, _animate)
splash.update()
return splash
def _t(key: str, **kwargs) -> str:
val = _INSTALLER_STRINGS.get(_LANG, {}).get(key)
if val is None:
val = _INSTALLER_STRINGS["en"].get(key, key)
if kwargs:
try:
return val.format(**kwargs)
except Exception:
return val
return val
# ── Platform constants ─────────────────────────────────────────────────
if sys.platform == "win32":
TESSERACT_EXE = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
TESSDATA_DIR = r"C:\Program Files\Tesseract-OCR\tessdata"
TESSERACT_URL = (
"https://github.com/UB-Mannheim/tesseract/releases/download/"
"v5.4.0.20240606/tesseract-ocr-w64-setup-5.4.0.20240606.exe"
)
# Pinned SHA256 of the installer above. If the URL/version changes,
# recompute via: python -c "import urllib.request,hashlib;print(hashlib.sha256(urllib.request.urlopen(URL).read()).hexdigest())"
TESSERACT_SHA256 = "c885fff6998e0608ba4bb8ab51436e1c6775c2bafc2559a19b423e18678b60c9"
elif sys.platform == "darwin":
TESSERACT_EXE = shutil.which("tesseract") or "/opt/homebrew/bin/tesseract"
TESSDATA_DIR = "/opt/homebrew/share/tessdata"
TESSERACT_URL = None
TESSERACT_SHA256 = None
else:
TESSERACT_EXE = shutil.which("tesseract") or "/usr/bin/tesseract"
TESSDATA_DIR = "/usr/share/tesseract-ocr/5/tessdata"
TESSERACT_URL = None
TESSERACT_SHA256 = None
LANG_PACKS = ["eng", "por"]
# ── Ghostscript constants ─────────────────────────────────────────────
if sys.platform == "win32":
# Bumped from 10.05.0 → 10.07.0 to clear 4 medium-severity CVEs
# affecting gs ≤10.05.1: CVE-2025-48708 (password leak in created
# PDFs), CVE-2025-59798 / 59799 (stack buffer overflow in
# pdf_write_cmap / pdfmark_coerce_dest), CVE-2025-59800 (integer →
# heap overflow in ocr_begin_page). NVD confirms 10.07.0 has zero
# known CVEs as of 2026-05.
GHOSTSCRIPT_EXE = r"C:\Program Files\gs\gs10.07.0\bin\gswin64c.exe"
GHOSTSCRIPT_URL = (
"https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/"
"gs10070/gs10070w64.exe"
)
GHOSTSCRIPT_SHA256 = "8af854e2d62f9a3a674331321b347118a83928a3726631e458194121cf3bbeec"
elif sys.platform == "darwin":
GHOSTSCRIPT_EXE = shutil.which("gs") or "/opt/homebrew/bin/gs"
GHOSTSCRIPT_URL = None
GHOSTSCRIPT_SHA256 = None
else:
GHOSTSCRIPT_EXE = shutil.which("gs") or "/usr/bin/gs"
GHOSTSCRIPT_URL = None
GHOSTSCRIPT_SHA256 = None
def resource(rel: str) -> str:
base = getattr(sys, "_MEIPASS", os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base, rel)
def default_dir() -> str:
if sys.platform == "win32":
pf = os.environ.get("ProgramFiles", r"C:\Program Files")
return os.path.join(pf, APP_NAME)
elif sys.platform == "darwin":
return os.path.expanduser(f"~/Applications/{APP_NAME}.app")
else:
return os.path.expanduser(f"~/.local/opt/{APP_NAME}")
def open_file(path: str) -> None:
"""Open a file with the default application, cross-platform."""
if sys.platform == "win32":
os.startfile(path)
elif sys.platform == "darwin":
subprocess.Popen(["open", path])
else:
subprocess.Popen([path])
def _no_window():
"""Flags to hide console window (Windows only)."""
return {"creationflags": 0x08000000} if sys.platform == "win32" else {}
# ── Shortcuts / launchers ───────────────────────────────────────────────────────
def create_shortcut_windows(target: str, lnk: str) -> None:
# Validate paths before interpolation
if not os.path.isabs(target) or not os.path.isabs(lnk):
raise ValueError("Shortcut paths must be absolute")
t_safe = target.replace("'", "''")
l_safe = lnk.replace("'", "''")
ps = (
f"$s=(New-Object -COM WScript.Shell).CreateShortcut('{l_safe}');"
f"$s.TargetPath='{t_safe}';$s.IconLocation='{t_safe}';$s.Save()"
)
subprocess.run(
["powershell", "-NoProfile", "-NonInteractive", "-Command", ps],
capture_output=True, **_no_window()
)
def create_desktop_entry_linux(exe: str, desktop_file: str) -> None:
icon = os.path.join(os.path.dirname(exe), "icon.png")
content = (
"[Desktop Entry]\n"
"Type=Application\n"
f"Name={APP_NAME}\n"
"Comment=PDF editor and viewer\n"
f"Exec={exe} %f\n"
f"Icon={icon}\n"
"Terminal=false\n"
"Categories=Office;Graphics;\n"
"MimeType=application/pdf;\n"
)
os.makedirs(os.path.dirname(desktop_file), exist_ok=True)
with open(desktop_file, "w") as f:
f.write(content)
os.chmod(desktop_file, 0o644)
def create_app_bundle_macos(exe: str, app_dir: str) -> None:
"""Create minimal .app structure for macOS."""
contents = os.path.join(app_dir, "Contents", "MacOS")
os.makedirs(contents, exist_ok=True)
launcher = os.path.join(contents, APP_NAME)
shutil.copy2(exe, launcher)
os.chmod(launcher, 0o755)
icns_src = os.path.join(os.path.dirname(exe), "icon.icns")
resources = os.path.join(app_dir, "Contents", "Resources")
if os.path.isfile(icns_src):
os.makedirs(resources, exist_ok=True)
shutil.copy2(icns_src, os.path.join(resources, "icon.icns"))
plist = (
'<?xml version="1.0" encoding="UTF-8"?>\n'
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" '
'"http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n'
'<plist version="1.0"><dict>\n'
f' <key>CFBundleName</key><string>{APP_NAME}</string>\n'
f' <key>CFBundleExecutable</key><string>{APP_NAME}</string>\n'
' <key>CFBundleIdentifier</key><string>com.pdfapps.app</string>\n'
f' <key>CFBundleVersion</key><string>{APP_VERSION}</string>\n'
' <key>CFBundleIconFile</key><string>icon</string>\n'
' <key>LSMinimumSystemVersion</key><string>10.14</string>\n'
' <key>NSHighResolutionCapable</key><true/>\n'
' <key>CFBundleDocumentTypes</key><array><dict>\n'
' <key>CFBundleTypeName</key><string>PDF Document</string>\n'
' <key>CFBundleTypeRole</key><string>Editor</string>\n'
' <key>LSItemContentTypes</key><array>'
'<string>com.adobe.pdf</string></array>\n'
' </dict></array>\n'
'</dict></plist>\n'
)
with open(os.path.join(app_dir, "Contents", "Info.plist"), "w") as f:
f.write(plist)
# ── File associations ───────────────────────────────────────────────────
def register_file_association(app_exe: str) -> None:
if sys.platform == "win32":
_register_file_association_win(app_exe)
elif sys.platform == "linux":
_register_file_association_linux(app_exe)
def _register_file_association_win(app_exe: str) -> None:
import winreg
prog_id = "PDFApps.Document"
try:
with winreg.CreateKey(winreg.HKEY_CURRENT_USER,
rf"Software\Classes\{prog_id}") as k:
winreg.SetValueEx(k, "", 0, winreg.REG_SZ, "PDF Document")
with winreg.CreateKey(winreg.HKEY_CURRENT_USER,
rf"Software\Classes\{prog_id}\DefaultIcon") as k:
winreg.SetValueEx(k, "", 0, winreg.REG_SZ, f'"{app_exe}",0')
with winreg.CreateKey(winreg.HKEY_CURRENT_USER,
rf"Software\Classes\{prog_id}\shell\open\command") as k:
winreg.SetValueEx(k, "", 0, winreg.REG_SZ, f'"{app_exe}" "%1"')
with winreg.CreateKey(winreg.HKEY_CURRENT_USER,
r"Software\Classes\.pdf\OpenWithProgids") as k:
winreg.SetValueEx(k, prog_id, 0, winreg.REG_NONE, b"")
cap_key = r"Software\PDFApps\Capabilities"
with winreg.CreateKey(winreg.HKEY_CURRENT_USER, cap_key) as k:
winreg.SetValueEx(k, "ApplicationName", 0, winreg.REG_SZ, APP_NAME)
winreg.SetValueEx(k, "ApplicationDescription", 0, winreg.REG_SZ,
"PDF editor and viewer")
with winreg.CreateKey(winreg.HKEY_CURRENT_USER,
cap_key + r"\FileAssociations") as k:
winreg.SetValueEx(k, ".pdf", 0, winreg.REG_SZ, prog_id)
with winreg.CreateKey(winreg.HKEY_CURRENT_USER,
r"Software\RegisteredApplications") as k:
winreg.SetValueEx(k, APP_NAME, 0, winreg.REG_SZ, cap_key)
subprocess.run(["ie4uinit.exe", "-show"],
capture_output=True, **_no_window())
except Exception:
pass
def _register_file_association_linux(app_exe: str) -> None:
try:
subprocess.run(
["xdg-mime", "default", f"{APP_NAME}.desktop", "application/pdf"],
capture_output=True
)
subprocess.run(["update-desktop-database",
os.path.expanduser("~/.local/share/applications")],
capture_output=True)
except Exception:
pass
def register_uninstall(install_dir: str, uninstall_exe: str) -> None:
if sys.platform != "win32":
return
import winreg
key = r"Software\Microsoft\Windows\CurrentVersion\Uninstall\PDFApps"
try:
with winreg.CreateKey(winreg.HKEY_CURRENT_USER, key) as k:
winreg.SetValueEx(k, "DisplayName", 0, winreg.REG_SZ, APP_NAME)
winreg.SetValueEx(k, "UninstallString", 0, winreg.REG_SZ, f'"{uninstall_exe}"')
winreg.SetValueEx(k, "QuietUninstallString", 0, winreg.REG_SZ, f'"{uninstall_exe}" /silent')
winreg.SetValueEx(k, "InstallLocation", 0, winreg.REG_SZ, install_dir)
winreg.SetValueEx(k, "DisplayIcon", 0, winreg.REG_SZ,
os.path.join(install_dir, "PDFApps.exe") + ",0")
winreg.SetValueEx(k, "Publisher", 0, winreg.REG_SZ, APP_NAME)
winreg.SetValueEx(k, "DisplayVersion", 0, winreg.REG_SZ, APP_VERSION)
winreg.SetValueEx(k, "NoModify", 0, winreg.REG_DWORD, 1)
winreg.SetValueEx(k, "NoRepair", 0, winreg.REG_DWORD, 1)
except Exception:
pass
# ── Tesseract ─────────────────────────────────────────────────────────────────
def tesseract_installed() -> bool:
return os.path.isfile(TESSERACT_EXE) or bool(shutil.which("tesseract"))
def download_file(url: str, dest: str, on_progress=None,
expected_sha256: str | None = None,
asset_name: str = "") -> None:
"""Download URL to dest. If expected_sha256 is set, verify the SHA256
of the written file using a constant-time compare; on mismatch, delete
the file and raise RuntimeError. Refuses to proceed for executables
that should be hash-pinned but aren't."""
h = hashlib.sha256() if expected_sha256 else None
with urllib.request.urlopen(url, timeout=60) as resp:
total = int(resp.headers.get("Content-Length", 0))
downloaded = 0
with open(dest, "wb") as f:
while True:
chunk = resp.read(65536)
if not chunk:
break
f.write(chunk)
if h is not None:
h.update(chunk)
downloaded += len(chunk)
if on_progress and total:
on_progress(downloaded / total)
if expected_sha256 is not None:
actual = h.hexdigest()
if not hmac.compare_digest(actual.lower(), expected_sha256.lower()):
try:
os.remove(dest)
except OSError:
pass
raise RuntimeError(_t("verify_failed", name=asset_name or os.path.basename(dest)))
def install_tesseract_windows(step_fn) -> None:
import tempfile
temp = tempfile.gettempdir()
installer = os.path.join(temp, "tesseract_setup.exe")
step_fn(_t("dl_tesseract"), 42)
download_file(TESSERACT_URL, installer,
expected_sha256=TESSERACT_SHA256, asset_name="Tesseract OCR")
step_fn(_t("inst_tesseract"), 52)
subprocess.run([installer, "/S"], check=True)
for _ in range(30):
if os.path.isfile(TESSERACT_EXE):
break
time.sleep(1)
try:
os.remove(installer)
except Exception:
pass
def install_tesseract_macos(step_fn) -> None:
step_fn(_t("inst_tess_brew"), 42)
if not shutil.which("brew"):
raise RuntimeError(
"Homebrew not found.\n"
"Install at https://brew.sh then run:\n"
"brew install tesseract tesseract-lang"
)
subprocess.run(["brew", "install", "tesseract", "tesseract-lang"], check=True)
def install_tesseract_linux(step_fn) -> None:
step_fn(_t("inst_tess_pkg"), 42)
pkg_manager = None
for pm in [("apt-get", ["-y", "install", "tesseract-ocr",
"tesseract-ocr-por", "tesseract-ocr-eng"]),
("dnf", ["-y", "install", "tesseract", "tesseract-langpack-por",
"tesseract-langpack-eng"]),
("pacman", ["-S", "--noconfirm", "tesseract",
"tesseract-data-por", "tesseract-data-eng"])]:
if shutil.which(pm[0]):
pkg_manager = pm
break
if not pkg_manager:
raise RuntimeError(
"Package manager not found.\n"
"Install manually:\n sudo apt install tesseract-ocr"
)
subprocess.run(["sudo", pkg_manager[0]] + pkg_manager[1], check=True)
def install_lang_packs_windows(step_fn, base_pct: int) -> None:
os.makedirs(TESSDATA_DIR, exist_ok=True)
for i, lang in enumerate(LANG_PACKS):
dest = os.path.join(TESSDATA_DIR, f"{lang}.traineddata")
if os.path.isfile(dest):
continue
pct = base_pct + i * 8
step_fn(_t("dl_lang", lang=lang), pct)
url = f"https://github.com/tesseract-ocr/tessdata/raw/main/{lang}.traineddata"
download_file(url, dest)
# ── Ghostscript ───────────────────────────────────────────────────────────────
def ghostscript_installed() -> bool:
if bool(shutil.which("gswin64c")) or bool(shutil.which("gs")):
return True
if sys.platform == "win32":
import glob
return bool(glob.glob(r"C:\Program Files\gs\gs*\bin\gswin64c.exe"))
return False
def install_ghostscript_windows(step_fn) -> None:
import tempfile
temp = tempfile.gettempdir()
installer = os.path.join(temp, "gs_setup.exe")
step_fn(_t("dl_gs"), 76)
download_file(GHOSTSCRIPT_URL, installer,
expected_sha256=GHOSTSCRIPT_SHA256, asset_name="Ghostscript")
step_fn(_t("inst_gs"), 82)
subprocess.run([installer, "/S"], check=True)
for _ in range(30):
if ghostscript_installed():
break
time.sleep(1)
try:
os.remove(installer)
except Exception:
pass
def install_ghostscript_macos(step_fn) -> None:
step_fn(_t("inst_gs_brew"), 76)
if not shutil.which("brew"):
raise RuntimeError(
"Homebrew not found.\n"
"Install at https://brew.sh then run:\n"
"brew install ghostscript"
)
subprocess.run(["brew", "install", "ghostscript"], check=True)
def install_ghostscript_linux(step_fn) -> None:
step_fn(_t("inst_gs_pkg"), 76)
pkg_manager = None
for pm in [("apt-get", ["-y", "install", "ghostscript"]),
("dnf", ["-y", "install", "ghostscript"]),
("pacman", ["-S", "--noconfirm", "ghostscript"])]:
if shutil.which(pm[0]):
pkg_manager = pm
break
if not pkg_manager:
raise RuntimeError(
"Package manager not found.\n"
"Install manually:\n sudo apt install ghostscript"
)
subprocess.run(["sudo", pkg_manager[0]] + pkg_manager[1], check=True)
# ── UI ────────────────────────────────────────────────────────────────────────
class InstallerApp(tk.Tk):
def __init__(self):
super().__init__()
# Show loading splash immediately
self._splash = _show_loading_splash(self)
self.withdraw() # hide main window while building UI
self.title(_t("title", app=APP_NAME, ver=APP_VERSION))
self.geometry("600x520")
self.resizable(False, False)
self.configure(bg=BG)
try:
self.iconbitmap(resource("icon.ico"))
except Exception:
pass
self._build()
# Ensure splash is visible for at least 1 second
self.after(1000, self._close_splash)
def _close_splash(self):
try:
self._splash.destroy()
except Exception:
pass
self.deiconify()
def _build(self):
# Wizard-style layout (banner header + body + footer with status
# and action buttons), modelled on installers like LibreOffice's.
BANNER_BG = "#E5EDF5" # soft blue-gray header band
BORDER = "#C9D2DF"
# ── Banner (title + subtitle) ────────────────────────────────
banner = tk.Frame(self, bg=BANNER_BG, height=80)
banner.pack(side="top", fill="x")
banner.pack_propagate(False)
tk.Label(banner,
text=_t("banner_title", app=APP_NAME, ver=APP_VERSION),
bg=BANNER_BG, fg=TEXT,
font=("Segoe UI", 13, "bold")).place(x=24, y=16)
tk.Label(banner, text=_t("banner_subtitle"),
bg=BANNER_BG, fg="#475569",
font=("Segoe UI", 9)).place(x=24, y=44)
tk.Frame(self, bg=BORDER, height=1).pack(side="top", fill="x")
# ── Footer (packed bottom-up so body fills the middle) ───────
# Bottom border line first (will be the bottommost element)
tk.Frame(self, bg=BORDER, height=1).pack(side="bottom", fill="x")
# Action buttons row (right-aligned)
btn_row = tk.Frame(self, bg=BG)
btn_row.pack(side="bottom", fill="x", padx=24, pady=(8, 14))
self._btn = tk.Button(btn_row, text=_t("install"),
command=self._start,
bg=ACCENT, fg="#FFFFFF",
font=("Segoe UI", 10, "bold"),
relief="flat", cursor="hand2")
self._btn.pack(side="right", ipady=6, ipadx=14)
tk.Button(btn_row, text=_t("cancel"), command=self.destroy,
bg="#E2E8F0", fg=TEXT, font=("Segoe UI", 10),
relief="flat", cursor="hand2").pack(
side="right", padx=(0, 8), ipady=6, ipadx=14)
# Status label + current-operation text + progress bar
progress_area = tk.Frame(self, bg=BG)
progress_area.pack(side="bottom", fill="x", padx=24, pady=(10, 0))
tk.Label(progress_area, text=_t("status_label"), bg=BG, fg=TEXT,
font=("Segoe UI", 9, "bold")).pack(anchor="w")
self._status_var = tk.StringVar(value=_t("ready"))
tk.Label(progress_area, textvariable=self._status_var, bg=BG,
fg=TEXT_L, font=("Segoe UI", 9)).pack(
anchor="w", pady=(2, 6))
self._pb = ttk.Progressbar(progress_area, mode="determinate")
self._pb.pack(fill="x")
# Top border above the footer block
tk.Frame(self, bg=BORDER, height=1).pack(side="bottom", fill="x")
# ── Body (form fields, fills the middle) ─────────────────────
body = tk.Frame(self, bg=BG, padx=24, pady=18)
body.pack(side="top", fill="both", expand=True)
# Folder picker
tk.Label(body, text=_t("folder"), bg=BG, fg=TEXT,
font=("Segoe UI", 10, "bold")).pack(anchor="w")
row = tk.Frame(body, bg=BG)
row.pack(fill="x", pady=(4, 14))
self._dir_var = tk.StringVar(value=default_dir())
self._dir_entry = tk.Entry(row, textvariable=self._dir_var,
font=("Segoe UI", 10), bg="#F8FAFC",
relief="flat", bd=1,
highlightbackground="#CBD5E1",
highlightthickness=1)
self._dir_entry.pack(side="left", fill="x", expand=True, ipady=6)
tk.Button(row, text=_t("browse"), command=self._browse,
bg="#E2E8F0", fg=TEXT, relief="flat",
font=("Segoe UI", 9), cursor="hand2").pack(
side="left", padx=(6, 0), ipady=6)
self._desktop_var = tk.BooleanVar(value=True)
self._startmenu_var = tk.BooleanVar(value=True)
if sys.platform == "win32":
tk.Checkbutton(body, text=_t("desktop"),
variable=self._desktop_var, bg=BG, fg=TEXT,
font=("Segoe UI", 10), activebackground=BG,
selectcolor="#EFF6FF").pack(anchor="w")
tk.Checkbutton(body, text=_t("startmenu"),
variable=self._startmenu_var, bg=BG, fg=TEXT,
font=("Segoe UI", 10), activebackground=BG,
selectcolor="#EFF6FF").pack(anchor="w", pady=(4, 0))
elif sys.platform == "darwin":
tk.Checkbutton(body, text=_t("desktop"),
variable=self._desktop_var, bg=BG, fg=TEXT,
font=("Helvetica", 10), activebackground=BG,
selectcolor="#EFF6FF").pack(anchor="w")
else:
tk.Checkbutton(body, text=_t("desktop"),
variable=self._desktop_var, bg=BG, fg=TEXT,
font=("Segoe UI", 10), activebackground=BG,
selectcolor="#EFF6FF").pack(anchor="w")
tk.Checkbutton(body, text=_t("appmenu"),
variable=self._startmenu_var, bg=BG, fg=TEXT,
font=("Segoe UI", 10), activebackground=BG,
selectcolor="#EFF6FF").pack(anchor="w", pady=(4, 0))
self._ocr_var = tk.BooleanVar(value=True)
self._ocr_chk = tk.Checkbutton(
body,
text=_t("ocr"),
variable=self._ocr_var, bg=BG, fg="#0369A1",
font=("Segoe UI", 10), activebackground=BG, selectcolor="#EFF6FF",
)
if not tesseract_installed():
self._ocr_chk.pack(anchor="w", pady=(4, 0))
self._gs_var = tk.BooleanVar(value=True)
self._gs_chk = tk.Checkbutton(
body,
text=_t("gs"),
variable=self._gs_var, bg=BG, fg="#0369A1",
font=("Segoe UI", 10), activebackground=BG, selectcolor="#EFF6FF",
)
if not ghostscript_installed():
self._gs_chk.pack(anchor="w", pady=(4, 0))
notes = []
if tesseract_installed():
notes.append(_t("tess_ok"))
if ghostscript_installed():
notes.append(_t("gs_ok"))
self._note_var = tk.StringVar(value=" ".join(notes))
tk.Label(body, textvariable=self._note_var, bg=BG, fg="#10B981",
font=("Segoe UI", 9)).pack(anchor="w", pady=(6, 0))
def _browse(self):
d = filedialog.askdirectory(initialdir=self._dir_var.get())
if d:
self._dir_var.set(os.path.normpath(d))
def _start(self):
self._btn.config(state="disabled", text=_t("installing"))
self._dir_entry.config(state="disabled")
threading.Thread(target=self._install, daemon=True).start()
def _step(self, msg: str, pct: int):
self._status_var.set(msg)
self._pb["value"] = pct
self.update_idletasks()
def _install(self):
install_dir = self._dir_var.get()
try:
self._step(_t("creating_folder"), 8)
try:
os.makedirs(install_dir, exist_ok=True)
test = os.path.join(install_dir, ".write_test")
open(test, "w").close()
os.remove(test)
except PermissionError:
if sys.platform == "win32":