|
21 | 21 | using namespace std;
|
22 | 22 | namespace bo = boost;
|
23 | 23 |
|
24 |
| -string desktopName = "HeadlessDesktop"; |
| 24 | +string desktopName; |
25 | 25 |
|
26 | 26 | template <class SepT, class IterT>
|
27 | 27 | SepT join(IterT begin, const IterT end, const SepT &sep)
|
@@ -58,9 +58,24 @@ string getAppCmdArgs() {
|
58 | 58 | return cmdLine;
|
59 | 59 | }
|
60 | 60 |
|
| 61 | +void prepareDesktopName() { |
| 62 | + if (Environment::variableExists("HEADLESS_UNIQUE")) { |
| 63 | + bo::random_device random; |
| 64 | + |
| 65 | + string name; |
| 66 | + do { |
| 67 | + name = (bo::format("HeadlessDesktop_%1%") % random()).str(); |
| 68 | + } while (Desktop::exists(name)); |
| 69 | + |
| 70 | + desktopName = name; |
| 71 | + } |
| 72 | + else |
| 73 | + desktopName = "HeadlessDesktop"; |
| 74 | +} |
| 75 | + |
61 | 76 | // TODO: Implement safer SearchPath.
|
62 | 77 | string findIEDriver() {
|
63 |
| - bo::shared_ptr<wchar_t[]> buffer(new wchar_t[32*1024]); |
| 78 | + bo::movelib::unique_ptr<wchar_t[]> buffer(new wchar_t[32*1024]); |
64 | 79 | wchar_t *bufferEnd = 0;
|
65 | 80 |
|
66 | 81 | DWORD length = SearchPath(
|
@@ -90,7 +105,7 @@ void cleanUp() {
|
90 | 105 | LOGD << "Top level windows in the headless desktop: " << topWindows.size();
|
91 | 106 |
|
92 | 107 | for (HWND w : topWindows) {
|
93 |
| - LOGT << bo::format("Quitting the '%1%' top level window.") % w; |
| 108 | + LOGT << (bo::format("Quitting the '%1%' top level window.") % w).str(); |
94 | 109 |
|
95 | 110 | PostMessage(w, WM_ENDSESSION, NULL, ENDSESSION_CLOSEAPP);
|
96 | 111 | PostMessage(w, WM_QUIT, 0, 0);
|
@@ -138,6 +153,8 @@ int _tmain(int argc, _TCHAR* argv[])
|
138 | 153 | try {
|
139 | 154 | setupLogger();
|
140 | 155 |
|
| 156 | + prepareDesktopName(); |
| 157 | + |
141 | 158 | string cmdLine = getAppCmdArgs();
|
142 | 159 | string ieDriverPath = findIEDriver();
|
143 | 160 |
|
|
0 commit comments