mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
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:
parent
e41dedf9dd
commit
92e95400b0
9 changed files with 95 additions and 37 deletions
|
|
@ -22,7 +22,7 @@ namespace Penumbra
|
|||
public bool EnableHttpApi { get; set; }
|
||||
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 DefaultCollection { get; set; } = "Default";
|
||||
|
|
|
|||
|
|
@ -126,7 +126,11 @@ namespace Penumbra.Meta
|
|||
|
||||
public void WriteNewFiles()
|
||||
{
|
||||
Directory.CreateDirectory( _dir.FullName );
|
||||
if( _currentFiles.Any() )
|
||||
{
|
||||
Directory.CreateDirectory( _dir.FullName );
|
||||
}
|
||||
|
||||
foreach( var kvp in _currentFiles.Where( kvp => kvp.Value.Changed ) )
|
||||
{
|
||||
kvp.Value.Write( _dir, kvp.Key );
|
||||
|
|
|
|||
|
|
@ -14,26 +14,42 @@ namespace Penumbra.Mods
|
|||
public class ModManager
|
||||
{
|
||||
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 CollectionManager Collections { get; }
|
||||
|
||||
public bool Valid { get; private set; }
|
||||
|
||||
public Configuration Config
|
||||
=> _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 )
|
||||
{
|
||||
_plugin = plugin;
|
||||
BasePath = new DirectoryInfo( plugin.Configuration.ModDirectory );
|
||||
MetaManager.ClearBaseDirectory( BasePath );
|
||||
_plugin = plugin;
|
||||
SetBaseDirectory( plugin.Configuration.ModDirectory );
|
||||
MetaManager.ClearBaseDirectory( BasePath! );
|
||||
|
||||
Collections = new CollectionManager( plugin, this );
|
||||
}
|
||||
|
||||
public void DiscoverMods( DirectoryInfo basePath )
|
||||
public void DiscoverMods( string basePath )
|
||||
{
|
||||
BasePath = basePath;
|
||||
SetBaseDirectory( basePath );
|
||||
DiscoverMods();
|
||||
}
|
||||
|
||||
|
|
@ -62,7 +78,7 @@ namespace Penumbra.Mods
|
|||
public void DiscoverMods()
|
||||
{
|
||||
Mods.Clear();
|
||||
if( !BasePath.Exists )
|
||||
if( Valid && !BasePath.Exists )
|
||||
{
|
||||
PluginLog.Debug( "The mod directory {Directory} does not exist.", BasePath.FullName );
|
||||
try
|
||||
|
|
@ -72,22 +88,26 @@ namespace Penumbra.Mods
|
|||
catch( Exception 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 );
|
||||
if( mod == null )
|
||||
foreach( var modFolder in BasePath.EnumerateDirectories() )
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
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()
|
||||
{
|
||||
if( !ImGui.CollapsingHeader( "General##Debug" ) )
|
||||
|
|
@ -124,16 +134,17 @@ namespace Penumbra.UI
|
|||
return;
|
||||
}
|
||||
|
||||
ImGui.TableNextRow();
|
||||
ImGui.TableNextColumn();
|
||||
var manager = Service< ModManager >.Get();
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
private void DrawDebugTabRedraw()
|
||||
{
|
||||
if( !ImGui.CollapsingHeader( "Redrawing##Debug" ) )
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Windows.Forms;
|
|||
using Dalamud.Plugin;
|
||||
using ImGuiNET;
|
||||
using Penumbra.Importer;
|
||||
using Penumbra.Mods;
|
||||
using Penumbra.Util;
|
||||
|
||||
namespace Penumbra.UI
|
||||
|
|
@ -22,7 +23,8 @@ namespace Penumbra.UI
|
|||
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 uint ColorRed = 0xFF0000C8;
|
||||
private const uint ColorRed = 0xFF0000C8;
|
||||
private const uint ColorYellow = 0xFF00C8C8;
|
||||
|
||||
private static readonly Vector2 ImportBarSize = new( -1, 0 );
|
||||
|
||||
|
|
@ -30,9 +32,13 @@ namespace Penumbra.UI
|
|||
private bool _hasError;
|
||||
private TexToolsImport? _texToolsImport;
|
||||
private readonly SettingsInterface _base;
|
||||
private readonly ModManager _manager;
|
||||
|
||||
public TabImport( SettingsInterface ui )
|
||||
=> _base = ui;
|
||||
{
|
||||
_base = ui;
|
||||
_manager = Service< ModManager >.Get();
|
||||
}
|
||||
|
||||
public bool IsImporting()
|
||||
=> _isImportRunning;
|
||||
|
|
@ -64,7 +70,7 @@ namespace Penumbra.UI
|
|||
|
||||
try
|
||||
{
|
||||
_texToolsImport = new TexToolsImport( new DirectoryInfo( _base._plugin!.Configuration!.ModDirectory ) );
|
||||
_texToolsImport = new TexToolsImport( _manager.BasePath );
|
||||
_texToolsImport.ImportModPack( new FileInfo( fileName ) );
|
||||
|
||||
PluginLog.Log( $"-> {fileName} OK!" );
|
||||
|
|
@ -96,7 +102,25 @@ namespace Penumbra.UI
|
|||
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,11 +24,6 @@ namespace Penumbra.UI
|
|||
private static void DrawNoModsAvailable()
|
||||
{
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System.Text.RegularExpressions;
|
|||
using Dalamud.Plugin;
|
||||
using ImGuiNET;
|
||||
using Penumbra.Interop;
|
||||
using Penumbra.Mods;
|
||||
using Penumbra.Util;
|
||||
|
||||
namespace Penumbra.UI
|
||||
|
|
@ -39,10 +40,13 @@ namespace Penumbra.UI
|
|||
private void DrawRootFolder()
|
||||
{
|
||||
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;
|
||||
_configChanged = true;
|
||||
_base.ReloadMods();
|
||||
_base._menu.InstalledTab.Selector.ClearSelection();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -59,7 +63,7 @@ namespace Penumbra.UI
|
|||
{
|
||||
if( ImGui.Button( LabelOpenFolder ) )
|
||||
{
|
||||
if( !Directory.Exists( _config.ModDirectory ) )
|
||||
if( !Directory.Exists( _config.ModDirectory ) || !Service< ModManager >.Get().Valid )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,11 +43,9 @@ namespace Penumbra.UI
|
|||
{
|
||||
_menu.InstalledTab.Selector.ResetModNamesLower();
|
||||
_menu.InstalledTab.Selector.ClearSelection();
|
||||
// create the directory if it doesn't exist
|
||||
Directory.CreateDirectory( _plugin!.Configuration!.ModDirectory );
|
||||
|
||||
var modManager = Service< ModManager >.Get();
|
||||
modManager.DiscoverMods( new DirectoryInfo( _plugin.Configuration.ModDirectory ) );
|
||||
modManager.DiscoverMods( _plugin.Configuration.ModDirectory );
|
||||
_menu.InstalledTab.Selector.ResetModNamesLower();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using System.Numerics;
|
||||
using ImGuiNET;
|
||||
using Penumbra.Mods;
|
||||
using Penumbra.Util;
|
||||
|
||||
namespace Penumbra.UI
|
||||
{
|
||||
|
|
@ -63,7 +65,7 @@ namespace Penumbra.UI
|
|||
_collectionsTab.Draw();
|
||||
_importTab.Draw();
|
||||
|
||||
if( !_importTab.IsImporting() )
|
||||
if( Service<ModManager>.Get().Valid && !_importTab.IsImporting() )
|
||||
{
|
||||
_browserTab.Draw();
|
||||
InstalledTab.Draw();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue