Skip to content

Commit

Permalink
Rewrite logic and output format; 2.0.0 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
SeRi0uS007 committed Sep 30, 2023
1 parent 55591e8 commit 2ba2ca5
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 191 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ login3;password3;sharedSecret3
Someday in the future. After I have used it, I write down a list of things to do.

- Add proxy support to speed up data collection;
- Finalize the configuration code;
- Сross-platform releases.
- Finalize the configuration code.
81 changes: 18 additions & 63 deletions SteamAccountDataFetcher/FSAgent/WriteJSONAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@

namespace SteamAccountDataFetcher.FSAgent;

internal class WriteJSONAgent : IList<ResponseData>
internal class WriteJSONAgent
{
public class OutMapper
{
public List<PackageInfo> PackagesInfo { get; set; } = new();
public List<AccountInfo> AccountsInfo { get; set; } = new();
}

private string FilePath { get; init; }

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

internal List<PackageInfo> PackageInfos { get => _outMapper.PackagesInfo; }
internal List<AccountInfo> AccountsInfo { get => _outMapper.AccountsInfo; }

internal WriteJSONAgent(string path)
{
if (string.IsNullOrEmpty(path))
Expand All @@ -27,88 +36,34 @@ internal WriteJSONAgent(string path)

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

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

}

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

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

public int Count => _accountDataList.Count;

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

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

public void Insert(int index, ResponseData item)
public void AddAccount(AccountInfo item)
{
_accountDataList.Insert(index, item);
_outMapper.AccountsInfo.Add(item);
WriteCache();
}

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

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

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

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

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

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

return success;
}

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

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
6 changes: 4 additions & 2 deletions SteamAccountDataFetcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ public static async Task Main()
}
var jsonAccounts = new WriteJSONAgent(Configuration.WriteJSONFilePath);

Client.LoadPackagesCache(jsonAccounts.PackageInfos);

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

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

jsonAccounts.Add(data);
jsonAccounts.AddAccount(data);
csvAccounts.Remove(account);
}
}
Expand Down
5 changes: 2 additions & 3 deletions SteamAccountDataFetcher/SteamAccountDataFetcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0-windows7.0</TargetFramework>
<TargetFramework>net7.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.1.0</Version>
<Version>2.0.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
16 changes: 16 additions & 0 deletions SteamAccountDataFetcher/SteamDataClient/AccountInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace SteamAccountDataFetcher.SteamDataClient;

public class AccountInfo
{
public class PackageInfo
{
public uint PackageId { get; set; } = 0;
public long RegistrationTime { get; set; } = 0;
}
public string Username { get; set; } = string.Empty;
public ulong SteamId { get; set; } = 0;
public List<PackageInfo> Packages { get; set; } = new();
public bool IsLimited { get; set; }
public bool IsBanned { get; set; }
public string ApiKey { get; set; } = string.Empty;
}
Loading

0 comments on commit 2ba2ca5

Please sign in to comment.