Skip to content

Commit

Permalink
Merge pull request #1831 from erri120/feat/1763-download-types
Browse files Browse the repository at this point in the history
Cleanup and download types
  • Loading branch information
erri120 committed Jul 31, 2024
2 parents 8847c94 + 22aa9ac commit 6a9cee9
Show file tree
Hide file tree
Showing 35 changed files with 87 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public static LoadoutFile.New ToLoadoutFile(
LoadoutItem = new LoadoutItem.New(tx, id)
{
LoadoutId = loadoutId,
IsIsDisabledMarker = false,
Name = input.Item.Value.FileName,
ParentId = parent,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using JetBrains.Annotations;
using NexusMods.Abstractions.MnemonicDB.Attributes;
using NexusMods.MnemonicDB.Abstractions.Models;

namespace NexusMods.Abstractions.Library.Models;

/// <summary>
/// Represents a downloaded file in the file.
/// </summary>
[PublicAPI]
[Include<LibraryFile>]
public partial class DownloadedFile : IModelDefinition
{
private const string Namespace = "NexusMods.Library.DownloadedFile";

/// <summary>
/// URI to the download page, not the direct download link.
/// </summary>
/// <remarks>
/// Many direct download links aren't permalinks. Those shouldn't be stored.
/// Instead, this is the link to the page from which the download was initiated.
/// </remarks>
/// <example>
/// https://www.nexusmods.com/skyrim/mods/3863
/// </example>
public static readonly UriAttribute DownloadPageUri = new(Namespace, nameof(DownloadPageUri));
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class LibraryArchive : IModelDefinition
/// <summary>
/// Marker.
/// </summary>
public static readonly MarkerAttribute IsLibraryArchiveMarker = new(Namespace, nameof(IsLibraryArchiveMarker));
public static readonly MarkerAttribute Archive = new(Namespace, nameof(Archive));

/// <summary>
/// Back-reference to all files inside the archive.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
<Compile Update="LibraryArchiveTree.cs">
<DependentUpon>LibraryArchive.cs</DependentUpon>
</Compile>
<Compile Update="DownloadedFile.cs">
<DependentUpon>LibraryItem.cs</DependentUpon>
</Compile>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static IServiceCollection AddLibraryModels(this IServiceCollection servic
return serviceCollection
.AddLibraryItemModel()
.AddLibraryFileModel()
.AddDownloadedFileModel()
.AddLocalFileModel()
.AddLibraryArchiveModel()
.AddLibraryArchiveFileEntryModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected LoadoutOverridesGroupId GetOrCreateOverridesGroup(ITransaction tx, Loa
OverridesForId = loadout,
LoadoutItemGroup = new LoadoutItemGroup.New(tx, id)
{
IsIsLoadoutItemGroupMarker = true,
IsGroup = true,
LoadoutItem = new LoadoutItem.New(tx, id)
{
Name = "Overrides",
Expand Down Expand Up @@ -225,7 +225,7 @@ public SyncTree BuildSyncTree(DiskStateTree currentState, DiskStateTree previous
/// </summary>
private static bool FileIsEnabled(LoadoutItem.ReadOnly arg)
{
return !arg.GetThisAndParents().Any(f => f.Contains(LoadoutItem.IsDisabledMarker));
return !arg.GetThisAndParents().Any(f => f.Contains(LoadoutItem.Disabled));
}

/// <inheritdoc />
Expand Down Expand Up @@ -381,7 +381,7 @@ private void WarnOfUnableToExtract(SyncActionGroupings<SyncTreeNode> groupings)
{
var delete = new DeletedFile.New(tx, out var id)
{
IsIsDeletedFileMarker = true,
Reason = "Reified delete",
LoadoutItemWithTargetPath = new LoadoutItemWithTargetPath.New(tx, id)
{
TargetPath = item.Path,
Expand Down Expand Up @@ -800,7 +800,7 @@ private LoadoutGameFilesGroup.New CreateLoadoutGameFilesGroup(LoadoutId loadout,
GameMetadataId = installation.GameMetadataId,
LoadoutItemGroup = new LoadoutItemGroup.New(tx, id)
{
IsIsLoadoutItemGroupMarker = true,
IsGroup = true,
LoadoutItem = new LoadoutItem.New(tx, id)
{
Name = "Game Files",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public partial class DeletedFile : IModelDefinition
private const string Namespace = "NexusMods.Loadouts.DeletedFile";

/// <summary>
/// Marker.
/// Reason.
/// </summary>
public static readonly MarkerAttribute IsDeletedFileMarker = new(Namespace, nameof(IsDeletedFileMarker));
public static readonly StringAttribute Reason = new(Namespace, nameof(Reason));
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ public static class LoadoutExtensions
{
public static IEnumerable<LoadoutItemGroup.ReadOnly> GetEnabledGroups(this Loadout.ReadOnly loadout)
{
return loadout.Items.OfTypeLoadoutItemGroup().Where(group => !group.AsLoadoutItem().IsIsDisabledMarker);
return loadout.Items.OfTypeLoadoutItemGroup().Where(group => !group.AsLoadoutItem().IsDisabled);
}



private static IEnumerable<Mod.ReadOnly> GetEnabledMods(this Loadout.ReadOnly loadout, bool onlyEnabledMods)
{
var enumerable = onlyEnabledMods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public static class LoadoutItemExtensions
/// </summary>
public static bool IsEnabled(this LoadoutItem.ReadOnly item)
{
return !item.GetThisAndParents().Any(i => i.IsIsDisabledMarker);
return !item.GetThisAndParents().Any(i => i.IsDisabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class LoadoutItem : IModelDefinition
/// <remarks>
/// The exact meaning of a "disabled" loadout item is up to the implementations.
/// </remarks>
public static readonly MarkerAttribute IsDisabledMarker = new(Namespace, nameof(IsDisabledMarker));
public static readonly MarkerAttribute Disabled = new(Namespace, nameof(Disabled));

/// <summary>
/// Loadout that contains the item.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class LoadoutItemGroup : IModelDefinition
/// <summary>
/// Marker.
/// </summary>
public static readonly MarkerAttribute IsLoadoutItemGroupMarker = new(Namespace, nameof(IsLoadoutItemGroupMarker));
public static readonly MarkerAttribute Group = new(Namespace, nameof(Group));

/// <summary>
/// Children of the group.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
namespace NexusMods.Abstractions.NexusModsLibrary;

/// <summary>
/// Represented a <see cref="LibraryFile"/> originating from Nexus Mods.
/// Represented a <see cref="DownloadedFile"/> originating from Nexus Mods.
/// </summary>
[PublicAPI]
[Include<LibraryFile>]
[Include<DownloadedFile>]
public partial class NexusModsLibraryFile : IModelDefinition
{
private const string Namespace = "NexusMods.Library.NexusModsLibraryFile";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,14 @@ public override async ValueTask<InstallerResult> ExecuteAsync(
var loadoutItem = new LoadoutItem.New(tx)
{
LoadoutId = loadout.Id,
IsIsDisabledMarker = false,
Name = infoJson.Name,
ParentId = loadoutGroup.Id,
};

var groupItem = new LoadoutItemGroup.New(tx, loadoutItem.Id)
{
LoadoutItem = loadoutItem,
IsIsLoadoutItemGroupMarker = true,
IsGroup = true,
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public override ValueTask<InstallerResult> ExecuteAsync(
Name = relativePath.Name,
LoadoutId = loadout.Id,
ParentId = loadoutGroup.Id,
IsIsDisabledMarker = false,
},
},
Hash = file.Item.LibraryFile.Value.Hash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static IEnumerable<Diagnostic> DiagnoseDisabledDependencies(
.Where(kv =>
{
var (loadoutItemId, _) = kv;
return !SMAPIModLoadoutItem.Load(loadout.Db, loadoutItemId).AsLoadoutItemGroup().AsLoadoutItem().IsIsDisabledMarker;
return !SMAPIModLoadoutItem.Load(loadout.Db, loadoutItemId).AsLoadoutItemGroup().AsLoadoutItem().IsDisabled;
})
.Select(kv =>
{
Expand All @@ -87,7 +87,7 @@ private static IEnumerable<Diagnostic> DiagnoseDisabledDependencies(
var disabledDependencies = requiredDependencies
.Select(uniqueIdToLoadoutItemId.GetValueOrDefault)
.Where(id => id != default(SMAPIModLoadoutItemId))
.Where(id => !SMAPIModLoadoutItem.Load(loadout.Db, id).AsLoadoutItemGroup().AsLoadoutItem().IsIsDisabledMarker)
.Where(id => !SMAPIModLoadoutItem.Load(loadout.Db, id).AsLoadoutItemGroup().AsLoadoutItem().IsDisabled)
.ToArray();
return (Id: loadoutItemId, DisabledDependencies: disabledDependencies);
Expand Down Expand Up @@ -118,7 +118,7 @@ private async Task<IEnumerable<Diagnostic>> DiagnoseMissingDependencies(
.Where(kv =>
{
var (loadoutItemId, _) = kv;
return !SMAPIModLoadoutItem.Load(loadout.Db, loadoutItemId).AsLoadoutItemGroup().AsLoadoutItem().IsIsDisabledMarker;
return !SMAPIModLoadoutItem.Load(loadout.Db, loadoutItemId).AsLoadoutItemGroup().AsLoadoutItem().IsDisabled;
})
.Select(kv =>
{
Expand Down
4 changes: 2 additions & 2 deletions src/Games/NexusMods.Games.StardewValley/Emitters/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static bool TryGetSMAPI(Loadout.ReadOnly loadout, out SMAPILoadoutItem.Re
var foundSMAPI = loadout.Items
.OfTypeLoadoutItemGroup()
.OfTypeSMAPILoadoutItem()
.TryGetFirst(x => !x.AsLoadoutItemGroup().AsLoadoutItem().IsIsDisabledMarker, out smapi);
.TryGetFirst(x => !x.AsLoadoutItemGroup().AsLoadoutItem().IsDisabled, out smapi);

return foundSMAPI;
}
Expand All @@ -36,7 +36,7 @@ public static bool TryGetSMAPI(Loadout.ReadOnly loadout, out SMAPILoadoutItem.Re
var asyncEnumerable = loadout.Items
.OfTypeLoadoutItemGroup()
.OfTypeSMAPIModLoadoutItem()
.Where(x => !onlyEnabledMods || !x.AsLoadoutItemGroup().AsLoadoutItem().IsIsDisabledMarker)
.Where(x => !onlyEnabledMods || !x.AsLoadoutItemGroup().AsLoadoutItem().IsDisabled)
.ToAsyncEnumerable()
.ConfigureAwait(continueOnCapturedContext: false)
.WithCancellation(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async IAsyncEnumerable<Diagnostic> Diagnose(
yield break;
}

var isSMAPIEnabled = smapiLoadoutItems.Any(x => !x.AsLoadoutItemGroup().AsLoadoutItem().IsIsDisabledMarker);
var isSMAPIEnabled = smapiLoadoutItems.Any(x => !x.AsLoadoutItemGroup().AsLoadoutItem().IsDisabled);
if (isSMAPIEnabled) yield break;

yield return Diagnostics.CreateSMAPIRequiredButDisabled(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public override async ValueTask<InstallerResult> ExecuteAsync(
{
_ = new SMAPIModDatabaseLoadoutFile.New(transaction, entityId)
{
IsIsModDatabaseFileMarker = true,
IsModDatabaseFile = true,
LoadoutFile = loadoutFile,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public override async ValueTask<InstallerResult> ExecuteAsync(

var smapiModGroup = new LoadoutItemGroup.New(transaction, out var smapiModEntityId)
{
IsIsLoadoutItemGroupMarker = true,
IsGroup = true,
LoadoutItem = new LoadoutItem.New(transaction, smapiModEntityId)
{
Name = manifest.Name,
Expand Down Expand Up @@ -153,7 +153,7 @@ public override async ValueTask<InstallerResult> ExecuteAsync(
manifestLoadoutItemId = entityId;
_ = new SMAPIManifestLoadoutFile.New(transaction, entityId)
{
IsIsManifestMarker = true,
IsManifestFile = true,
LoadoutFile = loadoutFile,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public partial class SMAPIManifestLoadoutFile : IModelDefinition
{
private const string Namespace = "NexusMods.StardewValley.SMAPIManifestLoadoutFile";

public static readonly MarkerAttribute IsManifestMarker = new(Namespace, nameof(IsManifestMarker));
public static readonly MarkerAttribute ManifestFile = new(Namespace, nameof(ManifestFile));
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public partial class SMAPIModDatabaseLoadoutFile : IModelDefinition
{
private const string Namespace = "NexusMods.StardewValley.SMAPIModDatabaseLoadoutFile";

public static readonly MarkerAttribute IsModDatabaseFileMarker = new(Namespace, nameof(IsModDatabaseFileMarker));
public static readonly MarkerAttribute ModDatabaseFile = new(Namespace, nameof(ModDatabaseFile));
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private static bool TryGetSMAPIMod(RelativePath modDirectoryName, Loadout.ReadOn
var manifestFilePath = new GamePath(LocationId.Game, Constants.ModsFolder.Join(modDirectoryName).Join(Constants.ManifestFile));

if (!LoadoutItemWithTargetPath.FindByTargetPath(db, manifestFilePath)
.TryGetFirst(x => x.AsLoadoutItem().LoadoutId == loadout && x.Contains(SMAPIManifestLoadoutFile.IsManifestMarker), out var file))
.TryGetFirst(x => x.AsLoadoutItem().LoadoutId == loadout && x.Contains(SMAPIManifestLoadoutFile.ManifestFile), out var file))
{
mod = default(SMAPIModLoadoutItem.ReadOnly);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace NexusMods.Networking.Downloaders.Tasks.State;
/// might not need it since it uses another strategy to start a mod download.
/// </remarks>
// ReSharper disable once PartialTypeWithSinglePart
[Obsolete("To be replaced by jobs")]
public partial class DownloaderState : IModelDefinition
{
private const string Namespace = "NexusMods.Networking.Downloaders.Tasks.DownloaderState";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace NexusMods.Networking.Downloaders.Tasks.State;
/// </summary>
// ReSharper disable once PartialTypeWithSinglePart
[Include<DownloaderState>]
[Obsolete("To be replaced by jobs")]
public partial class HttpDownloadState : IModelDefinition
{
private const string Namespace = "NexusMods.Networking.Downloaders.Tasks.State.HttpDownloadState";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace NexusMods.Networking.Downloaders.Tasks.State;

[Obsolete("To be replaced by jobs")]
[Include<DownloaderState>]
public partial class NxmDownloadState : IModelDefinition
{
Expand Down
3 changes: 1 addition & 2 deletions src/NexusMods.App.UI/Filters/LibraryUserFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public static bool ShouldShow(LibraryItem.ReadOnly libraryItem)
if (!libraryItem.TryGetAsLibraryFile(out var file))
return false;

// TODO: also show downloads
return file.IsLocalFile();
return file.IsLocalFile() || file.IsDownloadedFile();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ModEnabledViewModel(IConnection conn)
this.WhenAnyValue(vm => vm.Row)
.Select(groupId => LoadoutItemGroup.Observe(_connection, groupId))
.Switch()
.Select(group => !group.AsLoadoutItem().IsIsDisabledMarker)
.Select(group => !group.AsLoadoutItem().IsDisabled)
.BindToVM(this, vm => vm.Enabled)
.DisposeWith(d);
});
Expand All @@ -42,13 +42,13 @@ public ModEnabledViewModel(IConnection conn)
tx.Add(Row.Value, static (txInner, db, id) =>
{
var item = LoadoutItem.Load(db, id);
if (item.IsIsDisabledMarker)
if (item.IsDisabled)
{
txInner.Retract(item.Id, LoadoutItem.IsDisabledMarker, Null.Instance);
txInner.Retract(item.Id, LoadoutItem.Disabled, Null.Instance);
}
else
{
txInner.Add(item.Id, LoadoutItem.IsDisabledMarker, Null.Instance);
txInner.Add(item.Id, LoadoutItem.Disabled, Null.Instance);
}
});
Expand All @@ -62,6 +62,6 @@ public int Compare(LoadoutItemGroupId a, LoadoutItemGroupId b)
var db = _connection.Db;
var aEnt = LoadoutItemGroup.Load(db, a);
var bEnt = LoadoutItemGroup.Load(db, b);
return aEnt.AsLoadoutItem().IsIsDisabledMarker.CompareTo(bEnt.AsLoadoutItem().IsIsDisabledMarker);
return aEnt.AsLoadoutItem().IsDisabled.CompareTo(bEnt.AsLoadoutItem().IsDisabled);
}
}
2 changes: 1 addition & 1 deletion src/NexusMods.Library/AddLibraryFileJobWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected override async Task<JobResult> ExecuteAsync(AddLibraryFileJob job, Can
job.LibraryArchive = new LibraryArchive.New(job.Transaction, job.EntityId.Value)
{
LibraryFile = job.LibraryFile.Value,
IsIsLibraryArchiveMarker = true,
IsArchive = true,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/NexusMods.Library/InstallLoadoutItemJobWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected override async Task<JobResult> ExecuteAsync(InstallLoadoutItemJob job,
var transaction = job.Connection.BeginTransaction();
var loadoutGroup = new LoadoutItemGroup.New(transaction, out var groupId)
{
IsIsLoadoutItemGroupMarker = true,
IsGroup = true,
LoadoutItem = new LoadoutItem.New(transaction, groupId)
{
Name = job.LibraryItem.Name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public async Task PathBasedDiagnosticEmittersLookAtTheCorrectPaths(Type diagnost
{
var dependencyMod = LoadoutItemGroup.Load(Connection.Db, loadout.Items.First(m => m.Name == "DependencyMod").Id);
using var tx = Connection.BeginTransaction();
tx.Add(dependencyMod, LoadoutItem.IsDisabledMarker, Null.Instance);
tx.Add(dependencyMod, LoadoutItem.Disabled, Null.Instance);
await tx.Commit();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
+ | 0200000000000000 | Timestamp | DateTime : 0 | 0200000000000000
+ | 0200000000000001 | Name | one_mod.7z | 0200000000000000
+ | 0200000000000001 | Loadout | 0200000000000002 | 0200000000000000
+ | 0200000000000001 | IsLoadoutItemGroupMarker | Null | 0200000000000000
+ | 0200000000000001 | Group | Null | 0200000000000000
+ | 0200000000000003 | RedModInfoFile | 0200000000000004 | 0200000000000000
+ | 0200000000000003 | Name | Driver_Shotgun | 0200000000000000
+ | 0200000000000003 | Loadout | 0200000000000002 | 0200000000000000
+ | 0200000000000003 | Parent | 0200000000000001 | 0200000000000000
+ | 0200000000000003 | IsLoadoutItemGroupMarker | Null | 0200000000000000
+ | 0200000000000003 | Group | Null | 0200000000000000
+ | 0200000000000004 | Name | Driver_Shotgun | 0200000000000000
+ | 0200000000000004 | Version | 1.0.0 | 0200000000000000
+ | 0200000000000004 | Name | info.json | 0200000000000000
Expand Down
Loading

0 comments on commit 6a9cee9

Please sign in to comment.