Implemented fabric version setting
This commit is contained in:
@@ -40,6 +40,9 @@
|
||||
if(Tags.Contains("forgeversion"))
|
||||
Settings.Add("Forge version", typeof(ForgeVersionSetting));
|
||||
|
||||
if(Tags.Contains("fabricversion"))
|
||||
Settings.Add("Fabric version", typeof(FabricVersionSetting));
|
||||
|
||||
if(Tags.Contains("join2start"))
|
||||
Settings.Add("Join2Start", typeof(Join2StartSetting));
|
||||
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
@using Moonlight.App.Services
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using Moonlight.App.Database.Entities
|
||||
@using Moonlight.App.Repositories
|
||||
@using Moonlight.App.Repositories.Servers
|
||||
@using Moonlight.App.Helpers
|
||||
|
||||
@inject ServerService ServerService
|
||||
@inject ServerRepository ServerRepository
|
||||
@inject ImageRepository ImageRepository
|
||||
@inject FabricService FabricService
|
||||
@inject SmartTranslateService TranslationService
|
||||
|
||||
<div class="col">
|
||||
<div class="card card-body">
|
||||
<LazyLoader Load="Load">
|
||||
<label class="mb-2 form-label">
|
||||
<TL>Fabric version</TL>
|
||||
</label>
|
||||
<input class="mb-2 form-control" disabled="" value="@(FabricVersion)"/>
|
||||
<label class="mb-2 form-label">
|
||||
<TL>Fabric loader version</TL>
|
||||
</label>
|
||||
<input class="mb-2 form-control" disabled="" value="@(LoaderVersion)"/>
|
||||
<label class="mb-2 form-label">
|
||||
<TL>Minecraft version</TL>
|
||||
</label>
|
||||
<select class="mb-2 form-select" @bind="CurrentVersion">
|
||||
@foreach (var version in Versions)
|
||||
{
|
||||
if (version == CurrentVersion)
|
||||
{
|
||||
<option value="@(version)" selected="">@(version)</option>
|
||||
}
|
||||
else
|
||||
{
|
||||
<option value="@(version)">@(version)</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
<WButton
|
||||
OnClick="Save"
|
||||
Text="@(TranslationService.Translate("Change"))"
|
||||
WorkingText="@(TranslationService.Translate("Changing"))"
|
||||
CssClasses="btn-primary">
|
||||
</WButton>
|
||||
</LazyLoader>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[CascadingParameter]
|
||||
public Server CurrentServer { get; set; }
|
||||
|
||||
private string[] Versions = Array.Empty<string>();
|
||||
private string CurrentVersion = "";
|
||||
|
||||
private string FabricVersion = "";
|
||||
private string LoaderVersion = "";
|
||||
|
||||
|
||||
private async Task Load(LazyLoader lazyLoader)
|
||||
{
|
||||
// Fabric version
|
||||
|
||||
var fabricVersion = LiveMigrateVar(
|
||||
"FABRIC_VERSION",
|
||||
await FabricService.GetLatestInstallerVersion(),
|
||||
true
|
||||
);
|
||||
|
||||
FabricVersion = fabricVersion.Value;
|
||||
|
||||
// Fabric loader version
|
||||
|
||||
var loaderVersion = LiveMigrateVar(
|
||||
"LOADER_VERSION",
|
||||
await FabricService.GetLatestLoaderVersion(),
|
||||
true
|
||||
);
|
||||
|
||||
LoaderVersion = loaderVersion.Value;
|
||||
|
||||
// Minecraft versions
|
||||
|
||||
Versions = await FabricService.GetGameVersions();
|
||||
|
||||
var mcVersion = LiveMigrateVar(
|
||||
"MC_VERSION",
|
||||
Versions.First()
|
||||
);
|
||||
|
||||
CurrentVersion = mcVersion.Value;
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private ServerVariable LiveMigrateVar(string key, string value, bool overwrite = false)
|
||||
{
|
||||
var v = CurrentServer.Variables.FirstOrDefault(x => x.Key == key);
|
||||
|
||||
if (v == null)
|
||||
{
|
||||
CurrentServer.Variables.Add(new()
|
||||
{
|
||||
Key = key,
|
||||
Value = value
|
||||
});
|
||||
|
||||
ServerRepository.Update(CurrentServer);
|
||||
|
||||
return CurrentServer.Variables.First(x => x.Key == key);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(v.Value) || overwrite)
|
||||
{
|
||||
v.Value = value;
|
||||
|
||||
ServerRepository.Update(CurrentServer);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Save()
|
||||
{
|
||||
var vars = CurrentServer.Variables;
|
||||
var versionVar = vars.First(x => x.Key == "MC_VERSION");
|
||||
|
||||
versionVar.Value = CurrentVersion;
|
||||
|
||||
// This searches for the display name of a version using the constructed full version
|
||||
var version = ParseHelper.MinecraftToInt(CurrentVersion);
|
||||
|
||||
var serverImage = ImageRepository
|
||||
.Get()
|
||||
.Include(x => x.DockerImages)
|
||||
.First(x => x.Id == CurrentServer.Image.Id);
|
||||
|
||||
var dockerImages = serverImage.DockerImages;
|
||||
|
||||
var dockerImageToUpdate = dockerImages.Last();
|
||||
|
||||
if (version < 1130)
|
||||
{
|
||||
dockerImageToUpdate = dockerImages.First(x => x.Name.Contains("8"));
|
||||
}
|
||||
|
||||
if (version >= 1130)
|
||||
{
|
||||
dockerImageToUpdate = dockerImages.First(x => x.Name.Contains("11"));
|
||||
}
|
||||
|
||||
if (version >= 1170)
|
||||
{
|
||||
dockerImageToUpdate = dockerImages.First(x => x.Name.Contains("16"));
|
||||
}
|
||||
|
||||
if (version >= 1190)
|
||||
{
|
||||
dockerImageToUpdate = dockerImages.First(x => x.Name.Contains("17"));
|
||||
}
|
||||
|
||||
CurrentServer.DockerImageIndex = dockerImages.IndexOf(dockerImageToUpdate);
|
||||
|
||||
ServerRepository.Update(CurrentServer);
|
||||
|
||||
await ServerService.Reinstall(CurrentServer);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user