Fixed DepotDownloader to make use of the latest ContentServerClient changes.

--HG--
extra : convert_revision : svn%3A946a0da7-ebce-4904-9acb-2f1e67aed693%40238
pull/8/head
Ryan Stecker 15 years ago
parent 391dbd9b8a
commit 3a8fbb363c

@ -73,13 +73,16 @@ namespace DepotDownloader
ContentServerClient csClient = new ContentServerClient(); ContentServerClient csClient = new ContentServerClient();
csClient.Connect( contentServer ); csClient.Connect( contentServer );
csClient.EnterStorageMode( ( uint )cellId );
uint storageId = csClient.OpenStorage( ( uint )depotId, ( uint )depotVersion, credentials );
if ( storageId == uint.MaxValue ) ContentServerClient.StorageSession session = null;
try
{
session = csClient.OpenStorage( ( uint )depotId, ( uint )depotVersion, ( uint )cellId );
}
catch ( Steam2Exception ex )
{ {
Console.WriteLine( "This depot requires valid user credentials and a license for this app" ); Console.WriteLine( "Unable to open storage: " + ex.Message );
if ( steam3 != null ) if ( steam3 != null )
steam3.Disconnect(); steam3.Disconnect();
@ -87,139 +90,141 @@ namespace DepotDownloader
return; return;
} }
Console.Write( "Downloading depot manifest..." ); using ( session )
{
Console.Write( "Downloading depot manifest..." );
byte[] manifestData = csClient.DownloadManifest( storageId );
File.WriteAllBytes( manifestFile, manifestData );
Console.WriteLine( " Done!" ); Manifest manifest = session.DownloadManifest();
byte[] manifestData = manifest.RawData;
Manifest manifest = new Manifest( manifestData ); File.WriteAllBytes( manifestFile, manifestData );
if ( onlyManifest ) Console.WriteLine( " Done!" );
File.Delete( txtManifest );
StringBuilder manifestBuilder = new StringBuilder(); if ( onlyManifest )
List<Regex> rgxList = new List<Regex>(); File.Delete( txtManifest );
if ( fileList != null ) StringBuilder manifestBuilder = new StringBuilder();
{ List<Regex> rgxList = new List<Regex>();
foreach ( string fileListentry in fileList )
if ( fileList != null )
{ {
try foreach ( string fileListentry in fileList )
{ {
Regex rgx = new Regex( fileListentry, RegexOptions.Compiled | RegexOptions.IgnoreCase ); try
rgxList.Add( rgx ); {
Regex rgx = new Regex( fileListentry, RegexOptions.Compiled | RegexOptions.IgnoreCase );
rgxList.Add( rgx );
}
catch { continue; }
} }
catch { continue; }
} }
}
for ( int x = 0 ; x < manifest.DirEntries.Count ; ++x )
{
Manifest.DirectoryEntry dirEntry = manifest.DirEntries[ x ];
string downloadPath = Path.Combine( downloadDir, dirEntry.FullName );
if ( onlyManifest ) for ( int x = 0 ; x < manifest.Nodes.Count ; ++x )
{ {
if ( dirEntry.FileID == -1 ) var dirEntry = manifest.Nodes[ x ];
continue;
manifestBuilder.Append( string.Format( "{0}\n", dirEntry.FullName ) );
continue;
}
if ( fileList != null ) string downloadPath = Path.Combine( downloadDir, dirEntry.FullName );
{
bool bMatched = false;
foreach ( string fileListEntry in fileList ) if ( onlyManifest )
{ {
if ( fileListEntry.Equals( dirEntry.FullName, StringComparison.OrdinalIgnoreCase ) ) if ( dirEntry.FileID == -1 )
{ continue;
bMatched = true;
break; manifestBuilder.Append( string.Format( "{0}\n", dirEntry.FullName ) );
} continue;
} }
if ( !bMatched ) if ( fileList != null )
{ {
foreach ( Regex rgx in rgxList ) bool bMatched = false;
{
Match m = rgx.Match( dirEntry.FullName );
if ( m.Success ) foreach ( string fileListEntry in fileList )
{
if ( fileListEntry.Equals( dirEntry.FullName, StringComparison.OrdinalIgnoreCase ) )
{ {
bMatched = true; bMatched = true;
break; break;
} }
} }
}
if ( !bMatched ) if ( !bMatched )
continue; {
foreach ( Regex rgx in rgxList )
{
Match m = rgx.Match( dirEntry.FullName );
string path = Path.GetDirectoryName( downloadPath ); if ( m.Success )
{
bMatched = true;
break;
}
}
}
if ( !Directory.Exists( path ) ) if ( !bMatched )
Directory.CreateDirectory( path ); continue;
}
if ( dirEntry.FileID == -1 ) string path = Path.GetDirectoryName( downloadPath );
{
if ( !Directory.Exists( downloadPath ) ) if ( !Directory.Exists( path ) )
{ Directory.CreateDirectory( path );
// this is a directory, so lets just create it
Directory.CreateDirectory( downloadPath );
} }
continue; if ( dirEntry.FileID == -1 )
} {
if ( !Directory.Exists( downloadPath ) )
{
// this is a directory, so lets just create it
Directory.CreateDirectory( downloadPath );
}
float perc = ( ( float )x / ( float )manifest.DirEntries.Count ) * 100.0f; continue;
Console.WriteLine( " {0:0.00}%\t{1}", perc, dirEntry.FullName ); }
FileInfo fi = new FileInfo( downloadPath ); float perc = ( ( float )x / ( float )manifest.Nodes.Count ) * 100.0f;
Console.WriteLine( " {0:0.00}%\t{1}", perc, dirEntry.FullName );
if ( fi.Exists && fi.Length == dirEntry.ItemSize ) FileInfo fi = new FileInfo( downloadPath );
continue;
ContentServerClient.File file = csClient.DownloadFile( storageId, dirEntry.FileID ); if ( fi.Exists && fi.Length == dirEntry.SizeOrCount )
continue;
if ( file.FileMode == 1 ) var file = session.DownloadFile( dirEntry, ContentServerClient.StorageSession.DownloadPriority.High );
{
// file is compressed if ( file.Mode == ContentServerClient.StorageSession.File.FileMode.Compressed )
using ( MemoryStream ms = new MemoryStream( file.Data ) )
using ( DeflateStream ds = new DeflateStream( ms, CompressionMode.Decompress ) )
{ {
// skip zlib header // file is compressed
ms.Seek( 2, SeekOrigin.Begin ); using ( MemoryStream ms = new MemoryStream( file.Data ) )
using ( DeflateStream ds = new DeflateStream( ms, CompressionMode.Decompress ) )
{
// skip zlib header
ms.Seek( 2, SeekOrigin.Begin );
byte[] inflated = new byte[ dirEntry.ItemSize ]; byte[] inflated = new byte[ dirEntry.SizeOrCount ];
ds.Read( inflated, 0, inflated.Length ); ds.Read( inflated, 0, inflated.Length );
file.Data = inflated; file.Data = inflated;
}
} }
} else
else {
{ Debug.Assert( false, string.Format(
Debug.Assert( false, string.Format( "Got file with unexpected filemode!\n" +
"Got file with unexpected filemode!\n" + "DepotID: {0}\nVersion: {1}\nFile: {2}\nMode: {3}\n",
"DepotID: {0}\nVersion: {1}\nFile: {2}\nMode: {3}\n", depotId, depotVersion, dirEntry.FullName, file.Mode
depotId, depotVersion, dirEntry.FullName, file.FileMode ) );
) ); }
File.WriteAllBytes( downloadPath, file.Data );
} }
File.WriteAllBytes( downloadPath, file.Data ); if ( onlyManifest )
File.WriteAllText( txtManifest, manifestBuilder.ToString() );
} }
if ( onlyManifest )
File.WriteAllText( txtManifest, manifestBuilder.ToString() );
csClient.CloseStorage( storageId );
csClient.ExitStorageMode();
csClient.Disconnect(); csClient.Disconnect();
if ( steam3 != null ) if ( steam3 != null )

Loading…
Cancel
Save