|
|
|
@ -73,13 +73,16 @@ namespace DepotDownloader
|
|
|
|
|
ContentServerClient csClient = new ContentServerClient();
|
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
|
steam3.Disconnect();
|
|
|
|
@ -87,139 +90,141 @@ namespace DepotDownloader
|
|
|
|
|
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 )
|
|
|
|
|
File.Delete( txtManifest );
|
|
|
|
|
Console.WriteLine( " Done!" );
|
|
|
|
|
|
|
|
|
|
StringBuilder manifestBuilder = new StringBuilder();
|
|
|
|
|
List<Regex> rgxList = new List<Regex>();
|
|
|
|
|
if ( onlyManifest )
|
|
|
|
|
File.Delete( txtManifest );
|
|
|
|
|
|
|
|
|
|
if ( fileList != null )
|
|
|
|
|
{
|
|
|
|
|
foreach ( string fileListentry in fileList )
|
|
|
|
|
StringBuilder manifestBuilder = new StringBuilder();
|
|
|
|
|
List<Regex> rgxList = new List<Regex>();
|
|
|
|
|
|
|
|
|
|
if ( fileList != null )
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
foreach ( string fileListentry in fileList )
|
|
|
|
|
{
|
|
|
|
|
Regex rgx = new Regex( fileListentry, RegexOptions.Compiled | RegexOptions.IgnoreCase );
|
|
|
|
|
rgxList.Add( rgx );
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
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 )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
manifestBuilder.Append( string.Format( "{0}\n", dirEntry.FullName ) );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
var dirEntry = manifest.Nodes[ x ];
|
|
|
|
|
|
|
|
|
|
if ( fileList != null )
|
|
|
|
|
{
|
|
|
|
|
bool bMatched = false;
|
|
|
|
|
string downloadPath = Path.Combine( downloadDir, dirEntry.FullName );
|
|
|
|
|
|
|
|
|
|
foreach ( string fileListEntry in fileList )
|
|
|
|
|
if ( onlyManifest )
|
|
|
|
|
{
|
|
|
|
|
if ( fileListEntry.Equals( dirEntry.FullName, StringComparison.OrdinalIgnoreCase ) )
|
|
|
|
|
{
|
|
|
|
|
bMatched = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ( dirEntry.FileID == -1 )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
manifestBuilder.Append( string.Format( "{0}\n", dirEntry.FullName ) );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !bMatched )
|
|
|
|
|
if ( fileList != null )
|
|
|
|
|
{
|
|
|
|
|
foreach ( Regex rgx in rgxList )
|
|
|
|
|
{
|
|
|
|
|
Match m = rgx.Match( dirEntry.FullName );
|
|
|
|
|
bool bMatched = false;
|
|
|
|
|
|
|
|
|
|
if ( m.Success )
|
|
|
|
|
foreach ( string fileListEntry in fileList )
|
|
|
|
|
{
|
|
|
|
|
if ( fileListEntry.Equals( dirEntry.FullName, StringComparison.OrdinalIgnoreCase ) )
|
|
|
|
|
{
|
|
|
|
|
bMatched = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !bMatched )
|
|
|
|
|
continue;
|
|
|
|
|
if ( !bMatched )
|
|
|
|
|
{
|
|
|
|
|
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 ) )
|
|
|
|
|
Directory.CreateDirectory( path );
|
|
|
|
|
}
|
|
|
|
|
if ( !bMatched )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if ( dirEntry.FileID == -1 )
|
|
|
|
|
{
|
|
|
|
|
if ( !Directory.Exists( downloadPath ) )
|
|
|
|
|
{
|
|
|
|
|
// this is a directory, so lets just create it
|
|
|
|
|
Directory.CreateDirectory( downloadPath );
|
|
|
|
|
string path = Path.GetDirectoryName( downloadPath );
|
|
|
|
|
|
|
|
|
|
if ( !Directory.Exists( path ) )
|
|
|
|
|
Directory.CreateDirectory( path );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
Console.WriteLine( " {0:0.00}%\t{1}", perc, dirEntry.FullName );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
|
continue;
|
|
|
|
|
FileInfo fi = new FileInfo( downloadPath );
|
|
|
|
|
|
|
|
|
|
ContentServerClient.File file = csClient.DownloadFile( storageId, dirEntry.FileID );
|
|
|
|
|
if ( fi.Exists && fi.Length == dirEntry.SizeOrCount )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if ( file.FileMode == 1 )
|
|
|
|
|
{
|
|
|
|
|
// file is compressed
|
|
|
|
|
using ( MemoryStream ms = new MemoryStream( file.Data ) )
|
|
|
|
|
using ( DeflateStream ds = new DeflateStream( ms, CompressionMode.Decompress ) )
|
|
|
|
|
var file = session.DownloadFile( dirEntry, ContentServerClient.StorageSession.DownloadPriority.High );
|
|
|
|
|
|
|
|
|
|
if ( file.Mode == ContentServerClient.StorageSession.File.FileMode.Compressed )
|
|
|
|
|
{
|
|
|
|
|
// skip zlib header
|
|
|
|
|
ms.Seek( 2, SeekOrigin.Begin );
|
|
|
|
|
// file is compressed
|
|
|
|
|
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 ];
|
|
|
|
|
ds.Read( inflated, 0, inflated.Length );
|
|
|
|
|
byte[] inflated = new byte[ dirEntry.SizeOrCount ];
|
|
|
|
|
ds.Read( inflated, 0, inflated.Length );
|
|
|
|
|
|
|
|
|
|
file.Data = inflated;
|
|
|
|
|
file.Data = inflated;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.Assert( false, string.Format(
|
|
|
|
|
"Got file with unexpected filemode!\n" +
|
|
|
|
|
"DepotID: {0}\nVersion: {1}\nFile: {2}\nMode: {3}\n",
|
|
|
|
|
depotId, depotVersion, dirEntry.FullName, file.FileMode
|
|
|
|
|
) );
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.Assert( false, string.Format(
|
|
|
|
|
"Got file with unexpected filemode!\n" +
|
|
|
|
|
"DepotID: {0}\nVersion: {1}\nFile: {2}\nMode: {3}\n",
|
|
|
|
|
depotId, depotVersion, dirEntry.FullName, file.Mode
|
|
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
if ( steam3 != null )
|
|
|
|
|