Skip to content

Commit 1687e43

Browse files
committed
Pre 3.1.8
- Fix DepotDownloader as Steam3 library was updated to .NET 9
1 parent 2b3decb commit 1687e43

28 files changed

+343
-235
lines changed

H1EmuLauncher/DepotDownloader/CDNClientPool.cs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Linq;
99
using System.Threading;
1010
using System.Threading.Tasks;
11-
using H1EmuLauncher;
1211
using SteamKit2.CDN;
1312

1413
namespace H1EmuLauncher

H1EmuLauncher/DepotDownloader/ContentDownloader.cs

+18-19
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@
55
using System.Buffers;
66
using System.Collections.Concurrent;
77
using System.Collections.Generic;
8+
using System.Diagnostics;
89
using System.IO;
910
using System.Linq;
1011
using System.Net;
1112
using System.Threading;
1213
using System.Threading.Tasks;
13-
using System.Windows;
1414
using SteamKit2;
1515
using SteamKit2.CDN;
16-
using H1EmuLauncher;
1716
using H1EmuLauncher.SteamFramePages;
18-
using System.Diagnostics;
1917

20-
namespace H1emuLauncher
18+
namespace H1EmuLauncher
2119
{
2220
class ContentDownloaderException(string value) : Exception(value)
2321
{
@@ -36,7 +34,7 @@ static class ContentDownloader
3634
private static CDNClientPool cdnPool;
3735

3836
public static string DEFAULT_DOWNLOAD_DIR = "depots";
39-
private const string CONFIG_DIR = ".DepotDownloader";
37+
private const string CONFIG_DIR = "DepotDownloader";
4038
private static readonly string STAGING_DIR = Path.Combine(CONFIG_DIR, "staging");
4139

4240
private sealed class DepotDownloadInfo(
@@ -60,11 +58,7 @@ static bool CreateDirectories(uint depotId, uint depotVersion, out string instal
6058
{
6159
Directory.CreateDirectory(DEFAULT_DOWNLOAD_DIR);
6260

63-
var depotPath = Path.Combine(DEFAULT_DOWNLOAD_DIR, depotId.ToString());
64-
Directory.CreateDirectory(depotPath);
65-
66-
installDir = Path.Combine(depotPath, depotVersion.ToString());
67-
Directory.CreateDirectory(installDir);
61+
installDir = DEFAULT_DOWNLOAD_DIR;
6862

6963
Directory.CreateDirectory(Path.Combine(installDir, CONFIG_DIR));
7064
Directory.CreateDirectory(Path.Combine(installDir, STAGING_DIR));
@@ -110,7 +104,7 @@ static bool TestIsFileIncluded(string filename)
110104
return false;
111105
}
112106

113-
static async Task<bool> AccountHasAccess(uint depotId)
107+
static async Task<bool> AccountHasAccess(uint appId, uint depotId)
114108
{
115109
if (steam3 == null || steam3.steamUser.SteamID == null || (steam3.Licenses == null && steam3.steamUser.SteamID.AccountType != EAccountType.AnonUser))
116110
return false;
@@ -139,6 +133,11 @@ static async Task<bool> AccountHasAccess(uint depotId)
139133
}
140134
}
141135

136+
// Check if this app is free to download without a license
137+
var info = GetSteam3AppSection(appId, EAppInfoSection.Common);
138+
if (info != null && info["FreeToDownload"].AsBoolean())
139+
return true;
140+
142141
return false;
143142
}
144143

@@ -367,7 +366,7 @@ public static async Task DownloadUGCAsync(uint appId, ulong ugcId)
367366
}
368367
else
369368
{
370-
await DownloadAppAsync(appId, new List<(uint, ulong)> { (appId, ugcId) }, DEFAULT_BRANCH, null, null, null, false, true);
369+
await DownloadAppAsync(appId, [(appId, ugcId)], DEFAULT_BRANCH, null, null, null, false, true);
371370
}
372371
}
373372

@@ -387,7 +386,7 @@ private static async Task DownloadWebFile(uint appId, string fileName, string ur
387386
Directory.CreateDirectory(Path.GetDirectoryName(fileStagingPath));
388387

389388
using (var file = File.OpenWrite(fileStagingPath))
390-
using (var client = H1EmuLauncher.HttpClientFactory.CreateHttpClient())
389+
using (var client = HttpClientFactory.CreateHttpClient())
391390
{
392391
Debug.WriteLine("Downloading {0}", fileName);
393392
var responseStream = await client.GetStreamAsync(url);
@@ -418,7 +417,7 @@ public static async Task DownloadAppAsync(uint appId, List<(uint depotId, ulong
418417

419418
await steam3?.RequestAppInfo(appId);
420419

421-
if (!await AccountHasAccess(appId))
420+
if (!await AccountHasAccess(appId, appId))
422421
{
423422
if (await steam3.RequestFreeAppLicense(appId))
424423
{
@@ -560,7 +559,7 @@ static async Task<DepotDownloadInfo> GetDepotInfo(uint depotId, uint appId, ulon
560559
await steam3.RequestAppInfo(appId);
561560
}
562561

563-
if (!await AccountHasAccess(depotId))
562+
if (!await AccountHasAccess(appId, depotId))
564563
{
565564
Debug.WriteLine("Depot {0} is not available from this account.", depotId);
566565

@@ -1048,7 +1047,7 @@ private static void DownloadSteam3AsyncDepotFile(
10481047
{
10491048
System.Windows.Application.Current.Dispatcher.Invoke(new Action(delegate
10501049
{
1051-
DownloadStatus.downloadStatusInstance.downloadProgressText.Text = $"{LauncherWindow.launcherInstance.FindResource("item57")} {file.FileName}";
1050+
DownloadStatus.downloadStatusInstance.downloadProgressText.Text = $"{LauncherWindow.launcherInstance.FindResource("item57")} {file.FileName.Substring(file.FileName.LastIndexOf("\\") + 1)}";
10521051
}));
10531052

10541053
Debug.WriteLine("Pre-allocating {0}", fileFinalPath);
@@ -1140,7 +1139,7 @@ private static void DownloadSteam3AsyncDepotFile(
11401139
fsOld.Seek((long)match.OldChunk.Offset, SeekOrigin.Begin);
11411140

11421141
var tmp = new byte[match.OldChunk.UncompressedLength];
1143-
fsOld.Read(tmp, 0, tmp.Length);
1142+
fsOld.ReadExactly(tmp);
11441143

11451144
fs.Seek((long)match.NewChunk.Offset, SeekOrigin.Begin);
11461145
fs.Write(tmp, 0, tmp.Length);
@@ -1388,7 +1387,7 @@ private static async Task DownloadSteam3AsyncDepotFileChunk(
13881387
System.Windows.Application.Current.Dispatcher.Invoke(new Action(delegate
13891388
{
13901389
DownloadStatus.downloadStatusInstance.downloadProgress.Value = sizeDownloaded / (float)depotDownloadCounter.completeDownloadSize * 100.0f;
1391-
DownloadStatus.downloadStatusInstance.downloadProgressText.Text = $"{LauncherWindow.launcherInstance.FindResource("item54")} {sizeDownloaded / (float)depotDownloadCounter.completeDownloadSize * 100.0f:0.00}% - {downloadSpeed:0.00} MB/s";
1390+
DownloadStatus.downloadStatusInstance.downloadProgressText.Text = $"{LauncherWindow.launcherInstance.FindResource("item54")} {sizeDownloaded / (float)depotDownloadCounter.completeDownloadSize * 100.0f:0.00}% - {downloadSpeed:0.00}MB/s";
13921391
LauncherWindow.launcherInstance.taskbarIcon.ProgressValue = sizeDownloaded / (float)depotDownloadCounter.completeDownloadSize;
13931392
}));
13941393
}
@@ -1430,7 +1429,7 @@ static void DumpManifestToTextFile(DepotDownloadInfo depot, ProtoManifest manife
14301429

14311430
foreach (var file in manifest.Files)
14321431
{
1433-
var sha1Hash = BitConverter.ToString(file.FileHash).Replace("-", "");
1432+
var sha1Hash = Convert.ToHexString(file.FileHash);
14341433
sw.WriteLine($"{file.TotalSize,14} {file.Chunks.Count,6} {sha1Hash} {file.Flags,5:D} {file.FileName}");
14351434
}
14361435
}

H1EmuLauncher/DepotDownloader/HttpDiagnosticEventListener.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// This file is subject to the terms and conditions defined
22
// in file 'LICENSE', which is part of this source code package.
33

4-
using System;
54
using System.Diagnostics;
65
using System.Diagnostics.Tracing;
76
using System.Text;

H1EmuLauncher/DepotDownloader/PlatformUtilities.cs

-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// This file is subject to the terms and conditions defined
22
// in file 'LICENSE', which is part of this source code package.
33

4-
using System;
54
using System.IO;
65
using System.Runtime.InteropServices;
7-
using System.Runtime.Versioning;
86

97
namespace H1EmuLauncher
108
{

H1EmuLauncher/DepotDownloader/Steam3Session.cs

+40-29
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
using System.Collections.Concurrent;
66
using System.Collections.Generic;
77
using System.Collections.ObjectModel;
8+
using System.Diagnostics;
89
using System.Linq;
910
using System.Threading;
1011
using System.Threading.Tasks;
12+
using QRCoder;
1113
using SteamKit2;
1214
using SteamKit2.Authentication;
1315
using SteamKit2.CDN;
1416
using SteamKit2.Internal;
15-
using H1emuLauncher;
16-
using H1EmuLauncher.Classes;
17-
using System.Diagnostics;
1817

1918
namespace H1EmuLauncher
2019
{
@@ -58,12 +57,10 @@ public ReadOnlyCollection<SteamApps.LicenseListCallback.License> Licenses
5857

5958
// input
6059
readonly SteamUser.LogOnDetails logonDetails;
61-
60+
public static string twoauth;
6261
public static CancellationTokenSource tokenSource = new();
6362
CancellationToken token;
6463

65-
public static string twoauth;
66-
6764
public Steam3Session(SteamUser.LogOnDetails details)
6865
{
6966
this.logonDetails = details;
@@ -96,7 +93,7 @@ public Steam3Session(SteamUser.LogOnDetails details)
9693

9794
public delegate bool WaitCondition();
9895

99-
private readonly object steamLock = new();
96+
private readonly Lock steamLock = new();
10097

10198
public bool WaitUntilCallback(Action submitter, WaitCondition waiter)
10299
{
@@ -231,9 +228,17 @@ public async Task RequestPackageInfo(IEnumerable<uint> packageIds)
231228

232229
public async Task<bool> RequestFreeAppLicense(uint appId)
233230
{
234-
var resultInfo = await steamApps.RequestFreeLicense(appId);
231+
try
232+
{
233+
var resultInfo = await steamApps.RequestFreeLicense(appId);
235234

236-
return resultInfo.GrantedApps.Contains(appId);
235+
return resultInfo.GrantedApps.Contains(appId);
236+
}
237+
catch (Exception ex)
238+
{
239+
Debug.WriteLine($"Failed to request FreeOnDemand license for app {appId}: {ex.Message}");
240+
return false;
241+
}
237242
}
238243

239244
public async Task RequestDepotKey(uint depotId, uint appid = 0)
@@ -243,11 +248,6 @@ public async Task RequestDepotKey(uint depotId, uint appid = 0)
243248

244249
var depotKey = await steamApps.GetDepotDecryptionKey(depotId, appid);
245250

246-
System.Windows.Application.Current.Dispatcher.Invoke(new Action(delegate
247-
{
248-
SteamFramePages.DownloadStatus.downloadStatusInstance.downloadProgressText.Text = $"{LauncherWindow.launcherInstance.FindResource("item21").ToString().Replace("{0}", $"{depotKey.DepotID}").Replace("{1}", $"{depotKey.Result}")}";
249-
}));
250-
251251
Debug.WriteLine("Got depot key for {0} result: {1}", depotKey.DepotID, depotKey.Result);
252252

253253
if (depotKey.Result != EResult.OK)
@@ -458,7 +458,12 @@ private async void ConnectedCallback(SteamClient.ConnectedCallback connected)
458458
{
459459
Debug.WriteLine("");
460460
Debug.WriteLine("The QR code has changed:");
461+
462+
DisplayQrCode(session.ChallengeURL);
461463
};
464+
465+
// Draw initial QR code immediately
466+
DisplayQrCode(session.ChallengeURL);
462467
}
463468
catch (TaskCanceledException)
464469
{
@@ -477,6 +482,12 @@ private async void ConnectedCallback(SteamClient.ConnectedCallback connected)
477482
{
478483
try
479484
{
485+
System.Windows.Application.Current.Dispatcher.Invoke(new Action(delegate
486+
{
487+
LauncherWindow.launcherInstance.steamFramePanel.Navigate(new Uri("..\\SteamFramePages\\2FA.xaml", UriKind.Relative));
488+
SteamFramePages._2FA.twoFacInstruction = 3;
489+
}));
490+
480491
var result = await authSession.PollingWaitForResultAsync();
481492

482493
logonDetails.Username = result.AccountName;
@@ -507,7 +518,7 @@ private async void ConnectedCallback(SteamClient.ConnectedCallback connected)
507518

508519
authSession = null;
509520
}
510-
521+
511522
steamUser.LogOn(logonDetails);
512523
}
513524
}
@@ -554,10 +565,6 @@ private void DisconnectedCallback(SteamClient.DisconnectedCallback disconnected)
554565

555566
private void LogOnCallback(SteamUser.LoggedOnCallback loggedOn)
556567
{
557-
tokenSource.Dispose();
558-
tokenSource = new CancellationTokenSource();
559-
token = tokenSource.Token;
560-
561568
var isSteamGuard = loggedOn.Result == EResult.AccountLogonDenied;
562569
var is2FA = loggedOn.Result == EResult.AccountLoginDeniedNeedTwoFactor;
563570
var isAccessToken = ContentDownloader.Config.RememberPassword && logonDetails.AccessToken != null &&
@@ -627,23 +634,15 @@ or EResult.Expired
627634

628635
if (loggedOn.Result == EResult.ServiceUnavailable)
629636
{
630-
System.Windows.Application.Current.Dispatcher.Invoke(new Action(delegate
631-
{
632-
LauncherWindow.launcherInstance.steamFramePanel.Navigate(new Uri("..\\SteamFramePages\\Login.xaml", UriKind.Relative));
633-
CustomMessageBox.Show(LauncherWindow.launcherInstance.FindResource("item17").ToString() + $" \"{loggedOn.Result}\".", LauncherWindow.launcherInstance);
634-
}));
637+
Debug.WriteLine("Unable to login to Steam3: {0}", loggedOn.Result);
635638
Abort(false);
636639

637640
return;
638641
}
639642

640643
if (loggedOn.Result != EResult.OK)
641644
{
642-
System.Windows.Application.Current.Dispatcher.Invoke(new Action(delegate
643-
{
644-
LauncherWindow.launcherInstance.steamFramePanel.Navigate(new Uri("..\\SteamFramePages\\Login.xaml", UriKind.Relative));
645-
CustomMessageBox.Show(LauncherWindow.launcherInstance.FindResource("item17").ToString() + $" \"{loggedOn.Result}\".", LauncherWindow.launcherInstance);
646-
}));
645+
Debug.WriteLine("Unable to login to Steam3: {0}", loggedOn.Result);
647646
Abort();
648647

649648
return;
@@ -682,5 +681,17 @@ private void LicenseListCallback(SteamApps.LicenseListCallback licenseList)
682681
}
683682
}
684683
}
684+
685+
private static void DisplayQrCode(string challengeUrl)
686+
{
687+
// Encode the link as a QR code
688+
using var qrGenerator = new QRCodeGenerator();
689+
var qrCodeData = qrGenerator.CreateQrCode(challengeUrl, QRCodeGenerator.ECCLevel.L);
690+
using var qrCode = new AsciiQRCode(qrCodeData);
691+
var qrCodeAsAsciiArt = qrCode.GetGraphic(1, drawQuietZones: false);
692+
693+
Debug.WriteLine("Use the Steam Mobile App to sign in with this QR code:");
694+
Debug.WriteLine(qrCodeAsAsciiArt);
695+
}
685696
}
686697
}

H1EmuLauncher/H1EmuLauncher.csproj

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
<UseWPF>true</UseWPF>
88
<UseWindowsForms>true</UseWindowsForms>
99
<ApplicationIcon>Icon.ico</ApplicationIcon>
10-
<FileVersion>3.1.7</FileVersion>
10+
<FileVersion>3.1.8</FileVersion>
1111
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1212
<Authors>H1Emu</Authors>
13-
<Version>3.1.7</Version>
13+
<Version>3.1.8</Version>
1414
<AssemblyName>H1EmuLauncher</AssemblyName>
1515
<SignAssembly>false</SignAssembly>
1616
<Copyright>© H1Emu</Copyright>
1717
<Product>H1Emu Launcher</Product>
1818
<Description>A launcher for the H1Emu project.</Description>
1919
<Title>H1Emu Launcher</Title>
2020
<PackageIcon>Icon.ico</PackageIcon>
21-
<AssemblyVersion>3.1.7</AssemblyVersion>
21+
<AssemblyVersion>3.1.8</AssemblyVersion>
2222
</PropertyGroup>
2323

2424
<ItemGroup>
@@ -115,6 +115,7 @@
115115

116116
<ItemGroup>
117117
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
118+
<PackageReference Include="QRCoder" Version="1.6.0" />
118119
<PackageReference Include="SteamKit2" Version="3.0.0" />
119120
</ItemGroup>
120121

H1EmuLauncher/Language/StringResources.bg-BG.xaml

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<system:String x:Key="item78">Моля, въведете двуфакторния код за удостоверяване, изпратен на вашето приложение Steam.</system:String>
7676
<system:String x:Key="item79">Моля, въведете двуфакторния код за удостоверяване, изпратен на вашия имейл.</system:String>
7777
<system:String x:Key="item80">Запазена конфигурация преди зареждане</system:String>
78+
<system:String x:Key="item81">Please approve the Steam login from your Steam mobile app.</system:String>
7879
<system:String x:Key="item84">Не можах да намеря никакви депа за изтегляне за приложение {0}</system:String>
7980
<system:String x:Key="item85">Депо {0} не е посочено за приложение {1}</system:String>
8081
<system:String x:Key="item89">Избраната директория не е празна.\n\nИзкате ли да продължите въпреки това?</system:String>
@@ -97,6 +98,7 @@
9798
<system:String x:Key="item114">Изтриване на стари файлове...</system:String>
9899
<system:String x:Key="item116">Разархивиране на сърварната информация...</system:String>
99100
<system:String x:Key="item118">Разархивиране node files...</system:String>
101+
<system:String x:Key="item119">Community Managers</system:String>
100102
<system:String x:Key="item120">Моля затворете H1Z1.</system:String>
101103
<system:String x:Key="item121">H1Z1.exe се използва.\n\nЗатворете всички отворени прозорци на H1Z1.\n\nМожете да използвате бутона по-долу, за да убиете всички процеси на H1Z1.</system:String>
102104
<system:String x:Key="item122">Сегашна версия на играта: 2016</system:String>

H1EmuLauncher/Language/StringResources.de-DE.xaml

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<system:String x:Key="item78">Bitte geben Sie den Zwei-Faktor-Authentifizierungscode ein, der an Ihre Steam-App gesendet wurde.</system:String>
7676
<system:String x:Key="item79">Bitte geben Sie den Zwei-Faktor-Authentifizierungscode ein, der an Ihre E-Mail gesendet wurde.</system:String>
7777
<system:String x:Key="item80">Installationsdatei kann nicht heruntergeladen werden:</system:String>
78+
<system:String x:Key="item81">Please approve the Steam login from your Steam mobile app.</system:String>
7879
<system:String x:Key="item84">Es konnten keine Depots zum Herunterladen für die App gefunden werden {0}</system:String>
7980
<system:String x:Key="item85">Depot {0} nicht für die App gelistet {1}</system:String>
8081
<system:String x:Key="item89">Das ausgewählte Verzeichnis ist nicht leer.\n\nMöchten Sie trotzdem fortfahren?</system:String>
@@ -97,6 +98,7 @@
9798
<system:String x:Key="item114">Entferne alte Dateien...</system:String>
9899
<system:String x:Key="item116">Entpacke Serverdatei...</system:String>
99100
<system:String x:Key="item118">Entpacke node Dateien...</system:String>
101+
<system:String x:Key="item119">Community Managers</system:String>
100102
<system:String x:Key="item120">Bitte schließe H1Z1.</system:String>
101103
<system:String x:Key="item121">H1Z1.exe wird gerade verwendet\n\nBitte schließen Sie alle offenen Instanzen von H1Z1.\n\nSie können die Schaltfläche unten verwenden, um alle Prozesse von H1Z1 zu beenden.</system:String>
102104
<system:String x:Key="item122">Aktuelle Spielversion: 2016</system:String>

0 commit comments

Comments
 (0)