Compare commits
4 Commits
9bcdfd88e6
...
1c3b8963ac
| Author | SHA1 | Date | |
|---|---|---|---|
| 1c3b8963ac | |||
| e915892fa2 | |||
| ab1aefd619 | |||
| 459b3f09f9 |
@ -38,7 +38,7 @@ public class GameVersion
|
||||
_descriptor.javaVersion.component, LauncherApp.Config.redirect_game_output);
|
||||
}
|
||||
|
||||
public async Task Download(bool update, Action<NetworkTask> networkTaskCreatedCallback)
|
||||
public async Task Download(bool checkHashes, Action<NetworkTask> networkTaskCreatedCallback)
|
||||
{
|
||||
LauncherApp.Logger.LogInfo(Id, $"started updating version {Id}");
|
||||
|
||||
@ -47,9 +47,9 @@ public class GameVersion
|
||||
new AssetsDownloadTaskFactory(_descriptor),
|
||||
new LibrariesDownloadTaskFactory(_descriptor, _libraries),
|
||||
];
|
||||
if (LauncherApp.Config.download_java)
|
||||
if (LauncherApp.Config.download_java && (!File.Exists(JavaExecutableFilePath) || checkHashes))
|
||||
taskFactories.Add(new JavaDownloadTaskFactory(_descriptor));
|
||||
if (_descriptor.modpack != null)
|
||||
if (_descriptor.modpack != null)
|
||||
taskFactories.Add(new ModpackDownloadTaskFactory(_descriptor));
|
||||
// has to be downloaded last because it is used to check if version is installed
|
||||
taskFactories.Add(new VersionJarDownloadTaskFactory(_descriptor));
|
||||
@ -57,7 +57,7 @@ public class GameVersion
|
||||
var networkTasks = new List<NetworkTask>();
|
||||
for (int i = 0; i < taskFactories.Count; i++)
|
||||
{
|
||||
var nt = await taskFactories[i].CreateAsync(update);
|
||||
var nt = await taskFactories[i].CreateAsync(checkHashes);
|
||||
if (nt != null)
|
||||
{
|
||||
networkTasks.Add(nt);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Version>1.1.1</Version>
|
||||
<Version>1.1.2</Version>
|
||||
<OutputType Condition="'$(Configuration)' == 'Debug'">Exe</OutputType>
|
||||
<OutputType Condition="'$(Configuration)' != 'Debug'">WinExe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
@ -12,7 +12,6 @@
|
||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||
<ApplicationIcon>капитал\кубе.ico</ApplicationIcon>
|
||||
<AssemblyName>млаумчерб</AssemblyName>
|
||||
<Configurations>Release;Debug</Configurations>
|
||||
<Platforms>x64</Platforms>
|
||||
<!-- AXAML resource has no public constructor -->
|
||||
<NoWarn>AVLN3001</NoWarn>
|
||||
@ -25,7 +24,7 @@
|
||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.*" />
|
||||
<PackageReference Include="Avalonia.Labs.Gif" Version="11.2.*" />
|
||||
<PackageReference Include="CliWrap" Version="3.7.0" />
|
||||
<PackageReference Include="DTLib" Version="1.6.1" />
|
||||
<PackageReference Include="DTLib" Version="1.7.3" />
|
||||
<PackageReference Include="LZMA-SDK" Version="22.1.1" />
|
||||
<PackageReference Include="MessageBox.Avalonia" Version="3.2.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.*" />
|
||||
@ -35,9 +34,5 @@
|
||||
<AvaloniaResource Include="капитал\**"/>
|
||||
<EmbeddedResource Include="встроенное\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Gitea\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -2,7 +2,6 @@ using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Mlaumcherb.Client.Avalonia.классы;
|
||||
using Mlaumcherb.Client.Avalonia.сеть;
|
||||
using Mlaumcherb.Client.Avalonia.сеть.Update;
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
|
||||
@ -20,19 +19,26 @@ public class LauncherApp : Application
|
||||
Config = Config.LoadFromFile();
|
||||
Logger.DebugLogEnabled = Config.debug;
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
|
||||
Update();
|
||||
|
||||
// some file required by forge installer
|
||||
if (!File.Exists("launcher_profiles.json"))
|
||||
try
|
||||
{
|
||||
File.WriteAllText("launcher_profiles.json", "{}");
|
||||
}
|
||||
SelfUpdateAsync();
|
||||
|
||||
// some file required by forge installer
|
||||
if (!File.Exists("launcher_profiles.json"))
|
||||
{
|
||||
File.WriteAllText("launcher_profiles.json", "{}");
|
||||
}
|
||||
|
||||
InstalledVersionCatalog = InstalledVersionCatalog.Load();
|
||||
InstalledVersionCatalog = InstalledVersionCatalog.Load();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorHelper.ShowMessageBox(nameof(LauncherApp), e);
|
||||
}
|
||||
}
|
||||
|
||||
private async void Update()
|
||||
private async void SelfUpdateAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -46,6 +52,10 @@ public class LauncherApp : Application
|
||||
Logger.LogInfo(nameof(LauncherApp), "restarting...");
|
||||
upd.RestartSelf();
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogInfo(nameof(LauncherApp), "no updates found");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@ -71,7 +71,7 @@ public partial class MainWindow : Window
|
||||
try
|
||||
{
|
||||
LauncherApp.Logger.OnLogMessage += GuiLogMessage;
|
||||
LauncherVersionTextBox.Text = $"v {Assembly.GetExecutingAssembly().GetName().Version}";
|
||||
LauncherVersionTextBox.Text = $"v{Assembly.GetExecutingAssembly().GetName().Version}";
|
||||
|
||||
PlayerName = LauncherApp.Config.player_name;
|
||||
MemoryLimit = LauncherApp.Config.max_memory;
|
||||
@ -92,6 +92,20 @@ public partial class MainWindow : Window
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnUnloaded(RoutedEventArgs e)
|
||||
{
|
||||
SaveGuiPropertiesToConfig();
|
||||
}
|
||||
|
||||
private void SaveGuiPropertiesToConfig()
|
||||
{
|
||||
LauncherApp.Config.player_name = PlayerName;
|
||||
LauncherApp.Config.max_memory = MemoryLimit;
|
||||
LauncherApp.Config.download_java = EnableJavaDownload;
|
||||
LauncherApp.Config.redirect_game_output = RedirectGameOutput;
|
||||
LauncherApp.Config.SaveToFile();
|
||||
}
|
||||
|
||||
private void UpdateInstalledVersionsCatalogView(string? selectVersion)
|
||||
{
|
||||
LauncherApp.InstalledVersionCatalog.CheckInstalledVersions();
|
||||
@ -121,8 +135,15 @@ public partial class MainWindow : Window
|
||||
|
||||
private void RescanInstalledVersionsButton_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var selectedVersionView = InstalledVersionCatalogComboBox.SelectedItem as InstalledGameVersionItemView;
|
||||
UpdateInstalledVersionsCatalogView(selectedVersionView?.Props.Id);
|
||||
try
|
||||
{
|
||||
var selectedVersionView = InstalledVersionCatalogComboBox.SelectedItem as InstalledGameVersionItemView;
|
||||
UpdateInstalledVersionsCatalogView(selectedVersionView?.Props.Id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ErrorHelper.ShowMessageBox(nameof(MainWindow), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void GuiLogMessage(LauncherLogger.LogMessage msg)
|
||||
@ -147,22 +168,27 @@ public partial class MainWindow : Window
|
||||
|
||||
Dispatcher.UIThread.Invoke(() => LaunchButton.IsEnabled = false);
|
||||
LauncherApp.Config.last_launched_version = selectedVersionView.Props.Id;
|
||||
LauncherApp.Config.player_name = PlayerName;
|
||||
LauncherApp.Config.max_memory = MemoryLimit;
|
||||
LauncherApp.Config.download_java = EnableJavaDownload;
|
||||
LauncherApp.Config.redirect_game_output = RedirectGameOutput;
|
||||
LauncherApp.Config.SaveToFile();
|
||||
SaveGuiPropertiesToConfig();
|
||||
|
||||
var v = await selectedVersionView.Props.LoadDescriptor(UpdateGameFiles);
|
||||
await v.Download(UpdateGameFiles, nt =>
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
|
||||
try
|
||||
{
|
||||
await v.Download(UpdateGameFiles, nt =>
|
||||
{
|
||||
DownloadsPanel.Children.Add(new NetworkTaskView(nt,
|
||||
ntv => DownloadsPanel.Children.Remove(ntv)));
|
||||
});
|
||||
}
|
||||
);
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
DownloadsPanel.Children.Add(new NetworkTaskView(nt,
|
||||
ntv => DownloadsPanel.Children.Remove(ntv)));
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ErrorHelper.ShowMessageBox(nameof(MainWindow), ex);
|
||||
}
|
||||
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
UpdateGameFiles = false;
|
||||
@ -183,7 +209,6 @@ public partial class MainWindow : Window
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
string workingDir = Directory.GetCurrent().ToString();
|
||||
LauncherApp.Logger.LogDebug(nameof(MainWindow),
|
||||
$"opening working directory: {workingDir}");
|
||||
|
||||
@ -66,23 +66,26 @@ public class InstalledGameVersionProps : IComparable<InstalledGameVersionProps>,
|
||||
JObject descriptorRaw = JObject.Parse(descriptorText);
|
||||
|
||||
// Descriptors can inherit from other descriptors.
|
||||
// For example, 1.12.2-forge-14.23.5.2860 inherits from 1.12.2
|
||||
if (descriptorRaw.TryGetValue("inheritsFrom", out var v))
|
||||
// For example, timerix-anarx-2 inherits from 1.12.2-forge-14.23.5.2860, which inherits from 1.12.2
|
||||
while (descriptorRaw.TryGetValue("inheritsFrom", out var v))
|
||||
{
|
||||
string parentDescriptorId = v.Value<string>()
|
||||
?? throw new Exception("inheritsFrom is null");
|
||||
?? throw new Exception("inheritsFrom is null");
|
||||
LauncherApp.Logger.LogInfo(Id, $"merging descriptor '{parentDescriptorId}' with '{Id}'");
|
||||
|
||||
IOPath parentDescriptorPath = PathHelper.GetVersionDescriptorPath(parentDescriptorId);
|
||||
if (!File.Exists(parentDescriptorPath))
|
||||
throw new Exception($"Версия '{Id} требует установить версию '{parentDescriptorId}'");
|
||||
string parentDescriptorText = File.ReadAllText(parentDescriptorPath);
|
||||
JObject parentDescriptorRaw = JObject.Parse(parentDescriptorText);
|
||||
JObject parentDescriptorRaw = JObject.Parse(File.ReadAllText(parentDescriptorPath));
|
||||
|
||||
// Remove `inheritsFrom: parentDescriptor.Id` to prevent overriding of `parentDescriptor.inheritsFrom`
|
||||
descriptorRaw.Remove("inheritsFrom");
|
||||
// Merge child descriptor into its parent.
|
||||
// Child descriptor values override values of parent.
|
||||
// Array values are merged together.
|
||||
parentDescriptorRaw.Merge(descriptorRaw,
|
||||
new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Concat });
|
||||
descriptorRaw = parentDescriptorRaw;
|
||||
// removing dependency
|
||||
// descriptorRaw.Remove("inheritsFrom");
|
||||
// File.WriteAllText(DescriptorPath, descriptorRaw.ToString());
|
||||
}
|
||||
|
||||
var descriptor = descriptorRaw.ToObject<GameVersionDescriptor>()
|
||||
|
||||
@ -29,7 +29,6 @@ public class InstalledVersionCatalog
|
||||
}
|
||||
|
||||
catalog.CheckInstalledVersions();
|
||||
catalog.Save();
|
||||
return catalog;
|
||||
}
|
||||
|
||||
@ -44,6 +43,7 @@ public class InstalledVersionCatalog
|
||||
|
||||
/// <summary>
|
||||
/// Check if any versions were installed or deleted manually.
|
||||
/// Calls <see cref="Save"/>
|
||||
/// </summary>
|
||||
public void CheckInstalledVersions()
|
||||
{
|
||||
@ -53,17 +53,16 @@ public class InstalledVersionCatalog
|
||||
{
|
||||
string id = subdir.LastName().ToString();
|
||||
if (!File.Exists(PathHelper.GetVersionDescriptorPath(id)))
|
||||
throw new Exception(
|
||||
$"Can't find version descriptor file in directory '{subdir}'. Rename it as directory name.");
|
||||
|
||||
{
|
||||
LauncherApp.Logger.LogWarn(nameof(CheckInstalledVersions),
|
||||
$"Can't find version descriptor file in directory '{subdir}'. " +
|
||||
$"Rename it as directory name.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (versions.TryGetValue(id, out var foundProps))
|
||||
{
|
||||
versionsUpdated.Add(foundProps);
|
||||
}
|
||||
else
|
||||
{
|
||||
versionsUpdated.Add(new InstalledGameVersionProps(id, null, null));
|
||||
}
|
||||
else versionsUpdated.Add(new InstalledGameVersionProps(id, null, null));
|
||||
}
|
||||
|
||||
// reverse sort
|
||||
@ -73,5 +72,7 @@ public class InstalledVersionCatalog
|
||||
versionsUpdated.Select(props =>
|
||||
new KeyValuePair<string, InstalledGameVersionProps>(props.Id, props)
|
||||
));
|
||||
|
||||
Save();
|
||||
}
|
||||
}
|
||||
@ -12,6 +12,7 @@ public static class NetworkHelper
|
||||
// thanks for Sashok :3
|
||||
// https://github.com/new-sashok724/Launcher/blob/23485c3f7de6620d2c6b7b2dd9339c3beb6a0366/Launcher/source/helper/IOHelper.java#L259
|
||||
_http.DefaultRequestHeaders.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
|
||||
_http.Timeout = TimeSpan.FromSeconds(4);
|
||||
}
|
||||
|
||||
public static Task<string> GetString(string url, CancellationToken ct = default) => _http.GetStringAsync(url, ct);
|
||||
|
||||
@ -42,14 +42,20 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory
|
||||
|
||||
foreach (var l in _libraries.Libs)
|
||||
{
|
||||
if (!HashHelper.CheckFileSHA1(l.jarFilePath, l.artifact?.sha1, checkHashes))
|
||||
if (l is Libraries.NativeLib native)
|
||||
{
|
||||
_libsToDownload.Add(l);
|
||||
//TODO: replace with actual native libraries check
|
||||
if(!nativeDirExists || checkHashes)
|
||||
{
|
||||
_libsToDownload.Add(l);
|
||||
}
|
||||
}
|
||||
//TODO: replace with actual native libraries check
|
||||
else if (!nativeDirExists && l is Libraries.NativeLib)
|
||||
else
|
||||
{
|
||||
_libsToDownload.Add(l);
|
||||
if (!HashHelper.CheckFileSHA1(l.jarFilePath, l.artifact?.sha1, checkHashes))
|
||||
{
|
||||
_libsToDownload.Add(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user