diff --git a/Package/Package.appxmanifest b/Package/Package.appxmanifest index 01e49313..01b5323c 100644 --- a/Package/Package.appxmanifest +++ b/Package/Package.appxmanifest @@ -11,7 +11,7 @@ + Version="0.4.7.0" /> SD Launcher diff --git a/Package/Package.wapproj b/Package/Package.wapproj index 22c57d14..1ed499cb 100644 --- a/Package/Package.wapproj +++ b/Package/Package.wapproj @@ -61,7 +61,7 @@ SHA256 False True - x86|x64|arm + x64 C:\ 0 diff --git a/SDLauncher UWP/App.xaml.cs b/SDLauncher UWP/App.xaml.cs index 482b73a7..9b061501 100644 --- a/SDLauncher UWP/App.xaml.cs +++ b/SDLauncher UWP/App.xaml.cs @@ -1,4 +1,5 @@ -using Microsoft.Toolkit.Uwp.Helpers; +using CmlLib.Core.Auth; +using Microsoft.Toolkit.Uwp.Helpers; using SDLauncher_UWP.Helpers; using System; using System.Collections.Generic; @@ -37,9 +38,9 @@ public App() this.InitializeComponent(); this.Suspending += OnSuspending; } - SettingsDataManager settings = new SettingsDataManager(); public static event EventHandler AppServiceConnected = delegate { }; public static AppServiceConnection Connection { get; private set; } + public bool Loaded = false; public BackgroundTaskDeferral AppServiceDeferral { get; private set; } /// @@ -49,43 +50,60 @@ public App() /// Details about the launch request and process. protected async override void OnLaunched(LaunchActivatedEventArgs e) { - if (!SystemInformation.Instance.IsFirstRun) + if (SystemInformation.Instance.IsFirstRun) { - try - { - await ApplicationData.Current.RoamingFolder.GetFileAsync("settings.xml"); - } - catch - { - await settings.CreateSettingsFile(false); - } - try - { - await settings.LoadSettingsFile(); - } - catch - { - vars.CurrentRam = 2048; - try - { - await settings.CreateSettingsFile(false); - await settings.LoadSettingsFile(); - } - catch { } - } + ApplicationData.Current.RoamingSettings.Values["IsInAppSettings"] = false.ToString(); + } + bool IsInAppSettings = false; + try + { + IsInAppSettings = bool.Parse(ApplicationData.Current.RoamingSettings.Values["IsInAppSettings"] as string); + } + catch + { + ApplicationData.Current.RoamingSettings.Values["IsInAppSettings"] = false.ToString(); + } + if (IsInAppSettings == false) + { + await SettingsManager.LoadSettings(); } else { - vars.CurrentRam = 2048; - try + SettingsManager.DeserializeSettings(ApplicationData.Current.RoamingSettings.Values["InAppSettings"] as string); + } + Frame rootFrame = Window.Current.Content as Frame; + if (vars.autoLog && vars.Accounts != null) + { + foreach (var item in vars.Accounts) { - await settings.CreateSettingsFile(false); - await settings.LoadSettingsFile(); + if (item.Last) + { + if (item.Type != null) + { + if (item.Type == "Offline") + { + if (item.UserName == null) + { + vars.session = null; + } + else + { + vars.session = MSession.GetOfflineSession(item.UserName); + } + } + else + { + if (item.UserName != null && item.AccessToken != null && item.UUID != null) + { + vars.session = new MSession(item.UserName, item.AccessToken, item.UUID); + } + } + } + vars.CurrentAccountCount = item.Count; + } } - catch { } + Loaded = true; } - Frame rootFrame = Window.Current.Content as Frame; - // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) @@ -148,28 +166,7 @@ protected async override void OnActivated(IActivatedEventArgs args) if (args.Kind == ActivationKind.CommandLineLaunch) { - if (!SystemInformation.Instance.IsFirstRun) - { - try - { - await ApplicationData.Current.RoamingFolder.GetFileAsync("settings.xml"); - } - catch - { - await settings.CreateSettingsFile(false); - } - await settings.LoadSettingsFile(); - } - else - { - vars.CurrentRam = 2048; - try - { - await settings.CreateSettingsFile(false); - await settings.LoadSettingsFile(); - } - catch { } - } + await SettingsManager.LoadSettings(); Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, @@ -192,7 +189,20 @@ protected async override void OnActivated(IActivatedEventArgs args) } private async void App_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { - await settings.CreateSettingsFile(false); + e.Handled = true; + if (!vars.closing && Loaded) + { + vars.closing = true; + if (bool.Parse(ApplicationData.Current.RoamingSettings.Values["IsInAppSettings"] as string) == false) + { + await SettingsManager.SaveSettings(); + } + else + { + ApplicationData.Current.RoamingSettings.Values["InAppSettings"] = await SettingsManager.SerializeSettings(); + } + } + Application.Current.Exit(); } /// diff --git a/SDLauncher UWP/Dialogs/Login.xaml b/SDLauncher UWP/Dialogs/Login.xaml index a5deca22..f7865965 100644 --- a/SDLauncher UWP/Dialogs/Login.xaml +++ b/SDLauncher UWP/Dialogs/Login.xaml @@ -2,133 +2,314 @@ Loaded="ContentDialog_Loaded" x:Class="SDLauncher_UWP.Login" CloseButtonText="Exit" - CloseButtonStyle="{ThemeResource ButtonRevealStyle}" - xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:local="using:SDLauncher_UWP" - xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - mc:Ignorable="d" - xmlns:winui="using:Microsoft.UI.Xaml.Controls" xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals" xmlns:helpers="using:SDLauncher_UWP.Helpers" + CloseButtonStyle="{ThemeResource ButtonRevealStyle}" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:SDLauncher_UWP" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + mc:Ignorable="d" xmlns:winui="using:Microsoft.UI.Xaml.Controls" xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals" xmlns:helpers="using:SDLauncher_UWP.Helpers" Title="Login" Background="{ThemeResource AcrylicInAppFillColorDefaultBrush}" PrimaryButtonClick="ContentDialog_PrimaryButtonClick" CornerRadius="10" SecondaryButtonClick="ContentDialog_SecondaryButtonClick"> - - + - + + - + - - - - - + + + + + - - - - - - + + + + + + - - - + + - + - - + + - + - - + + - - - + - - - - + + - + - - + + - + - - - + - + - - + + - + - - + + - + - - - + + + - - - - - + + + + + - + - - - + + + - + - - - - - + + + + + - - - - - - - - - @@ -230,28 +534,51 @@ - - + - + - - + + - - + + - + - - - - + + + + @@ -259,4 +586,4 @@ - + \ No newline at end of file diff --git a/SDLauncher UWP/Dialogs/Login.xaml.cs b/SDLauncher UWP/Dialogs/Login.xaml.cs index fa59d15b..eaede0a4 100644 --- a/SDLauncher UWP/Dialogs/Login.xaml.cs +++ b/SDLauncher UWP/Dialogs/Login.xaml.cs @@ -290,7 +290,7 @@ private void LogOutFromCache(object sender, RoutedEventArgs e) } - void AddAccount(MSession session) + public void AddAccount(MSession session) { foreach (var item in vars.Accounts) { @@ -301,7 +301,7 @@ void AddAccount(MSession session) } if (session.UserType == "Mojang") { - vars.Accounts.Add(new Account(session.Username, "Offline", "null", "null", vars.AccountsCount + 1, true)); + vars.Accounts.Add(new Account(session.Username, "Offline", null, null, vars.AccountsCount + 1, true)); vars.AccountsCount++; } else diff --git a/SDLauncher UWP/Dialogs/MessageBoxEx.xaml.cs b/SDLauncher UWP/Dialogs/MessageBoxEx.xaml.cs index fb2639f0..5b19cd2f 100644 --- a/SDLauncher UWP/Dialogs/MessageBoxEx.xaml.cs +++ b/SDLauncher UWP/Dialogs/MessageBoxEx.xaml.cs @@ -140,9 +140,15 @@ private void ContentDialog_CloseButtonClick(ContentDialog sender, ContentDialogB } public class MessageBox { - public static async Task Show(string title,string caption, MessageBoxButtons buttons,string customResult1 = null, string customResult2 = null) + public static async Task Show(string title, string caption, MessageBoxButtons buttons, string customResult1 = null, string customResult2 = null) { - var d = new MessageBoxEx(title, caption, buttons,customResult1,customResult2); + var d = new MessageBoxEx(title, caption, buttons, customResult1, customResult2); + await d.ShowAsync(); + return d.Result; + } + public static async Task Show(string text) + { + var d = new MessageBoxEx("Information", text, MessageBoxButtons.Ok); await d.ShowAsync(); return d.Result; } diff --git a/SDLauncher UWP/Helpers/Account.cs b/SDLauncher UWP/Helpers/Account.cs index 63ed0051..423ac000 100644 --- a/SDLauncher UWP/Helpers/Account.cs +++ b/SDLauncher UWP/Helpers/Account.cs @@ -21,7 +21,6 @@ public class Account : INotifyPropertyChanged 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; @@ -33,35 +32,23 @@ 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) + public Account(string username, string type, string accesstoken, string uuid, int count, bool last) { IsCheckboxVsible = Visibility.Collapsed; IsChecked = false; - PicList.Add("https://github.com/SeaDevTeam/SDLauncher/raw/main/Pictures/steve.png"); - PicList.Add("https://github.com/SeaDevTeam/SDLauncher/raw/main/Pictures/NoobSteve.png"); - PicList.Add("https://github.com/SeaDevTeam/SDLauncher/raw/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") + if (UUID != null) { ProfilePicture = "https://minotar.net/avatar/" + UUID; - ProfileAvatarID = 3; + } + else + { + ProfilePicture = "https://minotar.net/avatar/MHF_Steve" + UUID; } TypeIconGlyph = Type == "Offline" ? "\xF384" : "\xEC05"; } diff --git a/SDLauncher UWP/Helpers/GlacierClient.cs b/SDLauncher UWP/Helpers/GlacierClient.cs index 7cec50c4..acf21b03 100644 --- a/SDLauncher UWP/Helpers/GlacierClient.cs +++ b/SDLauncher UWP/Helpers/GlacierClient.cs @@ -33,68 +33,53 @@ public async Task ClientExists() } public async void DownloadClient() { - UIChangedReqested(false, new EventArgs()); - try - { - Uri source = new Uri("https://slashonline.net/glacier/get/release/Glacier.zip".Trim()); - string destination = "Glacier.zip"; - - StorageFile destinationFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync( - destination, - CreationCollisionOption.ReplaceExisting); - - BackgroundDownloader downloader = new BackgroundDownloader(); - DownloadOperation download = downloader.CreateDownload(source, destinationFile); - StartDownloadWithProgress(download); - } - catch - { - - } - } - DownloadOperation operation; - DispatcherTimer downloadprog = new DispatcherTimer(); - private async void StartDownloadWithProgress(DownloadOperation operation) - { - StatusChanged("Downloading Glacier Client", 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) - { - if (operation.Progress.Status == BackgroundTransferStatus.Completed) - { - DownloadFileCompleted(); - downloadprog.Stop(); - ProgressChanged(0, new SDLauncher.ProgressChangedEventArgs(currentfile:0)); - } - else if (operation.Progress.Status == BackgroundTransferStatus.Running) + var ver = await Util.DownloadText("https://www.slashonline.net/glacier/c.txt"); + if (ver != vars.GlacierClientVersion) { + int taskID = LittleHelp.AddTask("Download Glacier Client"); + UIChangedReqested(false, new EventArgs()); try { - double bytesIn = operation.Progress.BytesReceived; - double totalBytes = operation.Progress.TotalBytesToReceive; - ProgressChanged(this, new SDLauncher.ProgressChangedEventArgs(currentfile: unchecked((int)bytesIn), maxfiles: unchecked((int)totalBytes))); + StorageFile destinationFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync( + "Glacier.zip", + CreationCollisionOption.ReplaceExisting); + using (var client = new HttpClientDownloadWithProgress("https://slashonline.net/glacier/get/release/Glacier.zip", destinationFile.Path)) + { + client.ProgressChanged += (totalFileSize, totalBytesDownloaded, progressPercentage) => + { + StatusChanged("Downloading Glacier Client", new EventArgs()); + try + { + this.ProgressChanged(this, new SDLauncher.ProgressChangedEventArgs(currentProg: Convert.ToInt32(progressPercentage), maxfiles: 100, currentfile: Convert.ToInt32(progressPercentage))); + } + catch { } + if (progressPercentage == 100) + { + StatusChanged("Ready", new EventArgs()); + this.Extract(); + client.Dispose(); + vars.GlacierClientVersion = ver; + this.ProgressChanged(this, new SDLauncher.ProgressChangedEventArgs(currentProg: 0, maxfiles: 100, currentfile: 00)); + LittleHelp.CompleteTask(taskID, true); + } + }; + + await client.StartDownload(); + } + } + catch + { + LittleHelp.CompleteTask(taskID, false); } - catch { } - StatusChanged("Downloading Glacier Client", new EventArgs()); - } - else if (operation.Progress.Status == BackgroundTransferStatus.Error) - { - DownloadCompleted(false, new EventArgs()); - downloadprog.Stop(); } } - private async void DownloadFileCompleted() + + private async void Extract() { + int TaskID = LittleHelp.AddTask("Extract Glacier Client"); UIChangedReqested(false, new EventArgs()); - StatusChanged("Extracting", new EventArgs()); + StatusChanged("Extracting Glacier Client", new EventArgs()); //Read the file stream var wf = await StorageFolder.GetFolderFromPathAsync(vars.Launcher.Launcher.MinecraftPath.Versions); @@ -109,6 +94,8 @@ private async void DownloadFileCompleted() StatusChanged(Localized.Ready, new EventArgs()); UIChangedReqested(true, new EventArgs()); DownloadCompleted(true, new EventArgs()); + LittleHelp.CompleteTask(TaskID, true); + vars.GlacierClientVersion = await Util.DownloadText("https://www.slashonline.net/glacier/c.txt"); } } diff --git a/SDLauncher UWP/Helpers/Labrinth.cs b/SDLauncher UWP/Helpers/Labrinth.cs index 0077f0fd..6ef9bfe2 100644 --- a/SDLauncher UWP/Helpers/Labrinth.cs +++ b/SDLauncher UWP/Helpers/Labrinth.cs @@ -1,4 +1,5 @@ -using System; +using SDLauncher_UWP.Resources; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -89,8 +90,8 @@ private async void ModrinthDownload(string link,string folderdir, string fileNam { client.ProgressChanged += (totalFileSize, totalBytesDownloaded, progressPercentage) => { - StatusChanged("Download " + fileName, new EventArgs()); - this.ProgressChanged(this, new SDLauncher.ProgressChangedEventArgs(currentProg: Convert.ToInt32(progressPercentage))); + StatusChanged("Downloading : " + fileName, new EventArgs()); + this.ProgressChanged(this, new SDLauncher.ProgressChangedEventArgs(currentProg: Convert.ToInt32(progressPercentage), maxfiles: 100, currentfile: Convert.ToInt32(progressPercentage))); if (progressPercentage == 100) { this.DownloadFileCompleted(); @@ -116,8 +117,8 @@ private async void ModrinthDownload(string link,string folderdir, string fileNam } private void DownloadFileCompleted() { - StatusChanged("Ready", new EventArgs()); - ProgressChanged(this, new SDLauncher.ProgressChangedEventArgs(currentProg:0)); + StatusChanged(Localized.Ready, new EventArgs()); + ProgressChanged(this, new SDLauncher.ProgressChangedEventArgs(currentProg:0,currentfile:0)); MainUIChangeRequested(this, new SDLauncher.UIChangeRequestedEventArgs(true)); } public async Task Search(string name, int? limit = null, LabrinthResults.SearchSortOptions sortOptions = LabrinthResults.SearchSortOptions.Relevance, LabrinthResults.SearchCategories[] categories = null) @@ -159,14 +160,14 @@ private void DownloadFileCompleted() } var json = await Util.DownloadText("https://api.modrinth.com/v2/search?query=" + q + "&index=" + sortOptions.ToString().ToLower() + "&facets=[[\"categories:fabric\"]" + categouriesString + ",[\"project_type:mod\"]]&" + l); s = JSONConverter.ConvertToLabrinthSearchResult(json); - StatusChanged("Ready", new EventArgs()); + StatusChanged(Localized.Ready, new EventArgs()); UI(true); LittleHelp.CompleteTask(taskID); return s; } catch { - StatusChanged("Ready", new EventArgs()); + StatusChanged(Localized.Ready, new EventArgs()); UI(true); LittleHelp.CompleteTask(taskID, false); return null; @@ -185,7 +186,7 @@ private void DownloadFileCompleted() { var json = await Util.DownloadText("https://api.modrinth.com/v2/project/" + id); s = JSONConverter.ConvertToLabrinthProject(json); - StatusChanged("Ready", new EventArgs()); + StatusChanged(Localized.Ready, new EventArgs()); if (UIChange) { UI(true); @@ -195,7 +196,7 @@ private void DownloadFileCompleted() } catch { - StatusChanged("Ready", new EventArgs()); + StatusChanged(Localized.Ready, new EventArgs()); if (UIChange) { UI(true); @@ -215,14 +216,14 @@ private void DownloadFileCompleted() string link = "https://api.modrinth.com/v2/project/" + id + "/version"; var json = await Util.DownloadText(link); s = JSONConverter.ConvertDownloadLinksToCS(json); - StatusChanged("Ready", new EventArgs()); + StatusChanged(Localized.Ready, new EventArgs()); UI(true); LittleHelp.CompleteTask(taskID); return s; } catch { - StatusChanged("Ready", new EventArgs()); + StatusChanged(Localized.Ready, new EventArgs()); UI(true); LittleHelp.CompleteTask(taskID, false); return null; diff --git a/SDLauncher UWP/Helpers/MenuItemsCreator.cs b/SDLauncher UWP/Helpers/MenuItemsCreator.cs index 327f4e41..c1cb7d74 100644 --- a/SDLauncher UWP/Helpers/MenuItemsCreator.cs +++ b/SDLauncher UWP/Helpers/MenuItemsCreator.cs @@ -16,44 +16,60 @@ public enum MCType Fabric } public event EventHandler ItemInvoked = delegate { }; + public MenuFlyout Flyout; public MenuFlyout CreateVersions() { - var f = new MenuFlyout(); - f.Items.Add(GetFromStrings("1.19")); - f.Items.Add(GetFromStrings("1.18")); - f.Items.Add(GetFromStrings("1.17")); - f.Items.Add(GetFromStrings("1.16")); - f.Items.Add(GetFromStrings("1.15")); - f.Items.Add(GetFromStrings("1.12")); - f.Items.Add(GetFromStrings("1.11")); - f.Items.Add(GetFromStrings("1.10")); - f.Items.Add(GetFromStrings("1.9")); - f.Items.Add(GetFromStrings("1.8")); - f.Items.Add(GetFromStrings("1.7")); - f.Items.Add(GetFromStrings("1.6")); - f.Items.Add(GetFromStrings("1.5")); - f.Items.Add(GetFromStrings("1.4")); - f.Items.Add(GetFromStrings("1.3")); - f.Items.Add(GetFromStrings("1.2")); - f.Items.Add(GetFromStrings("1.1")); - return f; + Flyout = new MenuFlyout(); + AddItem("1.19"); + AddItem("1.18"); + AddItem("1.17"); + AddItem("1.16"); + AddItem("1.15"); + AddItem("1.12"); + AddItem("1.11"); + AddItem("1.10"); + AddItem("1.9"); + AddItem("1.8"); + AddItem("1.7"); + AddItem("1.6"); + AddItem("1.5"); + AddItem("1.4"); + AddItem("1.3"); + AddItem("1.2"); + AddItem("1.1"); + return Flyout; + } + public void AddItem(string ver) + { + var m = GetFromStrings(ver); + if (m != null) + { + Flyout.Items.Add(m); + } } public MenuFlyoutItemBase GetFromStrings(string ver) { - var subVers = vars.Launcher.GetSubVersions(ver); - if (subVers.Count() > 1) + if (vars.Launcher.MCVerNames.Contains(ver)) { - MenuFlyoutSubItem f = new MenuFlyoutSubItem(); - f.Text = ver; - foreach (var item in subVers) + var subVers = vars.Launcher.GetSubVersions(ver); + if (subVers.Count() > 1) { - f.Items.Add(ReturnMCWithFabric(item)); + MenuFlyoutSubItem f = new MenuFlyoutSubItem(); + f.Text = ver; + foreach (var item in subVers) + { + f.Items.Add(ReturnMCWithFabric(item)); + } + return f; + } + else + { + return CreateItem(ver, "vaniila-" + ver); } - return f; } else { - return CreateItem(ver, "vaniila-" + ver); + return null; } } public MenuFlyoutItemBase ReturnMCWithFabric(string ver) diff --git a/SDLauncher UWP/Helpers/OptiFine.cs b/SDLauncher UWP/Helpers/OptiFine.cs index beef4d1b..caae44d2 100644 --- a/SDLauncher UWP/Helpers/OptiFine.cs +++ b/SDLauncher UWP/Helpers/OptiFine.cs @@ -10,276 +10,59 @@ using Windows.Storage; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; +using System.Xml.Serialization; namespace SDLauncher_UWP.Helpers { - public class OptiFine + public class OptiFineManager { - 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; - public async Task IsOptiFineFilePresent(string lastFileName, string mcVer, bool isLib) + public List GetOptiFine() { - if (!isLib) - { - try - { - var verFolder = await StorageFolder.GetFolderFromPathAsync(vars.Launcher.Launcher.MinecraftPath.Versions); - var mcVerFolder = await verFolder.GetFolderAsync(mcVer); - var file = await mcVerFolder.GetFileAsync(lastFileName); - return true; - } - catch (Exception) - { - return false; - } - } - else - { - try - { - var LibsFolder = await StorageFolder.GetFolderFromPathAsync(vars.Launcher.Launcher.MinecraftPath.Library); - var LibFolder = await LibsFolder.GetFolderAsync("optifine"); - return true; - } - catch (Exception) - { - return false; - } - } + return new List(); } - int taskID; - - public void DownloadOptiFineVer(string mcver, string modVer, string DisplayVer) + public static class Deserializer { - taskID = LittleHelp.AddTask("Download OptiFine"); - MCver = mcver; - Modver = modVer; - Displayver = DisplayVer; - UIChangedReqested(false, new EventArgs()); - switch (mcver) - { - case "1.18.2": - returns = new OptFineVerReturns(modVer, mcver, DisplayVer, OptFineVerReturns.Results.DownloadOptiFineVer); - optver = ": " + mcver; - OptFineDownload("https://github.com/SeaDevTeam/SDLauncher/raw/main/OptiFine-1.18.2.zip", "OptiFine-" + mcver + ".zip", ModType.ver); - break; - case "1.18.1": - returns = new OptFineVerReturns(modVer, mcver, DisplayVer, OptFineVerReturns.Results.DownloadOptiFineVer); - optver = ": " + mcver; - OptFineDownload("https://github.com/SeaDevTeam/SDLauncher/raw/main/OptiFine-1.18.1.zip", "OptiFine-" + mcver + ".zip", ModType.ver); - break; - case "1.17.1": - returns = new OptFineVerReturns(modVer, mcver, DisplayVer, OptFineVerReturns.Results.DownloadOptiFineVer); - optver = ": " + mcver; - OptFineDownload("https://github.com/SeaDevTeam/SDLauncher/raw/main/OptiFine-1.17.1.zip", "OptiFine-" + mcver + ".zip", ModType.ver); - break; - case "1.16.5": - returns = new OptFineVerReturns(modVer, mcver, DisplayVer, OptFineVerReturns.Results.DownloadOptiFineVer); - optver = ": " + mcver; - OptFineDownload("https://github.com/SeaDevTeam/SDLauncher/raw/main/OptiFine-1.16.5.zip", "OptiFine-" + mcver + ".zip", ModType.ver); - break; - } - } - 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) - { - await vars.Launcher.RefreshVersions(); - UIChangedReqested(false, new EventArgs()); - bool exists = false; - if (vars.Launcher.MCVersions != null) - { - foreach (var veritem in vars.Launcher.MCVersions) + public static OptifineManager Deserialize(string OptiFineString) + { + XmlSerializer serializer = new XmlSerializer(typeof(OptifineManager)); + using (StringReader reader = new StringReader(OptiFineString)) { - if (veritem.Name == modVer) - { - exists = true; - } + var test = (OptifineManager)serializer.Deserialize(reader); + return test; } - if (exists) - { - returns = new OptFineVerReturns(modVer, mcver, DisplayVer, OptFineVerReturns.Results.Exists); - UIChangedReqested(true, new EventArgs()); - return returns; - } - else - { - 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(modVer, mcver, "Version", OptFineVerReturns.Results.DownloadOptiFineVer); - UIChangedReqested(true, new EventArgs()); - return returns; - } - else - { - 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, "Version", OptFineVerReturns.Results.DownloadOptiFineLib); - OptFineDownload("https://github.com/SeaDevTeam/SDLauncher/raw/main/optifine.zip", "OptiFine.zip", ModType.lib); - UIChangedReqested(true, new EventArgs()); - return returns; - } - } - else - { - await MessageBox.Show("Error", "You have to install & run minecraft version " + mcver + " one time to install OptiFine", MessageBoxButtons.Ok); - returns = new OptFineVerReturns(mcver, mcver,mcver, OptFineVerReturns.Results.DownloadMCVer); - UIChangedReqested(true, new EventArgs()); - return returns; - } - } - else - { - returns = new OptFineVerReturns(modVer, mcver, "Version", OptFineVerReturns.Results.Failed); - UIChangedReqested(true, new EventArgs()); - return returns; - } - } - } - else - { - returns = new OptFineVerReturns(modVer, mcver, "Version", OptFineVerReturns.Results.Failed); - UIChangedReqested(true, new EventArgs()); - return returns; } - } - // + [XmlRoot(ElementName = "Optifine")] + public class Optifine + { - private enum ModType - { - lib, - ver - } - string optDir; - ModType dwnOptiType; - private async void OptFineDownload(string link, string dir, ModType m) - { - try - { - Uri source = new Uri(link.Trim()); - string destination = dir.Trim(); + [XmlAttribute(AttributeName = "VersionName")] + public string VersionName { get; set; } - StorageFile destinationFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync( - destination, - CreationCollisionOption.ReplaceExisting); + [XmlAttribute(AttributeName = "BasedOn")] + public DateTime BasedOn { get; set; } - BackgroundDownloader downloader = new BackgroundDownloader(); - DownloadOperation download = downloader.CreateDownload(source, destinationFile); - StartDownloadWithProgress(download); - } - catch - { + [XmlAttribute(AttributeName = "DownloadUrl")] + public string DownloadUrl { get; set; } + } - } - optDir = dir; - dwnOptiType = m; - UIChangedReqested(false, new EventArgs()); - } - DownloadOperation operation; - DispatcherTimer downloadprog = new DispatcherTimer(); - private async void StartDownloadWithProgress(DownloadOperation operation) - { - 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(); - } + [XmlRoot(ElementName = "OptifineManager")] + public class OptifineManager + { + [XmlElement(ElementName = "Optifine")] + public List Optifine { get; set; } - private void Downloadprog_Tick(object sender, object e) - { - 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) - { - ErrorAppeared("Failed to download the file",new EventArgs()); - DownloadCompleted(false, new EventArgs()); - downloadprog.Stop(); - } - } + [XmlAttribute(AttributeName = "APIVersion")] + public double APIVersion { get; set; } - private async void DownloadFileCompleted() - { - UIChangedReqested(false, new EventArgs()); - StatusChanged("Extracting", new EventArgs()); + [XmlAttribute(AttributeName = "Version")] + public double Version { get; set; } - //Read the file stream - var a = await ApplicationData.Current.TemporaryFolder.GetFileAsync(optDir); - Stream b = await a.OpenStreamForReadAsync(); - //unzip - ZipArchive archive = new ZipArchive(b); - if (dwnOptiType == ModType.lib) - { - archive.ExtractToDirectory(vars.Launcher.Launcher.MinecraftPath.Library, true); - } - else if (dwnOptiType == ModType.ver) - { + [XmlAttribute(AttributeName = "LibraryUrl")] + public string LibraryUrl { get; set; } + } - archive.ExtractToDirectory(vars.Launcher.Launcher.MinecraftPath.Versions, true); - } - ProgressChanged(100, new EventArgs()); - StatusChanged(Localized.Ready, new EventArgs()); - UIChangedReqested(true, new EventArgs()); - DownloadCompleted(true, new EventArgs()); - LittleHelp.CompleteTask(taskID); - } - + } + } - } - public class OptFineVerReturns - { - public enum Results - { - Failed, - DownloadOptiFineLib, - DownloadOptiFineVer, - DownloadMCVer, - Exists - } - public string MCVer { get; set; } - public string ModVer { get; set; } - public string DisplayVer { get; set; } - public Results Result { get; set; } - public OptFineVerReturns(string modver, string mcver, string displayver, Results result) - { - this.ModVer = modver; - this.MCVer = mcver; - DisplayVer = displayver; - Result = result; - } - } } diff --git a/SDLauncher UWP/Helpers/SDLauncher.cs b/SDLauncher UWP/Helpers/SDLauncher.cs index 07260a61..33a3d0a4 100644 --- a/SDLauncher UWP/Helpers/SDLauncher.cs +++ b/SDLauncher UWP/Helpers/SDLauncher.cs @@ -96,17 +96,11 @@ public List FabricMCVerNames public StoreManager StoreManager { get; private set; } public CMLauncher Launcher { get; set; } - public OptiFine OptiFine { get; set; } public Labrinth Labrinth { get; set; } public TasksHelper TasksHelper { get; set; } public GlacierClient GlacierClient { get; set; } public SDLauncher() { - OptiFine = new OptiFine(); - OptiFine.ProgressChanged += OptiFine_ProgressChanged; - OptiFine.StatusChanged += OptiFine_StatusChanged; - OptiFine.UIChangedReqested += OptiFine_UIChangedReqested; - OptiFine.ErrorAppeared += OptiFine_ErrorAppeared; GlacierClient = new GlacierClient(); GlacierClient.StatusChanged += GlacierClient_StatusChanged; @@ -171,9 +165,10 @@ private void SDLauncher_FileOrProgressChanged(object sender, ProgressChangedEven int ProgPrecentage; if(e.ProgressPercentage != null && e.DownloadArgs != null) { - stats = e.CurrentFile + " of " + e.MaxFiles; + stats = e.MaxFiles.Value + " of " + e.CurrentFile.Value; + int per = e.MaxFiles.Value / e.CurrentFile.Value * 100; ProgPrecentage = e.ProgressPercentage.Value; - UpdateToast(e.DownloadArgs.FileKind.ToString(), stats, ProgPrecentage); + UpdateToast(e.DownloadArgs.FileKind.ToString(), stats, per); } } @@ -252,21 +247,21 @@ public async Task LoadStore() var result = await MessageBox.Show("Error", "Failed to load the data of the store, Retry", MessageBoxButtons.OkCancel); if(result == MessageBoxResults.Ok) { - Status("Ready"); + Status(Localized.Ready); var s = await LoadStore(); TasksHelper.CompleteTask(taskID,true); return s; } else { - Status("Ready"); + Status(Localized.Ready); TasksHelper.CompleteTask(taskID,false); return false; } } else { - Status("Ready"); + Status(Localized.Ready); TasksHelper.CompleteTask(taskID,true); return true; } @@ -316,7 +311,7 @@ public async Task GetChangelog(string version) var changelogHtml = await changelogs.GetChangelogHtml(version); var fullbody = "\n" + "

Version " + version + "

" + changelogHtml; - Status("Ready"); + Status(Localized.Ready); return fullbody.Replace("h1", "h2").ToString(); } private void GlacierClient_ProgressChanged(object sender, ProgressChangedEventArgs e) @@ -341,25 +336,6 @@ public static SDLauncher CreateLauncher(MinecraftPath mcpath) 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) { @@ -399,19 +375,23 @@ public async Task RefreshVersions() var result = await MessageBox.Show("Error", "Couldn't detect a valid internet connecton.Do you want to retry or switch to offfline mode ? (you can switch to online mode again by restarting the app.)", MessageBoxButtons.CustomWithCancel, "Retry", "Switch to offline mode"); if (result == MessageBoxResults.CustomResult1) { + TasksHelper.CompleteTask(taskID, false); await RefreshVersions(); } else if(result == MessageBoxResults.CustomResult2) { + vars.VerSelectors = Views.VerSelectors.Classic; + TasksHelper.CompleteTask(taskID, false); + int offTask = TasksHelper.AddTask("Switch to offline mode"); Launcher.VersionLoader = new LocalVersionLoader(Launcher.MinecraftPath); UseOfflineLoader = true; + TasksHelper.CompleteTask(offTask,true); await RefreshVersions(); } else { CoreApplication.Exit(); } - TasksHelper.CompleteTask(taskID,false); } UI(true); } @@ -452,11 +432,11 @@ public async Task CheckFabric(string mcver, string modver, stri var fabric = FabricMCVersions.GetVersionMetadata(launchVer); await fabric.SaveAsync(Launcher.MinecraftPath); UI(true); - Status("Ready"); + Status(Localized.Ready); await RefreshVersions(); launchVer = modver; displayVer = displayver; - Status("Ready"); + Status(Localized.Ready); TasksHelper.CompleteTask(taskID, true); return new FabricResponsoe(launchVer, displayVer, FabricResponsoe.Responses.ExistsOrCreated); } diff --git a/SDLauncher UWP/Helpers/SettingsDataManager.cs b/SDLauncher UWP/Helpers/SettingsDataManager.cs index 6cab18d1..65027d76 100644 --- a/SDLauncher UWP/Helpers/SettingsDataManager.cs +++ b/SDLauncher UWP/Helpers/SettingsDataManager.cs @@ -18,362 +18,187 @@ namespace SDLauncher_UWP.Helpers { - public class SettingsDataManager + public static class SettingsManager { - - public async Task CreateSettingsFile(bool Exit = false,StorageFile file = null) + public static Rootobject SettingsData = Rootobject.CreateNew(); + public static async Task SaveSettings(StorageFile file = null) { - StorageFile storageFile; - if (file == null) + StorageFile final; + if (file != null) { - storageFile = await ApplicationData.Current.RoamingFolder.CreateFileAsync("settings.xml", CreationCollisionOption.ReplaceExisting); + final = file; } else { - storageFile = file; - } - 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("Settings"); - writer.WriteComment("\nThis is the settings of the SDLauncher uwp.Anyone can edit this.\n For something true you must write \"True\" and something false you must write \"False\"."); - writer.WriteStartElement("Minecraft"); - writer.WriteComment("\n The default maximum RAM of Minecraft in MegaByte.\n The minimum RAM will be automatically decided by the Launcher.\n "); - writer.WriteStartElement("RAM"); - writer.WriteAttributeString("value", vars.CurrentRam.ToString()); - writer.WriteEndElement(); - writer.WriteStartElement("Accounts"); - writer.WriteComment( - "\n The accounts will be used on the Minecraft." + - "\n Types : \"Offline\",\"Microsoft\",\"null\"(not added\")." + - "\n AcessToken : This is the token to login with Microsoft, can be get through the Microsoft Login." + - "\n UUID : This is the UUID to login with Microsoft,also can be get through the Microsoft Login." + - "\n AvatarID : The avatar of your account. Values: \"0\",\"1\",\"2\",\"3\"(microsoft),\"\"(empty)" + - "\n LastAccessed : For autologin. Add this to only one account." + - "\n "); - if (vars.Accounts != null) - { - foreach (var item in vars.Accounts) - { - writer.WriteStartElement("Account"); - writer.WriteAttributeString("Type", item.Type); - writer.WriteAttributeString("Username", item.UserName); - writer.WriteAttributeString("AccessToken", item.AccessToken); - writer.WriteAttributeString("UUID", item.UUID); - if (item.Last) - { - writer.WriteAttributeString("LastAccessed", item.Last.ToString()); - } - writer.WriteAttributeString("AvatarID", item.ProfileAvatarID.ToString()); - writer.WriteEndElement(); - } - } - writer.WriteEndElement(); - writer.WriteStartElement("Downloader"); - 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.WriteAttributeString("GameLogs", vars.GameLogs.ToString()); - writer.WriteStartElement("Arguments"); - if(vars.JVMArgs != null) - { - foreach (var item in vars.JVMArgs) - { - writer.WriteStartElement("Argument"); - writer.WriteAttributeString("Content", item); - writer.WriteEndElement(); - } - } - writer.WriteEndElement(); - writer.WriteEndElement(); - writer.WriteEndElement(); - writer.WriteStartElement("App"); - writer.WriteAttributeString("AutoClose", vars.AutoClose.ToString()); - writer.WriteComment("\n The theme and background of the app"); - writer.WriteStartElement("Appearance"); - writer.WriteAttributeString("CustomBackgroundImagePath", vars.BackgroundImagePath.ToString()); - writer.WriteAttributeString("UseCustomBackgroundImage", vars.CustomBackground.ToString()); - if (vars.Theme.ToString() == "") - { - writer.WriteAttributeString("Theme", "null"); - } - else - { - writer.WriteAttributeString("Theme", vars.Theme.ToString()); - } - writer.WriteEndElement(); - writer.WriteStartElement("Tips"); - writer.WriteAttributeString("value", vars.ShowTips.ToString()); - writer.WriteEndElement(); - writer.WriteStartElement("AutoLogin"); - writer.WriteAttributeString("value", vars.autoLog.ToString()); - writer.WriteEndElement(); - writer.WriteStartElement("VersionsSeletor"); - writer.WriteAttributeString("value", vars.VerSelectors.ToString()); - writer.WriteEndElement(); - writer.WriteStartElement("Discord"); - writer.WriteAttributeString("IsPinned", vars.IsFixedDiscord.ToString()); - writer.WriteEndElement(); - writer.WriteEndElement(); - writer.WriteEndElement(); - writer.Flush(); - await writer.FlushAsync(); - } - } - - if (vars.showXMLOnClose) - { - await Windows.System.Launcher.LaunchFileAsync(storageFile); - vars.showXMLOnClose = false; - } - if (Exit == true) - { - Application.Current.Exit(); + final = await ApplicationData.Current.RoamingFolder.CreateFileAsync("settings.json", CreationCollisionOption.ReplaceExisting); } + await FileIO.WriteTextAsync(final, await SerializeSettings()); } - public ObservableCollection Accounts = new ObservableCollection(); - public async Task LoadSettingsFile() + public static async Task SerializeSettings() { - //var doc = await DocumentLoad().AsAsyncOperation(); - //var settings = doc.GetElementById("settings"); - //var app = settings.GetElementsByTagName("value"); - //app.Contains(settings); - var storagefile = await ApplicationData.Current.RoamingFolder.GetFileAsync("settings.xml"); - - string theme; - string tips; - string ram; - string hashcheck; - string assetscheck; - string autolog; - string verselect; - string fixDiscord; - string gamelogs; - string jvmWidth; - string jvmHeight; - string jvmFullScreen; - string isCustombg; - string BGPath; - string autoClose; - using (IRandomAccessStream stream = await storagefile.OpenAsync(FileAccessMode.Read)) + SettingsData = Rootobject.CreateNew(); + SettingsData.Settings.App.Appearance.Theme = ((ElementTheme)vars.Theme).ToString(); + SettingsData.Settings.App.Appearance.UseCustomBackgroundImage = vars.CustomBackground; + SettingsData.Settings.App.Appearance.CustomBackgroundImagePath = vars.BackgroundImagePath; + SettingsData.Settings.App.AutoLogin = vars.autoLog; + SettingsData.Settings.App.VersionsSeletor.Style = vars.VerSelectors.ToString(); + SettingsData.Settings.App.AutoClose = vars.AutoClose; + SettingsData.Settings.App.Tips = vars.ShowTips; + SettingsData.Settings.App.Discord.IsPinned = vars.IsFixedDiscord; + // + SettingsData.Settings.Minecraft.RAM = vars.CurrentRam; + SettingsData.Settings.Minecraft.GlacierClient.Exists = await vars.GlacierExists(); + SettingsData.Settings.Minecraft.GlacierClient.Version = vars.GlacierClientVersion; + SettingsData.Settings.Minecraft.Downloader.AssetsCheck = vars.AssestsCheck; + SettingsData.Settings.Minecraft.Downloader.HashCheck = vars.HashCheck; + SettingsData.Settings.Minecraft.JVM.FullScreen = vars.FullScreen; + SettingsData.Settings.Minecraft.JVM.ScreenWidth = vars.JVMScreenWidth; + SettingsData.Settings.Minecraft.JVM.ScreenHeight = vars.JVMScreenHeight; + SettingsData.Settings.Minecraft.JVM.GameLogs = vars.GameLogs; + SettingsData.Settings.Minecraft.JVM.Arguments = vars.JVMArgs.ToArray(); + var accs = new List(); + foreach (var item in vars.Accounts) { - Stream s = stream.AsStreamForRead(); - XmlReaderSettings settings = new XmlReaderSettings(); - settings.Async = true; - using (XmlReader reader = XmlReader.Create(s, settings)) - { - await reader.ReadAsync(); - reader.ReadStartElement("Settings"); - reader.ReadToFollowing("Minecraft"); - reader.ReadToFollowing("RAM"); - ram = reader.GetAttribute("value"); - reader.ReadToFollowing("Accounts"); - 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"); - gamelogs = reader.GetAttribute("GameLogs"); - reader.ReadToFollowing("App"); - autoClose = reader.GetAttribute("AutoClose"); - reader.ReadToFollowing("Appearance"); - theme = reader.GetAttribute("Theme"); - isCustombg = reader.GetAttribute("UseCustomBackgroundImage"); - BGPath = reader.GetAttribute("CustomBackgroundImagePath"); - reader.ReadToFollowing("Tips"); - tips = reader.GetAttribute("value"); - reader.ReadToFollowing("AutoLogin"); - autolog = reader.GetAttribute("value"); - reader.ReadToFollowing("VersionsSeletor"); - verselect = reader.GetAttribute("value"); - reader.ReadToFollowing("Discord"); - fixDiscord = reader.GetAttribute("IsPinned"); - - } - s = stream.AsStreamForRead(); - using (StreamReader streamReader = new StreamReader(s)) - { - string content; - content = await FileIO.ReadTextAsync(storagefile); - System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); - doc.LoadXml(content); - - var list = doc.SelectNodes("//Settings/Minecraft/Accounts/Account"); - for (int i = list.Count - 1; i >= 0; i--) - { - if (list[i].Attributes["Type"].Value != "null") - { - string avatarid; - try - { - avatarid = list[i].Attributes["AvatarID"].Value; - } - catch - { - avatarid = null; - } - try - { - var lastv = list[i].Attributes["LastAccessed"]; - if (lastv != null) - { - string last = lastv.Value; - if (last == "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 - { - 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 - { - throw new Exception(); - } - } - catch - { - - 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))); - } - } - } - } - vars.Accounts = Accounts; - vars.AccountsCount = Accounts.Count; - list = doc.SelectNodes("//Settings/Minecraft/JVM/Arguments/Argument"); - var args = new List(); - for (int i = list.Count - 1; i >= 0; i--) - { - args.Add(list[i].Attributes["Content"].Value); - } - vars.JVMArgs = args; - } + accs.Add(new Account { AccessToken = item.AccessToken, UUID = item.UUID, Type = item.Type, Username = item.UserName, LastAccessed = item.Last }); } - int jvmwidth; - int jvmheight; + SettingsData.Settings.Minecraft.Accounts = accs.ToArray(); + return Newtonsoft.Json.JsonConvert.SerializeObject(SettingsData, Newtonsoft.Json.Formatting.Indented); + } + public static async Task LoadSettings() + { try { - jvmheight = int.Parse(jvmHeight); - jvmwidth = int.Parse(jvmWidth); + var storagefile = await ApplicationData.Current.RoamingFolder.GetFileAsync("settings.json"); + var text = await FileIO.ReadTextAsync(storagefile); + DeserializeSettings(text); + return true; } catch { - jvmwidth = 0; - jvmheight = 0; - } - vars.JVMScreenWidth = jvmwidth; - vars.JVMScreenHeight = jvmheight; - if(BGPath != null) - { - vars.BackgroundImagePath = BGPath; - } - else - { - vars.BackgroundImagePath = ""; - } - vars.LoadedRam = int.Parse(ram); - if (theme == "Default") - { - vars.Theme = ElementTheme.Default; - } - else if (theme == "Light") - { - vars.Theme = ElementTheme.Light; + return false; } - else + } + public static void DeserializeSettings(string text) + { + SettingsData = Newtonsoft.Json.JsonConvert.DeserializeObject(text); + + // + vars.Theme = (ElementTheme)Enum.Parse(typeof(ElementTheme), SettingsData.Settings.App.Appearance.Theme); + vars.CustomBackground = SettingsData.Settings.App.Appearance.UseCustomBackgroundImage; + vars.BackgroundImagePath = SettingsData.Settings.App.Appearance.CustomBackgroundImagePath; + vars.autoLog = SettingsData.Settings.App.AutoLogin; + vars.VerSelectors = (Views.VerSelectors)Enum.Parse(typeof(Views.VerSelectors), SettingsData.Settings.App.VersionsSeletor.Style); + vars.AutoClose = SettingsData.Settings.App.AutoClose; + vars.ShowTips = SettingsData.Settings.App.Tips; + vars.IsFixedDiscord = SettingsData.Settings.App.Discord.IsPinned; + // + vars.GlacierClientVersion = SettingsData.Settings.Minecraft.GlacierClient.Version; + vars.CurrentRam = SettingsData.Settings.Minecraft.RAM; + vars.AssestsCheck = SettingsData.Settings.Minecraft.Downloader.AssetsCheck; + vars.HashCheck = SettingsData.Settings.Minecraft.Downloader.HashCheck; + vars.FullScreen = SettingsData.Settings.Minecraft.JVM.FullScreen; + vars.JVMScreenWidth = SettingsData.Settings.Minecraft.JVM.ScreenWidth; + vars.JVMScreenHeight = SettingsData.Settings.Minecraft.JVM.ScreenHeight; + vars.GameLogs = SettingsData.Settings.Minecraft.JVM.GameLogs; + if (SettingsData.Settings.Minecraft.JVM.Arguments != null) { vars.JVMArgs = SettingsData.Settings.Minecraft.JVM.Arguments.ToList(); } + var accs = new ObservableCollection(); + foreach (var item in SettingsData.Settings.Minecraft.Accounts) { - vars.Theme = theme == "Dark" ? ElementTheme.Dark : ElementTheme.Default; + accs.Add(new Helpers.Account(item.Username, item.Type, item.AccessToken, item.UUID, accs.Count + 1, item.LastAccessed)); } - if (Window.Current.Content is FrameworkElement fe) + vars.Accounts = accs; + vars.AccountsCount = accs.Count; + } + public class Rootobject + { + public static Rootobject CreateNew() { - fe.RequestedTheme = (ElementTheme)vars.Theme; + var s = new Rootobject(); + s.Settings = new Settings(); + s.Settings.App = new App(); + s.Settings.App.Discord = new Discord(); + s.Settings.App.Appearance = new Appearance(); + s.Settings.App.VersionsSeletor = new Versionsseletor(); + s.Settings.Minecraft = new Minecraft(); + s.Settings.Minecraft.JVM = new JVM(); + s.Settings.Minecraft.GlacierClient = new GlacierClient(); + s.Settings.Minecraft.Downloader = new Downloader(); + return s; } - vars.VerSelectors = (Views.VerSelectors)Enum.Parse(typeof(Views.VerSelectors),verselect); - vars.ShowTips = tips == "True"; - vars.HashCheck = hashcheck == "True"; - vars.AutoClose = autoClose == "True"; - vars.CustomBackground = isCustombg == "True"; - vars.GameLogs = gamelogs == "True"; - vars.AssestsCheck = assetscheck == "True"; - vars.autoLog = autolog == "True"; - vars.IsFixedDiscord = fixDiscord == "True"; - vars.FullScreen = jvmFullScreen == "True"; - if (vars.autoLog) - { - foreach (var item in vars.Accounts) - { - if (item.Last) - { - if (item.Type != "null") - { - if (item.Type == "Offline") - { - if (item.UserName == "null") - { - vars.session = null; - } - else - { - vars.session = MSession.GetOfflineSession(item.UserName); - } - } - else - { - if (item.UserName != "null" && item.AccessToken != "null" && item.UUID != "null") - { - vars.session = new MSession(item.UserName, item.AccessToken, item.UUID); - } - } - } - vars.CurrentAccountCount = item.Count; - } - } + public Settings Settings { get; set; } + } - } + public class Settings + { + public Minecraft Minecraft { get; set; } + public App App { get; set; } + } + + public class Minecraft + { + public int RAM { get; set; } + public Account[] Accounts { get; set; } + public Downloader Downloader { get; set; } + public GlacierClient GlacierClient { get; set; } + public JVM JVM { get; set; } + } + public class GlacierClient + { + public string Version { get; set; } + public bool Exists { get; set; } + } + public class Account + { + public string Type { get; set; } + public string Username { get; set; } + public string AccessToken { get; set; } + public string UUID { get; set; } + public bool LastAccessed { get; set; } + } + + public class Downloader + { + public bool HashCheck { get; set; } + public bool AssetsCheck { get; set; } + } + + public class JVM + { + public string[] Arguments { get; set; } + public int ScreenWidth { get; set; } + public int ScreenHeight { get; set; } + public bool FullScreen { get; set; } + public bool GameLogs { get; set; } + } + + + public class App + { + public Appearance Appearance { get; set; } + public bool Tips { get; set; } + public bool AutoLogin { get; set; } + public Versionsseletor VersionsSeletor { get; set; } + public Discord Discord { get; set; } + public bool AutoClose { get; set; } + } + public class Appearance + { + public string CustomBackgroundImagePath { get; set; } + public bool UseCustomBackgroundImage { get; set; } + public string Theme { get; set; } } + + public class Versionsseletor + { + public string Style { get; set; } + } + + public class Discord + { + public bool IsPinned { get; set; } + } + + } -} +} \ No newline at end of file diff --git a/SDLauncher UWP/SDLauncher UWP.csproj b/SDLauncher UWP/SDLauncher UWP.csproj index 00b01072..12047fd9 100644 --- a/SDLauncher UWP/SDLauncher UWP.csproj +++ b/SDLauncher UWP/SDLauncher UWP.csproj @@ -350,7 +350,7 @@ 1.0.175 - 6.2.12 + 6.2.14 7.1.2 diff --git a/SDLauncher UWP/UserControls/TaskListView.xaml b/SDLauncher UWP/UserControls/TaskListView.xaml index 61560606..2bf39f24 100644 --- a/SDLauncher UWP/UserControls/TaskListView.xaml +++ b/SDLauncher UWP/UserControls/TaskListView.xaml @@ -44,6 +44,12 @@ + + + + + @@ -75,6 +81,12 @@ + + + + + diff --git a/SDLauncher UWP/Views/BaseLauncherPage.xaml.cs b/SDLauncher UWP/Views/BaseLauncherPage.xaml.cs index eb289917..38f0d921 100644 --- a/SDLauncher UWP/Views/BaseLauncherPage.xaml.cs +++ b/SDLauncher UWP/Views/BaseLauncherPage.xaml.cs @@ -95,7 +95,6 @@ public async void InitializeLauncher() vars.Launcher.VersionsRefreshed += Launcher_VersionsRefreshed; vars.Launcher.StatusChanged += Launcher_StatusChanged; vars.Launcher.FileOrProgressChanged += Launcher_FileOrProgressChanged; - vars.Launcher.OptiFine.DownloadCompleted += OptiFine_DownloadCompleted; vars.Launcher.GlacierClient.DownloadCompleted += GlacierClient_DownloadCompleted; vars.Launcher.VersionLoaderChanged += Launcher_VersionLoaderChanged; vars.VerSelctorChanged += Vars_VerSelctorChanged; @@ -165,6 +164,12 @@ private void Vars_VerSelctorChanged(object sender, EventArgs e) btnMCVer.Visibility = Visibility.Collapsed; break; } + if (vars.Launcher.UseOfflineLoader) + { + btnAdvMCVer.Visibility = Visibility.Collapsed; + cmbxVer.Visibility = Visibility.Visible; + btnMCVer.Visibility = Visibility.Collapsed; + } } private void Vars_SessionChanged(object sender, EventArgs e) @@ -219,19 +224,6 @@ private void Launcher_VersionsRefreshed(object sender, EventArgs e) cmbxVer.ItemsSource = vars.Launcher.MCVerNames; } - private async void OptiFine_DownloadCompleted(object sender, EventArgs e) - { - if (!(bool)sender) - { - launchVer = ""; - btnMCVer.Content = "Version"; - } - else - { - await vars.Launcher.RefreshVersions(); - OptiFineFinish(await vars.Launcher.OptiFine.CheckOptiFine(vars.Launcher.OptiFine.MCver, vars.Launcher.OptiFine.Modver, vars.Launcher.OptiFine.Displayver)); - } - } private void Launcher_FileOrProgressChanged(object sender, SDLauncher.ProgressChangedEventArgs e) { @@ -363,6 +355,9 @@ private async void BtnLaunch_Click(object sender, RoutedEventArgs e) } private async void StartProcess(Process process) { + pb_File.Value = 0; + pb_Prog.Value = 0; + txtStatus.Text = Localized.Ready; await ProcessToXmlConverter.Convert(process, ApplicationData.Current.LocalFolder, "StartInfo.xml"); if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0)) { @@ -375,9 +370,10 @@ private async void StartProcess(Process process) await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync("User"); } } - CreateToast("Done!", "Successfully launcher minecraft version \"" + launchVer + "\"", true); + CreateToast("Done!", "Successfully launched minecraft version \"" + launchVer + "\"", true); if (vars.AutoClose) { + await SettingsManager.SaveSettings(); Application.Current.Exit(); } } @@ -417,6 +413,7 @@ private void CreateToast(string Title,string description,bool clearBefore) } private void Page_Loaded(object sender, RoutedEventArgs e) { + LogsPage.UpdateLogs(); Vars_VerSelctorChanged(null, null); } @@ -483,19 +480,6 @@ private async void VersionCheck(MenuFlyoutItem item) launchVer = vars.Launcher.Launcher.Versions?.LatestSnapshotVersion?.Name; btnMCVer.Content = launchVer; break; - case "OptiFine 1.18.2": - OptiFineFinish(await vars.Launcher.OptiFine.CheckOptiFine("1.18.2", "1.18.2-OptiFine_HD_U_H6_pre1", displayName)); - break; - case "OptiFine 1.18.1": - OptiFineFinish(await vars.Launcher.OptiFine.CheckOptiFine("1.18.1", "1.18.1-OptiFine_HD_U_H4", displayName)); - break; - case "OptiFine 1.17.1": - OptiFineFinish(await vars.Launcher.OptiFine.CheckOptiFine("1.17.1", "1.17.1-OptiFine_HD_U_H1", displayName)); - break; - case "OptiFine 1.16.5": - OptiFineFinish(await vars.Launcher.OptiFine.CheckOptiFine("1.16.5", "OptiFine 1.16.5", displayName)); - break; - case "Fabric 1.19": FabricResponse(await vars.Launcher.CheckFabric("1.19", SearchFabric("1.19"), item.Text)); break; @@ -544,38 +528,6 @@ private void UI(bool value) btnServer.IsEnabled = value; cmbxVer.IsEnabled = value; } - private void OptiFineFinish(OptFineVerReturns returned) - { - txtStatus.Text = "Ready"; - UI(true); - switch (returned.Result) - { - case OptFineVerReturns.Results.DownloadOptiFineLib: - btnMCVer.Content = "Version"; - launchVer = ""; - break; - case OptFineVerReturns.Results.DownloadOptiFineVer: - pb_File.Value = 0; - pb_Prog.Maximum = 100; - vars.Launcher.OptiFine.DownloadOptiFineVer(returned.MCVer, returned.ModVer, returned.DisplayVer); - break; - case OptFineVerReturns.Results.Failed: - btnMCVer.Content = "Version"; - launchVer = ""; - break; - case OptFineVerReturns.Results.Exists: - btnMCVer.Content = returned.DisplayVer; - launchVer = returned.ModVer; - break; - case OptFineVerReturns.Results.DownloadMCVer: - btnMCVer.Content = returned.DisplayVer; - launchVer = returned.MCVer; - break; - } - } - - - private void cmbxVer_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (vars.VerSelectors == VerSelectors.Classic || vars.Launcher.UseOfflineLoader) diff --git a/SDLauncher UWP/Views/MainPage.xaml.cs b/SDLauncher UWP/Views/MainPage.xaml.cs index 12301f0f..04bda492 100644 --- a/SDLauncher UWP/Views/MainPage.xaml.cs +++ b/SDLauncher UWP/Views/MainPage.xaml.cs @@ -39,7 +39,6 @@ public sealed partial class MainPage : Page { public BaseLauncherPage launcher; public SettingsPage settingsPage; - public SettingsDataManager settings = new SettingsDataManager(); public MainPage() { this.InitializeComponent(); @@ -69,6 +68,17 @@ private void Vars_SessionChanged(object sender, EventArgs e) txtLogin.Text = vars.session.Username; prpFly.DisplayName = vars.session.Username; prpLogin.DisplayName = vars.session.Username; + prpLogin.DisplayName = vars.session.Username; + if(vars.session.UUID == "user_uuid") + { + prpFly.ProfilePicture = new BitmapImage(new Uri("https://minotar.net/helm/MHF_Steve")); + prpLogin.ProfilePicture = new BitmapImage(new Uri("https://minotar.net/helm/MHF_Steve")); + } + else + { + prpFly.ProfilePicture = new BitmapImage(new Uri("https://minotar.net/helm/" + vars.session.UUID)); + prpLogin.ProfilePicture = new BitmapImage(new Uri("https://minotar.net/helm/" + vars.session.UUID)); + } btnLogin.Tag = "Change"; } else @@ -112,10 +122,6 @@ private async void Page_Loaded(object sender, RoutedEventArgs e) { Page_ActualThemeChanged(null, null); MainFrame.Content = launcher; - foreach (var account in vars.Accounts) - { - - } if (vars.ShowTips) { tipacc.IsOpen = true; diff --git a/SDLauncher UWP/Views/SettingsPage.xaml b/SDLauncher UWP/Views/SettingsPage.xaml index 352c2132..cf029cb2 100644 --- a/SDLauncher UWP/Views/SettingsPage.xaml +++ b/SDLauncher UWP/Views/SettingsPage.xaml @@ -210,15 +210,22 @@ - -