wabbajack/Wabbajack.Server/DataLayer/ValidationData.cs

56 lines
2.0 KiB
C#
Raw Normal View History

2020-05-14 22:21:56 +00:00
using System;
using System.Collections.Generic;
2020-05-13 21:52:34 +00:00
using System.Linq;
using System.Threading.Tasks;
using Dapper;
2021-09-27 12:42:46 +00:00
using Wabbajack.DTOs;
using Wabbajack.Hashing.xxHash64;
2020-05-13 21:52:34 +00:00
using Wabbajack.Server.DTOs;
2021-10-23 16:51:17 +00:00
namespace Wabbajack.Server.DataLayer;
public partial class SqlService
2020-05-13 21:52:34 +00:00
{
2021-10-23 16:51:17 +00:00
public async Task<ValidationData> GetValidationData()
2020-05-13 21:52:34 +00:00
{
2021-10-23 16:51:17 +00:00
var archiveStatus = AllModListArchivesStatus();
var modLists = AllModLists();
var mirrors = GetAllMirroredHashes();
var authoredFiles = AllAuthoredFiles();
var nexusFiles = await AllNexusFiles();
return new ValidationData
2020-05-13 21:52:34 +00:00
{
2021-10-23 16:51:17 +00:00
NexusFiles = nexusFiles.ToDictionary(nf => (nf.NexusGameId, nf.ModId, nf.FileId), nf => nf.category),
ArchiveStatus = await archiveStatus,
ModLists = await modLists,
Mirrors = await mirrors,
AllowedMirrors = new Lazy<Task<Dictionary<Hash, string>>>(async () => await GetAllowedMirrors()),
AllAuthoredFiles = await authoredFiles
};
}
2021-10-23 16:51:17 +00:00
public async Task<Dictionary<(string PrimaryKeyString, Hash Hash), bool>> AllModListArchivesStatus()
{
await using var conn = await Open();
var results =
await conn.QueryAsync<(string, Hash, bool)>(
@"SELECT PrimaryKeyString, Hash, IsValid FROM dbo.ModListArchiveStatus");
return results.ToDictionary(v => (v.Item1, v.Item2), v => v.Item3);
}
2020-05-13 21:52:34 +00:00
2021-10-23 16:51:17 +00:00
public async Task<HashSet<(long NexusGameId, long ModId, long FileId, string category)>> AllNexusFiles()
{
await using var conn = await Open();
var results =
await conn.QueryAsync<(long, long, long, string)>(
@"SELECT Game, ModId, FileId, JSON_VALUE(Data, '$.category_name') FROM dbo.NexusModFile");
return results.ToHashSet();
}
public async Task<List<ModlistMetadata>> AllModLists()
{
await using var conn = await Open();
var results = await conn.QueryAsync<ModlistMetadata>(@"SELECT Metadata FROM dbo.ModLists");
return results.ToList();
2020-05-13 21:52:34 +00:00
}
2021-10-23 16:51:17 +00:00
}