Move loader initialization

- [src/loader.gd] Make console a member variable
- [src/loader.gd] Move warning into new function print_warning()
- [src/loader.gd] Move presentation loading process into new function load_presentation()
- [src/loader.gd] Remove ability to modify configuration options using environment variables
This commit is contained in:
JeremyStar™ 2024-01-16 21:41:55 +01:00
parent a3ba0bf759
commit e65186adce

View file

@ -33,11 +33,11 @@ var config_skipwarning: bool = true
### I don't know why I put this here lol ### I don't know why I put this here lol
var config_slow_init: bool = false var config_slow_init: bool = false
# Nodes
var logrtl: RichTextLabel = null var logrtl: RichTextLabel = null
var console: Control = null
func _ready() -> void: func _ready() -> void:
logger.info("Updating configuration")
update_configuration()
logger.info("Updating loader scene") logger.info("Updating loader scene")
# Rename loader scene # Rename loader scene
name = "Presencode" name = "Presencode"
@ -103,35 +103,21 @@ Licensed under the GNU General Public License version 3
misc.check_platform() misc.check_platform()
# Create temporary directory # Create temporary directory
DirAccess.make_dir_recursive_absolute(misc.get_temporary_dir()) DirAccess.make_dir_recursive_absolute(misc.get_temporary_dir())
# Print warning
if !config_skipwarning and OS.is_debug_build():
logger.warn("""Displaying warning
###################################################
##### !!! WARNING !!! WARNING !!! WARNING !!! #####
###################################################
Presentations made with Presencode perform
malicious actions such as collect your passwords,
encrypt your files, display you unwanted ads,
install other malware, etc..
ONLY VIEW PRESENCODE PRESENTATIONS IF YOU TRUST THE
AUTHOR AND HAVE VERIFIED THE PRESENTATION SCRIPT!
YOU HAVE 5 SECONDS TO EXIT PRESENCODE
YOU HAVE BEEN WARNED.
###################################################
##### !!! WARNING !!! WARNING !!! WARNING !!! #####
###################################################
""")
await get_tree().create_timer(5).timeout
logger.info("Injecting console") logger.info("Injecting console")
var console: Control = ResourceLoader.load("res://Console.tscn").instantiate() console = ResourceLoader.load("res://Console.tscn").instantiate()
get_tree().root.add_child.call_deferred(console) get_tree().root.add_child.call_deferred(console)
if config_slow_init: await get_tree().create_timer(randf_range(0.1, 0.15)).timeout if config_slow_init: await get_tree().create_timer(randf_range(0.1, 0.15)).timeout
# Check for presentation path in commandline arguments
# Open presentation archive/directory # Open presentation archive/directory
var path: String = " ".join(OS.get_cmdline_user_args()) var path: String = " ".join(OS.get_cmdline_user_args())
if OS.get_cmdline_user_args().size() == 0: if OS.get_cmdline_user_args().size() == 0:
await logger.error("No presentation was passed to Presencode") await logger.error("No presentation was passed to Presencode")
else:
await print_warning()
await load_presentation(path)
# Load a presentation from commandline arguments
func load_presentation(path: String) -> void:
if FileAccess.file_exists(path) and path.ends_with(".zip") or path.ends_with(".pcpa"): # .pcpa = presencode presentation archive if FileAccess.file_exists(path) and path.ends_with(".zip") or path.ends_with(".pcpa"): # .pcpa = presencode presentation archive
logger.info("Opening presentation archive") logger.info("Opening presentation archive")
preader.open_presentation(path, true) preader.open_presentation(path, true)
@ -176,41 +162,24 @@ func _process(_delta: float) -> void:
func append_log(_type: logger.Types, _message: String, log_str: String) -> void: func append_log(_type: logger.Types, _message: String, log_str: String) -> void:
logrtl.text = $Log.text + log_str + "\n" logrtl.text = $Log.text + log_str + "\n"
# Update all config_ variables func print_warning() -> void:
func update_configuration() -> void: if !config_skipwarning and OS.is_debug_build():
match(OS.get_environment("CONFIG_LOADER_SKIPWARNING")): logger.warn("""Displaying warning
"true": config_skipwarning = true ###################################################
"false": config_skipwarning = false ##### !!! WARNING !!! WARNING !!! WARNING !!! #####
_: pass ###################################################
match(OS.get_environment("CONFIG_LOADER_WINDOW_SIZE_SUPPORT")): Presentations made with Presencode perform
"true": config_window_size_support = true malicious actions such as collect your passwords,
"false": config_window_size_support = false encrypt your files, display you unwanted ads,
_: install other malware, etc..
logger.diag("CONFIG_LOADER_WINDOW_SIZE_SUPPORT=\"" + OS.get_environment("CONFIG_LOADER_WINDOW_SIZE_SUPPORT") + "\"")
pass ONLY VIEW PRESENCODE PRESENTATIONS IF YOU TRUST THE
match(OS.get_environment("CONFIG_LOADER_SLOW_INIT")): AUTHOR AND HAVE VERIFIED THE PRESENTATION SCRIPT!
"true": config_slow_init = true YOU HAVE 5 SECONDS TO EXIT PRESENCODE
"false": config_slow_init = false
_: pass YOU HAVE BEEN WARNED.
match(OS.get_environment("CONFIG_LOGGER_ENABLED")): ###################################################
"true": logger.config_enabled = true ##### !!! WARNING !!! WARNING !!! WARNING !!! #####
"false": logger.config_enabled = false ###################################################
_: pass """)
match(OS.get_environment("CONFIG_LOGGER_DIAGNOSTIC")): await get_tree().create_timer(5).timeout
"true": logger.config_diagnostic = true
"false": logger.config_diagnostic = false
_: pass
match(OS.get_environment("CONFIG_LOGGER_COLORED")):
"true": logger.config_colored = true
"false": logger.config_colored = false
_: pass
match(OS.get_environment("CONFIG_LOGGER_HARDFAIL")):
"true": logger.config_hardfail = true
"false": logger.config_hardfail = false
_: pass
if OS.get_environment("CONFIG_LOGGER_LOGSTRING") != "":
logger.config_logstring = OS.get_environment("CONFIG_LOGGER_LOGSTRING")
match(OS.get_environment("CONFIG_MISC_SHUTDOWN_INVISIBLE")):
"true": misc.config_shutdown_invisible = true
"false": misc.config_shutdown_invisible = false
_: pass