Skip to content
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
1 change: 1 addition & 0 deletions Knossos.NET/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<Application.Styles>
<StyleInclude Source="/AppStyles.axaml" />
<FluentTheme />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
</Application.Styles>

<Application.Resources>
Expand Down
4 changes: 4 additions & 0 deletions Knossos.NET/Knossos.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<ItemGroup>
<PackageReference Include="AnimatedImage.Avalonia" Version="1.0.7" />
<PackageReference Include="Avalonia" Version="11.0.5" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.5" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.5" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.5" />
Expand All @@ -90,6 +91,9 @@
<Compile Update="Views\DeveloperModsView.axaml.cs">
<DependentUpon>DeveloperModsView.axaml</DependentUpon>
</Compile>
<Compile Update="Views\Windows\DevModAdvancedUploadView.axaml.cs">
<DependentUpon>DevModAdvancedUploadView.axaml</DependentUpon>
</Compile>
<Compile Update="Views\Windows\MessageBox.axaml.cs">
<DependentUpon>MessageBox.axaml</DependentUpon>
</Compile>
Expand Down
13 changes: 13 additions & 0 deletions Knossos.NET/Models/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ public async Task LoadFulLNebulaData()

/// <summary>
/// To use with the List .Sort()
/// Retuns a list that is sort from older to newer
/// </summary>
/// <param name="mod1"></param>
/// <param name="mod2"></param>
Expand All @@ -788,6 +789,18 @@ public static int CompareVersion(Mod mod1, Mod mod2)
return SemanticVersion.Compare(mod1.version, mod2.version);
}

/// <summary>
/// To use with the List .Sort()
/// Retuns a list that is sort from newer to older
/// </summary>
/// <param name="mod1"></param>
/// <param name="mod2"></param>
public static int CompareVersionNewerToOlder(Mod mod1, Mod mod2)
{
//inverted
return SemanticVersion.Compare(mod2.version, mod1.version);
}

/// <summary>
/// Compares two mods and determines if the metadata is different
/// Full data must be loaded on both mods for this to work properly
Expand Down
7 changes: 5 additions & 2 deletions Knossos.NET/ViewModels/TaskViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,10 @@ public async void CreateModVersion(Mod oldMod, string newVersion, Action hackCal
/// <param name="mod"></param>
/// <param name="isNewMod"></param>
/// <param name="metadataonly"></param>
public async void UploadModVersion(Mod mod, bool isNewMod, bool metadataonly = false)
/// <param name="advData"></param>
/// <param name="parallelCompression"></param>
/// <param name="parallelUploads"></param>
public async void UploadModVersion(Mod mod, bool isNewMod, bool metadataonly = false, int parallelCompression = 1, int parallelUploads = 1, List<DevModAdvancedUploadData>? advData = null )
{
using (var cancelSource = new CancellationTokenSource())
{
Expand All @@ -446,7 +449,7 @@ public async void UploadModVersion(Mod mod, bool isNewMod, bool metadataonly = f
TaskList.Add(newTask);
taskQueue.Enqueue(newTask);
});
await newTask.UploadModVersion(mod, isNewMod, metadataonly, cancelSource).ConfigureAwait(false);
await newTask.UploadModVersion(mod, isNewMod, metadataonly, cancelSource, parallelCompression, parallelUploads, advData).ConfigureAwait(false);
}
}

Expand Down
40 changes: 39 additions & 1 deletion Knossos.NET/ViewModels/Templates/DevModVersionsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace Knossos.NET.ViewModels
{
Expand Down Expand Up @@ -217,7 +218,44 @@ public void HackUpdateModList()
Mods = Mods.ToList();
}

internal async void UploadModAdvanced()
{
var mod = editor?.ActiveVersion;
if (mod != null)
{
if (!mod.inNebula)
{
if (mod.type == ModType.mod || mod.type == ModType.tc)
{
var dialog = new DevModAdvancedUploadView();
dialog.DataContext = new DevModAdvancedUploadViewModel(mod, dialog, this);
await dialog.ShowDialog<DevModAdvancedUploadView?>(MainWindow.instance!);
}
else
{
_ = MessageBox.Show(MainWindow.instance!, "Advanced uploading is only available for Mods and TCs.", "Unsupported for type: " + mod.type, MessageBox.MessageBoxButtons.OK);
}
}
else
{
_ = MessageBox.Show(MainWindow.instance!, "This mod version is already uploaded to nebula, if you want to update the metadata use the basic upload", "Mod already uploaded", MessageBox.MessageBoxButtons.OK);
}
}
}

//For UI button
internal async void UploadMod()
{
await UploadProcess();
}

//for the advanced upload window
public void AdvancedUpload(List<DevModAdvancedUploadData> advData, int parallelCompression, int parallelUploads)
{
_ = UploadProcess(advData, parallelCompression, parallelUploads);
}

private async Task UploadProcess(List<DevModAdvancedUploadData>? advData = null, int parallelCompression = 1, int parallelUploads = 1)
{
/*
* Pre-Upload Checks:
Expand Down Expand Up @@ -502,7 +540,7 @@ await MessageBox.Show(MainWindow.instance!, "Your mod depends on mod id: " + dep

//Basic check finish, create task
ButtonsEnabled = true;
TaskViewModel.Instance!.UploadModVersion(mod, isNewMod, metaUpdOnly);
TaskViewModel.Instance!.UploadModVersion(mod, isNewMod, metaUpdOnly, parallelCompression, parallelUploads, advData);
}
}
catch(Exception ex)
Expand Down
69 changes: 58 additions & 11 deletions Knossos.NET/ViewModels/Templates/TaskItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ private async Task<bool> PrepareModPkg(ModPackage pkg, string modFullPath, Cance
}
}

public async Task<bool> UploadModVersion(Mod mod, bool isNewMod, bool metaOnly, CancellationTokenSource? cancelSource = null)
public async Task<bool> UploadModVersion(Mod mod, bool isNewMod, bool metaOnly, CancellationTokenSource? cancelSource = null, int parallelCompression = 1, int parallelUploads = 1, List<DevModAdvancedUploadData>? advData = null )
{
try
{
Expand Down Expand Up @@ -1607,25 +1607,72 @@ public async Task<bool> UploadModVersion(Mod mod, bool isNewMod, bool metaOnly,
Info = "Prepare Packages";
Directory.CreateDirectory(mod.fullPath + Path.DirectorySeparatorChar + "kn_upload");
//Prepare packages, update data on mod
await Parallel.ForEachAsync(mod.packages, new ParallelOptions { MaxDegreeOfParallelism = Knossos.globalSettings.compressionMaxParallelism }, async (pkg, token) =>
await Parallel.ForEachAsync(mod.packages, new ParallelOptions { MaxDegreeOfParallelism = parallelCompression }, async (pkg, token) =>
{
if (mod.type != ModType.mod && mod.type != ModType.tc) //Just to be sure
pkg.isVp = false;
var newTask = new TaskItemViewModel();
await Dispatcher.UIThread.InvokeAsync(() => TaskList.Insert(0, newTask));
await newTask.PrepareModPkg(pkg, mod.fullPath, cancellationTokenSource);
bool skipPkg = false;
//We should skip this?
if(advData != null)
{
var advDataPkg = advData.FirstOrDefault(p => p.packageInNebula != null && p.packageInNebula!.name == pkg.name);
if (advDataPkg != null && !advDataPkg.Upload)
{
var uploadedPkg = advDataPkg.packageInNebula;
if (uploadedPkg != null)
{
pkg.notes = uploadedPkg.notes;
pkg.isVp = uploadedPkg.isVp;
pkg.status = uploadedPkg.status;
pkg.filelist = uploadedPkg.filelist;
pkg.files = uploadedPkg.files;
pkg.dependencies = uploadedPkg.dependencies;
pkg.environment = uploadedPkg.environment;
pkg.executables = uploadedPkg.executables;
pkg.folder = uploadedPkg.folder;
pkg.checkNotes = uploadedPkg.checkNotes;
pkg.files?.ForEach(f => f.urls = null); //Cant send urls to Nebula or it gets rejected
skipPkg = true;
Log.Add(Log.LogSeverity.Information, "TaskItemViewModel.UploadModVersion()", "Skipping package preparation for :" + pkg.name + ". Data was loaded from Nebula.");
}
}
}
if (!skipPkg)
{
if (mod.type != ModType.mod && mod.type != ModType.tc) //Just to be sure
pkg.isVp = false;
var newTask = new TaskItemViewModel();
await Dispatcher.UIThread.InvokeAsync(() => TaskList.Insert(0, newTask));
await newTask.PrepareModPkg(pkg, mod.fullPath, cancellationTokenSource);
}
ProgressCurrent++;
if (cancellationTokenSource.IsCancellationRequested)
throw new TaskCanceledException();
});

Info = "Upload Packages";
//Upload Packages
await Parallel.ForEachAsync(mod.packages, new ParallelOptions { MaxDegreeOfParallelism = 1 }, async (pkg, token) =>
await Parallel.ForEachAsync(mod.packages, new ParallelOptions { MaxDegreeOfParallelism = parallelUploads }, async (pkg, token) =>
{
var newTask = new TaskItemViewModel();
await Dispatcher.UIThread.InvokeAsync(() => TaskList.Insert(0, newTask));
await newTask.UploadModPkg(pkg, mod.fullPath, cancellationTokenSource);
bool skipPkg = false;
//We should skip this?
if (advData != null)
{
var advDataPkg = advData.FirstOrDefault(p => p.packageInNebula != null && p.packageInNebula!.name == pkg.name);
if (advDataPkg != null && !advDataPkg.Upload)
{
var uploadedPkg = advDataPkg.packageInNebula;
if (uploadedPkg != null)
{
skipPkg = true;
Log.Add(Log.LogSeverity.Information, "TaskItemViewModel.UploadModVersion()", "Skipping package upload for :" + pkg.name + ". Used the one in Nebula instead, file hash: " + advDataPkg.CustomHash );
}
}
}
if (!skipPkg)
{
var newTask = new TaskItemViewModel();
await Dispatcher.UIThread.InvokeAsync(() => TaskList.Insert(0, newTask));
await newTask.UploadModPkg(pkg, mod.fullPath, cancellationTokenSource);
}
ProgressCurrent++;
if (cancellationTokenSource.IsCancellationRequested)
throw new TaskCanceledException();
Expand Down
Loading