diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f74277 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/package/out diff --git a/src/Launcher/.gitignore b/Launcher-Core/.gitignore similarity index 100% rename from src/Launcher/.gitignore rename to Launcher-Core/.gitignore diff --git a/src/Launcher/cmllibLauncher.csproj b/Launcher-Core/Launcher-Core.csproj similarity index 100% rename from src/Launcher/cmllibLauncher.csproj rename to Launcher-Core/Launcher-Core.csproj diff --git a/Launcher-Core/Launcher.cs b/Launcher-Core/Launcher.cs new file mode 100644 index 0000000..511dcc3 --- /dev/null +++ b/Launcher-Core/Launcher.cs @@ -0,0 +1,72 @@ +using System.Formats.Tar; +using System.Net; +using System.Runtime.InteropServices; +using System.Security.AccessControl; +using CmlLib.Core; +using CmlLib.Core.Auth; +using CmlLib.Core.ProcessBuilder; + +namespace Plombir; + +/* + Basically a class to manage everything launcher related. + TODO - minecraft downloading from webserver +*/ +public class Launcher +{ + private readonly string _version; + private readonly string _nickname; + static private MinecraftPath? _mcPath; + static private MinecraftLauncher? _mcLauncher; + + public int DownloadProgress; + public string? DownloadStatus; + + public Launcher(string userName, string version, string? location = null) + { + _version = version; + _nickname = userName; + _mcPath = new($"{location}/{version}/minecraft"); + _mcLauncher = new(_mcPath); + } + + async public Task BuildLauncher(CancellationToken token) + { + if (_mcLauncher is null) + throw new NullReferenceException("Failed to build! Launcher is null!"); + + _mcLauncher.ByteProgressChanged += (_, args) => + { + Console.WriteLine($"{(int)(args.ProgressedBytes * 0.000001)} MBytes / {(int)(args.TotalBytes * 0.000001)} MBytes"); + DownloadProgress = (int)(args.ProgressedBytes * 100 / args.TotalBytes); + }; + + DownloadStatus = "Installing minecraft..."; + Console.WriteLine(DownloadStatus); + await _mcLauncher.InstallAsync(_version); + DownloadStatus = "Finished!"; + Console.WriteLine(DownloadStatus); + return; + } + + async public Task RunLauncher() + { + if (_mcLauncher is null) + throw new NullReferenceException("Failed to run launcher! Launcher is null!"); + + var process = await _mcLauncher.BuildProcessAsync(_version, new MLaunchOption + { + + Session = MSession.CreateOfflineSession(_nickname), + MaximumRamMb = 4096, + + }) ?? throw new Exception("Failed to start minecraft process!"); + + var processUtil = new ProcessWrapper(process); + processUtil.OutputReceived += (s, e) => Console.WriteLine(e); + processUtil.StartWithEvents(); + + await processUtil.WaitForExitTaskAsync(); + } + +} diff --git a/Launcher-Core/Program.cs b/Launcher-Core/Program.cs new file mode 100644 index 0000000..7a3ff86 --- /dev/null +++ b/Launcher-Core/Program.cs @@ -0,0 +1,9 @@ +namespace Plombir; + +sealed class Program +{ + public static void Main() + { + Console.WriteLine("init: launcher"); + } +} diff --git a/Launcher-Core/Utils.cs b/Launcher-Core/Utils.cs new file mode 100644 index 0000000..86cf813 --- /dev/null +++ b/Launcher-Core/Utils.cs @@ -0,0 +1,32 @@ +using System.IO.Compression; +using System; +using System.IO; +using SharpCompress.Archives; +using SharpCompress.Common; +using SharpCompress.Readers; +using System.Diagnostics; +using CmlLib.Core; + +namespace Plombir; + +static public class Utils +{ + + public static async Task> GetAllMcVersions() + { + return await Task.Run(async () => + { + var ln = new MinecraftLauncher(); + var result = new List(); + foreach (var x in await ln.GetAllVersionsAsync()) + { + result.Add(x.Name); + } + return result; + }); + + } + + + +} diff --git a/src/LauncherGUI/.gitignore b/Launcher-UI/.gitignore similarity index 100% rename from src/LauncherGUI/.gitignore rename to Launcher-UI/.gitignore diff --git a/Launcher-UI/App.axaml b/Launcher-UI/App.axaml new file mode 100644 index 0000000..fa69988 --- /dev/null +++ b/Launcher-UI/App.axaml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + avares://Launcher-UI/Assets/Fonts/Quicksand-SemiBold.ttf#Quicksand + + + diff --git a/src/LauncherGUI/App.axaml.cs b/Launcher-UI/App.axaml.cs similarity index 100% rename from src/LauncherGUI/App.axaml.cs rename to Launcher-UI/App.axaml.cs diff --git a/src/LauncherGUI/Assets/Fonts/Quicksand-SemiBold.ttf b/Launcher-UI/Assets/Fonts/Quicksand-SemiBold.ttf similarity index 100% rename from src/LauncherGUI/Assets/Fonts/Quicksand-SemiBold.ttf rename to Launcher-UI/Assets/Fonts/Quicksand-SemiBold.ttf diff --git a/src/LauncherGUI/Assets/background.jpg b/Launcher-UI/Assets/background.jpg similarity index 100% rename from src/LauncherGUI/Assets/background.jpg rename to Launcher-UI/Assets/background.jpg diff --git a/src/LauncherGUI/Assets/cog.png b/Launcher-UI/Assets/cog.png similarity index 100% rename from src/LauncherGUI/Assets/cog.png rename to Launcher-UI/Assets/cog.png diff --git a/src/LauncherGUI/Assets/gitlab-logo.png b/Launcher-UI/Assets/gitlab-logo.png similarity index 100% rename from src/LauncherGUI/Assets/gitlab-logo.png rename to Launcher-UI/Assets/gitlab-logo.png diff --git a/src/LauncherGUI/Assets/icon.png b/Launcher-UI/Assets/icon.png similarity index 100% rename from src/LauncherGUI/Assets/icon.png rename to Launcher-UI/Assets/icon.png diff --git a/src/LauncherGUI/Assets/title.png b/Launcher-UI/Assets/title.png similarity index 100% rename from src/LauncherGUI/Assets/title.png rename to Launcher-UI/Assets/title.png diff --git a/src/LauncherGUI/Assets/toml-paper.png b/Launcher-UI/Assets/toml-paper.png similarity index 100% rename from src/LauncherGUI/Assets/toml-paper.png rename to Launcher-UI/Assets/toml-paper.png diff --git a/src/LauncherGUI/ConfigManager.cs b/Launcher-UI/ConfigManager.cs similarity index 83% rename from src/LauncherGUI/ConfigManager.cs rename to Launcher-UI/ConfigManager.cs index 2d6124e..5a3e796 100644 --- a/src/LauncherGUI/ConfigManager.cs +++ b/Launcher-UI/ConfigManager.cs @@ -2,7 +2,7 @@ using System; using System.IO; using Tommy; -namespace PlombirLauncher; +namespace Plombir; public class ConfigManager { @@ -27,7 +27,7 @@ public class ConfigManager ["nickname"] = "slugcat" }; - using(StreamWriter writer = File.CreateText("tweaks.toml")) + using (StreamWriter writer = File.CreateText("tweaks.toml")) { toml.WriteTo(writer); // Remember to flush the data if needed! @@ -41,7 +41,7 @@ public class ConfigManager { BuildDefault(); } - using(StreamReader reader = File.OpenText("tweaks.toml")) + using (StreamReader reader = File.OpenText("tweaks.toml")) { TomlTable table = TOML.Parse(reader); @@ -58,18 +58,18 @@ public class ConfigManager TomlTable table; - using(StreamReader reader = File.OpenText("tweaks.toml")) + using (StreamReader reader = File.OpenText("tweaks.toml")) { table = TOML.Parse(reader); table[key] = value; } - using(StreamWriter writer = File.CreateText("tweaks.toml")) + using (StreamWriter writer = File.CreateText("tweaks.toml")) { table.WriteTo(writer); // Remember to flush the data if needed! writer.Flush(); } } -} \ No newline at end of file +} diff --git a/src/LauncherGUI/LauncherGUI.csproj b/Launcher-UI/Launcher-UI.csproj similarity index 93% rename from src/LauncherGUI/LauncherGUI.csproj rename to Launcher-UI/Launcher-UI.csproj index ffb860d..e73fc7c 100644 --- a/src/LauncherGUI/LauncherGUI.csproj +++ b/Launcher-UI/Launcher-UI.csproj @@ -32,6 +32,7 @@ - + + diff --git a/src/LauncherGUI/LauncherUtils.cs b/Launcher-UI/LauncherUtils.cs similarity index 71% rename from src/LauncherGUI/LauncherUtils.cs rename to Launcher-UI/LauncherUtils.cs index 4d66092..dc0dd1f 100644 --- a/src/LauncherGUI/LauncherUtils.cs +++ b/Launcher-UI/LauncherUtils.cs @@ -1,14 +1,18 @@ +using System; using System.Threading.Tasks; using Avalonia.Controls; using LauncherGUI.ViewModels; using LauncherGUI.Views; -namespace PlombirLauncher; +namespace Plombir; public class LauncherUtils { public async static Task CreateMinecraftInstance(MainWindowViewModel vm, Window windowCaller) { + if (vm.Usernick is null) throw new NullReferenceException("Failed to create minecraft instance! Nickname is null!"); + if (vm.SelectedVersion is null) throw new NullReferenceException("Failed to create minecraft instance! Selected version is null!"); + 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); @@ -20,4 +24,4 @@ public class LauncherUtils await loading.RunMinecraft(); return; } -} \ No newline at end of file +} diff --git a/Launcher-UI/PlombirLinux-v1-1-0.tar.gz b/Launcher-UI/PlombirLinux-v1-1-0.tar.gz new file mode 100644 index 0000000..229151a Binary files /dev/null and b/Launcher-UI/PlombirLinux-v1-1-0.tar.gz differ diff --git a/Launcher-UI/PlombirWindows-v1-1-0.tar.gz b/Launcher-UI/PlombirWindows-v1-1-0.tar.gz new file mode 100644 index 0000000..229151a Binary files /dev/null and b/Launcher-UI/PlombirWindows-v1-1-0.tar.gz differ diff --git a/src/LauncherGUI/Program.cs b/Launcher-UI/Program.cs similarity index 91% rename from src/LauncherGUI/Program.cs rename to Launcher-UI/Program.cs index 860be03..b9c7da5 100644 --- a/src/LauncherGUI/Program.cs +++ b/Launcher-UI/Program.cs @@ -1,5 +1,5 @@ -using Avalonia; -using PlombirLauncher; +using Avalonia; +using Plombir; using System; namespace LauncherGUI; diff --git a/src/LauncherGUI/ViewLocator.cs b/Launcher-UI/ViewLocator.cs similarity index 100% rename from src/LauncherGUI/ViewLocator.cs rename to Launcher-UI/ViewLocator.cs diff --git a/src/LauncherGUI/ViewModels/LoadingWindowViewModel.cs b/Launcher-UI/ViewModels/LoadingWindowViewModel.cs similarity index 100% rename from src/LauncherGUI/ViewModels/LoadingWindowViewModel.cs rename to Launcher-UI/ViewModels/LoadingWindowViewModel.cs diff --git a/Launcher-UI/ViewModels/MainWindowViewModel.cs b/Launcher-UI/ViewModels/MainWindowViewModel.cs new file mode 100644 index 0000000..f334bfd --- /dev/null +++ b/Launcher-UI/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using Plombir; + +namespace LauncherGUI.ViewModels; + +public partial class MainWindowViewModel : ViewModelBase +{ + public string Greeting { get; } = "Plombir launcher"; + + private string? _userNick = ConfigManager.ReadConfig("nickname"); + public string? Usernick { get => _userNick; set { _userNick = value; OnPropertyChanged(nameof(Usernick)); } } + + private string? _selectedVersion = ConfigManager.ReadConfig("last-version-launched"); + 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)); } } +} diff --git a/src/LauncherGUI/ViewModels/SettingsWindowViewModel.cs b/Launcher-UI/ViewModels/SettingsWindowViewModel.cs similarity index 100% rename from src/LauncherGUI/ViewModels/SettingsWindowViewModel.cs rename to Launcher-UI/ViewModels/SettingsWindowViewModel.cs diff --git a/src/LauncherGUI/ViewModels/VersionSelectorWindowViewModel.cs b/Launcher-UI/ViewModels/VersionSelectorWindowViewModel.cs similarity index 90% rename from src/LauncherGUI/ViewModels/VersionSelectorWindowViewModel.cs rename to Launcher-UI/ViewModels/VersionSelectorWindowViewModel.cs index f9c2fdf..5c26947 100644 --- a/src/LauncherGUI/ViewModels/VersionSelectorWindowViewModel.cs +++ b/Launcher-UI/ViewModels/VersionSelectorWindowViewModel.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using PlombirLauncher; +using Plombir; using LauncherGUI.ViewModels; namespace LauncherGUI.ViewModels; @@ -7,4 +7,4 @@ namespace LauncherGUI.ViewModels; public partial class VersionSelectorWindowViewModel : ViewModelBase { // I save launcher data mostly in MainWindowViewModel. -} \ No newline at end of file +} diff --git a/src/LauncherGUI/ViewModels/ViewModelBase.cs b/Launcher-UI/ViewModels/ViewModelBase.cs similarity index 100% rename from src/LauncherGUI/ViewModels/ViewModelBase.cs rename to Launcher-UI/ViewModels/ViewModelBase.cs diff --git a/src/LauncherGUI/Views/LoadingWindow.axaml b/Launcher-UI/Views/LoadingWindow.axaml similarity index 100% rename from src/LauncherGUI/Views/LoadingWindow.axaml rename to Launcher-UI/Views/LoadingWindow.axaml diff --git a/src/LauncherGUI/Views/LoadingWindow.axaml.cs b/Launcher-UI/Views/LoadingWindow.axaml.cs similarity index 80% rename from src/LauncherGUI/Views/LoadingWindow.axaml.cs rename to Launcher-UI/Views/LoadingWindow.axaml.cs index 879574c..1f9aeac 100644 --- a/src/LauncherGUI/Views/LoadingWindow.axaml.cs +++ b/Launcher-UI/Views/LoadingWindow.axaml.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.VisualTree; -using PlombirLauncher; +using Plombir; using LauncherGUI.ViewModels; using System.Threading; @@ -12,9 +12,9 @@ namespace LauncherGUI.Views; public partial class LoadingWindow : Window { private Launcher ln; - private Task _buildingTask; + private Task? _buildingTask; - // Tokens for controlling download task. + // Tokens for controlling download task. CancellationTokenSource tokenSource = new CancellationTokenSource(); public LoadingWindow(string nickname, string? version = null, string? location = null) { @@ -23,7 +23,7 @@ public partial class LoadingWindow : Window DataContext = new LoadingWindowViewModel(); } - public async Task InitLoading() + public async Task InitLoading() { var viewModel = DataContext as LoadingWindowViewModel; if (viewModel == null) @@ -31,10 +31,12 @@ public partial class LoadingWindow : Window throw new InvalidOperationException("No DataContext set"); } - Task updateGui = new Task(async () => { - while (ln.DownloadStatus != "Finished!"){ + Task updateGui = new Task(async () => + { + while (ln.DownloadStatus != "Finished!") + { viewModel.Progress = ln.DownloadProgress; - viewModel.LoadingStatus = ln.DownloadStatus; + viewModel.LoadingStatus = ln.DownloadStatus ?? "Looking at qubits..."; await Task.Delay(1000); } viewModel.Progress = 100; @@ -42,12 +44,12 @@ public partial class LoadingWindow : Window updateGui.Start(); - + _buildingTask = ln.BuildLauncher(tokenSource.Token); await _buildingTask; - - + + } public async Task RunMinecraft() @@ -62,4 +64,4 @@ public partial class LoadingWindow : Window System.Console.WriteLine("Loading disabled gracefully."); Close(); } -} \ No newline at end of file +} diff --git a/src/LauncherGUI/Views/MainWindow.axaml b/Launcher-UI/Views/MainWindow.axaml similarity index 100% rename from src/LauncherGUI/Views/MainWindow.axaml rename to Launcher-UI/Views/MainWindow.axaml diff --git a/src/LauncherGUI/Views/MainWindow.axaml.cs b/Launcher-UI/Views/MainWindow.axaml.cs similarity index 95% rename from src/LauncherGUI/Views/MainWindow.axaml.cs rename to Launcher-UI/Views/MainWindow.axaml.cs index 5dc7429..3e22395 100644 --- a/src/LauncherGUI/Views/MainWindow.axaml.cs +++ b/Launcher-UI/Views/MainWindow.axaml.cs @@ -4,7 +4,7 @@ using System.Linq; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.VisualTree; -using PlombirLauncher; +using Plombir; using CmlLib.Core.VersionMetadata; using LauncherGUI.ViewModels; using System.Diagnostics; @@ -29,11 +29,11 @@ public partial class MainWindow : Window var root = button.GetVisualRoot() as MainWindow; if (root == null) return; - + var vm = DataContext as MainWindowViewModel; await LauncherUtils.CreateMinecraftInstance(vm, root); button.Content = "Minecraft launched"; - + } private void OnChooseVersionClick(object sender, RoutedEventArgs e) @@ -86,4 +86,4 @@ public partial class MainWindow : Window } } -} \ No newline at end of file +} diff --git a/src/LauncherGUI/Views/SettingsWindow.axaml b/Launcher-UI/Views/SettingsWindow.axaml similarity index 100% rename from src/LauncherGUI/Views/SettingsWindow.axaml rename to Launcher-UI/Views/SettingsWindow.axaml diff --git a/src/LauncherGUI/Views/SettingsWindow.axaml.cs b/Launcher-UI/Views/SettingsWindow.axaml.cs similarity index 92% rename from src/LauncherGUI/Views/SettingsWindow.axaml.cs rename to Launcher-UI/Views/SettingsWindow.axaml.cs index 5379973..572dbe5 100644 --- a/src/LauncherGUI/Views/SettingsWindow.axaml.cs +++ b/Launcher-UI/Views/SettingsWindow.axaml.cs @@ -3,7 +3,7 @@ using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Platform.Storage; using LauncherGUI.ViewModels; -using PlombirLauncher; +using Plombir; namespace LauncherGUI.Views; @@ -21,6 +21,7 @@ public partial class SettingsWindow : Window // Get top level from the current control. Alternatively, you can use Window reference instead. var topLevel = TopLevel.GetTopLevel(this); + if (topLevel is null) throw new NullReferenceException("Failed to start file picker!"); // Start async operation to open the dialog. var files = await topLevel.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions { @@ -38,4 +39,3 @@ public partial class SettingsWindow : Window } } } - diff --git a/src/LauncherGUI/Views/VersionSelectorWindow.axaml b/Launcher-UI/Views/VersionSelectorWindow.axaml similarity index 100% rename from src/LauncherGUI/Views/VersionSelectorWindow.axaml rename to Launcher-UI/Views/VersionSelectorWindow.axaml diff --git a/src/LauncherGUI/Views/VersionSelectorWindow.axaml.cs b/Launcher-UI/Views/VersionSelectorWindow.axaml.cs similarity index 82% rename from src/LauncherGUI/Views/VersionSelectorWindow.axaml.cs rename to Launcher-UI/Views/VersionSelectorWindow.axaml.cs index 96d8f0b..29f546d 100644 --- a/src/LauncherGUI/Views/VersionSelectorWindow.axaml.cs +++ b/Launcher-UI/Views/VersionSelectorWindow.axaml.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.Threading; using LauncherGUI.ViewModels; -using PlombirLauncher; +using Plombir; namespace LauncherGUI.Views; @@ -13,14 +13,14 @@ public partial class VersionSelectorWindow : Window private MainWindowViewModel _mainViewModel; public VersionSelectorWindow(MainWindowViewModel mainViewModel) { - InitializeComponent(); + InitializeComponent(); _mainViewModel = mainViewModel; //Load versions asynchronously - var versionsList = Task.Run(() => PlombirLauncher.Utils.GetAllMcVersions().GetAwaiter().GetResult()); - + var versionsList = Task.Run(() => Plombir.Utils.GetAllMcVersions().GetAwaiter().GetResult()); + versions.ItemsSource = versionsList.Result; - + } private async void OnSelectionChanged(object sender, SelectionChangedEventArgs e) @@ -30,10 +30,10 @@ public partial class VersionSelectorWindow : Window _mainViewModel.SelectedVersion = selectedVersion; System.Console.WriteLine($"Selected version: {selectedVersion}"); - + LauncherUtils.CreateMinecraftInstance(_mainViewModel, this); Close(); } -} \ No newline at end of file +} diff --git a/src/LauncherGUI/app.manifest b/Launcher-UI/app.manifest similarity index 100% rename from src/LauncherGUI/app.manifest rename to Launcher-UI/app.manifest diff --git a/Launcher-UI/tweaks.toml b/Launcher-UI/tweaks.toml new file mode 100644 index 0000000..3c7e373 --- /dev/null +++ b/Launcher-UI/tweaks.toml @@ -0,0 +1,6 @@ +title = "Launcher tweaks file!" +# Path to folder that will hold all minecraft versions +runtime-path = "./runtime" +# Saving last launched version to use it after launch +last-version-launched = "1.20.1" +nickname = "slugcat" diff --git a/package/build-targz-linux-ui.sh b/package/build-targz-linux-ui.sh new file mode 100755 index 0000000..dcac85e --- /dev/null +++ b/package/build-targz-linux-ui.sh @@ -0,0 +1,11 @@ +cd ../Launcher-UI + +out_dir=../package/out/build +archieve_name=PlombirLinux-v1-1-0.tar.gz + +rm -r $out_dir + +dotnet publish -r linux-x64 -o $out_dir -p:PublishReadyToRun=true -p:PublishSingleFile=true --self-contained true -p:IncludeNativeLibrariesForSelfExtract=true + +cd ../package/out +tar -czvf $archieve_name -C build/ . diff --git a/package/build-targz-osx-ui.sh b/package/build-targz-osx-ui.sh new file mode 100755 index 0000000..48b6b50 --- /dev/null +++ b/package/build-targz-osx-ui.sh @@ -0,0 +1,11 @@ +cd ../Launcher-UI + +out_dir=../package/out/build +archieve_name=PlombirOSX-v1-1-0.tar.gz + +rm -r $out_dir + +dotnet publish -r osx-x64 -o $out_dir -p:PublishReadyToRun=true -p:PublishSingleFile=true --self-contained true -p:IncludeNativeLibrariesForSelfExtract=true + +cd ../package/out +tar -czvf $archieve_name -C build/ . diff --git a/package/build-targz-win-ui.sh b/package/build-targz-win-ui.sh new file mode 100755 index 0000000..ccbcd6e --- /dev/null +++ b/package/build-targz-win-ui.sh @@ -0,0 +1,11 @@ +cd ../Launcher-UI + +out_dir=../package/out/build +archieve_name=PlombirWindows-v1-1-0.tar.gz + +rm -r $out_dir + +dotnet publish -r win-x64 -o $out_dir -p:PublishReadyToRun=true -p:PublishSingleFile=true --self-contained true -p:IncludeNativeLibrariesForSelfExtract=true + +cd ../package/out +tar -czvf $archieve_name -C build/ . diff --git a/src/Launcher/Launcher.cs b/src/Launcher/Launcher.cs deleted file mode 100644 index aeaa9f6..0000000 --- a/src/Launcher/Launcher.cs +++ /dev/null @@ -1,139 +0,0 @@ -using System.Formats.Tar; -using System.Net; -using System.Runtime.InteropServices; -using System.Security.AccessControl; -using CmlLib.Core; -using CmlLib.Core.Auth; -using CmlLib.Core.ProcessBuilder; - -namespace PlombirLauncher -{ - /* - Basically a class to manage everything launcher related. - TODO - minecraft downloading from webserver - */ - public class Launcher - { - private readonly string _version; - private readonly string _nickname; - static private MinecraftPath _mcPath; - static private MinecraftLauncher _mcLauncher; - - public int DownloadProgress; - public string DownloadStatus; - - public Launcher(string userName, string version, string? location = null) - { - _version = version; - _nickname = userName; - _mcPath = new($"{location}/{version}/minecraft"); - _mcLauncher = new(_mcPath); - } - - // Using it for forge loading because i don't know event-based async. - //static TaskCompletionSource tcs = new(); - - - // Not used. Because launcher supports only VANILLA. - // public async Task FetchMinecraft() - // { - - // string archieve = "mc-archieve.tar.xz"; - // string runtimePath = "runtime"; - - // System.Uri download_uri = new("https://dixxe.top/static/distro/cmllibcore-minecraft-forge-1201.tar.xz"); - // WebClient client = new(); - - // if ((!File.Exists(archieve)) && (!Directory.Exists(runtimePath))) - // { - // DownloadStatus = "Fetching deploy-minecraft from host..."; - // Console.WriteLine(DownloadStatus); - - // // Implement async download - // client.DownloadFileAsync(download_uri, archieve); - // client.DownloadDataCompleted += (o, e) => - // { - // DownloadStatus = "Download completed"; - // Console.WriteLine(DownloadStatus); - // }; - // client.DownloadProgressChanged += (o, e) => - // { - // // Curentlly this scope doing nothing - // Console.WriteLine($"{e.ProgressPercentage}% downloaded"); - // DownloadProgress = e.ProgressPercentage; - // DownloadStatus = "Fetching modpack..."; - - // if (DownloadProgress == 100) - // { - // tcs.SetResult(true); - // } - - // }; - // // Waiting for archieve to download. - // await tcs.Task; - // } - - // DownloadStatus = "Unarchiving modpack..."; - // unarchiveMinecraft(archieve, runtimePath); - - // } - - // Not used. Because launcher supports only VANILLA. - // private void unarchiveMinecraft(string archieveName, string path) - // { - // if (Directory.Exists(path)) { return; } - // Console.WriteLine(DownloadStatus); - // Directory.CreateDirectory(path); - // Utils.UnzipTarGzFile(archieveName, path); - - // if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - // { - // Utils.LinuxExec($"chmod -R +x {path}/"); - // Console.WriteLine("Execute permissions added successfully."); - // } - - // File.Delete(archieveName); - // } - - async public Task BuildLauncher(CancellationToken token) - { - _mcLauncher.ByteProgressChanged += (_, args) => - { - Console.WriteLine($"{(int)(args.ProgressedBytes * 0.000001)} MBytes / {(int)(args.TotalBytes * 0.000001)} MBytes"); - DownloadProgress = (int)(args.ProgressedBytes * 100 / args.TotalBytes); - }; - - // Before installAsync I should fetch lightweight minecraft instance from webserver - // Then installAsync will download any runtime needed stuff. - // This method is FetchMinecraft() - // Currently this is only one viable option for forge installations. - // But it requires server, so forge (and all mod loaders) is disabled. - //await FetchMinecraft(); - - DownloadStatus = "Installing minecraft..."; - Console.WriteLine(DownloadStatus); - await _mcLauncher.InstallAsync(_version); - DownloadStatus = "Finished!"; - Console.WriteLine(DownloadStatus); - return; - } - - async public Task RunLauncher() - { - var process = await _mcLauncher.BuildProcessAsync(_version, new MLaunchOption - { - - Session = MSession.CreateOfflineSession(_nickname), - MaximumRamMb = 4096, - - }) ?? throw new Exception("Failed to start minecraft process!"); - - var processUtil = new ProcessWrapper(process); - processUtil.OutputReceived += (s, e) => Console.WriteLine(e); - processUtil.StartWithEvents(); - - await processUtil.WaitForExitTaskAsync(); - } - - } -} diff --git a/src/Launcher/Program.cs b/src/Launcher/Program.cs deleted file mode 100644 index 052e051..0000000 --- a/src/Launcher/Program.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace PlombirLauncher -{ - sealed class Program - { - public static void Main() - { - Console.WriteLine("init: launcher"); - } - } -} \ No newline at end of file diff --git a/src/Launcher/Utils.cs b/src/Launcher/Utils.cs deleted file mode 100644 index 86fe32c..0000000 --- a/src/Launcher/Utils.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System.IO.Compression; -using System; -using System.IO; -using SharpCompress.Archives; -using SharpCompress.Common; -using SharpCompress.Readers; -using System.Diagnostics; -using CmlLib.Core; - -namespace PlombirLauncher -{ - static public class Utils - { - public static void UnzipTarGzFile(string filePath, string destinationPath) - { - using (Stream stream = File.OpenRead(filePath)) - { - using (var reader = ReaderFactory.Open(stream)) - { - while (reader.MoveToNextEntry()) - { - if (!reader.Entry.IsDirectory) - { - reader.WriteEntryToDirectory(destinationPath, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); - } - } - } - } - } - - public static void LinuxExec(string cmd) - { - var escapedArgs = cmd.Replace("\"", "\\\""); - - using var process = new Process - { - StartInfo = new ProcessStartInfo - { - RedirectStandardOutput = true, - UseShellExecute = false, - CreateNoWindow = true, - WindowStyle = ProcessWindowStyle.Hidden, - FileName = "/bin/bash", - Arguments = $"-c \"{escapedArgs}\"" - } - }; - - process.Start(); - process.WaitForExit(); - } - - public static async Task> GetAllMcVersions() - { - return await Task.Run(async() => { - var ln = new MinecraftLauncher(); - var result = new List(); - foreach (var x in await ln.GetAllVersionsAsync()) - { - result.Add(x.Name); - } - return result; - }); - - } - - - - } - -} \ No newline at end of file diff --git a/src/LauncherGUI/App.axaml b/src/LauncherGUI/App.axaml deleted file mode 100644 index 7f394db..0000000 --- a/src/LauncherGUI/App.axaml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - avares://LauncherGUI/Assets/Fonts/Quicksand-SemiBold.ttf#Quicksand - - - \ No newline at end of file diff --git a/src/LauncherGUI/Assets/Fonts/Quicksand.ttf b/src/LauncherGUI/Assets/Fonts/Quicksand.ttf deleted file mode 100644 index bd332b6..0000000 Binary files a/src/LauncherGUI/Assets/Fonts/Quicksand.ttf and /dev/null differ diff --git a/src/LauncherGUI/ViewModels/MainWindowViewModel.cs b/src/LauncherGUI/ViewModels/MainWindowViewModel.cs deleted file mode 100644 index 387e1d8..0000000 --- a/src/LauncherGUI/ViewModels/MainWindowViewModel.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections.Generic; -using PlombirLauncher; - -namespace LauncherGUI.ViewModels; - -public partial class MainWindowViewModel : ViewModelBase -{ - public string Greeting { get; } = "Plombir launcher"; - - private string _userNick = ConfigManager.ReadConfig("nickname"); - public string Usernick {get => _userNick; set {_userNick = value; OnPropertyChanged(nameof(Usernick)); }} - - private string _selectedVersion = ConfigManager.ReadConfig("last-version-launched"); - 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)); }} -} diff --git a/src/LauncherGUI/tweaks.toml b/src/LauncherGUI/tweaks.toml deleted file mode 100644 index 3eafe99..0000000 --- a/src/LauncherGUI/tweaks.toml +++ /dev/null @@ -1,4 +0,0 @@ -title = "Launcher tweaks file!" -runtime-path = "/home/nullmax17/test_folder" -last-version-launched = "1.15" -nickname = "nullmax17" diff --git a/tweaks.toml b/tweaks.toml new file mode 100644 index 0000000..3c7e373 --- /dev/null +++ b/tweaks.toml @@ -0,0 +1,6 @@ +title = "Launcher tweaks file!" +# Path to folder that will hold all minecraft versions +runtime-path = "./runtime" +# Saving last launched version to use it after launch +last-version-launched = "1.20.1" +nickname = "slugcat"