diff --git a/shell_integration/windows/NCContextMenu/NCClientInterface.cpp b/shell_integration/windows/NCContextMenu/NCClientInterface.cpp index 864e9950676fe..df54575d93a8f 100644 --- a/shell_integration/windows/NCContextMenu/NCClientInterface.cpp +++ b/shell_integration/windows/NCContextMenu/NCClientInterface.cpp @@ -46,8 +46,8 @@ NCClientInterface::ContextMenuInfo NCClientInterface::FetchInfo(const std::wstri logger << "error with Connect" << std::endl; return {}; } - socket.SendMsg(L"GET_STRINGS:CONTEXT_MENU_TITLE\n"); - socket.SendMsg((L"GET_MENU_ITEMS:" + files + L"\n").data()); + socket.SendMsg(L"GET_STRINGS:CONTEXT_MENU_TITLE\n", logger); + socket.SendMsg((L"GET_MENU_ITEMS:" + files + L"\n").data(), logger); ContextMenuInfo info; std::wstring response; @@ -97,7 +97,7 @@ NCClientInterface::ContextMenuInfo NCClientInterface::FetchInfo(const std::wstri return info; } -void NCClientInterface::SendRequest(const wchar_t *verb, const std::wstring &path) +void NCClientInterface::SendRequest(const wchar_t *verb, const std::wstring &path, std::ofstream &logger) { auto pipename = CommunicationSocket::DefaultPipePath(); @@ -109,5 +109,5 @@ void NCClientInterface::SendRequest(const wchar_t *verb, const std::wstring &pat return; } - socket.SendMsg((verb + (L":" + path + L"\n")).data()); + socket.SendMsg((verb + (L":" + path + L"\n")).data(), logger); } diff --git a/shell_integration/windows/NCContextMenu/NCClientInterface.h b/shell_integration/windows/NCContextMenu/NCClientInterface.h index 02dc3cdb6b4ff..c0d145c38c03d 100644 --- a/shell_integration/windows/NCContextMenu/NCClientInterface.h +++ b/shell_integration/windows/NCContextMenu/NCClientInterface.h @@ -54,7 +54,7 @@ class NCClientInterface std::vector menuItems; }; static ContextMenuInfo FetchInfo(const std::wstring &files, std::ofstream &logger); - static void SendRequest(const wchar_t *verb, const std::wstring &path); + static void SendRequest(const wchar_t *verb, const std::wstring &path, std::ofstream &logger); }; #endif //ABSTRACTSOCKETHANDLER_H diff --git a/shell_integration/windows/NCContextMenu/NCContextMenu.cpp b/shell_integration/windows/NCContextMenu/NCContextMenu.cpp index fc774b30bc8a0..72f91cc347649 100644 --- a/shell_integration/windows/NCContextMenu/NCContextMenu.cpp +++ b/shell_integration/windows/NCContextMenu/NCContextMenu.cpp @@ -230,7 +230,7 @@ IFACEMETHODIMP NCContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO pici) return E_FAIL; } - NCClientInterface::SendRequest(command.data(), m_selectedFiles); + NCClientInterface::SendRequest(command.data(), m_selectedFiles, m_logger); return S_OK; } diff --git a/shell_integration/windows/NCOverlays/NCOverlay.cpp b/shell_integration/windows/NCOverlays/NCOverlay.cpp index a70f38b23248d..9d983b3966041 100644 --- a/shell_integration/windows/NCOverlays/NCOverlay.cpp +++ b/shell_integration/windows/NCOverlays/NCOverlay.cpp @@ -35,22 +35,24 @@ namespace { unique_ptr s_instance; -RemotePathChecker *getGlobalChecker() +RemotePathChecker *getGlobalChecker(ofstream &logger) { // On Vista we'll run into issue #2680 if we try to create the thread+pipe connection // on any DllGetClassObject of our registered classes. // Work around the issue by creating the static RemotePathChecker only once actually needed. static once_flag s_onceFlag; - call_once(s_onceFlag, [] { s_instance.reset(new RemotePathChecker); }); + call_once(s_onceFlag, [&logger] { s_instance.reset(new RemotePathChecker{logger}); }); return s_instance.get(); } } -NCOverlay::NCOverlay(int state) +NCOverlay::NCOverlay(int state) : _referenceCount(1) , _state(state) { + m_logger.open("c:\\testOverlay.log"); + m_logger << "hello world" << std::endl; } NCOverlay::~NCOverlay(void) @@ -120,7 +122,7 @@ IFACEMETHODIMP NCOverlay::GetPriority(int *pPriority) IFACEMETHODIMP NCOverlay::IsMemberOf(PCWSTR pwszPath, DWORD dwAttrib) { - RemotePathChecker* checker = getGlobalChecker(); + RemotePathChecker* checker = getGlobalChecker(m_logger); std::shared_ptr> watchedDirectories = checker->WatchedDirectories(); if (watchedDirectories->empty()) { diff --git a/shell_integration/windows/NCOverlays/NCOverlay.h b/shell_integration/windows/NCOverlays/NCOverlay.h index 688a6b0950287..45966c9f51d88 100644 --- a/shell_integration/windows/NCOverlays/NCOverlay.h +++ b/shell_integration/windows/NCOverlays/NCOverlay.h @@ -18,12 +18,13 @@ #pragma once #include +#include class NCOverlay : public IShellIconOverlayIdentifier { public: - NCOverlay(int state); + explicit NCOverlay(int state); IFACEMETHODIMP_(ULONG) AddRef(); IFACEMETHODIMP GetOverlayInfo(PWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags); @@ -38,6 +39,7 @@ class NCOverlay : public IShellIconOverlayIdentifier private: long _referenceCount; int _state; + std::ofstream m_logger; }; -#endif \ No newline at end of file +#endif diff --git a/shell_integration/windows/NCUtil/CommunicationSocket.cpp b/shell_integration/windows/NCUtil/CommunicationSocket.cpp index 6f9cdbb983c63..06232675df089 100644 --- a/shell_integration/windows/NCUtil/CommunicationSocket.cpp +++ b/shell_integration/windows/NCUtil/CommunicationSocket.cpp @@ -81,8 +81,10 @@ bool CommunicationSocket::Connect(const std::wstring &pipename) return true; } -bool CommunicationSocket::SendMsg(const wchar_t* message) const +bool CommunicationSocket::SendMsg(const wchar_t* message, std::ofstream &logger) const { + logger << "CommunicationSocket::SendMsg: " << (*message) << std::endl; + auto utf8_msg = StringUtil::toUtf8(message); DWORD numBytesWritten = 0; diff --git a/shell_integration/windows/NCUtil/CommunicationSocket.h b/shell_integration/windows/NCUtil/CommunicationSocket.h index bc55c2d933de2..0b631a849670f 100644 --- a/shell_integration/windows/NCUtil/CommunicationSocket.h +++ b/shell_integration/windows/NCUtil/CommunicationSocket.h @@ -21,6 +21,7 @@ #include #include +#include #include class __declspec(dllexport) CommunicationSocket @@ -34,7 +35,7 @@ class __declspec(dllexport) CommunicationSocket bool Connect(const std::wstring& pipename); bool Close(); - bool SendMsg(const wchar_t*) const; + bool SendMsg(const wchar_t*, std::ofstream &logger) const; bool ReadLine(std::wstring*); HANDLE Event() { return _pipe; } diff --git a/shell_integration/windows/NCUtil/RemotePathChecker.cpp b/shell_integration/windows/NCUtil/RemotePathChecker.cpp index 5d004d567d286..e61725dd58b76 100644 --- a/shell_integration/windows/NCUtil/RemotePathChecker.cpp +++ b/shell_integration/windows/NCUtil/RemotePathChecker.cpp @@ -30,7 +30,7 @@ using namespace std; // This code is run in a thread -void RemotePathChecker::workerThreadLoop() +void RemotePathChecker::workerThreadLoop(ofstream &logger) { auto pipename = CommunicationSocket::DefaultPipePath(); bool connected = false; @@ -62,7 +62,7 @@ void RemotePathChecker::workerThreadLoop() lock.unlock(); if (!asked.count(filePath)) { asked.insert(filePath); - socket.SendMsg(wstring(L"RETRIEVE_FILE_STATUS:" + filePath + L'\n').data()); + socket.SendMsg(wstring(L"RETRIEVE_FILE_STATUS:" + filePath + L'\n').data(), logger); } lock.lock(); } @@ -162,12 +162,12 @@ void RemotePathChecker::workerThreadLoop() -RemotePathChecker::RemotePathChecker() +RemotePathChecker::RemotePathChecker(ofstream &logger) : _stop(false) , _watchedDirectories(make_shared>()) , _connected(false) , _newQueries(CreateEvent(nullptr, FALSE, FALSE, nullptr)) - , _thread([this]{ this->workerThreadLoop(); }) + , _thread([this, &logger]{ this->workerThreadLoop(logger); }) { } diff --git a/shell_integration/windows/NCUtil/RemotePathChecker.h b/shell_integration/windows/NCUtil/RemotePathChecker.h index 134138f137244..63afba079f928 100644 --- a/shell_integration/windows/NCUtil/RemotePathChecker.h +++ b/shell_integration/windows/NCUtil/RemotePathChecker.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #pragma once @@ -36,7 +37,7 @@ class RemotePathChecker { StateWarning, StateNone }; - RemotePathChecker(); + explicit RemotePathChecker(std::ofstream &logger); ~RemotePathChecker(); std::shared_ptr> WatchedDirectories() const; bool IsMonitoredPath(const wchar_t* filePath, int* state); @@ -64,7 +65,7 @@ class RemotePathChecker { HANDLE _newQueries; std::thread _thread; - void workerThreadLoop(); + void workerThreadLoop(std::ofstream &logger); }; -#endif \ No newline at end of file +#endif diff --git a/src/gui/application.cpp b/src/gui/application.cpp index ab80245bb24e6..98832bf04078a 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -659,8 +659,9 @@ void Application::setupLogging() logger->setLogDir(_logDir.isEmpty() ? ConfigFile().logDir() : _logDir); } logger->setLogExpire(_logExpire > 0 ? _logExpire : ConfigFile().logExpire()); - logger->setLogFlush(_logFlush || ConfigFile().logFlush()); - logger->setLogDebug(_logDebug || ConfigFile().logDebug()); + logger->setLogFlush(true || _logFlush || ConfigFile().logFlush()); + logger->setLogDebug(true || _logDebug || ConfigFile().logDebug()); + if (!logger->isLoggingToFile() && ConfigFile().automaticLogDir()) { logger->setupTemporaryFolderLogDir(); } diff --git a/src/gui/socketapi/socketapi.cpp b/src/gui/socketapi/socketapi.cpp index 69cd4127f5f5b..f66867676ed86 100644 --- a/src/gui/socketapi/socketapi.cpp +++ b/src/gui/socketapi/socketapi.cpp @@ -1352,7 +1352,7 @@ SocketApi::FileData SocketApi::FileData::parentFolder() const void SocketApi::command_GET_MENU_ITEMS(const QString &argument, OCC::SocketListener *listener) { - listener->sendMessage(QString("GET_MENU_ITEMS:BEGIN")); + listener->sendMessage(QString("GET_MENU_ITEMS:BEGIN"), true); const QStringList files = split(argument); // Find the common sync folder.