-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdialogs.cpp
More file actions
1439 lines (1291 loc) · 57.4 KB
/
Copy pathdialogs.cpp
File metadata and controls
1439 lines (1291 loc) · 57.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
// ═══════════════════════════════════════════════════════════════════════
// dialogs.cpp — see dialogs.h for the public interface
// ═══════════════════════════════════════════════════════════════════════
//
// Implements the six themed modal dialogs. Each dialog has its own
// wndproc (file-static) that paints a stone backdrop + gold border
// + content, owner-draws its buttons via MainProc's WM_DRAWITEM
// pipeline, and runs a local message pump until the user clicks
// a button or closes the window.
//
// WM_DRAWITEM forwarding: every dialog proc's WM_DRAWITEM case
// calls PaintOwnerDrawButton (in buttons.cpp) so dialog buttons get
// the same NexusUpdate visuals as the main window's controls.
#include "dialogs.h"
#include "core.h" // g_hwMain, g_hInst, g_dpiScale
#include "scaling.h" // S, SF, U, MemDC
#include "colors.h" // Tok::Gold, Tok::Bronze, GP/GPA
#include "assets.h" // AssetImage, DrawAssetStretched
#include "fonts.h" // g_fModName, g_fBtn, g_fNavSm, ...
#include "layout.h" // LO:: constants
#include "config.h" // g_cfg, SaveCfg
#include "update_cache.h"
#include "control_ids.h" // IDC_LAUNCHER_RESTART_BTN, IDM_*
#include "mod_types.h"
#include "launcher_self_update.h" // g_launcherUpdateLatestTag, g_forceUpdatePrompt,
// StartLauncherUpdateInstall
#include "buttons.h" // ButtonKind, MkStdBtn, PaintOwnerDrawButton
// Owner-drawn button paint is delegated to buttons.cpp via
// PaintOwnerDrawButton. Each dialog wndproc forwards its WM_DRAWITEM
// to that helper so dialog buttons paint identically to main-window
// buttons (same asset frames, same hover/click transforms, same gold
// text treatment).
// SetPath dialog re-uses Angiris.cpp's existing SHBrowseForFolder
// helper rather than duplicating the picker logic here. Defined in
// Angiris.cpp; non-static since Phase 7a/7b extraction.
extern bool PromptForD2RPath(HWND parent);
// ─────────────────────────────────────────────────────────────────────────
// CONFLICT DIALOG (themed modal — "Mod Folder Already Exists")
// ─────────────────────────────────────────────────────────────────────────
//
// Shown by the zip-install worker when a dropped mod's target folder
// already exists. Three NexusUpdate-styled buttons:
//
// Update → keep folder, copy only files whose paths exist in dest
// (per the user's strict reading of "Update only overwrites
// files found in the archive that are also found in the
// folder")
// Overwrite → wipe folder, extract fresh
// Cancel → leave folder untouched, skip to next queued zip
//
// The dialog uses bg_stone.png as its background (same texture as the
// loader-options panel for visual continuity) with a gold border and
// renders all text in g_fModName so it picks up the user's selected
// font automatically.
//
// Modal mechanics: the worker thread SendMessages into MainProc, which
// calls ShowConflictDialog inline. ShowConflictDialog runs a local
// message pump so the parent stays responsive (in terms of paint /
// non-input messages) while input is gated to the dialog via
// EnableWindow(parent, FALSE).
//
// Button paint is delegated back to MainProc's WM_DRAWITEM handler —
// MainProc's WM_DRAWITEM doesn't depend on the parent being g_hwMain,
// only on the d->hwndItem button HWND, so direct re-entry works.
static const wstring* g_dlgModNamePtr = nullptr; // shared with paint
static HWND g_conflictDlg = nullptr; // for re-entry guard
static LRESULT CALLBACK ConflictDlgProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp) {
switch (msg) {
case WM_ERASEBKGND: return 1; // suppress flicker; WM_PAINT fills
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hw, &ps);
RECT rc; GetClientRect(hw, &rc);
int W = rc.right, H = rc.bottom;
// Double-buffer to avoid the asset-blit flicker when the user
// drags between buttons.
HDC memDC = CreateCompatibleDC(hdc);
HBITMAP memBM = CreateCompatibleBitmap(hdc, W, H);
HBITMAP oldBM = (HBITMAP)SelectObject(memDC, memBM);
{
Graphics g(memDC);
g.SetSmoothingMode(SmoothingModeAntiAlias);
g.SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
// Stone background — same source as the loader-options panel.
// Cropped from the upper-left region of bg_stone so the
// texture variation reads consistent with the main window.
Bitmap* stone = AssetImage(L"bg_stone.png");
if (stone) {
int sw = (int)stone->GetWidth();
int sh = (int)stone->GetHeight();
// Crop a tile-sized region: the dialog is much smaller
// than the full asset, so use a top-left slice that
// matches the loader-options panel's sampling area.
int cropW = (sw < W) ? sw : W;
int cropH = (sh < H) ? sh : H;
Rect dst(0, 0, W, H);
g.DrawImage(stone, dst, 40, 40, cropW, cropH, UnitPixel);
} else {
SolidBrush bg(Color(28, 24, 20));
g.FillRectangle(&bg, 0, 0, W, H);
}
// Gold border (2 px) — matches the main window frame.
Pen border(Tok::Gold, 2.0f);
g.DrawRectangle(&border, 1, 1, W - 3, H - 3);
// Inner darker pen for the engraved feel.
Pen innerB(Tok::Bronze, 1.0f);
g.DrawRectangle(&innerB, 3, 3, W - 7, H - 7);
// Text — uses g_fModName so the user's selected font applies.
SolidBrush textBr(Tok::TextParchment);
SolidBrush goldBr(Tok::Gold);
StringFormat sf;
sf.SetAlignment(StringAlignmentCenter);
sf.SetLineAlignment(StringAlignmentNear);
sf.SetFormatFlags(sf.GetFormatFlags() | StringFormatFlagsNoWrap);
int padX = (int)(24 * g_dpiScale);
int y = (int)(18 * g_dpiScale);
int lineH= (int)(30 * g_dpiScale);
// Title — "Mod Folder Already Exists" in gold accent.
g.DrawString(L"Mod Folder Already Exists", -1,
g_fModName ? g_fModName : g_fBtn,
RectF((REAL)padX, (REAL)y,
(REAL)(W - 2 * padX), (REAL)lineH),
&sf, &goldBr);
y += lineH;
// Mod name in quotes on its own line.
if (g_dlgModNamePtr && !g_dlgModNamePtr->empty()) {
wstring nm = L"\u201C" + *g_dlgModNamePtr + L"\u201D";
g.DrawString(nm.c_str(), -1,
g_fModName ? g_fModName : g_fBtn,
RectF((REAL)padX, (REAL)y,
(REAL)(W - 2 * padX), (REAL)lineH),
&sf, &textBr);
}
y += lineH;
y += (int)(8 * g_dpiScale);
// Per-action descriptions — small body text, multi-line.
int descY = y;
int descLH = (int)(20 * g_dpiScale);
sf.SetLineAlignment(StringAlignmentCenter);
auto descLine = [&](const wchar_t* s) {
g.DrawString(s, -1, g_fBtn,
RectF((REAL)padX, (REAL)descY,
(REAL)(W - 2 * padX), (REAL)descLH),
&sf, &textBr);
descY += descLH;
};
descLine(L"Update overwrites only files present in the archive that already exist in the folder.");
descLine(L"Overwrite erases the folder and extracts the archive fresh.");
descLine(L"Cancel leaves the folder untouched.");
}
BitBlt(hdc, 0, 0, W, H, memDC, 0, 0, SRCCOPY);
SelectObject(memDC, oldBM);
DeleteObject(memBM);
DeleteDC(memDC);
EndPaint(hw, &ps);
return 0;
}
case WM_DRAWITEM: {
// Re-enter MainProc's WM_DRAWITEM so the dialog's owner-drawn
// buttons paint with the same NexusUpdate visuals as the main
// window's. MainProc keys off d->hwndItem, not the parent.
if (PaintOwnerDrawButton((DRAWITEMSTRUCT*)lp)) return TRUE;
return DefWindowProc(hw, msg, wp, lp);
}
case WM_COMMAND: {
int id = LOWORD(wp);
int* res = (int*)GetWindowLongPtrW(hw, GWLP_USERDATA);
if (res) {
if (id == 1) *res = 1; // Update
else if (id == 2) *res = 2; // Overwrite
else if (id == 3) *res = 0; // Cancel
}
if (id >= 1 && id <= 3) DestroyWindow(hw);
return 0;
}
case WM_CLOSE: {
int* res = (int*)GetWindowLongPtrW(hw, GWLP_USERDATA);
if (res) *res = 0;
DestroyWindow(hw);
return 0;
}
case WM_DESTROY: {
if (g_conflictDlg == hw) g_conflictDlg = nullptr;
return 0;
}
}
return DefWindowProcW(hw, msg, wp, lp);
}
// Show the modal conflict dialog on the UI thread. Blocks until the user
// picks an action; returns 0=cancel / 1=update / 2=overwrite.
int ShowConflictDialog(HWND parent, const wstring& modName) {
// Re-entry guard: shouldn't happen (worker SendMessages serially),
// but if it ever does, decline the inner call rather than stack two
// modal pumps.
if (g_conflictDlg) return 0;
static bool classReg = false;
if (!classReg) {
WNDCLASSEXW wc = { sizeof(wc) };
wc.lpfnWndProc = ConflictDlgProc;
wc.hInstance = GetModuleHandleW(nullptr);
wc.lpszClassName = L"AngirisConflictDlg";
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
wc.hbrBackground = nullptr;
RegisterClassExW(&wc);
classReg = true;
}
// Dialog size in PHYSICAL pixels — scaled by DPI only (not by
// g_userScale; the dialog isn't part of the user-scaled UI body).
int dlgW = (int)(560 * g_dpiScale);
int dlgH = (int)(280 * g_dpiScale);
// Center on parent. AdjustWindowRectEx adds caption + border so the
// CLIENT area ends up at dlgW × dlgH after the WS_CAPTION decoration.
RECT pr; GetWindowRect(parent, &pr);
RECT clientReq = { 0, 0, dlgW, dlgH };
AdjustWindowRectEx(&clientReq, WS_POPUP | WS_CAPTION, FALSE, WS_EX_DLGMODALFRAME);
int winW = clientReq.right - clientReq.left;
int winH = clientReq.bottom - clientReq.top;
int cx = (pr.left + pr.right) / 2 - winW / 2;
int cy = (pr.top + pr.bottom) / 2 - winH / 2;
int result = 0;
g_dlgModNamePtr = &modName;
HWND dlg = CreateWindowExW(
WS_EX_DLGMODALFRAME | WS_EX_TOPMOST,
L"AngirisConflictDlg",
L"Mod Folder Already Exists",
WS_POPUP | WS_CAPTION,
cx, cy, winW, winH,
parent, nullptr, GetModuleHandleW(nullptr), nullptr);
if (!dlg) {
g_dlgModNamePtr = nullptr;
return 0;
}
g_conflictDlg = dlg;
SetWindowLongPtrW(dlg, GWLP_USERDATA, (LONG_PTR)&result);
// Three NexusUpdate-styled buttons at the bottom of the client area.
// The native NexusUpdate asset is 254×54 — for the dialog we scale
// down to ~170×46 (physical px) so all three fit comfortably inside
// the 560 px dialog without their decorative edges bleeding into
// the bronze border. Outer buttons get an additional 5 px inward
// nudge so the left/right border padding is symmetric (was a tight
// fit before — at 1.0 DPI scale the row was 568 wide in a 560
// dialog and the outer chevron ornaments bled over the frame).
int btnW = (int)(170 * g_dpiScale);
int btnH = (int)(46 * g_dpiScale);
int btnGap = (int)(14 * g_dpiScale);
int nudge = (int)( 5 * g_dpiScale); // outer buttons toward center
RECT cr; GetClientRect(dlg, &cr);
int rowW = 3 * btnW + 2 * btnGap;
int rowX0 = (cr.right - rowW) / 2;
int rowY = cr.bottom - btnH - (int)(20 * g_dpiScale);
MkStdBtn(dlg, L"Update", 1, rowX0 + nudge, rowY, btnW, btnH,
true, ButtonKind::NexusUpdate);
MkStdBtn(dlg, L"Overwrite", 2, rowX0 + (btnW + btnGap), rowY, btnW, btnH,
true, ButtonKind::NexusUpdate);
MkStdBtn(dlg, L"Cancel", 3, rowX0 + 2 * (btnW + btnGap) - nudge, rowY, btnW, btnH,
true, ButtonKind::NexusUpdate);
ShowWindow(dlg, SW_SHOW);
UpdateWindow(dlg);
EnableWindow(parent, FALSE);
// Local modal pump — runs until the dialog is destroyed (one of the
// three buttons clicked, the close box, or Esc). IsDialogMessageW
// handles Tab cycling between the buttons automatically.
MSG msg;
bool done = false;
while (!done) {
BOOL got = GetMessageW(&msg, nullptr, 0, 0);
if (got <= 0) {
// WM_QUIT or error — break out without committing a choice.
if (got == 0) PostQuitMessage((int)msg.wParam);
done = true;
break;
}
// Esc = cancel, Enter = update (the safe default).
if (msg.message == WM_KEYDOWN && msg.hwnd == dlg) {
if (msg.wParam == VK_ESCAPE) {
result = 0;
done = true;
break;
}
if (msg.wParam == VK_RETURN) {
result = 1;
done = true;
break;
}
}
if (!IsDialogMessageW(dlg, &msg)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
if (!IsWindow(dlg)) done = true;
}
EnableWindow(parent, TRUE);
SetForegroundWindow(parent);
if (IsWindow(dlg)) DestroyWindow(dlg);
g_dlgModNamePtr = nullptr;
g_conflictDlg = nullptr;
return result;
}
// ─────────────────────────────────────────────────────────────────────────
// LAUNCHER UPDATE DIALOG (themed modal — Update / Skip Version / Ignore)
// ─────────────────────────────────────────────────────────────────────────
//
// Same paint/dispatch pattern as ConflictDlg: stone background, gold +
// bronze border, three NexusUpdate-styled buttons, Esc = Ignore,
// Enter = Update. State travels via two file-scope pointers so the
// paint code can show the live tag values; the result lands in an int
// pointed to by GWLP_USERDATA so the modal pump can return it.
static const wstring* g_dlgLatestTagPtr = nullptr;
static const wstring* g_dlgCurrentTagPtr = nullptr;
static HWND g_launcherUpdateDlg = nullptr;
static LRESULT CALLBACK LauncherUpdateDlgProc(HWND hw, UINT msg,
WPARAM wp, LPARAM lp) {
switch (msg) {
case WM_ERASEBKGND: return 1;
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hw, &ps);
RECT rc; GetClientRect(hw, &rc);
int W = rc.right, H = rc.bottom;
HDC memDC = CreateCompatibleDC(hdc);
HBITMAP memBM = CreateCompatibleBitmap(hdc, W, H);
HBITMAP oldBM = (HBITMAP)SelectObject(memDC, memBM);
{
Graphics g(memDC);
g.SetSmoothingMode(SmoothingModeAntiAlias);
g.SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
Bitmap* stone = AssetImage(L"bg_stone.png");
if (stone) {
int sw = (int)stone->GetWidth();
int sh = (int)stone->GetHeight();
int cropW = (sw < W) ? sw : W;
int cropH = (sh < H) ? sh : H;
Rect dst(0, 0, W, H);
g.DrawImage(stone, dst, 40, 40, cropW, cropH, UnitPixel);
} else {
SolidBrush bg(Color(28, 24, 20));
g.FillRectangle(&bg, 0, 0, W, H);
}
Pen border(Tok::Gold, 2.0f);
g.DrawRectangle(&border, 1, 1, W - 3, H - 3);
Pen innerB(Tok::Bronze, 1.0f);
g.DrawRectangle(&innerB, 3, 3, W - 7, H - 7);
SolidBrush textBr(Tok::TextParchment);
SolidBrush goldBr(Tok::Gold);
StringFormat sf;
sf.SetAlignment(StringAlignmentCenter);
sf.SetLineAlignment(StringAlignmentNear);
sf.SetFormatFlags(sf.GetFormatFlags() | StringFormatFlagsNoWrap);
int padX = (int)(24 * g_dpiScale);
int y = (int)(18 * g_dpiScale);
int lineH = (int)(30 * g_dpiScale);
Font* titleFont = g_fModName ? g_fModName : g_fBtn;
g.DrawString(L"Launcher Update Available", -1, titleFont,
RectF((REAL)padX, (REAL)y,
(REAL)(W - 2 * padX), (REAL)lineH),
&sf, &goldBr);
y += lineH;
// Version line: "Version <latest> is available (current <vN>)"
wstring versionLine = L"Version ";
versionLine += (g_dlgLatestTagPtr && !g_dlgLatestTagPtr->empty())
? *g_dlgLatestTagPtr : L"?";
versionLine += L" is available (you have ";
versionLine += (g_dlgCurrentTagPtr && !g_dlgCurrentTagPtr->empty())
? *g_dlgCurrentTagPtr : L"?";
versionLine += L")";
g.DrawString(versionLine.c_str(), -1, titleFont,
RectF((REAL)padX, (REAL)y,
(REAL)(W - 2 * padX), (REAL)lineH),
&sf, &textBr);
y += lineH;
y += (int)(8 * g_dpiScale);
// Per-action descriptions — same descLine pattern as
// ShowConflictDialog so the visual rhythm matches.
int descY = y;
int descLH = (int)(20 * g_dpiScale);
sf.SetLineAlignment(StringAlignmentCenter);
auto descLine = [&](const wchar_t* s) {
g.DrawString(s, -1, g_fBtn,
RectF((REAL)padX, (REAL)descY,
(REAL)(W - 2 * padX), (REAL)descLH),
&sf, &textBr);
descY += descLH;
};
descLine(L"Update downloads the new release and replaces the running launcher.");
descLine(L"Skip Version stops prompting for this release; you'll be notified for newer ones.");
descLine(L"Ignore continues normally and re-prompts on the next launch.");
}
BitBlt(hdc, 0, 0, W, H, memDC, 0, 0, SRCCOPY);
SelectObject(memDC, oldBM);
DeleteObject(memBM);
DeleteDC(memDC);
EndPaint(hw, &ps);
return 0;
}
case WM_DRAWITEM:
// Re-enter MainProc's WM_DRAWITEM so the buttons paint as
// NexusUpdate just like ConflictDlg's do. Owner-drawn buttons
// key off d->hwndItem, so the dispatching window doesn't have
// to be g_hwMain.
if (PaintOwnerDrawButton((DRAWITEMSTRUCT*)lp)) return TRUE;
return DefWindowProc(hw, msg, wp, lp);
case WM_COMMAND: {
int id = LOWORD(wp);
int* res = (int*)GetWindowLongPtrW(hw, GWLP_USERDATA);
if (res) {
if (id == 1) *res = 1; // Update
else if (id == 2) *res = 2; // Skip Version
else if (id == 3) *res = 0; // Ignore
}
if (id >= 1 && id <= 3) DestroyWindow(hw);
return 0;
}
case WM_CLOSE: {
int* res = (int*)GetWindowLongPtrW(hw, GWLP_USERDATA);
if (res) *res = 0;
DestroyWindow(hw);
return 0;
}
case WM_DESTROY:
if (g_launcherUpdateDlg == hw) g_launcherUpdateDlg = nullptr;
return 0;
}
return DefWindowProcW(hw, msg, wp, lp);
}
int ShowLauncherUpdateDialog(HWND parent, const wstring& latestTag) {
if (g_launcherUpdateDlg) return 0; // re-entry guard
static bool classReg = false;
if (!classReg) {
WNDCLASSEXW wc = { sizeof(wc) };
wc.lpfnWndProc = LauncherUpdateDlgProc;
wc.hInstance = GetModuleHandleW(nullptr);
wc.lpszClassName = L"AngirisLauncherUpdateDlg";
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
wc.hbrBackground = nullptr;
RegisterClassExW(&wc);
classReg = true;
}
int dlgW = (int)(560 * g_dpiScale);
int dlgH = (int)(260 * g_dpiScale);
RECT pr; GetWindowRect(parent, &pr);
RECT clientReq = { 0, 0, dlgW, dlgH };
AdjustWindowRectEx(&clientReq, WS_POPUP | WS_CAPTION, FALSE, WS_EX_DLGMODALFRAME);
int winW = clientReq.right - clientReq.left;
int winH = clientReq.bottom - clientReq.top;
int cx = (pr.left + pr.right) / 2 - winW / 2;
int cy = (pr.top + pr.bottom) / 2 - winH / 2;
int result = 0;
wstring currentVer = LAUNCHER_VERSION;
g_dlgLatestTagPtr = &latestTag;
g_dlgCurrentTagPtr = ¤tVer;
HWND dlg = CreateWindowExW(
WS_EX_DLGMODALFRAME | WS_EX_TOPMOST,
L"AngirisLauncherUpdateDlg",
L"Launcher Update Available",
WS_POPUP | WS_CAPTION,
cx, cy, winW, winH,
parent, nullptr, GetModuleHandleW(nullptr), nullptr);
if (!dlg) {
g_dlgLatestTagPtr = g_dlgCurrentTagPtr = nullptr;
return 0;
}
g_launcherUpdateDlg = dlg;
SetWindowLongPtrW(dlg, GWLP_USERDATA, (LONG_PTR)&result);
// Same three-button row geometry as the conflict dialog so the
// two share a visual rhythm.
int btnW = (int)(170 * g_dpiScale);
int btnH = (int)(46 * g_dpiScale);
int btnGap = (int)(14 * g_dpiScale);
int nudge = (int)( 5 * g_dpiScale);
RECT cr; GetClientRect(dlg, &cr);
int rowW = 3 * btnW + 2 * btnGap;
int rowX0 = (cr.right - rowW) / 2;
int rowY = cr.bottom - btnH - (int)(20 * g_dpiScale);
MkStdBtn(dlg, L"Update", 1, rowX0 + nudge, rowY, btnW, btnH,
true, ButtonKind::NexusUpdate);
MkStdBtn(dlg, L"Skip Version", 2, rowX0 + (btnW + btnGap), rowY, btnW, btnH,
true, ButtonKind::NexusUpdate);
MkStdBtn(dlg, L"Ignore", 3, rowX0 + 2 * (btnW + btnGap) - nudge, rowY, btnW, btnH,
true, ButtonKind::NexusUpdate);
ShowWindow(dlg, SW_SHOW);
UpdateWindow(dlg);
EnableWindow(parent, FALSE);
MSG msg;
bool done = false;
while (!done) {
BOOL got = GetMessageW(&msg, nullptr, 0, 0);
if (got <= 0) {
if (got == 0) PostQuitMessage((int)msg.wParam);
done = true; break;
}
// Esc = Ignore, Enter = Update.
if (msg.message == WM_KEYDOWN && msg.hwnd == dlg) {
if (msg.wParam == VK_ESCAPE) { result = 0; done = true; break; }
if (msg.wParam == VK_RETURN) { result = 1; done = true; break; }
}
if (!IsDialogMessageW(dlg, &msg)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
if (!IsWindow(dlg)) done = true;
}
EnableWindow(parent, TRUE);
SetForegroundWindow(parent);
if (IsWindow(dlg)) DestroyWindow(dlg);
g_dlgLatestTagPtr = g_dlgCurrentTagPtr = nullptr;
g_launcherUpdateDlg = nullptr;
return result;
}
// ─────────────────────────────────────────────────────────────────────────
// NO MODINFO DIALOG (themed modal — "Zip didn't contain modinfo.json")
// ─────────────────────────────────────────────────────────────────────────
//
// Shown when a dropped zip has no modinfo.json anywhere in its tree.
// Single OK button, message names the offending zip so the user can tell
// it apart in a multi-drop. Returns nothing — the worker just skips
// this zip and moves to the next.
static const wstring* g_dlgZipNamePtr = nullptr; // shared with paint
static HWND g_noModInfoDlg = nullptr;
static LRESULT CALLBACK NoModInfoDlgProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp) {
switch (msg) {
case WM_ERASEBKGND: return 1;
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hw, &ps);
RECT rc; GetClientRect(hw, &rc);
int W = rc.right, H = rc.bottom;
HDC memDC = CreateCompatibleDC(hdc);
HBITMAP memBM = CreateCompatibleBitmap(hdc, W, H);
HBITMAP oldBM = (HBITMAP)SelectObject(memDC, memBM);
{
Graphics g(memDC);
g.SetSmoothingMode(SmoothingModeAntiAlias);
g.SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
Bitmap* stone = AssetImage(L"bg_stone.png");
if (stone) {
int sw = (int)stone->GetWidth();
int sh = (int)stone->GetHeight();
int cropW = (sw < W) ? sw : W;
int cropH = (sh < H) ? sh : H;
Rect dst(0, 0, W, H);
g.DrawImage(stone, dst, 40, 40, cropW, cropH, UnitPixel);
} else {
SolidBrush bg(Color(28, 24, 20));
g.FillRectangle(&bg, 0, 0, W, H);
}
Pen border(Tok::Gold, 2.0f);
g.DrawRectangle(&border, 1, 1, W - 3, H - 3);
Pen innerB(Tok::Bronze, 1.0f);
g.DrawRectangle(&innerB, 3, 3, W - 7, H - 7);
SolidBrush textBr(Tok::TextParchment);
SolidBrush goldBr(Tok::Gold);
StringFormat sf;
sf.SetAlignment(StringAlignmentCenter);
sf.SetLineAlignment(StringAlignmentCenter);
sf.SetFormatFlags(sf.GetFormatFlags() | StringFormatFlagsNoWrap);
int padX = (int)(24 * g_dpiScale);
int y = (int)(24 * g_dpiScale);
int lineH= (int)(30 * g_dpiScale);
// Title — "Invalid Mod Archive" in gold.
g.DrawString(L"Invalid Mod Archive", -1,
g_fModName ? g_fModName : g_fBtn,
RectF((REAL)padX, (REAL)y,
(REAL)(W - 2 * padX), (REAL)lineH),
&sf, &goldBr);
y += lineH;
y += (int)(10 * g_dpiScale);
// Body — wrapped over two lines. Don't NoWrap here because the
// zip filename can be long and we want it to break naturally
// rather than overflow the rect.
StringFormat sfWrap;
sfWrap.SetAlignment(StringAlignmentCenter);
sfWrap.SetLineAlignment(StringAlignmentNear);
int bodyH = (int)(60 * g_dpiScale);
wstring msgText = (g_dlgZipNamePtr ? *g_dlgZipNamePtr : wstring())
+ L" did not contain a modinfo.json file, please contact the mod author.";
g.DrawString(msgText.c_str(), -1, g_fBtn,
RectF((REAL)padX, (REAL)y,
(REAL)(W - 2 * padX), (REAL)bodyH),
&sfWrap, &textBr);
}
BitBlt(hdc, 0, 0, W, H, memDC, 0, 0, SRCCOPY);
SelectObject(memDC, oldBM);
DeleteObject(memBM);
DeleteDC(memDC);
EndPaint(hw, &ps);
return 0;
}
case WM_DRAWITEM:
if (PaintOwnerDrawButton((DRAWITEMSTRUCT*)lp)) return TRUE;
return DefWindowProc(hw, msg, wp, lp);
case WM_COMMAND: {
int id = LOWORD(wp);
if (id == 1) DestroyWindow(hw);
return 0;
}
case WM_CLOSE:
DestroyWindow(hw);
return 0;
case WM_DESTROY:
if (g_noModInfoDlg == hw) g_noModInfoDlg = nullptr;
return 0;
}
return DefWindowProcW(hw, msg, wp, lp);
}
void ShowNoModInfoDialog(HWND parent, const wstring& zipName) {
if (g_noModInfoDlg) return;
static bool classReg = false;
if (!classReg) {
WNDCLASSEXW wc = { sizeof(wc) };
wc.lpfnWndProc = NoModInfoDlgProc;
wc.hInstance = GetModuleHandleW(nullptr);
wc.lpszClassName = L"AngirisNoModInfoDlg";
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
RegisterClassExW(&wc);
classReg = true;
}
int dlgW = (int)(560 * g_dpiScale);
int dlgH = (int)(220 * g_dpiScale);
RECT pr; GetWindowRect(parent, &pr);
RECT clientReq = { 0, 0, dlgW, dlgH };
AdjustWindowRectEx(&clientReq, WS_POPUP | WS_CAPTION, FALSE, WS_EX_DLGMODALFRAME);
int winW = clientReq.right - clientReq.left;
int winH = clientReq.bottom - clientReq.top;
int cx = (pr.left + pr.right) / 2 - winW / 2;
int cy = (pr.top + pr.bottom) / 2 - winH / 2;
g_dlgZipNamePtr = &zipName;
HWND dlg = CreateWindowExW(
WS_EX_DLGMODALFRAME | WS_EX_TOPMOST,
L"AngirisNoModInfoDlg",
L"Invalid Mod Archive",
WS_POPUP | WS_CAPTION,
cx, cy, winW, winH,
parent, nullptr, GetModuleHandleW(nullptr), nullptr);
if (!dlg) { g_dlgZipNamePtr = nullptr; return; }
g_noModInfoDlg = dlg;
// Single centered OK button.
int btnW = (int)(160 * g_dpiScale);
int btnH = (int)(46 * g_dpiScale);
RECT cr; GetClientRect(dlg, &cr);
int btnX = (cr.right - btnW) / 2;
int btnY = cr.bottom - btnH - (int)(20 * g_dpiScale);
MkStdBtn(dlg, L"OK", 1, btnX, btnY, btnW, btnH, true, ButtonKind::NexusUpdate);
ShowWindow(dlg, SW_SHOW);
UpdateWindow(dlg);
EnableWindow(parent, FALSE);
MSG msg;
while (IsWindow(dlg)) {
BOOL got = GetMessageW(&msg, nullptr, 0, 0);
if (got <= 0) {
if (got == 0) PostQuitMessage((int)msg.wParam);
break;
}
if (msg.message == WM_KEYDOWN && msg.hwnd == dlg) {
if (msg.wParam == VK_ESCAPE || msg.wParam == VK_RETURN) {
DestroyWindow(dlg);
break;
}
}
if (!IsDialogMessageW(dlg, &msg)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
EnableWindow(parent, TRUE);
SetForegroundWindow(parent);
if (IsWindow(dlg)) DestroyWindow(dlg);
g_dlgZipNamePtr = nullptr;
g_noModInfoDlg = nullptr;
}
// ─────────────────────────────────────────────────────────────────────────
// UNINSTALL CONFIRM DIALOG (themed modal — "Delete <mod>?")
// ─────────────────────────────────────────────────────────────────────────
//
// Shown from the mod-list right-click context menu when the user picks
// Uninstall. Two NexusUpdate-styled buttons:
// Cancel → leaves the mod alone (default; Esc and the close-X also
// route here)
// Delete → returns 1 to the caller, which then DeleteFolderRecursive's
// the mod's directory
//
// Cancel is positioned on the left and is the default focus, so a
// reflexive Enter press dismisses the dialog without deleting. Delete
// requires an explicit click — there's no keyboard shortcut for it,
// because muscle memory should not be able to nuke a mod by accident.
static const wstring* g_dlgUninstallNamePtr = nullptr; // shared with paint
static HWND g_uninstallDlg = nullptr;
static LRESULT CALLBACK UninstallDlgProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp) {
switch (msg) {
case WM_ERASEBKGND: return 1;
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hw, &ps);
RECT rc; GetClientRect(hw, &rc);
int W = rc.right, H = rc.bottom;
HDC memDC = CreateCompatibleDC(hdc);
HBITMAP memBM = CreateCompatibleBitmap(hdc, W, H);
HBITMAP oldBM = (HBITMAP)SelectObject(memDC, memBM);
{
Graphics g(memDC);
g.SetSmoothingMode(SmoothingModeAntiAlias);
g.SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
Bitmap* stone = AssetImage(L"bg_stone.png");
if (stone) {
int sw = (int)stone->GetWidth();
int sh = (int)stone->GetHeight();
int cropW = (sw < W) ? sw : W;
int cropH = (sh < H) ? sh : H;
Rect dst(0, 0, W, H);
g.DrawImage(stone, dst, 40, 40, cropW, cropH, UnitPixel);
} else {
SolidBrush bg(Color(28, 24, 20));
g.FillRectangle(&bg, 0, 0, W, H);
}
Pen border(Tok::Gold, 2.0f);
g.DrawRectangle(&border, 1, 1, W - 3, H - 3);
Pen innerB(Tok::Bronze, 1.0f);
g.DrawRectangle(&innerB, 3, 3, W - 7, H - 7);
SolidBrush textBr(Tok::TextParchment);
SolidBrush goldBr(Tok::Gold);
StringFormat sf;
sf.SetAlignment(StringAlignmentCenter);
sf.SetLineAlignment(StringAlignmentCenter);
sf.SetFormatFlags(sf.GetFormatFlags() | StringFormatFlagsNoWrap);
int padX = (int)(24 * g_dpiScale);
int y = (int)(22 * g_dpiScale);
int lineH= (int)(30 * g_dpiScale);
g.DrawString(L"Delete Mod", -1,
g_fModName ? g_fModName : g_fBtn,
RectF((REAL)padX, (REAL)y,
(REAL)(W - 2 * padX), (REAL)lineH),
&sf, &goldBr);
y += lineH;
// Mod name in quotes — visually anchors which mod is on the
// chopping block, even when modnames are long.
if (g_dlgUninstallNamePtr && !g_dlgUninstallNamePtr->empty()) {
wstring nm = L"\u201C" + *g_dlgUninstallNamePtr + L"\u201D";
g.DrawString(nm.c_str(), -1,
g_fModName ? g_fModName : g_fBtn,
RectF((REAL)padX, (REAL)y,
(REAL)(W - 2 * padX), (REAL)lineH),
&sf, &textBr);
}
y += lineH;
y += (int)(8 * g_dpiScale);
StringFormat sfWrap;
sfWrap.SetAlignment(StringAlignmentCenter);
sfWrap.SetLineAlignment(StringAlignmentNear);
int bodyH = (int)(60 * g_dpiScale);
g.DrawString(
L"This will permanently delete the mod's folder and all its files. This cannot be undone.",
-1, g_fBtn,
RectF((REAL)padX, (REAL)y,
(REAL)(W - 2 * padX), (REAL)bodyH),
&sfWrap, &textBr);
}
BitBlt(hdc, 0, 0, W, H, memDC, 0, 0, SRCCOPY);
SelectObject(memDC, oldBM);
DeleteObject(memBM);
DeleteDC(memDC);
EndPaint(hw, &ps);
return 0;
}
case WM_DRAWITEM:
if (PaintOwnerDrawButton((DRAWITEMSTRUCT*)lp)) return TRUE;
return DefWindowProc(hw, msg, wp, lp);
case WM_COMMAND: {
int id = LOWORD(wp);
int* res = (int*)GetWindowLongPtrW(hw, GWLP_USERDATA);
if (res) {
if (id == 1) *res = 0; // Cancel
else if (id == 2) *res = 1; // Delete
}
if (id == 1 || id == 2) DestroyWindow(hw);
return 0;
}
case WM_CLOSE: {
int* res = (int*)GetWindowLongPtrW(hw, GWLP_USERDATA);
if (res) *res = 0;
DestroyWindow(hw);
return 0;
}
case WM_DESTROY:
if (g_uninstallDlg == hw) g_uninstallDlg = nullptr;
return 0;
}
return DefWindowProcW(hw, msg, wp, lp);
}
int ShowUninstallConfirmDialog(HWND parent, const wstring& modName) {
if (g_uninstallDlg) return 0;
static bool classReg = false;
if (!classReg) {
WNDCLASSEXW wc = { sizeof(wc) };
wc.lpfnWndProc = UninstallDlgProc;
wc.hInstance = GetModuleHandleW(nullptr);
wc.lpszClassName = L"AngirisUninstallDlg";
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
RegisterClassExW(&wc);
classReg = true;
}
int dlgW = (int)(560 * g_dpiScale);
int dlgH = (int)(260 * g_dpiScale);
RECT pr; GetWindowRect(parent, &pr);
RECT clientReq = { 0, 0, dlgW, dlgH };
AdjustWindowRectEx(&clientReq, WS_POPUP | WS_CAPTION, FALSE, WS_EX_DLGMODALFRAME);
int winW = clientReq.right - clientReq.left;
int winH = clientReq.bottom - clientReq.top;
int cx = (pr.left + pr.right) / 2 - winW / 2;
int cy = (pr.top + pr.bottom) / 2 - winH / 2;
int result = 0;
g_dlgUninstallNamePtr = &modName;
HWND dlg = CreateWindowExW(
WS_EX_DLGMODALFRAME | WS_EX_TOPMOST,
L"AngirisUninstallDlg",
L"Delete Mod",
WS_POPUP | WS_CAPTION,
cx, cy, winW, winH,
parent, nullptr, GetModuleHandleW(nullptr), nullptr);
if (!dlg) { g_dlgUninstallNamePtr = nullptr; return 0; }
g_uninstallDlg = dlg;
SetWindowLongPtrW(dlg, GWLP_USERDATA, (LONG_PTR)&result);
int btnW = (int)(170 * g_dpiScale);
int btnH = (int)(46 * g_dpiScale);
int btnGap = (int)(16 * g_dpiScale);
RECT cr; GetClientRect(dlg, &cr);
int rowW = 2 * btnW + btnGap;
int rowX = (cr.right - rowW) / 2;
int rowY = cr.bottom - btnH - (int)(20 * g_dpiScale);
// Cancel on the left so the user's reflexive default action sits
// closer to where they'd naturally land. id=1 (Cancel) is also the
// initial focus so Enter triggers Cancel.
HWND bCancel = MkStdBtn(dlg, L"Cancel", 1, rowX, rowY,
btnW, btnH, true, ButtonKind::NexusUpdate);
MkStdBtn(dlg, L"Delete", 2, rowX + btnW + btnGap, rowY,
btnW, btnH, true, ButtonKind::NexusUpdate);
ShowWindow(dlg, SW_SHOW);
UpdateWindow(dlg);
EnableWindow(parent, FALSE);
SetFocus(bCancel); // Enter → Cancel, the safe default
MSG msg;
while (IsWindow(dlg)) {
BOOL got = GetMessageW(&msg, nullptr, 0, 0);
if (got <= 0) {
if (got == 0) PostQuitMessage((int)msg.wParam);
break;
}
if (msg.message == WM_KEYDOWN && msg.hwnd == dlg) {
if (msg.wParam == VK_ESCAPE) {
result = 0;
DestroyWindow(dlg);
break;
}
// Deliberately no Enter shortcut for Delete — destructive
// action must be an explicit click. (Enter while Cancel
// has focus naturally routes to Cancel via IsDialogMessage.)
}
if (!IsDialogMessageW(dlg, &msg)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
EnableWindow(parent, TRUE);
SetForegroundWindow(parent);
if (IsWindow(dlg)) DestroyWindow(dlg);
g_dlgUninstallNamePtr = nullptr;
g_uninstallDlg = nullptr;
return result;
}
// ─────────────────────────────────────────────────────────────────────────
// SET PATH DIALOG (themed modal — "D2R install folder not configured")
// ─────────────────────────────────────────────────────────────────────────
//
// Shown when a zip is dropped but the launcher doesn't know where D2R
// lives. Two buttons:
// Set Path → runs the SHBrowseForFolder picker (same as the rail
// "..." button); on success the worker continues with the
// current zip
// Cancel → skips this zip; remaining queued zips will hit the same
// dialog again on their turn (unless one of them set the
// path)
//
// Returns 1 if a path was set (worker continues with the zip), 0 if
// cancelled (worker skips the zip).
static HWND g_setPathDlg = nullptr;
static LRESULT CALLBACK SetPathDlgProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp) {
switch (msg) {
case WM_ERASEBKGND: return 1;
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hw, &ps);
RECT rc; GetClientRect(hw, &rc);
int W = rc.right, H = rc.bottom;
HDC memDC = CreateCompatibleDC(hdc);