From 93ac01840040341f639df22aa0e5485819685f1f Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sat, 1 Jan 2022 15:46:08 +0100 Subject: [PATCH] SNIClient: make SNI finder a bit smarter --- SNIClient.py | 11 +++++++---- WebHostLib/options.py | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/SNIClient.py b/SNIClient.py index f6509938..6215ffad 100644 --- a/SNIClient.py +++ b/SNIClient.py @@ -523,10 +523,13 @@ def launch_sni(ctx: Context): if not os.path.isdir(sni_path): sni_path = Utils.local_path(sni_path) if os.path.isdir(sni_path): - for file in os.listdir(sni_path): - lower_file = file.lower() - if (lower_file.startswith("sni.") and not lower_file.endswith(".proto")) or lower_file == "sni": - sni_path = os.path.join(sni_path, file) + dir_entry: os.DirEntry + for dir_entry in os.scandir(sni_path): + if dir_entry.is_file(): + lower_file = dir_entry.name.lower() + if (lower_file.startswith("sni.") and not lower_file.endswith(".proto")) or (lower_file == "sni"): + sni_path = dir_entry.path + break if os.path.isfile(sni_path): snes_logger.info(f"Attempting to start {sni_path}") diff --git a/WebHostLib/options.py b/WebHostLib/options.py index 3b742068..a2041339 100644 --- a/WebHostLib/options.py +++ b/WebHostLib/options.py @@ -97,7 +97,7 @@ def create(): os.makedirs(os.path.join(target_folder, 'player-settings'), exist_ok=True) with open(os.path.join(target_folder, 'player-settings', game_name + ".json"), "w") as f: - f.write(json.dumps(player_settings, indent=2, separators=(',', ': '))) + json.dump(player_settings, f, indent=2, separators=(',', ': ')) if not world.hidden: weighted_settings["baseOptions"]["game"][game_name] = 0 @@ -107,4 +107,4 @@ def create(): weighted_settings["games"][game_name]["gameLocations"] = tuple(world.location_names) with open(os.path.join(target_folder, 'weighted-settings.json'), "w") as f: - f.write(json.dumps(weighted_settings, indent=2, separators=(',', ': '))) + json.dump(weighted_settings, f, indent=2, separators=(',', ': '))