Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ModForge.Shared/Services/IconService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,20 @@ public IconService(UserConfigurationService configService, ILogger<IconService>

public string? GetBase64Icon(string iconId, string matchingFolder = null!)
{
if (string.IsNullOrEmpty(configService.Current.GameDirectory))
{
logger.LogWarning("Game directory is not configured. Cannot load icon: {IconId}", iconId);
return null;
}

string pakPath = Path.Combine(configService.Current.GameDirectory, "Data", "IPL_GameData.pak");

if (!File.Exists(pakPath))
{
logger.LogWarning("Game data file not found at: {PakPath}", pakPath);
return null;
}

string targetFilename = $"{iconId}";

using FileStream zipStream = new(pakPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
Expand Down
13 changes: 13 additions & 0 deletions ModForge.Shared/Services/ModService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ public void InitiateModCollections()
}

var modFolder = Path.Combine(userConfigurationService.Current.GameDirectory, "Mods");

if (!Directory.Exists(modFolder))
{
Directory.CreateDirectory(modFolder);
logger.LogInformation("Created Mods folder at: {ModFolder}", modFolder);
}

var modDirectories = Directory.EnumerateDirectories(modFolder);

ModCollection.Clear();
Expand Down Expand Up @@ -229,6 +236,12 @@ public void DeleteMod(ModDescription mod)
}

var modFolder = Path.Combine(userConfigurationService.Current.GameDirectory, "Mods");

if (!Directory.Exists(modFolder))
{
return; // Nothing to delete if Mods folder doesn't exist
}

var modDirectories = Directory.EnumerateDirectories(modFolder);

foreach (var modPath in modDirectories)
Expand Down
4 changes: 2 additions & 2 deletions ModForge.Shared/Services/XmlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ ILogger<XmlService> logger
}

#region Properties
public IList<IModItem> Perks { get; private set; }
public IList<IModItem> Buffs { get; private set; }
public IList<IModItem> Perks { get; private set; } = new List<IModItem>();
public IList<IModItem> Buffs { get; private set; } = new List<IModItem>();
public IList<IModItem> Weapons { get; private set; } = new List<IModItem>();
public IList<IModItem> Armors { get; private set; } = new List<IModItem>();
public IList<IModItem> Consumeables { get; private set; } = new List<IModItem>();
Expand Down
7 changes: 7 additions & 0 deletions ModForge.UI/Components/MenuComponents/NewMod.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ public void StartModding()
return;
}

if (string.IsNullOrEmpty(UserConfigurationService?.Current?.GameDirectory))
{
Logger?.LogWarning("Game directory is not configured. Cannot start modding.");
Snackbar?.Add("Please configure your game directory in Settings before starting a mod.", Severity.Error);
return;
}

var mod = ModService.CreateNewMod(name, description, author, version, createdOn, modId, modifiesLevel, supportedGameVersions);

if (mod is null)
Expand Down
2 changes: 1 addition & 1 deletion ModForge.UI/Components/ModItemComponents/Armors.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ protected override async Task OnInitializedAsync()
{
SetLanguage();
ModService.TryGetModFromCollection(ModId);
armors = await Task.Run(() => XmlService.Armors.ToList());
armors = await Task.Run(() => XmlService.Armors?.ToList() ?? new List<IModItem>());
isLoaded = true;
}

Expand Down
2 changes: 1 addition & 1 deletion ModForge.UI/Components/ModItemComponents/Buffs.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ protected override async Task OnInitializedAsync()
{
SetLanguage();
ModService.TryGetModFromCollection(ModId);
buffs = await Task.Run(() => XmlService.Buffs.ToList());
buffs = await Task.Run(() => XmlService.Buffs?.ToList() ?? new List<IModItem>());
isLoaded = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ protected override async Task OnInitializedAsync()
{
SetLanguage();
ModService.TryGetModFromCollection(ModId);
consumables = await Task.Run(() => XmlService.Consumeables.ToList());
consumables = await Task.Run(() => XmlService.Consumeables?.ToList() ?? new List<IModItem>());
isLoaded = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ protected override async Task OnInitializedAsync()
{
SetLanguage();
ModService.TryGetModFromCollection(ModId);
craftingMaterials = await Task.Run(() => XmlService.CraftingMaterials.ToList());
craftingMaterials = await Task.Run(() => XmlService.CraftingMaterials?.ToList() ?? new List<IModItem>());
isLoaded = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ protected override async Task OnInitializedAsync()
{
SetLanguage();
ModService.TryGetModFromCollection(ModId);
miscItems = await Task.Run(() => XmlService.MiscItems.ToList());
miscItems = await Task.Run(() => XmlService.MiscItems?.ToList() ?? new List<IModItem>());
isLoaded = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ModForge.UI/Components/ModItemComponents/Perks.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ protected override async Task OnInitializedAsync()
{
SetLanguage();
ModService.TryGetModFromCollection(ModId);
perks = await Task.Run(() => XmlService.Perks.ToList());
perks = await Task.Run(() => XmlService.Perks?.ToList() ?? new List<IModItem>());
isLoaded = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ModForge.UI/Components/ModItemComponents/Weapons.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ protected override async Task OnInitializedAsync()
{
SetLanguage();
ModService.TryGetModFromCollection(ModId);
weapons = await Task.Run(() => XmlService.Weapons.ToList());
weapons = await Task.Run(() => XmlService.Weapons?.ToList() ?? new List<IModItem>());
isLoaded = true;
}
}
Expand Down