2022-05-18 03:30:13 +00:00
|
|
|
|
#include "base/HGDef.h"
|
|
|
|
|
#include "base/HGInc.h"
|
2022-09-23 09:53:00 +00:00
|
|
|
|
#include "base/HGCrash.h"
|
2022-05-18 03:30:13 +00:00
|
|
|
|
#include "base/HGThread.h"
|
2022-05-21 06:34:02 +00:00
|
|
|
|
#include "base/HGUtility.h"
|
2022-05-30 11:01:23 +00:00
|
|
|
|
#include "base/HGIni.h"
|
2022-05-21 10:09:34 +00:00
|
|
|
|
#include "base/HGMsgPump.h"
|
2022-05-23 10:29:23 +00:00
|
|
|
|
#include "ManagerV1.h"
|
|
|
|
|
#include "ManagerV2.h"
|
2022-05-23 02:35:42 +00:00
|
|
|
|
#include "HttpServer.h"
|
|
|
|
|
#include "SockIoServer.h"
|
|
|
|
|
#include "WSServer.h"
|
|
|
|
|
#include "MsgPumpCallback.h"
|
2022-07-02 02:40:30 +00:00
|
|
|
|
#include "curl/curl.h"
|
2022-05-03 10:25:52 +00:00
|
|
|
|
|
2022-10-12 03:35:09 +00:00
|
|
|
|
static void HGAPI CrashFunc(HGPointer crashAddr, HGPointer param)
|
2022-09-23 09:53:00 +00:00
|
|
|
|
{
|
|
|
|
|
HGChar logPath[256];
|
|
|
|
|
HGBase_GetLogFilePath(logPath, 256);
|
|
|
|
|
strcat(logPath, "crash.dmp");
|
|
|
|
|
HGBase_MakeCrashFile(logPath);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-07 07:28:56 +00:00
|
|
|
|
static void HGAPI ThreadFuncV1(HGThread thread, HGPointer param)
|
|
|
|
|
{
|
|
|
|
|
(void)thread;
|
|
|
|
|
HGMsgPump msgPump = (HGMsgPump)param;
|
|
|
|
|
|
|
|
|
|
HGChar cfgPath[256];
|
|
|
|
|
HGBase_GetConfigPath(cfgPath, 256);
|
|
|
|
|
HGChar cfgName[256];
|
|
|
|
|
sprintf(cfgName, "%s%s", cfgPath, "config.ini");
|
|
|
|
|
|
|
|
|
|
ver_1::ManagerV1 manager(msgPump);
|
|
|
|
|
ver_1::HttpServer httpServer(msgPump, &manager);
|
|
|
|
|
ver_1::SockIoServer sockIoServer(msgPump, &manager);
|
|
|
|
|
|
|
|
|
|
if (httpServer.Open(18999))
|
|
|
|
|
{
|
|
|
|
|
if (sockIoServer.Open(28999))
|
|
|
|
|
{
|
|
|
|
|
HGBase_RunMsgPump(msgPump, ver_1::HGMsgPumpCallback, NULL);
|
|
|
|
|
sockIoServer.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
httpServer.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void HGAPI ThreadFuncV2(HGThread thread, HGPointer param)
|
2022-05-03 10:25:52 +00:00
|
|
|
|
{
|
|
|
|
|
(void)thread;
|
2022-05-21 10:09:34 +00:00
|
|
|
|
HGMsgPump msgPump = (HGMsgPump)param;
|
2022-05-03 10:25:52 +00:00
|
|
|
|
|
2022-05-21 06:34:02 +00:00
|
|
|
|
HGChar cfgPath[256];
|
|
|
|
|
HGBase_GetConfigPath(cfgPath, 256);
|
2022-06-10 06:33:16 +00:00
|
|
|
|
HGChar cfgName[256];
|
2024-04-07 07:28:56 +00:00
|
|
|
|
sprintf(cfgName, "%s%s", cfgPath, "config2.ini");
|
|
|
|
|
|
|
|
|
|
ver_2::ManagerV2 manager(msgPump);
|
|
|
|
|
ver_2::WSServer wsServer(msgPump, &manager);
|
|
|
|
|
|
|
|
|
|
HGInt port = 38999;
|
|
|
|
|
HGBase_GetProfileInt(cfgName, "connect", "port", 38999, &port);
|
|
|
|
|
if (wsServer.Open(port))
|
|
|
|
|
{
|
|
|
|
|
HGBase_RunMsgPump(msgPump, ver_2::HGMsgPumpCallback, NULL);
|
|
|
|
|
wsServer.Close();
|
|
|
|
|
}
|
2022-05-03 10:25:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-20 13:03:28 +00:00
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
|
|
|
#include <shellapi.h>
|
|
|
|
|
#include "resource.h"
|
|
|
|
|
#define WM_TRAY (WM_USER + 100)
|
|
|
|
|
ULONG taskbarMsgId = 0;
|
|
|
|
|
NOTIFYICONDATAA nid;
|
|
|
|
|
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
{
|
|
|
|
|
if (WM_DESTROY == uMsg)
|
|
|
|
|
{
|
|
|
|
|
Shell_NotifyIconA(NIM_DELETE, &nid);
|
|
|
|
|
PostQuitMessage(0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else if (uMsg == taskbarMsgId)
|
|
|
|
|
{
|
|
|
|
|
//系统Explorer崩溃重启时,重新加载托盘
|
|
|
|
|
Shell_NotifyIconA(NIM_ADD, &nid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-05-03 10:25:52 +00:00
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
|
|
|
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE iPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
|
|
|
|
|
#else
|
|
|
|
|
int main()
|
|
|
|
|
#endif
|
|
|
|
|
{
|
2022-09-23 09:53:00 +00:00
|
|
|
|
HGBase_RegisterCrashFunc(CrashFunc, NULL);
|
|
|
|
|
|
2022-05-03 10:25:52 +00:00
|
|
|
|
#if defined(HG_CMP_MSC)
|
2023-03-20 13:03:28 +00:00
|
|
|
|
HANDLE hMutex = CreateMutexW(NULL, FALSE, L"{1A67EFC9-B41C-4CE6-B95A-A16958E7010F}");
|
|
|
|
|
assert(NULL != hMutex);
|
|
|
|
|
if (GetLastError() == ERROR_ALREADY_EXISTS)
|
|
|
|
|
{
|
|
|
|
|
MessageBoxA(NULL, "扫描服务已打开", "提示", 0);
|
|
|
|
|
CloseHandle(hMutex);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-03 10:25:52 +00:00
|
|
|
|
WSADATA ws = { 0 };
|
|
|
|
|
int ret = WSAStartup(MAKEWORD(2, 2), &ws);
|
|
|
|
|
assert(0 == ret);
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-07-02 02:40:30 +00:00
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
2024-04-07 07:28:56 +00:00
|
|
|
|
|
|
|
|
|
HGMsgPump msgPumpV1 = NULL;
|
|
|
|
|
HGBase_CreateMsgPump(&msgPumpV1);
|
|
|
|
|
HGThread threadV1 = NULL;
|
|
|
|
|
HGBase_OpenThread(ThreadFuncV1, msgPumpV1, &threadV1);
|
|
|
|
|
|
|
|
|
|
HGMsgPump msgPumpV2 = NULL;
|
|
|
|
|
HGBase_CreateMsgPump(&msgPumpV2);
|
|
|
|
|
HGThread threadV2 = NULL;
|
|
|
|
|
HGBase_OpenThread(ThreadFuncV2, msgPumpV2, &threadV2);
|
2023-03-20 13:03:28 +00:00
|
|
|
|
|
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
|
|
|
WNDCLASSA wc = { 0 };
|
|
|
|
|
wc.style = NULL;
|
|
|
|
|
wc.hIcon = NULL;
|
|
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
|
wc.cbWndExtra = 0;
|
|
|
|
|
wc.hInstance = hInstance;
|
|
|
|
|
wc.lpfnWndProc = WndProc;
|
|
|
|
|
wc.hbrBackground = NULL;
|
|
|
|
|
wc.lpszMenuName = NULL;
|
|
|
|
|
wc.lpszClassName = "HGWebServie";
|
|
|
|
|
wc.hCursor = NULL;
|
|
|
|
|
RegisterClassA(&wc);
|
|
|
|
|
|
|
|
|
|
HWND hWnd = CreateWindowExA(WS_EX_TOOLWINDOW, "HGWebServie", "HGWebServie", WS_POPUP, CW_USEDEFAULT,
|
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
|
|
|
|
|
|
|
|
|
|
taskbarMsgId = RegisterWindowMessageA("TaskbarCreated");
|
|
|
|
|
nid.cbSize = sizeof(NOTIFYICONDATAA);
|
|
|
|
|
nid.hWnd = hWnd;
|
|
|
|
|
nid.uID = IDI_ICON_HGWEBSERVICE;
|
|
|
|
|
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_INFO;
|
|
|
|
|
nid.uCallbackMessage = WM_TRAY;
|
|
|
|
|
nid.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON_HGWEBSERVICE));
|
2023-08-03 03:14:31 +00:00
|
|
|
|
lstrcpyA(nid.szTip, "扫描服务程序(连接数 0)");
|
2023-03-20 13:03:28 +00:00
|
|
|
|
Shell_NotifyIconA(NIM_ADD, &nid);
|
|
|
|
|
|
|
|
|
|
ShowWindow(hWnd, SW_HIDE);
|
|
|
|
|
UpdateWindow(hWnd);
|
|
|
|
|
|
|
|
|
|
MSG msg;
|
|
|
|
|
while (GetMessage(&msg, NULL, 0, 0))
|
|
|
|
|
{
|
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-04-07 07:28:56 +00:00
|
|
|
|
HGBase_CloseThread(threadV2);
|
|
|
|
|
threadV2 = NULL;
|
|
|
|
|
HGBase_DestroyMsgPump(msgPumpV2);
|
|
|
|
|
msgPumpV2 = NULL;
|
|
|
|
|
HGBase_CloseThread(threadV1);
|
|
|
|
|
threadV1 = NULL;
|
|
|
|
|
HGBase_DestroyMsgPump(msgPumpV1);
|
|
|
|
|
msgPumpV1 = NULL;
|
|
|
|
|
|
2022-07-02 02:40:30 +00:00
|
|
|
|
curl_global_cleanup();
|
|
|
|
|
|
2022-05-03 10:25:52 +00:00
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
|
|
|
WSACleanup();
|
2023-03-20 13:03:28 +00:00
|
|
|
|
CloseHandle(hMutex);
|
2022-05-03 10:25:52 +00:00
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
2022-10-24 14:48:17 +00:00
|
|
|
|
}
|