Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Game tags column to plugin and zipmod windows #154

Merged
merged 10 commits into from
Apr 13, 2024
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
9 changes: 8 additions & 1 deletion src/KKManager.Core/Data/ModInfoBase.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Security.Permissions;
using KKManager.Functions;

namespace KKManager.Data
{
public abstract class ModInfoBase : IFileInfoBase
{
protected ModInfoBase(FileInfo location, string guid, string name, string version, string author, string description, string website)
protected ModInfoBase(FileInfo location, string guid, string name, string version, string author, string description, string website, IReadOnlyList<string> games)
{
Location = location ?? throw new ArgumentNullException(nameof(location));
Guid = guid ?? throw new ArgumentNullException(nameof(guid));
Expand All @@ -16,6 +19,7 @@ protected ModInfoBase(FileInfo location, string guid, string name, string versio
Author = author;
Description = description;
Website = website;
Games = games ?? Array.Empty<string>();
}

public FileInfo Location { get; }
Expand All @@ -26,6 +30,9 @@ protected ModInfoBase(FileInfo location, string guid, string name, string versio
public string Author { get; }
public string Description { get; }
public string Website { get; }
[TypeConverter(typeof(ReadOnlyStringCollectionConverterWithPreview))]
public IReadOnlyList<string> Games { get; }


[Browsable(false)]
public string FileName => Location.Name;
Expand Down
3 changes: 2 additions & 1 deletion src/KKManager.Core/Data/Plugins/PluginInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public PluginInfo(
string author,
string description,
string website,
IReadOnlyList<string> processes,
FileInfo configFile)
: base(location, guid, name, version, author, description, website)
: base(location, guid, name, version, author, description, website, processes)
{
var extension = location.Extension;
if (!PluginLoader.IsValidPluginExtension(extension))
Expand Down
15 changes: 12 additions & 3 deletions src/KKManager.Core/Data/Plugins/PluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void ReadPluginsAsync()
var configDir = new DirectoryInfo(Path.Combine(pluginDirectory, "config"));
var configFiles = configDir.Exists ? configDir.GetFiles("*.cfg", SearchOption.TopDirectoryOnly) : Array.Empty<FileInfo>();

Parallel.ForEach(files, new ParallelOptions { MaxDegreeOfParallelism = 6, CancellationToken = token}, file =>
Parallel.ForEach(files, new ParallelOptions { MaxDegreeOfParallelism = 6, CancellationToken = token }, file =>
{
try
{
Expand Down Expand Up @@ -186,6 +186,14 @@ public static IEnumerable<PluginInfo> LoadFromFile(string dllFile, FileInfo[] co
.Where(x => !string.IsNullOrWhiteSpace(x))
.ToArray();


var processAttributes = pc.c.CustomAttributes
.Where(x => x.AttributeType.FullName == "BepInEx.BepInProcess");
var processes = processAttributes
.Select(x => x.ConstructorArguments.ElementAtOrDefault(0).Value?.ToString())
.Where(x => !string.IsNullOrWhiteSpace(x))
.ToArray();

var url = pc.c.CustomAttributes
.Where(x => x.AttributeType.FullName == "UnityEngine.HelpURLAttribute")
.Select(x => x.ConstructorArguments.ElementAtOrDefault(0).Value?.ToString())
Expand All @@ -209,6 +217,7 @@ public static IEnumerable<PluginInfo> LoadFromFile(string dllFile, FileInfo[] co
author,
description,
url,
processes,
config);
}
}
Expand All @@ -232,7 +241,7 @@ public static IEnumerable<PluginInfo> LoadFromFile(string dllFile, FileInfo[] co
var assRefs = md.AssemblyReferences.Select(x => x.FullName).ToArray();

yield return new PluginInfo(Path.GetFileNameWithoutExtension(dllFile), string.IsNullOrWhiteSpace(f.FileVersion) ? f.ProductVersion : f.FileVersion, "< PATCHER PLUGIN >", null, location,
Array.Empty<string>(), assRefs, author, description, fileUrl, null);
Array.Empty<string>(), assRefs, author, description, fileUrl, null, null);
}
}
}
Expand Down Expand Up @@ -304,4 +313,4 @@ public static IEnumerable<PluginInfo> CheckDependencies(IList<PluginInfo> plugin
return topLevelDependancies;
}
}
}
}
2 changes: 1 addition & 1 deletion src/KKManager.Core/Data/Zipmods/SideloaderModInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace KKManager.Data.Zipmods
public class SideloaderModInfo : ModInfoBase
{
public SideloaderModInfo(FileInfo location, Manifest manifest, List<Func<Image>> images, IReadOnlyList<string> contents)
: base(location, manifest.GUID, manifest.Name, manifest.Version, manifest.Author, manifest.Description, manifest.Website)
: base(location, manifest.GUID, manifest.Name, manifest.Version, manifest.Author, manifest.Description, manifest.Website, manifest.Games)
{
var extension = location.Extension;
if (!SideloaderModLoader.IsValidZipmodExtension(extension))
Expand Down
1 change: 1 addition & 0 deletions src/KKManager.Core/KKManager.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
<Compile Include="Data\ModInfoBase.cs" />
<Compile Include="Data\Plugins\PluginInfo.cs" />
<Compile Include="Data\Plugins\PluginLoader.cs" />
<Compile Include="Util\TypeConverters\ReadOnlyStringCollectionConverterWithPreview.cs" />
<Compile Include="Data\Zipmods\Manifest.cs" />
<Compile Include="Data\Zipmods\MigrationInfo.cs" />
<Compile Include="Data\Zipmods\MigrationType.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;

namespace KKManager.Data
{
public class ReadOnlyStringCollectionConverterWithPreview : CollectionConverter
{
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == null)
throw new ArgumentNullException(nameof(destinationType));

var arr = value as IReadOnlyCollection<string>;
var arr2 = value as ICollection<string>;
if (arr != null || arr2 != null)
{
var count = arr?.Count ?? arr2.Count;
var result = $"{count} items";
if (count > 0)
{
result += $" - {string.Join(", ", ((IEnumerable<string>)arr ?? arr2).Take(3))}";
if (count > 3)
result += "...";
}

return result;
}

return base.ConvertTo(context, culture, value, destinationType);
}

public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
{
PropertyDescriptor[] properties = null;

var arr = value as IReadOnlyCollection<string>;
var arr2 = value as ICollection<string>;
if (arr != null || arr2 != null)
{
var count = arr?.Count ?? arr2.Count;

properties = new PropertyDescriptor[count];
for (int index = 0; index < count; ++index)
properties[index] = new StringCollectionPropertyDescriptor(value.GetType(), index);
}
return new PropertyDescriptorCollection(properties);
}

/// <summary>Gets a value indicating whether this object supports properties.</summary>
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
/// <returns>
/// <see langword="true" /> because <see cref="M:System.ComponentModel.ArrayConverter.GetProperties(System.ComponentModel.ITypeDescriptorContext,System.Object,System.Attribute[])" /> should be called to find the properties of this object. This method never returns <see langword="false" />.</returns>
public override bool GetPropertiesSupported(ITypeDescriptorContext context) => true;

private class StringCollectionPropertyDescriptor : TypeConverter.SimplePropertyDescriptor
{
private int index;

public StringCollectionPropertyDescriptor(Type arrayType, int index)
: base(arrayType, "[" + index.ToString() + "]", typeof(string), null)
{
this.index = index;
}

public override object GetValue(object instance)
{
var arr = instance as IReadOnlyCollection<string>;
var arr2 = instance as ICollection<string>;
if (arr != null || arr2 != null)
{
var count = arr?.Count ?? arr2.Count;

if (count > this.index)
return arr.Skip(index).First();
}
return null;
}

public override void SetValue(object instance, object value)
{
}
}
}
}
3 changes: 3 additions & 0 deletions src/KKManager/KKManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
</EmbeddedResource>
<EmbeddedResource Include="Windows\Content\CardWindow.resx">
<DependentUpon>CardWindow.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Windows\Content\CardWindow.ru.resx">
<DependentUpon>CardWindow.cs</DependentUpon>
Expand Down Expand Up @@ -388,9 +389,11 @@
</EmbeddedResource>
<EmbeddedResource Include="Windows\Content\PluginsWindow.resx">
<DependentUpon>PluginsWindow.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Windows\Content\SideloaderModsWindow.resx">
<DependentUpon>SideloaderModsWindow.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Windows\MainWindow.ru.resx">
<DependentUpon>MainWindow.cs</DependentUpon>
Expand Down
25 changes: 17 additions & 8 deletions src/KKManager/Windows/Content/PluginsWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/KKManager/Windows/Content/PluginsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading;
using System.Windows.Forms;
using BrightIdeasSoftware;
using KKManager.Data;
using KKManager.Data.Plugins;
using KKManager.Functions;
using KKManager.Util;
Expand All @@ -34,6 +35,8 @@ public PluginsWindow()

objectListView1.PrimarySortColumn = olvColumnName;

olvColumnGames.AspectGetter = x => string.Join(", ", ((ModInfoBase)x)?.Games.Distinct().OrderBy(z => z) ?? Enumerable.Empty<string>());

ListTools.SetUpSearchBox(objectListView1, toolStripTextBoxSearch);
}

Expand Down
Loading
Loading