Skip to content
Snippets Groups Projects
Commit cfa82c4b authored by dg's avatar dg
Browse files

Error repor window has a close all buton, can be closed with Esc and tells if the error is new

git-svn-id: http://svn.net-core.org/repos/t-engine4@4968 51575b47-30f0-44d4-a5cc-537603b46e54
parent 20701851
No related branches found
No related tags found
No related merge requests found
......@@ -26,33 +26,85 @@ local Textbox = require "engine.ui.Textbox"
module(..., package.seeall, class.inherit(Dialog))
function _M:init(errs)
self.errs = errs
self.errs = table.concat(errs, "\n")
Dialog.init(self, "Lua Error", 700, 500)
local md5 = require "md5"
local errmd5 = md5.sumhexa(errs)
self.errmd5 = errmd5
fs.mkdir("/error-reports")
local errdir = "/error-reports/"..game.__mod_info.short_name.."-"..game.__mod_info.version_name
self.errdir = errdir
fs.mkdir(errdir)
local infos = {}
local f, err = loadfile(errdir.."/"..errmd5)
if f then
setfenv(f, infos)
if pcall(f) then infos.loaded = true end
end
local reason = "If you already reported that error, you do not have to do it again (unless you feel the situation is different)."
if infos.loaded then
if infos.reported then reason = "You #LIGHT_GREEN#already reported#WHITE# that error, you do not have to do it again (unless you feel the situation is different)."
else reason = "You have already got this error but #LIGHT_RED#never reported#WHITE# it, please do."
end
else reason = "You have #LIGHT_RED#never seen#WHITE# that error, please report it."
end
self:saveError(true, infos.reported)
local errmsg = Textzone.new{text=[[#{bold}#Oh my! It seems there was an error!
The game might still work but this is suspect, please type in your current situation and click on "Send" to send an error report to the game creator.
If you are not currently connected to the internet, please report this bug when you can on the forums at http://forums.te4.org/
If you already reported that error, you do not have to do it again (unless you feel the situation is different).
#{normal}#]], width=690, auto_height=true}
local errzone = Textzone.new{text=table.concat(errs, "\n"), width=690, height=400}
]]..reason..[[#{normal}#]], width=690, auto_height=true}
local errzone = Textzone.new{text=errs, width=690, height=400}
self.what = Textbox.new{title="What happened?: ", text="", chars=60, max_len=1000, fct=function(text) self:send() end}
local ok = require("engine.ui.Button").new{text="Send", fct=function() self:send() end}
local cancel = require("engine.ui.Button").new{text="Close", fct=function() game:unregisterDialog(self) end}
local cancel_all = require("engine.ui.Button").new{text="Close All", fct=function()
for i = #self.dialogs, 1, -1 do
local d = self.dialogs[i]
if d.__CLASSNAME == "engine.dialogs.ShowErrorStack" then
game:unregisterDialog(d)
end
end
end}
local many_errs = false
for i = #self.dialogs, 1, -1 do local d = self.dialogs[i] if d.__CLASSNAME == "engine.dialogs.ShowErrorStack" then many_errs = true break end end
self:loadUI{
local uis = {
{left=0, top=0, padding_h=10, ui=errmsg},
{left=0, top=errmsg.h + 10, padding_h=10, ui=errzone},
{left=0, bottom=ok.h, ui=self.what},
{left=0, bottom=0, ui=ok},
{right=0, bottom=0, ui=cancel},
}
if many_errs then
table.insert(uis, #uis, {right=cancel.w, bottom=0, ui=cancel_all})
end
self:loadUI(uis)
self:setFocus(self.what)
self:setupUI(false, true)
self.key:addBinds{
EXIT = function() game:unregisterDialog(self) end,
}
end
function _M:saveError(seen, reported)
local f = fs.open(self.errdir.."/"..self.errmd5, "w")
f:write(("error = %q\n"):format(self.errs))
f:write(("seen = %s\n"):format(seen and "true" or "false"))
f:write(("reported = %s\n"):format(reported and "true" or "false"))
f:close()
end
function _M:send()
game:unregisterDialog(self)
profile:sendError(self.what.text, table.concat(self.errs, "\n"))
profile:sendError(self.what.text, self.errs)
game.log("#YELLOW#Error report sent, thank you.")
self:saveError(true, true)
end
No preview for this file type
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