diff --git a/Artemis/Artemis/Resources/Keyboards/default-profiles.zip b/Artemis/Artemis/Resources/Keyboards/default-profiles.zip index dba026291..4d583b7c1 100644 Binary files a/Artemis/Artemis/Resources/Keyboards/default-profiles.zip and b/Artemis/Artemis/Resources/Keyboards/default-profiles.zip differ diff --git a/Artemis/Artemis/Utilities/DataReaders/PipeServer.cs b/Artemis/Artemis/Utilities/DataReaders/PipeServer.cs index 5430c7de9..ed60e3a4a 100644 --- a/Artemis/Artemis/Utilities/DataReaders/PipeServer.cs +++ b/Artemis/Artemis/Utilities/DataReaders/PipeServer.cs @@ -15,10 +15,12 @@ namespace Artemis.Utilities.DataReaders private readonly ILogger _logger; private string _pipeName; private NamedPipeServerStream _pipeServer; + private bool _closed; public PipeServer(ILogger logger) { _logger = logger; + _closed = true; } public event DelegateMessage PipeMessage; @@ -34,10 +36,12 @@ namespace Artemis.Utilities.DataReaders PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 4096, 4096, security); _pipeServer.BeginWaitForConnection(WaitForConnectionCallBack, _pipeServer); _logger.Info("Opened named pipe '{0}'", _pipeName); + _closed = false; } public void Stop() { + _closed = true; _pipeServer.Close(); _pipeServer.Dispose(); _logger.Info("Closed named pipe '{0}'", _pipeName); @@ -73,8 +77,8 @@ namespace Artemis.Utilities.DataReaders } catch (Exception e) { - _logger.Error(e, "Exception in named pipe '{0}'", _pipeName); - // ignored + if (!_closed) + _logger.Error(e, "Exception in named pipe '{0}'", _pipeName); } } diff --git a/Artemis/Razer2Artemis/Log.h b/Artemis/Razer2Artemis/Log.h new file mode 100644 index 000000000..e04d2ed4c --- /dev/null +++ b/Artemis/Razer2Artemis/Log.h @@ -0,0 +1,67 @@ +/* +* File: Log.h +* Author: Alberto Lepe +* +* Created on December 1, 2015, 6:00 PM +*/ + +#ifndef LOG_H +#define LOG_H + +#include + +using namespace std; + +enum typelog { + DEBUG, + INFO, + WARN, + ERR +}; + +struct structlog { + bool headers = false; + typelog level = WARN; +}; + +extern structlog LOGCFG; + +class LOG { +public: + LOG() {} + LOG(typelog type) { + msglevel = type; + if (LOGCFG.headers) { + operator << ("[" + getLabel(type) + "]"); + } + } + ~LOG() { + if (opened) { + cout << endl; + } + opened = false; + } + template + LOG &operator<<(const T &msg) { + if (msglevel >= LOGCFG.level) { + cout << msg; + opened = true; + } + return *this; + } +private: + bool opened = false; + typelog msglevel = DEBUG; + inline string getLabel(typelog type) { + string label; + switch (type) { + case DEBUG: label = "DEBUG"; break; + case INFO: label = "INFO "; break; + case WARN: label = "WARN "; break; + case ERR: label = "ERR"; break; + } + return label; + } +}; + +#endif /* LOG_H */ \ No newline at end of file diff --git a/Artemis/Razer2Artemis/main.cpp b/Artemis/Razer2Artemis/main.cpp index 4b0a6650f..3720cb623 100644 --- a/Artemis/Razer2Artemis/main.cpp +++ b/Artemis/Razer2Artemis/main.cpp @@ -1,8 +1,9 @@ #include "main.h" #include +#include #include #include - +using namespace std; TCHAR szName[] = TEXT("overwatchMmf"); #define WIN32_LEAN_AND_MEAN @@ -17,15 +18,15 @@ BOOL WINAPI DllMain(HINSTANCE hInst, DWORD fdwReason, LPVOID) { if (fdwReason == DLL_PROCESS_ATTACH) { - // // Get the process that loaded the DLL - // TCHAR overwatchFind[] = _T("Overwatch"); - // TCHAR szPath[MAX_PATH]; - // GetModuleFileName(nullptr, szPath, MAX_PATH); - // - // if (_tcscmp(szPath, overwatchFind) != 0) - // game = "overwatch"; - } + // Get the process that loaded the DLL + TCHAR szPath[MAX_PATH]; + GetModuleFileName(nullptr, szPath, MAX_PATH); + ofstream myfile; + myfile.open("log.txt", ios::out | ios::app); + myfile << "Main called, DLL loaded into " << szPath << "\n"; + myfile.close(); + } return true; } @@ -44,8 +45,25 @@ void WritePipe(std::string msg) pipe = CreateFile(TEXT("\\\\.\\pipe\\artemis"), GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, nullptr); if (pipe == nullptr || pipe == INVALID_HANDLE_VALUE) { + ofstream myfile; + myfile.open("log.txt", ios::out | ios::app); + myfile << "Couldn't create pipe, nullptr or INVALID_HANDLE_VALUE\n"; + myfile.close(); return; } + auto lastError = GetLastError(); + if (lastError != 0) + { + ofstream myfile; + myfile.open("log.txt", ios::out | ios::app); + myfile << "Couldn't create pipe: " << lastError << "\n"; + myfile.close(); + return; + } + ofstream myfile; + myfile.open("log.txt", ios::out | ios::app); + myfile << "Created pipe and sending msg\n"; + myfile.close(); DWORD cbWritten; WriteFile(pipe, msg.c_str(), msg.size(), &cbWritten, nullptr); @@ -53,22 +71,38 @@ void WritePipe(std::string msg) RZRESULT Init() { + ofstream myfile; + myfile.open("log.txt", ios::out | ios::app); + myfile << "Init called\n"; + myfile.close(); g_hasInitialised = true; return 0; } RZRESULT UnInit() { + ofstream myfile; + myfile.open("log.txt", ios::out | ios::app); + myfile << "UnInit called\n"; + myfile.close(); return 0; } RZRESULT CreateEffect(RZDEVICEID DeviceId, ChromaSDK::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId) { + ofstream myfile; + myfile.open("log.txt", ios::out | ios::app); + myfile << "CreateEffect called\n"; + myfile.close(); return 0; } RZRESULT CreateKeyboardEffect(ChromaSDK::Keyboard::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId) { + ofstream myfile; + myfile.open("log.txt", ios::out | ios::app); + myfile << "CreateKeyboardEffect called\n"; + myfile.close(); std::string res = ""; if (Effect == Keyboard::CHROMA_CUSTOM) { @@ -109,45 +143,81 @@ RZRESULT CreateKeyboardEffect(ChromaSDK::Keyboard::EFFECT_TYPE Effect, PRZPARAM RZRESULT CreateMouseEffect(ChromaSDK::Mouse::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId) { + ofstream myfile; + myfile.open("log.txt", ios::out | ios::app); + myfile << "CreateMouseEffect called\n"; + myfile.close(); return 0; } RZRESULT CreateHeadsetEffect(ChromaSDK::Headset::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId) { + ofstream myfile; + myfile.open("log.txt", ios::out | ios::app); + myfile << "CreateHeadsetEffect called\n"; + myfile.close(); return 0; } RZRESULT CreateMousepadEffect(ChromaSDK::Mousepad::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId) { + ofstream myfile; + myfile.open("log.txt", ios::out | ios::app); + myfile << "CreateMousepadEffect called\n"; + myfile.close(); return 0; } RZRESULT CreateKeypadEffect(ChromaSDK::Keypad::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId) { + ofstream myfile; + myfile.open("log.txt", ios::out | ios::app); + myfile << "CreateKeypadEffect called\n"; + myfile.close(); return 0; } RZRESULT DeleteEffect(RZEFFECTID EffectId) { + ofstream myfile; + myfile.open("log.txt", ios::out | ios::app); + myfile << "DeleteEffect called\n"; + myfile.close(); return 0; } RZRESULT SetEffect(RZEFFECTID EffectId) { + ofstream myfile; + myfile.open("log.txt", ios::out | ios::app); + myfile << "SetEffect called\n"; + myfile.close(); return 0; } RZRESULT RegisterEventNotification(HWND hWnd) { + ofstream myfile; + myfile.open("log.txt", ios::out | ios::app); + myfile << "RegisterEventNotification called\n"; + myfile.close(); return 0; } RZRESULT UnregisterEventNotification() { + ofstream myfile; + myfile.open("log.txt", ios::out | ios::app); + myfile << "UnregisterEventNotification called\n"; + myfile.close(); return 0; } RZRESULT QueryDevice(RZDEVICEID DeviceId, DEVICE_INFO_TYPE& DeviceInfo) { + ofstream myfile; + myfile.open("log.txt", ios::out | ios::app); + myfile << "QueryDevice called\n"; + myfile.close(); return 0; }