Skip to content

Commit 8327385

Browse files
authored
fix: 🐛 check if mod zip is structured correctly (#303)
* fix: 🐛 check if mod zip is structured correctly * fix: 🐛 Check if mod is loaded before setting active state
1 parent 409c00e commit 8327385

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

addons/mod_loader/api/profile.gd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ static func _update_disabled_mods() -> void:
208208
# Iterate through the mod list in the current user profile to find disabled mods
209209
for mod_id in current_user_profile.mod_list:
210210
var mod_list_entry: Dictionary = current_user_profile.mod_list[mod_id]
211-
ModLoaderStore.mod_data[mod_id].is_active = mod_list_entry.is_active
211+
if ModLoaderStore.mod_data.has(mod_id):
212+
ModLoaderStore.mod_data[mod_id].is_active = mod_list_entry.is_active
212213

213214
ModLoaderLog.debug(
214215
"Updated the active state of all mods, based on the current user profile \"%s\""

addons/mod_loader/internal/file.gd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static func _get_json_string_as_dict(string: String) -> Dictionary:
4545

4646
# Load the mod ZIP from the provided directory
4747
static func load_zips_in_folder(folder_path: String) -> Dictionary:
48+
var URL_MOD_STRUCTURE_DOCS := "https://github.com/GodotModding/godot-mod-loader/wiki/Mod-Structure"
4849
var zip_data := {}
4950

5051
var mod_dir := Directory.new()
@@ -85,13 +86,23 @@ static func load_zips_in_folder(folder_path: String) -> Dictionary:
8586
# Get the current directories inside UNPACKED_DIR
8687
# This array is used to determine which directory is new
8788
var current_mod_dirs := _ModLoaderPath.get_dir_paths_in_dir(_ModLoaderPath.get_unpacked_mods_dir_path())
89+
8890
# Create a backup to reference when the next mod is loaded
8991
var current_mod_dirs_backup := current_mod_dirs.duplicate()
9092

9193
# Remove all directory paths that existed before, leaving only the one added last
9294
for previous_mod_dir in ModLoaderStore.previous_mod_dirs:
9395
current_mod_dirs.erase(previous_mod_dir)
9496

97+
# If the mod zip is not structured correctly, it may not be in the UNPACKED_DIR.
98+
if current_mod_dirs.empty():
99+
ModLoaderLog.fatal(
100+
"The mod zip at path \"%s\" does not have the correct file structure. For more information, please visit \"%s\"."
101+
% [mod_zip_global_path, URL_MOD_STRUCTURE_DOCS],
102+
LOG_NAME
103+
)
104+
continue
105+
95106
# The key is the mod_id of the latest loaded mod, and the value is the path to the zip file
96107
zip_data[current_mod_dirs[0].get_slice("/", 3)] = mod_zip_global_path
97108

addons/mod_loader/internal/path.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ static func get_file_paths_in_dir(src_dir_path: String) -> Array:
113113
var error := directory.open(src_dir_path)
114114

115115
if not error == OK:
116+
ModLoaderLog.fatal("Encountered an error (%s) when attempting to open a directory, with the path: %s" % [error, src_dir_path], LOG_NAME)
116117
return file_paths
117-
ModLoaderLog.error("Error opening directory", LOG_NAME)
118118

119119
directory.list_dir_begin()
120120
var file_name := directory.get_next()
@@ -133,9 +133,9 @@ static func get_dir_paths_in_dir(src_dir_path: String) -> Array:
133133
var directory := Directory.new()
134134
var error := directory.open(src_dir_path)
135135

136-
if not error == OK:
136+
if not error == OK:
137+
ModLoaderLog.fatal("Encountered an error (%s) when attempting to open a directory, with the path: %s" % [error, src_dir_path], LOG_NAME)
137138
return dir_paths
138-
ModLoaderLog.error("Error opening directory", LOG_NAME)
139139

140140
directory.list_dir_begin()
141141
var file_name := directory.get_next()

0 commit comments

Comments
 (0)