From e65186adce90c51b5c78f8e1502fbaf6a8f37c82 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Tue, 16 Jan 2024 21:41:55 +0100 Subject: [PATCH] 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 --- src/loader.gd | 93 +++++++++++++++++---------------------------------- 1 file changed, 31 insertions(+), 62 deletions(-) diff --git a/src/loader.gd b/src/loader.gd index 82375c8..ab13476 100644 --- a/src/loader.gd +++ b/src/loader.gd @@ -33,11 +33,11 @@ var config_skipwarning: bool = true ### I don't know why I put this here lol var config_slow_init: bool = false +# Nodes var logrtl: RichTextLabel = null +var console: Control = null func _ready() -> void: - logger.info("Updating configuration") - update_configuration() logger.info("Updating loader scene") # Rename loader scene name = "Presencode" @@ -103,35 +103,21 @@ Licensed under the GNU General Public License version 3 misc.check_platform() # Create temporary directory 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") - var console: Control = ResourceLoader.load("res://Console.tscn").instantiate() + console = ResourceLoader.load("res://Console.tscn").instantiate() get_tree().root.add_child.call_deferred(console) 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 var path: String = " ".join(OS.get_cmdline_user_args()) if OS.get_cmdline_user_args().size() == 0: 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 logger.info("Opening presentation archive") 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: logrtl.text = $Log.text + log_str + "\n" -# Update all config_ variables -func update_configuration() -> void: - match(OS.get_environment("CONFIG_LOADER_SKIPWARNING")): - "true": config_skipwarning = true - "false": config_skipwarning = false - _: pass - match(OS.get_environment("CONFIG_LOADER_WINDOW_SIZE_SUPPORT")): - "true": config_window_size_support = true - "false": config_window_size_support = false - _: - logger.diag("CONFIG_LOADER_WINDOW_SIZE_SUPPORT=\"" + OS.get_environment("CONFIG_LOADER_WINDOW_SIZE_SUPPORT") + "\"") - pass - match(OS.get_environment("CONFIG_LOADER_SLOW_INIT")): - "true": config_slow_init = true - "false": config_slow_init = false - _: pass - match(OS.get_environment("CONFIG_LOGGER_ENABLED")): - "true": logger.config_enabled = true - "false": logger.config_enabled = false - _: pass - match(OS.get_environment("CONFIG_LOGGER_DIAGNOSTIC")): - "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 +func print_warning() -> void: + 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