From 7e1409596a7984b805002dacc3d2147f2827d6aa Mon Sep 17 00:00:00 2001 From: Mr_Goldberg Date: Tue, 16 Aug 2022 19:27:44 -0400 Subject: [PATCH] Don't crash script when some controller configs don't have URLs. --- scripts/generate_emu_config.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) mode change 100644 => 100755 scripts/generate_emu_config.py diff --git a/scripts/generate_emu_config.py b/scripts/generate_emu_config.py old mode 100644 new mode 100755 index 31a8dbd..3022a0c --- a/scripts/generate_emu_config.py +++ b/scripts/generate_emu_config.py @@ -183,12 +183,17 @@ def download_published_file(client, published_file_id, backup_directory): with open(os.path.join(backup_directory, "info.txt"), "w") as f: f.write(str(ugc_info.body)) - with urllib.request.urlopen(file_details.file_url) as response: - data = response.read() - with open(os.path.join(backup_directory, file_details.filename.replace("/", "_").replace("\\", "_")), "wb") as f: - f.write(data) - return data - return None + if len(file_details.file_url) > 0: + with urllib.request.urlopen(file_details.file_url) as response: + data = response.read() + with open(os.path.join(backup_directory, file_details.filename.replace("/", "_").replace("\\", "_")), "wb") as f: + f.write(data) + return data + return None + else: + print("Could not download file", published_file_id, "no url (you can ignore this if the game doesn't need a controller config)") + return None + def get_inventory_info(client, game_id): return client.send_um_and_wait('Inventory.GetItemDefMeta#1', {