mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-06 06:01:46 +00:00
Fixes crash when a corrupted savefile is detected
This commit is contained in:
@@ -115,7 +115,12 @@ module SaveData
|
|||||||
self.each_slot do |file_slot|
|
self.each_slot do |file_slot|
|
||||||
full_path = self.get_full_path(file_slot)
|
full_path = self.get_full_path(file_slot)
|
||||||
next if !File.file?(full_path)
|
next if !File.file?(full_path)
|
||||||
|
begin
|
||||||
temp_save_data = self.read_from_file(full_path)
|
temp_save_data = self.read_from_file(full_path)
|
||||||
|
rescue
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
save_time = temp_save_data[:player].last_time_saved || Time.at(1)
|
save_time = temp_save_data[:player].last_time_saved || Time.at(1)
|
||||||
if save_time > newest_time
|
if save_time > newest_time
|
||||||
newest_time = save_time
|
newest_time = save_time
|
||||||
@@ -266,8 +271,18 @@ class PokemonLoadScreen
|
|||||||
# @param file_path [String] file to load save data from
|
# @param file_path [String] file to load save data from
|
||||||
# @return [Hash] save data
|
# @return [Hash] save data
|
||||||
def load_save_file(file_path)
|
def load_save_file(file_path)
|
||||||
|
begin
|
||||||
save_data = SaveData.read_from_file(file_path)
|
save_data = SaveData.read_from_file(file_path)
|
||||||
|
rescue
|
||||||
|
save_data =try_load_backup(file_path)
|
||||||
|
end
|
||||||
unless SaveData.valid?(save_data)
|
unless SaveData.valid?(save_data)
|
||||||
|
save_data =try_load_backup(file_path)
|
||||||
|
end
|
||||||
|
return save_data
|
||||||
|
end
|
||||||
|
|
||||||
|
def try_load_backup(file_path)
|
||||||
if File.file?(file_path + ".bak")
|
if File.file?(file_path + ".bak")
|
||||||
pbMessage(_INTL("The save file is corrupt. A backup will be loaded."))
|
pbMessage(_INTL("The save file is corrupt. A backup will be loaded."))
|
||||||
save_data = load_save_file(file_path + ".bak")
|
save_data = load_save_file(file_path + ".bak")
|
||||||
@@ -275,7 +290,6 @@ class PokemonLoadScreen
|
|||||||
self.prompt_save_deletion(file_path)
|
self.prompt_save_deletion(file_path)
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
end
|
|
||||||
return save_data
|
return save_data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user