From 3525d78afc5d21468a39dd4f85205b36c87c9544 Mon Sep 17 00:00:00 2001 From: Chaniru Rajapakse Date: Tue, 24 May 2022 00:09:00 +0530 Subject: [PATCH] Bump to version 0.3.1 --- Client Launcher/Client Launcher.csproj | 9 + Client Launcher/Program.cs | 12 + ClientLauncher/ClientLauncher.csproj | 8 + ClientLauncher/Program.cs | 116 +++ Package/Package.appxmanifest | 21 +- Package/Package.wapproj | 1 + SDLauncher UWP.sln | 22 + SDLauncher UWP/App.xaml | 11 +- SDLauncher UWP/App.xaml.cs | 3 +- .../Converters/ProcessToXmlConverter.cs | 43 ++ .../Converters/StringToVisibility.cs | 47 ++ SDLauncher UWP/Dialogs/Login.xaml | 271 +++++++ SDLauncher UWP/{ => Dialogs}/Login.xaml.cs | 257 ++++--- .../{ => Dialogs}/MessageBoxEx.xaml | 4 +- .../{ => Dialogs}/MessageBoxEx.xaml.cs | 67 +- SDLauncher UWP/Helpers/Account.cs | 69 ++ SDLauncher UWP/Helpers/Localizer.cs | 20 + SDLauncher UWP/{ => Helpers}/MSLogin.cs | 2 +- SDLauncher UWP/{Views => Helpers}/OptiFine.cs | 145 ++-- SDLauncher UWP/Helpers/SDLauncher.cs | 228 ++++++ .../SettingsDataManager.cs} | 153 ++-- SDLauncher UWP/{ => Helpers}/Util.cs | 2 +- SDLauncher UWP/Login.xaml | 252 ------- SDLauncher UWP/Package.appxmanifest | 12 +- SDLauncher UWP/Resources/ExpanderStyle.xaml | 671 ++++++++++++++++++ SDLauncher UWP/Resources/LocalizedStrings.cs | 27 + SDLauncher UWP/SDLauncher UWP.csproj | 63 +- SDLauncher UWP/Strings/en-US/Resources.resw | 178 +++++ .../UserControls/ArgumentsListView.xaml | 37 + .../UserControls/ArgumentsListView.xaml.cs | 128 ++++ SDLauncher UWP/UserControls/Expander.xaml | 63 ++ SDLauncher UWP/UserControls/Expander.xaml.cs | 119 ++++ SDLauncher UWP/UserControls/SettingsCard.xaml | 58 ++ .../UserControls/SettingsCard.xaml.cs | 70 ++ SDLauncher UWP/Views/BaseLauncherPage.xaml | 34 +- SDLauncher UWP/Views/BaseLauncherPage.xaml.cs | 331 ++++----- SDLauncher UWP/Views/CursedForgePage.xaml.cs | 1 - SDLauncher UWP/{ => Views}/MainPage.xaml | 58 +- SDLauncher UWP/{ => Views}/MainPage.xaml.cs | 38 +- SDLauncher UWP/Views/SettingsPage.xaml | 226 +++--- SDLauncher UWP/Views/SettingsPage.xaml.cs | 167 ++++- SDLauncher UWP/vars.cs | 15 +- 42 files changed, 3198 insertions(+), 861 deletions(-) create mode 100644 Client Launcher/Client Launcher.csproj create mode 100644 Client Launcher/Program.cs create mode 100644 ClientLauncher/ClientLauncher.csproj create mode 100644 ClientLauncher/Program.cs create mode 100644 SDLauncher UWP/Converters/ProcessToXmlConverter.cs create mode 100644 SDLauncher UWP/Converters/StringToVisibility.cs create mode 100644 SDLauncher UWP/Dialogs/Login.xaml rename SDLauncher UWP/{ => Dialogs}/Login.xaml.cs (76%) rename SDLauncher UWP/{ => Dialogs}/MessageBoxEx.xaml (89%) rename SDLauncher UWP/{ => Dialogs}/MessageBoxEx.xaml.cs (63%) create mode 100644 SDLauncher UWP/Helpers/Account.cs create mode 100644 SDLauncher UWP/Helpers/Localizer.cs rename SDLauncher UWP/{ => Helpers}/MSLogin.cs (98%) rename SDLauncher UWP/{Views => Helpers}/OptiFine.cs (50%) create mode 100644 SDLauncher UWP/Helpers/SDLauncher.cs rename SDLauncher UWP/{SettingsData.cs => Helpers/SettingsDataManager.cs} (76%) rename SDLauncher UWP/{ => Helpers}/Util.cs (99%) delete mode 100644 SDLauncher UWP/Login.xaml create mode 100644 SDLauncher UWP/Resources/ExpanderStyle.xaml create mode 100644 SDLauncher UWP/Resources/LocalizedStrings.cs create mode 100644 SDLauncher UWP/Strings/en-US/Resources.resw create mode 100644 SDLauncher UWP/UserControls/ArgumentsListView.xaml create mode 100644 SDLauncher UWP/UserControls/ArgumentsListView.xaml.cs create mode 100644 SDLauncher UWP/UserControls/Expander.xaml create mode 100644 SDLauncher UWP/UserControls/Expander.xaml.cs create mode 100644 SDLauncher UWP/UserControls/SettingsCard.xaml create mode 100644 SDLauncher UWP/UserControls/SettingsCard.xaml.cs rename SDLauncher UWP/{ => Views}/MainPage.xaml (80%) rename SDLauncher UWP/{ => Views}/MainPage.xaml.cs (91%) diff --git a/Client Launcher/Client Launcher.csproj b/Client Launcher/Client Launcher.csproj new file mode 100644 index 00000000..9c74c9de --- /dev/null +++ b/Client Launcher/Client Launcher.csproj @@ -0,0 +1,9 @@ + + + + Exe + net5.0 + Client_Launcher + + + diff --git a/Client Launcher/Program.cs b/Client Launcher/Program.cs new file mode 100644 index 00000000..c7999c7c --- /dev/null +++ b/Client Launcher/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace Client_Launcher +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/ClientLauncher/ClientLauncher.csproj b/ClientLauncher/ClientLauncher.csproj new file mode 100644 index 00000000..20827042 --- /dev/null +++ b/ClientLauncher/ClientLauncher.csproj @@ -0,0 +1,8 @@ + + + + Exe + net5.0 + + + diff --git a/ClientLauncher/Program.cs b/ClientLauncher/Program.cs new file mode 100644 index 00000000..9aab6fa6 --- /dev/null +++ b/ClientLauncher/Program.cs @@ -0,0 +1,116 @@ +using System; +using System.IO; +using System.Xml; +using System.Diagnostics; +using System.Threading.Tasks; + +namespace ClientLauncher +{ + class Program + { + static void Main(string[] args) + { + + if (args.Length > 2) + { + if (args[2] == "/admin") + { + string aliasPath = + Path.Combine(AppDomain.CurrentDomain.BaseDirectory + + @"\ClientLauncher.exe"); + + ProcessStartInfo Restartinfo = new ProcessStartInfo(); + Restartinfo.Verb = "runas"; + Restartinfo.UseShellExecute = true; + Restartinfo.FileName = aliasPath; + Process.Start(Restartinfo); + return; + } + } + Console.Title = "SDLauncher Loging System"; + var l = GetEnviromentVar("LocalAppData"); + var path = Path.Combine(l, @"Packages\SeaDevs.Launcher.UWP_0dk3ndwmrga1t\LocalState"); + string arguements = ""; + string fileName = ""; + string workdir = ""; + using (StreamReader sr = File.OpenText(Path.Combine(path, "StartInfo.xml"))) + { + var s = sr.BaseStream; + + XmlReaderSettings settings = new XmlReaderSettings(); + settings.Async = true; + using (XmlReader reader = XmlReader.Create(s, settings)) + { + reader.Read(); + reader.ReadStartElement("Process"); + reader.ReadToFollowing("StartInfo"); + arguements = reader.GetAttribute("Arguments"); + fileName = reader.GetAttribute("FileName"); + workdir = reader.GetAttribute("WorkingDirectory"); + reader.Close(); + } + try + { + s.Close(); + sr.Close(); + } + catch + { + + } + } + //Console.WriteLine(arguements); + //Console.WriteLine(fileName); + //Console.WriteLine(workdir); + var info = new ProcessStartInfo { FileName = fileName, Arguments = arguements, WorkingDirectory = workdir }; + var proc = new Process { StartInfo = info }; + var processUtil = new ProcessUtil(proc); + processUtil.OutputReceived += (s, e) => Console.WriteLine(e); + processUtil.StartWithEvents(); + proc.WaitForExit(); + } + static string GetEnviromentVar(string variableName) + { + return Environment.GetEnvironmentVariable(variableName); + } + } + public class ProcessUtil + { + public event EventHandler? OutputReceived; + public event EventHandler? Exited; + + public Process Process { get; private set; } + + public ProcessUtil(Process process) + { + this.Process = process; + } + + public void StartWithEvents() + { + Process.StartInfo.CreateNoWindow = true; + Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + Process.StartInfo.UseShellExecute = false; + Process.StartInfo.RedirectStandardError = true; + Process.StartInfo.RedirectStandardOutput = true; + Process.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8; + Process.StartInfo.StandardErrorEncoding = System.Text.Encoding.UTF8; + Process.EnableRaisingEvents = true; + Process.ErrorDataReceived += (s, e) => OutputReceived?.Invoke(this, e.Data ?? ""); + Process.OutputDataReceived += (s, e) => OutputReceived?.Invoke(this, e.Data ?? ""); + Process.Exited += (s, e) => Exited?.Invoke(this, new EventArgs()); + + Process.Start(); + Process.BeginErrorReadLine(); + Process.BeginOutputReadLine(); + } + + public Task WaitForExitTaskAsync() + { + return Task.Run(() => + { + Process.WaitForExit(); + }); + } + } +} diff --git a/Package/Package.appxmanifest b/Package/Package.appxmanifest index 662a6266..a4c3ed5b 100644 --- a/Package/Package.appxmanifest +++ b/Package/Package.appxmanifest @@ -4,16 +4,17 @@ xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5" + xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" - IgnorableNamespaces="uap rescap uap5"> + IgnorableNamespaces="uap rescap uap5 desktop"> + Version="0.3.1.0" /> - Package + SD Launcher user Images\StoreLogo.png @@ -32,10 +33,10 @@ Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$"> + Square44x44Logo="Images\Square44x44Logo.png" Description="UWP Minecraft Launcher for Windows by SeaDevs"> @@ -48,6 +49,14 @@ + + + + + + diff --git a/Package/Package.wapproj b/Package/Package.wapproj index 7ba0d8a8..0504036d 100644 --- a/Package/Package.wapproj +++ b/Package/Package.wapproj @@ -159,6 +159,7 @@ + \ No newline at end of file diff --git a/SDLauncher UWP.sln b/SDLauncher UWP.sln index 1b3cfe86..ced923b4 100644 --- a/SDLauncher UWP.sln +++ b/SDLauncher UWP.sln @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDLauncher UWP", "SDLaunche EndProject Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "Package", "Package\Package.wapproj", "{817AAF28-3E88-4E8F-99C6-EE0C0B66C013}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientLauncher", "ClientLauncher\ClientLauncher.csproj", "{F97BA254-A457-4D27-BC65-90B7761B162D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -77,6 +79,26 @@ Global {817AAF28-3E88-4E8F-99C6-EE0C0B66C013}.Release|x86.ActiveCfg = Release|x86 {817AAF28-3E88-4E8F-99C6-EE0C0B66C013}.Release|x86.Build.0 = Release|x86 {817AAF28-3E88-4E8F-99C6-EE0C0B66C013}.Release|x86.Deploy.0 = Release|x86 + {F97BA254-A457-4D27-BC65-90B7761B162D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Debug|ARM.ActiveCfg = Debug|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Debug|ARM.Build.0 = Debug|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Debug|ARM64.Build.0 = Debug|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Debug|x64.ActiveCfg = Debug|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Debug|x64.Build.0 = Debug|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Debug|x86.ActiveCfg = Debug|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Debug|x86.Build.0 = Debug|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Release|Any CPU.Build.0 = Release|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Release|ARM.ActiveCfg = Release|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Release|ARM.Build.0 = Release|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Release|ARM64.ActiveCfg = Release|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Release|ARM64.Build.0 = Release|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Release|x64.ActiveCfg = Release|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Release|x64.Build.0 = Release|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Release|x86.ActiveCfg = Release|Any CPU + {F97BA254-A457-4D27-BC65-90B7761B162D}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SDLauncher UWP/App.xaml b/SDLauncher UWP/App.xaml index 606a8065..9491c7ef 100644 --- a/SDLauncher UWP/App.xaml +++ b/SDLauncher UWP/App.xaml @@ -3,11 +3,11 @@ xmlns:local="using:SDLauncher_UWP" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:controls="using:Microsoft.UI.Xaml.Controls" + xmlns:winui="using:Microsoft.UI.Xaml.Controls" xmlns:Windows10version1903="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 8)"> - - + + /Fonts/Pixeboy.ttf#Pixeboy @@ -17,7 +17,8 @@ - - + + + diff --git a/SDLauncher UWP/App.xaml.cs b/SDLauncher UWP/App.xaml.cs index 8db14f44..79cde83c 100644 --- a/SDLauncher UWP/App.xaml.cs +++ b/SDLauncher UWP/App.xaml.cs @@ -1,4 +1,5 @@ using Microsoft.Toolkit.Uwp.Helpers; +using SDLauncher_UWP.Helpers; using System; using System.Collections.Generic; using System.IO; @@ -34,7 +35,7 @@ public App() this.InitializeComponent(); this.Suspending += OnSuspending; } - SettingsData settings = new SettingsData(); + SettingsDataManager settings = new SettingsDataManager(); /// /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. diff --git a/SDLauncher UWP/Converters/ProcessToXmlConverter.cs b/SDLauncher UWP/Converters/ProcessToXmlConverter.cs new file mode 100644 index 00000000..ee26dd1a --- /dev/null +++ b/SDLauncher UWP/Converters/ProcessToXmlConverter.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Windows.Storage; +using System.Threading.Tasks; +using System.Diagnostics; +using Windows.Storage.Streams; +using System.IO; +using System.Xml; + +namespace SDLauncher_UWP.Converters +{ + public class ProcessToXmlConverter + { + public async static Task Convert(Process Process,StorageFolder Destination,string FileName) + { + var inf = Process.StartInfo; + var storagefile = await Destination.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting); + using (IRandomAccessStream writestream = await storagefile.OpenAsync(FileAccessMode.ReadWrite)) + { + Stream s = writestream.AsStreamForWrite(); + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Async = true; + settings.NewLineOnAttributes = false; + settings.Indent = true; + using (XmlWriter writer = XmlWriter.Create(s, settings)) + { + writer.WriteStartDocument(); + writer.WriteStartElement("Process"); + writer.WriteStartElement("StartInfo"); + writer.WriteAttributeString("Arguments", inf.Arguments); + writer.WriteAttributeString("FileName", inf.FileName); + writer.WriteAttributeString("WorkingDirectory", inf.WorkingDirectory); + writer.WriteEndElement(); + writer.WriteEndElement(); + writer.Flush(); + await writer.FlushAsync(); + } + } + } + } +} diff --git a/SDLauncher UWP/Converters/StringToVisibility.cs b/SDLauncher UWP/Converters/StringToVisibility.cs new file mode 100644 index 00000000..34d434ba --- /dev/null +++ b/SDLauncher UWP/Converters/StringToVisibility.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Data; + +namespace SDLauncher_UWP.Converters +{ + public class StringToVisibility : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, string language) + { + // Reversed result + if (parameter is string param) + { + if (param == "0") + { + return (value is string val && val.Length > 0) ? Visibility.Collapsed : Visibility.Visible; + } + } + + return (value is string str && str.Length > 0) ? Visibility.Visible : Visibility.Collapsed; + } + + public object ConvertBack(object value, Type targetType, object parameter, string language) + { + throw new InvalidOperationException("Use the boolean to visibility converter in this situation. " + + "A string is very likely unnecessary in this case."); + } + } + + public class BindlessStringToVisibility + { + public static Visibility BindlessConvert(object value) + { + return (value is string str && str.Length > 0) ? Visibility.Visible : Visibility.Collapsed; + } + + public static void BindlessConvertBack(object value) + { + throw new InvalidOperationException("Use the boolean to visibility converter in this situation." + + "A string is very likely unnecessary in this case. You tried to convert: " + value.ToString()); + } + } +} diff --git a/SDLauncher UWP/Dialogs/Login.xaml b/SDLauncher UWP/Dialogs/Login.xaml new file mode 100644 index 00000000..0abffb11 --- /dev/null +++ b/SDLauncher UWP/Dialogs/Login.xaml @@ -0,0 +1,271 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SDLauncher UWP/Login.xaml.cs b/SDLauncher UWP/Dialogs/Login.xaml.cs similarity index 76% rename from SDLauncher UWP/Login.xaml.cs rename to SDLauncher UWP/Dialogs/Login.xaml.cs index 313a9c15..2b98eee3 100644 --- a/SDLauncher UWP/Login.xaml.cs +++ b/SDLauncher UWP/Dialogs/Login.xaml.cs @@ -22,6 +22,7 @@ using System.Threading.Tasks; using Windows.UI.Xaml.Media.Imaging; using Microsoft.Toolkit.Uwp.UI; +using SDLauncher_UWP.Helpers; // The Content Dialog item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 @@ -58,29 +59,29 @@ private async void btnMSLogin_Click(object sender, RoutedEventArgs e) if (result == MSLogin.Exceptions.Cancelled) { this.Hide(); - await new MessageBoxEx("Error", "User canceld the login!", MessageBoxEx.Buttons.Ok).ShowAsync(); + _ = await MessageBox.Show("Error", "User canceld the login!", MessageBoxButtons.Ok); vars.session = tempsession; vars.UserName = tempsession.Username; - this.ShowAsync(); + _ = this.ShowAsync(); } else if (result == MSLogin.Exceptions.NoAccount) { this.Hide(); - await new MessageBoxEx("Error", "You don't have an Minecraft profile on that Microsoft account!", MessageBoxEx.Buttons.Ok).ShowAsync(); + _ = await MessageBox.Show("Error", "You don't have an Minecraft profile on that Microsoft account!", MessageBoxButtons.Ok); vars.session = tempsession; vars.UserName = tempsession.Username; - this.ShowAsync(); + _ = this.ShowAsync(); } else if (result == MSLogin.Exceptions.ConnectFailed) { this.Hide(); - await new MessageBoxEx("Error", "Connection to login service failed!", MessageBoxEx.Buttons.Ok).ShowAsync(); + _ = await MessageBox.Show("Error", "Connection to login service failed!", MessageBoxButtons.Ok); if (tempsession != null) { vars.session = tempsession; vars.UserName = tempsession.Username; } - this.ShowAsync(); + _ = this.ShowAsync(); UpdateAccounts(); } else if (result == MSLogin.Exceptions.Success) @@ -127,10 +128,8 @@ private async void btnOfflineLog_Click(object sender, RoutedEventArgs e) { string msg = "You already have " + count + " offline account(s) called \"" + txtbxOffUsername.Text.Replace(" ", "").ToString() + "\" \nAre you really want to add a new one"; this.Hide(); - var m = new MessageBoxEx("Infomation", msg, MessageBoxEx.Buttons.YesNo); - await m.ShowAsync(); - this.ShowAsync(); - if (m.Result == MessageBoxEx.Results.No) + _ = this.ShowAsync(); + if (await MessageBox.Show("Infomation", msg, MessageBoxButtons.YesNo) == MessageBoxResults.No) { goAhead = false; } @@ -182,29 +181,63 @@ private void ContentDialog_Loaded(object sender, RoutedEventArgs e) private void LoginFromCache(object sender, RoutedEventArgs e) { + bool isSelectionMode = false; foreach (var item in vars.Accounts) { - if (item.Last) + if (item.IsCheckboxVsible == Visibility.Visible) { - item.Last = false; + isSelectionMode = true; + } + else + { + isSelectionMode = false; } } - if (sender is Button btn) + if(vars.Accounts.Count == 1) { - foreach (var item in vars.Accounts) + isSelectionMode = false; + } + if (isSelectionMode) + { + if (sender is Button btn) { - if (item.Count == int.Parse(btn.Tag.ToString())) + foreach (var item in vars.Accounts) { - item.Last = true; - if (item.Type == "Offline") + if (item.Count == int.Parse(btn.Tag.ToString())) { - UpdateSession(MSession.GetOfflineSession(item.UserName)); + item.IsChecked = !item.IsChecked; + return; } - else + } + } + } + else + { + foreach (var item in vars.Accounts) + { + if (item.Last) + { + item.Last = false; + } + } + if (sender is Button btn) + { + foreach (var item in vars.Accounts) + { + if (item.Count == int.Parse(btn.Tag.ToString())) { - UpdateSession(new MSession(item.UserName, item.AccessToken, item.UUID)); + item.Last = true; + if (item.Type == "Offline") + { + UpdateSession(MSession.GetOfflineSession(item.UserName)); + } + else + { + UpdateSession(new MSession(item.UserName, item.AccessToken, item.UUID)); + } + vars.CurrentAccountCount = item.Count; + return; } - vars.CurrentAccountCount = item.Count; } } } @@ -213,31 +246,52 @@ private void LogOutFromCache(object sender, RoutedEventArgs e) { if (sender is MenuFlyoutItem itm) { - foreach (var item in vars.Accounts) + var sltaccs = GetSelectedAccounts(); + if (sltaccs.Count > 0) { - if (item.Count == int.Parse(itm.Tag.ToString())) + foreach (var item in sltaccs) { - if (item.Type == "Offline") + if (item.Count == vars.CurrentAccountCount) { - if (item.Count == vars.CurrentAccountCount) - { - vars.session = null; - vars.UserName = ""; - vars.CurrentAccountCount = null; - } + vars.session = null; + vars.UserName = ""; + vars.CurrentAccountCount = null; } - else + + _ = vars.Accounts.Remove(item); + + } + UpdateAccounts(); + return; + } + else + { + foreach (var item in vars.Accounts) + { + if (item.Count == int.Parse(itm.Tag.ToString())) { - if (item.Count == vars.CurrentAccountCount) + if (item.Type == "Offline") { - vars.session = null; - vars.UserName = ""; - vars.CurrentAccountCount = null; + if (item.Count == vars.CurrentAccountCount) + { + vars.session = null; + vars.UserName = ""; + vars.CurrentAccountCount = null; + } } + else + { + if (item.Count == vars.CurrentAccountCount) + { + vars.session = null; + vars.UserName = ""; + vars.CurrentAccountCount = null; + } + } + _ = vars.Accounts.Remove(item); + UpdateAccounts(); + return; } - vars.Accounts.Remove(item); - UpdateAccounts(); - return; } } } @@ -268,18 +322,14 @@ void AddAccount(MSession session) vars.CurrentAccountCount = vars.AccountsCount; this.Hide(); } - AdvancedCollectionView AccountsACV = new AdvancedCollectionView(vars.Accounts, true); - bool DontNull = false; - void UpdateAccounts() + private void UpdateAccounts() { - //try - //{ - if (!DontNull) + foreach (var item in vars.Accounts) { - accountsRepeater.ItemsSource = null; + item.IsCheckboxVsible = Visibility.Collapsed; + item.IsChecked = false; } - //} - //catch { } + accountsRepeater.ItemsSource = null; accountsRepeater.ItemsSource = vars.Accounts; if (vars.Accounts.Count == 0) { @@ -310,7 +360,7 @@ private void btnChooseAcc_Click(object sender, RoutedEventArgs e) private void Login_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { - UpdateAccounts(); + // UpdateAccounts(); } private void btnBack_Click(object sender, RoutedEventArgs e) @@ -445,7 +495,7 @@ private void itmRename_Click(object sender, RoutedEventArgs e) txtSettingsPrpName.Visibility = Visibility.Collapsed; txtbxRename.Visibility = Visibility.Visible; txtbxRename.Text = txtSettingsPrpName.Text; - txtbxRename.Focus(FocusState.Keyboard); + _ = txtbxRename.Focus(FocusState.Keyboard); } private void txtbxRename_LostFocus(object sender, RoutedEventArgs e) @@ -523,7 +573,6 @@ private void chkbxSelectAcc_Click(object sender, RoutedEventArgs e) { item.IsChecked = true; ShowSelect(true); - UpdateAccounts(); return; } } @@ -537,7 +586,7 @@ private void chkbxSelectAcc_Click(object sender, RoutedEventArgs e) { item.IsChecked = false; ShowSelect(true); - IsAnyAccountChecked(); + _ = IsAnyAccountChecked(); return; } } @@ -558,7 +607,6 @@ private void itmSelect_Click(object sender, RoutedEventArgs e) { item.IsChecked = true; ShowSelect(true); - UpdateAccounts(); return; } } @@ -572,7 +620,7 @@ private void itmSelect_Click(object sender, RoutedEventArgs e) { item.IsChecked = false; ShowSelect(true); - IsAnyAccountChecked(); + _ = IsAnyAccountChecked(); return; } } @@ -580,18 +628,18 @@ private void itmSelect_Click(object sender, RoutedEventArgs e) } } - private void ShowSelect(bool value,bool? isSelected = null) + private void ShowSelect(bool value, bool? isSelected = null) { if (value) { foreach (var item in vars.Accounts) { item.IsCheckboxVsible = Visibility.Visible; - if(isSelected == true) + if (isSelected == true) { item.IsChecked = true; } - else if(isSelected == false) + else if (isSelected == false) { item.IsChecked = false; } @@ -623,14 +671,13 @@ private bool IsAnyAccountChecked() isChecked.Add(true); } } - if(isChecked.Count == 0) + if (isChecked.Count == 0) { foreach (var item in vars.Accounts) { item.IsChecked = false; item.IsCheckboxVsible = Visibility.Collapsed; } - UpdateAccounts(); return false; } else @@ -641,35 +688,79 @@ private bool IsAnyAccountChecked() private void Button_PointerEntered(object sender, PointerRoutedEventArgs e) { - //if(sender is Button btn) - //{ - // foreach (var item in vars.Accounts) - // { - // if (item.Count == int.Parse(btn.Tag.ToString())) - // { - // item.IsCheckboxVsible = Visibility.Visible; - // DontNull = true; - // return; - // } - // } - //} + if (sender is Button btn) + { + foreach (var item in vars.Accounts) + { + if (item.Count == int.Parse(btn.Tag.ToString())) + { + item.IsCheckboxVsible = Visibility.Visible; + return; + } + } + } } private void Button_PointerExited(object sender, PointerRoutedEventArgs e) { - //if(!IsAnyAccountChecked()) - //if (sender is Button btn) - //{ - // foreach (var item in vars.Accounts) - // { - // if (item.Count == int.Parse(btn.Tag.ToString())) - // { - // item.IsCheckboxVsible = Visibility.Collapsed; - // DontNull = false; - // return; - // } - // } - //} + if (!IsAnyAccountChecked()) + if (sender is Button btn) + { + foreach (var item in vars.Accounts) + { + if (item.Count == int.Parse(btn.Tag.ToString())) + { + item.IsCheckboxVsible = Visibility.Collapsed; + return; + } + } + } + } + + private List GetSelectedAccounts() + { + List SelectedList = new List(); + foreach (var item in vars.Accounts) + { + if (item.IsChecked) + { + SelectedList.Add(item); + } + } + return SelectedList; + } + private void btnDel_Click(object sender, RoutedEventArgs e) + { + var SelectedList = GetSelectedAccounts(); + if (SelectedList.Count > 0) + { + LogOutFromCache(new MenuFlyoutItem(), null); + UpdateAccounts(); + } + else + { + bool isvivsible = true; + if (sender is Button btn) + { + foreach (var item in vars.Accounts) + { + if (item.IsCheckboxVsible == Visibility.Collapsed) + { + isvivsible = false; + } + } + } + if (!isvivsible) + { + foreach (var item in vars.Accounts) + { + item.IsCheckboxVsible = Visibility.Visible; + item.IsChecked = false; + } + } + } } + + } } diff --git a/SDLauncher UWP/MessageBoxEx.xaml b/SDLauncher UWP/Dialogs/MessageBoxEx.xaml similarity index 89% rename from SDLauncher UWP/MessageBoxEx.xaml rename to SDLauncher UWP/Dialogs/MessageBoxEx.xaml index f5634804..ffaf5c27 100644 --- a/SDLauncher UWP/MessageBoxEx.xaml +++ b/SDLauncher UWP/Dialogs/MessageBoxEx.xaml @@ -8,7 +8,7 @@ mc:Ignorable="d" Loaded="ContentDialog_Loaded" Background="{ThemeResource AcrylicInAppFillColorDefaultBrush}" - xmlns:controls="using:Microsoft.UI.Xaml.Controls" + xmlns:winui="using:Microsoft.UI.Xaml.Controls" PrimaryButtonStyle="{StaticResource AccentButtonStyle}" SecondaryButtonStyle="{StaticResource ButtonRevealStyle}" PrimaryButtonClick="ContentDialog_PrimaryButtonClick" @@ -20,6 +20,6 @@ - + diff --git a/SDLauncher UWP/MessageBoxEx.xaml.cs b/SDLauncher UWP/Dialogs/MessageBoxEx.xaml.cs similarity index 63% rename from SDLauncher UWP/MessageBoxEx.xaml.cs rename to SDLauncher UWP/Dialogs/MessageBoxEx.xaml.cs index f90e7eaa..11a96db8 100644 --- a/SDLauncher UWP/MessageBoxEx.xaml.cs +++ b/SDLauncher UWP/Dialogs/MessageBoxEx.xaml.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; +using System.Threading.Tasks; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; @@ -17,53 +18,53 @@ namespace SDLauncher_UWP { + public enum MessageBoxResults + { + Ok, + Cancel, + Yes, + No + } + public enum MessageBoxButtons + { + Ok, + OkCancel, + YesNo + } public sealed partial class MessageBoxEx : ContentDialog { - public Results Result { get; set; } - public enum Results - { - Ok, - Cancel, - Yes, - No - } - public enum Buttons - { - Ok, - OkCancel, - YesNo - } - public MessageBoxEx(string title,string caption, Buttons buttons) + public MessageBoxResults Result { get; set; } + public MessageBoxEx(string title, string caption, MessageBoxButtons buttons) { this.InitializeComponent(); Title = title; txt.Text = caption; - if (buttons == Buttons.Ok) + if (buttons == MessageBoxButtons.Ok) { PrimaryButtonText = ""; SecondaryButtonText = "OK"; } - else if (buttons == Buttons.OkCancel) + else if (buttons == MessageBoxButtons.OkCancel) { PrimaryButtonText = "OK"; SecondaryButtonText = "Cancel"; } - else if (buttons == Buttons.YesNo) + else if (buttons == MessageBoxButtons.YesNo) { PrimaryButtonText = "Yes"; SecondaryButtonText = "No"; } + this.RequestedTheme = (ElementTheme)vars.theme; } - private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { if (sender.PrimaryButtonText == "OK") { - Result = Results.Ok; + Result = MessageBoxResults.Ok; } else if (sender.PrimaryButtonText == "Yes") { - Result = Results.Yes; + Result = MessageBoxResults.Yes; } } @@ -71,29 +72,29 @@ private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDia { if (sender.SecondaryButtonText == "OK") { - Result = Results.Ok; + Result = MessageBoxResults.Ok; } else if (sender.SecondaryButtonText == "Cancel") { - Result = Results.Cancel; + Result = MessageBoxResults.Cancel; } else if (sender.SecondaryButtonText == "No") { - Result = Results.No; + Result = MessageBoxResults.No; } } private void ContentDialog_Loaded(object sender, RoutedEventArgs e) { - if (vars.theme != null) - { - if (Window.Current.Content is FrameworkElement fe) - { - this.RequestedTheme = (ElementTheme)vars.theme; - fe.RequestedTheme = (ElementTheme)vars.theme; - } - } - + } + } + public class MessageBox + { + public static async Task Show(string title,string caption, MessageBoxButtons buttons) + { + var d = new MessageBoxEx(title, caption, buttons); + await d.ShowAsync(); + return d.Result; } } } diff --git a/SDLauncher UWP/Helpers/Account.cs b/SDLauncher UWP/Helpers/Account.cs new file mode 100644 index 00000000..7bd6717e --- /dev/null +++ b/SDLauncher UWP/Helpers/Account.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using Windows.UI.Xaml; + +namespace SDLauncher_UWP.Helpers +{ + public class Account : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged = delegate { }; + List PicList = new List(); + private string userName; + public string UserName { get { return userName; } set { userName = value; OnPropertyChanged(); } } + public string ProfilePicture { get; set; } + public string Type { get; set; } + public string TypeIconGlyph { get; set; } + public string AccessToken { get; set; } + public string UUID { get; set; } + public int Count { get; set; } + public int ProfileAvatarID { get; set; } + public bool Last { get; set; } + // For app UI + private Visibility isCheckboxVsible; + public Visibility IsCheckboxVsible { get { return isCheckboxVsible; } set { isCheckboxVsible = value; OnPropertyChanged(); } } + private bool sChecked; + public bool IsChecked { get { return sChecked; } set { sChecked = value; OnPropertyChanged(); } } + + public void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + public Account(string username, string type, string accesstoken, string uuid, int count, bool last, int? pic = null) + { + IsCheckboxVsible = Visibility.Collapsed; + IsChecked = false; + PicList.Add("https://raw.githubusercontent.com/Chaniru22/SDLauncher/main/Pictures/steve.png"); + PicList.Add("https://raw.githubusercontent.com/Chaniru22/SDLauncher/main/Pictures/NoobSteve.png"); + PicList.Add("https://raw.githubusercontent.com/Chaniru22/SDLauncher/main/Pictures/alex.png"); + if (pic == null) + { + Random r = new Random(); + int index = r.Next(PicList.Count); + ProfilePicture = PicList[index]; + ProfileAvatarID = index; + } + else + { + ProfilePicture = PicList[(int)pic]; + ProfileAvatarID = (int)pic; + } + UserName = username; + Type = type; + AccessToken = accesstoken; + UUID = uuid; + Count = count; + Last = last; + if (UUID != "null") + { + ProfilePicture = "https://minotar.net/avatar/" + UUID; + ProfileAvatarID = 3; + } + TypeIconGlyph = Type == "Offline" ? "\xF384" : "\xEC05"; + } + } +} diff --git a/SDLauncher UWP/Helpers/Localizer.cs b/SDLauncher UWP/Helpers/Localizer.cs new file mode 100644 index 00000000..f43c2b35 --- /dev/null +++ b/SDLauncher UWP/Helpers/Localizer.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Windows.ApplicationModel.Resources; + +namespace SDLauncher_UWP.Helpers +{ + public static class Localizer + { + + private static ResourceLoader _resLoader = new ResourceLoader(); + + public static string GetLocalizedString(string resourceKey) + { + return _resLoader.GetString(resourceKey); + } + } +} diff --git a/SDLauncher UWP/MSLogin.cs b/SDLauncher UWP/Helpers/MSLogin.cs similarity index 98% rename from SDLauncher UWP/MSLogin.cs rename to SDLauncher UWP/Helpers/MSLogin.cs index 0d732e3a..56c0f52a 100644 --- a/SDLauncher UWP/MSLogin.cs +++ b/SDLauncher UWP/Helpers/MSLogin.cs @@ -9,7 +9,7 @@ using CmlLib.Core.Auth.Microsoft; using System.Net.Http; -namespace SDLauncher_UWP +namespace SDLauncher_UWP.Helpers { class MSLogin { diff --git a/SDLauncher UWP/Views/OptiFine.cs b/SDLauncher UWP/Helpers/OptiFine.cs similarity index 50% rename from SDLauncher UWP/Views/OptiFine.cs rename to SDLauncher UWP/Helpers/OptiFine.cs index 75fa8101..412f3cf9 100644 --- a/SDLauncher UWP/Views/OptiFine.cs +++ b/SDLauncher UWP/Helpers/OptiFine.cs @@ -1,4 +1,5 @@ -using System; +using SDLauncher_UWP.Resources; +using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; @@ -10,22 +11,28 @@ using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; -namespace SDLauncher_UWP.Views +namespace SDLauncher_UWP.Helpers { - class OptiFine + public class OptiFine { + public event EventHandler StatusChanged = delegate { }; + public event EventHandler ProgressChanged = delegate { }; + public event EventHandler ErrorAppeared = delegate { }; + public event EventHandler UIChangedReqested = delegate { }; + public event EventHandler DownloadCompleted = delegate { }; + public OptFineVerReturns returns; string optver; public bool UI; public int DownloadProg; public string DownloadStats; - private async Task IsOptiFineFilePresent(string lastFileName, string mcVer, bool isLib) + public async Task IsOptiFineFilePresent(string lastFileName, string mcVer, bool isLib) { if (!isLib) { try { - var verFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("versions"); + var verFolder = await StorageFolder.GetFolderFromPathAsync(vars.Launcher.Launcher.MinecraftPath.Versions); var mcVerFolder = await verFolder.GetFolderAsync(mcVer); var file = await mcVerFolder.GetFileAsync(lastFileName); return true; @@ -39,7 +46,7 @@ private async Task IsOptiFineFilePresent(string lastFileName, string mcVer { try { - var LibsFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("libraries"); + var LibsFolder = await StorageFolder.GetFolderFromPathAsync(vars.Launcher.Launcher.MinecraftPath.Library); var LibFolder = await LibsFolder.GetFolderAsync("optifine"); return true; } @@ -49,44 +56,48 @@ private async Task IsOptiFineFilePresent(string lastFileName, string mcVer } } } - public void DownloadOptiFineVer(string mcver, string modVer, MenuFlyoutItem mit) + + public void DownloadOptiFineVer(string mcver, string modVer, string DisplayVer) { + MCver = mcver; + Modver = modVer; + Displayver = DisplayVer; + UIChangedReqested(false, new EventArgs()); switch (mcver) { case "1.18.2": - returns = new OptFineVerReturns(modVer, mit.Text.ToString(), OptFineVerReturns.Results.DownloadOptiFineVer); - UI = false; + returns = new OptFineVerReturns(modVer, DisplayVer, OptFineVerReturns.Results.DownloadOptiFineVer); optver = ": " + mcver; OptFineDownload("https://raw.githubusercontent.com/Chaniru22/SDLauncher/main/OptiFine-1.18.2.zip", "OptiFine-" + mcver + ".zip", ModType.ver); break; case "1.18.1": - returns = new OptFineVerReturns(modVer, mit.Text.ToString(), OptFineVerReturns.Results.DownloadOptiFineVer); - UI = false; + returns = new OptFineVerReturns(modVer, DisplayVer, OptFineVerReturns.Results.DownloadOptiFineVer); optver = ": " + mcver; OptFineDownload("https://raw.githubusercontent.com/Chaniru22/SDLauncher/main/OptiFine-1.18.1.zip", "OptiFine-" + mcver + ".zip", ModType.ver); break; case "1.17.1": - returns = new OptFineVerReturns(modVer, mit.Text.ToString(), OptFineVerReturns.Results.DownloadOptiFineVer); - UI = false; + returns = new OptFineVerReturns(modVer, DisplayVer, OptFineVerReturns.Results.DownloadOptiFineVer); optver = ": " + mcver; OptFineDownload("https://raw.githubusercontent.com/Chaniru22/SDLauncher/main/OptiFine-1.17.1.zip", "OptiFine-" + mcver + ".zip", ModType.ver); break; case "1.16.5": - returns = new OptFineVerReturns(modVer, mit.Text.ToString(), OptFineVerReturns.Results.DownloadOptiFineVer); - UI = false; + returns = new OptFineVerReturns(modVer, DisplayVer, OptFineVerReturns.Results.DownloadOptiFineVer); optver = ": " + mcver; OptFineDownload("https://raw.githubusercontent.com/Chaniru22/SDLauncher/main/OptiFine-1.16.5.zip", "OptiFine-" + mcver + ".zip", ModType.ver); break; - } } - public async Task CheckOptiFine(string mcver, string modVer, MenuFlyoutItem mit, CmlLib.Core.Version.MVersionCollection mcVers) + public string MCver { get; set; } + public string Modver { get; set; } + public string Displayver { get; set; } + public async Task CheckOptiFine(string mcver, string modVer, string DisplayVer) { - MessageBoxEx msgbx; + await vars.Launcher.RefreshVersions(); + UIChangedReqested(false, new EventArgs()); bool exists = false; - if (mcVers != null) + if (vars.Launcher.MCVersions != null) { - foreach (var veritem in mcVers) + foreach (var veritem in vars.Launcher.MCVersions) { if (veritem.Name == modVer) { @@ -95,41 +106,51 @@ public async Task CheckOptiFine(string mcver, string modVer, MenuFlyoutItem mit, } if (exists) { - returns = new OptFineVerReturns(modVer, mit.Text.ToString(), OptFineVerReturns.Results.Exists); + returns = new OptFineVerReturns(modVer, DisplayVer, OptFineVerReturns.Results.Exists); + UIChangedReqested(true, new EventArgs()); + return returns; } else { - msgbx = new MessageBoxEx("Error", "Couldn't find OptiFine installed on this minecraft. Do you want to download and install from our servers ?", MessageBoxEx.Buttons.YesNo); - await msgbx.ShowAsync(); - if (msgbx.Result == MessageBoxEx.Results.Yes) + var r = await MessageBox.Show("Error", "Couldn't find OptiFine installed on this minecraft. Do you want to download and install from our servers ?", MessageBoxButtons.YesNo); + + if (r == MessageBoxResults.Yes) { if (await IsOptiFineFilePresent(mcver + ".jar", mcver, false)) { if (await IsOptiFineFilePresent(null, null, true)) { returns = new OptFineVerReturns(null, null, OptFineVerReturns.Results.DownloadOptiFineVer); + UIChangedReqested(true, new EventArgs()); + return returns; } else { - msgbx = new MessageBoxEx("Error", "This will download main OptiFine library, Please click again " + mit.Text.ToString() + " (after download and extract the main OptiFine) to install optifine of that version !", MessageBoxEx.Buttons.Ok); - await msgbx.ShowAsync(); + await MessageBox.Show("Information", "This will download main OptiFine library, Please click again " + DisplayVer + " (after download and extract the main OptiFine) to install optifine of that version !", MessageBoxButtons.Ok); optver = " Lib"; returns = new OptFineVerReturns(modVer, mcver, OptFineVerReturns.Results.DownloadOptiFineLib); OptFineDownload("https://raw.githubusercontent.com/Chaniru22/SDLauncher/main/optifine.zip", "OptiFine.zip", ModType.lib); + UIChangedReqested(true, new EventArgs()); + return returns; } } else { - msgbx = new MessageBoxEx("Error", "You have to install & run minecraft version " + mcver + " one time to install OptiFine", MessageBoxEx.Buttons.Ok); - await msgbx.ShowAsync(); - returns = new OptFineVerReturns(modVer, mcver, OptFineVerReturns.Results.DownloadMCVer); + await MessageBox.Show("Error", "You have to install & run minecraft version " + mcver + " one time to install OptiFine", MessageBoxButtons.Ok); + returns = new OptFineVerReturns(mcver, mcver, OptFineVerReturns.Results.DownloadMCVer); + UIChangedReqested(true, new EventArgs()); + return returns; } } } + UIChangedReqested(true, new EventArgs()); + return returns; } else { - returns = new OptFineVerReturns(modVer, mcver, OptFineVerReturns.Results.Failed); + returns = new OptFineVerReturns(null, null, OptFineVerReturns.Results.Failed); + UIChangedReqested(true, new EventArgs()); + return returns; } } // @@ -149,7 +170,8 @@ private async void OptFineDownload(string link, string dir, ModType m) string destination = dir.Trim(); StorageFile destinationFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync( - destination, CreationCollisionOption.GenerateUniqueName); + destination, + CreationCollisionOption.ReplaceExisting); BackgroundDownloader downloader = new BackgroundDownloader(); DownloadOperation download = downloader.CreateDownload(source, destinationFile); @@ -161,35 +183,53 @@ private async void OptFineDownload(string link, string dir, ModType m) } optDir = dir; dwnOptiType = m; - UI = false; + UIChangedReqested(false, new EventArgs()); } DownloadOperation operation; - void StartDownloadWithProgress(DownloadOperation obj) + DispatcherTimer downloadprog = new DispatcherTimer(); + private async void StartDownloadWithProgress(DownloadOperation operation) { - operation = obj; - operation.StartAsync(); - DispatcherTimer downloadprog = new DispatcherTimer(); + StatusChanged("Downloading: OptiFine" + optver, new EventArgs()); + this.operation = operation; + await this.operation.StartAsync(); downloadprog.Interval = new TimeSpan(0, 0, 0, 0, 1); downloadprog.Tick += Downloadprog_Tick; - + downloadprog.Start(); } + private void Downloadprog_Tick(object sender, object e) { - double bytesIn = double.Parse(operation.Progress.BytesReceived.ToString()); - double totalBytes = double.Parse(operation.Progress.TotalBytesToReceive.ToString()); - double percentage = bytesIn / totalBytes * 100; - DownloadStats = "Downloading: OptiFine" + optver; - DownloadProg = int.Parse(Math.Truncate(percentage).ToString()); - if (DownloadProg > 99) + if (operation.Progress.Status == BackgroundTransferStatus.Completed) + { + DownloadFileCompleted(); + downloadprog.Stop(); + ProgressChanged(0, new EventArgs()); + } + else if (operation.Progress.Status == BackgroundTransferStatus.Running) + { + try + { + double bytesIn = operation.Progress.BytesReceived; + double totalBytes = operation.Progress.TotalBytesToReceive; + double percentage = bytesIn / totalBytes * 100; + ProgressChanged(int.Parse(Math.Floor(percentage).ToString()), new EventArgs()); + } + catch { } + StatusChanged("Downloading: OptiFine" + optver, new EventArgs()); + } + else if (operation.Progress.Status == BackgroundTransferStatus.Error) { - client_DownloadFileCompleted(); + ErrorAppeared("Failed to download the file",new EventArgs()); + DownloadCompleted(false, new EventArgs()); + downloadprog.Stop(); } } - async void client_DownloadFileCompleted() + private async void DownloadFileCompleted() { - DownloadStats = "Extracting"; + UIChangedReqested(false, new EventArgs()); + StatusChanged("Extracting", new EventArgs()); //Read the file stream var a = await ApplicationData.Current.TemporaryFolder.GetFileAsync(optDir); @@ -198,19 +238,22 @@ async void client_DownloadFileCompleted() ZipArchive archive = new ZipArchive(b); if (dwnOptiType == ModType.lib) { - archive.ExtractToDirectory(Path.Combine(ApplicationData.Current.LocalFolder.Path,"libraries"), true); + archive.ExtractToDirectory(vars.Launcher.Launcher.MinecraftPath.Library, true); } else if (dwnOptiType == ModType.ver) { - archive.ExtractToDirectory(Path.Combine(ApplicationData.Current.LocalFolder.Path,"versions"), true); + archive.ExtractToDirectory(vars.Launcher.Launcher.MinecraftPath.Versions, true); } - DownloadProg = 100; - UI = true; + ProgressChanged(100, new EventArgs()); + StatusChanged(Localized.Ready, new EventArgs()); + UIChangedReqested(true, new EventArgs()); + DownloadCompleted(true, new EventArgs()); } + } - class OptFineVerReturns + public class OptFineVerReturns { public enum Results { diff --git a/SDLauncher UWP/Helpers/SDLauncher.cs b/SDLauncher UWP/Helpers/SDLauncher.cs new file mode 100644 index 00000000..0e6d2301 --- /dev/null +++ b/SDLauncher UWP/Helpers/SDLauncher.cs @@ -0,0 +1,228 @@ +using CmlLib.Core; +using CmlLib.Core.Downloader; +using CmlLib.Core.Installer.FabricMC; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CmlLib.Core.Version; +using SDLauncher_UWP.Resources; + +namespace SDLauncher_UWP.Helpers +{ + public class SDLauncher + { + public event EventHandler UIChangeRequested = delegate { }; + public event EventHandler StatusChanged = delegate { }; + public event EventHandler FileOrProgressChanged = delegate { }; + public event EventHandler VersionsRefreshed = delegate { }; + + public List MCVerNames + { + get + { + if (mcVers != null) + { + List temp = new List(); + foreach (var item in mcVers) + { + temp.Add(item.Name); + } + return temp; + } + else + { + return null; + } + } + } + public MVersionCollection MCVersions + { + get + { + return mcVers; + } + } + public MVersionCollection FabricMCVersions + { + get + { + return mcFabricVers; + } + } + private MVersionCollection mcVers; + private MVersionCollection mcFabricVers; + + public CMLauncher Launcher { get; set; } + public OptiFine OptiFine { get; set; } + public SDLauncher() + { + OptiFine = new OptiFine(); + OptiFine.ProgressChanged += OptiFine_ProgressChanged; + OptiFine.StatusChanged += OptiFine_StatusChanged; + OptiFine.UIChangedReqested += OptiFine_UIChangedReqested; + OptiFine.ErrorAppeared += OptiFine_ErrorAppeared; + } + public static SDLauncher CreateLauncher(MinecraftPath mcpath) + { + var l = new SDLauncher(); + l.InitializeLauncher(mcpath); + return l; + } + private void OptiFine_ErrorAppeared(object sender, EventArgs e) + { + _ = MessageBox.Show("Error", sender.ToString(), MessageBoxButtons.Ok); + } + + private void OptiFine_UIChangedReqested(object sender, EventArgs e) + { + UIChangeRequested(this, new UIChangeRequestedEventArgs((bool)sender)); + } + + private void OptiFine_StatusChanged(object sender, EventArgs e) + { + StatusChanged(this, new StatusChangedEventArgs(sender.ToString())); + } + + private void OptiFine_ProgressChanged(object sender, EventArgs e) + { + FileOrProgressChanged(this, new ProgressChangedEventArgs(currentProg: int.Parse(sender.ToString()))); + } + + private void UI(bool ui) + { + UIChangeRequested(this, new UIChangeRequestedEventArgs(ui)); + } + private void Status(string stats) + { + StatusChanged(this, new StatusChangedEventArgs(stats)); + } + public void InitializeLauncher(MinecraftPath path) + { + UI(false); + Launcher = new CMLauncher(path); + Launcher.FileChanged += Launcher_FileChanged; + Launcher.ProgressChanged += Launcher_ProgressChanged; + UI(true); + } + + public async Task RefreshVersions() + { + UI(false); + Status(Localized.GettingVers); + mcVers = await Launcher.GetAllVersionsAsync(); + mcFabricVers = await new FabricVersionLoader().GetVersionMetadatasAsync(); + Status(Localized.Ready); + VersionsRefreshed(this, new EventArgs()); + UI(true); + } + + + private void Launcher_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) + { + FileOrProgressChanged(this, new ProgressChangedEventArgs(currentProg: e.ProgressPercentage)); + } + + private void Launcher_FileChanged(DownloadFileChangedEventArgs e) + { + Status($"{e.FileKind} : {e.FileName} ({e.ProgressedFileCount}/{e.TotalFileCount})"); + FileOrProgressChanged(this, new ProgressChangedEventArgs(maxfiles: e.ProgressedFileCount, currentfile: e.TotalFileCount)); + } + + public async Task CheckFabric(string mcver, string modver, string displayver) + { + string launchVer = ""; + string displayVer = ""; + bool exists = false; + foreach (var veritem in vars.Launcher.FabricMCVersions) + { + if (veritem.Name == modver) + { + exists = true; + } + } + if (exists) + { + launchVer = modver; + displayVer = displayver; + Status("Getting Fabric"); + UI(false); + var fabric = FabricMCVersions.GetVersionMetadata(launchVer); + await fabric.SaveAsync(Launcher.MinecraftPath); + UI(true); + Status("Ready"); + await RefreshVersions(); + launchVer = modver; + displayVer = displayver; + Status("Ready"); + return new FabricResponsoe(launchVer, displayVer, FabricResponsoe.Responses.ExistsOrCreated); + } + else + { + if (await MessageBox.Show("Error", "To run " + displayver + " you need to have installed version " + mcver + ". Vanilla,Do you want to install now ?", MessageBoxButtons.YesNo) == MessageBoxResults.Yes) + { + displayVer = mcver; + launchVer = mcver; + return new FabricResponsoe(launchVer, displayVer, FabricResponsoe.Responses.NeedMojangVer); + } + else + { + return new FabricResponsoe("", "Version", FabricResponsoe.Responses.NeedMojangVer); + } + } + } + + public class FabricResponsoe + { + public string LaunchVer { get { return launchVer; } } + private string launchVer; + public string DisplayVer { get { return displayVer; } } + private string displayVer; + public Responses Response { get { return response; } } + private Responses response; + + public enum Responses + { + ExistsOrCreated, + NeedMojangVer + } + public FabricResponsoe(string launchver, string displayver, Responses response) + { + this.launchVer = launchver; + this.displayVer = displayver; + this.response = response; + } + } + public class UIChangeRequestedEventArgs : EventArgs + { + public bool UI { get; set; } + public UIChangeRequestedEventArgs(bool ui) + { + this.UI = ui; + } + } + public class StatusChangedEventArgs : EventArgs + { + public string Status { get; set; } + public StatusChangedEventArgs(string status) + { + this.Status = status; + } + } + public class ProgressChangedEventArgs : EventArgs + { + public int? MaxFiles { get; set; } + // + public int? CurrentFile { get; set; } + // + public int? ProgressPercentage { get; set; } + public ProgressChangedEventArgs(int? currentfile = null, int? maxfiles = null, int? currentProg = null) + { + MaxFiles = maxfiles; + CurrentFile = currentfile; + ProgressPercentage = currentProg; + } + } + } +} \ No newline at end of file diff --git a/SDLauncher UWP/SettingsData.cs b/SDLauncher UWP/Helpers/SettingsDataManager.cs similarity index 76% rename from SDLauncher UWP/SettingsData.cs rename to SDLauncher UWP/Helpers/SettingsDataManager.cs index 2d0a59fe..7ebc11b1 100644 --- a/SDLauncher UWP/SettingsData.cs +++ b/SDLauncher UWP/Helpers/SettingsDataManager.cs @@ -14,10 +14,11 @@ using System.Collections.ObjectModel; using System.Runtime.CompilerServices; using System.ComponentModel; +using SDLauncher_UWP.Helpers; -namespace SDLauncher_UWP +namespace SDLauncher_UWP.Helpers { - public class SettingsData + public class SettingsDataManager { public async Task CreateSettingsFile(bool? Exit) @@ -71,6 +72,19 @@ public async Task CreateSettingsFile(bool? Exit) writer.WriteAttributeString("HashCheck", vars.HashCheck.ToString()); writer.WriteAttributeString("AssetsCheck", vars.AssestsCheck.ToString()); writer.WriteEndElement(); + writer.WriteStartElement("JVM"); + if (vars.JVMScreenWidth != 0 && vars.JVMScreenHeight != 0) + { + writer.WriteAttributeString("ScreenWidth", vars.JVMScreenWidth.ToString()); + writer.WriteAttributeString("ScreenHeight", vars.JVMScreenHeight.ToString()); + } + else + { + writer.WriteAttributeString("ScreenWidth", 0.ToString()); + writer.WriteAttributeString("ScreenHeight", 0.ToString()); + } + writer.WriteAttributeString("FullScreen", vars.FullScreen.ToString()); + writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteStartElement("App"); writer.WriteComment("\n The theme of the app" + @@ -92,6 +106,9 @@ public async Task CreateSettingsFile(bool? Exit) writer.WriteStartElement("AutoLogin"); writer.WriteAttributeString("value", vars.autoLog.ToString()); writer.WriteEndElement(); + writer.WriteStartElement("UseOldVersionsSeletor"); + writer.WriteAttributeString("value", vars.UseOldVerSeletor.ToString()); + writer.WriteEndElement(); writer.WriteStartElement("Discord"); writer.WriteAttributeString("IsPinned", vars.IsFixedDiscord.ToString()); writer.WriteEndElement(); @@ -127,7 +144,12 @@ public async Task LoadSettingsFile() string hashcheck; string assetscheck; string autolog; + string oldVer; string fixDiscord; + string jvmArgs; + string jvmWidth; + string jvmHeight; + string jvmFullScreen; using (IRandomAccessStream stream = await storagefile.OpenAsync(FileAccessMode.Read)) { Stream s = stream.AsStreamForRead(); @@ -144,6 +166,10 @@ public async Task LoadSettingsFile() reader.ReadToFollowing("Downloader"); hashcheck = reader.GetAttribute("HashCheck"); assetscheck = reader.GetAttribute("AssetsCheck"); + reader.ReadToFollowing("JVM"); + jvmWidth = reader.GetAttribute("ScreenWidth"); + jvmHeight = reader.GetAttribute("ScreenHeight"); + jvmFullScreen = reader.GetAttribute("FullScreen"); reader.ReadToFollowing("App"); reader.ReadToFollowing("Theme"); theme = reader.GetAttribute("value"); @@ -151,6 +177,8 @@ public async Task LoadSettingsFile() tips = reader.GetAttribute("value"); reader.ReadToFollowing("AutoLogin"); autolog = reader.GetAttribute("value"); + reader.ReadToFollowing("UseOldVersionsSeletor"); + oldVer = reader.GetAttribute("value"); reader.ReadToFollowing("Discord"); fixDiscord = reader.GetAttribute("IsPinned"); @@ -179,28 +207,36 @@ public async Task LoadSettingsFile() } try { - string last = list[i].Attributes["LastAccessed"].Value; - if (last == "False") + var lastv = list[i].Attributes["LastAccessed"]; + if (lastv != null) { - if(string.IsNullOrEmpty(avatarid)) + string last = lastv.Value; + if (last == "False") { - Accounts.Add(new Account(list[i].Attributes["Username"].Value, list[i].Attributes["Type"].Value, list[i].Attributes["AccessToken"].Value, list[i].Attributes["UUID"].Value, Accounts.Count + 1, false)); + if (string.IsNullOrEmpty(avatarid)) + { + Accounts.Add(new Account(list[i].Attributes["Username"].Value, list[i].Attributes["Type"].Value, list[i].Attributes["AccessToken"].Value, list[i].Attributes["UUID"].Value, Accounts.Count + 1, false)); + } + else + { + Accounts.Add(new Account(list[i].Attributes["Username"].Value, list[i].Attributes["Type"].Value, list[i].Attributes["AccessToken"].Value, list[i].Attributes["UUID"].Value, Accounts.Count + 1, false, int.Parse(avatarid))); + } } else { - Accounts.Add(new Account(list[i].Attributes["Username"].Value, list[i].Attributes["Type"].Value, list[i].Attributes["AccessToken"].Value, list[i].Attributes["UUID"].Value, Accounts.Count + 1, false,int.Parse(avatarid))); + if (string.IsNullOrEmpty(avatarid)) + { + Accounts.Add(new Account(list[i].Attributes["Username"].Value, list[i].Attributes["Type"].Value, list[i].Attributes["AccessToken"].Value, list[i].Attributes["UUID"].Value, Accounts.Count + 1, true)); + } + else + { + Accounts.Add(new Account(list[i].Attributes["Username"].Value, list[i].Attributes["Type"].Value, list[i].Attributes["AccessToken"].Value, list[i].Attributes["UUID"].Value, Accounts.Count + 1, true, int.Parse(avatarid))); + } } } else { - if (string.IsNullOrEmpty(avatarid)) - { - Accounts.Add(new Account(list[i].Attributes["Username"].Value, list[i].Attributes["Type"].Value, list[i].Attributes["AccessToken"].Value, list[i].Attributes["UUID"].Value, Accounts.Count + 1, true)); - } - else - { - Accounts.Add(new Account(list[i].Attributes["Username"].Value, list[i].Attributes["Type"].Value, list[i].Attributes["AccessToken"].Value, list[i].Attributes["UUID"].Value, Accounts.Count + 1, true,int.Parse(avatarid))); - } + throw new Exception(); } } catch @@ -221,6 +257,20 @@ public async Task LoadSettingsFile() vars.AccountsCount = Accounts.Count; } } + int jvmwidth; + int jvmheight; + try + { + jvmheight = int.Parse(jvmHeight); + jvmwidth = int.Parse(jvmWidth); + } + catch + { + jvmwidth = 0; + jvmheight = 0; + } + vars.JVMScreenWidth = jvmwidth; + vars.JVMScreenHeight = jvmheight; vars.LoadedRam = int.Parse(ram); if (theme == "Default") { @@ -258,6 +308,14 @@ public async Task LoadSettingsFile() { vars.HashCheck = false; } + if (oldVer == "True") + { + vars.UseOldVerSeletor = true; + } + else + { + vars.UseOldVerSeletor = false; + } if (assetscheck == "True") { vars.AssestsCheck = true; @@ -282,6 +340,14 @@ public async Task LoadSettingsFile() { vars.IsFixedDiscord = false; } + if (jvmFullScreen == "True") + { + vars.FullScreen = true; + } + else + { + vars.FullScreen = false; + } if (vars.autoLog) { foreach (var item in vars.Accounts) @@ -318,61 +384,4 @@ public async Task LoadSettingsFile() } } - public class Account : INotifyPropertyChanged - { - public event PropertyChangedEventHandler PropertyChanged = delegate { }; - List PicList = new List(); - private string userName; - public string UserName { get { return userName; } set { userName = value; OnPropertyChanged(); } } - public string ProfilePicture { get; set; } - public string Type { get; set; } - public string TypeIconGlyph { get; set; } - public string AccessToken { get; set; } - public string UUID { get; set; } - public int Count { get; set; } - public int ProfileAvatarID { get; set; } - public bool Last { get; set; } - // For app UI - private Visibility isCheckboxVsible; - public Visibility IsCheckboxVsible { get { return isCheckboxVsible; } set { isCheckboxVsible = value; OnPropertyChanged(); } } - private bool sChecked; - public bool IsChecked { get { return sChecked; } set { sChecked = value; OnPropertyChanged(); } } - - public void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); - } - public Account(string username, string type, string accesstoken, string uuid, int count, bool last, int? pic = null) - { - IsCheckboxVsible = Visibility.Collapsed; - IsChecked = false; - PicList.Add("https://raw.githubusercontent.com/Chaniru22/SDLauncher/main/Pictures/steve.png"); - PicList.Add("https://raw.githubusercontent.com/Chaniru22/SDLauncher/main/Pictures/NoobSteve.png"); - PicList.Add("https://raw.githubusercontent.com/Chaniru22/SDLauncher/main/Pictures/alex.png"); - if (pic == null) - { - Random r = new Random(); - int index = r.Next(PicList.Count); - ProfilePicture = PicList[index]; - ProfileAvatarID = index; - } - else - { - ProfilePicture = PicList[(int)pic]; - ProfileAvatarID = (int)pic; - } - UserName = username; - Type = type; - AccessToken = accesstoken; - UUID = uuid; - Count = count; - Last = last; - if(UUID != "null") - { - ProfilePicture = "https://minotar.net/avatar/" + UUID; - ProfileAvatarID = 3; - } - TypeIconGlyph = Type == "Offline" ? "\xF384" : "\xEC05"; - } - } } diff --git a/SDLauncher UWP/Util.cs b/SDLauncher UWP/Helpers/Util.cs similarity index 99% rename from SDLauncher UWP/Util.cs rename to SDLauncher UWP/Helpers/Util.cs index 2c10b564..15104908 100644 --- a/SDLauncher UWP/Util.cs +++ b/SDLauncher UWP/Helpers/Util.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; using Windows.System.Diagnostics; -namespace SDLauncher_UWP +namespace SDLauncher_UWP.Helpers { public class Util { diff --git a/SDLauncher UWP/Login.xaml b/SDLauncher UWP/Login.xaml deleted file mode 100644 index 376a3565..00000000 --- a/SDLauncher UWP/Login.xaml +++ /dev/null @@ -1,252 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SDLauncher UWP/Package.appxmanifest b/SDLauncher UWP/Package.appxmanifest index d01ef5b4..dab5773c 100644 --- a/SDLauncher UWP/Package.appxmanifest +++ b/SDLauncher UWP/Package.appxmanifest @@ -11,7 +11,7 @@ + Version="0.3.1.0" /> @@ -47,14 +47,6 @@ - - - - - @@ -62,6 +54,8 @@ + + diff --git a/SDLauncher UWP/Resources/ExpanderStyle.xaml b/SDLauncher UWP/Resources/ExpanderStyle.xaml new file mode 100644 index 00000000..9e8179e6 --- /dev/null +++ b/SDLauncher UWP/Resources/ExpanderStyle.xaml @@ -0,0 +1,671 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 16 + + + + + + + diff --git a/SDLauncher UWP/Resources/LocalizedStrings.cs b/SDLauncher UWP/Resources/LocalizedStrings.cs new file mode 100644 index 00000000..107f6a80 --- /dev/null +++ b/SDLauncher UWP/Resources/LocalizedStrings.cs @@ -0,0 +1,27 @@ +using SDLauncher_UWP.Helpers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SDLauncher_UWP.Resources +{ + public static class Localized + { + public static string Welcome { get { return Localizer.GetLocalizedString("Welcome"); } } + public static string GoodLuck { get { return Localizer.GetLocalizedString("GoodLuck"); } } + public static string GoodEvening { get { return Localizer.GetLocalizedString("GoodEvening"); } } + public static string GettingVers { get { return Localizer.GetLocalizedString("GettingVers"); } } + public static string Ready { get { return Localizer.GetLocalizedString("Ready"); } } + public static string RamFailed { get { return Localizer.GetLocalizedString("RamFailed"); } } + public static string GoodMorning { get { return Localizer.GetLocalizedString("GoodMorning"); } } + public static string BegLogIn { get { return Localizer.GetLocalizedString("BegLogIn"); } } + public static string Error { get { return Localizer.GetLocalizedString("Error"); } } + public static string BegVer { get { return Localizer.GetLocalizedString("BegVer"); } } + public static string WrongRAM { get { return Localizer.GetLocalizedString("WrongRAM"); } } + public static string NoNetwork { get { return Localizer.GetLocalizedString("NoNetwork"); } } + public static string Win32Error { get { return Localizer.GetLocalizedString("Win32Error"); } } + public static string GetVerFailed { get { return Localizer.GetLocalizedString("GetVerFailed"); } } + } +} diff --git a/SDLauncher UWP/SDLauncher UWP.csproj b/SDLauncher UWP/SDLauncher UWP.csproj index c8e8613f..a8c0b4d0 100644 --- a/SDLauncher UWP/SDLauncher UWP.csproj +++ b/SDLauncher UWP/SDLauncher UWP.csproj @@ -128,27 +128,42 @@ App.xaml - + + + Login.xaml - - - + + + + + + + + + ArgumentsListView.xaml + + + SettingsCard.xaml + + + Expander.xaml + BaseLauncherPage.xaml - + MainPage.xaml - + MessageBoxEx.xaml CursedForgePage.xaml - + SettingsPage.xaml @@ -221,7 +236,23 @@ MSBuild:Compile Designer - + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + Designer MSBuild:Compile @@ -229,11 +260,11 @@ Designer MSBuild:Compile - + MSBuild:Compile Designer - + Designer MSBuild:Compile @@ -256,9 +287,6 @@ 1.1.1 - - 1.1.3 - 6.2.12 @@ -266,7 +294,7 @@ 7.1.2 - 2.8.0-prerelease.220118001 + 2.8.0-prerelease.220413001 1.1.0 @@ -277,8 +305,13 @@ Always + + + + + Windows Desktop Extensions for the UWP + - 14.0 diff --git a/SDLauncher UWP/Strings/en-US/Resources.resw b/SDLauncher UWP/Strings/en-US/Resources.resw new file mode 100644 index 00000000..5056bde7 --- /dev/null +++ b/SDLauncher UWP/Strings/en-US/Resources.resw @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Please Login + + + Please enter a version + + + Error + + + Getting available versions... + + + Failed to get the version + + + Good Evening + + + Good Luck + + + Good Morning + + + Login + + + For a better RPC please add a small status! + + + Status: + + + Seems like you don't have good internet... + + + Failed to get the RAM of the device. + Rarely Used + + + Ready + + + Settings + + + Welcome + Rarely Used + + + It seems your java setting has problem + Rarely Used + + + Invalid RAM + Rarely Used + + \ No newline at end of file diff --git a/SDLauncher UWP/UserControls/ArgumentsListView.xaml b/SDLauncher UWP/UserControls/ArgumentsListView.xaml new file mode 100644 index 00000000..2d7ee588 --- /dev/null +++ b/SDLauncher UWP/UserControls/ArgumentsListView.xaml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SDLauncher UWP/UserControls/ArgumentsListView.xaml.cs b/SDLauncher UWP/UserControls/ArgumentsListView.xaml.cs new file mode 100644 index 00000000..2aded985 --- /dev/null +++ b/SDLauncher UWP/UserControls/ArgumentsListView.xaml.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Navigation; + +// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 + +namespace SDLauncher_UWP.UserControls +{ + public sealed partial class ArgumentsListView : UserControl + { + private int count = 0; + public ArgumentsListView() + { + this.InitializeComponent(); + view.ItemsSource = source; + } + + + private List source = new List(); + private void btnAdd_Click(object sender, RoutedEventArgs e) + { + count++; + var r = new ArgTemplate { Arg = "", Count = count }; + source.Add(r); + RefreshView(); + view.SelectedItem = r; + } + private void UpdateSource() + { + source = new List(); + foreach (var item in vars.JVMArgs) + { + count++; + var r = new ArgTemplate { Arg = item, Count = count }; + source.Add(r); + } + } + private void RefreshView() + { + view.ItemsSource = null; + view.ItemsSource = source; + } + private void UpdateMainSource() + { + vars.JVMArgs = new List(); + foreach (var item in source) + { + vars.JVMArgs.Add(item.Arg); + } + } + private void btnRemove_Click(object sender, RoutedEventArgs e) + { + foreach (var item in view.SelectedItems) + { + source.Remove((ArgTemplate)item); + } + RefreshView(); + } + + private void TextBox_PointerPressed(object sender, PointerRoutedEventArgs e) + { + if(sender is TextBox bx) + { + foreach (var item in source) + { + if(item.Count == int.Parse(bx.Tag.ToString())) + { + view.SelectedItem = null; + view.SelectedItem = item; + return; + } + } + } + } + + private void TextBox_TextChanged(object sender, TextChangedEventArgs e) + { + + if (sender is TextBox bx) + { + foreach (var item in source) + { + if (item.Count == int.Parse(bx.Tag.ToString())) + { + item.Arg = bx.Text; + view.SelectedItem = null; + view.SelectedItem = item; + UpdateMainSource(); + return; + } + } + } + } + + private void TextBox_GotFocus(object sender, RoutedEventArgs e) + { + + if (sender is TextBox bx) + { + foreach (var item in source) + { + if (item.Count == int.Parse(bx.Tag.ToString())) + { + view.SelectedItem = null; + view.SelectedItem = item; + return; + } + } + } + } + } + public class ArgTemplate + { + public string Arg { get; set; } + public int Count { get; set; } + } +} diff --git a/SDLauncher UWP/UserControls/Expander.xaml b/SDLauncher UWP/UserControls/Expander.xaml new file mode 100644 index 00000000..d7816318 --- /dev/null +++ b/SDLauncher UWP/UserControls/Expander.xaml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SDLauncher UWP/UserControls/Expander.xaml.cs b/SDLauncher UWP/UserControls/Expander.xaml.cs new file mode 100644 index 00000000..b1ad54cf --- /dev/null +++ b/SDLauncher UWP/UserControls/Expander.xaml.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Media.Animation; +using Windows.UI.Xaml.Navigation; + +// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 + +namespace SDLauncher_UWP.UserControls +{ + public sealed partial class Expander : UserControl + { + public Expander() + { + this.InitializeComponent(); + } + + + + public TransitionCollection ControlsTransition + { + get { return (TransitionCollection)GetValue(ControlsTransitionProperty); } + set { SetValue(ControlsTransitionProperty, value); } + } + + // Using a DependencyProperty as the backing store for ControlsTransition. This enables animation, styling, binding, etc... + public static readonly DependencyProperty ControlsTransitionProperty = + DependencyProperty.Register("ControlsTransition", typeof(TransitionCollection), typeof(Expander), null); + + + + + public bool IsExpanded + { + get { return (bool)GetValue(IsExpandedProperty); } + set { SetValue(IsExpandedProperty, value); } + } + + // Using a DependencyProperty as the backing store for IsExpanded. This enables animation, styling, binding, etc... + public static readonly DependencyProperty IsExpandedProperty = + DependencyProperty.Register("IsExpanded", typeof(bool), typeof(Expander), null); + + + public string Icon + { + get { return (string)GetValue(IconProperty); } + set { SetValue(IconProperty, value); } + } + + // Using a DependencyProperty as the backing store for Icon. This enables animation, styling, binding, etc... + public static readonly DependencyProperty IconProperty = + DependencyProperty.Register("Icon", typeof(string), typeof(Expander), null); + + + public string Title + { + get { return (string)GetValue(TitleProperty); } + set { SetValue(TitleProperty, value); } + } + + // Using a DependencyProperty as the backing store for Title. This enables animation, styling, binding, etc... + public static readonly DependencyProperty TitleProperty = + DependencyProperty.Register("Title", typeof(string), typeof(Expander), null); + + + + public string Description + { + get { return (string)GetValue(DescriptionProperty); } + set { SetValue(DescriptionProperty, value); } + } + + // Using a DependencyProperty as the backing store for Description. This enables animation, styling, binding, etc... + public static readonly DependencyProperty DescriptionProperty = + DependencyProperty.Register("Description", typeof(string), typeof(Expander), null); + + + + public object HeaderControls + { + get { return (object)GetValue(HeaderControlsProperty); } + set { SetValue(HeaderControlsProperty, value); } + } + + // Using a DependencyProperty as the backing store for HeaderControls. This enables animation, styling, binding, etc... + public static readonly DependencyProperty HeaderControlsProperty = + DependencyProperty.Register("HeaderControls", typeof(object), typeof(Expander), null); + + + + public object Controls + { + get { return (object)GetValue(ControlsProperty); } + set { SetValue(ControlsProperty, value); } + } + + // Using a DependencyProperty as the backing store for Controls. This enables animation, styling, binding, etc... + public static readonly DependencyProperty ControlsProperty = + DependencyProperty.Register("Controls", typeof(object), typeof(Expander), null); + + private void container_Loaded(object sender, RoutedEventArgs e) + { + if (ControlsTransition != null) + { + container.ChildrenTransitions = ControlsTransition; + } + } + } +} diff --git a/SDLauncher UWP/UserControls/SettingsCard.xaml b/SDLauncher UWP/UserControls/SettingsCard.xaml new file mode 100644 index 00000000..a372341a --- /dev/null +++ b/SDLauncher UWP/UserControls/SettingsCard.xaml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SDLauncher UWP/UserControls/SettingsCard.xaml.cs b/SDLauncher UWP/UserControls/SettingsCard.xaml.cs new file mode 100644 index 00000000..55461927 --- /dev/null +++ b/SDLauncher UWP/UserControls/SettingsCard.xaml.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Navigation; + +// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 + +namespace SDLauncher_UWP.UserControls +{ + public sealed partial class SettingsCard : UserControl + { + public SettingsCard() + { + this.InitializeComponent(); + } + + public string Icon + { + get { return (string)GetValue(IconProperty); } + set { SetValue(IconProperty, value); } + } + + // Using a DependencyProperty as the backing store for Icon. This enables animation, styling, binding, etc... + public static readonly DependencyProperty IconProperty = + DependencyProperty.Register("Icon", typeof(string), typeof(SettingsCard), null); + + + public string Title + { + get { return (string)GetValue(TitleProperty); } + set { SetValue(TitleProperty, value); } + } + + // Using a DependencyProperty as the backing store for Title. This enables animation, styling, binding, etc... + public static readonly DependencyProperty TitleProperty = + DependencyProperty.Register("Title", typeof(string), typeof(SettingsCard), null); + + + public string Description + { + get { return (string)GetValue(DescriptionProperty); } + set { SetValue(DescriptionProperty, value); } + } + + // Using a DependencyProperty as the backing store for Description. This enables animation, styling, binding, etc... + public static readonly DependencyProperty DescriptionProperty = + DependencyProperty.Register("Description", typeof(string), typeof(SettingsCard), null); + + + public object Controls + { + get { return (object)GetValue(ControlsProperty); } + set { SetValue(ControlsProperty, value); } + } + + // Using a DependencyProperty as the backing store for Controls. This enables animation, styling, binding, etc... + public static readonly DependencyProperty ControlsProperty = + DependencyProperty.Register("Controls", typeof(object), typeof(SettingsCard), null); + } +} diff --git a/SDLauncher UWP/Views/BaseLauncherPage.xaml b/SDLauncher UWP/Views/BaseLauncherPage.xaml index e843e301..f6038f12 100644 --- a/SDLauncher UWP/Views/BaseLauncherPage.xaml +++ b/SDLauncher UWP/Views/BaseLauncherPage.xaml @@ -4,7 +4,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:SDLauncher_UWP" Loaded="Page_Loaded" - xmlns:controls="using:Microsoft.UI.Xaml.Controls" + xmlns:winui="using:Microsoft.UI.Xaml.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals" mc:Ignorable="d"> @@ -22,7 +22,7 @@ - - - - - - + + + + - - - - + + + + @@ -58,10 +58,10 @@ - - - - + + + + @@ -101,8 +101,8 @@ - - + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - public sealed partial class SettingsPage : Page { + public event EventHandler BackRequested = delegate { }; public SettingsPage() { this.InitializeComponent(); @@ -36,7 +38,7 @@ public void SetRam(long val) txtRam.Text = val.ToString() + "MB"; SliderRam.Value = val; vars.CurrentRam = (int)SliderRam.Value; - if (vars.SliderRamMax != null && vars.SliderRamMax != null) + if (vars.SliderRamMax != 0 && vars.SliderRamMax != 0) SliderRam.Maximum = vars.SliderRamMax; SliderRam.Minimum = vars.SliderRamMin; } @@ -130,27 +132,34 @@ private void Page_Loaded(object sender, RoutedEventArgs e) cmbxTheme.SelectedIndex = 2; } cbAsset.IsChecked = vars.AssestsCheck; + chkbxFullScreen.IsChecked = vars.FullScreen; + if(vars.JVMScreenWidth != 0 && vars.JVMScreenHeight != 0) + { + nbrbxHeight.Value = vars.JVMScreenHeight; + nbrbxWidth.Value = vars.JVMScreenWidth; + } + RefreshScreenData(); cbHash.IsChecked = vars.HashCheck; switchAutolog.IsOn = vars.autoLog; + tglOldVerSelector.IsOn = vars.UseOldVerSeletor; pageCount++; if (pageCount == 1) { SetRam(vars.LoadedRam); } - if(vars.LauncherSynced != null) + if(vars.Launcher.Launcher != null) { - txtGamePath.Text = vars.LauncherSynced.MinecraftPath.BasePath; + txtGamePath.Text = vars.Launcher.Launcher.MinecraftPath.BasePath; } } private async void btnXML_Click(object sender, RoutedEventArgs e) { - var p = new MessageBoxEx("Information", "You need to close the application before editing the XML file. \nContinue ?", MessageBoxEx.Buttons.OkCancel); - await p.ShowAsync(); - if (p.Result == MessageBoxEx.Results.Ok) + + if (await MessageBox.Show("Information", "You need to close the application before editing the XML file. \nContinue ?", MessageBoxButtons.OkCancel) == MessageBoxResults.Ok) { vars.showXMLOnClose = true; - new SettingsData().CreateSettingsFile(true); + await new SettingsDataManager().CreateSettingsFile(true); } } @@ -195,5 +204,145 @@ private async void btnCopyDir_Click(object sender, RoutedEventArgs e) await Task.Delay(TimeSpan.FromSeconds(2)); smbCopyDir.Glyph = "\xE71B"; } + + private void btnRefreshVers_Click(object sender, RoutedEventArgs e) + { + _ = vars.Launcher.RefreshVersions(); + BackRequested(this, new EventArgs()); + } + + private void tglOldVerSelector_Toggled(object sender, RoutedEventArgs e) + { + vars.UseOldVerSeletor = tglOldVerSelector.IsOn; + BackRequested(this, new EventArgs()); + } + + + private void nbrbxWidth_ValueChanged(Microsoft.UI.Xaml.Controls.NumberBox sender, Microsoft.UI.Xaml.Controls.NumberBoxValueChangedEventArgs args) + { + int? r = 0; + if (double.IsNaN(args.NewValue)) + { + r = -1; + } + else + { + var s = Math.Floor(args.NewValue); + r = int.Parse(s.ToString()); + } + SetScreenSize(width: r); + RefreshScreenData(); + } + + private void SetScreenSize(int? width = null,int? height = null) + { + if (width != null) + { + if (width == 0) + { + txtWidth.Visibility = Visibility.Visible; + vars.JVMScreenWidth = 0; + return; + } + if (width == -1) + { + if (!double.IsNaN(nbrbxHeight.Value)) + { + txtWidth.Visibility = Visibility.Visible; + vars.JVMScreenWidth = 0; + return; + } + else + { + txtWidth.Visibility = Visibility.Collapsed; + vars.JVMScreenWidth = 0; + return; + } + } + if (double.IsNaN(nbrbxHeight.Value)) + { + txtHeight.Visibility = Visibility.Visible; + } + txtWidth.Visibility = Visibility.Collapsed; + vars.JVMScreenWidth = (int)width; + return; + } + if (height != null) + { + if (height == 0) + { + txtHeight.Visibility = Visibility.Visible; + vars.JVMScreenHeight = (int)height; + return; + } + if(height == -1) + { + if (!double.IsNaN(nbrbxWidth.Value)) + { + txtHeight.Visibility = Visibility.Visible; + vars.JVMScreenHeight = 0; + return; + } + else + { + txtHeight.Visibility = Visibility.Collapsed; + vars.JVMScreenHeight = 0; + return; + } + } + if (double.IsNaN(nbrbxWidth.Value)) + { + txtWidth.Visibility = Visibility.Visible; + } + txtHeight.Visibility = Visibility.Collapsed; + vars.JVMScreenHeight = (int)height; + return; + } + } + private void nbrbxHeight_ValueChanged(Microsoft.UI.Xaml.Controls.NumberBox sender, Microsoft.UI.Xaml.Controls.NumberBoxValueChangedEventArgs args) + { + int? r = 0; + if (double.IsNaN(args.NewValue)) + { + r = -1; + } + else + { + var s = Math.Floor(args.NewValue); + r = int.Parse(s.ToString()); + } + SetScreenSize(height: r); + RefreshScreenData(); + } + + private void RefreshScreenData() + { + if (vars.FullScreen) + { + nbrbxWidth.IsEnabled = false; + nbrbxHeight.IsEnabled = false; + txtScreenStatus.Text = "Full Screen"; + } + else + { + nbrbxWidth.IsEnabled = true; + nbrbxHeight.IsEnabled = true; + if (vars.JVMScreenWidth != 0 && vars.JVMScreenHeight != 0) + { + txtScreenStatus.Text = vars.JVMScreenWidth + " × " + vars.JVMScreenHeight; + } + else + { + txtWidth.Visibility = Visibility.Collapsed; + txtHeight.Visibility = Visibility.Collapsed; + txtScreenStatus.Text = "Default"; + } + } + } + private void chkbxFullScreen_Click(object sender, RoutedEventArgs e) + { + vars.FullScreen = (bool)chkbxFullScreen.IsChecked; + RefreshScreenData(); + } } -} +} \ No newline at end of file diff --git a/SDLauncher UWP/vars.cs b/SDLauncher UWP/vars.cs index a3f0ba8c..50857b28 100644 --- a/SDLauncher UWP/vars.cs +++ b/SDLauncher UWP/vars.cs @@ -6,11 +6,12 @@ using System.Threading.Tasks; using CmlLib.Core; using CmlLib.Core.Auth; +using SDLauncher_UWP.Helpers; using Windows.UI.Xaml; namespace SDLauncher_UWP { - class vars + public class vars { //App public static bool closing = false; @@ -18,10 +19,10 @@ class vars public static ElementTheme? theme = ElementTheme.Default; public static bool ShowLaunchTips = false; public static bool ShowTips = true; - public static bool UI = true; + public static bool UseOldVerSeletor = false; public static bool autoLog = false; public static int LoadedRam = 1024; - public static CMLauncher LauncherSynced; + public static SDLauncher Launcher; public static ObservableCollection Accounts; public static int AccountsCount; @@ -29,8 +30,12 @@ class vars //CMLLIB public static MSession session; - public static string UserName; + public static string UserName = ""; public static int MinRam; + public static int JVMScreenWidth = 0; + public static int JVMScreenHeight = 0; + public static bool FullScreen = false; + public static List JVMArgs = new List(); public static int CurrentRam = 0; // public static long SliderRamMax; @@ -41,7 +46,5 @@ class vars public static bool HashCheck = true; // public static bool IsFixedDiscord = false; - // - public static string ProgressStatus; } }