Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow exporting config and debug.txt with one click (on all platforms) #13605

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ read_globals = {
"profiler",
"Settings",

string = {fields = {"split", "trim"}},
string = {fields = {"split", "tail", "trim"}},
table = {fields = {"copy", "getn", "indexof", "insert_all"}},
math = {fields = {"hypot", "round"}},
}
Expand Down
10 changes: 0 additions & 10 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,6 @@
android:enabled="true"
android:exported="false" />

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="net.minetest.minetest.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>

</application>

</manifest>
20 changes: 4 additions & 16 deletions android/app/src/main/java/net/minetest/minetest/GameActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import android.net.Uri;
import android.os.Bundle;
import android.text.InputType;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
Expand All @@ -35,9 +34,7 @@

import androidx.annotation.Keep;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.FileProvider;

import java.io.File;
import java.util.Locale;
import java.util.Objects;

Expand Down Expand Up @@ -176,19 +173,10 @@ public String getCachePath() {
return Utils.getCacheDirectory(this).getAbsolutePath();
}

public void shareFile(String path) {
File file = new File(path);
if (!file.exists()) {
Log.e("GameActivity", "File " + file.getAbsolutePath() + " doesn't exist");
return;
}

Uri fileUri = FileProvider.getUriForFile(this, "net.minetest.minetest.fileprovider", file);

Intent intent = new Intent(Intent.ACTION_SEND, fileUri);
intent.setDataAndType(fileUri, getContentResolver().getType(fileUri));
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_STREAM, fileUri);
public void shareText(String text) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, text);

Intent shareIntent = Intent.createChooser(intent, null);
startActivity(shareIntent);
Expand Down
21 changes: 21 additions & 0 deletions builtin/common/misc_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,27 @@ function string.split(str, delim, include_empty, max_splits, sep_is_pattern)
return items
end

--------------------------------------------------------------------------------
function string.tail(str, num_lines)
Copy link
Contributor

@appgurueu appgurueu Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not very important, but if we're gonna expose this, I'd probably try to give it a clearer name ("tail" may also be in reference to characters rather than lines). I'd also probably implement this using a reverse numeric for: for index = #str, 1, -1 do local char = str:sub(index, index)...

local first_char = 1

local str_reversed = str:reverse()
local index = #str
local num_newlines = 0
for char in str_reversed:gmatch(".") do
if char == "\n" then -- catches CRLF as well
num_newlines = num_newlines + 1
end
if num_newlines > num_lines then
first_char = index + 1
break
end
index = index - 1
end

return str:sub(first_char)
end

--------------------------------------------------------------------------------
function table.indexof(list, val)
for i, v in ipairs(list) do
Expand Down
32 changes: 32 additions & 0 deletions builtin/common/tests/misc_helpers_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,38 @@ describe("string", function()
end)
end)
end)

it("tail()", function()
local test_str_lf = "123456\n234567\n345678\n456789\n"
local test_str_crlf = "123456\r\n234567\r\n345678\r\n456789\r\n"

assert.equal(string.tail(test_str_lf, -math.huge), "")
assert.equal(string.tail(test_str_crlf, -math.huge), "")

assert.equal(string.tail(test_str_lf, -1), "")
assert.equal(string.tail(test_str_crlf, -1), "")

assert.equal(string.tail(test_str_lf, 0), "")
assert.equal(string.tail(test_str_crlf, 0), "")

assert.equal(string.tail(test_str_lf, 1), "456789\n")
assert.equal(string.tail(test_str_crlf, 1), "456789\r\n")

assert.equal(string.tail(test_str_lf, 2), "345678\n456789\n")
assert.equal(string.tail(test_str_crlf, 2), "345678\r\n456789\r\n")

assert.equal(string.tail(test_str_lf, 3), "234567\n345678\n456789\n")
assert.equal(string.tail(test_str_crlf, 3), "234567\r\n345678\r\n456789\r\n")

assert.equal(string.tail(test_str_lf, 4), test_str_lf)
assert.equal(string.tail(test_str_crlf, 4), test_str_crlf)

assert.equal(string.tail(test_str_lf, 5), test_str_lf)
assert.equal(string.tail(test_str_crlf, 5), test_str_crlf)

assert.equal(string.tail(test_str_lf, math.huge), test_str_lf)
assert.equal(string.tail(test_str_crlf, math.huge), test_str_crlf)
end)
end)

describe("privs", function()
Expand Down
2 changes: 2 additions & 0 deletions builtin/mainmenu/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ mt_color_dark_green = "#25C191"
mt_color_orange = "#FF8800"
mt_color_red = "#FF3300"

SCROLLBAR_W = TOUCHSCREEN_GUI and 0.6 or 0.4

local menupath = core.get_mainmenu_path()
local basepath = core.get_builtin_path()
defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" ..
Expand Down
12 changes: 5 additions & 7 deletions builtin/mainmenu/settings/dlg_settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,8 @@ local function get_formspec(dialogdata)
height = TOUCHSCREEN_GUI and (10 - extra_h) or 12,
}

local scrollbar_w = TOUCHSCREEN_GUI and 0.6 or 0.4

local left_pane_width = TOUCHSCREEN_GUI and 4.5 or 4.25
local search_width = left_pane_width + scrollbar_w - (0.75 * 2)
local search_width = left_pane_width + SCROLLBAR_W - (0.75 * 2)
rubenwardy marked this conversation as resolved.
Show resolved Hide resolved

local technical_names_w = TOUCHSCREEN_GUI and 6 or 5
local show_technical_names = core.settings:get_bool("show_technical_names")
Expand Down Expand Up @@ -516,7 +514,7 @@ local function get_formspec(dialogdata)
if y >= tabsize.height - 1.25 then
fs[#fs + 1] = make_scrollbaroptions_for_scroll_container(tabsize.height - 1.5, y, 0.1)
fs[#fs + 1] = ("scrollbar[%f,1.25;%f,%f;vertical;leftscroll;%f]"):format(
left_pane_width + 0.25, scrollbar_w, tabsize.height - 1.5, dialogdata.leftscroll or 0)
left_pane_width + 0.25, SCROLLBAR_W, tabsize.height - 1.5, dialogdata.leftscroll or 0)
end

fs[#fs + 1] = "style_type[button;border=;bgcolor=]"
Expand All @@ -525,9 +523,9 @@ local function get_formspec(dialogdata)
dialogdata.components = page and build_page_components(page) or {}
end

local right_pane_width = tabsize.width - left_pane_width - 0.375 - 2*scrollbar_w - 0.25
local right_pane_width = tabsize.width - left_pane_width - 0.375 - 2*SCROLLBAR_W - 0.25
fs[#fs + 1] = ("scroll_container[%f,0;%f,%f;rightscroll;vertical;0.1]"):format(
tabsize.width - right_pane_width - scrollbar_w, right_pane_width, tabsize.height)
tabsize.width - right_pane_width - SCROLLBAR_W, right_pane_width, tabsize.height)

y = 0.25
for i, comp in ipairs(dialogdata.components) do
Expand Down Expand Up @@ -584,7 +582,7 @@ local function get_formspec(dialogdata)
if y >= tabsize.height then
fs[#fs + 1] = make_scrollbaroptions_for_scroll_container(tabsize.height, y + 0.375, 0.1)
fs[#fs + 1] = ("scrollbar[%f,0;%f,%f;vertical;rightscroll;%f]"):format(
tabsize.width - scrollbar_w, scrollbar_w, tabsize.height, dialogdata.rightscroll or 0)
tabsize.width - SCROLLBAR_W, SCROLLBAR_W, tabsize.height, dialogdata.rightscroll or 0)
end

return table.concat(fs, "")
Expand Down
128 changes: 92 additions & 36 deletions builtin/mainmenu/tab_about.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,49 @@ local function build_hacky_list(items, spacing)
return table.concat(ret, ""), y
end

local function read_text_file(path)
local f = io.open(path, "r")
if not f then
return "[not available]\n"
end
local text = f:read("*all")
f:close()
return text
end

local function collect_debug_info()
local version = core.get_version()
local build_info = core.get_build_info()
local irrlicht_device = core.get_active_irrlicht_device()
local driver = core.get_active_driver()
local renderer = core.get_active_renderer()

local path_prefix = core.get_user_path() .. DIR_DELIM
-- Write the current settings to "minetest.conf" so we don't read outdated ones.
core.settings:write()
local minetest_conf = read_text_file(path_prefix .. "minetest.conf")
local debug_txt = string.tail(read_text_file(path_prefix .. "debug.txt"), 64)

return table.concat({
version.project, " ", (version.hash or version.string), " (", PLATFORM, ")\n",
build_info, "\n\n",
"Active Irrlicht device = ", irrlicht_device, "\n",
"Active \"video_driver\" = ", driver, "\n", -- not redundant!
"Active renderer = ", renderer, "\n\n",
"minetest.conf\n",
"-------------\n",
minetest_conf, "\n",
"debug.txt\n",
"---------\n",
debug_txt,
})
end

return {
name = "about",
caption = fgettext("About"),
cbf_formspec = function(tabview, name, tabdata)
local logofile = defaulttexturedir .. "logo.png"
local version = core.get_version()

cbf_formspec = function(tabview, name, tabdata)
local credit_list = {}
table.insert_all(credit_list, {
core.colorize("#000", "Dedication of the current release"),
Expand Down Expand Up @@ -157,53 +193,73 @@ return {
core.colorize("#ff0", fgettext("Previous Contributors"))
})
prepare_credits(credit_list, previous_contributors)

local credit_fs, scroll_height = build_hacky_list(credit_list)
-- account for the visible portion
scroll_height = math.max(0, scroll_height - 6.9)

local fs = "image[1.5,0.6;2.5,2.5;" .. core.formspec_escape(logofile) .. "]" ..
"style[label_button;border=false]" ..
"button[0.1,3.4;5.3,0.5;label_button;" ..
core.formspec_escape(version.project .. " " .. version.string) .. "]" ..
"button[1.5,4.1;2.5,0.8;homepage;minetest.net]" ..
"scroll_container[5.5,0.1;9.5,6.9;scroll_credits;vertical;" ..
tostring(scroll_height / 1000) .. "]" .. credit_fs ..
"scroll_container_end[]"..
"scrollbar[15,0.1;0.4,6.9;vertical;scroll_credits;0]"

-- Render information
local active_renderer_info = fgettext("Active renderer:") .. " " ..
core.formspec_escape(core.get_active_renderer())
fs = fs .. "style[label_button2;border=false]" ..
"button[0.1,6;5.3,0.5;label_button2;" .. active_renderer_info .. "]"..
"tooltip[label_button2;" .. active_renderer_info .. "]"

-- Irrlicht device information
local irrlicht_device_info = fgettext("Irrlicht device:") .. " " ..
core.formspec_escape(core.get_active_irrlicht_device())
fs = fs .. "style[label_button3;border=false]" ..
"button[0.1,6.5;5.3,0.5;label_button3;" .. irrlicht_device_info .. "]"..
"tooltip[label_button3;" .. irrlicht_device_info .. "]"

if PLATFORM == "Android" then
fs = fs .. "button[0.5,5.1;4.5,0.8;share_debug;" .. fgettext("Share debug log") .. "]"
else
fs = fs .. "tooltip[userdata;" ..
local fs = {
-- This is the right half of the tab (the credits).
("scroll_container[5.5,0.1;%f,6.9;scroll_credits;vertical;%f]"):format(
9.9 - SCROLLBAR_W, scroll_height / 1000),
credit_fs,
"scroll_container_end[]",
("scrollbar[%f,0.1;%f,6.9;vertical;scroll_credits;0]"):format(
15.4 - SCROLLBAR_W, SCROLLBAR_W),
}

-- Place the content of the left half from bottom to top.
local TAB_H = 7.1
local TAB_PADDING = 0.5
local LOGO_SIZE = 2.5
local BTN_H = 0.8
local LABEL_BTN_H = 0.5

local pos_y = TAB_H - TAB_PADDING
local show_userdata_btn = PLATFORM ~= "Android"

if show_userdata_btn then
pos_y = pos_y - BTN_H
fs[#fs + 1] = "tooltip[userdata;" ..
fgettext("Opens the directory that contains user-provided worlds, games, mods,\n" ..
"and texture packs in a file manager / explorer.") .. "]"
fs = fs .. "button[0.5,5.1;4.5,0.8;userdata;" .. fgettext("Open User Data Directory") .. "]"
fs[#fs + 1] = ("button[0.5,%f;4.5,%f;userdata;%s]"):format(
pos_y, BTN_H, fgettext("Open user data directory"))
pos_y = pos_y - 0.1
end

return fs
pos_y = pos_y - BTN_H
local export_debug_label = PLATFORM == "Android" and fgettext("Share debug info") or
fgettext("Copy debug info")
fs[#fs + 1] = ("button[0.5,%f;4.5,%f;export_debug;%s]"):format(pos_y, BTN_H, export_debug_label)
pos_y = pos_y - (show_userdata_btn and 0.25 or 0.15)

pos_y = pos_y - BTN_H
fs[#fs + 1] = ("button[0.5,%f;4.5,%f;homepage;minetest.net]"):format(pos_y, BTN_H)
pos_y = pos_y - 0.15

pos_y = pos_y - LABEL_BTN_H
local version = core.get_version()
fs[#fs + 1] = "style[label_button;border=false]"
fs[#fs + 1] = ("button[0.1,%f;5.3,%f;label_button;%s]"):format(
pos_y, LABEL_BTN_H, core.formspec_escape(version.project .. " " .. version.string))

local logofile = core.formspec_escape(defaulttexturedir .. "logo.png")
-- Place the logo in the middle of the remaining vertical space.
fs[#fs + 1] = ("image[1.5,%f;%f,%f;%s]"):format(
pos_y / 2 - LOGO_SIZE / 2, LOGO_SIZE, LOGO_SIZE, logofile)

return table.concat(fs)
end,

cbf_button_handler = function(this, fields, name, tabdata)
if fields.homepage then
core.open_url("https://www.minetest.net")
end

if fields.share_debug then
local path = core.get_user_path() .. DIR_DELIM .. "debug.txt"
core.share_file(path)
if fields.export_debug then
local export_fn = PLATFORM == "Android" and core.share_text or core.copy_text
export_fn(collect_debug_info())
end

if fields.userdata then
Expand Down
2 changes: 2 additions & 0 deletions doc/client_lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@ Helper functions
* If `max_splits` is negative, do not limit splits.
* `sep_is_pattern` specifies if separator is a plain string or a pattern (regex).
* e.g. `string:split("a,b", ",") == {"a","b"}`
* `string.tail(str, num_lines)`
* Returns the last `num_lines` lines of `str`.
* `string:trim()`
* e.g. `string.trim("\n \t\tfoo bar\t ") == "foo bar"`
* `minetest.wrap_text(str, limit)`: returns a string
Expand Down
2 changes: 2 additions & 0 deletions doc/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3898,6 +3898,8 @@ Helper functions
* `sep_is_pattern`: boolean, it specifies whether separator is a plain
string or a pattern (regex), default: `false`
* e.g. `"a,b":split","` returns `{"a","b"}`
* `string.tail(str, num_lines)`
* Returns the last `num_lines` lines of `str`.
* `string:trim()`: returns the string without whitespace pre- and suffixes
* e.g. `"\n \t\tfoo bar\t ":trim()` returns `"foo bar"`
* `minetest.wrap_text(str, limit, as_table)`: returns a string or table
Expand Down
8 changes: 6 additions & 2 deletions doc/menu_lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ Functions
* `core.open_dir(path)`
* opens the path in the system file browser/explorer, returns false on failure.
* Must be an existing directory.
* `core.share_file(path)`
* Android only. Shares file using the share popup
* `core.copy_text(text)`
* Copies `text` to the clipboard.
* `core.share_text(text)`
* Android only. Shares `text` using the share popup.
* `core.get_version()` (possible in async calls)
* returns current core version
* `core.get_build_info()`
* Returns a string containing build information, similar to the output of `minetest --version`.



Expand Down
2 changes: 1 addition & 1 deletion games/devtest/.luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ read_globals = {
"check",
"PseudoRandom",

string = {fields = {"split", "trim"}},
string = {fields = {"split", "tail", "trim"}},
table = {fields = {"copy", "getn", "indexof", "insert_all"}},
math = {fields = {"hypot", "round"}},
}
Expand Down
1 change: 1 addition & 0 deletions src/cmake_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define STATIC_LOCALEDIR "@LOCALEDIR@"
#define BUILD_TYPE "@CMAKE_BUILD_TYPE@"
#define ICON_DIR "@ICONDIR@"
#define ARCH "@CMAKE_SYSTEM_PROCESSOR@"
#cmakedefine01 RUN_IN_PLACE
#cmakedefine01 DEVELOPMENT_BUILD
#cmakedefine01 ENABLE_UPDATE_CHECKER
Expand Down