Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
SeRi0uS007 committed Sep 2, 2023
1 parent e20e7fd commit 0370357
Show file tree
Hide file tree
Showing 11 changed files with 1,238 additions and 0 deletions.
25 changes: 25 additions & 0 deletions SteamAccountDataFetcher.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33829.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SteamAccountDataFetcher", "SteamAccountDataFetcher\SteamAccountDataFetcher.csproj", "{C92C7AAB-EDCC-49B8-81F5-537F72B6477F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C92C7AAB-EDCC-49B8-81F5-537F72B6477F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C92C7AAB-EDCC-49B8-81F5-537F72B6477F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C92C7AAB-EDCC-49B8-81F5-537F72B6477F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C92C7AAB-EDCC-49B8-81F5-537F72B6477F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2FB4C9BB-D08A-46C5-B95F-2BC39B542136}
EndGlobalSection
EndGlobal
175 changes: 175 additions & 0 deletions SteamAccountDataFetcher/FSAgent/ReadCSVAgent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
using System.Collections;

namespace SteamAccountDataFetcher.FSAgent;

internal record AccountLoginInfo(string Username, string Password, string SharedSecret);

internal class ReadCSVAgent : IList<AccountLoginInfo>, IDisposable
{
private const string HEADER = "AccountLogin;AccountPassword;SharedSecret";

private string FilePath { get; init; }

private List<AccountLoginInfo> _accountLoginList;

internal ReadCSVAgent(string path)
{
if (string.IsNullOrEmpty(path))
{
var msg = $"{nameof(path)} is empty.";
Logger.Log(msg, Logger.Level.Error);
throw new ArgumentException(msg);
}

if (!Path.Exists(path))
{
var msg = $"{nameof(path)} file not exists.";
Logger.Log(msg, Logger.Level.Error);
throw new ArgumentException(msg);
}

_accountLoginList = new();
FilePath = path;

using (StreamReader reader = new StreamReader(path))
{
if (reader.EndOfStream)
{
var msg = $"{nameof(path)} file is empty.";
Logger.Log(msg, Logger.Level.Error);
throw new ArgumentException(msg);
}

string? header = reader.ReadLine();
if (string.IsNullOrEmpty(header) || header != HEADER)
{
var msg = $"{nameof(path)} file is invalid.";
Logger.Log(msg, Logger.Level.Error);
throw new ArgumentException(msg);
}

int lineIndex = 1;
while (!reader.EndOfStream)
{
var dataLine = reader.ReadLine();
if (string.IsNullOrEmpty(dataLine))
{
Logger.Log($"{nameof(path)} file in line {lineIndex} is empty.");
++lineIndex;
continue;
}

var data = dataLine.Split(';');
if (data == null || data.Length != 3)
{
Logger.Log($"{nameof(path)} file in line {lineIndex} is invalid.");
++lineIndex;
continue;
}

var username = data[0];
var password = data[1];
var sharedSecret = data[2];

if (string.IsNullOrEmpty(username))
{
Logger.Log($"{nameof(path)} file in line {lineIndex} component {nameof(username)} is invalid.");
++lineIndex;
continue;
}
if (string.IsNullOrEmpty(password))
{
Logger.Log($"{nameof(path)} file in line {lineIndex} component {nameof(password)} is invalid.");
++lineIndex;
continue;
}
if (string.IsNullOrEmpty(sharedSecret))
{
Logger.Log($"{nameof(path)} file in line {lineIndex} component {nameof(sharedSecret)} is invalid.");
++lineIndex;
continue;
}

_accountLoginList.Add(new(username, password, sharedSecret));
++lineIndex;
}

if (Count == 0)
{
var msg = $"{nameof(path)} all data lines are invalid.";
Logger.Log(msg, Logger.Level.Error);
throw new ArgumentException(msg);
}
}
}

internal void WriteCache()
{
using (StreamWriter writer = new(FilePath, false))
{
writer.WriteLine(HEADER);

foreach(AccountLoginInfo accountInfo in _accountLoginList)
writer.WriteLine($"{accountInfo.Username};{accountInfo.Password};{accountInfo.SharedSecret}");
}
}

public AccountLoginInfo this[int index]
{
get => _accountLoginList[index];
set
{
_accountLoginList[index] = value;
WriteCache();
}
}

public int Count => _accountLoginList.Count;

public bool IsReadOnly => ((IList<AccountLoginInfo>)_accountLoginList).IsReadOnly;

public void Add(AccountLoginInfo item)
{
_accountLoginList.Add(item);
WriteCache();
}

public void Clear()
{
_accountLoginList.Clear();
WriteCache();
}

public bool Contains(AccountLoginInfo item) => _accountLoginList.Contains(item);

public void CopyTo(AccountLoginInfo[] array, int arrayIndex) => _accountLoginList.CopyTo(array, arrayIndex);

public IEnumerator<AccountLoginInfo> GetEnumerator() => _accountLoginList.GetEnumerator();

public int IndexOf(AccountLoginInfo item) => _accountLoginList.IndexOf(item);

public void Insert(int index, AccountLoginInfo item)
{
_accountLoginList.Insert(index, item);
WriteCache();
}

public bool Remove(AccountLoginInfo item)
{
var success = _accountLoginList.Remove(item);
if (success)
WriteCache();

return success;
}

public void RemoveAt(int index)
{
_accountLoginList.RemoveAt(index);
WriteCache();
}

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public void Dispose() => WriteCache();
}
113 changes: 113 additions & 0 deletions SteamAccountDataFetcher/FSAgent/WriteJSONAgent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System.Collections;
using System.Text.Json;

namespace SteamAccountDataFetcher.FSAgent;

internal class WriteJSONAgent : IList<SteamDataClient.SteamDataClient.ResponseData>
{
private string FilePath { get; init; }

private List<SteamDataClient.SteamDataClient.ResponseData> _accountDataList;
private static readonly JsonSerializerOptions _jsonSerializerOptions = new()
{
WriteIndented = true
};

internal WriteJSONAgent(string path)
{
if (string.IsNullOrEmpty(path))
{
var msg = $"{nameof(path)} is empty.";
Logger.Log(msg, Logger.Level.Error);
throw new ArgumentException(msg);
}

FilePath = path;

if (!Path.Exists(path))
{
_accountDataList = new();
return;
}

try
{
using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
{
var cachedType = JsonSerializer.Deserialize<List<SteamDataClient.SteamDataClient.ResponseData>?>(file);
if (cachedType == null)
{
_accountDataList = new();
return;
}
_accountDataList = cachedType;
return;
}
} catch (JsonException)
{
_accountDataList = new();
return;
}

}

private void WriteCache()
{
using (FileStream file = new FileStream(FilePath, FileMode.Create, FileAccess.Write))
JsonSerializer.Serialize(file, _accountDataList, _jsonSerializerOptions);
}

public SteamDataClient.SteamDataClient.ResponseData this[int index]
{
get => _accountDataList[index];
set => _accountDataList[index] = value;
}

public int Count => _accountDataList.Count;

public bool IsReadOnly =>
((IList<SteamDataClient.SteamDataClient.ResponseData>)_accountDataList).IsReadOnly;

public int IndexOf(SteamDataClient.SteamDataClient.ResponseData item) => _accountDataList.IndexOf(item);

public void Insert(int index, SteamDataClient.SteamDataClient.ResponseData item)
{
_accountDataList.Insert(index, item);
WriteCache();
}

public void RemoveAt(int index)
{
_accountDataList.RemoveAt(index);
WriteCache();
}

public void Add(SteamDataClient.SteamDataClient.ResponseData item)
{
_accountDataList.Add(item);
WriteCache();
}

public void Clear()
{
_accountDataList.Clear();
WriteCache();
}

public bool Contains(SteamDataClient.SteamDataClient.ResponseData item) => _accountDataList.Contains(item);

public void CopyTo(SteamDataClient.SteamDataClient.ResponseData[] array, int arrayIndex) => _accountDataList.CopyTo(array, arrayIndex);

public bool Remove(SteamDataClient.SteamDataClient.ResponseData item)
{
var success = _accountDataList.Remove(item);
if (success)
WriteCache();

return success;
}

public IEnumerator<SteamDataClient.SteamDataClient.ResponseData> GetEnumerator() => _accountDataList.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
25 changes: 25 additions & 0 deletions SteamAccountDataFetcher/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace SteamAccountDataFetcher;

internal static class Logger
{
public enum Level
{
Debug,
Info,
Warning,
Error
}

internal static void Log(string message, Level level = Level.Info, [CallerMemberName] string callerName = "")
{
string timeString = DateTime.Now.ToString("dd.MM.yy - HH:mm:ss.ff");
Console.WriteLine($"|{level}| [{timeString}] ({callerName}) -> {message}");
}
}
32 changes: 32 additions & 0 deletions SteamAccountDataFetcher/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using SteamAccountDataFetcher.SteamDataClient;
using SteamAccountDataFetcher.FSAgent;

namespace SteamAccountDataFetcher;

public class Program
{
public static async Task Main()
{
ReadCSVAgent csvAccounts;
try
{
csvAccounts = new ReadCSVAgent(Configuration.ReadCSVFilePath);
} catch (Exception e)
{
Logger.Log($"Unable to read CSV file, {e.Message}", Logger.Level.Error);
return;
}
var jsonAccounts = new WriteJSONAgent(Configuration.WriteJSONFilePath);

while (csvAccounts.Count > 0)
{
AccountLoginInfo account = csvAccounts.First();

SteamDataClient.SteamDataClient steamDataClient = new(account.Username, account.Password, account.SharedSecret);
SteamDataClient.SteamDataClient.ResponseData data = await steamDataClient.GetResponseDataAsync();

jsonAccounts.Add(data);
csvAccounts.Remove(account);
}
}
}
20 changes: 20 additions & 0 deletions SteamAccountDataFetcher/SteamAccountDataFetcher.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0-windows7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
<Title>Steam Account Data Fetcher</Title>
<Authors>Andrii Lavrenko</Authors>
<Description>Utility for collecting Steam account information</Description>
<Copyright>Andrii Lavrenko</Copyright>
<Version>1.0.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SteamKit2" Version="2.4.1" />
</ItemGroup>

</Project>
Loading

0 comments on commit 0370357

Please sign in to comment.