| 1 | // SysTray.cpp : Defines the entry point for the DLL application. |
|---|
| 2 | // |
|---|
| 3 | |
|---|
| 4 | #include "stdafx.h" |
|---|
| 5 | #include "SysTray.h" |
|---|
| 6 | #include "TrayIcon.h" |
|---|
| 7 | #include <ServiceCmd.h> |
|---|
| 8 | #include <config.h> |
|---|
| 9 | |
|---|
| 10 | SysTray gSysTray; |
|---|
| 11 | |
|---|
| 12 | BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) |
|---|
| 13 | { |
|---|
| 14 | NSCModuleWrapper::wrapDllMain(hModule, ul_reason_for_call); |
|---|
| 15 | return TRUE; |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | SysTray::SysTray() {} |
|---|
| 19 | SysTray::~SysTray() {} |
|---|
| 20 | bool SysTray::loadModule() { |
|---|
| 21 | try { |
|---|
| 22 | if ((serviceControll::GetServiceType(SZSERVICENAME)&SERVICE_INTERACTIVE_PROCESS)!=SERVICE_INTERACTIVE_PROCESS) { |
|---|
| 23 | NSC_LOG_ERROR("SysTray is not installed (or it cannot interact with the desktop) SysTray wont be loaded. Run " SZAPPNAME " SysTray install ti change this."); |
|---|
| 24 | return true; |
|---|
| 25 | } |
|---|
| 26 | } catch (serviceControll::SCException e) { |
|---|
| 27 | NSC_LOG_ERROR("SysTray is not installed (or it cannot interact with the desktop) SysTray wont be loaded. Run " SZAPPNAME " SysTray install ti change this."); |
|---|
| 28 | return true; |
|---|
| 29 | } |
|---|
| 30 | icon.createThread(); |
|---|
| 31 | return true; |
|---|
| 32 | } |
|---|
| 33 | bool SysTray::unloadModule() { |
|---|
| 34 | if (!icon.exitThread(20000)) { |
|---|
| 35 | std::cout << "MAJOR ERROR: Could not unload thread..." << std::endl; |
|---|
| 36 | NSC_LOG_ERROR("Could not exit the thread, memory leak and potential corruption may be the result..."); |
|---|
| 37 | return false; |
|---|
| 38 | } |
|---|
| 39 | return true; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | int SysTray::commandLineExec(const char* command,const unsigned int argLen,char** args) { |
|---|
| 43 | if (stricmp(command, "install") == 0) { |
|---|
| 44 | try { |
|---|
| 45 | serviceControll::ModifyServiceType(SZSERVICENAME, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS); |
|---|
| 46 | NSC_LOG_MESSAGE(MODULE_NAME " is now able to run as the SERVICE_INTERACTIVE_PROCESS flag has been set."); |
|---|
| 47 | } catch (const serviceControll::SCException& e) { |
|---|
| 48 | NSC_LOG_ERROR("Could not modify service: " + e.error_); |
|---|
| 49 | return -1; |
|---|
| 50 | } |
|---|
| 51 | } else if (stricmp(command, "uninstall") == 0) { |
|---|
| 52 | try { |
|---|
| 53 | serviceControll::ModifyServiceType(SZSERVICENAME, SERVICE_WIN32_OWN_PROCESS); |
|---|
| 54 | NSC_LOG_MESSAGE(MODULE_NAME " is now not able to run as the SERVICE_INTERACTIVE_PROCESS flag has been reset."); |
|---|
| 55 | } catch (const serviceControll::SCException& e) { |
|---|
| 56 | NSC_LOG_ERROR("Could not modify service: " + e.error_); |
|---|
| 57 | return -1; |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | return 0; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | bool SysTray::hasCommandHandler() { |
|---|
| 64 | return false; |
|---|
| 65 | } |
|---|
| 66 | bool SysTray::hasMessageHandler() { |
|---|
| 67 | return false; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | NSC_WRAPPERS_MAIN_DEF(gSysTray); |
|---|
| 71 | NSC_WRAPPERS_IGNORE_MSG_DEF(); |
|---|
| 72 | NSC_WRAPPERS_IGNORE_CMD_DEF(); |
|---|
| 73 | NSC_WRAPPERS_CLI_DEF(gSysTray); |
|---|
| 74 | |
|---|