Left: | ||
Right: |
OLD | NEW |
---|---|
1 #include "stdafx.h" | 1 #include "stdafx.h" |
2 | 2 |
3 #include "../shared/AutoHandle.h" | 3 #include "../shared/AutoHandle.h" |
4 #include "../shared/Communication.h" | 4 #include "../shared/Communication.h" |
5 #include "Debug.h" | 5 #include "Debug.h" |
6 #include "Utils.h" | 6 #include "Utils.h" |
7 | 7 |
8 namespace | 8 namespace |
9 { | 9 { |
10 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; | 10 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 { | 155 { |
156 DebugException(e); | 156 DebugException(e); |
157 } | 157 } |
158 | 158 |
159 // TODO: Keep the pipe open until the client disconnects | 159 // TODO: Keep the pipe open until the client disconnects |
160 | 160 |
161 return 0; | 161 return 0; |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 std::auto_ptr<AdblockPlus::FilterEngine> CreateFilterEngine() | 165 std::auto_ptr<AdblockPlus::FilterEngine> CreateFilterEngine(const std::wstring& locale) |
166 { | 166 { |
167 // TODO: Pass appInfo in, which should be sent by the client | 167 AdblockPlus::AppInfo appInfo; |
Felix Dahlke
2013/06/04 09:46:09
The version's missing, would like to see at least
| |
168 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(); | 168 appInfo.name = "adblockplusie"; |
169 appInfo.platform = "msie"; | |
170 appInfo.locale = ToUtf8String(locale); | |
171 | |
172 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo); | |
169 std::string dataPath = ToUtf8String(GetAppDataPath()); | 173 std::string dataPath = ToUtf8String(GetAppDataPath()); |
170 dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get()) ->SetBasePath(dataPath); | 174 dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get()) ->SetBasePath(dataPath); |
171 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterE ngine(jsEngine)); | 175 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterE ngine(jsEngine)); |
172 return filterEngine; | 176 return filterEngine; |
173 } | 177 } |
174 | 178 |
175 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) | 179 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) |
176 { | 180 { |
177 // TODO: Attempt to create the pipe first, and exit immediately if this | 181 // TODO: Attempt to create the pipe first, and exit immediately if this |
178 // fails. Since multiple instances of the engine could be running, | 182 // fails. Since multiple instances of the engine could be running, |
179 // this may need named mutices to avoid race conditions. | 183 // this may need named mutices to avoid race conditions. |
180 // Note that as soon as the pipe is created first, we can reduce the | 184 // Note that as soon as the pipe is created first, we can reduce the |
181 // client timeout after CreateProcess(), but should increase the one | 185 // client timeout after CreateProcess(), but should increase the one |
182 // in WaitNamedPipe(). | 186 // in WaitNamedPipe(). |
183 | 187 |
184 filterEngine = CreateFilterEngine(); | 188 int argc; |
189 LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); | |
Felix Dahlke
2013/06/04 09:46:09
According to the docs, you need to free argv using
| |
190 std::wstring locale(argc >= 1 ? argv[0] : L""); | |
191 filterEngine = CreateFilterEngine(locale); | |
185 | 192 |
186 for (;;) | 193 for (;;) |
187 { | 194 { |
188 try | 195 try |
189 { | 196 { |
190 Communication::Pipe* pipe = new Communication::Pipe(Communication::pipeNam e, | 197 Communication::Pipe* pipe = new Communication::Pipe(Communication::pipeNam e, |
191 Communication::Pipe::MODE_CREATE); | 198 Communication::Pipe::MODE_CREATE); |
192 | 199 |
193 // TODO: Count established connections, kill the engine when none are left | 200 // TODO: Count established connections, kill the engine when none are left |
194 AutoHandle thread(CreateThread(0, 0, ClientThread, static_cast<LPVOID>(pip e), 0, 0)); | 201 AutoHandle thread(CreateThread(0, 0, ClientThread, static_cast<LPVOID>(pip e), 0, 0)); |
195 if (!thread.get()) | 202 if (!thread.get()) |
196 { | 203 { |
197 delete pipe; | 204 delete pipe; |
198 DebugLastError("CreateThread failed"); | 205 DebugLastError("CreateThread failed"); |
199 return 1; | 206 return 1; |
200 } | 207 } |
201 } | 208 } |
202 catch (std::runtime_error e) | 209 catch (std::runtime_error e) |
203 { | 210 { |
204 DebugException(e); | 211 DebugException(e); |
205 return 1; | 212 return 1; |
206 } | 213 } |
207 } | 214 } |
208 | 215 |
209 return 0; | 216 return 0; |
210 } | 217 } |
OLD | NEW |