1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-19 01:29:49 +00:00

Handle extension improvements (#715)

* Added crash protection

* removed an empty line

* Formatting

* more Formatting
This commit is contained in:
Variable 2022-07-20 17:22:43 +05:00 committed by GitHub
parent 69f25d398e
commit d7065ad6ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,7 @@ const EXTENSIONS_PATH := "user://extensions"
var extensions := {} # Extension name : Extension class
var extension_selected := -1
var damaged_extension: String
onready var extension_list: ItemList = $InstalledExtensions
onready var enable_button: Button = $HBoxContainer/EnableButton
@ -89,6 +90,29 @@ func _uninstall_extension(file_name := "", remove_file := true, item := extensio
func _add_extension(file_name: String) -> void:
var tester_file := File.new() # For testing and deleting damaged extensions
var remover_directory := Directory.new()
# Remove any extension that was proven guilty before this extension is loaded
if tester_file.file_exists(EXTENSIONS_PATH.plus_file("Faulty.txt")):
# This code will only run if pixelorama crashed
var faulty_path = EXTENSIONS_PATH.plus_file("Faulty.txt")
tester_file.open(faulty_path, File.READ)
damaged_extension = tester_file.get_as_text()
tester_file.close()
remover_directory.remove(EXTENSIONS_PATH.plus_file(damaged_extension))
remover_directory.remove(EXTENSIONS_PATH.plus_file("Faulty.txt"))
# Don't load a deleted extension
if damaged_extension == file_name:
# This code will only run if pixelorama crashed
damaged_extension = ""
return
# The new (about to load) extension will be considered guilty till it's proven innocent
tester_file.open(EXTENSIONS_PATH.plus_file("Faulty.txt"), File.WRITE)
tester_file.store_string(file_name) # Guilty till proven innocent ;)
tester_file.close()
if extensions.has(file_name):
var item := -1
for i in extension_list.get_item_count():
@ -139,6 +163,10 @@ func _add_extension(file_name: String) -> void:
if extension.enabled:
_enable_extension(extension)
# If an extension doesn't crash pixelorama then it is proven innocent
# And we should now delete it's "Faulty.txt" file
remover_directory.remove(EXTENSIONS_PATH.plus_file("Faulty.txt"))
func _enable_extension(extension: Extension, save_to_config := true) -> void:
var extension_path: String = "res://src/Extensions/%s/" % extension.file_name