Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into custom-game-bg
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryotechnic committed Aug 24, 2024
2 parents e8df9fb + 2bb7696 commit 02d9631
Show file tree
Hide file tree
Showing 15 changed files with 474 additions and 369 deletions.
1 change: 1 addition & 0 deletions CollapseLauncher.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CDNURL/@EntryIndexedValue">CDNURL</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FX/@EntryIndexedValue">FX</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FXAA/@EntryIndexedValue">FXAA</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GLC/@EntryIndexedValue">GLC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HD/@EntryIndexedValue">HD</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HDR/@EntryIndexedValue">HDR</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ID/@EntryIndexedValue">ID</s:String>
Expand Down
32 changes: 20 additions & 12 deletions CollapseLauncher/Classes/Helper/WindowUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ private static IntPtr MainWndProc(IntPtr hwnd, uint msg, UIntPtr wParam, IntPtr
{
mainWindow._TrayIcon.ToggleAllVisibility();
}
else TrayNullHandler("WindowUtility.MainWndProc");

return 0;
}
Expand Down Expand Up @@ -661,21 +662,21 @@ internal static bool IsCurrentWindowInFocus()
/// </summary>
public static void ToggleToTray_MainWindow()
{
if (CurrentWindow is MainWindow window)
{
window._TrayIcon.ToggleMainVisibility();
}
if (CurrentWindow is not MainWindow window) return;

if (window._TrayIcon != null) window._TrayIcon.ToggleMainVisibility();
else TrayNullHandler(nameof(Tray_ShowNotification));
}

/// <summary>
/// <inheritdoc cref="TrayIcon.ToggleAllVisibility" />
/// </summary>
public static void ToggleToTray_AllWindow()
{
if (CurrentWindow is MainWindow window)
{
window._TrayIcon.ToggleAllVisibility();
}
if (CurrentWindow is not MainWindow window) return;

if (window._TrayIcon != null) window._TrayIcon.ToggleAllVisibility();
else TrayNullHandler(nameof(Tray_ShowNotification));
}

/// <summary>
Expand Down Expand Up @@ -722,10 +723,17 @@ public static void Tray_ShowNotification(string title,
bool respectQuietTime = true,
bool realtime = false)
{
if (CurrentWindow is MainWindow window)
{
window._TrayIcon.ShowNotification(title, message, icon, customIconHandle, largeIcon, sound, respectQuietTime, realtime);
}
if (CurrentWindow is not MainWindow window) return;

if (window._TrayIcon != null)
window._TrayIcon.ShowNotification(title, message, icon, customIconHandle, largeIcon, sound,
respectQuietTime, realtime);
else TrayNullHandler(nameof(Tray_ShowNotification));
}

private static void TrayNullHandler(string caller)
{
Logger.LogWriteLine($"TrayIcon is null/not initialized!\r\n\tCalled by: {caller}");
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2776,7 +2776,10 @@ private async Task StartSteamMigration(string gamePath)

try
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
// This is intentional as the dialog is only to cancel the routine, not waiting for user input.
SimpleDialogs.QueueAndSpawnDialog(contentDialog);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
await gameRepairInstance.StartCheckRoutine();
statusActivity.Text = Lang._InstallMigrateSteam.Step4Title;
await gameRepairInstance.StartRepairRoutine(false);
Expand Down
20 changes: 10 additions & 10 deletions CollapseLauncher/CollapseLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@

<PackageReference Include="CommunityToolkit.Common" Version="8.2.2" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="CommunityToolkit.WinUI.Behaviors" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.ImageCropper" Version="8.1.240328-rc" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.Primitives" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.WinUI.Media" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.WinUI.Converters" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.WinUI.Extensions" Version="8.1.240328-rc" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.Sizers" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.WinUI.Behaviors" Version="8.1.240821" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.ImageCropper" Version="8.1.240821" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.Primitives" Version="8.1.240821" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.1.240821" />
<PackageReference Include="CommunityToolkit.WinUI.Media" Version="8.1.240821" />
<PackageReference Include="CommunityToolkit.WinUI.Converters" Version="8.1.240821" />
<PackageReference Include="CommunityToolkit.WinUI.Extensions" Version="8.1.240821" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.Sizers" Version="8.1.240821" />

<!--
Only include FFmpegInteropX NuGet if USEFFMPEGFORVIDEOBG is defined in constants.
Expand All @@ -90,8 +90,8 @@
<PackageReference Include="FFmpegInteropX" Version="*-*" Condition="$(DefineConstants.Contains('USEFFMPEGFORVIDEOBG'))" />

<PackageReference Include="GitInfo" Version="3.3.5" PrivateAssets="all" />
<PackageReference Include="H.NotifyIcon.WinUI" Version="2.1.2" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.63" />
<PackageReference Include="H.NotifyIcon.WinUI" Version="2.1.3" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.64" />
<PackageReference Include="ImageEx" Version="2.1.1" />
<PackageReference Include="Markdig.Signed" Version="0.37.0" />
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.2.0" />
Expand Down
4 changes: 2 additions & 2 deletions CollapseLauncher/XAMLs/MainApp/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@
</Grid>
<customcontrol:ContentDialogCollapse x:Name="ContentDialog"
x:FieldModifier="internal" />
<local:TrayIcon x:Name="_TrayIcon"
x:FieldModifier="internal" />
<local:TrayIcon Grid.Row="0" x:Name="_TrayIcon"
x:FieldModifier="public" />
<Grid x:Name="TitleBarFrameGrid"
Grid.Row="0">
<Grid x:Name="AppTitleBar"
Expand Down
9 changes: 4 additions & 5 deletions CollapseLauncher/XAMLs/MainApp/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ namespace CollapseLauncher
{
public sealed partial class MainWindow : Window
{
internal static bool IsForceDisableIntro = false;

private static bool _isForceDisableIntro;
public MainWindow() { }

public void InitializeWindowProperties(bool startOOBE = false)
Expand All @@ -40,7 +39,7 @@ public void InitializeWindowProperties(bool startOOBE = false)

if (IsFirstInstall || startOOBE)
{
IsForceDisableIntro = true;
_isForceDisableIntro = true;
WindowUtility.CurrentWindowTitlebarExtendContent = true;
WindowUtility.SetWindowSize(WindowSize.WindowSize.CurrentWindowSize.WindowBounds.Width, WindowSize.WindowSize.CurrentWindowSize.WindowBounds.Height);
WindowUtility.ApplyWindowTitlebarLegacyColor();
Expand Down Expand Up @@ -71,7 +70,7 @@ public void StartMainPage()

private async void RunIntroSequence()
{
bool isIntroEnabled = IsIntroEnabled && !IsForceDisableIntro;
bool isIntroEnabled = IsIntroEnabled && !_isForceDisableIntro;
RootFrameGrid.Opacity = 0;

if (isIntroEnabled)
Expand Down Expand Up @@ -109,7 +108,7 @@ private async void RunIntroSequence()
}
WindowUtility.SetWindowBackdrop(WindowBackdropKind.None);

IsForceDisableIntro = true;
_isForceDisableIntro = true;
IntroSequenceToggle.Visibility = Visibility.Collapsed;
IntroAnimationGrid.Visibility = Visibility.Collapsed;

Expand Down
98 changes: 55 additions & 43 deletions CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Windows.Foundation;
using Microsoft.UI.Xaml.Media;
using static CollapseLauncher.Dialogs.SimpleDialogs;
using static CollapseLauncher.InnerLauncherConfig;
Expand All @@ -56,6 +56,7 @@
using static Hi3Helper.Shared.Region.LauncherConfig;
using Brush = Microsoft.UI.Xaml.Media.Brush;
using Image = Microsoft.UI.Xaml.Controls.Image;
using Point = Windows.Foundation.Point;
using Size = System.Drawing.Size;
using Timer = System.Timers.Timer;
using UIElementExtensions = CollapseLauncher.Extension.UIElementExtensions;
Expand All @@ -72,8 +73,8 @@ public sealed partial class HomePage
private int barWidth;
private int consoleWidth;

public static int RefreshRateDefault { get; } = 500;
public static int RefreshRateSlow { get; } = 1000;
public static int RefreshRateDefault => 500;
public static int RefreshRateSlow => 1000;

private static int _refreshRate;

Expand Down Expand Up @@ -2600,15 +2601,16 @@ private async void GameBoost_Invoke(GamePresetProperty gameProp)
#region Pre/Post Game Launch Command
private Process _procPreGLC;

private async void PreLaunchCommand(IGameSettingsUniversal _settings)
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
private async void PreLaunchCommand(IGameSettingsUniversal settings)
{
try
{
string preGameLaunchCommand = _settings?.SettingsCollapseMisc?.GamePreLaunchCommand;
var preGameLaunchCommand = settings?.SettingsCollapseMisc?.GamePreLaunchCommand;
if (string.IsNullOrEmpty(preGameLaunchCommand)) return;

LogWriteLine($"Using Pre-launch command : {preGameLaunchCommand}\r\n" +
$"Game launch is delayed by {_settings.SettingsCollapseMisc.GameLaunchDelay} ms\r\n\t" +
$"Game launch is delayed by {settings.SettingsCollapseMisc.GameLaunchDelay} ms\r\n\t" +
$"BY USING THIS, NO SUPPORT IS PROVIDED IF SOMETHING HAPPENED TO YOUR ACCOUNT, GAME, OR SYSTEM!",
LogType.Warning, true);

Expand All @@ -2621,23 +2623,18 @@ private async void PreLaunchCommand(IGameSettingsUniversal _settings)
_procPreGLC.StartInfo.RedirectStandardOutput = true;
_procPreGLC.StartInfo.RedirectStandardError = true;

_procPreGLC.OutputDataReceived += (_, e) =>
{
if (!string.IsNullOrEmpty(e.Data)) LogWriteLine(e.Data, LogType.GLC, true);
};

_procPreGLC.ErrorDataReceived += (_, e) =>
{
if (!string.IsNullOrEmpty(e.Data)) LogWriteLine($"ERROR RECEIVED!\r\n\t" +
$"{e.Data}", LogType.GLC, true);
};
_procPreGLC.OutputDataReceived += GLC_OutputHandler;
_procPreGLC.ErrorDataReceived += GLC_ErrorHandler;

_procPreGLC.Start();

_procPreGLC.BeginOutputReadLine();
_procPreGLC.BeginErrorReadLine();

await _procPreGLC.WaitForExitAsync();

_procPreGLC.OutputDataReceived -= GLC_OutputHandler;
_procPreGLC.ErrorDataReceived -= GLC_ErrorHandler;
}
catch (Win32Exception ex)
{
Expand All @@ -2647,36 +2644,45 @@ private async void PreLaunchCommand(IGameSettingsUniversal _settings)
}
finally
{
if (_procPreGLC != null) _procPreGLC.Dispose();
_procPreGLC?.Dispose();
}
}

[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
private void PreLaunchCommand_ForceClose()
{
try
{
if (_procPreGLC != null && !_procPreGLC.HasExited)
{
// Kill main and child processes
Process taskKill = new Process();
taskKill.StartInfo.FileName = "taskkill";
taskKill.StartInfo.Arguments = $"/F /T /PID {_procPreGLC.Id}";
taskKill.Start();
taskKill.WaitForExit();
if (_procPreGLC is not { HasExited: false }) return;

LogWriteLine("Pre-launch command has been forced to close!", LogType.Warning, true);
}
// Kill main and child processes
var taskKill = new Process();
taskKill.StartInfo.FileName = "taskkill";
taskKill.StartInfo.Arguments = $"/F /T /PID {_procPreGLC.Id}";
taskKill.Start();
taskKill.WaitForExit();

LogWriteLine("Pre-launch command has been forced to close!", LogType.Warning, true);
}
// Ignore external errors
catch (InvalidOperationException) { }
catch (Win32Exception) { }
catch (InvalidOperationException)
{
}
catch (Win32Exception)
{
}
catch (Exception ex)
{
LogWriteLine($"Error when trying to close Pre-GLC!\r\n{ex}", LogType.Error, true);
}
}

private async void PostExitCommand(IGameSettingsUniversal _settings)
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
private static async void PostExitCommand(IGameSettingsUniversal settings)
{
try
{
string postGameExitCommand = _settings?.SettingsCollapseMisc?.GamePostExitCommand;
var postGameExitCommand = settings?.SettingsCollapseMisc?.GamePostExitCommand;
if (string.IsNullOrEmpty(postGameExitCommand)) return;

LogWriteLine($"Using Post-launch command : {postGameExitCommand}\r\n\t" +
Expand All @@ -2692,30 +2698,36 @@ private async void PostExitCommand(IGameSettingsUniversal _settings)
procPostGLC.StartInfo.RedirectStandardOutput = true;
procPostGLC.StartInfo.RedirectStandardError = true;

procPostGLC.OutputDataReceived += (_, e) =>
{
if (!string.IsNullOrEmpty(e.Data)) LogWriteLine(e.Data, LogType.GLC, true);
};

procPostGLC.ErrorDataReceived += (_, e) =>
{
if (!string.IsNullOrEmpty(e.Data)) LogWriteLine($"ERROR RECEIVED!\r\n\t" +
$"{e.Data}", LogType.GLC, true);
};
procPostGLC.OutputDataReceived += GLC_OutputHandler;
procPostGLC.ErrorDataReceived += GLC_ErrorHandler;

procPostGLC.Start();
procPostGLC.BeginOutputReadLine();
procPostGLC.BeginErrorReadLine();

await procPostGLC.WaitForExitAsync();

procPostGLC.OutputDataReceived -= GLC_OutputHandler;
procPostGLC.ErrorDataReceived -= GLC_ErrorHandler;
}
catch (Win32Exception ex)
{
LogWriteLine($"There is a problem while trying to launch Post-Game Command with Region: " +
$"{CurrentGameProperty._GameVersion.GamePreset.ZoneName}\r\nTraceback: {ex}", LogType.Error, true);
LogWriteLine($"There is a problem while trying to launch Post-Game Command with command:\r\n\t" +
$"{settings?.SettingsCollapseMisc?.GamePostExitCommand}\r\n" +
$"Traceback: {ex}", LogType.Error, true);
ErrorSender.SendException(new Win32Exception($"There was an error while trying to launch Post-Exit command\r\tThrow: {ex}", ex));
}
}

private static void GLC_OutputHandler(object _, DataReceivedEventArgs e)
{
if (!string.IsNullOrEmpty(e.Data)) LogWriteLine(e.Data, LogType.GLC, true);
}

private static void GLC_ErrorHandler(object _, DataReceivedEventArgs e)
{
if (!string.IsNullOrEmpty(e.Data)) LogWriteLine($"ERROR RECEIVED!\r\n\t" + $"{e.Data}", LogType.GLC, true);
}
#endregion

#region Shortcut Creation
Expand Down
Loading

0 comments on commit 02d9631

Please sign in to comment.