mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-01-01 05:13:43 +01:00
Change folder handling and introduce drag & drop for folders
This commit is contained in:
parent
ec99887387
commit
2532e73f9d
21 changed files with 1690 additions and 651 deletions
|
|
@ -1,11 +1,51 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Dalamud.Plugin;
|
||||
using Penumbra.Mods;
|
||||
using Penumbra.Util;
|
||||
|
||||
namespace Penumbra.Mod
|
||||
{
|
||||
public struct SortOrder : IComparable<SortOrder>
|
||||
{
|
||||
public ModFolder ParentFolder { get; set; }
|
||||
|
||||
private string _sortOrderName;
|
||||
|
||||
public string SortOrderName
|
||||
{
|
||||
get => _sortOrderName;
|
||||
set => _sortOrderName = value.Replace( '/', '\\' );
|
||||
}
|
||||
|
||||
public string SortOrderPath
|
||||
=> ParentFolder.FullName;
|
||||
|
||||
public string FullName
|
||||
{
|
||||
get
|
||||
{
|
||||
var path = SortOrderPath;
|
||||
return path.Any() ? $"{path}/{SortOrderName}" : SortOrderName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public SortOrder( ModFolder parentFolder, string name )
|
||||
{
|
||||
ParentFolder = parentFolder;
|
||||
_sortOrderName = name.Replace( '/', '\\' );
|
||||
}
|
||||
|
||||
public string FullPath
|
||||
=> SortOrderPath.Any() ? $"{SortOrderPath}/{SortOrderName}" : SortOrderName;
|
||||
|
||||
public int CompareTo( SortOrder other )
|
||||
=> string.Compare(FullPath, other.FullPath, StringComparison.InvariantCultureIgnoreCase );
|
||||
}
|
||||
|
||||
// ModData contains all permanent information about a mod,
|
||||
// and is independent of collections or settings.
|
||||
// It only changes when the user actively changes the mod or their filesystem.
|
||||
|
|
@ -14,17 +54,22 @@ namespace Penumbra.Mod
|
|||
public DirectoryInfo BasePath;
|
||||
public ModMeta Meta;
|
||||
public ModResources Resources;
|
||||
public string SortOrder;
|
||||
|
||||
public SortOrder SortOrder;
|
||||
|
||||
public SortedList< string, object? > ChangedItems { get; } = new();
|
||||
public string LowerChangedItemsString { get; private set; } = string.Empty;
|
||||
public FileInfo MetaFile { get; set; }
|
||||
|
||||
private ModData( DirectoryInfo basePath, ModMeta meta, ModResources resources )
|
||||
private ModData( ModFolder parentFolder, DirectoryInfo basePath, ModMeta meta, ModResources resources )
|
||||
{
|
||||
BasePath = basePath;
|
||||
Meta = meta;
|
||||
Resources = resources;
|
||||
MetaFile = MetaFileInfo( basePath );
|
||||
SortOrder = meta.Name.Replace( '/', '\\' );
|
||||
SortOrder = new SortOrder( parentFolder, Meta.Name );
|
||||
SortOrder.ParentFolder.AddMod( this );
|
||||
|
||||
ComputeChangedItems();
|
||||
}
|
||||
|
||||
|
|
@ -44,12 +89,14 @@ namespace Penumbra.Mod
|
|||
{
|
||||
identifier.Identify( ChangedItems, path );
|
||||
}
|
||||
|
||||
LowerChangedItemsString = string.Join( "\0", ChangedItems.Keys.Select( k => k.ToLowerInvariant() ) );
|
||||
}
|
||||
|
||||
public static FileInfo MetaFileInfo( DirectoryInfo basePath )
|
||||
=> new( Path.Combine( basePath.FullName, "meta.json" ) );
|
||||
|
||||
public static ModData? LoadMod( DirectoryInfo basePath )
|
||||
public static ModData? LoadMod( ModFolder parentFolder, DirectoryInfo basePath )
|
||||
{
|
||||
basePath.Refresh();
|
||||
if( !basePath.Exists )
|
||||
|
|
@ -77,10 +124,13 @@ namespace Penumbra.Mod
|
|||
data.SetManipulations( meta, basePath );
|
||||
}
|
||||
|
||||
return new ModData( basePath, meta, data );
|
||||
return new ModData( parentFolder, basePath, meta, data );
|
||||
}
|
||||
|
||||
public void SaveMeta()
|
||||
=> Meta.SaveToFile( MetaFile );
|
||||
|
||||
public override string ToString()
|
||||
=> SortOrder.FullPath;
|
||||
}
|
||||
}
|
||||
|
|
@ -13,8 +13,37 @@ namespace Penumbra.Mod
|
|||
public class ModMeta
|
||||
{
|
||||
public uint FileVersion { get; set; }
|
||||
public string Name { get; set; } = "Mod";
|
||||
public string Author { get; set; } = "";
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
set
|
||||
{
|
||||
_name = value;
|
||||
LowerName = value.ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
|
||||
private string _name = "Mod";
|
||||
|
||||
[JsonIgnore]
|
||||
public string LowerName { get; private set; } = "mod";
|
||||
|
||||
private string _author = "";
|
||||
|
||||
public string Author
|
||||
{
|
||||
get => _author;
|
||||
set
|
||||
{
|
||||
_author = value;
|
||||
LowerAuthor = value.ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public string LowerAuthor { get; private set; } = "";
|
||||
|
||||
public string Description { get; set; } = "";
|
||||
public string Version { get; set; } = "";
|
||||
public string Website { get; set; } = "";
|
||||
|
|
@ -66,8 +95,8 @@ namespace Penumbra.Mod
|
|||
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore } );
|
||||
if( meta != null )
|
||||
{
|
||||
meta.FileHash = text.GetHashCode();
|
||||
meta.HasGroupsWithConfig = meta.Groups.Values.Any( g => g.SelectionType == SelectType.Multi || g.Options.Count > 1 );
|
||||
meta.FileHash = text.GetHashCode();
|
||||
meta.RefreshHasGroupsWithConfig();
|
||||
}
|
||||
|
||||
return meta;
|
||||
|
|
@ -79,6 +108,14 @@ namespace Penumbra.Mod
|
|||
}
|
||||
}
|
||||
|
||||
public bool RefreshHasGroupsWithConfig()
|
||||
{
|
||||
var oldValue = HasGroupsWithConfig;
|
||||
HasGroupsWithConfig = Groups.Values.Any( g => g.Options.Count > 1 || g.SelectionType == SelectType.Multi && g.Options.Count == 1 );
|
||||
return oldValue != HasGroupsWithConfig;
|
||||
}
|
||||
|
||||
|
||||
public void SaveToFile( FileInfo filePath )
|
||||
{
|
||||
try
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue