mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-06 06:01:46 +00:00
More code changes for Plugin Manager
This commit is contained in:
@@ -33,7 +33,7 @@ def pbPrintException(e)
|
||||
end
|
||||
btrace.gsub!(/Section(\d+)/) { $RGSS_SCRIPTS[$1.to_i][1] } rescue nil
|
||||
message = "[Pokémon Essentials version #{Essentials::VERSION}]\r\n"
|
||||
message += "#{Essentials::ERROR_TEXT}" # For third party scripts to add to
|
||||
message += "#{Essentials::ERROR_TEXT}\r\n" # For third party scripts to add to
|
||||
message += "Exception: #{e.class}\r\n"
|
||||
message += "Message: #{emessage}\r\n"
|
||||
message += "\r\nBacktrace:\r\n#{btrace}"
|
||||
@@ -42,11 +42,10 @@ def pbPrintException(e)
|
||||
errorlog = RTP.getSaveFileName("errorlog.txt")
|
||||
end
|
||||
File.open(errorlog,"ab") { |f| f.write(premessage); f.write(message) }
|
||||
errorlogline = errorlog
|
||||
errorlogline.sub!(Dir.pwd + "/", "")
|
||||
errorlogline = errorlog.gsub!("/", "\\")
|
||||
errorlogline.sub!(Dir.pwd + "\\", "")
|
||||
errorlogline.sub!(pbGetUserName, "USERNAME")
|
||||
errorlogline = "\r\n" + errorlogline if errorlogline.length > 20
|
||||
errorlogline.gsub!("/", "\\") if System.platform[/Windows/]
|
||||
print("#{message}\r\nThis exception was logged in #{errorlogline}.\r\nHold Ctrl after closing this message to copy it to the clipboard.")
|
||||
# Give a ~500ms coyote time to start holding Control
|
||||
t = System.delta
|
||||
|
||||
@@ -21,12 +21,17 @@ class Dir
|
||||
def self.all(dir, filters = "*", full = true)
|
||||
# sets variables for starting
|
||||
files = []
|
||||
subfolders = []
|
||||
for file in self.get(dir, filters, full)
|
||||
# engages in recursion to read the entire file tree
|
||||
files += self.safe?(file) ? self.get(file, filters, full) : [file]
|
||||
if self.safe?(file) # Is a directory
|
||||
subfolders += self.all(file, filters, full)
|
||||
else # Is a file
|
||||
files += [file]
|
||||
end
|
||||
end
|
||||
# returns all found files
|
||||
return files
|
||||
return files + subfolders
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Checks for existing directory, gets around accents
|
||||
|
||||
@@ -428,6 +428,45 @@ module PluginManager
|
||||
return 0
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# formats the error message
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.pluginErrorMsg(name, script)
|
||||
# begin message formatting
|
||||
msg = "[Pokémon Essentials version #{Essentials::VERSION}]\r\n"
|
||||
msg += "#{Essentials::ERROR_TEXT}\r\n" # For third party scripts to add to
|
||||
msg += "Error in Plugin [#{name}]:\r\n"
|
||||
msg += "#{$!.class} occurred.\r\n"
|
||||
# go through message content
|
||||
for line in $!.message.split("\r\n")
|
||||
next if !line || line == ""
|
||||
n = line[/\d+/]
|
||||
err = line.split(":")[-1].strip
|
||||
lms = line.split(":")[0].strip
|
||||
err.gsub!(n, "") if n
|
||||
err = err.capitalize if err.is_a?(String) && !err.empty?
|
||||
linum = n ? "Line #{n}: " : ""
|
||||
msg += "#{linum}#{err}: #{lms}\r\n"
|
||||
end
|
||||
# show trace
|
||||
msg += "\r\nFull trace can be found below:\r\n"
|
||||
for bck in $!.backtrace
|
||||
msg += "#{bck}\r\n"
|
||||
end
|
||||
# output to log
|
||||
errorlog = "errorlog.txt"
|
||||
if (Object.const_defined?(:RTP) rescue false)
|
||||
errorlog = RTP.getSaveFileName("errorlog.txt")
|
||||
end
|
||||
premessage = "\r\n=================\r\n\r\n[#{Time.now}]\r\n"
|
||||
File.open(errorlog, "ab") { |f| f.write(premessage); f.write(msg) }
|
||||
errorlogline = errorlog.gsub!("/", "\\")
|
||||
errorlogline.sub!(Dir.pwd + "\\", "")
|
||||
errorlogline.sub!(pbGetUserName, "USERNAME")
|
||||
errorlogline = "\r\n" + errorlogline if errorlogline.length > 20
|
||||
# output message
|
||||
return "#{msg}\r\nThis exception was logged in #{errorlogline}.\r\nHold Ctrl after closing this message to copy it to the clipboard."
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
# Used to read the metadata file
|
||||
#-----------------------------------------------------------------------------
|
||||
def self.readMeta(dir, file)
|
||||
@@ -481,7 +520,7 @@ module PluginManager
|
||||
meta[:scripts] = [] if !meta[:scripts]
|
||||
# get all script files from plugin Dir
|
||||
for fl in Dir.all(dir)
|
||||
next if !File.extname(fl).include?(".rb")
|
||||
next if !fl.include?(".rb")
|
||||
meta[:scripts].push(fl.gsub("#{dir}/", ""))
|
||||
end
|
||||
# ensure no duplicate script files are queued
|
||||
@@ -606,7 +645,9 @@ module PluginManager
|
||||
dat = [o, meta, []]
|
||||
# iterate through each file to deflate
|
||||
for file in plugins[o][:scripts]
|
||||
File.open("#{plugins[o][:dir]}/#{file}", 'rb') { |f| dat[2].push(Zlib::Deflate.deflate(f.read)) }
|
||||
File.open("#{plugins[o][:dir]}/#{file}", 'rb') do |f|
|
||||
dat[2].push([file, Zlib::Deflate.deflate(f.read)])
|
||||
end
|
||||
end
|
||||
# push to the main scripts array
|
||||
scripts.push(dat)
|
||||
@@ -624,7 +665,6 @@ module PluginManager
|
||||
order, plugins = self.getPluginOrder
|
||||
# compile if necessary
|
||||
self.compilePlugins(order, plugins) if self.needCompiling?(order, plugins)
|
||||
# run the plugins from compiled archive
|
||||
# load plugins
|
||||
scripts = load_data("Data/PluginScripts.rxdata")
|
||||
for plugin in scripts
|
||||
@@ -635,38 +675,37 @@ module PluginManager
|
||||
# go through each script and interpret
|
||||
for scr in script
|
||||
# turn code into plaintext
|
||||
code = Zlib::Inflate.inflate(scr)
|
||||
code = Zlib::Inflate.inflate(scr[1])
|
||||
# get rid of tabs
|
||||
code.gsub!("\t", " ")
|
||||
# construct filename
|
||||
fname = "[Plugin] " + name
|
||||
sname = scr[0].gsub("\\","/").split("/")[-1]
|
||||
fname = "[#{name}] #{sname}"
|
||||
# try to run the code
|
||||
begin
|
||||
eval(code, TOPLEVEL_BINDING, fname)
|
||||
rescue Exception # format error message to display
|
||||
msg = "[Pokémon Essentials v#{Essentials::VERSION}] #{Essentials::ERROR_TEXT}\r\n\r\n"
|
||||
msg += "#{$raise_msg}\r\n-------------------------------\r\n" if $raise_msg
|
||||
msg += "Error in Plugin [#{name}]:\r\n"
|
||||
msg += "#{$!.class} occurred.\r\n"
|
||||
for line in $!.message.split("\r\n")
|
||||
next if !line || line == ""
|
||||
n = line[/\d+/]
|
||||
err = line.split(":")[-1].strip
|
||||
lms = line.split(":")[0].strip
|
||||
err.gsub!(n, "") if n
|
||||
err = err.capitalize if err.is_a?(String) && !err.empty?
|
||||
linum = n ? "Line #{n}: " : ""
|
||||
msg += "#{linum}#{err}: #{lms}\r\n"
|
||||
Graphics.update
|
||||
t = Thread.new do
|
||||
print(self.pluginErrorMsg(name, sname))
|
||||
# Give a ~500ms coyote time to start holding Control
|
||||
tm = System.delta
|
||||
until (System.delta - tm) >= 500000
|
||||
Input.update
|
||||
if Input.press?(Input::CTRL)
|
||||
Input.clipboard = message
|
||||
break
|
||||
end
|
||||
msg += "\r\nFull trace can be found below:\r\n"
|
||||
for bck in $!.backtrace
|
||||
msg += "#{bck}\r\n"
|
||||
end
|
||||
msg += "\r\nEnd of Error."
|
||||
$raise_msg = nil
|
||||
raise msg
|
||||
Thread.exit
|
||||
end
|
||||
while t.status
|
||||
Graphics.update
|
||||
end
|
||||
Kernel.exit! true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
#-----------------------------------------------------------------------------
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user