Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/engine/main.cpp

Issue 10790071: Send debug output to a file (Closed)
Patch Set: Created May 31, 2013, 9:54 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/engine/Debug.cpp ('K') | « src/engine/Utils.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/engine/main.cpp
===================================================================
--- a/src/engine/main.cpp
+++ b/src/engine/main.cpp
@@ -1,35 +1,19 @@
#include "stdafx.h"
#include "../shared/AutoHandle.h"
#include "../shared/Communication.h"
+#include "Debug.h"
+#include "Utils.h"
namespace
{
std::auto_ptr<AdblockPlus::FilterEngine> filterEngine;
- void Log(const std::string& message)
- {
- // TODO: Log to a log file
- MessageBoxA(0, ("AdblockPlusEngine: " + message).c_str(), "", MB_OK);
- }
-
- void LogLastError(const std::string& message)
- {
- std::stringstream stream;
- stream << message << " (Error code: " << GetLastError() << ")";
- Log(stream.str());
- }
-
- void LogException(const std::exception& exception)
- {
- Log(std::string("An exception occurred: ") + exception.what());
- }
-
std::string ToUtf8String(std::wstring str)
{
size_t length = str.size();
if (length == 0)
return std::string();
DWORD utf8StringLength = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), length, 0, 0, 0, 0);
if (utf8StringLength == 0)
@@ -152,53 +136,23 @@ namespace
try
{
Communication::InputBuffer message = pipe->ReadMessage();
Communication::OutputBuffer response = HandleRequest(message);
pipe->WriteMessage(response);
}
catch (const std::exception& e)
{
- LogException(e);
+ DebugException(e);
}
// TODO: Keep the pipe open until the client disconnects
return 0;
}
-
- bool IsWindowsVistaOrLater()
- {
- OSVERSIONINFOEX osvi;
- ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
- GetVersionEx(reinterpret_cast<LPOSVERSIONINFO>(&osvi));
- return osvi.dwMajorVersion >= 6;
- }
-}
-
-std::wstring GetAppDataPath()
-{
- std::wstring appDataPath;
- if (IsWindowsVistaOrLater())
- {
- WCHAR* pathBuffer;
- if (FAILED(SHGetKnownFolderPath(FOLDERID_LocalAppDataLow, 0, 0, &pathBuffer)))
- throw std::runtime_error("Unable to find app data directory");
- appDataPath.assign(pathBuffer);
- CoTaskMemFree(pathBuffer);
- }
- else
- {
- std::auto_ptr<wchar_t> pathBuffer(new wchar_t[MAX_PATH]);
- if (!SHGetSpecialFolderPath(0, pathBuffer.get(), CSIDL_LOCAL_APPDATA, true))
- throw std::runtime_error("Unable to find app data directory");
- appDataPath.assign(pathBuffer.get());
- }
- return appDataPath + L"\\AdblockPlus";
}
std::auto_ptr<AdblockPlus::FilterEngine> CreateFilterEngine()
{
// TODO: Pass appInfo in, which should be sent by the client
AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New();
std::string dataPath = ToUtf8String(GetAppDataPath());
dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get())->SetBasePath(dataPath);
@@ -224,21 +178,21 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE,
Communication::Pipe* pipe = new Communication::Pipe(Communication::pipeName,
Communication::Pipe::MODE_CREATE);
// TODO: Count established connections, kill the engine when none are left
AutoHandle thread(CreateThread(0, 0, ClientThread, static_cast<LPVOID>(pipe), 0, 0));
if (!thread.get())
{
delete pipe;
- LogLastError("CreateThread failed");
+ DebugLastError("CreateThread failed");
return 1;
}
}
catch (std::runtime_error e)
{
- LogException(e);
+ DebugException(e);
return 1;
}
}
return 0;
}
« src/engine/Debug.cpp ('K') | « src/engine/Utils.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld