Skip to content
Snippets Groups Projects
Commit 3fbb964f authored by DarkGod's avatar DarkGod
Browse files

Removed os.execute altogether

parent 3c131d28
No related branches found
No related tags found
No related merge requests found
......@@ -2315,7 +2315,6 @@ function util.uuid()
end
function util.browserOpenUrl(url, forbid_methods)
local osexecute = os.execute
forbid_methods = forbid_methods or {}
if forbid_methods.is_external and config.settings.open_links_external then
forbid_methods.webview = true
......@@ -2324,25 +2323,10 @@ function util.browserOpenUrl(url, forbid_methods)
if core.webview and not forbid_methods.webview then local d = require("engine.ui.Dialog"):webPopup(url) if d then return "webview", d end end
if core.steam and not forbid_methods.steam and core.steam.openOverlayUrl(url) then return "steam", true end
if forbid_methods.native then return false end
if core.game.openBrowser(url) then return "native", true end
local tries = {
"rundll32 url.dll,FileProtocolHandler %s", -- Windows
"open %s", -- OSX
"xdg-open %s", -- Linux - portable way
"gnome-open %s", -- Linux - Gnome
"kde-open %s", -- Linux - Kde
"firefox %s", -- Linux - try to find something
"mozilla-firefox %s", -- Linux - try to find something
"google-chrome-stable %s", -- Linux - try to find something
"google-chrome %s", -- Linux - try to find something
}
while #tries > 0 do
local urlbase = table.remove(tries, 1)
urlbase = urlbase:format(url)
print("Trying to run URL with command: ", urlbase)
if osexecute(urlbase) == 0 then return "native", true end
end
return false
end
......@@ -2390,12 +2374,3 @@ end
function util.steamCanCloud()
if core.steam and core.steam.isCloudEnabled(true) and core.steam.isCloudEnabled(false) and not savefile_pipe.disable_cloud_saves then return true end
end
--------------------------------------------------------------
-- Remove invalidate some dangerous functions
--------------------------------------------------------------
os.execute = nil
os.getenv = nil
os.remove = nil
os.rename = nil
......@@ -185,3 +185,11 @@ function string.unserialize(str)
local ok, err = pcall(f)
if ok then return setmetatable(t, nil) else print("[UNSERIALIZE] error", err) return nil end
end
--------------------------------------------------------------
-- Remove invalidate some dangerous functions
--------------------------------------------------------------
os.execute = nil
os.getenv = nil
os.remove = nil
os.rename = nil
......@@ -597,6 +597,28 @@ static int lua_force_next_tick(lua_State *L)
return 0;
}
static int lua_open_browser(lua_State *L)
{
#if defined(SELFEXE_LINUX) || defined(SELFEXE_BSD)
const char *command = "xdg-open \"%s\"";
#elif defined(SELFEXE_WINDOWS)
const char *command = "rundll32 url.dll,FileProtocolHandler \"%s\"";
#elif defined(SELFEXE_MACOSX)
const char *command = "open \"%s\"";
#else
{ return 0; }
#endif
char buf[2048];
size_t len;
char *path = strdup(luaL_checklstring(L, 1, &len));
size_t i;
for (i = 0; i < len; i++) if (path[i] == '"') path[i] = '_'; // Just dont put " in there
snprintf(buf, 2047, command, path);
lua_pushboolean(L, system(buf) == 0);
return 1;
}
static const struct luaL_Reg gamelib[] =
{
{"setRebootMessage", lua_set_reboot_message},
......@@ -612,6 +634,7 @@ static const struct luaL_Reg gamelib[] =
{"requestNextTick", lua_force_next_tick},
{"checkError", lua_check_error},
{"resetLocale", lua_reset_locale},
{"openBrowser", lua_open_browser},
{NULL, NULL},
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment