forked from xLightsSequencer/xLights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxScannerApp.cpp
326 lines (299 loc) · 10.1 KB
/
xScannerApp.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/***************************************************************
* Name: xScannerApp.cpp
* Purpose: Code for Application Class
* Author: xLights ()
* Created: 2016-12-30
* Copyright: xLights (http://xlights.org)
* License:
**************************************************************/
#include "xScannerApp.h"
//(*AppHeaders
#include "xScannerMain.h"
#include <wx/image.h>
//*)
#include <log4cpp/Category.hh>
#include <log4cpp/PropertyConfigurator.hh>
#include <log4cpp/Configurator.hh>
#include <wx/file.h>
#include <wx/msgdlg.h>
#include "../xLights/xLightsVersion.h"
#include <wx/filename.h>
#include <wx/stdpaths.h>
#include <wx/debugrpt.h>
#include <wx/cmdline.h>
#include <wx/confbase.h>
#ifdef LINUX
#include <X11/Xlib.h>
#endif
#ifdef _MSC_VER
#ifdef _DEBUG
#pragma comment(lib, "wxbase"WXWIDGETS_VERSION"ud.lib")
#pragma comment(lib, "wxbase"WXWIDGETS_VERSION"ud_net.lib")
#pragma comment(lib, "wxmsw"WXWIDGETS_VERSION"ud_core.lib")
#pragma comment(lib, "wxscintillad.lib")
#pragma comment(lib, "wxregexud.lib")
#pragma comment(lib, "wxbase"WXWIDGETS_VERSION"ud_xml.lib")
#pragma comment(lib, "wxtiffd.lib")
#pragma comment(lib, "wxjpegd.lib")
#pragma comment(lib, "wxpngd.lib")
#pragma comment(lib, "wxzlibd.lib")
#pragma comment(lib, "wxmsw"WXWIDGETS_VERSION"ud_qa.lib")
#pragma comment(lib, "wxexpatd.lib")
#pragma comment(lib, "msvcprtd.lib")
#pragma comment(lib, "log4cpplibd.lib")
#else
#pragma comment(lib, "wxbase"WXWIDGETS_VERSION"u.lib")
#pragma comment(lib, "wxbase"WXWIDGETS_VERSION"u_net.lib")
#pragma comment(lib, "wxmsw"WXWIDGETS_VERSION"u_core.lib")
#pragma comment(lib, "wxscintilla.lib")
#pragma comment(lib, "wxregexu.lib")
#pragma comment(lib, "wxbase"WXWIDGETS_VERSION"u_xml.lib")
#pragma comment(lib, "wxtiff.lib")
#pragma comment(lib, "wxjpeg.lib")
#pragma comment(lib, "wxpng.lib")
#pragma comment(lib, "wxzlib.lib")
#pragma comment(lib, "wxmsw"WXWIDGETS_VERSION"u_qa.lib")
#pragma comment(lib, "wxexpat.lib")
#pragma comment(lib, "msvcprt.lib")
#pragma comment(lib, "log4cpplib.lib")
#endif
#pragma comment(lib, "libcurl.dll.a")
#pragma comment(lib, "ImageHlp.Lib")
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "WS2_32.Lib")
#pragma comment(lib, "comdlg32.lib")
#pragma comment(lib, "comctl32.lib")
#pragma comment(lib, "Rpcrt4.lib")
#pragma comment(lib, "uuid.lib")
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "shell32.lib")
#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "oleaut32.lib")
#pragma comment(lib, "odbc32.lib")
#pragma comment(lib, "odbccp32.lib")
#pragma comment(lib, "kernel32.lib")
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "winspool.lib")
#pragma comment(lib, "gdi32.lib")
#endif
IMPLEMENT_APP(xScannerApp)
xScannerApp::xScannerApp() :
xlBaseApp("xScanner")
{
}
std::string DecodeOS(wxOperatingSystemId o)
{
switch (o)
{
case wxOS_UNKNOWN:
return "Call get get operating system failed.";
case wxOS_MAC_OS:
return "Apple Mac OS 8 / 9 / X with Mac paths.";
case wxOS_MAC_OSX_DARWIN:
return "Apple OS X with Unix paths.";
case wxOS_MAC:
return "An Apple Mac of some type.";
case wxOS_WINDOWS_NT:
return "Windows NT family(XP / Vista / 7 / 8 / 10).";
case wxOS_WINDOWS:
return "A Windows system of some type.";
case wxOS_UNIX_LINUX:
return "Linux.";
case wxOS_UNIX_FREEBSD:
return "FreeBSD.";
case wxOS_UNIX_OPENBSD:
return "OpenBSD.";
case wxOS_UNIX_NETBSD:
return "NetBSD.";
case wxOS_UNIX_SOLARIS:
return "Solaris.";
case wxOS_UNIX_AIX:
return "AIX.";
case wxOS_UNIX_HPUX:
return "HP / UX.";
case wxOS_UNIX:
return "Some flavour of Unix.";
default:
break;
}
return "Unknown Operating System.";
}
void DumpConfig()
{
static log4cpp::Category &logger_base = log4cpp::Category::getInstance(std::string("log_base"));
logger_base.info("Version: " + std::string(xlights_version_string.c_str()));
logger_base.info("Bits: " + std::string(GetBitness().c_str()));
logger_base.info("Build Date: " + std::string(xlights_build_date.c_str()));
logger_base.info("Machine configuration:");
wxMemorySize s = wxGetFreeMemory();
if (s != -1)
{
#if wxUSE_LONGLONG
wxString msg = wxString::Format(_T(" Free Memory: %" wxLongLongFmtSpec "d."), s);
#else
wxString msg = wxString::Format(_T(" Free Memory: %ld."), s);
#endif
logger_base.info("%s", (const char *)msg.c_str());
}
logger_base.info(" Current directory: " + std::string(wxGetCwd().c_str()));
logger_base.info(" Machine name: " + std::string(wxGetHostName().c_str()));
logger_base.info(" OS: " + std::string(wxGetOsDescription().c_str()));
int verMaj = -1;
int verMin = -1;
wxOperatingSystemId o = wxGetOsVersion(&verMaj, &verMin);
logger_base.info(" OS: %s %d.%d", (const char *)DecodeOS(o).c_str(), verMaj, verMin);
if (wxIsPlatform64Bit())
{
logger_base.info(" 64 bit");
}
else
{
logger_base.info(" NOT 64 bit");
}
if (wxIsPlatformLittleEndian())
{
logger_base.info(" Little Endian");
}
else
{
logger_base.info(" Big Endian");
}
#ifdef LINUX
wxLinuxDistributionInfo l = wxGetLinuxDistributionInfo();
logger_base.info(" " + std::string(l.Id.c_str()) \
+ " " + std::string(l.Release.c_str()) \
+ " " + std::string(l.CodeName.c_str()) \
+ " " + std::string(l.Description.c_str()));
#endif
}
void InitialiseLogging(bool fromMain)
{
static bool loggingInitialised = false;
if (!loggingInitialised)
{
#ifdef __WXMSW__
std::string initFileName = "xScanner.windows.properties";
#endif
#ifdef __WXOSX__
std::string initFileName = "xScanner.mac.properties";
std::string resourceName = wxStandardPaths::Get().GetResourcesDir().ToStdString() + "/xScanner.mac.properties";
if (!wxFile::Exists(initFileName)) {
if (fromMain) {
return;
} else if (wxFile::Exists(resourceName)) {
initFileName = resourceName;
}
}
loggingInitialised = true;
#endif
#ifdef LINUX
std::string initFileName = wxStandardPaths::Get().GetInstallPrefix() + "/bin/xscanner.linux.properties";
if (!wxFile::Exists(initFileName)) {
initFileName = wxStandardPaths::Get().GetInstallPrefix() + "/share/xLights/xscanner.linux.properties";
}
#endif
if (!wxFile::Exists(initFileName))
{
#ifdef _MSC_VER
// the app is not initialized so GUI is not available and no event loop.
wxMessageBox(initFileName + " not found in " + wxGetCwd() + ". Logging disabled.");
#endif
}
else
{
try
{
log4cpp::PropertyConfigurator::configure(initFileName);
}
catch (log4cpp::ConfigureFailure& e) {
// ignore config failure ... but logging wont work
printf("Log issue: %s\n", e.what());
}
catch (const std::exception& ex) {
printf("Log issue: %s\n", ex.what());
}
}
}
}
void xScannerApp::WipeSettings()
{
static log4cpp::Category &logger_base = log4cpp::Category::getInstance(std::string("log_base"));
logger_base.warn("------ Wiping settings ------");
wxConfigBase* config = wxConfigBase::Get();
config->DeleteAll();
}
int xScannerApp::OnExit()
{
static log4cpp::Category &logger_base = log4cpp::Category::getInstance(std::string("log_base"));
logger_base.info("xScanner exiting.");
return 0;
}
bool xScannerApp::OnInit()
{
wxLog::SetLogLevel(wxLOG_FatalError);
#ifdef _MSC_VER
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
#ifdef VISUALSTUDIO_MEMORYLEAKDETECTION
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
#endif
InitialiseLogging(false);
static log4cpp::Category &logger_base = log4cpp::Category::getInstance(std::string("log_base"));
logger_base.info("******* OnInit: xScanner started.");
DumpConfig();
#ifdef __WXMSW__
MSWEnableDarkMode();
#endif
static const wxCmdLineEntryDesc cmdLineDesc[] =
{
{ wxCMD_LINE_SWITCH, "h", "help", "displays help on the command line parameters", wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
{ wxCMD_LINE_SWITCH, "s", "singlethreaded", "run the query process single threaded" },
{ wxCMD_LINE_SWITCH, "w", "wipe", "wipe settings clean" },
{ wxCMD_LINE_NONE }
};
bool parmfound = false;
bool singleThreaded = false;
#ifdef LINUX
singleThreaded = true;
#endif
wxCmdLineParser parser(cmdLineDesc, argc, argv);
switch (parser.Parse()) {
case -1:
// help was given
return false;
case 0:
if (parser.Found("w"))
{
parmfound = true;
logger_base.info("-w: Wiping settings");
WipeSettings();
}
if (parser.Found("s")) {
parmfound = true;
logger_base.info("-s: Running single threaded");
singleThreaded = true;
}
if (!parmfound && parser.GetParamCount() > 0)
{
logger_base.info("Unrecognised command line parameter found.");
wxMessageBox("Unrecognised command line parameter found.", _("Command Line Options")); //give positive feedback*/
}
break;
default:
wxMessageBox(_("Unrecognized command line parameters"), _("Command Line Error"));
return false;
}
//(*AppInitialize
bool wxsOK = true;
wxInitAllImageHandlers();
if ( wxsOK )
{
xScannerFrame* Frame = new xScannerFrame(0, singleThreaded);
Frame->Show();
SetTopWindow(Frame);
}
//*)
return wxsOK;
}