Extracted code to library in .net standard

pull/143/head
Raphael Guntersweiler 5 years ago
parent a6d30efade
commit ee560060f6

@ -8,10 +8,10 @@ using System.Linq;
using SteamKit2; using SteamKit2;
using SteamKit2.Discovery; using SteamKit2.Discovery;
namespace DepotDownloader namespace DepotDownloader.Core
{ {
[ProtoContract] [ProtoContract]
class AccountSettingsStore public class AccountSettingsStore
{ {
[ProtoMember(1, IsRequired=false)] [ProtoMember(1, IsRequired=false)]
public Dictionary<string, byte[]> SentryData { get; private set; } public Dictionary<string, byte[]> SentryData { get; private set; }

@ -7,12 +7,12 @@ using System.Net;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace DepotDownloader namespace DepotDownloader.Core
{ {
/// <summary> /// <summary>
/// CDNClientPool provides a pool of connections to CDN endpoints, requesting CDN tokens as needed /// CDNClientPool provides a pool of connections to CDN endpoints, requesting CDN tokens as needed
/// </summary> /// </summary>
class CDNClientPool public class CDNClientPool
{ {
private const int ServerEndpointMinimumSize = 8; private const int ServerEndpointMinimumSize = 8;

@ -4,7 +4,7 @@ using ProtoBuf;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
namespace DepotDownloader namespace DepotDownloader.Core
{ {
[ProtoContract] [ProtoContract]
class DepotConfigStore class DepotConfigStore

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="protobuf-net" Version="3.0.52" />
<PackageReference Include="SteamKit2" Version="2.3.0" />
</ItemGroup>
</Project>

@ -1,33 +1,33 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace DepotDownloader namespace DepotDownloader.Core
{ {
class DownloadConfig public class DownloadConfig
{ {
public int CellID { get; set; } public int CellID { get; set; }
public bool DownloadAllPlatforms { get; set; } public bool DownloadAllPlatforms { get; set; }
public bool DownloadAllLanguages { get; set; } public bool DownloadAllLanguages { get; set; }
public bool DownloadManifestOnly { get; set; } public bool DownloadManifestOnly { get; set; }
public string InstallDirectory { get; set; } public string InstallDirectory { get; set; }
public bool UsingFileList { get; set; } public bool UsingFileList { get; set; }
public List<string> FilesToDownload { get; set; } public List<string> FilesToDownload { get; set; }
public List<Regex> FilesToDownloadRegex { get; set; } public List<Regex> FilesToDownloadRegex { get; set; }
public bool UsingExclusionList { get; set; } public bool UsingExclusionList { get; set; }
public string BetaPassword { get; set; } public string BetaPassword { get; set; }
public bool VerifyAll { get; set; } public bool VerifyAll { get; set; }
public int MaxServers { get; set; } public int MaxServers { get; set; }
public int MaxDownloads { get; set; } public int MaxDownloads { get; set; }
public string SuppliedPassword { get; set; } public string SuppliedPassword { get; set; }
public bool RememberPassword { get; set; } public bool RememberPassword { get; set; }
// A Steam LoginID to allow multiple concurrent connections // A Steam LoginID to allow multiple concurrent connections
public uint? LoginID {get; set; } public uint? LoginID {get; set; }
} }
} }

@ -6,10 +6,10 @@ using System.IO.Compression;
using ProtoBuf; using ProtoBuf;
using SteamKit2; using SteamKit2;
namespace DepotDownloader namespace DepotDownloader.Core
{ {
[ProtoContract()] [ProtoContract()]
class ProtoManifest public class ProtoManifest
{ {
// Proto ctor // Proto ctor
private ProtoManifest() private ProtoManifest()

@ -1,136 +1,136 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
namespace DepotDownloader namespace DepotDownloader.Core
{ {
static class Util public static class Util
{ {
public static string GetSteamOS() public static string GetSteamOS()
{ {
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{ {
return "windows"; return "windows";
} }
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{ {
return "macos"; return "macos";
} }
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{ {
return "linux"; return "linux";
} }
return "unknown"; return "unknown";
} }
public static string GetSteamArch() public static string GetSteamArch()
{ {
return Environment.Is64BitOperatingSystem ? "64" : "32"; return Environment.Is64BitOperatingSystem ? "64" : "32";
} }
public static string ReadPassword() public static string ReadPassword()
{ {
ConsoleKeyInfo keyInfo; ConsoleKeyInfo keyInfo;
StringBuilder password = new StringBuilder(); StringBuilder password = new StringBuilder();
do do
{ {
keyInfo = Console.ReadKey( true ); keyInfo = Console.ReadKey( true );
if ( keyInfo.Key == ConsoleKey.Backspace ) if ( keyInfo.Key == ConsoleKey.Backspace )
{ {
if ( password.Length > 0 ) if ( password.Length > 0 )
password.Remove( password.Length - 1, 1 ); password.Remove( password.Length - 1, 1 );
continue; continue;
} }
/* Printable ASCII characters only */ /* Printable ASCII characters only */
char c = keyInfo.KeyChar; char c = keyInfo.KeyChar;
if ( c >= ' ' && c <= '~' ) if ( c >= ' ' && c <= '~' )
password.Append( c ); password.Append( c );
} while ( keyInfo.Key != ConsoleKey.Enter ); } while ( keyInfo.Key != ConsoleKey.Enter );
return password.ToString(); return password.ToString();
} }
// Validate a file against Steam3 Chunk data // Validate a file against Steam3 Chunk data
public static List<ProtoManifest.ChunkData> ValidateSteam3FileChecksums(FileStream fs, ProtoManifest.ChunkData[] chunkdata) public static List<ProtoManifest.ChunkData> ValidateSteam3FileChecksums(FileStream fs, ProtoManifest.ChunkData[] chunkdata)
{ {
var neededChunks = new List<ProtoManifest.ChunkData>(); var neededChunks = new List<ProtoManifest.ChunkData>();
int read; int read;
foreach (var data in chunkdata) foreach (var data in chunkdata)
{ {
byte[] chunk = new byte[data.UncompressedLength]; byte[] chunk = new byte[data.UncompressedLength];
fs.Seek((long)data.Offset, SeekOrigin.Begin); fs.Seek((long)data.Offset, SeekOrigin.Begin);
read = fs.Read(chunk, 0, (int)data.UncompressedLength); read = fs.Read(chunk, 0, (int)data.UncompressedLength);
byte[] tempchunk; byte[] tempchunk;
if (read < data.UncompressedLength) if (read < data.UncompressedLength)
{ {
tempchunk = new byte[read]; tempchunk = new byte[read];
Array.Copy(chunk, 0, tempchunk, 0, read); Array.Copy(chunk, 0, tempchunk, 0, read);
} }
else else
{ {
tempchunk = chunk; tempchunk = chunk;
} }
byte[] adler = AdlerHash(tempchunk); byte[] adler = AdlerHash(tempchunk);
if (!adler.SequenceEqual(data.Checksum)) if (!adler.SequenceEqual(data.Checksum))
{ {
neededChunks.Add(data); neededChunks.Add(data);
} }
} }
return neededChunks; return neededChunks;
} }
public static byte[] AdlerHash(byte[] input) public static byte[] AdlerHash(byte[] input)
{ {
uint a = 0, b = 0; uint a = 0, b = 0;
for (int i = 0; i < input.Length; i++) for (int i = 0; i < input.Length; i++)
{ {
a = (a + input[i]) % 65521; a = (a + input[i]) % 65521;
b = (b + a) % 65521; b = (b + a) % 65521;
} }
return BitConverter.GetBytes(a | (b << 16)); return BitConverter.GetBytes(a | (b << 16));
} }
public static byte[] SHAHash( byte[] input ) public static byte[] SHAHash( byte[] input )
{ {
using (var sha = SHA1.Create()) using (var sha = SHA1.Create())
{ {
var output = sha.ComputeHash( input ); var output = sha.ComputeHash( input );
return output; return output;
} }
} }
public static byte[] DecodeHexString( string hex ) public static byte[] DecodeHexString( string hex )
{ {
if ( hex == null ) if ( hex == null )
return null; return null;
int chars = hex.Length; int chars = hex.Length;
byte[] bytes = new byte[ chars / 2 ]; byte[] bytes = new byte[ chars / 2 ];
for ( int i = 0 ; i < chars ; i += 2 ) for ( int i = 0 ; i < chars ; i += 2 )
bytes[ i / 2 ] = Convert.ToByte( hex.Substring( i, 2 ), 16 ); bytes[ i / 2 ] = Convert.ToByte( hex.Substring( i, 2 ), 16 );
return bytes; return bytes;
} }
public static string EncodeHexString( byte[] input ) public static string EncodeHexString( byte[] input )
{ {
return input.Aggregate( new StringBuilder(), return input.Aggregate( new StringBuilder(),
( sb, v ) => sb.Append( v.ToString( "x2" ) ) ( sb, v ) => sb.Append( v.ToString( "x2" ) )
).ToString(); ).ToString();
} }
} }
} }

@ -1,9 +1,11 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio Version 16
VisualStudioVersion = 15.0.26228.4 VisualStudioVersion = 16.0.30517.126
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DepotDownloader", "DepotDownloader\DepotDownloader.csproj", "{39159C47-ACD3-449F-96CA-4F30C8ED147A}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DepotDownloader", "DepotDownloader\DepotDownloader.csproj", "{39159C47-ACD3-449F-96CA-4F30C8ED147A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DepotDownloader.Core", "DepotDownloader.Core\DepotDownloader.Core.csproj", "{8303B6A1-CE40-4C26-9376-DB08290645F7}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,8 +17,15 @@ Global
{39159C47-ACD3-449F-96CA-4F30C8ED147A}.Debug|Any CPU.Build.0 = Debug|Any CPU {39159C47-ACD3-449F-96CA-4F30C8ED147A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39159C47-ACD3-449F-96CA-4F30C8ED147A}.Release|Any CPU.ActiveCfg = Release|Any CPU {39159C47-ACD3-449F-96CA-4F30C8ED147A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39159C47-ACD3-449F-96CA-4F30C8ED147A}.Release|Any CPU.Build.0 = Release|Any CPU {39159C47-ACD3-449F-96CA-4F30C8ED147A}.Release|Any CPU.Build.0 = Release|Any CPU
{8303B6A1-CE40-4C26-9376-DB08290645F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8303B6A1-CE40-4C26-9376-DB08290645F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8303B6A1-CE40-4C26-9376-DB08290645F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8303B6A1-CE40-4C26-9376-DB08290645F7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B9D19618-4471-4B6A-999B-3884575BE066}
EndGlobalSection
EndGlobal EndGlobal

@ -1,11 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="protobuf-net" Version="3.0.24" /> <ProjectReference Include="..\DepotDownloader.Core\DepotDownloader.Core.csproj" />
<PackageReference Include="SteamKit2" Version="2.3.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -6,6 +6,8 @@ using SteamKit2;
using System.ComponentModel; using System.ComponentModel;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using DepotDownloader.Core;
namespace DepotDownloader namespace DepotDownloader
{ {
class Program class Program

Loading…
Cancel
Save