1+ // Apart of the BORA Source which uses the TAOSU License
2+ // Check LICENSE.md for more information regarding the BORA license.
3+ #include < windows.h>
4+ #include < iostream>
5+ #include < shobjidl.h>
6+ #include " tools/Env.h"
7+ #include " tools/DynamicLibrary.h"
8+ #include < filesystem>
9+ #include < shellapi.h>
10+ #include < commctrl.h>
11+
12+ #if defined _WIN64
13+ #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
14+ #else
15+ #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
16+ #endif
17+
18+ #pragma comment (lib, "Shlwapi.lib")
19+ #pragma comment (lib, "Comctl32.lib")
20+
21+
22+ using MainFuncSymbol = int (*)(int , char * b[]);
23+
24+ int WINAPI WinMain (
25+ HINSTANCE hInstance, // handle to the current instance of the application
26+ HINSTANCE hPrevInstance, // always NULL in Win32 apps
27+ LPSTR lpCmdLine, // command line as ANSI string
28+ int nCmdShow // how the window is to be shown
29+ ){
30+ SetProcessDpiAwarenessContext (DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
31+
32+ auto bPath = std::filesystem::path (Environment::getEnvVar (" BORA_RT_PATH" ) + " /compatibility/latest.dll" );
33+ DynamicLibrary latest (bPath.c_str ());
34+ if (latest.hasOpened ()) {
35+ // todo: implement winmain commands as arguments for DLL
36+ auto main = MainFuncSymbol (latest.getProcAddress (" main" ));
37+ main (__argc, __argv);
38+ latest.close ();
39+ } else {
40+ // Task Dialog configuration
41+ TASKDIALOGCONFIG config = { 0 };
42+ config.cbSize = sizeof (config);
43+ config.hwndParent = nullptr ;
44+ config.dwFlags = TDF_USE_COMMAND_LINKS | TDF_POSITION_RELATIVE_TO_WINDOW;
45+ config.dwCommonButtons = TDCBF_CLOSE_BUTTON;
46+ config.pszWindowTitle = L" BORA needs to be reinstalled" ;
47+ config.pszMainIcon = TD_ERROR_ICON;
48+ config.pszMainInstruction = L" Critical files that BORA requires to run are missing." ;
49+ config.pszContent = L" To fix this problem, please visit the downloads website and reinstall BORA." ;
50+
51+ // Buttons
52+ TASKDIALOG_BUTTON buttons[] =
53+ {
54+ { 100 , L" Open Download Page" },
55+ };
56+ config.cButtons = ARRAYSIZE (buttons);
57+ config.pButtons = buttons;
58+ config.nDefaultButton = 100 ;
59+
60+ int pressedButton = 0 ;
61+ TaskDialogIndirect (&config, &pressedButton, nullptr , nullptr );
62+
63+ // Handle result
64+ if (pressedButton == 100 )
65+ {
66+ SHELLEXECUTEINFOW sei = { sizeof (sei) };
67+ sei.fMask = SEE_MASK_FLAG_DDEWAIT;
68+ sei.lpVerb = L" open" ;
69+ sei.lpFile = L" https://bor.ad/downloads" ;
70+ sei.nShow = SW_SHOWNORMAL;
71+
72+ if (!ShellExecuteExW (&sei))
73+ {
74+ // Fallback if needed
75+ ShellExecuteW (nullptr , L" open" , L" https://bor.ad/downloads" , nullptr , nullptr , SW_SHOWNORMAL);
76+ }
77+
78+ // Try to bring the browser window forward
79+ AllowSetForegroundWindow (ASFW_ANY);
80+ }
81+ }
82+
83+ }
0 commit comments