Skip to content

Commit 95f2dfd

Browse files
committed
refactor: ♻️ added zip_path to user profiles
This allows to verify if the mod is still installed by confirming the existence of the zip file. However, this check is only performed when the mod is not loaded and a path to the zip file exists. This ensures that mods are not deleted from the profile when running in the editor. It's important to note that this new check may cause mods to appear in user profiles even if they are currently not loaded. To determine if a mod is actually loaded, you should also check `ModLoaderStore.mod_data` or use `ModLoaderMod.is_mod_loaded()`. closes #288
1 parent 23dddf2 commit 95f2dfd

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

addons/mod_loader/api/profile.gd

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,28 @@ static func _update_mod_list(mod_list: Dictionary, mod_data := ModLoaderStore.mo
273273
# If the current config doesn't exist, reset it to the default configuration
274274
mod_list_entry.current_config = ModLoaderConfig.DEFAULT_CONFIG_NAME
275275

276+
# If the mod is not loaded
277+
if not mod_data.has(mod_id):
278+
if (
279+
# Check if the entry has a zip_path key
280+
mod_list_entry.has("zip_path") and
281+
# Check if the entry has a zip_path
282+
not mod_list_entry.zip_path.empty() and
283+
# Check if the zip file for the mod exists
284+
not _ModLoaderFile.file_exists(mod_list_entry.zip_path)
285+
):
286+
# If the mod directory doesn't exist,
287+
# the mod is no longer installed and can be removed from the mod list
288+
ModLoaderLog.debug(
289+
"Mod \"%s\" has been deleted from all user profiles as the corresponding zip file no longer exists at path \"%s\"."
290+
% [mod_id, mod_list_entry.zip_path],
291+
LOG_NAME,
292+
true
293+
)
294+
295+
updated_mod_list.erase(mod_id)
296+
continue
297+
276298
updated_mod_list[mod_id] = mod_list_entry
277299

278300
return updated_mod_list
@@ -298,7 +320,13 @@ static func _generate_mod_list() -> Dictionary:
298320
static func _generate_mod_list_entry(mod_id: String, is_active: bool) -> Dictionary:
299321
var mod_list_entry := {}
300322

323+
# Set the mods active state
301324
mod_list_entry.is_active = is_active
325+
326+
# Set the mods zip path if available
327+
if ModLoaderStore.mod_data.has(mod_id):
328+
mod_list_entry.zip_path = ModLoaderStore.mod_data[mod_id].zip_path
329+
302330
# Set the current_config if the mod has a config schema and is active
303331
if is_active and not ModLoaderConfig.get_config_schema(mod_id).empty():
304332
var current_config: ModConfig = ModLoaderStore.mod_data[mod_id].current_config

0 commit comments

Comments
 (0)