Skip to content

Commit ded4902

Browse files
authored
Preview 1.82.10 Hotfix (#644)
# What's new? - 1.82.10 - **[Fix]** ``NullReferenceException`` crash caused by null ``voice_packs`` property, by @neon-nyan - **[Fix]** Some migration dialog still provides install choices, by @neon-nyan - **[Fix]** TimeSpan overflow + Number to Percentage and TimeSpan converter refactor, by @neon-nyan and @bagusnl - **[Fix]** Minor Audio Selection UI bug, by @neon-nyan - **[Fix]** More ``SharingViolation`` exceptions on ``InstallManagerBase``, by @neon-nyan - **[Fix]** ``DirectoryNotFoundException`` on HSR's Game Repair -> ``RemoveHashMarkFile()`` method, by @neon-nyan - **[Fix]** Relative URL for the Velopack packages getting cut-off, by @neon-nyan <details> <summary>Changelog Prefixes</summary> ``` **[New]** **[Imp]** **[Fix]** **[Loc]** **[Doc]** ``` </details>
2 parents e334415 + 98f7955 commit ded4902

File tree

19 files changed

+297
-248
lines changed

19 files changed

+297
-248
lines changed

CollapseLauncher/Classes/Helper/StreamUtility.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,19 @@ internal static FileInfo EnsureNoReadOnly(this FileInfo fileInfo)
5454

5555
internal static FileInfo EnsureNoReadOnly(this FileInfo fileInfo, out bool isFileExist)
5656
{
57-
if (!(isFileExist = fileInfo.Exists))
58-
return fileInfo;
57+
try
58+
{
59+
if (!(isFileExist = fileInfo.Exists))
60+
return fileInfo;
5961

60-
fileInfo.IsReadOnly = false;
62+
fileInfo.IsReadOnly = false;
6163

62-
return fileInfo;
64+
return fileInfo;
65+
}
66+
finally
67+
{
68+
fileInfo.Refresh();
69+
}
6370
}
6471

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

114-
if (directoryInfo is { Exists: false })
115-
directoryInfo.Create();
121+
try
122+
{
123+
if (directoryInfo is { Exists: false })
124+
directoryInfo.Create();
116125

117-
return filePath;
126+
return filePath;
127+
}
128+
finally
129+
{
130+
filePath.Refresh();
131+
}
118132
}
119133
}
120134
}

CollapseLauncher/Classes/InstallManagement/BaseClass/InstallManagerBase.cs

Lines changed: 78 additions & 99 deletions
Large diffs are not rendered by default.

CollapseLauncher/Classes/InstallManagement/GameConversionManagement.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,12 @@ public ConvertProgress(long StartSize, long EndSize, int StartCount, int EndCoun
461461
public long EndSize { get; private set; }
462462
public int StartCount { get; private set; }
463463
public int EndCount { get; private set; }
464-
public double Percentage => UseCountUnit ? Math.Round((StartCount / (double)EndCount) * 100, 2) :
465-
Math.Round((StartSize / (double)EndSize) * 100, 2);
466-
public long ProgressSpeed => (long)(StartSize / _TimeSecond);
467-
public TimeSpan RemainingTime => UseCountUnit ? TimeSpan.FromSeconds(0f) :
468-
((EndSize - StartSize) / Unzeroed(ProgressSpeed)).ToTimeSpanNormalized();
469-
private double Unzeroed(double i) => i == 0 ? 1 : i;
464+
public double Percentage => UseCountUnit ? ToPercentage(EndCount, StartCount) :
465+
ToPercentage(EndSize, StartSize);
466+
public double ProgressSpeed => StartSize / _TimeSecond;
467+
public TimeSpan RemainingTime => UseCountUnit ? TimeSpan.Zero :
468+
ToTimeSpanRemain(EndSize, StartSize, ProgressSpeed);
469+
470470
public string ProgressStatus => _StatusMsg;
471471
public string ProgressDetail => string.Format(
472472
"[{0}] ({1})\r\n{2}...",

CollapseLauncher/Classes/Interfaces/Class/ProgressBase.cs

Lines changed: 99 additions & 82 deletions
Large diffs are not rendered by default.

CollapseLauncher/Classes/Interfaces/Class/Structs.cs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,22 @@ namespace CollapseLauncher
99
{
1010
internal class TotalPerFileProgress
1111
{
12-
private double _progressPerFilePercentage;
13-
private double _progressPerFileSpeed;
14-
private double _progressAllPercentage;
15-
private double _progressAllSpeed;
16-
private long _progressPerFileEntryCountCurrent;
17-
private long _progressPerFileEntryCountTotal;
18-
private long _progressAllEntryCountCurrent;
19-
private long _progressAllEntryCountTotal;
20-
21-
public double ProgressPerFilePercentage { get => _progressPerFilePercentage; set => _progressPerFilePercentage = value.UnNaNInfinity(); }
22-
public double ProgressPerFileSpeed { get => _progressPerFileSpeed; set => _progressPerFileSpeed = value.UnNaNInfinity(); }
23-
public double ProgressAllPercentage { get => _progressAllPercentage; set => _progressAllPercentage = value.UnNaNInfinity(); }
24-
public double ProgressAllSpeed { get => _progressAllSpeed; set => _progressAllSpeed = value.UnNaNInfinity(); }
25-
26-
public long ProgressPerFileEntryCountCurrent { get => _progressPerFileEntryCountCurrent; set => _progressPerFileEntryCountCurrent = value; }
27-
public long ProgressPerFileEntryCountTotal { get => _progressPerFileEntryCountTotal; set => _progressPerFileEntryCountTotal = value; }
28-
public long ProgressAllEntryCountCurrent { get => _progressAllEntryCountCurrent; set => _progressAllEntryCountCurrent = value; }
29-
public long ProgressAllEntryCountTotal { get => _progressAllEntryCountTotal; set => _progressAllEntryCountTotal = value; }
12+
public double ProgressPerFilePercentage;
13+
public double ProgressPerFileSpeed;
14+
public double ProgressAllPercentage;
15+
public double ProgressAllSpeed;
16+
17+
public long ProgressPerFileEntryCountCurrent;
18+
public long ProgressPerFileEntryCountTotal;
19+
public long ProgressAllEntryCountCurrent;
20+
public long ProgressAllEntryCountTotal;
3021

3122
// Extension for IGameInstallManager
32-
public double ProgressPerFileSizeCurrent { get; set; }
33-
public double ProgressPerFileSizeTotal { get; set; }
34-
public double ProgressAllSizeCurrent { get; set; }
35-
public double ProgressAllSizeTotal { get; set; }
36-
public TimeSpan ProgressAllTimeLeft { get; set; }
23+
public long ProgressPerFileSizeCurrent;
24+
public long ProgressPerFileSizeTotal;
25+
public long ProgressAllSizeCurrent;
26+
public long ProgressAllSizeTotal;
27+
public TimeSpan ProgressAllTimeLeft;
3728
}
3829

3930
internal class TotalPerFileStatus

CollapseLauncher/Classes/RegionManagement/FallbackCDNUtil.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ public async Task DownloadFile(string url,
5454
try
5555
{
5656
FallbackCDNUtil.DownloadProgress += progressEvent;
57+
string relativePath = GetRelativePathOnly(url);
5758
await FallbackCDNUtil.DownloadCDNFallbackContent(downloadClient, targetFile, AppCurrentDownloadThread,
58-
GetRelativePathOnly(url),
59+
relativePath,
5960
#if !USEVELOPACK
60-
default
61+
default
6162
#else
6263
cancelToken
6364
#endif
@@ -80,7 +81,8 @@ public async Task<byte[]> DownloadBytes(string url, string authorization = null,
8081
public async Task<byte[]> DownloadBytes(string url, string? authorization = null, string? accept = null, double timeout = 30.0)
8182
#endif
8283
{
83-
await using BridgedNetworkStream stream = await FallbackCDNUtil.TryGetCDNFallbackStream(GetRelativePathOnly(url), default, true);
84+
string relativePath = GetRelativePathOnly(url);
85+
await using BridgedNetworkStream stream = await FallbackCDNUtil.TryGetCDNFallbackStream(relativePath, default, true);
8486
byte[] buffer = new byte[stream.Length];
8587
await stream.ReadExactlyAsync(buffer);
8688
return buffer;
@@ -92,16 +94,33 @@ public async Task<string> DownloadString(string url, string authorization = null
9294
public async Task<string> DownloadString(string url, string? authorization = null, string? accept = null, double timeout = 30.0)
9395
#endif
9496
{
95-
await using BridgedNetworkStream stream = await FallbackCDNUtil.TryGetCDNFallbackStream(GetRelativePathOnly(url), default, true);
97+
string relativePath = GetRelativePathOnly(url);
98+
await using BridgedNetworkStream stream = await FallbackCDNUtil.TryGetCDNFallbackStream(relativePath, default, true);
9699
byte[] buffer = new byte[stream.Length];
97100
await stream.ReadExactlyAsync(buffer);
98101
return Encoding.UTF8.GetString(buffer);
99102
}
100103

104+
private string[]? CdnBaseUrls;
101105
private string GetRelativePathOnly(string url)
102106
{
103-
string toCompare = FallbackCDNUtil.GetPreferredCDN().URLPrefix;
104-
return url.AsSpan(toCompare.Length).ToString();
107+
// Populate the CDN Base URLs if the field is null
108+
CdnBaseUrls ??= CDNList.Select(x => x.URLPrefix).ToArray();
109+
110+
// Get URL span and iterate through the CDN Base URLs
111+
ReadOnlySpan<char> urlSpan = url.AsSpan();
112+
for (int i = 0; i < CdnBaseUrls.Length; i++)
113+
{
114+
// Get the index of the base URL. If not found (-1), then continue
115+
int indexOf = urlSpan.IndexOf(CdnBaseUrls[i], StringComparison.OrdinalIgnoreCase);
116+
if (indexOf < 0) continue;
117+
118+
// Otherwise, slice the urlSpan based on the index and return the sliced relative URL.
119+
return urlSpan.Slice(indexOf + CdnBaseUrls[i].Length).ToString();
120+
}
121+
122+
// If it's not a CDN-based url, return it anyway.
123+
return url;
105124
}
106125
}
107126

CollapseLauncher/Classes/RepairManagement/BSDiff.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,17 +414,17 @@ public BinaryPatchProgress()
414414

415415
public void UpdatePatchEvent(long sizePatched, long sizeToBePatched, long read, double totalSecond)
416416
{
417-
this.Speed = (sizePatched / totalSecond);
417+
this.Speed = sizePatched / totalSecond;
418418
this.SizePatched = sizePatched;
419419
this.SizeToBePatched = sizeToBePatched;
420420
this.Read = read;
421421
}
422422

423423
public long SizePatched { get; private set; }
424424
public long SizeToBePatched { get; private set; }
425-
public double ProgressPercentage => Math.Round((SizePatched / (double)SizeToBePatched) * 100, 2);
425+
public double ProgressPercentage => ConverterTool.ToPercentage(SizeToBePatched, SizePatched);
426426
public long Read { get; private set; }
427427
public double Speed { get; private set; }
428-
public TimeSpan TimeLeft => checked(((SizeToBePatched - SizePatched) / Speed.Unzeroed()).ToTimeSpanNormalized());
428+
public TimeSpan TimeLeft => ConverterTool.ToTimeSpanRemain(SizeToBePatched, SizePatched, Speed);
429429
}
430430
}

CollapseLauncher/Classes/RepairManagement/Genshin/Fetch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ private void _httpClient_FetchManifestAssetProgress(int read, DownloadProgress d
588588
lock (_progress)
589589
{
590590
_progress.ProgressPerFilePercentage =
591-
GetPercentageNumber(downloadProgress.BytesDownloaded, downloadProgress.BytesTotal);
591+
ToPercentage(downloadProgress.BytesTotal, downloadProgress.BytesDownloaded);
592592
}
593593

594594
// Push status and progress update

CollapseLauncher/Classes/RepairManagement/StarRail/Check.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Hi3Helper;
1+
using CollapseLauncher.Helper;
2+
using Hi3Helper;
23
using Hi3Helper.Data;
34
using Hi3Helper.SentryHelper;
45
using Hi3Helper.Shared.ClassStruct;
@@ -389,10 +390,18 @@ private static void RemoveHashMarkFile(string filePath, out string basePath, out
389390
basePath = Path.GetDirectoryName(filePath);
390391
baseName = Path.GetFileNameWithoutExtension(filePath);
391392

393+
// Get directory base info. If it doesn't exist, return
394+
DirectoryInfo basePathDirInfo = new DirectoryInfo(basePath);
395+
if (!basePathDirInfo.Exists)
396+
{
397+
return;
398+
}
399+
392400
// Enumerate any possible existing hash path and delete it
393-
foreach (string existingPath in Directory.EnumerateFiles(basePath!, $"{baseName}_*.hash"))
401+
foreach (FileInfo existingPath in basePathDirInfo.EnumerateFiles($"{baseName}_*.hash")
402+
.EnumerateNoReadOnly())
394403
{
395-
File.Delete(existingPath);
404+
existingPath.Delete();
396405
}
397406
}
398407
#endregion

CollapseLauncher/CollapseLauncher.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<Authors>$(Company). neon-nyan, Cry0, bagusnl, shatyuka, gablm.</Authors>
1717
<Copyright>Copyright 2022-2024 $(Company)</Copyright>
1818
<!-- Versioning -->
19-
<Version>1.82.9</Version>
19+
<Version>1.82.10</Version>
2020
<LangVersion>preview</LangVersion>
2121
<!-- Target Settings -->
2222
<Platforms>x64</Platforms>

0 commit comments

Comments
 (0)