Compare commits
2 commits
dfe788ef20
...
aa3c1ecd30
Author | SHA1 | Date | |
---|---|---|---|
aa3c1ecd30 | |||
06b83a0589 |
1 changed files with 22 additions and 16 deletions
|
@ -16,28 +16,24 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
extends Node
|
||||
|
||||
# Presencode version
|
||||
const version: int = 1
|
||||
const version_float: float = float(version)
|
||||
const temporary_file: String = "user://temporary_file"
|
||||
|
||||
# CORE
|
||||
@onready var core: Core = get_node("/root/CORE")
|
||||
@onready var logger: CoreLoggerInstance = core.logger.get_instance("src/presenloader.gd", self)
|
||||
|
||||
# Presentation zip/dir info
|
||||
var path: String = ""
|
||||
var is_file: bool = true
|
||||
var manifest: Dictionary = {}
|
||||
|
||||
var entrypoint: Script = null
|
||||
var entrypoint_node: PresencodeEntrypoint = null
|
||||
var communication: PresencodeCommunication = PresencodeCommunication.new(core, self)
|
||||
|
||||
# Access methods
|
||||
var reader: ZIPReader = ZIPReader.new()
|
||||
var diraccess: DirAccess = null
|
||||
|
||||
# Communication
|
||||
var communication: PresencodeCommunication = PresencodeCommunication.new(core, self)
|
||||
|
||||
func _ready() -> void:
|
||||
# Register cleanup hook
|
||||
core.register_cleanup_hook(func() -> void: queue_free())
|
||||
|
@ -214,16 +210,9 @@ func load_entrypoint() -> String:
|
|||
if is_file:
|
||||
# Workaround (we can't load resources from buffer. why? idk)
|
||||
# -> Remove temporary file (if exists)
|
||||
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()
|
||||
write_temporary_file(reader.read_file("src/" + manifest["entrypoint"]))
|
||||
# -> Load temporary file
|
||||
entrypoint = ResourceLoader.load("user://entrypoint.gd")
|
||||
entrypoint = ResourceLoader.load(temporary_file)
|
||||
else:
|
||||
# Load entrypoint
|
||||
entrypoint = ResourceLoader.load(path + "/src/" + manifest["entrypoint"])
|
||||
|
@ -248,3 +237,20 @@ func inject_entrypoint() -> void:
|
|||
|
||||
# Execute 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()
|
||||
|
|
Loading…
Reference in a new issue