Skip to content

Commit

Permalink
[feat] Added bool flag for Updater fallbackRepoURL using CDN (#71)
Browse files Browse the repository at this point in the history
* [feat] Added bool flag for Updater fallbackRepoURL using CDN

* [feature] allow setup to change string language based on selection

Need to save currently selected language when changing option

* [fix] fixed string to be more accurate when region not installed

* [feat] added metadata repo link using CDN

Missing GameRepair & RepoIndex

* [feat] Added optional bool fallback arg to function call

* [fix] Added detection mechanism if bool fallback val is changed

* [feat] Added AppGameRepairIndexURLPrefixFallback to more files

* [fix] Force fallback for DataCheck

* [feat] Added fallback to DataIntegrityURL

* [fix] updated fallback CDN urls to statically

* [broken] Added fresh setup button for dbg

* [feat] force locale update on selectionchanged

* [broken] added process start on btn click

* [fix] add 1000ms delay for full app shutdown before restart

* [feat] add setup start btn

* [feat] added cdn selection page

* [fix] redirect launcher flow to go through CDN selection

* [feat] added next btn handling to cdn page

* [feat] added localization for new btn string

* [feat-fix] replaced btn with combobox & new locale strings for cdn instructions

* [fix] Added localization strings for CDN btn

* [fix-feat] Align items correctly on page & save cdn config

* [feat] Added missing localization for CDNSelect page

* [fix] string update for selector

* [rollback] removed fallback references in favor of dropdown select in setup

* [fix] changed App strings to static to allow for overwriting in cdn page

* [feat] overwrite Repo strings based on selected CDN

* [feat] Added CDN failover should default provider be unavailable

* [fix] removed comments

* [feat] add CDN selection in settings

* [fix] Disable debugging features from production
  • Loading branch information
Cryotechnic authored Feb 11, 2023
1 parent 7fe12ae commit 05d19d8
Show file tree
Hide file tree
Showing 27 changed files with 490 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion CollapseLauncher/Classes/RepairManagement/DataCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion CollapseLauncher/CollapseLauncher.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net7.0-windows10.0.19041.0</TargetFrameworks>
Expand Down Expand Up @@ -54,6 +54,7 @@
</PropertyGroup>
<ItemGroup>
<None Remove="XAMLs\MainApp\Pages\NotInstalledPage.xaml" />
<None Remove="XAMLs\MainApp\Pages\StartupPage_SelectCDN.xaml" />
<None Remove="XAMLs\MainApp\Pages\StartupPage_SelectGameBG.xaml" />
<None Remove="XAMLs\MainApp\Pages\WebView2Frame.xaml" />
</ItemGroup>
Expand Down Expand Up @@ -133,6 +134,11 @@
</ItemGroup>
</Target>

<ItemGroup>
<Page Update="XAMLs\MainApp\Pages\StartupPage_SelectCDN.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Update="XAMLs\MainApp\Pages\WebView2Frame.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
Expand Down
1 change: 1 addition & 0 deletions CollapseLauncher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static void Main(params string[] args)
Console.WriteLine("Initializing...", LogType.Empty);

InitializeAppSettings();
CheckRepoStatus();
ParseArguments(args);

switch (m_appMode)
Expand Down
7 changes: 4 additions & 3 deletions CollapseLauncher/XAMLs/Invoker/InvokerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(() =>
Expand Down
14 changes: 13 additions & 1 deletion CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Page
<Page
x:Class="CollapseLauncher.Pages.SettingsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand All @@ -24,6 +24,11 @@
<ComboBox x:Name="LanguageSelector" MinWidth="256" CornerRadius="14" SelectionChanged="LanguageChanged"/>
<TextBlock x:Name="AppLangSelectionWarning" Visibility="Collapsed" Text="{x:Bind helper:Locale.Lang._SettingsPage.AppLang_ApplyNeedRestart}" Margin="0,16,0,0" FontWeight="Bold" Foreground="{ThemeResource AccentColor}"/>
</StackPanel>
<StackPanel Margin="0,0,0,16">
<TextBlock Text="{x:Bind helper:Locale.Lang._SettingsPage.CDN}" Style="{ThemeResource SubtitleTextBlockStyle}" Margin="0,16,0,16"/>
<ComboBox x:Name="CDNSelector" MinWidth="256" CornerRadius="14" SelectionChanged="CDNChanged"/>
<TextBlock x:Name="CDNSelectionWarning" Visibility="Collapsed" Text="{x:Bind helper:Locale.Lang._SettingsPage.AppLang_ApplyNeedRestart}" Margin="0,16,0,0" FontWeight="Bold" Foreground="{ThemeResource AccentColor}"/>
</StackPanel>
<TextBlock Text="{x:Bind helper:Locale.Lang._SettingsPage.AppThemes}" Style="{ThemeResource SubtitleTextBlockStyle}" Margin="0,16,0,16"/>
<StackPanel Margin="0,-8,0,16">
<RadioButtons x:Name="AppThemeSelection" SelectedIndex="{x:Bind CurrentThemeSelection, Mode=TwoWay}">
Expand Down Expand Up @@ -127,6 +132,13 @@
<TextBlock Text="{x:Bind helper:Locale.Lang._SettingsPage.Update_ForceBtn}" Margin="8,-2,0,0" FontWeight="Medium" VerticalAlignment="Center"/>
</StackPanel>
</Button>

<!--<Button x:Name="ViewSetupPage" Margin="-32,16,0,0" Height="38" CornerRadius="0,17,17,0" Click="StartSetupPage" Style="{ThemeResource AccentButtonStyle}">
<StackPanel Orientation="Horizontal" Margin="32,0,0,0">
<TextBlock FontFamily="{ThemeResource FontAwesomeSolid}" Text="&#xf101;" FontSize="22"/>
<TextBlock Text="Start Setup" Margin="8,-2,0,0" FontWeight="Medium" VerticalAlignment="Center"/>
</StackPanel>
</Button>-->
</StackPanel>
<TextBlock Text="{x:Bind helper:Locale.Lang._SettingsPage.AppFiles}" Style="{ThemeResource SubtitleTextBlockStyle}" Margin="0,16,0,16"/>
<StackPanel Orientation="Horizontal" Margin="0,0,0,16">
Expand Down
88 changes: 87 additions & 1 deletion CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,6 +36,7 @@ public SettingsPage()
AppVersionTextBlock.Text = Version;
CurrentVersion.Text = Version;
GetLanguageList();
GetCDNList();
}

private void GetLanguageList()
Expand All @@ -56,6 +58,22 @@ private void GetLanguageList()
LanguageSelector.SelectedIndex = SelectedIndex;
}

private void GetCDNList()
{
List<string> list = new List<string>();
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))
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CollapseLauncher/XAMLs/MainApp/Pages/StartupPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
HorizontalAlignment="Right" VerticalAlignment="Bottom" IsEnabled="False"
Click="NextPage_Click" CornerRadius="16">
<StackPanel Orientation="Horizontal" Margin="8,0">
<TextBlock Text="{x:Bind helper:Locale.Lang._StartupPage.Pg1NextBtn}" FontWeight="Medium" Margin="0,0,8,0"/>
<TextBlock Text="{x:Bind helper:Locale.Lang._StartupPage.Pg1_5NextBtn}" FontWeight="Medium" Margin="0,0,8,0"/>
<FontIcon FontFamily="{ThemeResource FontAwesomeSolid}" Glyph="&#xf061;" FontSize="14"/>
</StackPanel>
</Button>
Expand Down
4 changes: 2 additions & 2 deletions CollapseLauncher/XAMLs/MainApp/Pages/StartupPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 });
}
}
}
Loading

0 comments on commit 05d19d8

Please sign in to comment.