Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stable 1.82.10 Hotfix #647

Merged
merged 16 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions CollapseLauncher/Classes/Helper/StreamUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,19 @@ internal static FileInfo EnsureNoReadOnly(this FileInfo fileInfo)

internal static FileInfo EnsureNoReadOnly(this FileInfo fileInfo, out bool isFileExist)
{
if (!(isFileExist = fileInfo.Exists))
return fileInfo;
try
{
if (!(isFileExist = fileInfo.Exists))
return fileInfo;

fileInfo.IsReadOnly = false;
fileInfo.IsReadOnly = false;

return fileInfo;
return fileInfo;
}
finally
{
fileInfo.Refresh();
}
}

internal static IEnumerable<FileInfo> EnumerateNoReadOnly(this IEnumerable<FileInfo> enumeratedFileInfo)
Expand Down Expand Up @@ -111,10 +118,17 @@ internal static FileInfo EnsureCreationOfDirectory(this FileInfo filePath)
ArgumentNullException.ThrowIfNull(filePath, nameof(filePath));
DirectoryInfo? directoryInfo = filePath.Directory;

if (directoryInfo is { Exists: false })
directoryInfo.Create();
try
{
if (directoryInfo is { Exists: false })
directoryInfo.Create();

return filePath;
return filePath;
}
finally
{
filePath.Refresh();
}
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,12 @@ public ConvertProgress(long StartSize, long EndSize, int StartCount, int EndCoun
public long EndSize { get; private set; }
public int StartCount { get; private set; }
public int EndCount { get; private set; }
public double Percentage => UseCountUnit ? Math.Round((StartCount / (double)EndCount) * 100, 2) :
Math.Round((StartSize / (double)EndSize) * 100, 2);
public long ProgressSpeed => (long)(StartSize / _TimeSecond);
public TimeSpan RemainingTime => UseCountUnit ? TimeSpan.FromSeconds(0f) :
((EndSize - StartSize) / Unzeroed(ProgressSpeed)).ToTimeSpanNormalized();
private double Unzeroed(double i) => i == 0 ? 1 : i;
public double Percentage => UseCountUnit ? ToPercentage(EndCount, StartCount) :
ToPercentage(EndSize, StartSize);
public double ProgressSpeed => StartSize / _TimeSecond;
public TimeSpan RemainingTime => UseCountUnit ? TimeSpan.Zero :
ToTimeSpanRemain(EndSize, StartSize, ProgressSpeed);

public string ProgressStatus => _StatusMsg;
public string ProgressDetail => string.Format(
"[{0}] ({1})\r\n{2}...",
Expand Down
181 changes: 99 additions & 82 deletions CollapseLauncher/Classes/Interfaces/Class/ProgressBase.cs

Large diffs are not rendered by default.

37 changes: 14 additions & 23 deletions CollapseLauncher/Classes/Interfaces/Class/Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,22 @@ namespace CollapseLauncher
{
internal class TotalPerFileProgress
{
private double _progressPerFilePercentage;
private double _progressPerFileSpeed;
private double _progressAllPercentage;
private double _progressAllSpeed;
private long _progressPerFileEntryCountCurrent;
private long _progressPerFileEntryCountTotal;
private long _progressAllEntryCountCurrent;
private long _progressAllEntryCountTotal;

public double ProgressPerFilePercentage { get => _progressPerFilePercentage; set => _progressPerFilePercentage = value.UnNaNInfinity(); }
public double ProgressPerFileSpeed { get => _progressPerFileSpeed; set => _progressPerFileSpeed = value.UnNaNInfinity(); }
public double ProgressAllPercentage { get => _progressAllPercentage; set => _progressAllPercentage = value.UnNaNInfinity(); }
public double ProgressAllSpeed { get => _progressAllSpeed; set => _progressAllSpeed = value.UnNaNInfinity(); }

public long ProgressPerFileEntryCountCurrent { get => _progressPerFileEntryCountCurrent; set => _progressPerFileEntryCountCurrent = value; }
public long ProgressPerFileEntryCountTotal { get => _progressPerFileEntryCountTotal; set => _progressPerFileEntryCountTotal = value; }
public long ProgressAllEntryCountCurrent { get => _progressAllEntryCountCurrent; set => _progressAllEntryCountCurrent = value; }
public long ProgressAllEntryCountTotal { get => _progressAllEntryCountTotal; set => _progressAllEntryCountTotal = value; }
public double ProgressPerFilePercentage;
public double ProgressPerFileSpeed;
public double ProgressAllPercentage;
public double ProgressAllSpeed;

public long ProgressPerFileEntryCountCurrent;
public long ProgressPerFileEntryCountTotal;
public long ProgressAllEntryCountCurrent;
public long ProgressAllEntryCountTotal;

// Extension for IGameInstallManager
public double ProgressPerFileSizeCurrent { get; set; }
public double ProgressPerFileSizeTotal { get; set; }
public double ProgressAllSizeCurrent { get; set; }
public double ProgressAllSizeTotal { get; set; }
public TimeSpan ProgressAllTimeLeft { get; set; }
public long ProgressPerFileSizeCurrent;
public long ProgressPerFileSizeTotal;
public long ProgressAllSizeCurrent;
public long ProgressAllSizeTotal;
public TimeSpan ProgressAllTimeLeft;
}

internal class TotalPerFileStatus
Expand Down
31 changes: 25 additions & 6 deletions CollapseLauncher/Classes/RegionManagement/FallbackCDNUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ public async Task DownloadFile(string url,
try
{
FallbackCDNUtil.DownloadProgress += progressEvent;
string relativePath = GetRelativePathOnly(url);
await FallbackCDNUtil.DownloadCDNFallbackContent(downloadClient, targetFile, AppCurrentDownloadThread,
GetRelativePathOnly(url),
relativePath,
#if !USEVELOPACK
default
default
#else
cancelToken
#endif
Expand All @@ -80,7 +81,8 @@ public async Task<byte[]> DownloadBytes(string url, string authorization = null,
public async Task<byte[]> DownloadBytes(string url, string? authorization = null, string? accept = null, double timeout = 30.0)
#endif
{
await using BridgedNetworkStream stream = await FallbackCDNUtil.TryGetCDNFallbackStream(GetRelativePathOnly(url), default, true);
string relativePath = GetRelativePathOnly(url);
await using BridgedNetworkStream stream = await FallbackCDNUtil.TryGetCDNFallbackStream(relativePath, default, true);
byte[] buffer = new byte[stream.Length];
await stream.ReadExactlyAsync(buffer);
return buffer;
Expand All @@ -92,16 +94,33 @@ public async Task<string> DownloadString(string url, string authorization = null
public async Task<string> DownloadString(string url, string? authorization = null, string? accept = null, double timeout = 30.0)
#endif
{
await using BridgedNetworkStream stream = await FallbackCDNUtil.TryGetCDNFallbackStream(GetRelativePathOnly(url), default, true);
string relativePath = GetRelativePathOnly(url);
await using BridgedNetworkStream stream = await FallbackCDNUtil.TryGetCDNFallbackStream(relativePath, default, true);
byte[] buffer = new byte[stream.Length];
await stream.ReadExactlyAsync(buffer);
return Encoding.UTF8.GetString(buffer);
}

private string[]? CdnBaseUrls;
private string GetRelativePathOnly(string url)
{
string toCompare = FallbackCDNUtil.GetPreferredCDN().URLPrefix;
return url.AsSpan(toCompare.Length).ToString();
// Populate the CDN Base URLs if the field is null
CdnBaseUrls ??= CDNList.Select(x => x.URLPrefix).ToArray();

// Get URL span and iterate through the CDN Base URLs
ReadOnlySpan<char> urlSpan = url.AsSpan();
for (int i = 0; i < CdnBaseUrls.Length; i++)
{
// Get the index of the base URL. If not found (-1), then continue
int indexOf = urlSpan.IndexOf(CdnBaseUrls[i], StringComparison.OrdinalIgnoreCase);
if (indexOf < 0) continue;

// Otherwise, slice the urlSpan based on the index and return the sliced relative URL.
return urlSpan.Slice(indexOf + CdnBaseUrls[i].Length).ToString();
}

// If it's not a CDN-based url, return it anyway.
return url;
}
}

Expand Down
6 changes: 3 additions & 3 deletions CollapseLauncher/Classes/RepairManagement/BSDiff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,17 +414,17 @@

public void UpdatePatchEvent(long sizePatched, long sizeToBePatched, long read, double totalSecond)
{
this.Speed = (sizePatched / totalSecond);
this.Speed = sizePatched / totalSecond;
this.SizePatched = sizePatched;
this.SizeToBePatched = sizeToBePatched;
this.Read = read;
}

public long SizePatched { get; private set; }
public long SizeToBePatched { get; private set; }
public double ProgressPercentage => Math.Round((SizePatched / (double)SizeToBePatched) * 100, 2);
public double ProgressPercentage => ConverterTool.ToPercentage(SizeToBePatched, SizePatched);
public long Read { get; private set; }

Check warning on line 426 in CollapseLauncher/Classes/RepairManagement/BSDiff.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Auto-property accessor is never used (non-private accessibility)

Auto-property accessor 'Read.get' is never used
public double Speed { get; private set; }
public TimeSpan TimeLeft => checked(((SizeToBePatched - SizePatched) / Speed.Unzeroed()).ToTimeSpanNormalized());
public TimeSpan TimeLeft => ConverterTool.ToTimeSpanRemain(SizeToBePatched, SizePatched, Speed);
}
}
2 changes: 1 addition & 1 deletion CollapseLauncher/Classes/RepairManagement/Genshin/Fetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ private void _httpClient_FetchManifestAssetProgress(int read, DownloadProgress d
lock (_progress)
{
_progress.ProgressPerFilePercentage =
GetPercentageNumber(downloadProgress.BytesDownloaded, downloadProgress.BytesTotal);
ToPercentage(downloadProgress.BytesTotal, downloadProgress.BytesDownloaded);
}

// Push status and progress update
Expand Down
15 changes: 12 additions & 3 deletions CollapseLauncher/Classes/RepairManagement/StarRail/Check.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Hi3Helper;
using CollapseLauncher.Helper;
using Hi3Helper;
using Hi3Helper.Data;
using Hi3Helper.SentryHelper;
using Hi3Helper.Shared.ClassStruct;
Expand Down Expand Up @@ -389,10 +390,18 @@
basePath = Path.GetDirectoryName(filePath);
baseName = Path.GetFileNameWithoutExtension(filePath);

// Get directory base info. If it doesn't exist, return
DirectoryInfo basePathDirInfo = new DirectoryInfo(basePath);

Check warning on line 394 in CollapseLauncher/Classes/RepairManagement/StarRail/Check.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Possible 'null' assignment to non-nullable entity

Possible 'null' assignment to non-nullable entity

Check warning

Code scanning / QDNET

Possible 'null' assignment to non-nullable entity Warning

Possible 'null' assignment to non-nullable entity
if (!basePathDirInfo.Exists)
{
return;
}

// Enumerate any possible existing hash path and delete it
foreach (string existingPath in Directory.EnumerateFiles(basePath!, $"{baseName}_*.hash"))
foreach (FileInfo existingPath in basePathDirInfo.EnumerateFiles($"{baseName}_*.hash")
.EnumerateNoReadOnly())
{
File.Delete(existingPath);
existingPath.Delete();
}
}
#endregion
Expand Down
2 changes: 1 addition & 1 deletion CollapseLauncher/CollapseLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Authors>$(Company). neon-nyan, Cry0, bagusnl, shatyuka, gablm.</Authors>
<Copyright>Copyright 2022-2024 $(Company)</Copyright>
<!-- Versioning -->
<Version>1.82.9</Version>
<Version>1.82.10</Version>
<LangVersion>preview</LangVersion>
<!-- Target Settings -->
<Platforms>x64</Platforms>
Expand Down
22 changes: 16 additions & 6 deletions CollapseLauncher/XAMLs/MainApp/Pages/Dialogs/SimpleDialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,16 @@
Grid thisIconText = (Grid)thisCheckBox?.FindDescendant("IconText");
if (thisIconText != null)
thisIconText.Opacity = 1;

RadioButton thisRadioButton = thisCheckBox.Parent as RadioButton;

Check warning on line 476 in CollapseLauncher/XAMLs/MainApp/Pages/Dialogs/SimpleDialogs.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Possible 'System.NullReferenceException'

Possible 'System.NullReferenceException'

Check warning

Code scanning / QDNET

Possible 'System.NullReferenceException' Warning

Possible 'System.NullReferenceException'
TextBlock textBlockLocal = thisRadioButton?.FindDescendant("UseAsDefaultLabel") as TextBlock;
if (thisRadioButton != null && textBlockLocal != null)
{
if (thisIndex != defaultChoiceRadioButton.SelectedIndex)
{
textBlockLocal.Opacity = 0.5;
}
}
};
checkBox.Unchecked += (sender, _) =>
{
Expand Down Expand Up @@ -663,24 +673,24 @@
Lang._Misc.NoKeepInstallIt
);

public static async Task<ContentDialogResult> Dialog_ExistingInstallationBetterLauncher(UIElement Content, string gamePath) =>
public static async Task<ContentDialogResult> Dialog_ExistingInstallationBetterLauncher(UIElement Content, string gamePath, bool isHasOnlyMigrateOption) =>
await SpawnDialog(
Lang._Dialogs.ExistingInstallBHI3LTitle,
string.Format(Lang._Dialogs.ExistingInstallBHI3LSubtitle, gamePath),
Content,
Lang._Misc.Cancel,
Lang._Misc.YesMigrateIt,
Lang._Misc.NoKeepInstallIt
isHasOnlyMigrateOption ? null : Lang._Misc.NoKeepInstallIt
);

public static async Task<ContentDialogResult> Dialog_ExistingInstallationSteam(UIElement Content, string gamePath) =>
public static async Task<ContentDialogResult> Dialog_ExistingInstallationSteam(UIElement Content, string gamePath, bool isHasOnlyMigrateOption) =>
await SpawnDialog(
Lang._Dialogs.ExistingInstallSteamTitle,
string.Format(Lang._Dialogs.ExistingInstallSteamSubtitle, gamePath),
Content,
Lang._Misc.Cancel,
Lang._Misc.YesMigrateIt,
Lang._Misc.NoKeepInstallIt
isHasOnlyMigrateOption ? null : Lang._Misc.NoKeepInstallIt
);


Expand All @@ -692,9 +702,9 @@
switch (migrateFromLauncherType)
{
case MigrateFromLauncherType.BetterHi3Launcher:
return await Dialog_ExistingInstallationBetterLauncher(Content, existingGamePath);
return await Dialog_ExistingInstallationBetterLauncher(Content, existingGamePath, isHasOnlyMigrateOption);
case MigrateFromLauncherType.Steam:
return await Dialog_ExistingInstallationSteam(Content, existingGamePath);
return await Dialog_ExistingInstallationSteam(Content, existingGamePath, isHasOnlyMigrateOption);
default:
throw new InvalidOperationException($"Dialog is not supported for unknown migration!");
}
Expand Down
4 changes: 3 additions & 1 deletion CollapseLauncher/XAMLs/Updater/Classes/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,9 @@ public UpdaterProgress(Stopwatch currentStopwatch, int counter, int counterGoal)

var elapsedMin = (float)currentStopwatch.ElapsedMilliseconds / 1000 / 60;
var minLeft = elapsedMin / counter * (counterGoal - counter);
TimeLeft = TimeSpan.FromMinutes(minLeft.UnNaNInfinity());
TimeLeft = double.IsNaN(minLeft) || double.IsInfinity(minLeft) ?
TimeSpan.Zero :
TimeSpan.FromMinutes(minLeft);

ProgressPercentage = counter;
}
Expand Down
4 changes: 2 additions & 2 deletions CollapseLauncher/XAMLs/Updater/UpdaterWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ await File.WriteAllTextAsync(Path.Combine(workingDir, "..\\", "release"),

private void FallbackCDNUtil_DownloadProgress(object sender, DownloadEvent e)
{
double speed = e.SizeDownloaded / CurrentStopwatch.Elapsed.TotalSeconds;
TimeSpan timeLeft = ((e.SizeToBeDownloaded - e.SizeDownloaded) / speed).ToTimeSpanNormalized();
double speed = e.SizeDownloaded / CurrentStopwatch.Elapsed.TotalSeconds;
TimeSpan timeLeft = ToTimeSpanRemain(e.SizeToBeDownloaded, e.SizeDownloaded, speed);

DispatcherQueue?.TryEnqueue(() =>
{
Expand Down
6 changes: 5 additions & 1 deletion Hi3Helper.Core/Lang/Locale/LangUpdatePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public sealed partial class LangUpdatePage

public string ApplyUpdateErrCollapseRunTitle { get; set; } = LangFallback?._UpdatePage.ApplyUpdateErrCollapseRunTitle;
public string ApplyUpdateErrCollapseRunSubtitle { get; set; } = LangFallback?._UpdatePage.ApplyUpdateErrCollapseRunSubtitle;
public string ApplyUpdateErrCollapseRunTitleWarnBox { get; set; } = LangFallback?._UpdatePage.ApplyUpdateErrCollapseRunTitleWarnBox;
public string ApplyUpdateErrCollapseRunSubtitleWarnBox { get; set; } = LangFallback?._UpdatePage.ApplyUpdateErrCollapseRunSubtitleWarnBox;
public string ApplyUpdateErrVelopackStateBrokenTitleWarnBox { get; set; } = LangFallback?._UpdatePage.ApplyUpdateErrVelopackStateBrokenTitleWarnBox;
public string ApplyUpdateErrVelopackStateBrokenSubtitleWarnBox { get; set; } = LangFallback?._UpdatePage.ApplyUpdateErrVelopackStateBrokenSubtitleWarnBox;
public string ApplyUpdateErrReleaseFileNotFoundTitle { get; set; } = LangFallback?._UpdatePage.ApplyUpdateErrReleaseFileNotFoundTitle;
public string ApplyUpdateErrReleaseFileNotFoundSubtitle { get; set; } = LangFallback?._UpdatePage.ApplyUpdateErrReleaseFileNotFoundSubtitle;

Expand All @@ -69,7 +73,7 @@ public sealed partial class LangUpdatePage
public string ApplyUpdateDownloadSpeedPlaceholder { get; set; } = LangFallback?._UpdatePage.ApplyUpdateDownloadSpeedPlaceholder;
public string ApplyUpdateDownloadTimeEst { get; set; } = LangFallback?._UpdatePage.ApplyUpdateDownloadTimeEst;
public string ApplyUpdateDownloadTimeEstPlaceholder { get; set; } = LangFallback?._UpdatePage.ApplyUpdateDownloadTimeEstPlaceholder;

public string ApplyUpdateTaskLegacyVerFoundTitle { get; set; } = LangFallback?._UpdatePage.ApplyUpdateTaskLegacyVerFoundTitle;
public string ApplyUpdateTaskLegacyVerFoundSubtitle1 { get; set; } = LangFallback?._UpdatePage.ApplyUpdateTaskLegacyVerFoundSubtitle1;
public string ApplyUpdateTaskLegacyVerFoundSubtitle2 { get; set; } = LangFallback?._UpdatePage.ApplyUpdateTaskLegacyVerFoundSubtitle2;
Expand Down
4 changes: 4 additions & 0 deletions Hi3Helper.Core/Lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,10 @@

"ApplyUpdateErrCollapseRunTitle": "Please close Collapse before applying the update!",
"ApplyUpdateErrCollapseRunSubtitle": "Waiting for Collapse to close...",
"ApplyUpdateErrCollapseRunTitleWarnBox": "An Instance of Collapse Launcher is Still Running!",
"ApplyUpdateErrCollapseRunSubtitleWarnBox": "We detected an instance of Collapse Launcher is running in the background. To forcely close the launcher, click \"Yes\". To wait until you manually close it, click \"No\".",
"ApplyUpdateErrVelopackStateBrokenTitleWarnBox": "Broken Existing Installation Detected!",
"ApplyUpdateErrVelopackStateBrokenSubtitleWarnBox": "We detected that you have a broken existing installation.\r\n\r\nClick on \"Yes\" to repair the installation before installing updates or Click \"No\" to just run the update installation.",
"ApplyUpdateErrReleaseFileNotFoundTitle": "ERROR:\r\n\"release\" file doesn't have \"stable\" or \"preview\" string in it",
"ApplyUpdateErrReleaseFileNotFoundSubtitle": "Please check your \"release\" file and try again.",

Expand Down
Loading
Loading