-
Notifications
You must be signed in to change notification settings - Fork 2
/
No5App.cpp
287 lines (245 loc) · 5.96 KB
/
No5App.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
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
// No5App.cpp: implementation of the CNo5App class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "no5app.h"
#include "path.h"
#include "imainframe.h"
#include "no5options.h"
#include "ignorelist.h"
#include "resource.h"
#include "recentrooms.h"
#include "no5obj.h"
#include "ddforms.tlh"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CNo5App::CNo5App()
{
m_pAppPath = new CPath();
NO5YAHOO::SmileyMapCreate(&m_psm);
m_pFrame = NULL;
m_pgo = NULL;
m_pvo = NULL;
m_pio = new CIgnoreOptions();
m_pRecentRooms = NULL;
m_pNo5 = NULL;
m_scripts = 0;
}
CNo5App::~CNo5App()
{
delete m_pAppPath;
NO5YAHOO::SmileyMapDestroy(&m_psm);
delete m_pio;
if(m_pRecentRooms)
delete m_pRecentRooms;
}
BOOL CNo5App::Init(void)
{
#ifdef _DEBUG
m_pAppPath->SetPath(PATH_CURDIR);
#else
CPath path(PATH_MODULE);
m_pAppPath->SetPath(path.GetLocation());
#endif
if(m_pAppPath->ExistLocation()){
if(!m_psm->IsLoaded()){
BOOL res = m_psm->LoadMap(GetSmileysFile());
ATLASSERT(res);
}
g_app.LoadName(IDR_MAINFRAME);
// create IGeneralOptions instance and load from file
ATLASSERT(!GetGeneralOptions());
SetGeneralOptions(IGeneralOptions::CreateMe());
GetGeneralOptions()->SetFileName(GetOptionsFile());
GetGeneralOptions()->GetInMemoryOptions();
// create IVisualOptions instance and load from file
ATLASSERT(!GetVisualOptions());
SetVisualOptions(IVisualOptions::CreateMe());
GetVisualOptions()->SetFile(GetVisualOptionsFile());
// load ignore options
LoadIgnoreOptions();
LoadIgnoreList();
LoadRecentRooms();
// register type lib
_Module.RegisterTypeLib();
// create script object
HRESULT hr;
hr = CComObject<CNo5Obj>::CreateInstance(&m_pNo5);
if(SUCCEEDED(hr)){
CComPtr<INo5Obj> sp;
hr = m_pNo5->QueryInterface(&sp);
if(SUCCEEDED(hr)){
hr = m_pNo5->PrivateInit();
sp.Detach();
}
}
if(SUCCEEDED(hr)){
CComPtr<DDFORMSLib::IFormEditor2> sp;
hr = sp.CoCreateInstance(DDFORMSLib::CLSID_FormEditor);
if(FAILED(hr)){
CString path = GetPath();
path += "ddforms.dll";
path += " /s";
UINT u = (UINT)::ShellExecute(GetDesktopWindow(),"open","regsvr32",path,NULL,SW_HIDE);
if(u > 32){
path = GetPath();
path += "ddcontrolpack.dll";
path += " /s";
u = (UINT)::ShellExecute(GetDesktopWindow(),"open","regsvr32",path,NULL,SW_HIDE);
path = GetPath();
path += "ddproppageall.dll";
path += " /s";
u = (UINT)::ShellExecute(GetDesktopWindow(),"open","regsvr32",path,NULL,SW_HIDE);
}
if(u < 32)
MessageBox(GetDesktopWindow(),"form dlls not registered",GetName(),MB_ICONINFORMATION);
else
hr = S_OK;
}
}
ATLASSERT(SUCCEEDED(hr));
}
return m_pAppPath->ExistLocation();
}
void CNo5App::Term(void)
{
WriteIgnoreOptions();
GetGeneralOptions()->WriteInMemoryOptions();
IGeneralOptions *pgo = GetGeneralOptions();
IGeneralOptions::DestroyMe(&pgo);
IVisualOptions *pvo = GetVisualOptions();
IVisualOptions::DestroyMe(&pvo);
UnloadIgnoreList();
UnloadRecentRooms();
m_pNo5->Release();
// unregister type lib
_Module.UnRegisterTypeLib();
}
CString CNo5App::GetPath(void)
{
return m_pAppPath->GetLocation();
}
CString CNo5App::GetModuleFileName(void)
{
CPath path(PATH_MODULE);
return path.GetLongPath();
}
CString CNo5App::GetOptionsFile(void)
{
return GetPath() + _T("no5.ini");
}
CString CNo5App::GetVisualOptionsFile(void)
{
return GetOptionsFile();
}
CString CNo5App::GetScriptsFolder(void)
{
return GetPath() + _T("scripts\\");
}
CString CNo5App::GetFormsFolder(void)
{
return GetPath() + _T("forms\\");
}
CString CNo5App::GetSmileysFolder(void)
{
return GetPath() + _T("smileys\\");
}
CString CNo5App::GetSmileysFile(void)
{
return GetPath() + _T("smileys.txt");
}
CString CNo5App::GetColorsFile(void)
{
return GetPath() + _T("colors.ini");
}
CString CNo5App::GetIgnoreFile(void)
{
return GetPath() + _T("ignore.txt");
}
CString CNo5App::GetRecentRoomsFile(void)
{
return GetPath() + _T("rooms.txt");
}
CString CNo5App::GetSnapshotFolder(void)
{
return GetPath() + _T("snapshots\\");
}
CString CNo5App::GetVideoFolder(void)
{
return GetPath() + _T("videos\\");
}
CString CNo5App::GetBotsFolder(void)
{
return GetPath() + _T("bots\\");
}
void CNo5App::LoadName(UINT uResourceID)
{
BOOL res = m_name.LoadString(uResourceID);
ATLASSERT(res);
}
CIgnoreOptions & CNo5App::GetIgnoreOptions(void)
{
return *m_pio;
}
void CNo5App::LoadIgnoreOptions(void)
{
ATLASSERT(m_pgo);
if(m_pgo){
BOOL res = m_pgo->GetIgnoreOptions(*m_pio);
ATLASSERT(res);
}
}
void CNo5App::WriteIgnoreOptions(void)
{
ATLASSERT(m_pgo);
if(m_pgo){
BOOL res = m_pgo->SetIgnoreOptions(*m_pio);
ATLASSERT(res);
}
}
void CNo5App::LoadIgnoreList(void)
{
bool res;
ATLASSERT(!m_pIgnoreList);
IIgnoreList::CreateMe(&m_pIgnoreList);
res = m_pIgnoreList->read(GetIgnoreFile());
ATLASSERT(res);
}
void CNo5App::UnloadIgnoreList(void)
{
if(m_pIgnoreList){
if(m_pIgnoreList->is_dirty()){
bool res = m_pIgnoreList->write(g_app.GetIgnoreFile());
ATLASSERT(res);
}
IIgnoreList::DestroyMe(&m_pIgnoreList);
}
}
CRecentRooms * CNo5App::GetRecentRooms(void)
{
if(!m_pRecentRooms){
LoadRecentRooms();
}
return m_pRecentRooms;
}
void CNo5App::LoadRecentRooms(void)
{
BOOL res;
if(!m_pRecentRooms){
m_pRecentRooms = new CRecentRooms();
}
res = m_pRecentRooms->Read(GetRecentRoomsFile());
ATLASSERT(res);
}
void CNo5App::UnloadRecentRooms(void)
{
if(m_pRecentRooms){
if(m_pRecentRooms->IsDirty()){
BOOL res = m_pRecentRooms->Write(GetRecentRoomsFile());
ATLASSERT(res);
}
delete m_pRecentRooms;
m_pRecentRooms = NULL;
}
}