mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-09 14:14:59 +00:00
Deprecated methods intended to work around filenames with accents, fixed crash when the Compiler wants to rewrite PBS files if they don't exist
This commit is contained in:
@@ -31,12 +31,9 @@ class Dir
|
||||
return files + subfolders
|
||||
end
|
||||
|
||||
# Checks for existing directory, gets around accents
|
||||
# Checks for existing directory
|
||||
def self.safe?(dir)
|
||||
return false if !FileTest.directory?(dir)
|
||||
ret = false
|
||||
self.chdir(dir) { ret = true } rescue nil
|
||||
return ret
|
||||
return FileTest.directory?(dir)
|
||||
end
|
||||
|
||||
# Creates all the required directories for filename path
|
||||
@@ -73,44 +70,20 @@ class Dir
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Extensions for file class
|
||||
#===============================================================================
|
||||
class File
|
||||
# Checks for existing file, gets around accents
|
||||
def self.safe?(file)
|
||||
ret = false
|
||||
self.open(file, "rb") { ret = true } rescue nil
|
||||
return ret
|
||||
end
|
||||
|
||||
# Checks for existing .rxdata file
|
||||
def self.safeData?(file)
|
||||
ret = (load_data(file) ? true : false) rescue false
|
||||
return ret
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Checking for files and directories
|
||||
#===============================================================================
|
||||
# Works around a problem with FileTest.directory if directory contains accent marks
|
||||
# @deprecated This method is slated to be removed in v22.
|
||||
def safeIsDirectory?(f)
|
||||
ret = false
|
||||
Dir.chdir(f) { ret = true } rescue nil
|
||||
return ret
|
||||
Deprecation.warn_method("safeIsDirectory?(f)", "v22", "FileTest.directory?(f)")
|
||||
return FileTest.directory?(f)
|
||||
end
|
||||
|
||||
# Works around a problem with FileTest.exist if path contains accent marks
|
||||
# @deprecated This method is slated to be removed in v22.
|
||||
def safeExists?(f)
|
||||
return FileTest.exist?(f) if f[/\A[\x20-\x7E]*\z/]
|
||||
ret = false
|
||||
begin
|
||||
File.open(f, "rb") { ret = true }
|
||||
rescue Errno::ENOENT, Errno::EINVAL, Errno::EACCES
|
||||
ret = false
|
||||
end
|
||||
return ret
|
||||
Deprecation.warn_method("safeExists?(f)", "v22", "FileTest.exist?(f)")
|
||||
return FileTest.exist?(f)
|
||||
end
|
||||
|
||||
# Similar to "Dir.glob", but designed to work around a problem with accessing
|
||||
@@ -211,9 +184,9 @@ module RTP
|
||||
def self.exists?(filename, extensions = [])
|
||||
return false if nil_or_empty?(filename)
|
||||
eachPathFor(filename) do |path|
|
||||
return true if safeExists?(path)
|
||||
return true if FileTest.exist?(path)
|
||||
extensions.each do |ext|
|
||||
return true if safeExists?(path + ext)
|
||||
return true if FileTest.exist?(path + ext)
|
||||
end
|
||||
end
|
||||
return false
|
||||
@@ -230,10 +203,10 @@ module RTP
|
||||
def self.getPath(filename, extensions = [])
|
||||
return filename if nil_or_empty?(filename)
|
||||
eachPathFor(filename) do |path|
|
||||
return path if safeExists?(path)
|
||||
return path if FileTest.exist?(path)
|
||||
extensions.each do |ext|
|
||||
file = path + ext
|
||||
return file if safeExists?(file)
|
||||
return file if FileTest.exist?(file)
|
||||
end
|
||||
end
|
||||
return filename
|
||||
@@ -307,9 +280,9 @@ end
|
||||
# NOTE: pbGetFileChar checks anything added in MKXP's RTP setting, and matching
|
||||
# mount points added through System.mount.
|
||||
def pbRgssExists?(filename)
|
||||
return !pbGetFileChar(filename).nil? if safeExists?("./Game.rgssad")
|
||||
return !pbGetFileChar(filename).nil? if FileTest.exist?("./Game.rgssad")
|
||||
filename = canonicalize(filename)
|
||||
return safeExists?(filename)
|
||||
return FileTest.exist?(filename)
|
||||
end
|
||||
|
||||
# Opens an IO, even if the file is in an encrypted archive.
|
||||
@@ -318,7 +291,7 @@ end
|
||||
# mount points added through System.mount.
|
||||
def pbRgssOpen(file, mode = nil)
|
||||
# File.open("debug.txt", "ab") { |fw| fw.write([file, mode, Time.now.to_f].inspect + "\r\n") }
|
||||
if !safeExists?("./Game.rgssad")
|
||||
if !FileTest.exist?("./Game.rgssad")
|
||||
if block_given?
|
||||
File.open(file, mode) { |f| yield f }
|
||||
return nil
|
||||
@@ -341,8 +314,8 @@ end
|
||||
# encrypted archives.
|
||||
def pbGetFileChar(file)
|
||||
canon_file = canonicalize(file)
|
||||
if !safeExists?("./Game.rgssad")
|
||||
return nil if !safeExists?(canon_file)
|
||||
if !FileTest.exist?("./Game.rgssad")
|
||||
return nil if !FileTest.exist?(canon_file)
|
||||
return nil if file.last == "/" # Is a directory
|
||||
begin
|
||||
File.open(canon_file, "rb") { |f| return f.read(1) } # read one byte
|
||||
@@ -370,8 +343,8 @@ end
|
||||
# mount points added through System.mount.
|
||||
def pbGetFileString(file)
|
||||
file = canonicalize(file)
|
||||
if !safeExists?("./Game.rgssad")
|
||||
return nil if !safeExists?(file)
|
||||
if !FileTest.exist?("./Game.rgssad")
|
||||
return nil if !FileTest.exist?(file)
|
||||
begin
|
||||
File.open(file, "rb") { |f| return f.read } # read all data
|
||||
rescue Errno::ENOENT, Errno::EINVAL, Errno::EACCES
|
||||
|
||||
@@ -32,7 +32,7 @@ module Translator
|
||||
end
|
||||
end
|
||||
# Get script texts from plugin script files
|
||||
if safeExists?("Data/PluginScripts.rxdata")
|
||||
if FileTest.exist?("Data/PluginScripts.rxdata")
|
||||
plugin_scripts = load_data("Data/PluginScripts.rxdata")
|
||||
plugin_scripts.each do |plugin|
|
||||
plugin[2].each do |script|
|
||||
@@ -511,12 +511,12 @@ class Translation
|
||||
def load_message_files(filename)
|
||||
begin
|
||||
core_filename = sprintf("Data/messages_%s_core.dat", filename)
|
||||
if safeExists?(core_filename)
|
||||
if FileTest.exist?(core_filename)
|
||||
pbRgssOpen(core_filename, "rb") { |f| @core_messages = Marshal.load(f) }
|
||||
end
|
||||
@core_messages = nil if !@core_messages.is_a?(Array)
|
||||
game_filename = sprintf("Data/messages_%s_game.dat", filename)
|
||||
if safeExists?(game_filename)
|
||||
if FileTest.exist?(game_filename)
|
||||
pbRgssOpen(game_filename, "rb") { |f| @game_messages = Marshal.load(f) }
|
||||
end
|
||||
@game_messages = nil if !@game_messages.is_a?(Array)
|
||||
@@ -529,11 +529,11 @@ class Translation
|
||||
def load_default_messages
|
||||
return if @default_core_messages
|
||||
begin
|
||||
if safeExists?("Data/messages_core.dat")
|
||||
if FileTest.exist?("Data/messages_core.dat")
|
||||
pbRgssOpen("Data/messages_core.dat", "rb") { |f| @default_core_messages = Marshal.load(f) }
|
||||
end
|
||||
@default_core_messages = [] if !@default_core_messages.is_a?(Array)
|
||||
if safeExists?("Data/messages_game.dat")
|
||||
if FileTest.exist?("Data/messages_game.dat")
|
||||
pbRgssOpen("Data/messages_game.dat", "rb") { |f| @default_game_messages = Marshal.load(f) }
|
||||
end
|
||||
@default_game_messages = [] if !@default_game_messages.is_a?(Array)
|
||||
|
||||
@@ -471,7 +471,7 @@ module PluginManager
|
||||
|
||||
# Get a list of all the plugin directories to inspect
|
||||
def self.listAll
|
||||
return [] if !$DEBUG || safeExists?("Game.rgssad") || !Dir.safe?("Plugins")
|
||||
return [] if !$DEBUG || FileTest.exist?("Game.rgssad") || !Dir.safe?("Plugins")
|
||||
# get a list of all directories in the `Plugins/` folder
|
||||
dirs = []
|
||||
Dir.get("Plugins").each { |d| dirs.push(d) if Dir.safe?(d) }
|
||||
@@ -534,7 +534,7 @@ module PluginManager
|
||||
# plugins.
|
||||
self.listAll.each do |dir|
|
||||
# skip if there is no meta file
|
||||
next if !safeExists?(dir + "/meta.txt")
|
||||
next if !FileTest.exist?(dir + "/meta.txt")
|
||||
ndx = order.length
|
||||
meta = self.readMeta(dir, "meta.txt")
|
||||
meta[:dir] = dir
|
||||
@@ -556,8 +556,8 @@ module PluginManager
|
||||
# Check if plugins need compiling
|
||||
def self.needCompiling?(order, plugins)
|
||||
# fixed actions
|
||||
return false if !$DEBUG || safeExists?("Game.rgssad")
|
||||
return true if !safeExists?("Data/PluginScripts.rxdata")
|
||||
return false if !$DEBUG || FileTest.exist?("Game.rgssad")
|
||||
return true if !FileTest.exist?("Data/PluginScripts.rxdata")
|
||||
Input.update
|
||||
return true if Input.press?(Input::SHIFT) || Input.press?(Input::CTRL)
|
||||
# analyze whether or not to push recompile
|
||||
@@ -655,7 +655,7 @@ module PluginManager
|
||||
# go through the plugins folder
|
||||
Dir.get("Plugins").each do |dir|
|
||||
next if !Dir.safe?(dir)
|
||||
next if !safeExists?(dir + "/meta.txt")
|
||||
next if !FileTest.exist?(dir + "/meta.txt")
|
||||
# read meta
|
||||
meta = self.readMeta(dir, "meta.txt")
|
||||
return dir if meta[:name] == name
|
||||
|
||||
@@ -83,20 +83,20 @@ end
|
||||
|
||||
# Gets the length of an audio file in seconds. Supports WAV, MP3, and OGG files.
|
||||
def getPlayTime(filename)
|
||||
if safeExists?(filename)
|
||||
if FileTest.exist?(filename)
|
||||
return [getPlayTime2(filename), 0].max
|
||||
elsif safeExists?(filename + ".wav")
|
||||
elsif FileTest.exist?(filename + ".wav")
|
||||
return [getPlayTime2(filename + ".wav"), 0].max
|
||||
elsif safeExists?(filename + ".mp3")
|
||||
elsif FileTest.exist?(filename + ".mp3")
|
||||
return [getPlayTime2(filename + ".mp3"), 0].max
|
||||
elsif safeExists?(filename + ".ogg")
|
||||
elsif FileTest.exist?(filename + ".ogg")
|
||||
return [getPlayTime2(filename + ".ogg"), 0].max
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
def getPlayTime2(filename)
|
||||
return -1 if !safeExists?(filename)
|
||||
return -1 if !FileTest.exist?(filename)
|
||||
time = -1
|
||||
fgetdw = proc { |file|
|
||||
(file.eof? ? 0 : (file.read(4).unpack("V")[0] || 0))
|
||||
|
||||
@@ -26,7 +26,7 @@ module GameData
|
||||
|
||||
singleton_class.alias_method(:__orig__load, :load) unless singleton_class.method_defined?(:__orig__load)
|
||||
def self.load
|
||||
__orig__load if safeExists?("Data/#{self::DATA_FILENAME}")
|
||||
__orig__load if FileTest.exist?("Data/#{self::DATA_FILENAME}")
|
||||
end
|
||||
|
||||
# @param species [Symbol, self, String]
|
||||
|
||||
@@ -59,7 +59,7 @@ def pbEditMysteryGift(type, item, id = 0, giftname = "")
|
||||
if id == 0
|
||||
master = []
|
||||
idlist = []
|
||||
if safeExists?("MysteryGiftMaster.txt")
|
||||
if FileTest.exist?("MysteryGiftMaster.txt")
|
||||
master = IO.read("MysteryGiftMaster.txt")
|
||||
master = pbMysteryGiftDecrypt(master)
|
||||
end
|
||||
@@ -101,7 +101,7 @@ def pbCreateMysteryGift(type, item)
|
||||
gift = pbEditMysteryGift(type, item)
|
||||
if gift
|
||||
begin
|
||||
if safeExists?("MysteryGiftMaster.txt")
|
||||
if FileTest.exist?("MysteryGiftMaster.txt")
|
||||
master = IO.read("MysteryGiftMaster.txt")
|
||||
master = pbMysteryGiftDecrypt(master)
|
||||
master.push(gift)
|
||||
@@ -124,7 +124,7 @@ end
|
||||
# file to be uploaded.
|
||||
#===============================================================================
|
||||
def pbManageMysteryGifts
|
||||
if !safeExists?("MysteryGiftMaster.txt")
|
||||
if !FileTest.exist?("MysteryGiftMaster.txt")
|
||||
pbMessage(_INTL("There are no Mystery Gifts defined."))
|
||||
return
|
||||
end
|
||||
|
||||
@@ -14,10 +14,10 @@ def pbGetLegalMoves(species)
|
||||
end
|
||||
|
||||
def pbSafeCopyFile(x, y, z = nil)
|
||||
if safeExists?(x)
|
||||
if FileTest.exist?(x)
|
||||
safetocopy = true
|
||||
filedata = nil
|
||||
if safeExists?(y)
|
||||
if FileTest.exist?(y)
|
||||
different = false
|
||||
if FileTest.size(x) == FileTest.size(y)
|
||||
filedata2 = ""
|
||||
|
||||
@@ -596,10 +596,10 @@ end
|
||||
|
||||
def pbImportAllAnimations
|
||||
animationFolders = []
|
||||
if safeIsDirectory?("Animations")
|
||||
if FileTest.directory?("Animations")
|
||||
Dir.foreach("Animations") do |fb|
|
||||
f = "Animations/" + fb
|
||||
animationFolders.push(f) if safeIsDirectory?(f) && fb != "." && fb != ".."
|
||||
animationFolders.push(f) if FileTest.directory?(f) && fb != "." && fb != ".."
|
||||
end
|
||||
end
|
||||
if animationFolders.length == 0
|
||||
@@ -639,14 +639,14 @@ def pbImportAllAnimations
|
||||
textdata.id = -1 # This is not an RPG Maker XP animation
|
||||
BattleAnimationEditor.pbConvertAnimToNewFormat(textdata)
|
||||
if textdata.graphic && textdata.graphic != "" &&
|
||||
!safeExists?(folder + "/" + textdata.graphic) &&
|
||||
!FileTest.exist?(folder + "/" + textdata.graphic) &&
|
||||
!FileTest.image_exist?("Graphics/Animations/" + textdata.graphic)
|
||||
textdata.graphic = ""
|
||||
missingFiles.push(textdata.graphic)
|
||||
end
|
||||
textdata.timing.each do |timing|
|
||||
next if !timing.name || timing.name == "" ||
|
||||
safeExists?(folder + "/" + timing.name) ||
|
||||
FileTest.exist?(folder + "/" + timing.name) ||
|
||||
FileTest.audio_exist?("Audio/SE/Anim/" + timing.name)
|
||||
timing.name = ""
|
||||
missingFiles.push(timing.name)
|
||||
|
||||
@@ -1018,7 +1018,7 @@ module Compiler
|
||||
Console.echo_li(_INTL("Saving messages..."))
|
||||
Translator.gather_script_and_event_texts
|
||||
MessageTypes.save_default_messages
|
||||
MessageTypes.load_default_messages if safeExists?("Data/messages_core.dat")
|
||||
MessageTypes.load_default_messages if FileTest.exist?("Data/messages_core.dat")
|
||||
Console.echo_done(true)
|
||||
Console.echoln_li_done(_INTL("Successfully compiled all game data"))
|
||||
end
|
||||
@@ -1026,6 +1026,14 @@ module Compiler
|
||||
def main
|
||||
return if !$DEBUG
|
||||
begin
|
||||
mustCompile = false
|
||||
# If no PBS file, create one and fill it, then recompile
|
||||
if !FileTest.directory?("PBS")
|
||||
Dir.mkdir("PBS") rescue nil
|
||||
GameData.load_all
|
||||
write_all
|
||||
mustCompile = true
|
||||
end
|
||||
# Get all data files and PBS files to be checked for their last modified times
|
||||
data_files = GameData.get_all_data_filenames
|
||||
data_files += [ # Extra .dat files for data that isn't a GameData class
|
||||
@@ -1036,19 +1044,11 @@ module Compiler
|
||||
text_files = get_all_pbs_files_to_compile
|
||||
latestDataTime = 0
|
||||
latestTextTime = 0
|
||||
mustCompile = false
|
||||
# Should recompile if new maps were imported
|
||||
mustCompile |= import_new_maps
|
||||
# If no PBS file, create one and fill it, then recompile
|
||||
if !safeIsDirectory?("PBS")
|
||||
Dir.mkdir("PBS") rescue nil
|
||||
GameData.load_all
|
||||
write_all
|
||||
mustCompile = true
|
||||
end
|
||||
# Check data files for their latest modify time
|
||||
data_files.each do |filename| # filename = [string, boolean (whether mandatory)]
|
||||
if safeExists?("Data/" + filename[0])
|
||||
if FileTest.exist?("Data/" + filename[0])
|
||||
begin
|
||||
File.open("Data/#{filename[0]}") do |file|
|
||||
latestDataTime = [latestDataTime, file.mtime.to_i].max
|
||||
@@ -1080,7 +1080,7 @@ module Compiler
|
||||
if mustCompile
|
||||
data_files.each do |filename|
|
||||
begin
|
||||
File.delete("Data/#{filename[0]}") if safeExists?("Data/#{filename[0]}")
|
||||
File.delete("Data/#{filename[0]}") if FileTest.exist?("Data/#{filename[0]}")
|
||||
rescue SystemCallError
|
||||
end
|
||||
end
|
||||
@@ -1093,7 +1093,7 @@ module Compiler
|
||||
pbPrintException(e)
|
||||
data_files.each do |filename|
|
||||
begin
|
||||
File.delete("Data/#{filename[0]}") if safeExists?("Data/#{filename[0]}")
|
||||
File.delete("Data/#{filename[0]}") if FileTest.exist?("Data/#{filename[0]}")
|
||||
rescue SystemCallError
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ module Compiler
|
||||
|
||||
def compile_PBS_file_generic(game_data, *paths)
|
||||
if game_data.const_defined?(:OPTIONAL) && game_data::OPTIONAL
|
||||
return if paths.none? { |p| safeExists?(p) }
|
||||
return if paths.none? { |p| FileTest.exist?(p) }
|
||||
end
|
||||
game_data::DATA.clear
|
||||
schema = game_data.schema
|
||||
@@ -947,7 +947,7 @@ module Compiler
|
||||
"Pokemon" => [1, "s"],
|
||||
"Challenges" => [2, "*s"]
|
||||
}
|
||||
if !safeExists?(path)
|
||||
if !FileTest.exist?(path)
|
||||
File.open(path, "wb") do |f|
|
||||
f.write(0xEF.chr)
|
||||
f.write(0xBB.chr)
|
||||
@@ -987,12 +987,12 @@ module Compiler
|
||||
rsection[3] = rsection[0]
|
||||
rsection[4] = rsection[1]
|
||||
rsection[5] = (name == "DefaultTrainerList")
|
||||
if safeExists?("PBS/" + rsection[0])
|
||||
if FileTest.exist?("PBS/" + rsection[0])
|
||||
rsection[0] = compile_battle_tower_trainers("PBS/" + rsection[0])
|
||||
else
|
||||
rsection[0] = []
|
||||
end
|
||||
if safeExists?("PBS/" + rsection[1])
|
||||
if FileTest.exist?("PBS/" + rsection[1])
|
||||
filename = "PBS/" + rsection[1]
|
||||
rsection[1] = []
|
||||
pbCompilerEachCommentedLine(filename) do |line, _lineno|
|
||||
@@ -1027,7 +1027,7 @@ module Compiler
|
||||
beginspeech = []
|
||||
endspeechwin = []
|
||||
endspeechlose = []
|
||||
if safeExists?(filename)
|
||||
if FileTest.exist?(filename)
|
||||
File.open(filename, "rb") do |f|
|
||||
FileLineData.file = filename
|
||||
pbEachFileSection(f) do |section, name|
|
||||
|
||||
@@ -24,7 +24,7 @@ end
|
||||
|
||||
def mainFunctionDebug
|
||||
begin
|
||||
MessageTypes.load_default_messages if safeExists?("Data/messages_core.dat")
|
||||
MessageTypes.load_default_messages if FileTest.exist?("Data/messages_core.dat")
|
||||
PluginManager.runPlugins
|
||||
Compiler.main
|
||||
Game.initialize
|
||||
|
||||
Reference in New Issue
Block a user