-
Notifications
You must be signed in to change notification settings - Fork 0
/
Application.cpp
70 lines (58 loc) · 2.24 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
#ifndef _SCRIPT_PAD_APPLICATION_CPP
#define _SCRIPT_PAD_APPLICATION_CPP
#include "Application.h"
namespace querier {
Application::Application(HINSTANCE hInst, int nCmdShow) : MainWindow(new AppWindow(hInst, nCmdShow)), ModuleManager(MainWindow), QueryManager(MainWindow, &ModuleManager) {
MainWindow->AddWebMessageHandler(std::bind(&Application::HandleWebMessage, this, std::placeholders::_1));
path specialFolder;
if (Directory::GetSpecialFolder(FOLDERID_RoamingAppData, &specialFolder)) {
path appDataFolder = specialFolder / path("Querier");
if (!Directory::Exists(appDataFolder))
Directory::Create(appDataFolder);
if (Directory::SetCurrentWorkingDirectory(appDataFolder)) {
m_WorkingDirectory = appDataFolder;
}
}
else {
m_WorkingDirectory = Directory::GetCurrentWorkingDirectory();
}
m_ModulesDirectory = m_WorkingDirectory / path(L"modules");
if (!Directory::Exists(m_ModulesDirectory))
Directory::Create(m_ModulesDirectory);
m_WorkspaceDirectory = m_WorkingDirectory / path(L"workspace");
if (!Directory::Exists(m_WorkspaceDirectory))
Directory::Create(m_WorkspaceDirectory);
ModuleManager.Initialize(m_WorkingDirectory, m_ModulesDirectory);
QueryManager.Initialize(m_WorkingDirectory, m_WorkspaceDirectory);
}
int Application::Start() {
if (MainWindow->Show())
return RunMessagePump();
return -1;
}
int Application::RunMessagePump() {
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
std::wstring Application::HandleWebMessage(json data) {
ApplicationMessage msg = data.template get<ApplicationMessage>();
switch (msg.type) {
case MODULE:
{
ModuleManager.HandleCommand(&msg.modmsg);
break;
}
case QUERY:
{
QueryManager.HandleCommand(&msg.querymsg);
break;
}
}
return str_to_wstr(json(msg).dump());
}
}
#endif