Skip to content

Commit

Permalink
Improve root directory behavior and AddMods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottermandias committed Jun 17, 2024
1 parent b3f8762 commit 250c403
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Penumbra/Api/Api/ModsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public PenumbraApiEc AddMod(string modDirectory)
if (!dir.Exists)
return ApiHelpers.Return(PenumbraApiEc.FileMissing, args);

if (dir.Parent == null || Path.GetFullPath(_modManager.BasePath.FullName) != Path.GetFullPath(dir.Parent.FullName))
if (dir.Parent == null
|| Path.TrimEndingDirectorySeparator(Path.GetFullPath(_modManager.BasePath.FullName))
!= Path.TrimEndingDirectorySeparator(Path.GetFullPath(dir.Parent.FullName)))
return ApiHelpers.Return(PenumbraApiEc.InvalidArgument, args);

_modManager.AddMod(dir);
Expand Down
16 changes: 9 additions & 7 deletions Penumbra/Mods/Manager/ModManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public ModManager(Configuration config, CommunicatorService communicator, ModDat
DataEditor = dataEditor;
OptionEditor = optionEditor;
Creator = creator;
SetBaseDirectory(config.ModDirectory, true);
SetBaseDirectory(config.ModDirectory, true, out _);
_communicator.ModPathChanged.Subscribe(OnModPathChange, ModPathChanged.Priority.ModManager);
DiscoverMods();
}

/// <summary> Change the mod base directory and discover available mods. </summary>
public void DiscoverMods(string newDir)
public void DiscoverMods(string newDir, out string resultNewDir)
{
SetBaseDirectory(newDir, false);
SetBaseDirectory(newDir, false, out resultNewDir);
DiscoverMods();
}

Expand Down Expand Up @@ -264,8 +264,9 @@ public void Dispose()
/// If its not the first time, check if it is the same directory as before.
/// Also checks if the directory is available and tries to create it if it is not.
/// </summary>
private void SetBaseDirectory(string newPath, bool firstTime)
private void SetBaseDirectory(string newPath, bool firstTime, out string resultNewDir)
{
resultNewDir = newPath;
if (!firstTime && string.Equals(newPath, _config.ModDirectory, StringComparison.Ordinal))
return;

Expand All @@ -278,7 +279,7 @@ private void SetBaseDirectory(string newPath, bool firstTime)
}
else
{
var newDir = new DirectoryInfo(newPath);
var newDir = new DirectoryInfo(Path.TrimEndingDirectorySeparator(newPath));
if (!newDir.Exists)
try
{
Expand All @@ -290,8 +291,9 @@ private void SetBaseDirectory(string newPath, bool firstTime)
Penumbra.Log.Error($"Could not create specified mod directory {newDir.FullName}:\n{e}");
}

BasePath = newDir;
Valid = Directory.Exists(newDir.FullName);
BasePath = newDir;
Valid = Directory.Exists(newDir.FullName);
resultNewDir = BasePath.FullName;
if (!firstTime && _config.ModDirectory != BasePath.FullName)
TriggerModDirectoryChange(BasePath.FullName, Valid);
}
Expand Down
2 changes: 1 addition & 1 deletion Penumbra/UI/Tabs/SettingsTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private void DrawRootFolder()
if (_config.ModDirectory != _newModDirectory
&& _newModDirectory.Length != 0
&& DrawPressEnterWarning(_newModDirectory, _config.ModDirectory, pos, save, selected))
_modManager.DiscoverMods(_newModDirectory);
_modManager.DiscoverMods(_newModDirectory, out _newModDirectory);
}

/// <summary> Draw the Open Directory and Rediscovery buttons.</summary>
Expand Down

0 comments on commit 250c403

Please sign in to comment.