Skip to content

Commit

Permalink
[Win32] Restructure + Add Customizable Toast API
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-nyan committed Dec 4, 2024
1 parent b129063 commit 7c0eb89
Show file tree
Hide file tree
Showing 21 changed files with 83 additions and 94 deletions.
2 changes: 1 addition & 1 deletion CollapseLauncher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using Hi3Helper;
using Hi3Helper.SentryHelper;
using Hi3Helper.Shared.Region;
using Hi3Helper.Win32.Native;
using Hi3Helper.Win32.Native.Enums;
using Hi3Helper.Win32.Native.LibraryImport;
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
Expand Down
6 changes: 3 additions & 3 deletions CollapseLauncher/Classes/GamePropertyVault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using Hi3Helper;
using Hi3Helper.SentryHelper;
using Hi3Helper.Shared.ClassStruct;
using Hi3Helper.Win32.Native;
using Hi3Helper.Win32.Native.ManagedTools;
using Microsoft.UI.Xaml;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -117,7 +117,7 @@ internal string _GameExecutableNameWithoutExtension

internal bool IsGameRunning
{
get => PInvoke.IsProcessExist(_GameExecutableName, out _, out _, Path.Combine(_GameVersion?.GameDirPath ?? "", _GameExecutableName), ILoggerHelper.GetILogger());
get => ProcessChecker.IsProcessExist(_GameExecutableName, out _, out _, Path.Combine(_GameVersion?.GameDirPath ?? "", _GameExecutableName), ILoggerHelper.GetILogger());
}

#nullable enable
Expand All @@ -136,7 +136,7 @@ internal bool IsGameRunning
Process process = processArr[i];
int processId = process.Id;

string? processPath = PInvoke.GetProcessPathByProcessId(processId, ILoggerHelper.GetILogger());
string? processPath = ProcessChecker.GetProcessPathByProcessId(processId, ILoggerHelper.GetILogger());
string expectedProcessPath = Path.Combine(_GameVersion?.GameDirPath ?? "", _GameExecutableName);
if (string.IsNullOrEmpty(processPath) || !expectedProcessPath.Equals(processPath, StringComparison.OrdinalIgnoreCase)
|| process.MainWindowHandle == IntPtr.Zero)
Expand Down
5 changes: 3 additions & 2 deletions CollapseLauncher/Classes/Helper/WindowUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
using Hi3Helper.SentryHelper;
using Hi3Helper.Shared.Region;
using Hi3Helper.Win32.FileDialogCOM;
using Hi3Helper.Win32.Native;
using Hi3Helper.Win32.Native.Enums;
using Hi3Helper.Win32.Native.LibraryImport;
using Hi3Helper.Win32.Native.ManagedTools;
using Hi3Helper.Win32.Native.Structs;
using Hi3Helper.Win32.Screen;
using Microsoft.Graphics.Display;
Expand Down Expand Up @@ -557,7 +558,7 @@ internal static void SetWindowTitlebarIcon(nint smallIconPtr, nint largeIconPtr)
return;
}

PInvoke.SetWindowIcon(CurrentWindowPtr, smallIconPtr, largeIconPtr);
Windowing.SetWindowIcon(CurrentWindowPtr, smallIconPtr, largeIconPtr);
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion CollapseLauncher/Classes/Properties/InnerLauncherConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using CollapseLauncher.Pages;
using Hi3Helper;
using Hi3Helper.Shared.ClassStruct;
using Hi3Helper.Win32.Native;
using Hi3Helper.Win32.Native.LibraryImport;
using Microsoft.UI.Text;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

using Hi3Helper;
using Hi3Helper.SentryHelper;
using Hi3Helper.Win32.Native;
using Hi3Helper.Win32.Native.Enums;
using Hi3Helper.Win32.Native.LibraryImport;
using Microsoft.Win32;
using System;
using System.ComponentModel;
Expand Down
4 changes: 2 additions & 2 deletions CollapseLauncher/Classes/RepairManagement/Genshin/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Hi3Helper.Data;
using Hi3Helper.EncTool.Parser.AssetIndex;
using Hi3Helper.SentryHelper;
using Hi3Helper.Win32.Native;
using Hi3Helper.Win32.Native.ManagedTools;
using System;
using System.Buffers;
using System.Collections.Concurrent;
Expand Down Expand Up @@ -49,7 +49,7 @@ private async Task Check(List<PkgVersionProperties> assetIndex, CancellationToke
try
{
var threadCount = _threadCount;
var isSsd = PInvoke.IsDriveSsd(_gameStreamingAssetsPath, ILoggerHelper.GetILogger());
var isSsd = DriveTypeChecker.IsDriveSsd(_gameStreamingAssetsPath, ILoggerHelper.GetILogger());
if (!isSsd)
{
threadCount = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Hi3Helper.Data;
using Hi3Helper.SentryHelper;
using Hi3Helper.Shared.ClassStruct;
using Hi3Helper.Win32.Native;
using Hi3Helper.Win32.Native.LibraryImport;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down
5 changes: 3 additions & 2 deletions CollapseLauncher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
using Hi3Helper.Data;
using Hi3Helper.Http.Legacy;
using Hi3Helper.Shared.ClassStruct;
using Hi3Helper.Win32.Native;
using Hi3Helper.Win32.Native.LibraryImport;
using Hi3Helper.Win32.Native.ManagedTools;
using Hi3Helper.Win32.ShellLinkCOM;
using InnoSetupHelper;
using Microsoft.UI.Dispatching;
Expand Down Expand Up @@ -184,7 +185,7 @@ public static void Main(params string[] args)

AppDomain.CurrentDomain.ProcessExit += OnProcessExit!;

InstanceCount = PInvoke.EnumerateInstances(ILoggerHelper.GetILogger());
InstanceCount = ProcessChecker.EnumerateInstances(ILoggerHelper.GetILogger());

AppActivation.Enable();
if (!AppActivation.DecideRedirection())
Expand Down
2 changes: 1 addition & 1 deletion CollapseLauncher/XAMLs/MainApp/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Hi3Helper;
using Hi3Helper.SentryHelper;
using Hi3Helper.Shared.Region;
using Hi3Helper.Win32.Native;
using Hi3Helper.Win32.Native.LibraryImport;
using Microsoft.UI.Composition;
using Microsoft.UI.Input;
using Microsoft.UI.Windowing;
Expand Down
42 changes: 21 additions & 21 deletions CollapseLauncher/XAMLs/MainApp/Pages/CachesPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#if !DISABLEDISCORD
using CollapseLauncher.DiscordPresence;
using CollapseLauncher.DiscordPresence;
#endif
using CollapseLauncher.Helper;
using CollapseLauncher.Statics;
using Hi3Helper;
using Hi3Helper.Shared.ClassStruct;
using Hi3Helper.Win32.Native;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using System;
using System.Threading.Tasks;
using static CollapseLauncher.InnerLauncherConfig;
using static Hi3Helper.Locale;
using static Hi3Helper.Logger;
using static Hi3Helper.Shared.Region.LauncherConfig;

namespace CollapseLauncher.Pages
using CollapseLauncher.Helper;
using CollapseLauncher.Statics;
using Hi3Helper;
using Hi3Helper.Shared.ClassStruct;
using Hi3Helper.Win32.Native.ManagedTools;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using System;
using System.Threading.Tasks;
using static CollapseLauncher.InnerLauncherConfig;
using static Hi3Helper.Locale;
using static Hi3Helper.Logger;
using static Hi3Helper.Shared.Region.LauncherConfig;

namespace CollapseLauncher.Pages
{
public sealed partial class CachesPage
{
Expand Down Expand Up @@ -58,7 +58,7 @@ public async void RunCheckRoutine(object sender, bool isFast, bool isMainButton)

try
{
PInvoke.PreventSleep(ILoggerHelper.GetILogger());
Sleep.PreventSleep(ILoggerHelper.GetILogger());
AddEvent();

bool IsNeedUpdate = await CurrentGameProperty._GameCache.StartCheckRoutine(isFast);
Expand Down Expand Up @@ -97,7 +97,7 @@ public async void RunCheckRoutine(object sender, bool isFast, bool isMainButton)
finally
{
RemoveEvent();
PInvoke.RestoreSleep();
Sleep.RestoreSleep();
}
}

Expand All @@ -108,7 +108,7 @@ public async void StartCachesUpdate(object sender, RoutedEventArgs e)

try
{
PInvoke.PreventSleep(ILoggerHelper.GetILogger());
Sleep.PreventSleep(ILoggerHelper.GetILogger());
AddEvent();

int assetCount = CurrentGameProperty._GameCache.AssetEntry.Count;
Expand Down Expand Up @@ -146,7 +146,7 @@ public async void StartCachesUpdate(object sender, RoutedEventArgs e)
}
finally
{
PInvoke.RestoreSleep();
Sleep.RestoreSleep();
RemoveEvent();
}
}
Expand Down
4 changes: 2 additions & 2 deletions CollapseLauncher/XAMLs/MainApp/Pages/Dialogs/SimpleDialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using CommunityToolkit.WinUI;
using Hi3Helper;
using Hi3Helper.SentryHelper;
using Hi3Helper.Win32.Native;
using Hi3Helper.Win32.Native.ManagedTools;
using Microsoft.UI.Input;
using Microsoft.UI.Text;
using Microsoft.UI.Xaml;
Expand Down Expand Up @@ -1146,7 +1146,7 @@ public static async Task<ContentDialogResult> Dialog_ShowUnhandledExceptionMenu(

private static async void CopyTextToClipboard(object sender, RoutedEventArgs e)
{
PInvoke.CopyStringToClipboard(ErrorSender.ExceptionContent, ILoggerHelper.GetILogger());
Clipboard.CopyStringToClipboard(ErrorSender.ExceptionContent, ILoggerHelper.GetILogger());
if (sender is Button btn && btn.Content != null && btn.Content is Panel panel)
{
FontIcon fontIcon = panel.Children[0] as FontIcon;
Expand Down
4 changes: 2 additions & 2 deletions CollapseLauncher/XAMLs/MainApp/Pages/FileCleanupPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using CollapseLauncher.InstallManager.Base;
using Hi3Helper;
using Hi3Helper.Data;
using Hi3Helper.Win32.Native;
using Hi3Helper.Win32.Native.ManagedTools;
using Microsoft.UI.Text;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
Expand Down Expand Up @@ -217,7 +217,7 @@ private async Task PerformRemoval(ICollection<LocalFileInfo>? deletionSource, lo
}
}

await Task.Run(() => PInvoke.MoveFileToRecycleBin(toBeDeleted));
await Task.Run(() => RecycleBin.MoveFileToRecycleBin(toBeDeleted));
DispatcherQueue.TryEnqueue(() =>
{
for (int i = FileInfoSource.Count - 1; i >= 0; i--)
Expand Down
22 changes: 11 additions & 11 deletions CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
using Hi3Helper.SentryHelper;
using Hi3Helper.Shared.ClassStruct;
using Hi3Helper.Win32.FileDialogCOM;
using Hi3Helper.Win32.Native;
using Hi3Helper.Win32.Native.ManagedTools;
using Microsoft.UI.Composition;
using Microsoft.UI.Input;
using Microsoft.UI.Text;
Expand Down Expand Up @@ -1224,7 +1224,7 @@ private async void PredownloadDialog(object sender, RoutedEventArgs e)
try
{
// Prevent device from sleep
PInvoke.PreventSleep(ILoggerHelper.GetILogger());
Sleep.PreventSleep(ILoggerHelper.GetILogger());
// Set the notification trigger to "Running" state
CurrentGameProperty._GameInstall.UpdateCompletenessStatus(CompletenessStatus.Running);

Expand Down Expand Up @@ -1259,7 +1259,7 @@ private async void PredownloadDialog(object sender, RoutedEventArgs e)

// Restore sleep before the dialog
// so system won't be stuck when download is finished because of the download verified dialog
PInvoke.RestoreSleep();
Sleep.RestoreSleep();

if (verifResult == -1)
{
Expand Down Expand Up @@ -1309,7 +1309,7 @@ private async void PredownloadDialog(object sender, RoutedEventArgs e)
CurrentGameProperty._GameInstall.Flush();

// Turn the sleep back on
PInvoke.RestoreSleep();
Sleep.RestoreSleep();
}
}

Expand Down Expand Up @@ -1347,7 +1347,7 @@ private async void InstallGameDialog(object sender, RoutedEventArgs e)
try
{
// Prevent device from sleep
PInvoke.PreventSleep(ILoggerHelper.GetILogger());
Sleep.PreventSleep(ILoggerHelper.GetILogger());
// Set the notification trigger to "Running" state
CurrentGameProperty._GameInstall.UpdateCompletenessStatus(CompletenessStatus.Running);

Expand Down Expand Up @@ -1515,7 +1515,7 @@ await SpawnDialog(Lang._HomePage.InstallFolderRootTitle,
ReturnToHomePage();

// Turn the sleep back on
PInvoke.RestoreSleep();
Sleep.RestoreSleep();
}
}

Expand Down Expand Up @@ -2166,11 +2166,11 @@ public async void TryInstallMediaPack()
#region Exclusive Window Payload
public async void StartExclusiveWindowPayload()
{
IntPtr _windowPtr = PInvoke.GetProcessWindowHandle(CurrentGameProperty._GameVersion.GamePreset.GameExecutableName ?? "");
IntPtr _windowPtr = ProcessChecker.GetProcessWindowHandle(CurrentGameProperty._GameVersion.GamePreset.GameExecutableName ?? "");
await Task.Delay(1000);
PInvoke.HideWindow(_windowPtr);
Windowing.HideWindow(_windowPtr);
await Task.Delay(1000);
PInvoke.ShowWindow(_windowPtr);
Windowing.ShowWindow(_windowPtr);
}
#endregion

Expand Down Expand Up @@ -2570,7 +2570,7 @@ private async void UpdateGameDialog(object sender, RoutedEventArgs e)
try
{
// Prevent device from sleep
PInvoke.PreventSleep(ILoggerHelper.GetILogger());
Sleep.PreventSleep(ILoggerHelper.GetILogger());
// Set the notification trigger to "Running" state
CurrentGameProperty._GameInstall.UpdateCompletenessStatus(CompletenessStatus.Running);

Expand Down Expand Up @@ -2673,7 +2673,7 @@ private async void UpdateGameDialog(object sender, RoutedEventArgs e)
ReturnToHomePage();

// Turn the sleep back on
PInvoke.RestoreSleep();
Sleep.RestoreSleep();
}
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using Hi3Helper.CommunityToolkit.WinUI.Controls;
using Hi3Helper.Shared.ClassStruct;
using Hi3Helper.Win32.FileDialogCOM;
using Hi3Helper.Win32.Native;
using Hi3Helper.Win32.Native.LibraryImport;
using Microsoft.UI.Composition;
using Microsoft.UI.Text;
using Microsoft.UI.Xaml;
Expand Down
Loading

0 comments on commit 7c0eb89

Please sign in to comment.