Full path of files should now work

This commit is contained in:
Timothy Baldridge 2021-07-19 23:08:12 -06:00
parent c9b96abd8c
commit bb33dea03a
16 changed files with 153 additions and 29 deletions

View File

@ -14,6 +14,8 @@ using Org.BouncyCastle.Asn1.Cms;
using Wabbajack.Common;
using Wabbajack.Lib.CompilationSteps;
using Wabbajack.Lib.Downloaders;
using Wabbajack.Lib.FileUploader;
using Wabbajack.Lib.GitHub;
using Wabbajack.Lib.ModListRegistry;
using Wabbajack.VirtualFileSystem;
@ -34,9 +36,10 @@ namespace Wabbajack.Lib
public string? ModListName, ModListAuthor, ModListDescription, ModListWebsite, ModlistReadme;
public Version? ModlistVersion;
protected Version? WabbajackVersion;
public UpdateRequest? PublishData;
public ACompiler(int steps, string modlistName, AbsolutePath sourcePath, AbsolutePath downloadsPath,
AbsolutePath outputModListName)
AbsolutePath outputModListName, UpdateRequest? publishData)
: base(steps)
{
SourcePath = sourcePath;
@ -48,8 +51,11 @@ namespace Wabbajack.Lib
Settings = new CompilerSettings();
ModListOutputFolder = AbsolutePath.EntryPoint.Combine("output_folder", Guid.NewGuid().ToString());
CompilingGame = new GameMetaData();
PublishData = publishData;
}
/// <summary>
/// Set to true to include game files during compilation, only ever disabled
/// in testing (to speed up tests)
@ -171,6 +177,35 @@ namespace Wabbajack.Lib
return true;
}
public async Task PreflightChecks()
{
Utils.Log($"Running preflight checks");
if (PublishData == null) return;
var ourLists = await (await AuthorApi.Client.Create()).GetMyModlists();
if (ourLists.All(l => l.MachineURL != PublishData.MachineUrl))
{
Utils.ErrorThrow(new CriticalFailureIntervention(
$"Cannot publish to {PublishData.MachineUrl}, you are not listed as a maintainer",
"Cannot publish"));
}
}
public async Task PublishModlist()
{
if (PublishData == null) return;
var api = await AuthorApi.Client.Create();
Utils.Log($"Uploading modlist {PublishData!.MachineUrl}");
var metadata = ((AbsolutePath)(ModListOutputFile + ".meta.json")).FromJson<DownloadMetadata>();
var uri = await api.UploadFile(Queue, ModListOutputFile, (s, percent) => Utils.Status(s, percent));
PublishData.DownloadUrl = uri;
PublishData.DownloadMetadata = metadata;
Utils.Log($"Publishing modlist {PublishData!.MachineUrl}");
await api.UpdateModListInformation(PublishData);
}
protected async Task IndexGameFileHashes()
{
if (UseGamePaths)

View File

@ -7,6 +7,7 @@ using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Wabbajack.Common;
using Wabbajack.Lib.GitHub;
using Wabbajack.Lib.ModListRegistry;
namespace Wabbajack.Lib.AuthorApi
@ -77,12 +78,12 @@ namespace Wabbajack.Lib.AuthorApi
return definition;
}
public async Task UpdateModListInformation(string machineUrl, DownloadMetadata metadata)
public async Task UpdateModListInformation(UpdateRequest metadata)
{
await CircuitBreaker.WithAutoRetryAllAsync(async () =>
{
Utils.Log($"Updating modlist information for {machineUrl} - {metadata.Version}");
using var result = await _client.PostAsync($"{Consts.WabbajackBuildServerUri}author_controls/{machineUrl}/download_metadata",
Utils.Log($"Updating modlist information for {metadata.MachineUrl} - {metadata.Version}");
using var result = await _client.PostAsync($"{Consts.WabbajackBuildServerUri}author_controls/lists/download_metadata",
new StringContent(metadata.ToJson()));
});
}

View File

@ -56,18 +56,19 @@ namespace Wabbajack.Lib.GitHub
await _client.Repository.Content.UpdateFile("wabbajack-tools", "mod-lists", PathNames[file], updateRequest);
}
public async Task UpdateList(string maintainer, string machineUrl, DownloadMetadata newData)
public async Task UpdateList(string maintainer, UpdateRequest newData)
{
foreach (var file in Enum.GetValues<List>())
{
var data = await GetData(file);
var found = data.Lists.FirstOrDefault(l => l.Links.MachineURL == machineUrl && l.Maintainers.Contains(maintainer));
var found = data.Lists.FirstOrDefault(l => l.Links.MachineURL == newData.MachineUrl && l.Maintainers.Contains(maintainer));
if (found == null) continue;
found.DownloadMetadata = newData;
found.DownloadMetadata = newData.DownloadMetadata;
found.Version = newData.Version;
found.Links.Download = newData.DownloadUrl.ToString();
await WriteData(file, machineUrl, data.Hash, data.Lists);
await WriteData(file, newData.MachineUrl, data.Hash, data.Lists);
return;
}

View File

@ -0,0 +1,15 @@
using System;
using Wabbajack.Common.Serialization.Json;
using Wabbajack.Lib.ModListRegistry;
namespace Wabbajack.Lib.GitHub
{
[JsonName("UpdateRequest")]
public class UpdateRequest
{
public string MachineUrl { get; set; } = "";
public Version? Version { get; set; } = new();
public Uri DownloadUrl { get; set; } = new("https://www.wabbajack.org");
public DownloadMetadata DownloadMetadata { get; set; } = new();
}
}

View File

@ -8,6 +8,7 @@ using Alphaleonis.Win32.Filesystem;
using Wabbajack.Common;
using Wabbajack.Lib.CompilationSteps;
using Wabbajack.Lib.Downloaders;
using Wabbajack.Lib.GitHub;
using Wabbajack.Lib.Validation;
using Wabbajack.VirtualFileSystem;
@ -15,8 +16,8 @@ namespace Wabbajack.Lib
{
public class MO2Compiler : ACompiler
{
public MO2Compiler(AbsolutePath sourcePath, AbsolutePath downloadsPath, string mo2Profile, AbsolutePath outputFile)
: base(21, mo2Profile, sourcePath, downloadsPath, outputFile)
public MO2Compiler(AbsolutePath sourcePath, AbsolutePath downloadsPath, string mo2Profile, AbsolutePath outputFile, UpdateRequest? publishData = null)
: base(23, mo2Profile, sourcePath, downloadsPath, outputFile, publishData)
{
MO2Profile = mo2Profile;
MO2Ini = SourcePath.Combine("ModOrganizer.ini").LoadIniFile();
@ -25,6 +26,7 @@ namespace Wabbajack.Lib
GamePath = CompilingGame.GameLocation();
}
public UpdateRequest? PublishData { get; set; }
public AbsolutePath MO2ModsFolder => SourcePath.Combine(Consts.MO2ModFolderName);
public string MO2Profile { get; }
@ -58,6 +60,10 @@ namespace Wabbajack.Lib
FileExtractor2.FavorPerfOverRAM = FavorPerfOverRam;
UpdateTracker.Reset();
UpdateTracker.NextStep("Running Preflight Checks");
await PreflightChecks();
UpdateTracker.NextStep("Gathering information");
Utils.Log("Loading compiler Settings");
@ -362,6 +368,9 @@ namespace Wabbajack.Lib
UpdateTracker.NextStep("Exporting Modlist");
await ExportModList();
UpdateTracker.NextStep("Publishing Modlist");
await PublishModlist();
ResetMembers();

View File

@ -138,8 +138,6 @@ namespace Wabbajack.Lib.ModListRegistry
{
public Hash Hash { get; set; }
public long Size { get; set; }
public Version Version { get; set; } = new();
public long NumberOfArchives { get; set; }
public long SizeOfArchives { get; set; }
public long NumberOfInstalledFiles { get; set; }

View File

@ -5,6 +5,7 @@ using System.Threading;
using System.Threading.Tasks;
using Wabbajack.Common;
using Wabbajack.Lib.CompilationSteps;
using Wabbajack.Lib.GitHub;
using Wabbajack.Lib.Validation;
using Wabbajack.VirtualFileSystem;
@ -12,8 +13,8 @@ namespace Wabbajack.Lib
{
public class NativeCompiler : ACompiler
{
public NativeCompiler(NativeCompilerSettings settings, AbsolutePath sourcePath, AbsolutePath downloadsPath, AbsolutePath outputModListPath)
: base(3, settings.ModListName, sourcePath, downloadsPath, outputModListPath)
public NativeCompiler(NativeCompilerSettings settings, AbsolutePath sourcePath, AbsolutePath downloadsPath, AbsolutePath outputModListPath, UpdateRequest? publishData = null)
: base(5, settings.ModListName, sourcePath, downloadsPath, outputModListPath, publishData)
{
CompilingGame = settings.CompilingGame.MetaData();
GamePath = CompilingGame.GameLocation();
@ -34,6 +35,10 @@ namespace Wabbajack.Lib
FileExtractor2.FavorPerfOverRAM = FavorPerfOverRam;
UpdateTracker.Reset();
UpdateTracker.NextStep("Running Preflight Checks");
await PreflightChecks();
UpdateTracker.NextStep("Gathering information");
Utils.Log($"Compiling Game: {CompilingGame.Game}");
@ -243,6 +248,9 @@ namespace Wabbajack.Lib
UpdateTracker.NextStep("Exporting Modlist");
await ExportModList();
UpdateTracker.NextStep("Publishing Modlist");
await PublishModlist();
ResetMembers();

View File

@ -16,6 +16,7 @@ using Wabbajack.Common;
using Wabbajack.Lib.GitHub;
using Wabbajack.Lib.ModListRegistry;
using Wabbajack.Server.DataLayer;
using Wabbajack.Server.Services;
namespace Wabbajack.BuildServer.Controllers
{
@ -25,11 +26,13 @@ namespace Wabbajack.BuildServer.Controllers
{
private ILogger<AuthorControls> _logger;
private SqlService _sql;
private readonly QuickSync _quickSync;
public AuthorControls(ILogger<AuthorControls> logger, SqlService sql)
public AuthorControls(ILogger<AuthorControls> logger, SqlService sql, QuickSync quickSync)
{
_logger = logger;
_sql = sql;
_quickSync = quickSync;
}
[Route("login/{authorKey}")]
@ -56,19 +59,21 @@ namespace Wabbajack.BuildServer.Controllers
return Ok(lists);
}
[Route("lists/{machineUrl}/download_metadata")]
[Route("lists/download_metadata")]
[HttpPost]
public async Task<IActionResult> AuthorLists(string machineUrl)
public async Task<IActionResult> PostDownloadMetadata()
{
var user = User.FindFirstValue(ClaimTypes.Name);
var data = (await Request.Body.ReadAllTextAsync()).FromJsonString<DownloadMetadata>();
var data = (await Request.Body.ReadAllTextAsync()).FromJsonString<UpdateRequest>();
var client = await Client.Get();
try
{
await client.UpdateList(user, machineUrl, data);
await client.UpdateList(user, data);
await _quickSync.Notify<ModListDownloader>();
}
catch (Exception ex)
{
_logger.LogError(ex, "During posting of download_metadata");
return BadRequest(ex);
}
return Ok(data);

View File

@ -141,6 +141,7 @@ namespace Wabbajack.BuildServer.Controllers
var definition = await _sql.GetCDNFileDefinition(serverAssignedUniqueId);
if (definition.Author != user)
return Forbid("File Id does not match authorized user");
await _discord.Send(Channel.Ham, new DiscordMessage() {Content = $"{user} is deleting {definition.MungedName}, {definition.Size.ToFileSizeString()} to be freed"});
_logger.Log(LogLevel.Information, $"Finalizing file upload {definition.OriginalFileName}");
await DeleteFolderOrSilentlyFail($"{definition.MungedName}");

View File

@ -24,17 +24,23 @@ namespace Wabbajack.Test
NumberOfInstalledFiles = rnd.Next(1000),
SizeOfInstalledFiles = rnd.Next(1000000),
Size = rnd.Next(10000),
Version = new Version(1, 0, rnd.Next(10), 0)
};
await client.UpdateList("ci_tester", "ci_test", meta);
var update = new UpdateRequest
{
DownloadMetadata = meta,
DownloadUrl = new Uri($"https://www.google.com/{rnd.Next()}"),
MachineUrl = "ci_test",
Version = new Version(1, rnd.Next(10), rnd.Next(10), rnd.Next(10))
};
await client.UpdateList("ci_tester", update);
var updated = await client.GetData(Client.List.CI);
var lst = updated.Lists.FirstOrDefault(l => l.Links.MachineURL == "ci_test");
var newMeta = lst!.DownloadMetadata!;
Assert.Equal(meta.Hash, newMeta.Hash);
Assert.Equal(meta.Size, newMeta.Size);
Assert.Equal(meta.Version, newMeta.Version);
Assert.Equal(lst.Version, newMeta.Version);
Assert.Equal(update.Version, lst.Version);
Assert.Equal(meta.NumberOfArchives, newMeta.NumberOfArchives);
Assert.Equal(meta.NumberOfInstalledFiles, newMeta.NumberOfInstalledFiles);

View File

@ -180,7 +180,10 @@ namespace Wabbajack
public string Website { get; set; }
public string Readme { get; set; }
public bool IsNSFW { get; set; }
public string MachineUrl { get; set; }
public AbsolutePath SplashScreen { get; set; }
public bool Publish { get; set; }
}
[JsonName("MO2CompilationSettings")]

View File

@ -16,6 +16,8 @@ using System.Windows.Media.Imaging;
using Wabbajack.Common;
using Wabbajack.Common.StatusFeed;
using Wabbajack.Lib;
using Wabbajack.Lib.AuthorApi;
using Wabbajack.Lib.FileUploader;
namespace Wabbajack
{
@ -65,11 +67,11 @@ namespace Wabbajack
private readonly ObservableAsPropertyHelper<(int CurrentCPUs, int DesiredCPUs)> _CurrentCpuCount;
public (int CurrentCPUs, int DesiredCPUs) CurrentCpuCount => _CurrentCpuCount.Value;
public CompilerVM(MainWindowVM mainWindowVM) : base(mainWindowVM)
{
MWVM = mainWindowVM;
OutputLocation = new FilePickerVM()
{
ExistCheckOption = FilePickerVM.CheckOptions.IfPathNotEmpty,

View File

@ -2,6 +2,7 @@
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reactive.Disposables;
@ -10,6 +11,9 @@ using System.Threading.Tasks;
using DynamicData;
using Wabbajack.Common;
using Wabbajack.Lib;
using Wabbajack.Lib.AuthorApi;
using Wabbajack.Lib.FileUploader;
using Wabbajack.Lib.GitHub;
using WebSocketSharp;
namespace Wabbajack
@ -34,6 +38,7 @@ namespace Wabbajack
public ACompiler ActiveCompilation { get; private set; }
private readonly ObservableAsPropertyHelper<ModlistSettingsEditorVM> _modlistSettings;
private readonly IObservable<IChangeSet<string>> _authorKeys;
public ModlistSettingsEditorVM ModlistSettings => _modlistSettings.Value;
[Reactive]
@ -201,11 +206,20 @@ namespace Wabbajack
try
{
ACompiler compiler;
UpdateRequest request = null;
if (ModlistSettings.Publish)
{
request = new UpdateRequest
{
MachineUrl = ModlistSettings.MachineUrl.Trim(),
Version = ModlistSettings.Version,
};
}
if (ModListLocation.TargetPath.FileName == Consts.NativeSettingsJson)
{
var settings = ModListLocation.TargetPath.FromJson<NativeCompilerSettings>();
compiler = new NativeCompiler(settings, Mo2Folder, DownloadLocation.TargetPath, outputFile)
compiler = new NativeCompiler(settings, Mo2Folder, DownloadLocation.TargetPath, outputFile, request)
{
ModListName = ModlistSettings.ModListName,
ModListAuthor = ModlistSettings.AuthorText,
@ -219,11 +233,13 @@ namespace Wabbajack
}
else
{
compiler = new MO2Compiler(
sourcePath: Mo2Folder,
downloadsPath: DownloadLocation.TargetPath,
mo2Profile: MOProfile,
outputFile: outputFile)
outputFile: outputFile,
publishData: request)
{
ModListName = ModlistSettings.ModListName,
ModListAuthor = ModlistSettings.AuthorText,

View File

@ -34,6 +34,9 @@ namespace Wabbajack
[Reactive]
public string Readme { get; set; }
[Reactive] public string MachineUrl { get; set; } = "";
[Reactive] public bool Publish { get; set; } = false;
[Reactive]
public string Website { get; set; }
@ -85,6 +88,8 @@ namespace Wabbajack
Website = _settings.Website;
VersionText = _settings.Version;
IsNSFW = _settings.IsNSFW;
MachineUrl = _settings.MachineUrl;
Publish = _settings.Publish;
}
public void Save()
@ -97,6 +102,8 @@ namespace Wabbajack
_settings.SplashScreen = ImagePath.TargetPath;
_settings.Website = Website;
_settings.IsNSFW = IsNSFW;
_settings.MachineUrl = MachineUrl;
_settings.Publish = Publish;
}
}
}

View File

@ -133,6 +133,15 @@
x:Name="NSFWSetting"
Content="NSFW"
ToolTip="Select this if your Modlist has adult themed content such as SexLab or other mods involving sexual acts. Nude body replacer do not fall under this category neither do revealing outfits or gore." />
<CheckBox
x:Name="PublishUpdate"
Content="Publish Update"
ToolTip="Select this if your want Wabbajack to automatically publish this modlist when compilation finished (requires a selected machineURL)" />
<TextBlock
Margin="{StaticResource TitleMargin}"
Text="MachineUrl"
ToolTip="If this box has a value the modlist will be published to this MachineUrl after compilation" />
<TextBox x:Name="MachineUrl" Style="{StaticResource ValueStyle}" />
</StackPanel>
</ScrollViewer>
<Border Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="5"

View File

@ -1,8 +1,10 @@
using System.Reactive.Disposables;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Windows.Controls;
using ReactiveUI;
using System.Windows;
using DynamicData;
using Wabbajack.Common;
namespace Wabbajack
@ -78,7 +80,13 @@ namespace Wabbajack
.DisposeWith(dispose);
this.BindStrict(ViewModel, x => x.CurrentModlistSettings.IsNSFW, x => x.NSFWSetting.IsChecked)
.DisposeWith(dispose);
this.BindStrict(ViewModel, x => x.CurrentModlistSettings.MachineUrl, x => x.MachineUrl.Text)
.DisposeWith(dispose);
this.BindStrict(ViewModel, x => x.CurrentModlistSettings.Publish, x => x.PublishUpdate.IsChecked)
.DisposeWith(dispose);
// Bottom Compiler Settings
this.WhenAny(x => x.ViewModel.StartedCompilation)
.Select(started => started ? Visibility.Hidden : Visibility.Visible)