Skip to content

Commit 00b51b7

Browse files
committed
fix opening profiling in browser on windows
1 parent 752717e commit 00b51b7

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

sources/libcore/concurrent/openUrl.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,35 @@ namespace cage
1818
namespace
1919
{
2020
#ifdef CAGE_SYSTEM_WINDOWS
21-
bool windowsTryFile(const String &url)
21+
void windowsOpenUrl(const String &url)
2222
{
23-
if (!isPattern(toLower(url), "file:/", "", ""))
24-
return false;
25-
String file = subString(url, 0, find(url, '?'));
26-
file = trim(subString(file, 5, m), true, false, "/");
27-
char tmp[MAX_PATH + 1] = {};
28-
auto res = FindExecutable(file.c_str(), NULL, tmp); // find default browser
29-
if (res > (HINSTANCE)32)
23+
const String esc = Stringizer() + "\"" + url + "\"";
24+
if (isPattern(toLower(url), "file:/", "", ""))
3025
{
31-
res = ShellExecute(NULL, "open", tmp, url.c_str(), NULL, SW_SHOWNORMAL);
32-
return res > (HINSTANCE)32;
26+
String file = subString(url, 0, find(url, '?'));
27+
file = trim(subString(file, 5, m), true, false, "/");
28+
char tmp[MAX_PATH + 1] = {};
29+
auto res = FindExecutable(file.c_str(), NULL, tmp); // find default browser
30+
if (res > (HINSTANCE)32)
31+
{
32+
res = ShellExecute(NULL, "open", tmp, esc.c_str(), NULL, SW_SHOWNORMAL);
33+
if (res > (HINSTANCE)32)
34+
return;
35+
}
3336
}
34-
return false;
37+
ShellExecute(NULL, "open", (Stringizer() + "\"" + url + "\"").value.c_str(), NULL, NULL, SW_SHOWNORMAL);
3538
}
3639
#endif
3740
}
3841

39-
void openUrl(const String &url)
42+
void openUrl(const String &url_)
4043
{
44+
const String url = replace(url_, "\"", "\\\"");
4145
CAGE_LOG(SeverityEnum::Info, "openUrl", Stringizer() + "opening browser with url: " + url);
4246
#ifdef CAGE_SYSTEM_WINDOWS
43-
if (!windowsTryFile(url))
44-
ShellExecute(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
47+
windowsOpenUrl(url);
4548
#else
46-
const String s = replace(url, "\"", "\\\"");
47-
std::system((Stringizer() + "xdg-open \"" + s + "\"").value.c_str());
49+
std::system((Stringizer() + "xdg-open \"" + url + "\"").value.c_str());
4850
#endif
4951
}
5052
}

sources/libcore/profiling.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <cage-core/concurrent.h>
99
#include <cage-core/concurrentQueue.h>
1010
#include <cage-core/config.h>
11-
#include <cage-core/string.h>
1211
#include <cage-core/files.h>
1312
#include <cage-core/math.h>
1413
#include <cage-core/networkWebsocket.h>
@@ -203,7 +202,7 @@ namespace cage
203202
try
204203
{
205204
writeFile("profiling.htm")->write(profiling_htm().cast<const char>());
206-
const String baseUrl = replace(pathWorkingDir(), " ", "%20") + "/profiling.htm";
205+
const String baseUrl = pathWorkingDir() + "/profiling.htm";
207206
const String url = Stringizer() + "file://" + baseUrl + "?port=" + server->port();
208207
openUrl(url);
209208
}

0 commit comments

Comments
 (0)