mirror of
https://gitlab.com/nullmax17/PlombirLauncher.git
synced 2025-03-14 18:01:12 +03:00
Version 1.1.0 | Settings and gitlab repo
This commit is contained in:
parent
48220f8b23
commit
96cefe5749
@ -1,4 +1,4 @@
|
|||||||
using System.Formats.Tar;
|
using System.Formats.Tar;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Security.AccessControl;
|
using System.Security.AccessControl;
|
||||||
@ -6,7 +6,7 @@ using CmlLib.Core;
|
|||||||
using CmlLib.Core.Auth;
|
using CmlLib.Core.Auth;
|
||||||
using CmlLib.Core.ProcessBuilder;
|
using CmlLib.Core.ProcessBuilder;
|
||||||
|
|
||||||
namespace BlightFlame
|
namespace PlombirLauncher
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Basically a class to manage everything launcher related.
|
Basically a class to manage everything launcher related.
|
||||||
@ -22,11 +22,11 @@ namespace BlightFlame
|
|||||||
public int DownloadProgress;
|
public int DownloadProgress;
|
||||||
public string DownloadStatus;
|
public string DownloadStatus;
|
||||||
|
|
||||||
public Launcher(string userName, string version)
|
public Launcher(string userName, string version, string? location = null)
|
||||||
{
|
{
|
||||||
_version = version;
|
_version = version;
|
||||||
_nickname = userName;
|
_nickname = userName;
|
||||||
_mcPath = new($"./runtime/{version}/minecraft");
|
_mcPath = new($"{location}/{version}/minecraft");
|
||||||
_mcLauncher = new(_mcPath);
|
_mcLauncher = new(_mcPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ namespace BlightFlame
|
|||||||
|
|
||||||
// System.Uri download_uri = new("https://dixxe.top/static/distro/cmllibcore-minecraft-forge-1201.tar.xz");
|
// System.Uri download_uri = new("https://dixxe.top/static/distro/cmllibcore-minecraft-forge-1201.tar.xz");
|
||||||
// WebClient client = new();
|
// WebClient client = new();
|
||||||
|
|
||||||
// if ((!File.Exists(archieve)) && (!Directory.Exists(runtimePath)))
|
// if ((!File.Exists(archieve)) && (!Directory.Exists(runtimePath)))
|
||||||
// {
|
// {
|
||||||
// DownloadStatus = "Fetching deploy-minecraft from host...";
|
// DownloadStatus = "Fetching deploy-minecraft from host...";
|
||||||
@ -72,7 +72,7 @@ namespace BlightFlame
|
|||||||
// // Waiting for archieve to download.
|
// // Waiting for archieve to download.
|
||||||
// await tcs.Task;
|
// await tcs.Task;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// DownloadStatus = "Unarchiving modpack...";
|
// DownloadStatus = "Unarchiving modpack...";
|
||||||
// unarchiveMinecraft(archieve, runtimePath);
|
// unarchiveMinecraft(archieve, runtimePath);
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ namespace BlightFlame
|
|||||||
// Directory.CreateDirectory(path);
|
// Directory.CreateDirectory(path);
|
||||||
// Utils.UnzipTarGzFile(archieveName, path);
|
// Utils.UnzipTarGzFile(archieveName, path);
|
||||||
|
|
||||||
// if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
// if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
// {
|
// {
|
||||||
// Utils.LinuxExec($"chmod -R +x {path}/");
|
// Utils.LinuxExec($"chmod -R +x {path}/");
|
||||||
// Console.WriteLine("Execute permissions added successfully.");
|
// Console.WriteLine("Execute permissions added successfully.");
|
||||||
@ -94,47 +94,46 @@ namespace BlightFlame
|
|||||||
|
|
||||||
// File.Delete(archieveName);
|
// File.Delete(archieveName);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
async public Task BuildLauncher()
|
async public Task BuildLauncher(CancellationToken token)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
_mcLauncher.ByteProgressChanged += (_, args) =>
|
_mcLauncher.ByteProgressChanged += (_, args) =>
|
||||||
{
|
{
|
||||||
Console.WriteLine($"{(int)(args.ProgressedBytes * 0.000001)} MBytes / {(int)(args.TotalBytes * 0.000001)} MBytes");
|
Console.WriteLine($"{(int)(args.ProgressedBytes * 0.000001)} MBytes / {(int)(args.TotalBytes * 0.000001)} MBytes");
|
||||||
DownloadProgress = (int)(args.ProgressedBytes * 100 / args.TotalBytes);
|
DownloadProgress = (int)(args.ProgressedBytes * 100 / args.TotalBytes);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Before installAsync I should fetch lightweight minecraft instance from webserver
|
// Before installAsync I should fetch lightweight minecraft instance from webserver
|
||||||
// Then installAsync will download any runtime needed stuff.
|
// Then installAsync will download any runtime needed stuff.
|
||||||
// This method is FetchMinecraft()
|
// This method is FetchMinecraft()
|
||||||
// Currently this is only one viable option for forge installations.
|
// Currently this is only one viable option for forge installations.
|
||||||
// But it requires server, so forge (and all mod loaders) is disabled.
|
// But it requires server, so forge (and all mod loaders) is disabled.
|
||||||
//await FetchMinecraft();
|
//await FetchMinecraft();
|
||||||
|
|
||||||
DownloadStatus = "Installing minecraft...";
|
DownloadStatus = "Installing minecraft...";
|
||||||
Console.WriteLine(DownloadStatus);
|
Console.WriteLine(DownloadStatus);
|
||||||
await _mcLauncher.InstallAsync(_version);
|
await _mcLauncher.InstallAsync(_version);
|
||||||
DownloadStatus = "Finished!";
|
DownloadStatus = "Finished!";
|
||||||
Console.WriteLine(DownloadStatus);
|
Console.WriteLine(DownloadStatus);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async public Task RunLauncher()
|
async public Task RunLauncher()
|
||||||
{
|
{
|
||||||
var process = await _mcLauncher.BuildProcessAsync(_version, new MLaunchOption{
|
var process = await _mcLauncher.BuildProcessAsync(_version, new MLaunchOption
|
||||||
|
{
|
||||||
|
|
||||||
Session = MSession.CreateOfflineSession(_nickname),
|
Session = MSession.CreateOfflineSession(_nickname),
|
||||||
MaximumRamMb = 4096,
|
MaximumRamMb = 4096,
|
||||||
|
|
||||||
}) ?? throw new Exception("Failed to start minecraft process!");
|
}) ?? throw new Exception("Failed to start minecraft process!");
|
||||||
|
|
||||||
var processUtil = new ProcessWrapper(process);
|
var processUtil = new ProcessWrapper(process);
|
||||||
processUtil.OutputReceived += (s, e) => Console.WriteLine(e);
|
processUtil.OutputReceived += (s, e) => Console.WriteLine(e);
|
||||||
processUtil.StartWithEvents();
|
processUtil.StartWithEvents();
|
||||||
|
|
||||||
await processUtil.WaitForExitTaskAsync();
|
await processUtil.WaitForExitTaskAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
namespace BlightFlame
|
namespace PlombirLauncher
|
||||||
{
|
{
|
||||||
sealed class Program
|
sealed class Program
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@ using SharpCompress.Readers;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using CmlLib.Core;
|
using CmlLib.Core;
|
||||||
|
|
||||||
namespace BlightFlame
|
namespace PlombirLauncher
|
||||||
{
|
{
|
||||||
static public class Utils
|
static public class Utils
|
||||||
{
|
{
|
||||||
|
BIN
src/LauncherGUI/Assets/cog.png
Normal file
BIN
src/LauncherGUI/Assets/cog.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 892 B |
BIN
src/LauncherGUI/Assets/gitlab-logo.png
Normal file
BIN
src/LauncherGUI/Assets/gitlab-logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 939 B |
BIN
src/LauncherGUI/Assets/toml-paper.png
Normal file
BIN
src/LauncherGUI/Assets/toml-paper.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 911 B |
75
src/LauncherGUI/ConfigManager.cs
Normal file
75
src/LauncherGUI/ConfigManager.cs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using Tommy;
|
||||||
|
|
||||||
|
namespace PlombirLauncher;
|
||||||
|
|
||||||
|
public class ConfigManager
|
||||||
|
{
|
||||||
|
public static void BuildDefault()
|
||||||
|
{
|
||||||
|
TomlTable toml = new TomlTable
|
||||||
|
{
|
||||||
|
["title"] = "Launcher tweaks file!",
|
||||||
|
|
||||||
|
["runtime-path"] = new TomlString
|
||||||
|
{
|
||||||
|
Value = "./runtime",
|
||||||
|
Comment = "Path to folder that will hold all minecraft versions"
|
||||||
|
},
|
||||||
|
|
||||||
|
["last-version-launched"] = new TomlString
|
||||||
|
{
|
||||||
|
Value = "1.20.1",
|
||||||
|
Comment = "Saving last launched version to use it after launch"
|
||||||
|
},
|
||||||
|
|
||||||
|
["nickname"] = "slugcat"
|
||||||
|
};
|
||||||
|
|
||||||
|
using(StreamWriter writer = File.CreateText("tweaks.toml"))
|
||||||
|
{
|
||||||
|
toml.WriteTo(writer);
|
||||||
|
// Remember to flush the data if needed!
|
||||||
|
writer.Flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static dynamic? ReadConfig(string key)
|
||||||
|
{
|
||||||
|
if (!File.Exists("tweaks.toml"))
|
||||||
|
{
|
||||||
|
BuildDefault();
|
||||||
|
}
|
||||||
|
using(StreamReader reader = File.OpenText("tweaks.toml"))
|
||||||
|
{
|
||||||
|
TomlTable table = TOML.Parse(reader);
|
||||||
|
|
||||||
|
return table[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void WriteInConfig(string key, dynamic value)
|
||||||
|
{
|
||||||
|
if (!File.Exists("tweaks.toml"))
|
||||||
|
{
|
||||||
|
BuildDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
TomlTable table;
|
||||||
|
|
||||||
|
using(StreamReader reader = File.OpenText("tweaks.toml"))
|
||||||
|
{
|
||||||
|
table = TOML.Parse(reader);
|
||||||
|
|
||||||
|
table[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
using(StreamWriter writer = File.CreateText("tweaks.toml"))
|
||||||
|
{
|
||||||
|
table.WriteTo(writer);
|
||||||
|
// Remember to flush the data if needed!
|
||||||
|
writer.Flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -28,6 +28,7 @@
|
|||||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
|
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
|
||||||
|
<PackageReference Include="Tommy" Version="3.1.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
23
src/LauncherGUI/LauncherUtils.cs
Normal file
23
src/LauncherGUI/LauncherUtils.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using LauncherGUI.ViewModels;
|
||||||
|
using LauncherGUI.Views;
|
||||||
|
|
||||||
|
namespace PlombirLauncher;
|
||||||
|
|
||||||
|
public class LauncherUtils
|
||||||
|
{
|
||||||
|
public async static Task CreateMinecraftInstance(MainWindowViewModel vm, Window windowCaller)
|
||||||
|
{
|
||||||
|
System.Console.WriteLine($"Creating minecraft instance for {vm.Usernick}, {vm.SelectedVersion} in {vm.RuntimeLocation}");
|
||||||
|
LoadingWindow loading = new(vm.Usernick, vm.SelectedVersion, vm.RuntimeLocation);
|
||||||
|
ConfigManager.WriteInConfig("last-version-launched", vm.SelectedVersion);
|
||||||
|
ConfigManager.WriteInConfig("nickname", vm.Usernick);
|
||||||
|
|
||||||
|
loading.Show();
|
||||||
|
await loading.InitLoading();
|
||||||
|
loading.Close();
|
||||||
|
await loading.RunMinecraft();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
using BlightFlame;
|
using PlombirLauncher;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace LauncherGUI;
|
namespace LauncherGUI;
|
||||||
|
@ -2,7 +2,7 @@ namespace LauncherGUI.ViewModels;
|
|||||||
|
|
||||||
public partial class LoadingWindowViewModel : ViewModelBase
|
public partial class LoadingWindowViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
private long _loadingProgress;
|
private long _loadingProgress = 0;
|
||||||
public long Progress {get => _loadingProgress; set {_loadingProgress = value; OnPropertyChanged(nameof(Progress)); }}
|
public long Progress {get => _loadingProgress; set {_loadingProgress = value; OnPropertyChanged(nameof(Progress)); }}
|
||||||
|
|
||||||
private string _loadingStatus = "Rotating transistors..";
|
private string _loadingStatus = "Rotating transistors..";
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using BlightFlame;
|
using PlombirLauncher;
|
||||||
|
|
||||||
namespace LauncherGUI.ViewModels;
|
namespace LauncherGUI.ViewModels;
|
||||||
|
|
||||||
@ -7,9 +7,12 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||||||
{
|
{
|
||||||
public string Greeting { get; } = "Plombir launcher";
|
public string Greeting { get; } = "Plombir launcher";
|
||||||
|
|
||||||
private string _userNick = "slugcat";
|
private string _userNick = ConfigManager.ReadConfig("nickname");
|
||||||
public string Usernick {get => _userNick; set {_userNick = value; OnPropertyChanged(nameof(Usernick)); }}
|
public string Usernick {get => _userNick; set {_userNick = value; OnPropertyChanged(nameof(Usernick)); }}
|
||||||
|
|
||||||
private string _selectedVersion = "1.20.1";
|
private string _selectedVersion = ConfigManager.ReadConfig("last-version-launched");
|
||||||
public string SelectedVersion {get => _selectedVersion; set {_selectedVersion = value; OnPropertyChanged(nameof(SelectedVersion)); }}
|
public string SelectedVersion {get => _selectedVersion; set {_selectedVersion = value; OnPropertyChanged(nameof(SelectedVersion)); }}
|
||||||
|
|
||||||
|
private string _runtimeLocation = ConfigManager.ReadConfig("runtime-path");
|
||||||
|
public string RuntimeLocation {get => _runtimeLocation; set {_runtimeLocation = value; OnPropertyChanged(nameof(RuntimeLocation)); }}
|
||||||
}
|
}
|
||||||
|
6
src/LauncherGUI/ViewModels/SettingsWindowViewModel.cs
Normal file
6
src/LauncherGUI/ViewModels/SettingsWindowViewModel.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
namespace LauncherGUI.ViewModels;
|
||||||
|
|
||||||
|
public partial class SettingsWindowViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
// I save launcher data mostly in MainWindowViewModel.
|
||||||
|
}
|
@ -1,10 +1,10 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using BlightFlame;
|
using PlombirLauncher;
|
||||||
using LauncherGUI.ViewModels;
|
using LauncherGUI.ViewModels;
|
||||||
|
|
||||||
namespace LauncherGUI.ViewModels;
|
namespace LauncherGUI.ViewModels;
|
||||||
|
|
||||||
public partial class VersionSelectorWindowViewModel : ViewModelBase
|
public partial class VersionSelectorWindowViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
|
// I save launcher data mostly in MainWindowViewModel.
|
||||||
}
|
}
|
@ -4,4 +4,5 @@ namespace LauncherGUI.ViewModels;
|
|||||||
|
|
||||||
public class ViewModelBase : ObservableObject
|
public class ViewModelBase : ObservableObject
|
||||||
{
|
{
|
||||||
|
// I save launcher data mostly in MainWindowViewModel.
|
||||||
}
|
}
|
||||||
|
@ -1,58 +1,65 @@
|
|||||||
<Window xmlns="https://github.com/avaloniaui"
|
<Window
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:vm="using:LauncherGUI.ViewModels"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:vm="using:LauncherGUI.ViewModels"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="200"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
x:Class="LauncherGUI.Views.LoadingWindow"
|
mc:Ignorable="d"
|
||||||
x:DataType="vm:LoadingWindowViewModel"
|
d:DesignWidth="400"
|
||||||
Icon="/Assets/icon.png"
|
d:DesignHeight="200"
|
||||||
Title="loading"
|
x:Class="LauncherGUI.Views.LoadingWindow"
|
||||||
RequestedThemeVariant="Dark"
|
x:DataType="vm:LoadingWindowViewModel"
|
||||||
Width="400" Height="200"
|
Icon="/Assets/icon.png"
|
||||||
MinWidth="400" MinHeight="200"
|
Title="Loading"
|
||||||
MaxWidth="400" MaxHeight="200"
|
RequestedThemeVariant="Dark"
|
||||||
Background="#353535">
|
Width="400"
|
||||||
|
Height="200"
|
||||||
<Design.DataContext>
|
MinWidth="400"
|
||||||
<!-- This only sets the DataContext for the previewer in an IDE,
|
MinHeight="200"
|
||||||
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
|
MaxWidth="400"
|
||||||
<vm:LoadingWindowViewModel/>
|
MaxHeight="200"
|
||||||
</Design.DataContext>
|
Background="#353535"
|
||||||
|
>
|
||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="50"/>
|
<RowDefinition Height="50" />
|
||||||
<RowDefinition Height="*"/>
|
<RowDefinition Height="*" />
|
||||||
<RowDefinition Height="50"/>
|
<RowDefinition Height="50" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="*"/>
|
<ColumnDefinition Width="*" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
<StackPanel
|
||||||
|
Grid.Row="0"
|
||||||
|
Grid.ColumnSpan="2" >
|
||||||
|
|
||||||
<TextBlock Text="Loading minecraft..."
|
<TextBlock
|
||||||
FontFamily="{StaticResource QuicksandFont}"
|
Text="Loading minecraft..."
|
||||||
HorizontalAlignment="Center"
|
FontFamily="{StaticResource QuicksandFont}"
|
||||||
Grid.Row="0" Grid.ColumnSpan="2"/>
|
HorizontalAlignment="Center" />
|
||||||
|
<!-- Todo: idk but installAsync ignores token. -->
|
||||||
|
<!-- <Button HorizontalAlignment="Center"
|
||||||
|
Content="Stop" Click="onStopDownloadClick" /> -->
|
||||||
|
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
|
||||||
<Border
|
<Border
|
||||||
Grid.Row="1" Grid.Column="1"
|
Grid.Row="1"
|
||||||
|
Grid.Column="1"
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
VerticalAlignment="Center">
|
VerticalAlignment="Center">
|
||||||
<TextBlock Text="{Binding LoadingStatus}"/>
|
|
||||||
|
<TextBlock Text="{Binding LoadingStatus}" />
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
<Border
|
<Border Margin="10" Grid.Row="2" Grid.ColumnSpan="2">
|
||||||
Margin="10"
|
<ProgressBar Minimum="0" Value="{Binding Progress}" Maximum="100" />
|
||||||
Grid.Row="2" Grid.ColumnSpan="2">
|
|
||||||
<ProgressBar
|
|
||||||
Minimum="0"
|
|
||||||
Value="{Binding Progress}"
|
|
||||||
Maximum="100"/>
|
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</Window>
|
</Window>
|
||||||
|
@ -3,17 +3,22 @@ using System.Threading.Tasks;
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.VisualTree;
|
using Avalonia.VisualTree;
|
||||||
using BlightFlame;
|
using PlombirLauncher;
|
||||||
using LauncherGUI.ViewModels;
|
using LauncherGUI.ViewModels;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace LauncherGUI.Views;
|
namespace LauncherGUI.Views;
|
||||||
|
|
||||||
public partial class LoadingWindow : Window
|
public partial class LoadingWindow : Window
|
||||||
{
|
{
|
||||||
private Launcher ln;
|
private Launcher ln;
|
||||||
public LoadingWindow(string nickname, string? version = null)
|
private Task _buildingTask;
|
||||||
|
|
||||||
|
// Tokens for controlling download task.
|
||||||
|
CancellationTokenSource tokenSource = new CancellationTokenSource();
|
||||||
|
public LoadingWindow(string nickname, string? version = null, string? location = null)
|
||||||
{
|
{
|
||||||
ln = new Launcher(nickname, version ?? "1.20.1");
|
ln = new Launcher(nickname, version ?? "1.20.1", location ?? "./runtime");
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
DataContext = new LoadingWindowViewModel();
|
DataContext = new LoadingWindowViewModel();
|
||||||
}
|
}
|
||||||
@ -25,6 +30,7 @@ public partial class LoadingWindow : Window
|
|||||||
{
|
{
|
||||||
throw new InvalidOperationException("No DataContext set");
|
throw new InvalidOperationException("No DataContext set");
|
||||||
}
|
}
|
||||||
|
|
||||||
Task updateGui = new Task(async () => {
|
Task updateGui = new Task(async () => {
|
||||||
while (ln.DownloadStatus != "Finished!"){
|
while (ln.DownloadStatus != "Finished!"){
|
||||||
viewModel.Progress = ln.DownloadProgress;
|
viewModel.Progress = ln.DownloadProgress;
|
||||||
@ -33,16 +39,27 @@ public partial class LoadingWindow : Window
|
|||||||
}
|
}
|
||||||
viewModel.Progress = 100;
|
viewModel.Progress = 100;
|
||||||
});
|
});
|
||||||
|
|
||||||
updateGui.Start();
|
updateGui.Start();
|
||||||
|
|
||||||
await ln.BuildLauncher();
|
|
||||||
|
_buildingTask = ln.BuildLauncher(tokenSource.Token);
|
||||||
|
|
||||||
|
await _buildingTask;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RunMinecraft()
|
public async Task RunMinecraft()
|
||||||
{
|
{
|
||||||
await ln.RunLauncher();
|
await ln.RunLauncher();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onStopDownloadClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var button = sender as Button;
|
||||||
|
tokenSource.Cancel();
|
||||||
|
System.Console.WriteLine("Loading disabled gracefully.");
|
||||||
|
Close();
|
||||||
|
}
|
||||||
}
|
}
|
@ -48,8 +48,25 @@
|
|||||||
|
|
||||||
</Border>
|
</Border>
|
||||||
<TextBlock FontFamily="{StaticResource QuicksandFont}"
|
<TextBlock FontFamily="{StaticResource QuicksandFont}"
|
||||||
HorizontalAlignment="Right" Text="v1.0.0 - nullmax17"/>
|
HorizontalAlignment="Right" Text="v1.1.0 - nullmax17"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
<Canvas Grid.Row="0" Grid.Column="1">
|
||||||
|
<Border
|
||||||
|
Background="#353535"
|
||||||
|
CornerRadius="10"
|
||||||
|
Margin="5"
|
||||||
|
Canvas.Left="290">
|
||||||
|
|
||||||
|
<Image
|
||||||
|
Height="60"
|
||||||
|
Source="/Assets/cog.png"
|
||||||
|
Stretch="Uniform"
|
||||||
|
PointerPressed="OnCogPressed" />
|
||||||
|
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
</Canvas>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -98,26 +115,35 @@
|
|||||||
HorizontalAlignment="Center"/>
|
HorizontalAlignment="Center"/>
|
||||||
</Border>
|
</Border>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
<StackPanel Height="300" Grid.Row="1" Grid.Column="2">
|
||||||
|
<Border
|
||||||
|
Background="#353535"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Width="305"
|
||||||
|
CornerRadius="10"
|
||||||
|
Padding="15" Margin="15">
|
||||||
|
|
||||||
|
<StackPanel>
|
||||||
|
<TextBlock FontFamily="{StaticResource QuicksandFont}" Text="> Cross-platform minecraft launcher!"/>
|
||||||
|
<TextBlock FontFamily="{StaticResource QuicksandFont}" Height="50" Text="> Fully open-source and privacy focused!"/>
|
||||||
|
<TextBlock FontFamily="{StaticResource QuicksandFont}" Text="To use it:"/>
|
||||||
|
<TextBlock FontFamily="{StaticResource QuicksandFont}" Text="1. Choose desired nickname."/>
|
||||||
|
<TextBlock FontFamily="{StaticResource QuicksandFont}" Text="2. Choose desired minecraft version."/>
|
||||||
|
<TextBlock FontFamily="{StaticResource QuicksandFont}" Height="50" Text="3. Launch minecraft!"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
<Border
|
</Border>
|
||||||
Background="#353535"
|
<Canvas>
|
||||||
HorizontalAlignment="Center"
|
<Image
|
||||||
Width="305"
|
Height="60"
|
||||||
Height="300"
|
Source="/Assets/gitlab-logo.png"
|
||||||
CornerRadius="10"
|
Stretch="Uniform"
|
||||||
Padding="15" Margin="15"
|
PointerPressed="OnGitlabPressed"
|
||||||
Grid.Row="1" Grid.Column="2">
|
Canvas.Left="290"
|
||||||
|
Canvas.Top="80"/>
|
||||||
<StackPanel>
|
</Canvas>
|
||||||
<TextBlock FontFamily="{StaticResource QuicksandFont}" Text="> Cross-platform minecraft launcher!"/>
|
|
||||||
<TextBlock FontFamily="{StaticResource QuicksandFont}" Height="50" Text="> Fully open-source and privacy focused!"/>
|
</StackPanel>
|
||||||
<TextBlock FontFamily="{StaticResource QuicksandFont}" Text="To use it:"/>
|
|
||||||
<TextBlock FontFamily="{StaticResource QuicksandFont}" Text="1. Choose desired nickname."/>
|
|
||||||
<TextBlock FontFamily="{StaticResource QuicksandFont}" Text="2. Choose desired minecraft version."/>
|
|
||||||
<TextBlock FontFamily="{StaticResource QuicksandFont}" Height="50" Text="3. Launch minecraft!"/>
|
|
||||||
</StackPanel>
|
|
||||||
|
|
||||||
</Border>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
</Window>
|
</Window>
|
||||||
|
@ -4,9 +4,11 @@ using System.Linq;
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.VisualTree;
|
using Avalonia.VisualTree;
|
||||||
using BlightFlame;
|
using PlombirLauncher;
|
||||||
using CmlLib.Core.VersionMetadata;
|
using CmlLib.Core.VersionMetadata;
|
||||||
using LauncherGUI.ViewModels;
|
using LauncherGUI.ViewModels;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace LauncherGUI.Views;
|
namespace LauncherGUI.Views;
|
||||||
|
|
||||||
@ -17,7 +19,7 @@ public partial class MainWindow : Window
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
DataContext = new MainWindowViewModel();
|
DataContext = new MainWindowViewModel();
|
||||||
if (DataContext == null) throw new NullReferenceException("Cant load MainWindow DataContext");
|
if (DataContext == null) throw new NullReferenceException("Failed to set DataContext for MainWindow");
|
||||||
}
|
}
|
||||||
private async void OnLaunchMinecraftClick(object sender, RoutedEventArgs e)
|
private async void OnLaunchMinecraftClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
@ -29,26 +31,59 @@ public partial class MainWindow : Window
|
|||||||
if (root == null) return;
|
if (root == null) return;
|
||||||
|
|
||||||
var vm = DataContext as MainWindowViewModel;
|
var vm = DataContext as MainWindowViewModel;
|
||||||
LoadingWindow loading = new(vm.Usernick, vm.SelectedVersion);
|
await LauncherUtils.CreateMinecraftInstance(vm, root);
|
||||||
loading.Show(root);
|
|
||||||
await loading.InitLoading();
|
|
||||||
loading.Close();
|
|
||||||
button.Content = "Minecraft launched";
|
button.Content = "Minecraft launched";
|
||||||
await loading.RunMinecraft();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnChooseVersionClick(object sender, RoutedEventArgs e)
|
private void OnChooseVersionClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (sender is not Button button) return;
|
||||||
|
|
||||||
var button = sender as Button;
|
if (button.GetVisualRoot() is not MainWindow root) return;
|
||||||
if (button == null) return;
|
|
||||||
|
|
||||||
var root = button.GetVisualRoot() as MainWindow;
|
|
||||||
if (root == null) return;
|
|
||||||
|
|
||||||
VersionSelectorWindow selector = new(DataContext as MainWindowViewModel);
|
VersionSelectorWindow selector = new(DataContext as MainWindowViewModel);
|
||||||
selector.Show(root);
|
selector.Show(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnCogPressed(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is not Image img) return;
|
||||||
|
|
||||||
|
if (img.GetVisualRoot() is not MainWindow root) return;
|
||||||
|
|
||||||
|
SettingsWindow settings = new(DataContext as MainWindowViewModel);
|
||||||
|
settings.Show(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnGitlabPressed(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
string url = "https://gitlab.com/nullmax17/PlombirLauncher";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Process.Start(url);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// hack because of this: https://github.com/dotnet/corefx/issues/10361
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
{
|
||||||
|
url = url.Replace("&", "^&");
|
||||||
|
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
|
||||||
|
}
|
||||||
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
{
|
||||||
|
Process.Start("xdg-open", url);
|
||||||
|
}
|
||||||
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||||
|
{
|
||||||
|
Process.Start("open", url);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
54
src/LauncherGUI/Views/SettingsWindow.axaml
Normal file
54
src/LauncherGUI/Views/SettingsWindow.axaml
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<Window
|
||||||
|
xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:LauncherGUI.ViewModels"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DesignWidth="500"
|
||||||
|
d:DesignHeight="400"
|
||||||
|
x:Class="LauncherGUI.Views.SettingsWindow"
|
||||||
|
x:DataType="vm:SettingsWindowViewModel"
|
||||||
|
Icon="/Assets/icon.png"
|
||||||
|
Title="Launcher tweaks"
|
||||||
|
RequestedThemeVariant="Dark"
|
||||||
|
Width="500"
|
||||||
|
Height="400"
|
||||||
|
MinWidth="500"
|
||||||
|
MinHeight="400"
|
||||||
|
Background="#353535"
|
||||||
|
>
|
||||||
|
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
|
<TextBlock
|
||||||
|
Grid.Row="0" Grid.ColumnSpan="2"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Text="All tweaks can be found in TOML near executable."
|
||||||
|
FontFamily="{StaticResource QuicksandFont}" />
|
||||||
|
<StackPanel
|
||||||
|
Grid.Row="1" Grid.Column="0">
|
||||||
|
|
||||||
|
<Button Margin="5" Content="Select minecraft folder" Click="OnFilePickerClick" />
|
||||||
|
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<StackPanel Grid.Row="2" Grid.Column="1">
|
||||||
|
<Image Source="/Assets/toml-paper.png"
|
||||||
|
Stretch="Uniform"/>
|
||||||
|
|
||||||
|
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
</Window>
|
41
src/LauncherGUI/Views/SettingsWindow.axaml.cs
Normal file
41
src/LauncherGUI/Views/SettingsWindow.axaml.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
using Avalonia.Platform.Storage;
|
||||||
|
using LauncherGUI.ViewModels;
|
||||||
|
using PlombirLauncher;
|
||||||
|
|
||||||
|
namespace LauncherGUI.Views;
|
||||||
|
|
||||||
|
public partial class SettingsWindow : Window
|
||||||
|
{
|
||||||
|
private MainWindowViewModel _mainWindowVM;
|
||||||
|
public SettingsWindow(MainWindowViewModel mainWindowVM)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_mainWindowVM = mainWindowVM;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnFilePickerClick(object sender, RoutedEventArgs args)
|
||||||
|
{
|
||||||
|
// Get top level from the current control. Alternatively, you can use Window reference instead.
|
||||||
|
var topLevel = TopLevel.GetTopLevel(this);
|
||||||
|
|
||||||
|
// Start async operation to open the dialog.
|
||||||
|
var files = await topLevel.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
|
||||||
|
{
|
||||||
|
Title = "Select directory for minecraft",
|
||||||
|
AllowMultiple = false
|
||||||
|
});
|
||||||
|
|
||||||
|
if (files.Count >= 1)
|
||||||
|
{
|
||||||
|
var location = files[0].TryGetLocalPath();
|
||||||
|
if (location is null) throw new NullReferenceException("Invalid location selected!");
|
||||||
|
_mainWindowVM.RuntimeLocation = location;
|
||||||
|
System.Console.WriteLine($"Selected {_mainWindowVM.RuntimeLocation}.");
|
||||||
|
ConfigManager.WriteInConfig("runtime-path", location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,7 @@ using System.Threading.Tasks;
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using LauncherGUI.ViewModels;
|
using LauncherGUI.ViewModels;
|
||||||
|
using PlombirLauncher;
|
||||||
|
|
||||||
namespace LauncherGUI.Views;
|
namespace LauncherGUI.Views;
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ public partial class VersionSelectorWindow : Window
|
|||||||
_mainViewModel = mainViewModel;
|
_mainViewModel = mainViewModel;
|
||||||
|
|
||||||
//Load versions asynchronously
|
//Load versions asynchronously
|
||||||
var versionsList = Task.Run(() => BlightFlame.Utils.GetAllMcVersions().GetAwaiter().GetResult());
|
var versionsList = Task.Run(() => PlombirLauncher.Utils.GetAllMcVersions().GetAwaiter().GetResult());
|
||||||
|
|
||||||
versions.ItemsSource = versionsList.Result;
|
versions.ItemsSource = versionsList.Result;
|
||||||
|
|
||||||
@ -28,15 +29,10 @@ public partial class VersionSelectorWindow : Window
|
|||||||
|
|
||||||
_mainViewModel.SelectedVersion = selectedVersion;
|
_mainViewModel.SelectedVersion = selectedVersion;
|
||||||
|
|
||||||
|
|
||||||
System.Console.WriteLine($"Selected version: {selectedVersion}");
|
System.Console.WriteLine($"Selected version: {selectedVersion}");
|
||||||
|
|
||||||
LoadingWindow loading = new(_mainViewModel.Usernick, _mainViewModel.SelectedVersion);
|
LauncherUtils.CreateMinecraftInstance(_mainViewModel, this);
|
||||||
loading.Show(this);
|
Close();
|
||||||
await loading.InitLoading();
|
|
||||||
loading.Close();
|
|
||||||
this.Close();
|
|
||||||
await loading.RunMinecraft();;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
4
src/LauncherGUI/tweaks.toml
Normal file
4
src/LauncherGUI/tweaks.toml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
title = "Launcher tweaks file!"
|
||||||
|
runtime-path = "/home/nullmax17/test_folder"
|
||||||
|
last-version-launched = "1.15"
|
||||||
|
nickname = "nullmax17"
|
Loading…
x
Reference in New Issue
Block a user