Compare commits

..

No commits in common. "aa3c1ecd30d397d533983a06c6672a91b1faab36" and "dfe788ef2055f03b93e29fa7ca4af00a0fca420f" have entirely different histories.

View file

@ -16,24 +16,28 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
extends Node extends Node
# Presencode version
const version: int = 1 const version: int = 1
const version_float: float = float(version) const version_float: float = float(version)
const temporary_file: String = "user://temporary_file"
# CORE
@onready var core: Core = get_node("/root/CORE") @onready var core: Core = get_node("/root/CORE")
@onready var logger: CoreLoggerInstance = core.logger.get_instance("src/presenloader.gd", self) @onready var logger: CoreLoggerInstance = core.logger.get_instance("src/presenloader.gd", self)
# Presentation zip/dir info
var path: String = "" var path: String = ""
var is_file: bool = true var is_file: bool = true
var manifest: Dictionary = {} var manifest: Dictionary = {}
var entrypoint: Script = null var entrypoint: Script = null
var entrypoint_node: PresencodeEntrypoint = null var entrypoint_node: PresencodeEntrypoint = null
var communication: PresencodeCommunication = PresencodeCommunication.new(core, self)
# Access methods
var reader: ZIPReader = ZIPReader.new() var reader: ZIPReader = ZIPReader.new()
var diraccess: DirAccess = null var diraccess: DirAccess = null
# Communication
var communication: PresencodeCommunication = PresencodeCommunication.new(core, self)
func _ready() -> void: func _ready() -> void:
# Register cleanup hook # Register cleanup hook
core.register_cleanup_hook(func() -> void: queue_free()) core.register_cleanup_hook(func() -> void: queue_free())
@ -210,9 +214,16 @@ func load_entrypoint() -> String:
if is_file: if is_file:
# Workaround (we can't load resources from buffer. why? idk) # Workaround (we can't load resources from buffer. why? idk)
# -> Remove temporary file (if exists) # -> Remove temporary file (if exists)
write_temporary_file(reader.read_file("src/" + manifest["entrypoint"])) if FileAccess.file_exists("user://entrypoint.gd"):
DirAccess.remove_absolute("user://entrypoint.gd")
# -> Write entrypoint file (buffer from ZIPReader) into temporary file
var file: FileAccess = FileAccess.open("user://entrypoint.gd", FileAccess.WRITE)
if file == null:
return core.misc.stringify_variables("Can't write temporary entrypoint: %error_string% (%error%)", { "error": FileAccess.get_open_error(), "error_string": error_string(FileAccess.get_open_error()) })
file.store_buffer(reader.read_file("src/" + manifest["entrypoint"]))
file.close()
# -> Load temporary file # -> Load temporary file
entrypoint = ResourceLoader.load(temporary_file) entrypoint = ResourceLoader.load("user://entrypoint.gd")
else: else:
# Load entrypoint # Load entrypoint
entrypoint = ResourceLoader.load(path + "/src/" + manifest["entrypoint"]) entrypoint = ResourceLoader.load(path + "/src/" + manifest["entrypoint"])
@ -237,20 +248,3 @@ func inject_entrypoint() -> void:
# Execute initialize() # Execute initialize()
await entrypoint_node.initialize() await entrypoint_node.initialize()
# +++ etc +++
func write_temporary_file(bytes: PackedByteArray) -> void:
# Check if exists, if so delete the file
if FileAccess.file_exists(temporary_file):
logger.diag("Removing temporary file")
# Open
var file: FileAccess = FileAccess.open(temporary_file, FileAccess.WRITE)
if file == null:
await logger.crash(core.misc.stringify_variables("Can't write temporary file: %error_string% (%error%)", { "error": FileAccess.get_open_error(), "error_string": error_string(FileAccess.get_open_error()) }))
# Write
file.store_buffer(bytes)
# Close
file.close()