-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
2153 lines (1861 loc) · 89.6 KB
/
Main.cpp
File metadata and controls
2153 lines (1861 loc) · 89.6 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
#include "Main.h"
#include "Cache.h"
#include <cassert>
#include <dwmapi.h>
#include <filesystem>
#include <fstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <winhttp.h>
namespace fs = std::filesystem;
// ── Forward declarations ──────────────────────────────────────────────────────
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK PreviewWndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam);
DWORD WINAPI FileThread(LPVOID arg);
DWORD WINAPI CacheLoadThread(LPVOID arg);
DWORD WINAPI ExtractThread(LPVOID arg);
DWORD WINAPI AddThread(LPVOID arg);
DWORD WINAPI CheckUpdateThread(LPVOID arg);
void OpenPazFolder(HWND hWnd, const std::wstring &folderPath);
void ShowSettingsDialog(HWND hParent);
void ShowSearchWindow(HWND hParent);
WNDPROC g_fnOrigStatusBarProc = nullptr; // original statusbar WndProc for subclass
WNDPROC g_fnOrigHeaderProc = nullptr; // original ListView header WndProc for subclass
void UpdatePreview(kukdh1::Tree *pTree);
HBITMAP LoadWICBitmap(const std::wstring &path, int maxW, int maxH);
// ── Global ────────────────────────────────────────────────────────────────────
AppData app;
// ─────────────────────────────────────────────────────────────────────────────
// WinMain
// ─────────────────────────────────────────────────────────────────────────────
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow) {
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
// ── Dark mode: make menus and common controls use dark theme ─────────────
// These are undocumented uxtheme.dll exports (ordinals 135, 104, 133).
// They are stable since Windows 10 1809 and used by many mainstream apps.
{
HMODULE hUxtheme = LoadLibraryExW(L"uxtheme.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (hUxtheme) {
// ordinal 135 = SetPreferredAppMode: 0=default,1=AllowDark,2=ForceDark
using fnSetPreferredAppMode = HRESULT(WINAPI*)(DWORD);
auto _SetPreferredAppMode = reinterpret_cast<fnSetPreferredAppMode>(
GetProcAddress(hUxtheme, MAKEINTRESOURCEA(135)));
// ordinal 104 = RefreshImmersiveColorPolicyState
using fnRefresh = void(WINAPI*)();
auto _Refresh = reinterpret_cast<fnRefresh>(
GetProcAddress(hUxtheme, MAKEINTRESOURCEA(104)));
if (_SetPreferredAppMode) _SetPreferredAppMode(2); // ForceDark
if (_Refresh) _Refresh();
// Don't FreeLibrary — keep it loaded so the setting stays active
}
}
HWND hWnd;
WNDCLASS wndclass;
MSG msg;
INITCOMMONCONTROLSEX iccex;
std::wstring lpszClass = app.CSetting.getString(kukdh1::Setting::ID_CAPTION);
// Append version to window class / caption base
lpszClass += L" v" APP_VERSION;
iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
iccex.dwICC = ICC_WIN95_CLASSES | ICC_PROGRESS_CLASS | ICC_TREEVIEW_CLASSES | ICC_LISTVIEW_CLASSES;
if (!InitCommonControlsEx(&iccex)) {
CoUninitialize();
return -1;
}
// Register preview panel window class
WNDCLASS previewClass = {};
previewClass.style = CS_HREDRAW | CS_VREDRAW;
previewClass.lpfnWndProc = PreviewWndProc;
previewClass.hInstance = hInstance;
previewClass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
previewClass.lpszClassName = L"PAZPreview";
RegisterClass(&previewClass);
// Register main window class
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = nullptr; // dark bg handled via WM_ERASEBKGND
wndclass.hCursor = LoadCursor(nullptr, IDC_ARROW);
wndclass.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WndProc;
wndclass.lpszClassName = lpszClass.c_str();
wndclass.lpszMenuName = nullptr;
wndclass.style = CS_VREDRAW | CS_HREDRAW;
RegisterClass(&wndclass);
hWnd = CreateWindow(lpszClass.c_str(), lpszClass.c_str(), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
nullptr, nullptr, hInstance, nullptr);
ShowWindow(hWnd, nCmdShow);
// Call AllowDarkModeForWindow AFTER ShowWindow for reliable dark menu bar
{
HMODULE hUxtheme = GetModuleHandleW(L"uxtheme.dll");
using fnAllowDark = BOOL(WINAPI*)(HWND, BOOL);
auto _Allow = reinterpret_cast<fnAllowDark>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(133)));
if (_Allow) { _Allow(hWnd, TRUE); _Allow(app.hStatusBar, TRUE); }
// SetWindowCompositionAttribute with WCA_USEDARKMODECOLORS=26 — makes Win11
// render the menu bar with the dark system colour (undocumented user32 export).
struct WINCOMPATTRIBDATA { DWORD attrib; PVOID pData; SIZE_T cbData; };
BOOL bDark = TRUE;
WINCOMPATTRIBDATA wca = { 26, &bDark, sizeof(bDark) };
using fnSetWCA = BOOL(WINAPI*)(HWND, WINCOMPATTRIBDATA*);
auto _SetWCA = reinterpret_cast<fnSetWCA>(
GetProcAddress(GetModuleHandleW(L"user32.dll"), "SetWindowCompositionAttribute"));
if (_SetWCA) _SetWCA(hWnd, &wca);
SendMessage(hWnd, WM_THEMECHANGED, 0, 0);
SendMessage(app.hStatusBar, WM_THEMECHANGED, 0, 0);
DrawMenuBar(hWnd);
}
while (GetMessage(&msg, nullptr, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
CoUninitialize();
return (int)msg.wParam;
}
// ─────────────────────────────────────────────────────────────────────────────
// Status bar dark-mode subclass
// The STATUSCLASSNAME control ignores WM_CTLCOLOR* messages.
// Subclass it to paint with dark colours ourselves.
// ─────────────────────────────────────────────────────────────────────────────
LRESULT CALLBACK DarkStatusBarProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
if (msg == WM_PAINT) {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
RECT rc; GetClientRect(hWnd, &rc);
FillRect(hdc, &rc, app.hBrushBg);
SetTextColor(hdc, CLR_DARK_TEXT2);
SetBkMode(hdc, TRANSPARENT);
if (app.hFont) SelectObject(hdc, app.hFont);
// Draw each part's text
int nParts = (int)SendMessage(hWnd, SB_GETPARTS, 0, 0);
for (int i = 0; i < nParts; i++) {
RECT partRc;
SendMessage(hWnd, SB_GETRECT, i, (LPARAM)&partRc);
wchar_t buf[256] = {};
SendMessage(hWnd, SB_GETTEXT, i, (LPARAM)buf);
InflateRect(&partRc, -2, 0);
DrawTextW(hdc, buf, -1, &partRc, DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
}
EndPaint(hWnd, &ps);
return 0;
}
if (msg == WM_ERASEBKGND) return 1;
return CallWindowProc(g_fnOrigStatusBarProc, hWnd, msg, wParam, lParam);
}
// ─────────────────────────────────────────────────────────────────────────────
// ListView header dark-mode subclass
// NM_CUSTOMDRAW cannot override visual-style themed drawing; subclassing WM_PAINT
// gives us full control, same technique used for the status bar.
// ─────────────────────────────────────────────────────────────────────────────
LRESULT CALLBACK DarkHeaderProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
if (msg == WM_PAINT) {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
RECT rc; GetClientRect(hWnd, &rc);
FillRect(hdc, &rc, app.hBrushInput);
int count = Header_GetItemCount(hWnd);
for (int i = 0; i < count; i++) {
RECT itemRc;
Header_GetItemRect(hWnd, i, &itemRc);
// Right divider
HPEN hPen = CreatePen(PS_SOLID, 1, CLR_DARK_BORDER);
HPEN hOld = (HPEN)SelectObject(hdc, hPen);
MoveToEx(hdc, itemRc.right - 1, itemRc.top, nullptr);
LineTo (hdc, itemRc.right - 1, itemRc.bottom);
SelectObject(hdc, hOld); DeleteObject(hPen);
// Item text
wchar_t buf[256] = {};
HDITEMW hdi = {}; hdi.mask = HDI_TEXT; hdi.pszText = buf; hdi.cchTextMax = _countof(buf);
Header_GetItem(hWnd, i, &hdi);
SetTextColor(hdc, CLR_DARK_TEXT);
SetBkMode(hdc, TRANSPARENT);
if (app.hFont) SelectObject(hdc, app.hFont);
RECT textRc = itemRc;
InflateRect(&textRc, -6, 0);
DrawTextW(hdc, buf, -1, &textRc, DT_SINGLELINE | DT_VCENTER | DT_LEFT | DT_END_ELLIPSIS);
}
// Bottom border
HPEN hPen = CreatePen(PS_SOLID, 1, CLR_DARK_BORDER);
HPEN hOld = (HPEN)SelectObject(hdc, hPen);
MoveToEx(hdc, rc.left, rc.bottom - 1, nullptr);
LineTo (hdc, rc.right, rc.bottom - 1);
SelectObject(hdc, hOld); DeleteObject(hPen);
EndPaint(hWnd, &ps);
return 0;
}
if (msg == WM_ERASEBKGND) return 1;
return CallWindowProc(g_fnOrigHeaderProc, hWnd, msg, wParam, lParam);
}
// ─────────────────────────────────────────────────────────────────────────────
// Preview panel WndProc
// ─────────────────────────────────────────────────────────────────────────────
LRESULT CALLBACK PreviewWndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) {
switch (iMessage) {
case WM_ERASEBKGND:
return 1; // handled in WM_PAINT — prevents flicker
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
RECT rc;
GetClientRect(hWnd, &rc);
if (app.hPreviewBitmap) {
BITMAP bm;
GetObject(app.hPreviewBitmap, sizeof(bm), &bm);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hOld = (HBITMAP)SelectObject(hdcMem, app.hPreviewBitmap);
// Dark grey background, image centred
FillRect(hdc, &rc, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
int x = (rc.right - bm.bmWidth) / 2;
int y = (rc.bottom - bm.bmHeight) / 2;
BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hOld);
DeleteDC(hdcMem);
}
else {
FillRect(hdc, &rc, app.hBrushPanel ? app.hBrushPanel : GetSysColorBrush(COLOR_BTNFACE));
SetTextColor(hdc, CLR_DARK_TEXT2);
SetBkMode(hdc, TRANSPARENT);
if (app.hFont) SelectObject(hdc, app.hFont);
DrawText(hdc, L"No preview", -1, &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
EndPaint(hWnd, &ps);
return 0;
}
}
return DefWindowProc(hWnd, iMessage, wParam, lParam);
}
// ─────────────────────────────────────────────────────────────────────────────
// Window message handlers
// ─────────────────────────────────────────────────────────────────────────────
BOOL Cls_OnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct) {
// ── Dark mode title bar ────────────────────────────────────────────────────
BOOL darkMode = TRUE;
DwmSetWindowAttribute(hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &darkMode, sizeof(darkMode));
// ── Dark mode brushes ──────────────────────────────────────────────────────
app.hBrushBg = CreateSolidBrush(CLR_DARK_BG);
app.hBrushPanel = CreateSolidBrush(CLR_DARK_PANEL);
app.hBrushInput = CreateSolidBrush(CLR_DARK_INPUT);
// ── Controls ───────────────────────────────────────────────────────────────
// Extract button — visible next to Load button; disabled until a file is selected
app.hButtonExctact = CreateWindow(WC_BUTTON, L"Extract",
WS_CHILD | WS_VISIBLE | WS_DISABLED | BS_PUSHBUTTON,
0, 0, 0, 0, hWnd, (HMENU)ID_BUTTON_EXTRACT, lpCreateStruct->hInstance, nullptr);
// Load button — visible at top of left panel; loads last saved PAZ folder
app.hButtonLoad = CreateWindow(WC_BUTTON, L"Load",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 0, 0, 0, hWnd, (HMENU)ID_BUTTON_LOAD, lpCreateStruct->hInstance, nullptr);
app.hTreeFileSystem = CreateWindow(WC_TREEVIEW, nullptr,
WS_CHILD | WS_VISIBLE | TVS_DISABLEDRAGDROP | TVS_HASBUTTONS | TVS_TRACKSELECT | TVS_LINESATROOT,
0, 0, 0, 0, hWnd, (HMENU)ID_TREE_FILESYSTEM, lpCreateStruct->hInstance, nullptr);
app.hStatusBar = CreateWindow(STATUSCLASSNAME, nullptr,
WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
0, 0, 0, 0, hWnd, (HMENU)ID_STATUSBAR, lpCreateStruct->hInstance, nullptr);
app.hStaticInfo = CreateWindow(WC_STATIC, nullptr,
WS_CHILD | WS_VISIBLE | SS_OWNERDRAW,
0, 0, 0, 0, hWnd, (HMENU)ID_STATIC, lpCreateStruct->hInstance, nullptr);
// ── Dark mode: allow dark common-control rendering for this window ─────────
{
HMODULE hUxtheme = GetModuleHandleW(L"uxtheme.dll");
using fnAllowDark = BOOL(WINAPI*)(HWND, BOOL);
auto _Allow = reinterpret_cast<fnAllowDark>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(133)));
if (_Allow) {
_Allow(hWnd, TRUE);
_Allow(app.hStatusBar, TRUE);
}
SendMessage(hWnd, WM_THEMECHANGED, 0, 0);
}
// Dark mode theming for controls
SetWindowTheme(app.hTreeFileSystem, L"DarkMode_Explorer", nullptr);
TreeView_SetBkColor(app.hTreeFileSystem, CLR_DARK_INPUT);
TreeView_SetTextColor(app.hTreeFileSystem, CLR_DARK_TEXT);
SetWindowTheme(app.hButtonLoad, L"DarkMode_Explorer", nullptr);
SetWindowTheme(app.hButtonExctact, L"DarkMode_Explorer", nullptr);
SetWindowTheme(app.hStatusBar, L"DarkMode_Explorer", nullptr);
SetWindowTheme(hWnd, L"DarkMode_Explorer", nullptr);
// Subclass status bar for dark custom painting
g_fnOrigStatusBarProc = (WNDPROC)SetWindowLongPtrW(
app.hStatusBar, GWLP_WNDPROC, (LONG_PTR)DarkStatusBarProc);
// ── Texture preview panel ─────────────────────────────────────────────────
app.hPreviewPanel = CreateWindow(L"PAZPreview", nullptr,
WS_CHILD | WS_VISIBLE,
0, 0, 0, 0, hWnd, (HMENU)ID_PREVIEW, lpCreateStruct->hInstance, nullptr);
// ── Font ──────────────────────────────────────────────────────────────────
app.hFont = CreateFont(FONT_SIZE, 0, 0, 0, FW_NORMAL, 0, 0, 0,
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_ROMAN, FONT_FACE);
SendMessage(app.hTreeFileSystem, WM_SETFONT, (WPARAM)app.hFont, TRUE);
SendMessage(app.hStatusBar, WM_SETFONT, (WPARAM)app.hFont, TRUE);
SendMessage(app.hStaticInfo, WM_SETFONT, (WPARAM)app.hFont, TRUE);
SendMessage(app.hButtonLoad, WM_SETFONT, (WPARAM)app.hFont, TRUE);
SendMessage(app.hButtonExctact, WM_SETFONT, (WPARAM)app.hFont, TRUE);
// ── Status bar sections ───────────────────────────────────────────────────
int parts[STATUSBAR_SECTION_COUNT] = { STATUSBAR_SECTION1, STATUSBAR_SECTION2, -1 };
SendMessage(app.hStatusBar, SB_SETPARTS, STATUSBAR_SECTION_COUNT, (LPARAM)parts);
SendMessage(app.hStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM)app.CSetting.getString(kukdh1::Setting::ID_STATUS_IDLE).c_str());
// ── Progress bar (inside status bar section 1) ────────────────────────────
RECT rtArea;
SendMessage(app.hStatusBar, SB_GETRECT, 1, (LPARAM)&rtArea);
app.hProgressBar = CreateWindow(PROGRESS_CLASS, nullptr,
WS_CHILD | WS_VISIBLE | PBS_SMOOTH,
rtArea.left, rtArea.top, rtArea.right - rtArea.left, rtArea.bottom - rtArea.top,
app.hStatusBar, nullptr, lpCreateStruct->hInstance, nullptr);
// ── WIC factory ──────────────────────────────────────────────────────────
CoCreateInstance(CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&app.pWICFactory));
// ── Menu bar ─────────────────────────────────────────────────────────────
{
HMENU hFile = CreatePopupMenu();
AppendMenuW(hFile, MF_STRING, ID_MENU_FILE_OPEN, L"&Open Folder...");
AppendMenuW(hFile, MF_STRING, ID_MENU_FILE_EXTRACT, L"&Extract...");
AppendMenuW(hFile, MF_SEPARATOR, 0, nullptr);
AppendMenuW(hFile, MF_STRING, ID_MENU_FILE_EXIT, L"E&xit");
HMENU hCache = CreatePopupMenu();
AppendMenuW(hCache, MF_STRING, ID_MENU_CACHE_REBUILD, L"&Rebuild Cache");
AppendMenuW(hCache, MF_STRING, ID_MENU_CACHE_CLEAR_TEMP, L"Clear &Preview Temp Files");
// Settings — single item, no submenu needed
HMENU hSettings = CreatePopupMenu();
AppendMenuW(hSettings, MF_STRING, ID_MENU_SETTINGS, L"&Configure Paths...");
HMENU hHelp = CreatePopupMenu();
AppendMenuW(hHelp, MF_STRING, ID_MENU_HELP_CHECK_UPDATE, L"Check for &Updates");
AppendMenuW(hHelp, MF_SEPARATOR, 0, nullptr);
AppendMenuW(hHelp, MF_STRING, ID_MENU_HELP_ABOUT, L"&About");
HMENU hMenu = CreateMenu();
AppendMenuW(hMenu, MF_POPUP, (UINT_PTR)hFile, L"&File");
AppendMenuW(hMenu, MF_POPUP, (UINT_PTR)hCache, L"&Cache");
AppendMenuW(hMenu, MF_STRING, ID_MENU_SEARCH_OPEN, L"&Search"); // direct action, no submenu
AppendMenuW(hMenu, MF_POPUP, (UINT_PTR)hSettings, L"Se&ttings");
AppendMenuW(hMenu, MF_POPUP, (UINT_PTR)hHelp, L"&Help");
SetMenu(hWnd, hMenu);
}
return TRUE;
}
void Cls_OnDestroy(HWND hWnd) {
if (app.hPreviewBitmap) { DeleteObject(app.hPreviewBitmap); app.hPreviewBitmap = nullptr; }
if (app.pWICFactory) { app.pWICFactory->Release(); app.pWICFactory = nullptr; }
if (app.hFont) { DeleteObject(app.hFont); app.hFont = nullptr; }
if (app.hBrushBg) { DeleteObject(app.hBrushBg); app.hBrushBg = nullptr; }
if (app.hBrushPanel) { DeleteObject(app.hBrushPanel); app.hBrushPanel = nullptr; }
if (app.hBrushInput) { DeleteObject(app.hBrushInput); app.hBrushInput = nullptr; }
// Save settings explicitly — ExitProcess skips all C++ destructors so ~Setting() never runs.
app.CSetting.Save();
// Exit immediately — letting ~AppData() run would cascade-free ~500k unique_ptr<Tree> nodes,
// stalling the system heap for several seconds. OS reclaims all memory instantly.
CoUninitialize();
ExitProcess(0);
}
void Cls_OnSize(HWND hWnd, UINT state, int cx, int cy) {
int nTreeWidth = (int)(cx * DIVIDE_RATIO + 0.5f);
int nRightWidth = cx - nTreeWidth;
int nStatusH = GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CYBORDER) * 2;
int nContentH = cy - nStatusH - HEADER_HEIGHT;
if (nContentH < 1) nContentH = 1;
int nInfoH = (int)(nContentH * INFO_RATIO);
int nPreviewH = nContentH - nInfoH;
// Row 0: Load | Extract buttons side by side across the left panel
int nHalfW = nTreeWidth / 2;
MoveWindow(app.hButtonLoad, 0, 0, nHalfW, LOAD_HEIGHT, TRUE);
MoveWindow(app.hButtonExctact, nHalfW, 0, nTreeWidth - nHalfW, LOAD_HEIGHT, TRUE);
// Main content area (directly below Load button)
MoveWindow(app.hTreeFileSystem, 0, HEADER_HEIGHT, nTreeWidth, nContentH, TRUE);
MoveWindow(app.hStaticInfo, nTreeWidth, HEADER_HEIGHT, nRightWidth, nInfoH, TRUE);
MoveWindow(app.hPreviewPanel, nTreeWidth, HEADER_HEIGHT + nInfoH, nRightWidth, nPreviewH, TRUE);
MoveWindow(app.hStatusBar, 0, 0, 0, 0, TRUE);
}
void Cls_OnGetMinMaxInfo(HWND hWnd, LPMINMAXINFO lpMinMaxInfo) {
lpMinMaxInfo->ptMinTrackSize.x = WINDOW_MIN_WIDTH;
lpMinMaxInfo->ptMinTrackSize.y = WINDOW_MIN_HEIGHT;
}
void Cls_OnCommand(HWND hWnd, int id, HWND hwndCtl, UINT codeNotify) {
switch (id) {
case ID_BUTTON_LOAD:
// Load from saved PAZ folder path — no browse dialog
{
if (app.bBusy) break;
std::wstring saved;
app.CSetting.getData(SETTING_LAST_FOLDER, saved, L"");
if (!saved.empty()) {
OpenPazFolder(hWnd, saved);
} else {
MessageBoxW(hWnd,
L"No PAZ folder configured.\r\nUse Settings \u2192 Configure Paths to set your PAZ folder.",
L"Load", MB_OK | MB_ICONINFORMATION);
}
}
break;
case ID_BUTTON_OPEN:
case ID_MENU_FILE_OPEN:
{
if (app.bBusy) break;
std::wstring folderPath;
std::wstring wsLastPath;
app.CSetting.getData(SETTING_LAST_FOLDER, wsLastPath, L"C:\\");
if (kukdh1::BrowseFolder(hWnd, app.CSetting.getString(kukdh1::Setting::ID_SELECT_FOLDER_TO_OPEN).c_str(), wsLastPath.c_str(), folderPath))
OpenPazFolder(hWnd, folderPath);
}
break;
case ID_BUTTON_EXTRACT:
case ID_MENU_FILE_EXTRACT:
{
if (app.bBusy) break;
TVITEM tvi = {};
HTREEITEM hTree = TreeView_GetSelection(app.hTreeFileSystem);
tvi.hItem = hTree;
tvi.mask = TVIF_PARAM;
TreeView_GetItem(app.hTreeFileSystem, &tvi);
if (tvi.lParam) {
HANDLE hThread = CreateThread(nullptr, 0, ExtractThread, (LPVOID)tvi.lParam, 0, nullptr);
CloseHandle(hThread);
}
}
break;
case ID_MENU_FILE_EXIT:
DestroyWindow(hWnd);
break;
case ID_MENU_CACHE_REBUILD:
if (!app.bBusy && app.CTree) {
// Delete cache so FileThread rebuilds it from scratch
DeleteFileW(kukdh1::CachePath(app.wsFolderPath).c_str());
OpenPazFolder(hWnd, app.wsFolderPath);
}
break;
case ID_MENU_CACHE_CLEAR_TEMP:
{
int n = kukdh1::ClearPreviewTempFiles();
WCHAR buf[64];
swprintf_s(buf, L"Deleted %d preview temp file(s).", n);
MessageBoxW(hWnd, buf, L"Clear Temp Files", MB_OK | MB_ICONINFORMATION);
}
break;
case ID_MENU_SEARCH_OPEN:
if (!app.bBusy)
ShowSearchWindow(hWnd);
break;
case ID_MENU_SETTINGS:
if (!app.bBusy)
ShowSettingsDialog(hWnd);
break;
case ID_MENU_HELP_CHECK_UPDATE:
{
// Disable item while checking to prevent double-clicks (Help is index 3)
HMENU hBar = GetMenu(hWnd);
HMENU hHelp = GetSubMenu(hBar, 4);
EnableMenuItem(hHelp, ID_MENU_HELP_CHECK_UPDATE, MF_BYCOMMAND | MF_GRAYED);
DrawMenuBar(hWnd);
CreateThread(nullptr, 0, CheckUpdateThread, (LPVOID)hWnd, 0, nullptr);
}
break;
case ID_MENU_HELP_ABOUT:
MessageBoxW(hWnd,
L"PAZ Unpacker v" APP_VERSION L"\r\n\r\n"
L"Community revival fork by sibercat\r\n"
L"Original tool by kukdh1 (2015)\r\n\r\n"
L"https://github.com/sibercat/PAZ-Unpacker",
L"About PAZ Unpacker", MB_OK | MB_ICONINFORMATION);
break;
}
}
void Cls_OnDrawItem(HWND hWnd, const DRAWITEMSTRUCT *lpDrawItem) {
if (lpDrawItem->CtlID == ID_STATIC) {
// Dark background + text
FillRect(lpDrawItem->hDC, &lpDrawItem->rcItem, app.hBrushBg);
SetTextColor(lpDrawItem->hDC, CLR_DARK_TEXT);
SetBkMode(lpDrawItem->hDC, TRANSPARENT);
SIZE size;
uint32_t uiLength = (uint32_t)SendMessage(lpDrawItem->hwndItem, WM_GETTEXTLENGTH, 0, 0);
std::wstring text(uiLength + 1, L'\0');
SendMessage(lpDrawItem->hwndItem, WM_GETTEXT, uiLength + 1, (LPARAM)text.data());
text.resize(uiLength);
GetTextExtentPoint32(lpDrawItem->hDC, text.c_str(), 1, &size);
WCHAR *handle = nullptr;
WCHAR *pszLine = wcstok_s(text.data(), L"\r\n", &handle);
for (int i = 0; ; i++) {
if (pszLine == nullptr) break;
RECT rtRect;
SetRect(&rtRect, 4, size.cy * i + 4, lpDrawItem->rcItem.right - 4, size.cy * (i + 1) + 4);
DrawText(lpDrawItem->hDC, pszLine, (int)wcslen(pszLine), &rtRect, DT_WORD_ELLIPSIS | DT_NOCLIP);
pszLine = wcstok_s(nullptr, L"\r\n", &handle);
}
}
}
// ─────────────────────────────────────────────────────────────────────────────
// UAH (undocumented) dark menu-bar messages — stable since Win10 1809
// Windows sends these when SetPreferredAppMode + AllowDarkModeForWindow are set.
// Handling them lets us paint the menu bar and items with our dark palette.
// ─────────────────────────────────────────────────────────────────────────────
#define WM_UAHDRAWMENU 0x0091
#define WM_UAHDRAWMENUITEM 0x0092
struct UAHMENU { HMENU hmenu; HDC hdc; DWORD dwFlags; };
struct UAHDRAWMENUITEM {
DRAWITEMSTRUCT dis;
struct { MENUITEMINFOW mii; } umi;
};
// ─────────────────────────────────────────────────────────────────────────────
// Main WndProc
// ─────────────────────────────────────────────────────────────────────────────
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) {
switch (iMessage) {
HANDLE_MSG(hWnd, WM_CREATE, Cls_OnCreate);
HANDLE_MSG(hWnd, WM_DESTROY, Cls_OnDestroy);
HANDLE_MSG(hWnd, WM_SIZE, Cls_OnSize);
HANDLE_MSG(hWnd, WM_GETMINMAXINFO,Cls_OnGetMinMaxInfo);
HANDLE_MSG(hWnd, WM_COMMAND, Cls_OnCommand);
HANDLE_MSG(hWnd, WM_DRAWITEM, Cls_OnDrawItem);
case WM_APP_LOAD_FALLBACK:
// Cache load failed or was stale — run full PAZ scan
{
HANDLE hThread = CreateThread(nullptr, 0, FileThread, nullptr, 0, nullptr);
CloseHandle(hThread);
}
return 0;
case WM_APP_UPDATE_RESULT:
{
// Re-enable the menu item (Help is now index 3 — File/Cache/Settings/Help)
HMENU hBar = GetMenu(hWnd);
HMENU hHelp = GetSubMenu(hBar, 4);
EnableMenuItem(hHelp, ID_MENU_HELP_CHECK_UPDATE, MF_BYCOMMAND | MF_ENABLED);
DrawMenuBar(hWnd);
int result = (int)(INT_PTR)wParam;
if (result == 1) {
// lParam = pointer to heap-allocated latest version string; caller frees
wchar_t *latestVer = (wchar_t *)(LPARAM)lParam;
wchar_t msg[256];
swprintf_s(msg,
L"A new version is available!\r\n\r\n"
L"Current: v" APP_VERSION L"\r\n"
L"Latest: %s\r\n\r\n"
L"Visit https://github.com/sibercat/PAZ-Unpacker/releases to download.",
latestVer);
delete[] latestVer;
MessageBoxW(hWnd, msg, L"Update Available", MB_OK | MB_ICONINFORMATION);
} else if (result == 0) {
MessageBoxW(hWnd,
L"You are running the latest version (v" APP_VERSION L").",
L"Up to Date", MB_OK | MB_ICONINFORMATION);
} else {
MessageBoxW(hWnd,
L"Could not reach GitHub to check for updates.\r\nPlease check your internet connection.",
L"Update Check Failed", MB_OK | MB_ICONWARNING);
}
}
return 0;
case WM_INITMENUPOPUP:
{
HMENU hSub = (HMENU)wParam;
bool hasPaz = (app.CTree != nullptr && !app.bBusy);
EnableMenuItem(hSub, ID_MENU_FILE_EXTRACT, MF_BYCOMMAND | (hasPaz ? MF_ENABLED : MF_GRAYED));
EnableMenuItem(hSub, ID_MENU_CACHE_REBUILD, MF_BYCOMMAND | (hasPaz ? MF_ENABLED : MF_GRAYED));
EnableMenuItem(hSub, ID_MENU_CACHE_CLEAR_TEMP, MF_BYCOMMAND | (!app.bBusy ? MF_ENABLED : MF_GRAYED));
EnableMenuItem(hSub, ID_MENU_SETTINGS, MF_BYCOMMAND | (!app.bBusy ? MF_ENABLED : MF_GRAYED));
}
return 0;
case WM_ERASEBKGND:
{
RECT rc;
GetClientRect(hWnd, &rc);
FillRect((HDC)wParam, &rc, app.hBrushBg);
return 1;
}
case WM_CTLCOLOREDIT:
SetTextColor((HDC)wParam, CLR_DARK_TEXT);
SetBkColor((HDC)wParam, CLR_DARK_INPUT);
return (LRESULT)app.hBrushInput;
case WM_CTLCOLORSTATIC:
SetTextColor((HDC)wParam, CLR_DARK_TEXT);
SetBkColor((HDC)wParam, CLR_DARK_BG);
return (LRESULT)app.hBrushBg;
case WM_CTLCOLORBTN:
SetTextColor((HDC)wParam, CLR_DARK_TEXT);
SetBkColor((HDC)wParam, CLR_DARK_PANEL);
return (LRESULT)app.hBrushPanel;
case WM_NOTIFY:
{
LPNMHDR hdr = (LPNMHDR)lParam;
if (hdr->idFrom == ID_TREE_FILESYSTEM) {
LPNMTREEVIEW ntv = (LPNMTREEVIEW)lParam;
kukdh1::Tree *pTree;
if (hdr->code == TVN_SELCHANGED) {
pTree = (kukdh1::Tree *)ntv->itemNew.lParam;
if (pTree != nullptr && !app.bBusy) {
WCHAR pszBuffer[1024];
std::wstring capacity;
switch (pTree->GetType()) {
case kukdh1::Tree::TREE_TYPE_ROOT:
if (app.CMeta != nullptr) {
kukdh1::ConvertCapacity(app.CTree->GetCapacity(), capacity);
swprintf_s(pszBuffer, app.CSetting.getString(kukdh1::Setting::ID_META_FILE_INFO).c_str(),
app.CMeta->uiVersion, app.CMeta->uiPAZFileCount, capacity.c_str());
SendMessage(app.hStaticInfo, WM_SETTEXT, 0, (LPARAM)pszBuffer);
}
break;
case kukdh1::Tree::TREE_TYPE_FOLDER:
kukdh1::ConvertCapacity(pTree->GetCapacity(), capacity);
swprintf_s(pszBuffer, app.CSetting.getString(kukdh1::Setting::ID_INTERNAL_FOLDER_INFO).c_str(),
pTree->GetName().c_str(), capacity.c_str());
SendMessage(app.hStaticInfo, WM_SETTEXT, 0, (LPARAM)pszBuffer);
break;
case kukdh1::Tree::TREE_TYPE_FILE:
kukdh1::ConvertCapacity(pTree->GetCapacity(), capacity);
swprintf_s(pszBuffer, app.CSetting.getString(kukdh1::Setting::ID_INTERNAL_FILE_INFO).c_str(),
pTree->GetName().c_str(), capacity.c_str(),
pTree->GetFileInfo().wsPazFullPath.c_str(),
pTree->GetFileInfo().sFullPath.c_str());
SendMessage(app.hStaticInfo, WM_SETTEXT, 0, (LPARAM)pszBuffer);
break;
}
UpdatePreview(pTree);
// Enable Extract for any selected node (file, folder, or root)
EnableWindow(app.hButtonExctact, TRUE);
}
}
else if (hdr->code == TVN_ITEMEXPANDING) {
if (ntv->action == TVE_EXPAND) {
pTree = (kukdh1::Tree *)ntv->itemNew.lParam;
if (pTree != nullptr) {
HANDLE hThread = CreateThread(nullptr, 0, AddThread, (LPVOID)pTree, 0, nullptr);
CloseHandle(hThread);
}
}
}
}
}
return 0;
case WM_CONTEXTMENU:
// Right-click on the main TreeView — show an Extract popup
if ((HWND)wParam == app.hTreeFileSystem) {
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
TVHITTESTINFO ht = {};
ht.pt = pt;
ScreenToClient(app.hTreeFileSystem, &ht.pt);
HTREEITEM hHit = TreeView_HitTest(app.hTreeFileSystem, &ht);
if (hHit && (ht.flags & TVHT_ONITEM)) {
TreeView_SelectItem(app.hTreeFileSystem, hHit);
TVITEM tvi = {};
tvi.hItem = hHit;
tvi.mask = TVIF_PARAM;
TreeView_GetItem(app.hTreeFileSystem, &tvi);
if (tvi.lParam) {
HMENU hMenu = CreatePopupMenu();
AppendMenuW(hMenu, MF_STRING | (app.bBusy ? MF_GRAYED : 0), 1, L"Extract");
int cmd = TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_RIGHTBUTTON, pt.x, pt.y, 0, hWnd, nullptr);
DestroyMenu(hMenu);
if (cmd == 1 && !app.bBusy) {
HANDLE hThread = CreateThread(nullptr, 0, ExtractThread, (LPVOID)tvi.lParam, 0, nullptr);
CloseHandle(hThread);
}
}
}
return 0;
}
break;
// ── UAH dark menu-bar painting ───────────────────────────────────────────
case WM_UAHDRAWMENU:
{
auto *p = reinterpret_cast<UAHMENU*>(lParam);
MENUBARINFO mbi = { sizeof(mbi) };
if (GetMenuBarInfo(hWnd, OBJID_MENU, 0, &mbi)) {
RECT rcWindow; GetWindowRect(hWnd, &rcWindow);
RECT rc = mbi.rcBar;
OffsetRect(&rc, -rcWindow.left, -rcWindow.top);
FillRect(p->hdc, &rc, app.hBrushBg);
}
return 0;
}
case WM_UAHDRAWMENUITEM:
{
auto *p = reinterpret_cast<UAHDRAWMENUITEM*>(lParam);
bool sel = (p->dis.itemState & ODS_SELECTED) != 0;
bool hot = (p->dis.itemState & ODS_HOTLIGHT) != 0;
HBRUSH hBr = (sel || hot) ? app.hBrushPanel : app.hBrushBg;
FillRect(p->dis.hDC, &p->dis.rcItem, hBr);
wchar_t buf[256] = {};
MENUITEMINFOW mii = {}; mii.cbSize = sizeof(mii);
mii.fMask = MIIM_STRING; mii.dwTypeData = buf; mii.cch = _countof(buf);
GetMenuItemInfoW(GetMenu(hWnd), p->dis.itemID, FALSE, &mii);
SetTextColor(p->dis.hDC, CLR_DARK_TEXT);
SetBkMode(p->dis.hDC, TRANSPARENT);
if (app.hFont) SelectObject(p->dis.hDC, app.hFont);
DrawTextW(p->dis.hDC, buf, -1, &p->dis.rcItem,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
return 0;
}
}
return DefWindowProc(hWnd, iMessage, wParam, lParam);
}
// ─────────────────────────────────────────────────────────────────────────────
// Open PAZ folder — shared by Open button, menu, and Rebuild Cache
// ─────────────────────────────────────────────────────────────────────────────
void OpenPazFolder(HWND hWnd, const std::wstring &folderPath) {
// Reset UI
TreeView_DeleteAllItems(app.hTreeFileSystem);
SendMessage(app.hStaticInfo, WM_SETTEXT, 0, (LPARAM)L"");
if (app.hPreviewBitmap) { DeleteObject(app.hPreviewBitmap); app.hPreviewBitmap = nullptr; }
InvalidateRect(app.hPreviewPanel, nullptr, TRUE);
SendMessage(app.hStatusBar, SB_SETTEXT, 2, (LPARAM)L"");
app.CTree.reset();
app.CMeta.reset();
app.wsFolderPath = folderPath;
app.CSetting.setData(SETTING_LAST_FOLDER, app.wsFolderPath);
WCHAR titleBuf[MAX_PATH + 64];
swprintf_s(titleBuf, app.CSetting.getString(kukdh1::Setting::ID_CAPTION_WITH_PATH).c_str(), app.wsFolderPath.c_str());
SetWindowText(hWnd, titleBuf);
try {
app.CMeta = std::make_unique<kukdh1::Meta>((wchar_t *)app.wsFolderPath.c_str());
app.CTree = std::make_unique<kukdh1::Tree>(kukdh1::Tree::TREE_TYPE_ROOT);
// Use cache if available and up-to-date, otherwise do full PAZ scan
if (kukdh1::IsCacheValid(app.wsFolderPath)) {
HANDLE hThread = CreateThread(nullptr, 0, CacheLoadThread, nullptr, 0, nullptr);
CloseHandle(hThread);
} else {
HANDLE hThread = CreateThread(nullptr, 0, FileThread, nullptr, 0, nullptr);
CloseHandle(hThread);
}
}
catch (const std::exception &e) {
std::wstring msg;
int len = MultiByteToWideChar(CP_ACP, 0, e.what(), -1, nullptr, 0);
if (len > 0) { msg.resize(len - 1); MultiByteToWideChar(CP_ACP, 0, e.what(), -1, msg.data(), len); }
if (msg.empty()) msg = app.CSetting.getString(kukdh1::Setting::ID_NO_META_FILE_EXISTS);
MessageBox(hWnd, msg.c_str(), app.CSetting.getString(kukdh1::Setting::ID_ALERT).c_str(), MB_OK);
app.CMeta.reset();
app.wsFolderPath.clear();
SetWindowText(hWnd, app.CSetting.getString(kukdh1::Setting::ID_CAPTION).c_str());
}
}
// ─────────────────────────────────────────────────────────────────────────────
// Cache load thread — fast path when paz_cache.bin is current
// ─────────────────────────────────────────────────────────────────────────────
DWORD WINAPI CacheLoadThread(LPVOID) {
app.bBusy = true;
EnableWindow(app.hTreeFileSystem, FALSE);
EnableWindow(app.hButtonLoad, FALSE);
EnableWindow(app.hButtonOpen, FALSE);
EnableWindow(app.hButtonExctact, FALSE);
SendMessage(app.hStatusBar, SB_SETTEXT, 0, (LPARAM)app.CSetting.getString(kukdh1::Setting::ID_STATUS_BUSY).c_str());
SendMessage(app.hStatusBar, SB_SETTEXT, 2, (LPARAM)L"Loading from cache...");
uint32_t pazVersion = 0, pazFileCount = 0;
bool ok = kukdh1::LoadCache(app.wsFolderPath, app.CTree.get(), pazVersion, pazFileCount);
if (!ok) {
// Cache corrupt or stale — fall back to full scan
DeleteFileW(kukdh1::CachePath(app.wsFolderPath).c_str());
app.CTree = std::make_unique<kukdh1::Tree>(kukdh1::Tree::TREE_TYPE_ROOT);
EnableWindow(app.hTreeFileSystem, TRUE);
EnableWindow(app.hButtonLoad, TRUE);
EnableWindow(app.hButtonOpen, TRUE);
EnableWindow(app.hButtonExctact, FALSE); // stays disabled until a file node is selected
app.bBusy = false;
PostMessage(GetParent(app.hTreeFileSystem), WM_APP_LOAD_FALLBACK, 0, 0);
return 0;
}
SendMessage(app.hStatusBar, SB_SETTEXT, 2, (LPARAM)L"Sorting...");
app.CTree->SortChild();
app.CTree->UpdateCapacity();
SendMessage(app.hStatusBar, SB_SETTEXT, 2, (LPARAM)L"Building tree...");
app.CTree->AddToTree(app.hTreeFileSystem);
app.CTree->AddChildsToTree(app.hTreeFileSystem);
SendMessage(app.hProgressBar, PBM_SETPOS, 0, 0);
SendMessage(app.hStatusBar, SB_SETTEXT, 0, (LPARAM)app.CSetting.getString(kukdh1::Setting::ID_STATUS_IDLE).c_str());
SendMessage(app.hStatusBar, SB_SETTEXT, 2, (LPARAM)app.CSetting.getString(kukdh1::Setting::ID_PROGRESS_READY).c_str());
EnableWindow(app.hButtonLoad, TRUE);
EnableWindow(app.hButtonOpen, TRUE);
EnableWindow(app.hButtonExctact, FALSE); // stays disabled until a file node is selected
EnableWindow(app.hTreeFileSystem, TRUE);
TreeView_Select(app.hTreeFileSystem, app.CTree->GetHandle(), TVGN_CARET);
TreeView_Expand(app.hTreeFileSystem, app.CTree->GetHandle(), TVE_EXPAND);
app.bBusy = false;
return 0;
}
// ─────────────────────────────────────────────────────────────────────────────
// Settings dialog
// ─────────────────────────────────────────────────────────────────────────────
#define IDC_EDIT_PAZ 101
#define IDC_EDIT_EXTRACT 102
#define IDC_BTN_BROWSE_PAZ 103
#define IDC_BTN_BROWSE_EXTRACT 104
#define IDC_BTN_SAVE 105
#define IDC_BTN_CANCEL 106
#define IDC_LBL_PAZ 107
#define IDC_LBL_EXTRACT 108
// Helper: apply dark colours to a settings-dialog control DC
static LRESULT SettingsDlgColor(HDC hdc, HBRUSH hBrush, COLORREF text, COLORREF bg) {
SetTextColor(hdc, text);
SetBkColor(hdc, bg);
return (LRESULT)hBrush;
}
LRESULT CALLBACK SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_CREATE:
{
BOOL dark = TRUE;
DwmSetWindowAttribute(hDlg, DWMWA_USE_IMMERSIVE_DARK_MODE, &dark, sizeof(dark));
HINSTANCE hInst = ((LPCREATESTRUCT)lParam)->hInstance;
// Layout constants — all in client coordinates
int W = 520, pad = 14, labelH = 18, editH = 26, btnW = 88, btnH = 28;
int y = pad;
// PAZ Folder row
CreateWindow(WC_STATIC, L"PAZ Folder (pad00000.meta location):", WS_CHILD|WS_VISIBLE,
pad, y, W-2*pad, labelH, hDlg, (HMENU)IDC_LBL_PAZ, hInst, nullptr);
y += labelH + 4;
CreateWindow(WC_EDIT, nullptr, WS_CHILD|WS_VISIBLE|WS_BORDER|ES_AUTOHSCROLL,
pad, y, W-2*pad-btnW-8, editH, hDlg, (HMENU)IDC_EDIT_PAZ, hInst, nullptr);
CreateWindow(WC_BUTTON, L"Browse", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
W-pad-btnW, y, btnW, editH, hDlg, (HMENU)IDC_BTN_BROWSE_PAZ, hInst, nullptr);
y += editH + pad;
// Extract Path row
CreateWindow(WC_STATIC, L"Default Extract Path:", WS_CHILD|WS_VISIBLE,
pad, y, W-2*pad, labelH, hDlg, (HMENU)IDC_LBL_EXTRACT, hInst, nullptr);
y += labelH + 4;
CreateWindow(WC_EDIT, nullptr, WS_CHILD|WS_VISIBLE|WS_BORDER|ES_AUTOHSCROLL,
pad, y, W-2*pad-btnW-8, editH, hDlg, (HMENU)IDC_EDIT_EXTRACT, hInst, nullptr);
CreateWindow(WC_BUTTON, L"Browse", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
W-pad-btnW, y, btnW, editH, hDlg, (HMENU)IDC_BTN_BROWSE_EXTRACT, hInst, nullptr);
y += editH + pad;
// Save / Cancel buttons (right-aligned)
CreateWindow(WC_BUTTON, L"Save", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_DEFPUSHBUTTON,
W - 2*btnW - pad - 8, y, btnW, btnH, hDlg, (HMENU)IDC_BTN_SAVE, hInst, nullptr);
CreateWindow(WC_BUTTON, L"Cancel", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
W - btnW - pad, y, btnW, btnH, hDlg, (HMENU)IDC_BTN_CANCEL, hInst, nullptr);
// Set font on all children
EnumChildWindows(hDlg, [](HWND hChild, LPARAM lp) -> BOOL {
SendMessage(hChild, WM_SETFONT, lp, TRUE);
return TRUE;
}, (LPARAM)app.hFont);
// Populate saved paths
std::wstring paz, ext;
app.CSetting.getData(SETTING_LAST_FOLDER, paz, L"");
app.CSetting.getData(SETTING_LAST_EXTRACT, ext, L"");
SetWindowTextW(GetDlgItem(hDlg, IDC_EDIT_PAZ), paz.c_str());
SetWindowTextW(GetDlgItem(hDlg, IDC_EDIT_EXTRACT), ext.c_str());
return 0;
}
case WM_CTLCOLOREDIT:
return SettingsDlgColor((HDC)wParam, app.hBrushInput, CLR_DARK_TEXT, CLR_DARK_INPUT);
case WM_CTLCOLORSTATIC:
return SettingsDlgColor((HDC)wParam, app.hBrushBg, CLR_DARK_TEXT, CLR_DARK_BG);
case WM_CTLCOLORBTN:
return SettingsDlgColor((HDC)wParam, app.hBrushPanel, CLR_DARK_TEXT, CLR_DARK_PANEL);
case WM_ERASEBKGND:
{
RECT rc; GetClientRect(hDlg, &rc);
FillRect((HDC)wParam, &rc, app.hBrushBg);
return 1;
}
case WM_COMMAND:
{
int ctrl = LOWORD(wParam);
if (ctrl == IDC_BTN_BROWSE_PAZ || ctrl == IDC_BTN_BROWSE_EXTRACT) {
bool isPaz = (ctrl == IDC_BTN_BROWSE_PAZ);
int editId = isPaz ? IDC_EDIT_PAZ : IDC_EDIT_EXTRACT;
WCHAR cur[MAX_PATH] = {};
GetWindowTextW(GetDlgItem(hDlg, editId), cur, MAX_PATH);
std::wstring chosen;
const wchar_t *prompt = isPaz
? L"Select PAZ folder (containing pad00000.meta)"
: L"Select default extract folder";
if (kukdh1::BrowseFolder(hDlg, prompt, cur, chosen))
SetWindowTextW(GetDlgItem(hDlg, editId), chosen.c_str());
} else if (ctrl == IDC_BTN_SAVE) {
WCHAR paz[MAX_PATH] = {}, ext[MAX_PATH] = {};
GetWindowTextW(GetDlgItem(hDlg, IDC_EDIT_PAZ), paz, MAX_PATH);
GetWindowTextW(GetDlgItem(hDlg, IDC_EDIT_EXTRACT), ext, MAX_PATH);
app.CSetting.setData(SETTING_LAST_FOLDER, std::wstring(paz));
app.CSetting.setData(SETTING_LAST_EXTRACT, std::wstring(ext));
app.CSetting.Save();
DestroyWindow(hDlg);
} else if (ctrl == IDC_BTN_CANCEL) {
DestroyWindow(hDlg);
}
return 0;
}
case WM_CLOSE:
DestroyWindow(hDlg);
return 0;
case WM_DESTROY:
EnableWindow(GetWindow(hDlg, GW_OWNER), TRUE);
SetForegroundWindow(GetWindow(hDlg, GW_OWNER));
return 0;
}
return DefWindowProc(hDlg, msg, wParam, lParam);
}
void ShowSettingsDialog(HWND hParent) {