This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
application.cpp
136 lines (111 loc) · 3.23 KB
/
application.cpp
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
#include "../include/pch.hpp"
#include "../include/application.hpp"
#include "../include/window.hpp"
#include "../include/log_helper.hpp"
#include "../include/d3d_impl.hpp"
namespace Win11SysCheck
{
// cotr & dotr
CApplication::CApplication(int, char**) :
m_pConfigFile(mINI::INIFile(CONFIG_FILE_NAME))
{
CLogHelper::Instance().Log(LL_SYS, fmt::format("Win11SysCheck started! Build: {} {}", __DATE__, __TIME__));
}
CApplication::~CApplication()
{
}
// main routines
void CApplication::Destroy()
{
if (m_spI18N)
m_spI18N->Destroy();
if (m_spSysCheck)
m_spSysCheck->Destroy();
if (m_spWND)
m_spWND->Destroy();
}
int CApplication::MainRoutine()
{
auto nRetCode = EXIT_FAILURE;
// Declare
m_spWND = std::make_shared<gui::CWindow>();
assert(m_spWND || m_spWND.get());
m_spUI = std::make_shared<gui::CMainUI>();
assert(m_spUI || m_spUI.get());
m_spI18N = std::make_shared<CI18N>();
assert(m_spI18N || m_spI18N.get());
m_spSysCheck = std::make_shared<CSysCheck>();
assert(m_spSysCheck || m_spSysCheck.get());
// Initialize
do
{
/*
BOOL Wow64Process = FALSE;
if (IsWow64Process(GetCurrentProcess(), &Wow64Process) && Wow64Process)
{
CLogHelper::Instance().Log(LL_ERR, "This process cannot be run under Wow64.");
break;
}
*/
if (!std::filesystem::exists(CONFIG_FILE_NAME))
{
CLogHelper::Instance().Log(LL_WARN, "Config file does not exist!");
std::ofstream ofs(CONFIG_FILE_NAME);
if (!ofs)
{
CLogHelper::Instance().Log(LL_ERR, "Config file create failed!");
break;
}
ofs << "";
ofs.close();
}
if (!m_pConfigFile.read(m_pConfigContext))
{
CLogHelper::Instance().Log(LL_ERR, "Config file read failed!");
break;
}
// Setup I18N
if (!m_spI18N->Initialize())
{
CLogHelper::Instance().Log(LL_ERR, "I18N initialization failed!");
break;
}
// Setup UI
m_spWND->SetInstance(GetModuleHandle(0));
m_spWND->Assemble("Win11SysCheck", "Win11SysCheck", gui::rectangle(0, 0, 680, 540), nullptr);
CD3DManager::Instance().SetWindow(m_spWND->GetHandle());
CD3DManager::Instance().CreateDevice();
CD3DManager::Instance().SetupImGui();
// Show main windows container window
::ShowWindow(m_spWND->GetHandle(), SW_SHOW);
::UpdateWindow(m_spWND->GetHandle());
// Setup updater
if (!m_spSysCheck->Initialize())
{
CLogHelper::Instance().Log(LL_ERR, "SysCheck initialization failed!");
break;
}
// Main loop
m_spWND->PeekMessageLoop([]() {
CD3DManager::Instance().OnRenderFrame();
});
nRetCode = EXIT_SUCCESS;
} while (FALSE);
// End-of-loop cleanup
Destroy();
return nRetCode;
}
bool CApplication::OpenWebPage(const std::string& stAddress)
{
// Initialize COM before calling ShellExecute().
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
// Execute process
const auto iExecuteRet = (INT_PTR)ShellExecuteA(nullptr, "open", stAddress.c_str(), nullptr, nullptr, SW_HIDE);
if (iExecuteRet <= 32) // If the function succeeds, it returns a value greater than 32.
{
CLogHelper::Instance().Log(LL_ERR, fmt::format("ShellExecuteA failed with status: {0} error: {1}", iExecuteRet, GetLastError()));
return false;
}
return true;
}
};