Skip to content

Commit

Permalink
Bugfix, minor changes, improvements
Browse files Browse the repository at this point in the history
- Correctly handle RawInput now. (I forgot the value is a "flag", not numeric value). Now holding mouse buttons while scrolling will still work.
- Improved PSO2 Updater Result dialog: Added name filter and export result to file.
- Changed 'PSO2 Data Manager' dialog, as well as added 1 new option regarding Nvidia DLSS version.
- Fixed COMException which make IE-based WebBrowser to load the pso2 news page.
- Update MahApps.Metro to v2.4.10.
  • Loading branch information
Leayal committed Jul 10, 2023
1 parent 1315553 commit 43d6827
Show file tree
Hide file tree
Showing 42 changed files with 832 additions and 287 deletions.
23 changes: 23 additions & 0 deletions LauncherCore/Classes/ConfigurationFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,29 @@ public bool LauncherCheckForSelfUpdates
set => this.Set("launcher_checkselfupdates", value);
}

public bool AllowNvidiaDlssModding
{
get
{
if (this.TryGetRaw("launcher_allowNvidiaDlssModding", out var val))
{
if (val.ValueKind == System.Text.Json.JsonValueKind.True)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
set => this.Set("launcher_allowNvidiaDlssModding", value);
}

public bool LauncherDisableInGameFileIntegrityCheck
{
get
Expand Down
52 changes: 42 additions & 10 deletions LauncherCore/Classes/PSO2/DataTypes/PSO2Version.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -36,7 +37,7 @@ public static bool TryParse(ReadOnlySpan<char> versionString, out PSO2Version va
// Or not

// WTF I am doing
if (versionString.Length == 0 || versionString.IsWhiteSpace())
if (versionString.IsEmpty || versionString.IsWhiteSpace())
{
value = default;
return false;
Expand Down Expand Up @@ -99,8 +100,8 @@ public static bool TryParse(ReadOnlySpan<char> versionString, out PSO2Version va
}
else
{
thisRC = TakeDigitOnly(in this.ReleaseCandidate);
otherRC = TakeDigitOnly(in other.ReleaseCandidate);
thisRC = TakeDigitOnly(this.ReleaseCandidate.AsSpan());
otherRC = TakeDigitOnly(other.ReleaseCandidate.AsSpan());
return thisRC.CompareTo(otherRC);
}
}
Expand All @@ -110,19 +111,50 @@ public static bool TryParse(ReadOnlySpan<char> versionString, out PSO2Version va
}
}

private static int TakeDigitOnly(in string str)
private static int TakeDigitOnly(ReadOnlySpan<char> span)
{
var span = str.AsSpan();
var sb = new StringBuilder(span.Length);
for (int i = 0; i < span.Length; i++)
if (span.IsEmpty) return int.Parse(span);
int i = 0, len = span.Length;
bool foundNonDigit = false;
for (i = 0; i < len; i++)
{
if (char.IsDigit(span[i]))
if (!char.IsDigit(span[i]))
{
sb.Append(span[i]);
foundNonDigit = true;
break;
}
}

return int.Parse(sb.ToString());
if (foundNonDigit)
{
char[]? arr = len > 512 ? ArrayPool<char>.Shared.Rent(len) : null;
Span<char> buffer = arr == null ? stackalloc char[len] : arr;
try
{
span.Slice(0, i).CopyTo(buffer);
int dstIndex = i;
for (; i < len; i++)
{
ref readonly var c = ref span[i];
if (char.IsDigit(c))
{
buffer[dstIndex++] = c;
}
}
return int.Parse(buffer.Slice(0, dstIndex));
}
finally
{
if (arr != null)
{
ArrayPool<char>.Shared.Return(arr);
}
}
}
else
{
return int.Parse(span);
}
}

public override readonly bool Equals(object? obj)
Expand Down
7 changes: 7 additions & 0 deletions LauncherCore/Classes/PSO2/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public enum FileScanFlags
/// <remarks><para>Hash table file is <u>data/win32/d4455ebc2bef618f29106da7692ebc1a</u>.</para></remarks>
IgnoreHashTableFile = 1 << 5,

/// <summary>Let the updater knows that it shouldn't re-download Nvidia DLSS binary file if the file is existed.</summary>
/// <remarks>
/// <para>However, this flag is meaningless if the file doesn't exist as it will be redownloaded to ensure the binary file isn't missing.</para>
/// <para>The DLSS binary file is <u>nvngx_dlss.dll</u>.</para>
/// </remarks>
DoNotRedownloadNvidiaDlssBin = 1 << 6,

// Preset below

[EnumDisplayName("Prefer speed [Not recommended: Unreliable] (Check missing and compare the cached MD5-hash if the file is already existed)")]
Expand Down
2 changes: 1 addition & 1 deletion LauncherCore/Classes/PSO2/GameClientUpdater.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private void OnClientOperationComplete1(string dir_pso2bin, string? pso2tweaker_
// Check whether Tweaker is targeting the same pso2_bin this launcher is managing.
if (string.Equals(pso2tweakerconfig_pso2bin, dir_pso2bin, StringComparison.OrdinalIgnoreCase))
{
pso2tweakerconfig.ResetFanPatchVersion();
pso2tweakerconfig.ResetFanPatchVersion(downloadMode);
pso2tweakerconfig.PSO2JPRemoteVersion = versionStringRaw;

if (tweakerhashcacheDump != null)
Expand Down
11 changes: 10 additions & 1 deletion LauncherCore/Classes/PSO2/GameClientUpdater.FileScan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace Leayal.PSO2Launcher.Core.Classes.PSO2
#nullable enable
partial class GameClientUpdater
{
private static readonly string __Filename_HashTableRelativePath = "data/win32/d4455ebc2bef618f29106da7692ebc1a";
private static readonly string __Filename_HashTableRelativePath = "data/win32/d4455ebc2bef618f29106da7692ebc1a",
__Filename_DlssBinaryFileRelativePath = "nvngx_dlss.dll";

const int ScanBufferSize = 1024 * 16; // 16KB buffer
private async Task<PatchListMemory> InnerGetFilelistToScan(GameClientSelection selection, CancellationToken cancellationToken)
Expand Down Expand Up @@ -329,6 +330,9 @@ static async Task<string> ___GetFileMD5(FileStream fs, MD5 hashal, CancellationT
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool IsHashTableFile(PatchListItem item) => (MemoryExtensions.Equals(item.GetSpanFilenameWithoutAffix(), __Filename_HashTableRelativePath, StringComparison.OrdinalIgnoreCase) || MemoryExtensions.Equals(item.GetSpanFilenameWithoutAffix(), __Filename_HashTableRelativePath.AsSpan(11), StringComparison.OrdinalIgnoreCase));

[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool IsDlssBinaryFile(PatchListItem item) => (MemoryExtensions.Equals(item.GetSpanFilenameWithoutAffix(), __Filename_DlssBinaryFileRelativePath, StringComparison.OrdinalIgnoreCase));

[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void AddItemToQueue(BlockingCollection<DownloadItem> queue, InnerDownloadQueueAddCallback callback, PatchListItem patchItem, string localFilePath, string dir_pso2bin, string? dir_classic_data, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -410,6 +414,11 @@ static async Task<ReadOnlyMemory<byte>> Md5ComputeHash(IncrementalHash engine, F
{
continue;
}
if ((flags & FileScanFlags.DoNotRedownloadNvidiaDlssBin) != 0 && IsDlssBinaryFile(patchItem))
{
if (File.Exists(Path.Join(dir_pso2bin, patchItem.GetSpanFilenameWithoutAffix())))
continue;
}
// data/win32/2b486d03bca4c2578f9e204b234f389b
if (flags == FileScanFlags.MissingFilesOnly)
{
Expand Down
21 changes: 17 additions & 4 deletions LauncherCore/Classes/PSO2TweakerConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Leayal.Shared;
using Leayal.PSO2Launcher.Core.Classes.PSO2;
using Leayal.Shared;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -19,10 +20,22 @@ public PSO2TweakerConfig(string path)
this.Filename = path;
}

public void ResetFanPatchVersion()
public void ResetFanPatchVersion(GameClientSelection gameClientSelection)
{
this.Set("LatestWin32FanPatchVersion", "0");
this.Set("LatestWin32RebootFanPatchVersion", "0");
switch (gameClientSelection)
{
case GameClientSelection.Classic_Only:
this.Set("LatestWin32FanPatchVersion", "0");
break;
case GameClientSelection.NGS_Only:
case GameClientSelection.NGS_Prologue_Only:
this.Set("LatestWin32RebootFanPatchVersion", "0");
break;
default:
this.Set("LatestWin32FanPatchVersion", "0");
this.Set("LatestWin32RebootFanPatchVersion", "0");
break;
}
}

public string UpdateChecks
Expand Down
2 changes: 1 addition & 1 deletion LauncherCore/LauncherCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

<ItemGroup>
<PackageReference Include="AvalonEdit" Version="6.3.0.90" />
<PackageReference Include="MahApps.Metro" Version="2.4.9" />
<PackageReference Include="MahApps.Metro" Version="2.4.10" />
<PackageReference Include="MahApps.Metro.IconPacks.FontAwesome" Version="4.11.0" />
</ItemGroup>

Expand Down
28 changes: 28 additions & 0 deletions LauncherCore/UIElements/ConvenientEventHandlers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Runtime.CompilerServices;
using System.Windows.Controls;

namespace Leayal.PSO2Launcher.Core.UIElements
{
static class ConvenientEventHandlers
{
/// <summary>When this method is added to a <seealso cref="System.Windows.Controls.Primitives.Selector.SelectionChanged"/>, prevent the control from selecting no items.</summary>
/// <remarks>
/// <para>You can also just pass-through the event handler to this handler.</para>
/// <para>Currently supports only <seealso cref="TabControl"/>.</para>
/// </remarks>
/// <param name="sender">The element which raised this event. May be <see langword="null"/>.</param>
/// <param name="e">The event parameters which associated with the event.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void TabControl_SelectionChanged_PreventSelectingNothing(object? sender, SelectionChangedEventArgs e)
{
if (e.AddedItems == null || e.AddedItems.Count == 0)
{
if (e.RemovedItems[0] is TabItem tab)
{
e.Handled = true;
tab.IsSelected = true;
}
}
}
}
}
Loading

0 comments on commit 43d6827

Please sign in to comment.