@ -576,7 +576,7 @@ namespace DepotDownloader
{
var clientIndex = rand . Next ( 0 , cdnClients . Count ) ;
string download_p ath = Path . Combine ( depot . installDir , file . FileName ) ;
string fileFinalP ath = Path . Combine ( depot . installDir , file . FileName ) ;
string fileStagingPath = Path . Combine ( stagingDir , file . FileName ) ;
// This may still exist if the previous run exited before cleanup
@ -587,11 +587,12 @@ namespace DepotDownloader
FileStream fs = null ;
List < DepotManifest . ChunkData > neededChunks ;
FileInfo fi = new FileInfo ( download_p ath) ;
FileInfo fi = new FileInfo ( fileFinalP ath) ;
if ( ! fi . Exists )
{
// create new file. need all chunks
fs = File . Create ( download_path ) ;
fs = File . Create ( fileFinalPath ) ;
fs . SetLength ( ( long ) file . TotalSize ) ;
neededChunks = new List < DepotManifest . ChunkData > ( file . Chunks ) ;
}
else
@ -607,7 +608,9 @@ namespace DepotDownloader
{
neededChunks = new List < DepotManifest . ChunkData > ( ) ;
// we have a version of this file. it may or may not match what we want
if ( oldManifestFile . FileHash ! = file . FileHash )
{
// we have a version of this file, but it doesn't fully match what we want
var matchingChunks = new List < ChunkMatch > ( ) ;
@ -624,14 +627,9 @@ namespace DepotDownloader
}
}
// can't use FileHash here. It doesn't seem to actually change...
if ( matchingChunks . Count ! = file . Chunks . Count )
{
if ( File . Exists ( download_path ) )
{
File . Move ( download_path , fileStagingPath ) ;
File . Move ( fileFinalPath , fileStagingPath ) ;
fs = File . Open ( download_p ath, FileMode . Create ) ;
fs = File . Open ( fileFinalPath , FileMode . Create ) ;
fs . SetLength ( ( long ) file . TotalSize ) ;
using ( var fsOld = File . Open ( fileStagingPath , FileMode . Open ) )
@ -649,30 +647,24 @@ namespace DepotDownloader
File . Delete ( fileStagingPath ) ;
}
else
{
fs = File . Open ( download_path , FileMode . Create ) ;
fs . SetLength ( ( long ) file . TotalSize ) ;
neededChunks = new List < DepotManifest . ChunkData > ( file . Chunks ) ;
}
}
}
else
{
fs = File . Open ( download_path , FileMode . Open ) ;
// No old manifest or file not in old manifest. We must validate.
fs = File . Open ( fileFinalPath , FileMode . Open ) ;
if ( ( ulong ) fi . Length ! = file . TotalSize )
{
fs . SetLength ( ( long ) file . TotalSize ) ;
}
// find which chunks we need, in order so that we aren't seeking every which way
neededChunks = Util . ValidateSteam3FileChecksums ( fs , file . Chunks . OrderBy ( x = > x . Offset ) . ToArray ( ) ) ;
}
if ( neededChunks . Count ( ) = = 0 )
{
size_downloaded + = file . TotalSize ;
Console . WriteLine ( "{0,6:#00.00}% {1}" , ( ( float ) size_downloaded / ( float ) complete_download_size ) * 100.0f , download_p ath) ;
Console . WriteLine ( "{0,6:#00.00}% {1}" , ( ( float ) size_downloaded / ( float ) complete_download_size ) * 100.0f , fileFinalP ath) ;
if ( fs ! = null )
fs . Close ( ) ;
return ;
@ -725,7 +717,7 @@ namespace DepotDownloader
fs . Close ( ) ;
Console . WriteLine ( "{0,6:#00.00}% {1}" , ( ( float ) size_downloaded / ( float ) complete_download_size ) * 100.0f , download_p ath) ;
Console . WriteLine ( "{0,6:#00.00}% {1}" , ( ( float ) size_downloaded / ( float ) complete_download_size ) * 100.0f , fileFinalP ath) ;
} ) ;
newProtoManifest . SaveToFile ( Path . Combine ( configDir , string . Format ( "{0}.bin" , depot . id ) ) ) ;