-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1799 from Nexus-Mods/update-cyberpunk-installers
Update cyberpunk installers to new LoadoutItem format
- Loading branch information
Showing
34 changed files
with
3,318 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
src/Abstractions/NexusMods.Abstractions.Library.Models/LibraryArchiveTree.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
using DynamicData.Kernel; | ||
using NexusMods.Paths; | ||
using NexusMods.Paths.Trees; | ||
using NexusMods.Paths.Trees.Traits; | ||
|
||
namespace NexusMods.Abstractions.Library.Models; | ||
using LibraryArchiveTreeNode = NexusMods.Paths.Trees.KeyedBox<NexusMods.Paths.RelativePath, LibraryArchiveTree>; | ||
|
||
/// <summary> | ||
/// Represents a tree of files sourced from a downloaded mod. | ||
/// </summary> | ||
/// <remarks> | ||
/// See this for reference https://github.com/Nexus-Mods/NexusMods.Paths/blob/main/docs/Trees/Introduction.md | ||
/// </remarks> | ||
public struct LibraryArchiveTree : | ||
IHaveBoxedChildrenWithKey<RelativePath, LibraryArchiveTree>, // basic functionality | ||
IHaveAFileOrDirectory, // for uses which want to distinguish file/directory | ||
IHaveParent<LibraryArchiveTree>, // optimized FindSubPathsByKeyUpward | ||
IHaveDepthInformation, // Depth info is used by some installers, and it's zero-cost to include, thanks to leftover padding space | ||
IHavePathSegment, // optimized path segment based operations | ||
IHaveKey<RelativePath>, | ||
IHaveValue<LibraryArchiveTree> | ||
{ | ||
/// <inheritdoc /> | ||
public Box<LibraryArchiveTree>? Parent { get; private set; } // 0 | ||
|
||
/// <inheritdoc /> | ||
public Dictionary<RelativePath, LibraryArchiveTreeNode> Children { get; private set; } // 8 | ||
|
||
/// <inheritdoc /> | ||
public ushort Depth { get; private set; } // 17 | ||
|
||
/// <summary> | ||
/// True if this node represents a file. | ||
/// </summary> | ||
public bool IsFile => LibraryFile.HasValue; | ||
|
||
/// <inheritdoc /> | ||
public RelativePath Segment { get; init; } // 24 | ||
|
||
/// <summary> | ||
/// The library file, this node represents. | ||
/// </summary> | ||
public Optional<LibraryFile.ReadOnly> LibraryFile { get; init; } | ||
|
||
/// <summary> | ||
/// The complete path of the file or directory. | ||
/// </summary> | ||
public RelativePath Path => this.ReconstructPath(); | ||
|
||
/// <summary> | ||
/// The name file or directory in this node. | ||
/// </summary> | ||
public RelativePath FileName => Segment; | ||
|
||
// Interface Redirects | ||
/// <inheritdoc /> | ||
public RelativePath Key => Segment; | ||
|
||
/// <inheritdoc /> | ||
public LibraryArchiveTree Value => this; | ||
|
||
/// <summary> | ||
/// Creates the tree! From the source entries. | ||
/// </summary> | ||
public static LibraryArchiveTreeNode Create(LibraryArchive.ReadOnly archive) | ||
{ | ||
// Unboxed root node. | ||
var root = CreateDirectoryNode(RelativePath.Empty, 0); | ||
|
||
// Add each entry to the tree. | ||
foreach (var entry in archive.Children) | ||
{ | ||
var libraryFile = entry.AsLibraryFile(); | ||
var current = root; | ||
var parts = entry.Path.GetParts(); | ||
|
||
for (var x = 0; x < parts.Length; x++) | ||
{ | ||
var segment = parts[x]; | ||
var isFile = x == parts.Length - 1; | ||
|
||
// Try get child for this segment. | ||
if (!current.Item.Children.TryGetValue(segment, out var child)) | ||
{ | ||
var depth = (ushort)(x + 1); | ||
child = isFile ? CreateFileNode(segment, libraryFile, depth, current) : CreateDirectoryNode(segment, depth, current); | ||
current.Item.Children.Add(segment, child); | ||
} | ||
|
||
current = child; | ||
} | ||
} | ||
|
||
return root; | ||
} | ||
|
||
private static LibraryArchiveTreeNode CreateDirectoryNode(RelativePath segmentName, ushort depth, Box<LibraryArchiveTree>? parent = null) | ||
=> CreateFileNode(segmentName, Optional<LibraryFile.ReadOnly>.None, depth, parent); | ||
|
||
private static LibraryArchiveTreeNode CreateFileNode(RelativePath segmentName, Optional<LibraryFile.ReadOnly> libraryFile, ushort depth, Box<LibraryArchiveTree>? parent) | ||
{ | ||
return new LibraryArchiveTreeNode | ||
{ | ||
Item = new LibraryArchiveTree | ||
{ | ||
Segment = segmentName, | ||
Children = new Dictionary<RelativePath, LibraryArchiveTreeNode>(), | ||
Parent = parent, | ||
LibraryFile = libraryFile, | ||
Depth = depth, | ||
}, | ||
}; | ||
} | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Converters and extensions for <see cref="LibraryArchiveTree"/>. | ||
/// </summary> | ||
public static class LibraryArchiveTreeExtensions | ||
{ | ||
/// <summary> | ||
/// Organize the children of this node into a tree based on their paths. | ||
/// </summary> | ||
public static LibraryArchiveTreeNode GetTree(this LibraryArchive.ReadOnly archive) | ||
=> LibraryArchiveTree.Create(archive); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Games/NexusMods.Games.RedEngine/Cyberpunk2077/Models/RedModInfoFile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using NexusMods.Abstractions.Library.Models; | ||
using NexusMods.Abstractions.Loadouts; | ||
using NexusMods.MnemonicDB.Abstractions.Attributes; | ||
using NexusMods.MnemonicDB.Abstractions.Models; | ||
|
||
namespace NexusMods.Games.RedEngine.Cyberpunk2077.Models; | ||
|
||
|
||
[Include<LoadoutFile>] | ||
public partial class RedModInfoFile : IModelDefinition | ||
{ | ||
private static string Namespace => "NexusMods.Games.RedEngine.Cyberpunk2077.RedModInfoFile"; | ||
|
||
/// <summary> | ||
/// The internal name of the mod | ||
/// </summary> | ||
public static readonly StringAttribute Name = new(Namespace, nameof(Name)); | ||
|
||
/// <summary> | ||
/// The internal version of the mod | ||
/// </summary> | ||
public static readonly StringAttribute Version = new(Namespace, nameof(Version)); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Games/NexusMods.Games.RedEngine/Cyberpunk2077/Models/RedModLoadoutGroup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using NexusMods.Abstractions.Library.Models; | ||
using NexusMods.Abstractions.Loadouts; | ||
using NexusMods.MnemonicDB.Abstractions.Attributes; | ||
using NexusMods.MnemonicDB.Abstractions.Models; | ||
|
||
namespace NexusMods.Games.RedEngine.Cyberpunk2077.Models; | ||
|
||
[Include<LoadoutItemGroup>] | ||
public partial class RedModLoadoutGroup : IModelDefinition | ||
{ | ||
private const string Namespace = "NexusMods.Games.RedEngine.Cyberpunk2077.RedModLoadoutGroup"; | ||
|
||
/// <summary> | ||
/// The info.json file for this RedMod | ||
/// </summary> | ||
public static readonly ReferenceAttribute<RedModInfoFile> RedModInfoFile = new(Namespace, nameof(RedModInfoFile)); | ||
} | ||
|
47 changes: 0 additions & 47 deletions
47
src/Games/NexusMods.Games.RedEngine/ModInstallers/AppearancePreset.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.