5
5
using System . Buffers ;
6
6
using System . Collections . Concurrent ;
7
7
using System . Collections . Generic ;
8
+ using System . Diagnostics ;
8
9
using System . IO ;
9
10
using System . Linq ;
10
11
using System . Net ;
11
12
using System . Threading ;
12
13
using System . Threading . Tasks ;
13
- using System . Windows ;
14
14
using SteamKit2 ;
15
15
using SteamKit2 . CDN ;
16
- using H1EmuLauncher ;
17
16
using H1EmuLauncher . SteamFramePages ;
18
- using System . Diagnostics ;
19
17
20
- namespace H1emuLauncher
18
+ namespace H1EmuLauncher
21
19
{
22
20
class ContentDownloaderException ( string value ) : Exception ( value )
23
21
{
@@ -36,7 +34,7 @@ static class ContentDownloader
36
34
private static CDNClientPool cdnPool ;
37
35
38
36
public static string DEFAULT_DOWNLOAD_DIR = "depots" ;
39
- private const string CONFIG_DIR = ". DepotDownloader" ;
37
+ private const string CONFIG_DIR = "DepotDownloader" ;
40
38
private static readonly string STAGING_DIR = Path . Combine ( CONFIG_DIR , "staging" ) ;
41
39
42
40
private sealed class DepotDownloadInfo (
@@ -60,11 +58,7 @@ static bool CreateDirectories(uint depotId, uint depotVersion, out string instal
60
58
{
61
59
Directory . CreateDirectory ( DEFAULT_DOWNLOAD_DIR ) ;
62
60
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 ;
68
62
69
63
Directory . CreateDirectory ( Path . Combine ( installDir , CONFIG_DIR ) ) ;
70
64
Directory . CreateDirectory ( Path . Combine ( installDir , STAGING_DIR ) ) ;
@@ -110,7 +104,7 @@ static bool TestIsFileIncluded(string filename)
110
104
return false ;
111
105
}
112
106
113
- static async Task < bool > AccountHasAccess ( uint depotId )
107
+ static async Task < bool > AccountHasAccess ( uint appId , uint depotId )
114
108
{
115
109
if ( steam3 == null || steam3 . steamUser . SteamID == null || ( steam3 . Licenses == null && steam3 . steamUser . SteamID . AccountType != EAccountType . AnonUser ) )
116
110
return false ;
@@ -139,6 +133,11 @@ static async Task<bool> AccountHasAccess(uint depotId)
139
133
}
140
134
}
141
135
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
+
142
141
return false ;
143
142
}
144
143
@@ -367,7 +366,7 @@ public static async Task DownloadUGCAsync(uint appId, ulong ugcId)
367
366
}
368
367
else
369
368
{
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 ) ;
371
370
}
372
371
}
373
372
@@ -387,7 +386,7 @@ private static async Task DownloadWebFile(uint appId, string fileName, string ur
387
386
Directory . CreateDirectory ( Path . GetDirectoryName ( fileStagingPath ) ) ;
388
387
389
388
using ( var file = File . OpenWrite ( fileStagingPath ) )
390
- using ( var client = H1EmuLauncher . HttpClientFactory . CreateHttpClient ( ) )
389
+ using ( var client = HttpClientFactory . CreateHttpClient ( ) )
391
390
{
392
391
Debug . WriteLine ( "Downloading {0}" , fileName ) ;
393
392
var responseStream = await client . GetStreamAsync ( url ) ;
@@ -418,7 +417,7 @@ public static async Task DownloadAppAsync(uint appId, List<(uint depotId, ulong
418
417
419
418
await steam3 ? . RequestAppInfo ( appId ) ;
420
419
421
- if ( ! await AccountHasAccess ( appId ) )
420
+ if ( ! await AccountHasAccess ( appId , appId ) )
422
421
{
423
422
if ( await steam3 . RequestFreeAppLicense ( appId ) )
424
423
{
@@ -560,7 +559,7 @@ static async Task<DepotDownloadInfo> GetDepotInfo(uint depotId, uint appId, ulon
560
559
await steam3 . RequestAppInfo ( appId ) ;
561
560
}
562
561
563
- if ( ! await AccountHasAccess ( depotId ) )
562
+ if ( ! await AccountHasAccess ( appId , depotId ) )
564
563
{
565
564
Debug . WriteLine ( "Depot {0} is not available from this account." , depotId ) ;
566
565
@@ -1048,7 +1047,7 @@ private static void DownloadSteam3AsyncDepotFile(
1048
1047
{
1049
1048
System . Windows . Application . Current . Dispatcher . Invoke ( new Action ( delegate
1050
1049
{
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 ) } ";
1052
1051
} ) ) ;
1053
1052
1054
1053
Debug . WriteLine ( "Pre-allocating {0}" , fileFinalPath ) ;
@@ -1140,7 +1139,7 @@ private static void DownloadSteam3AsyncDepotFile(
1140
1139
fsOld . Seek ( ( long ) match . OldChunk . Offset , SeekOrigin . Begin ) ;
1141
1140
1142
1141
var tmp = new byte [ match . OldChunk . UncompressedLength ] ;
1143
- fsOld . Read ( tmp , 0 , tmp . Length ) ;
1142
+ fsOld . ReadExactly ( tmp ) ;
1144
1143
1145
1144
fs . Seek ( ( long ) match . NewChunk . Offset , SeekOrigin . Begin ) ;
1146
1145
fs . Write ( tmp , 0 , tmp . Length ) ;
@@ -1388,7 +1387,7 @@ private static async Task DownloadSteam3AsyncDepotFileChunk(
1388
1387
System . Windows . Application . Current . Dispatcher . Invoke ( new Action ( delegate
1389
1388
{
1390
1389
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";
1392
1391
LauncherWindow . launcherInstance . taskbarIcon . ProgressValue = sizeDownloaded / ( float ) depotDownloadCounter . completeDownloadSize ;
1393
1392
} ) ) ;
1394
1393
}
@@ -1430,7 +1429,7 @@ static void DumpManifestToTextFile(DepotDownloadInfo depot, ProtoManifest manife
1430
1429
1431
1430
foreach ( var file in manifest . Files )
1432
1431
{
1433
- var sha1Hash = BitConverter . ToString ( file . FileHash ) . Replace ( "-" , "" ) ;
1432
+ var sha1Hash = Convert . ToHexString ( file . FileHash ) ;
1434
1433
sw . WriteLine ( $ "{ file . TotalSize , 14 } { file . Chunks . Count , 6 } { sha1Hash } { file . Flags , 5 : D} { file . FileName } ") ;
1435
1434
}
1436
1435
}
0 commit comments