diff --git a/CollapseLauncher/Classes/InstallManagement/GameConversionManagement.cs b/CollapseLauncher/Classes/InstallManagement/GameConversionManagement.cs index 1470de3a7..f19b27f81 100644 --- a/CollapseLauncher/Classes/InstallManagement/GameConversionManagement.cs +++ b/CollapseLauncher/Classes/InstallManagement/GameConversionManagement.cs @@ -65,7 +65,7 @@ public async Task StartPreparation() using (MemoryStream buffer = new MemoryStream()) { - URL = string.Format(AppGameRepairIndexURLPrefix, SourceProfile.ProfileName, this.GameVersion); + string.Format(AppGameRepairIndexURLPrefix, SourceProfile.ProfileName, this.GameVersion); ConvertDetail = Lang._InstallConvert.Step2Subtitle; this._http.DownloadProgress += FetchIngredientsAPI_Progress; await this._http.Download(URL, buffer, null, null, Token); diff --git a/CollapseLauncher/Classes/InstallManagement/InstallManagement.cs b/CollapseLauncher/Classes/InstallManagement/InstallManagement.cs index 249d7c395..0b30e49b4 100644 --- a/CollapseLauncher/Classes/InstallManagement/InstallManagement.cs +++ b/CollapseLauncher/Classes/InstallManagement/InstallManagement.cs @@ -476,7 +476,14 @@ private async Task RunPatch() CountCurrentDownload = 1; CountTotalToDownload = 1; - await StartPreparation(); + try + { + await StartPreparation(); + } catch (Exception ex) + { + LogWriteLine($"[InstallManagement] Game Conversion Prep failed!\r\n{ex}", LogType.Warning, true); + } + await RepairIngredients(await VerifyIngredients(SourceFileManifest, IngredientPath), IngredientPath); await Task.Run(StartConversion); } diff --git a/CollapseLauncher/Classes/RepairManagement/DataCheck.cs b/CollapseLauncher/Classes/RepairManagement/DataCheck.cs index dfebaf0f9..470ef0622 100644 --- a/CollapseLauncher/Classes/RepairManagement/DataCheck.cs +++ b/CollapseLauncher/Classes/RepairManagement/DataCheck.cs @@ -86,8 +86,8 @@ private async void StartGameCheck(object sender, RoutedEventArgs e) } GameBaseURL = RepoURLDict[regionResourceProp.data.game.latest.version] + '/'; + string indexURL = string.Format(AppGameRepairIndexURLPrefix, CurrentConfigV2.ProfileName, regionResourceProp.data.game.latest.version); - using (memBuffer = new MemoryStream()) { _httpClient.DownloadProgress += DataFetchingProgress; diff --git a/CollapseLauncher/CollapseLauncher.csproj b/CollapseLauncher/CollapseLauncher.csproj index e7a69a1bc..8fb273de7 100644 --- a/CollapseLauncher/CollapseLauncher.csproj +++ b/CollapseLauncher/CollapseLauncher.csproj @@ -1,4 +1,4 @@ - + WinExe net7.0-windows10.0.19041.0 @@ -54,6 +54,7 @@ + @@ -133,6 +134,11 @@ + + + MSBuild:Compile + + $(DefaultXamlRuntime) diff --git a/CollapseLauncher/Program.cs b/CollapseLauncher/Program.cs index 4e99de0a5..50f438bb1 100644 --- a/CollapseLauncher/Program.cs +++ b/CollapseLauncher/Program.cs @@ -47,6 +47,7 @@ public static void Main(params string[] args) Console.WriteLine("Initializing...", LogType.Empty); InitializeAppSettings(); + CheckRepoStatus(); ParseArguments(args); switch (m_appMode) diff --git a/CollapseLauncher/XAMLs/Invoker/InvokerWindow.xaml.cs b/CollapseLauncher/XAMLs/Invoker/InvokerWindow.xaml.cs index c1850a480..5b469876f 100644 --- a/CollapseLauncher/XAMLs/Invoker/InvokerWindow.xaml.cs +++ b/CollapseLauncher/XAMLs/Invoker/InvokerWindow.xaml.cs @@ -53,10 +53,11 @@ public InvokerWindow() UpdateChannelLabel.Text = m_arguments.Updater.UpdateChannel.ToString(); CurrentVersionLabel.Text = AppCurrentVersion; } - catch (Exception ex) + catch (Exception) { - LogWriteLine($"FATAL CRASH!!!\r\n{ex}", Hi3Helper.LogType.Error, true); - Console.ReadLine(); + //LogWriteLine($"FATAL CRASH!!!\r\n{ex}", Hi3Helper.LogType.Error, true); + //Console.ReadLine(); + LogWriteLine($"An exception occured while fetching update files. ", Hi3Helper.LogType.Warning, true); } } diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/Dialogs/InstallationConvert.xaml.cs b/CollapseLauncher/XAMLs/MainApp/Pages/Dialogs/InstallationConvert.xaml.cs index f005ed615..a5a80b8bb 100644 --- a/CollapseLauncher/XAMLs/MainApp/Pages/Dialogs/InstallationConvert.xaml.cs +++ b/CollapseLauncher/XAMLs/MainApp/Pages/Dialogs/InstallationConvert.xaml.cs @@ -311,7 +311,14 @@ private async Task DoDownloadRecipe() Step2ProgressStatus.Text = Lang._InstallConvert.Step2Subtitle; }); - SourceDataIntegrityURL = await FetchDataIntegrityURL(SourceProfile); + try + { + SourceDataIntegrityURL = await FetchDataIntegrityURL(SourceProfile); + } catch (Exception ex) + { + LogWriteLine($"Failed to fetch integrity metadata from URL.\r\n{ex}"); + } + bool IsChoosen = false; string cPath = null; @@ -370,7 +377,15 @@ private async Task DoPrepareIngredients() }); Converter.ProgressChanged += Step3ProgressEvents; - await Converter.StartPreparation(); + try + { + await Converter.StartPreparation(); + } catch (Exception ex) + { + LogWriteLine($"[InstallConvertXAML] Game Conversion Prep failed!\r\n{ex}", LogType.Warning, true); + } + + Converter.ProgressChanged -= Step3ProgressEvents; DispatcherQueue.TryEnqueue(() => diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml b/CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml index d18d1ffa7..de0139d20 100644 --- a/CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml +++ b/CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml @@ -1,4 +1,4 @@ - + + + + + @@ -127,6 +132,13 @@ + + diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs b/CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs index 384d42a2f..d17ab5f9c 100644 --- a/CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs +++ b/CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs @@ -7,6 +7,7 @@ using System.Diagnostics; using System.IO; using System.Linq; +using System.Threading; using static Hi3Helper.FileDialogNative; using static Hi3Helper.InvokeProp; using static Hi3Helper.Locale; @@ -35,6 +36,7 @@ public SettingsPage() AppVersionTextBlock.Text = Version; CurrentVersion.Text = Version; GetLanguageList(); + GetCDNList(); } private void GetLanguageList() @@ -56,6 +58,22 @@ private void GetLanguageList() LanguageSelector.SelectedIndex = SelectedIndex; } + private void GetCDNList() + { + List list = new List(); + string CurrentCDN = GetAppConfigValue("CDNType").ToString(); + list.Add($"Default (GitHub)"); + list.Add($"Statically"); + CDNSelector.ItemsSource = list; + if (CurrentCDN.Contains("Default")) + { + CDNSelector.SelectedIndex = 0; + } else + { + CDNSelector.SelectedIndex = 1; + } + } + private async void RelocateFolder(object sender, RoutedEventArgs e) { switch (await Dialogs.SimpleDialogs.Dialog_RelocateFolder(Content)) @@ -111,6 +129,27 @@ private void ClearLogsFolder(object sender, RoutedEventArgs e) (sender as Button).IsEnabled = false; } + // For debugging + //private void ForceRestart(object sender, RoutedEventArgs e) + //{ + // string execPath = Process.GetCurrentProcess().MainModule.FileName; + // string workingDir = Path.GetDirectoryName(execPath); + // string launcherPath = Path.Combine(workingDir, "CollapseLauncher.exe"); + // App.Current.Exit(); + // Thread.Sleep(1000); + // new Process + // { + // StartInfo = new ProcessStartInfo + // { + // UseShellExecute = true, + // Verb = "runas", + // FileName = launcherPath, + // WorkingDirectory = workingDir + // } + // }.Start(); + // MainFrameChanger.ChangeMainFrame(typeof(StartupLanguageSelect)); + //} + private void ForceUpdate(object sender, RoutedEventArgs e) { string ChannelName = IsPreview ? "Preview" : "Stable"; @@ -139,7 +178,10 @@ private void ForceUpdate(object sender, RoutedEventArgs e) return; } } - + public void StartSetupPage(object sender, RoutedEventArgs e) + { + MainFrameChanger.ChangeMainFrame(typeof(StartupPage)); + } private void CheckUpdate(object sender, RoutedEventArgs e) { UpdateLoadingStatus.Visibility = Visibility.Visible; @@ -228,6 +270,7 @@ private void Egg(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e } bool EnableLanguageChange = false; + bool EnableCDNChange = false; private void LanguageChanged(object sender, SelectionChangedEventArgs e) { if (IsAppLangNeedRestart) @@ -246,6 +289,49 @@ private void LanguageChanged(object sender, SelectionChangedEventArgs e) EnableLanguageChange = true; } + private void CDNChanged(object sender, SelectionChangedEventArgs e) + { + if (IsAppCDNNeedRestart) + CDNSelectionWarning.Visibility = Visibility.Visible; + + if (EnableCDNChange) + { + string s = CDNSelector.SelectedItem.ToString(); + // Better to call a function + if (s.Contains("Default")) + { + SetAndSaveConfigValue("CDNType", "Default"); + AppNotifURLPrefix = AppNotifURLPrefix.Replace(AppNotifURLPrefix, "https://github.com/neon-nyan/CollapseLauncher-ReleaseRepo/main/notification_{0}.json"); + AppGameConfigURLPrefix = AppGameConfigURLPrefix.Replace(AppGameConfigURLPrefix, "https://github.com/neon-nyan/CollapseLauncher-ReleaseRepo/main/metadata/metadata_{0}.json"); + AppGameConfigV2URLPrefix = AppGameConfigV2URLPrefix.Replace(AppGameConfigV2URLPrefix, "https://github.com/neon-nyan/CollapseLauncher-ReleaseRepo/main/metadata/metadatav2_{0}.json"); + AppGameRepairIndexURLPrefix = AppGameRepairIndexURLPrefix.Replace(AppGameRepairIndexURLPrefix, "https://github.com/neon-nyan/CollapseLauncher-ReleaseRepo/main/metadata/repair_indexes/{0}/{1}/index"); + AppGameRepoIndexURLPrefix = AppGameRepoIndexURLPrefix.Replace(AppGameRepoIndexURLPrefix, "https://github.com/neon-nyan/CollapseLauncher-ReleaseRepo/main/metadata/repair_indexes/{0}/repo"); + } + else + { + SetAndSaveConfigValue("CDNType", s); + // 1: statically + switch (s) + { + case "Statically": + // there is probably a better way to do this instead of replacing the entire string (maybe prepending?) + // LogWriteLine(s); + // LogWriteLine("Statically case"); + AppNotifURLPrefix = AppNotifURLPrefix.Replace(AppNotifURLPrefix, "https://cdn.statically.io/gh/neon-nyan/CollapseLauncher-ReleaseRepo/main/notification_{0}.json"); + AppGameConfigURLPrefix = AppGameConfigURLPrefix.Replace(AppGameConfigURLPrefix, "https://cdn.statically.io/gh/neon-nyan/CollapseLauncher-ReleaseRepo/main/metadata/metadata_{0}.json"); + AppGameConfigV2URLPrefix = AppGameConfigV2URLPrefix.Replace(AppGameConfigV2URLPrefix, "https://cdn.statically.io/gh/neon-nyan/CollapseLauncher-ReleaseRepo/main/metadata/metadatav2_{0}.json"); + AppGameRepairIndexURLPrefix = AppGameRepairIndexURLPrefix.Replace(AppGameRepairIndexURLPrefix, "https://cdn.statically.io/gh/neon-nyan/CollapseLauncher-ReleaseRepo/main/metadata/repair_indexes/{0}/{1}/index"); + AppGameRepoIndexURLPrefix = AppGameRepoIndexURLPrefix.Replace(AppGameRepoIndexURLPrefix, "https://cdn.statically.io/gh/neon-nyan/CollapseLauncher-ReleaseRepo/main/metadata/repair_indexes/{0}/repo"); + break; + } + } + SetAndSaveConfigValue("CDNType", new IniValue(s)); + CDNSelectionWarning.Visibility = Visibility.Visible; + IsAppCDNNeedRestart = true; + } + EnableCDNChange = true; + } + public bool IsBGCustom { get diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/StartupPage.xaml b/CollapseLauncher/XAMLs/MainApp/Pages/StartupPage.xaml index 5c0edd0d0..b867127d4 100644 --- a/CollapseLauncher/XAMLs/MainApp/Pages/StartupPage.xaml +++ b/CollapseLauncher/XAMLs/MainApp/Pages/StartupPage.xaml @@ -18,7 +18,7 @@ HorizontalAlignment="Right" VerticalAlignment="Bottom" IsEnabled="False" Click="NextPage_Click" CornerRadius="16"> - + diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/StartupPage.xaml.cs b/CollapseLauncher/XAMLs/MainApp/Pages/StartupPage.xaml.cs index 8bda90fad..ee178562b 100644 --- a/CollapseLauncher/XAMLs/MainApp/Pages/StartupPage.xaml.cs +++ b/CollapseLauncher/XAMLs/MainApp/Pages/StartupPage.xaml.cs @@ -1,4 +1,4 @@ -using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Media.Animation; @@ -169,7 +169,7 @@ private async void NextPage_Click(object sender, RoutedEventArgs e) await Task.Delay(2000); } - (m_window as MainWindow).rootFrame.Navigate(typeof(StartupPage_SelectGame), null, new SlideNavigationTransitionInfo() { Effect = SlideNavigationTransitionEffect.FromRight }); + (m_window as MainWindow).rootFrame.Navigate(typeof(StartupPage_SelectCDN), null, new SlideNavigationTransitionInfo() { Effect = SlideNavigationTransitionEffect.FromRight }); } } } diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/StartupPage_SelectCDN.xaml b/CollapseLauncher/XAMLs/MainApp/Pages/StartupPage_SelectCDN.xaml new file mode 100644 index 000000000..4d2747fcf --- /dev/null +++ b/CollapseLauncher/XAMLs/MainApp/Pages/StartupPage_SelectCDN.xaml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/StartupPage_SelectCDN.xaml.cs b/CollapseLauncher/XAMLs/MainApp/Pages/StartupPage_SelectCDN.xaml.cs new file mode 100644 index 000000000..a6f446b28 --- /dev/null +++ b/CollapseLauncher/XAMLs/MainApp/Pages/StartupPage_SelectCDN.xaml.cs @@ -0,0 +1,110 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Media.Animation; +using Microsoft.UI.Xaml.Navigation; +using Microsoft.VisualBasic; +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 static CollapseLauncher.InnerLauncherConfig; +using static Hi3Helper.Shared.Region.LauncherConfig; +using static Hi3Helper.Logger; + +namespace CollapseLauncher.Pages +{ + public sealed partial class StartupPage_SelectCDN : Page + { + public StartupPage_SelectCDN() + { + this.InitializeComponent(); + } + + private void PrevPage_Click(object sender, RoutedEventArgs e) + { + NextPage.IsEnabled = true; + (m_window as MainWindow).rootFrame.Navigate(typeof(StartupPage), null, new SlideNavigationTransitionInfo() { Effect = SlideNavigationTransitionEffect.FromLeft }); + } + + private void NextPage_Click(object sender, RoutedEventArgs e) + { + // Update string urls here, probably? Would be a good idea to create a central class for all GH outbound URLs + // FIXME: Add localization for this page + (m_window as MainWindow).rootFrame.Navigate(typeof(StartupPage_SelectGame), null, new SlideNavigationTransitionInfo() { Effect = SlideNavigationTransitionEffect.FromRight}); + } + + //private List CDNList + //{ + // get + // { + // List list = new List(); + // foreach (KeyValuePair entry in LanguageNames) + // list.Add($"{entry.Value.LangData.LanguageName} ({entry.Key}) by {entry.Value.LangData.Author}"); + // return list; + // } + //} + + private List CDNList + { + get + { + List list = new List(); + list.Add($"Default (GitHub)"); + list.Add($"Statically"); + return list; + } + } + + private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + string s = CDNSelect.SelectedItem.ToString(); + // LogWriteLine("Before if:" + s); + // There is probably a better way to do this but it's 3AM and I don't feel like thinking about + // Complex data types so it's a problem for either me or the person looking at this code. Sorry in advance ;-; + if (s.Contains("Default")){ + SetAndSaveConfigValue("CDNType", "Default"); + AppNotifURLPrefix = AppNotifURLPrefix.Replace(AppNotifURLPrefix, "https://github.com/neon-nyan/CollapseLauncher-ReleaseRepo/main/notification_{0}.json"); + AppGameConfigURLPrefix = AppGameConfigURLPrefix.Replace(AppGameConfigURLPrefix, "https://github.com/neon-nyan/CollapseLauncher-ReleaseRepo/main/metadata/metadata_{0}.json"); + AppGameConfigV2URLPrefix = AppGameConfigV2URLPrefix.Replace(AppGameConfigV2URLPrefix, "https://github.com/neon-nyan/CollapseLauncher-ReleaseRepo/main/metadata/metadatav2_{0}.json"); + AppGameRepairIndexURLPrefix = AppGameRepairIndexURLPrefix.Replace(AppGameRepairIndexURLPrefix, "https://github.com/neon-nyan/CollapseLauncher-ReleaseRepo/main/metadata/repair_indexes/{0}/{1}/index"); + AppGameRepoIndexURLPrefix = AppGameRepoIndexURLPrefix.Replace(AppGameRepoIndexURLPrefix, "https://github.com/neon-nyan/CollapseLauncher-ReleaseRepo/main/metadata/repair_indexes/{0}/repo"); + } else + { + SetAndSaveConfigValue("CDNType", s); + // 1: statically + switch(s) + { + case "Statically": + // there is probably a better way to do this instead of replacing the entire string (maybe prepending?) + // LogWriteLine(s); + // LogWriteLine("Statically case"); + AppNotifURLPrefix = AppNotifURLPrefix.Replace(AppNotifURLPrefix, "https://cdn.statically.io/gh/neon-nyan/CollapseLauncher-ReleaseRepo/main/notification_{0}.json"); + AppGameConfigURLPrefix = AppGameConfigURLPrefix.Replace(AppGameConfigURLPrefix, "https://cdn.statically.io/gh/neon-nyan/CollapseLauncher-ReleaseRepo/main/metadata/metadata_{0}.json"); + AppGameConfigV2URLPrefix = AppGameConfigV2URLPrefix.Replace(AppGameConfigV2URLPrefix, "https://cdn.statically.io/gh/neon-nyan/CollapseLauncher-ReleaseRepo/main/metadata/metadatav2_{0}.json"); + AppGameRepairIndexURLPrefix = AppGameRepairIndexURLPrefix.Replace(AppGameRepairIndexURLPrefix, "https://cdn.statically.io/gh/neon-nyan/CollapseLauncher-ReleaseRepo/main/metadata/repair_indexes/{0}/{1}/index"); + AppGameRepoIndexURLPrefix = AppGameRepoIndexURLPrefix.Replace(AppGameRepoIndexURLPrefix, "https://cdn.statically.io/gh/neon-nyan/CollapseLauncher-ReleaseRepo/main/metadata/repair_indexes/{0}/repo"); + break; + } + } + NextPage.IsEnabled = true; + // LogWriteLine(GetAppConfigValue("CDNType").ToString()); + // LogWriteLine("-----------------"); + // LogWriteLine(AppNotifURLPrefix); + // LogWriteLine(AppGameConfigURLPrefix); + // LogWriteLine(AppGameConfigV2URLPrefix); + // LogWriteLine(AppGameRepairIndexURLPrefix); + // LogWriteLine(AppGameRepoIndexURLPrefix); + // LogWriteLine("-----------------"); + } + } +} diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/UpdatePage.xaml.cs b/CollapseLauncher/XAMLs/MainApp/Pages/UpdatePage.xaml.cs index 93e6f983e..8a8ec067a 100644 --- a/CollapseLauncher/XAMLs/MainApp/Pages/UpdatePage.xaml.cs +++ b/CollapseLauncher/XAMLs/MainApp/Pages/UpdatePage.xaml.cs @@ -88,16 +88,23 @@ private async void StartUpdateRoutine() { string ChannelName = (IsPreview ? "Preview" : "Stable"); if (IsPortable) ChannelName += "Portable"; - string ExecutableLocation = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); - Updater updater = new Updater(ExecutableLocation.Replace('\\', '/'), ChannelName.ToLower(), (byte)GetAppConfigValue("DownloadThread").ToInt()); - updater.UpdaterProgressChanged += Updater_UpdaterProgressChanged; - updater.UpdaterStatusChanged += Updater_UpdaterStatusChanged; - - await updater.StartFetch(); - await updater.StartCheck(); - await updater.StartUpdate(); - await updater.FinishUpdate(); + try + { + Updater updater = new Updater(ExecutableLocation.Replace('\\', '/'), ChannelName.ToLower(), (byte)GetAppConfigValue("DownloadThread").ToInt()); + updater.UpdaterProgressChanged += Updater_UpdaterProgressChanged; + updater.UpdaterStatusChanged += Updater_UpdaterStatusChanged; + + await updater.StartFetch(); + await updater.StartCheck(); + await updater.StartUpdate(); + await updater.FinishUpdate(); + } catch (Exception) + { + Console.WriteLine("An exception occured while fetching update files. "); + //Console.ReadLine(); + } + } private void Updater_UpdaterStatusChanged(object sender, Updater.UpdaterStatus e) diff --git a/CollapseLauncher/XAMLs/StartUp/StartupLanguageSelect.xaml b/CollapseLauncher/XAMLs/StartUp/StartupLanguageSelect.xaml index d895c863a..bd32c0198 100644 --- a/CollapseLauncher/XAMLs/StartUp/StartupLanguageSelect.xaml +++ b/CollapseLauncher/XAMLs/StartUp/StartupLanguageSelect.xaml @@ -14,10 +14,10 @@ - -