-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.cpp
127 lines (111 loc) · 2.97 KB
/
Main.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
#define GAC_HEADER_USE_NAMESPACE
#include "GacPass.h"
#include "util.hpp"
#include "AsyncIO.h"
#include "ChromeHandler.h"
#include "ViewModel/CodeBookViewModel.h"
#include "ViewModel/RegisterVIewModel.h"
#include "ViewModel/LoginViewModel.h"
#include "db/DB.h"
#include "EventBus.h"
#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
#endif
using namespace vl::stream;
class ViewModel : public Object, public virtual gacpass::IViewModel
{
private:
::vl::Ptr<gacpass::IRegisterViewModel> registerViewModel;
::vl::Ptr<gacpass::ILoginViewModel> loginViewModel;
::vl::Ptr<gacpass::ICodeBookViewModel> codeBookViewModel;
public:
ViewModel()
: registerViewModel(MakePtr<RegisterViewModel>())
, loginViewModel(MakePtr<LoginViewModel>())
, codeBookViewModel(MakePtr<CodeBookViewModel>(loginViewModel))
{
auto folder = vl::MakePtr<vl::filesystem::Folder>(vl::filesystem::FilePath(WAppdata(L"")));
if (!folder->Exists())
{
folder->Create(false);
}
DB.sync_schema(true);
dynamic_cast<CodeBookViewModel *>(codeBookViewModel.Obj())->Load();
}
Ptr<gacpass::IRegisterViewModel> GetRegisterViewModel()override
{
return this->registerViewModel;
}
Ptr<gacpass::ILoginViewModel> GetLoginViewModel()override
{
return this->loginViewModel;
}
Ptr<gacpass::ICodeBookViewModel> GetCodeBookViewModel()override
{
return this->codeBookViewModel;
}
};
void initChromePlugin()
{
#ifdef _WIN32
//_setmode(_fileno(stdout), _O_BINARY);
_setmode(_fileno(stdin), _O_BINARY);
#endif
GetApplication()->InvokeAsync([] {
char cBuffer[1024] = { 0 };
while (true)
{
unsigned int uiSize = 0;
std::cin.read((char*)&uiSize, sizeof(unsigned int));
if (uiSize != 0 && uiSize < 1024)
{
memset(cBuffer, 0, 1024);
std::cin.read(cBuffer, uiSize);
WString input(std::wstring(&cBuffer[0], &cBuffer[uiSize]).c_str());
auto istream = EventBus::Get(EventBus::EventName::IStream);
istream->SetData(vl::__vwsn::Box(input));
istream->Signal();
}
}
});
GetApplication()->InvokeAsync([] {
WString input = L"";
auto producer = Ptr<ICoroutine>(new AsyncIO(input));
auto consumer = Ptr<ICoroutine>(new ChromeHandler());
auto cr = Ptr<CoroutineResult>(new CoroutineResult());
while (producer->GetStatus() != CoroutineStatus::Stopped && consumer->GetStatus() != CoroutineStatus::Stopped)
{
producer->Resume(false, NULL);
cr->SetResult(::vl::__vwsn::Box(input));
consumer->Resume(false, cr);
}
if (producer->GetFailure())
{
}
if (consumer->GetFailure())
{
}
});
}
void GuiMain()
{
//one instance at most
auto m = MakePtr<Mutex>();
m->Create(true, L"GacPass");
if (!m->WaitForTime(0))
{
return;
}
{
FileStream fileStream(L"MVVM.bin", FileStream::ReadOnly);
GetResourceManager()->LoadResourceOrPending(fileStream);
}
auto viewModel = MakePtr<ViewModel>();
initChromePlugin();
auto window = new gacpass::MainWindow(viewModel);
window->MoveToScreenCenter();
//window->SetShowInTaskBar(false);
GetApplication()->Run(window);
delete window;
}