Changed initial mod directory to be empty and prevent crashes on invalid or no root directories (also add some information to debug).

This commit is contained in:
Ottermandias 2021-07-11 23:15:42 +02:00
parent e41dedf9dd
commit 92e95400b0
9 changed files with 95 additions and 37 deletions

View file

@ -22,7 +22,7 @@ namespace Penumbra
public bool EnableHttpApi { get; set; } public bool EnableHttpApi { get; set; }
public bool EnableActorWatch { get; set; } = false; public bool EnableActorWatch { get; set; } = false;
public string ModDirectory { get; set; } = @"D:/ffxiv/fs_mods/"; public string ModDirectory { get; set; } = string.Empty;
public string CurrentCollection { get; set; } = "Default"; public string CurrentCollection { get; set; } = "Default";
public string DefaultCollection { get; set; } = "Default"; public string DefaultCollection { get; set; } = "Default";

View file

@ -126,7 +126,11 @@ namespace Penumbra.Meta
public void WriteNewFiles() public void WriteNewFiles()
{ {
Directory.CreateDirectory( _dir.FullName ); if( _currentFiles.Any() )
{
Directory.CreateDirectory( _dir.FullName );
}
foreach( var kvp in _currentFiles.Where( kvp => kvp.Value.Changed ) ) foreach( var kvp in _currentFiles.Where( kvp => kvp.Value.Changed ) )
{ {
kvp.Value.Write( _dir, kvp.Key ); kvp.Value.Write( _dir, kvp.Key );

View file

@ -14,26 +14,42 @@ namespace Penumbra.Mods
public class ModManager public class ModManager
{ {
private readonly Plugin _plugin; private readonly Plugin _plugin;
public DirectoryInfo BasePath { get; private set; } public DirectoryInfo BasePath { get; private set; } = null!;
public Dictionary< string, ModData > Mods { get; } = new(); public Dictionary< string, ModData > Mods { get; } = new();
public CollectionManager Collections { get; } public CollectionManager Collections { get; }
public bool Valid { get; private set; }
public Configuration Config public Configuration Config
=> _plugin.Configuration; => _plugin.Configuration;
private void SetBaseDirectory( string basePath )
{
if( basePath.Any() )
{
BasePath = new DirectoryInfo( basePath );
Valid = Path.IsPathRooted( basePath );
}
else
{
BasePath = new DirectoryInfo( "." );
Valid = false;
}
}
public ModManager( Plugin plugin ) public ModManager( Plugin plugin )
{ {
_plugin = plugin; _plugin = plugin;
BasePath = new DirectoryInfo( plugin.Configuration.ModDirectory ); SetBaseDirectory( plugin.Configuration.ModDirectory );
MetaManager.ClearBaseDirectory( BasePath ); MetaManager.ClearBaseDirectory( BasePath! );
Collections = new CollectionManager( plugin, this ); Collections = new CollectionManager( plugin, this );
} }
public void DiscoverMods( DirectoryInfo basePath ) public void DiscoverMods( string basePath )
{ {
BasePath = basePath; SetBaseDirectory( basePath );
DiscoverMods(); DiscoverMods();
} }
@ -62,7 +78,7 @@ namespace Penumbra.Mods
public void DiscoverMods() public void DiscoverMods()
{ {
Mods.Clear(); Mods.Clear();
if( !BasePath.Exists ) if( Valid && !BasePath.Exists )
{ {
PluginLog.Debug( "The mod directory {Directory} does not exist.", BasePath.FullName ); PluginLog.Debug( "The mod directory {Directory} does not exist.", BasePath.FullName );
try try
@ -72,22 +88,26 @@ namespace Penumbra.Mods
catch( Exception e ) catch( Exception e )
{ {
PluginLog.Error( $"The mod directory {BasePath.FullName} does not exist and could not be created:\n{e}" ); PluginLog.Error( $"The mod directory {BasePath.FullName} does not exist and could not be created:\n{e}" );
return; Valid = false;
} }
} }
foreach( var modFolder in BasePath.EnumerateDirectories() ) if( Valid )
{ {
var mod = ModData.LoadMod( modFolder ); foreach( var modFolder in BasePath.EnumerateDirectories() )
if( mod == null )
{ {
continue; var mod = ModData.LoadMod( modFolder );
if( mod == null )
{
continue;
}
Mods.Add( modFolder.Name, mod );
} }
Mods.Add( modFolder.Name, mod ); SetModOrders( _plugin.Configuration );
} }
SetModOrders( _plugin.Configuration );
Collections.RecreateCaches(); Collections.RecreateCaches();
} }

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using System.Reflection; using System.Reflection;
@ -111,6 +112,15 @@ namespace Penumbra.UI
} }
} }
private static void PrintValue( string name, string value )
{
ImGui.TableNextRow();
ImGui.TableNextColumn();
ImGui.Text( name );
ImGui.TableNextColumn();
ImGui.Text( value );
}
private void DrawDebugTabGeneral() private void DrawDebugTabGeneral()
{ {
if( !ImGui.CollapsingHeader( "General##Debug" ) ) if( !ImGui.CollapsingHeader( "General##Debug" ) )
@ -124,16 +134,17 @@ namespace Penumbra.UI
return; return;
} }
ImGui.TableNextRow(); var manager = Service< ModManager >.Get();
ImGui.TableNextColumn(); PrintValue( "Active Collection", manager.Collections.ActiveCollection.Name );
PrintValue( "Mod Manager BasePath", manager.BasePath.Name );
PrintValue( "Mod Manager BasePath-Full", manager.BasePath.FullName );
PrintValue( "Mod Manager BasePath IsRooted", Path.IsPathRooted( _plugin.Configuration.ModDirectory ).ToString() );
PrintValue( "Mod Manager BasePath Exists", Directory.Exists( manager.BasePath.FullName ).ToString() );
PrintValue( "Mod Manager Valid", manager.Valid.ToString() );
ImGui.Text( "Active Collection" );
ImGui.TableNextColumn();
ImGui.Text( Service< ModManager >.Get().Collections.ActiveCollection.Name );
ImGui.EndTable(); ImGui.EndTable();
} }
private void DrawDebugTabRedraw() private void DrawDebugTabRedraw()
{ {
if( !ImGui.CollapsingHeader( "Redrawing##Debug" ) ) if( !ImGui.CollapsingHeader( "Redrawing##Debug" ) )

View file

@ -6,6 +6,7 @@ using System.Windows.Forms;
using Dalamud.Plugin; using Dalamud.Plugin;
using ImGuiNET; using ImGuiNET;
using Penumbra.Importer; using Penumbra.Importer;
using Penumbra.Mods;
using Penumbra.Util; using Penumbra.Util;
namespace Penumbra.UI namespace Penumbra.UI
@ -22,7 +23,8 @@ namespace Penumbra.UI
private const string TooltipModpack1 = "Writing modpack to disk before extracting..."; private const string TooltipModpack1 = "Writing modpack to disk before extracting...";
private const string FailedImport = "One or more of your modpacks failed to import.\nPlease submit a bug report."; private const string FailedImport = "One or more of your modpacks failed to import.\nPlease submit a bug report.";
private const uint ColorRed = 0xFF0000C8; private const uint ColorRed = 0xFF0000C8;
private const uint ColorYellow = 0xFF00C8C8;
private static readonly Vector2 ImportBarSize = new( -1, 0 ); private static readonly Vector2 ImportBarSize = new( -1, 0 );
@ -30,9 +32,13 @@ namespace Penumbra.UI
private bool _hasError; private bool _hasError;
private TexToolsImport? _texToolsImport; private TexToolsImport? _texToolsImport;
private readonly SettingsInterface _base; private readonly SettingsInterface _base;
private readonly ModManager _manager;
public TabImport( SettingsInterface ui ) public TabImport( SettingsInterface ui )
=> _base = ui; {
_base = ui;
_manager = Service< ModManager >.Get();
}
public bool IsImporting() public bool IsImporting()
=> _isImportRunning; => _isImportRunning;
@ -64,7 +70,7 @@ namespace Penumbra.UI
try try
{ {
_texToolsImport = new TexToolsImport( new DirectoryInfo( _base._plugin!.Configuration!.ModDirectory ) ); _texToolsImport = new TexToolsImport( _manager.BasePath );
_texToolsImport.ImportModPack( new FileInfo( fileName ) ); _texToolsImport.ImportModPack( new FileInfo( fileName ) );
PluginLog.Log( $"-> {fileName} OK!" ); PluginLog.Log( $"-> {fileName} OK!" );
@ -96,7 +102,25 @@ namespace Penumbra.UI
private void DrawImportButton() private void DrawImportButton()
{ {
if( ImGui.Button( LabelImportButton ) ) if( !_manager.Valid )
{
ImGui.PushStyleVar( ImGuiStyleVar.Alpha, 0.5f );
ImGui.Button( LabelImportButton );
ImGui.PopStyleVar();
ImGui.PushStyleColor( ImGuiCol.Text, ColorRed );
ImGui.Text( "Can not import since the mod directory path is not valid." );
ImGui.Dummy( Vector2.UnitY * ImGui.GetTextLineHeightWithSpacing() );
ImGui.PopStyleColor();
ImGui.Text( "Please set the mod directory in the settings tab." );
ImGui.Text( "This folder should preferably be close to the root directory of your (preferably SSD) drive, for example" );
ImGui.PushStyleColor( ImGuiCol.Text, ColorYellow );
ImGui.Text( " D:\\ffxivmods" );
ImGui.PopStyleColor();
ImGui.Text( "You can return to this tab once you've done that." );
}
else if( ImGui.Button( LabelImportButton ) )
{ {
RunImportTask(); RunImportTask();
} }

View file

@ -24,11 +24,6 @@ namespace Penumbra.UI
private static void DrawNoModsAvailable() private static void DrawNoModsAvailable()
{ {
ImGui.Text( "You don't have any mods :(" ); ImGui.Text( "You don't have any mods :(" );
Custom.ImGuiCustom.VerticalDistance( 20f );
ImGui.Text( "You'll need to install them first by creating a folder close to the root of your drive (preferably an SSD)." );
ImGui.Text( "For example: D:/ffxiv/mods/" );
ImGui.Text( "And pasting that path into the settings tab and clicking the 'Rediscover Mods' button." );
ImGui.Text( "You can return to this tab once you've done that." );
} }
public void Draw() public void Draw()

View file

@ -5,6 +5,7 @@ using System.Text.RegularExpressions;
using Dalamud.Plugin; using Dalamud.Plugin;
using ImGuiNET; using ImGuiNET;
using Penumbra.Interop; using Penumbra.Interop;
using Penumbra.Mods;
using Penumbra.Util; using Penumbra.Util;
namespace Penumbra.UI namespace Penumbra.UI
@ -39,10 +40,13 @@ namespace Penumbra.UI
private void DrawRootFolder() private void DrawRootFolder()
{ {
var basePath = _config.ModDirectory; var basePath = _config.ModDirectory;
if( ImGui.InputText( LabelRootFolder, ref basePath, 255 ) && _config.ModDirectory != basePath ) if( ImGui.InputText( LabelRootFolder, ref basePath, 255, ImGuiInputTextFlags.EnterReturnsTrue )
&& _config.ModDirectory != basePath )
{ {
_config.ModDirectory = basePath; _config.ModDirectory = basePath;
_configChanged = true; _configChanged = true;
_base.ReloadMods();
_base._menu.InstalledTab.Selector.ClearSelection();
} }
} }
@ -59,7 +63,7 @@ namespace Penumbra.UI
{ {
if( ImGui.Button( LabelOpenFolder ) ) if( ImGui.Button( LabelOpenFolder ) )
{ {
if( !Directory.Exists( _config.ModDirectory ) ) if( !Directory.Exists( _config.ModDirectory ) || !Service< ModManager >.Get().Valid )
{ {
return; return;
} }

View file

@ -43,11 +43,9 @@ namespace Penumbra.UI
{ {
_menu.InstalledTab.Selector.ResetModNamesLower(); _menu.InstalledTab.Selector.ResetModNamesLower();
_menu.InstalledTab.Selector.ClearSelection(); _menu.InstalledTab.Selector.ClearSelection();
// create the directory if it doesn't exist
Directory.CreateDirectory( _plugin!.Configuration!.ModDirectory );
var modManager = Service< ModManager >.Get(); var modManager = Service< ModManager >.Get();
modManager.DiscoverMods( new DirectoryInfo( _plugin.Configuration.ModDirectory ) ); modManager.DiscoverMods( _plugin.Configuration.ModDirectory );
_menu.InstalledTab.Selector.ResetModNamesLower(); _menu.InstalledTab.Selector.ResetModNamesLower();
} }
} }

View file

@ -1,5 +1,7 @@
using System.Numerics; using System.Numerics;
using ImGuiNET; using ImGuiNET;
using Penumbra.Mods;
using Penumbra.Util;
namespace Penumbra.UI namespace Penumbra.UI
{ {
@ -63,7 +65,7 @@ namespace Penumbra.UI
_collectionsTab.Draw(); _collectionsTab.Draw();
_importTab.Draw(); _importTab.Draw();
if( !_importTab.IsImporting() ) if( Service<ModManager>.Get().Valid && !_importTab.IsImporting() )
{ {
_browserTab.Draw(); _browserTab.Draw();
InstalledTab.Draw(); InstalledTab.Draw();