Compare commits
No commits in common. "fdc2e0277fed8e0a3cafccc344976560611d8dde" and "950844a14ba7fa693e22165100f288314fa934ec" have entirely different histories.
fdc2e0277f
...
950844a14b
@ -9,8 +9,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AngleSharp" Version="0.14.0" />
|
||||
<PackageReference Include="LiteDB" Version="5.0.10" />
|
||||
<PackageReference Include="LiteDB.Async" Version="0.0.8" />
|
||||
<PackageReference Include="MvvmCross" Version="7.1.2" />
|
||||
<PackageReference Include="NinjaNye.SearchExtensions" Version="3.0.1" />
|
||||
<PackageReference Include="SharpCompress" Version="0.26.0" />
|
||||
|
@ -1,278 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace GoldbergGUI.Core.Models
|
||||
{
|
||||
public class GoldbergGlobalConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the user
|
||||
/// </summary>
|
||||
public string AccountName { get; set; }
|
||||
/// <summary>
|
||||
/// Steam64ID of the user
|
||||
/// </summary>
|
||||
public long UserSteamId { get; set; }
|
||||
/// <summary>
|
||||
/// language to be used
|
||||
/// </summary>
|
||||
public string Language { get; set; }
|
||||
/// <summary>
|
||||
/// Custom broadcast addresses (IPv4 or domain addresses)
|
||||
/// </summary>
|
||||
public List<string> CustomBroadcastIps { get; set; }
|
||||
}
|
||||
public class GoldbergConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// App ID of the game
|
||||
/// </summary>
|
||||
public int AppId { get; set; }
|
||||
/// <summary>
|
||||
/// List of DLC
|
||||
/// </summary>
|
||||
public List<SteamApp> DlcList { get; set; }
|
||||
|
||||
public List<Depot> Depots { get; set; }
|
||||
|
||||
public List<Group> SubscribedGroups { get; set; }
|
||||
|
||||
public List<AppPath> AppPaths { get; set; }
|
||||
|
||||
public List<Achievement> Achievements { get; set; }
|
||||
|
||||
public List<Item> Items { get; set; }
|
||||
|
||||
public List<Leaderboard> Leaderboards { get; set; }
|
||||
|
||||
public List<Stat> Stats { get; set; }
|
||||
|
||||
// Add controller setting here!
|
||||
/// <summary>
|
||||
/// Set offline mode.
|
||||
/// </summary>
|
||||
public bool Offline { get; set; }
|
||||
/// <summary>
|
||||
/// Disable networking (game is set to online, however all outgoing network connectivity will be disabled).
|
||||
/// </summary>
|
||||
public bool DisableNetworking { get; set; }
|
||||
/// <summary>
|
||||
/// Disable overlay (experimental only).
|
||||
/// </summary>
|
||||
public bool DisableOverlay { get; set; }
|
||||
|
||||
public GoldbergGlobalConfiguration OverwrittenGlobalConfiguration { get; set; }
|
||||
}
|
||||
|
||||
public class Depot
|
||||
{
|
||||
/// <summary>
|
||||
/// ID of Depot.
|
||||
/// </summary>
|
||||
public int DepotId { get; set; }
|
||||
/// <summary>
|
||||
/// Name of Depot.
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// Associated DLC App ID, can be null (e.g. if Depot is for base game).
|
||||
/// </summary>
|
||||
public int DlcAppId { get; set; }
|
||||
}
|
||||
|
||||
public class Group
|
||||
{
|
||||
/// <summary>
|
||||
/// ID of group (https://steamcommunity.com/gid/103582791433980119/memberslistxml/?xml=1).
|
||||
/// </summary>
|
||||
public int GroupId { get; set; }
|
||||
/// <summary>
|
||||
/// Name of group.
|
||||
/// </summary>
|
||||
public string GroupName { get; set; }
|
||||
/// <summary>
|
||||
/// App ID of game associated with group (https://steamcommunity.com/games/218620/memberslistxml/?xml=1).
|
||||
/// </summary>
|
||||
public int AppId { get; set; }
|
||||
}
|
||||
|
||||
public class AppPath
|
||||
{
|
||||
public int AppId { get; set; }
|
||||
public string Path { get; set; }
|
||||
}
|
||||
|
||||
public class Achievement
|
||||
{
|
||||
/// <summary>
|
||||
/// Achievement description.
|
||||
/// </summary>
|
||||
[JsonPropertyName("description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Human readable name, as shown on webpage, game libary, overlay, etc.
|
||||
/// </summary>
|
||||
[JsonPropertyName("displayName")]
|
||||
public string DisplayName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Is achievement hidden? 0 = false, else true.
|
||||
/// </summary>
|
||||
[JsonPropertyName("hidden")]
|
||||
public int Hidden { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Path to icon when unlocked (colored).
|
||||
/// </summary>
|
||||
[JsonPropertyName("icon")]
|
||||
public string Icon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Path to icon when locked (grayed out).
|
||||
/// </summary>
|
||||
[JsonPropertyName("icongray")]
|
||||
public string IconGray { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Internal name.
|
||||
/// </summary>
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
public class Item
|
||||
{
|
||||
[JsonPropertyName("Timestamp")]
|
||||
public DateTimeOffset Timestamp { get; set; }
|
||||
|
||||
[JsonPropertyName("modified")]
|
||||
public string Modified { get; set; }
|
||||
|
||||
[JsonPropertyName("date_created")]
|
||||
public string DateCreated { get; set; }
|
||||
|
||||
[JsonPropertyName("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
[JsonPropertyName("display_type")]
|
||||
public string DisplayType { get; set; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonPropertyName("bundle")]
|
||||
public string Bundle { get; set; }
|
||||
|
||||
[JsonPropertyName("description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
[JsonPropertyName("background_color")]
|
||||
public string BackgroundColor { get; set; }
|
||||
|
||||
[JsonPropertyName("icon_url")]
|
||||
public Uri IconUrl { get; set; }
|
||||
|
||||
[JsonPropertyName("icon_url_large")]
|
||||
public Uri IconUrlLarge { get; set; }
|
||||
|
||||
[JsonPropertyName("name_color")]
|
||||
public string NameColor { get; set; }
|
||||
|
||||
[JsonPropertyName("tradable")]
|
||||
// [JsonConverter(typeof(PurpleParseStringConverter))]
|
||||
public bool Tradable { get; set; }
|
||||
|
||||
[JsonPropertyName("marketable")]
|
||||
// [JsonConverter(typeof(PurpleParseStringConverter))]
|
||||
public bool Marketable { get; set; }
|
||||
|
||||
[JsonPropertyName("commodity")]
|
||||
// [JsonConverter(typeof(PurpleParseStringConverter))]
|
||||
public bool Commodity { get; set; }
|
||||
|
||||
[JsonPropertyName("drop_interval")]
|
||||
// [JsonConverter(typeof(FluffyParseStringConverter))]
|
||||
public long DropInterval { get; set; }
|
||||
|
||||
[JsonPropertyName("drop_max_per_window")]
|
||||
// [JsonConverter(typeof(FluffyParseStringConverter))]
|
||||
public long DropMaxPerWindow { get; set; }
|
||||
|
||||
[JsonPropertyName("workshopid")]
|
||||
// [JsonConverter(typeof(FluffyParseStringConverter))]
|
||||
public long Workshopid { get; set; }
|
||||
|
||||
[JsonPropertyName("tw_unique_to_own")]
|
||||
// [JsonConverter(typeof(PurpleParseStringConverter))]
|
||||
public bool TwUniqueToOwn { get; set; }
|
||||
|
||||
[JsonPropertyName("item_quality")]
|
||||
// [JsonConverter(typeof(FluffyParseStringConverter))]
|
||||
public long ItemQuality { get; set; }
|
||||
|
||||
[JsonPropertyName("tw_price")]
|
||||
public string TwPrice { get; set; }
|
||||
|
||||
[JsonPropertyName("tw_type")]
|
||||
public string TwType { get; set; }
|
||||
|
||||
[JsonPropertyName("tw_client_visible")]
|
||||
// [JsonConverter(typeof(FluffyParseStringConverter))]
|
||||
public long TwClientVisible { get; set; }
|
||||
|
||||
[JsonPropertyName("tw_icon_small")]
|
||||
public string TwIconSmall { get; set; }
|
||||
|
||||
[JsonPropertyName("tw_icon_large")]
|
||||
public string TwIconLarge { get; set; }
|
||||
|
||||
[JsonPropertyName("tw_description")]
|
||||
public string TwDescription { get; set; }
|
||||
|
||||
[JsonPropertyName("tw_client_name")]
|
||||
public string TwClientName { get; set; }
|
||||
|
||||
[JsonPropertyName("tw_client_type")]
|
||||
public string TwClientType { get; set; }
|
||||
|
||||
[JsonPropertyName("tw_rarity")]
|
||||
public string TwRarity { get; set; }
|
||||
}
|
||||
|
||||
public class Leaderboard
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public SortMethod SortMethodSetting { get; set; }
|
||||
public DisplayType DisplayTypeSetting { get; set; }
|
||||
|
||||
public enum SortMethod
|
||||
{
|
||||
None,
|
||||
Ascending,
|
||||
Descending
|
||||
}
|
||||
public enum DisplayType
|
||||
{
|
||||
None,
|
||||
Numeric,
|
||||
TimeSeconds,
|
||||
TimeMilliseconds
|
||||
}
|
||||
}
|
||||
|
||||
public class Stat
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public StatType StatTypeSetting { get; set; }
|
||||
public string Value { get; set; }
|
||||
|
||||
public enum StatType
|
||||
{
|
||||
Int,
|
||||
Float,
|
||||
AvgRate
|
||||
}
|
||||
}
|
||||
}
|
@ -17,9 +17,6 @@ namespace GoldbergGUI.Core.Models
|
||||
private string _comparableName;
|
||||
[JsonPropertyName("appid")] public int AppId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of Steam app
|
||||
/// </summary>
|
||||
[JsonPropertyName("name")]
|
||||
public string Name
|
||||
{
|
||||
@ -31,14 +28,8 @@ namespace GoldbergGUI.Core.Models
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Trimmed and cleaned name of Steam app, used for comparisons.
|
||||
/// </summary>
|
||||
public bool CompareName(string value) => _comparableName.Equals(value);
|
||||
|
||||
/// <summary>
|
||||
/// App type (Game, DLC, ...)
|
||||
/// </summary>
|
||||
public AppType type { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
|
@ -5,6 +5,7 @@ using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using GoldbergGUI.Core.Models;
|
||||
using GoldbergGUI.Core.Utils;
|
||||
@ -23,8 +24,8 @@ namespace GoldbergGUI.Core.Services
|
||||
public Task<GoldbergGlobalConfiguration> GetGlobalSettings();
|
||||
public Task SetGlobalSettings(GoldbergGlobalConfiguration configuration);
|
||||
public bool GoldbergApplied(string path);
|
||||
// public Task<bool> Download();
|
||||
// public Task Extract(string archivePath);
|
||||
public Task<bool> Download();
|
||||
public Task Extract(string archivePath);
|
||||
public Task GenerateInterfacesFile(string filePath);
|
||||
public List<string> Languages();
|
||||
}
|
||||
@ -33,10 +34,8 @@ namespace GoldbergGUI.Core.Services
|
||||
public class GoldbergService : IGoldbergService
|
||||
{
|
||||
private IMvxLog _log;
|
||||
private const string DefaultAccountName = "Mr_Goldberg";
|
||||
private const long DefaultSteamId = 76561197960287930;
|
||||
private const string DefaultLanguage = "english";
|
||||
private const string GoldbergUrl = "https://mr_goldberg.gitlab.io/goldberg_emulator/";
|
||||
private const string DefaultLanguage = "english";
|
||||
private readonly string _goldbergZipPath = Path.Combine(Directory.GetCurrentDirectory(), "goldberg.zip");
|
||||
private readonly string _goldbergPath = Path.Combine(Directory.GetCurrentDirectory(), "goldberg");
|
||||
|
||||
@ -47,9 +46,7 @@ namespace GoldbergGUI.Core.Services
|
||||
private readonly string _accountNamePath = Path.Combine(GlobalSettingsPath, "settings/account_name.txt");
|
||||
private readonly string _userSteamIdPath = Path.Combine(GlobalSettingsPath, "settings/user_steam_id.txt");
|
||||
private readonly string _languagePath = Path.Combine(GlobalSettingsPath, "settings/language.txt");
|
||||
private readonly string _customBroadcastIpsPath = Path.Combine(GlobalSettingsPath, "settings/custom_broadcasts.txt");
|
||||
|
||||
// ReSharper disable StringLiteralTypo
|
||||
private readonly List<string> _interfaceNames = new List<string>
|
||||
{
|
||||
"SteamClient",
|
||||
@ -92,31 +89,23 @@ namespace GoldbergGUI.Core.Services
|
||||
public async Task<GoldbergGlobalConfiguration> GetGlobalSettings()
|
||||
{
|
||||
_log.Info("Getting global settings...");
|
||||
var accountName = DefaultAccountName;
|
||||
var steamId = DefaultSteamId;
|
||||
var accountName = "Account name...";
|
||||
long steamId = -1;
|
||||
var language = DefaultLanguage;
|
||||
var customBroadcastIps = new List<string>();
|
||||
if (!File.Exists(GlobalSettingsPath)) Directory.CreateDirectory(Path.Join(GlobalSettingsPath, "settings"));
|
||||
await Task.Run(() =>
|
||||
{
|
||||
if (File.Exists(_accountNamePath)) accountName = File.ReadLines(_accountNamePath).First().Trim();
|
||||
if (File.Exists(_userSteamIdPath) &&
|
||||
!long.TryParse(File.ReadLines(_userSteamIdPath).First().Trim(), out steamId) &&
|
||||
steamId < 76561197960265729 && steamId > 76561202255233023)
|
||||
{
|
||||
_log.Error("Invalid User Steam ID!");
|
||||
}
|
||||
if (File.Exists(_languagePath)) language = File.ReadLines(_languagePath).First().Trim();
|
||||
if (File.Exists(_customBroadcastIpsPath))
|
||||
customBroadcastIps.AddRange(
|
||||
File.ReadLines(_customBroadcastIpsPath).Select(line => line.Trim()));
|
||||
}).ConfigureAwait(false);
|
||||
return new GoldbergGlobalConfiguration
|
||||
{
|
||||
AccountName = accountName,
|
||||
UserSteamId = steamId,
|
||||
Language = language,
|
||||
CustomBroadcastIps = customBroadcastIps
|
||||
Language = language
|
||||
};
|
||||
}
|
||||
|
||||
@ -125,68 +114,39 @@ namespace GoldbergGUI.Core.Services
|
||||
var accountName = c.AccountName;
|
||||
var userSteamId = c.UserSteamId;
|
||||
var language = c.Language;
|
||||
var customBroadcastIps = c.CustomBroadcastIps;
|
||||
_log.Info("Setting global settings...");
|
||||
// Account Name
|
||||
if (!string.IsNullOrEmpty(accountName))
|
||||
if (accountName != null && accountName != "Account name...")
|
||||
{
|
||||
_log.Info("Setting account name...");
|
||||
if (!File.Exists(_accountNamePath))
|
||||
await File.Create(_accountNamePath).DisposeAsync().ConfigureAwait(false);
|
||||
await File.WriteAllTextAsync(_accountNamePath, accountName).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.Info("Invalid account name! Skipping...");
|
||||
if (!File.Exists(_accountNamePath))
|
||||
await File.Create(_accountNamePath).DisposeAsync().ConfigureAwait(false);
|
||||
await File.WriteAllTextAsync(_accountNamePath, DefaultAccountName).ConfigureAwait(false);
|
||||
await File.WriteAllTextAsync(_accountNamePath, "Goldberg").ConfigureAwait(false);
|
||||
}
|
||||
// User SteamID
|
||||
|
||||
if (userSteamId >= 76561197960265729 && userSteamId <= 76561202255233023)
|
||||
{
|
||||
_log.Info("Setting user Steam ID...");
|
||||
if (!File.Exists(_userSteamIdPath))
|
||||
await File.Create(_userSteamIdPath).DisposeAsync().ConfigureAwait(false);
|
||||
await File.WriteAllTextAsync(_userSteamIdPath, userSteamId.ToString()).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.Info("Invalid user Steam ID! Skipping...");
|
||||
if (!File.Exists(_userSteamIdPath))
|
||||
await File.Create(_userSteamIdPath).DisposeAsync().ConfigureAwait(false);
|
||||
await File.WriteAllTextAsync(_userSteamIdPath, DefaultSteamId.ToString()).ConfigureAwait(false);
|
||||
await Task.Run(() => File.Delete(_userSteamIdPath)).ConfigureAwait(false);
|
||||
}
|
||||
// Language
|
||||
if (!string.IsNullOrEmpty(language))
|
||||
|
||||
if (language != null)
|
||||
{
|
||||
_log.Info("Setting language...");
|
||||
if (!File.Exists(_languagePath))
|
||||
await File.Create(_languagePath).DisposeAsync().ConfigureAwait(false);
|
||||
await File.WriteAllTextAsync(_languagePath, language).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.Info("Invalid language! Skipping...");
|
||||
if (!File.Exists(_languagePath))
|
||||
await File.Create(_languagePath).DisposeAsync().ConfigureAwait(false);
|
||||
await File.WriteAllTextAsync(_languagePath, DefaultLanguage).ConfigureAwait(false);
|
||||
}
|
||||
// Custom Broadcast IPs
|
||||
if (customBroadcastIps != null && customBroadcastIps.Count > 0)
|
||||
{
|
||||
_log.Info("Setting custom broadcast IPs...");
|
||||
var result =
|
||||
customBroadcastIps.Aggregate("", (current, address) => $"{current}{address}\n");
|
||||
if (!File.Exists(_customBroadcastIpsPath))
|
||||
await File.Create(_customBroadcastIpsPath).DisposeAsync().ConfigureAwait(false);
|
||||
await File.WriteAllTextAsync(_customBroadcastIpsPath, result).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.Info("Empty list of custom broadcast IPs! Skipping...");
|
||||
await Task.Run(() => File.Delete(_customBroadcastIpsPath)).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
// If first time, call GenerateInterfaces
|
||||
@ -346,11 +306,11 @@ namespace GoldbergGUI.Core.Services
|
||||
return steamSettingsDirExists && steamAppIdTxtExists;
|
||||
}
|
||||
|
||||
private async Task<bool> Download()
|
||||
// Get webpage
|
||||
// Get job id, compare with local if exists, save it if false or missing
|
||||
// Get latest archive if mismatch, call Extract
|
||||
public async Task<bool> Download()
|
||||
{
|
||||
// Get webpage
|
||||
// Get job id, compare with local if exists, save it if false or missing
|
||||
// Get latest archive if mismatch, call Extract
|
||||
_log.Info("Initializing download...");
|
||||
if (!Directory.Exists(_goldbergPath)) Directory.CreateDirectory(_goldbergPath);
|
||||
var client = new HttpClient();
|
||||
@ -393,7 +353,7 @@ namespace GoldbergGUI.Core.Services
|
||||
|
||||
// Empty subfolder ./goldberg/
|
||||
// Extract all from archive to subfolder ./goldberg/
|
||||
private async Task Extract(string archivePath)
|
||||
public async Task Extract(string archivePath)
|
||||
{
|
||||
_log.Debug("Start extraction...");
|
||||
await Task.Run(() =>
|
||||
|
@ -1,17 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Dom;
|
||||
using AngleSharp.Html.Parser;
|
||||
using GoldbergGUI.Core.Models;
|
||||
using GoldbergGUI.Core.Utils;
|
||||
using LiteDB;
|
||||
using LiteDB.Async;
|
||||
using MvvmCross.Logging;
|
||||
using NinjaNye.SearchExtensions;
|
||||
using SteamStorefrontAPI;
|
||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||
|
||||
namespace GoldbergGUI.Core.Services
|
||||
{
|
||||
@ -27,250 +29,24 @@ namespace GoldbergGUI.Core.Services
|
||||
|
||||
class SteamCache
|
||||
{
|
||||
public string Filename { get; }
|
||||
public string SteamUri { get; }
|
||||
public Type ApiVersion { get; }
|
||||
public AppType SteamAppType { get; }
|
||||
public HashSet<SteamApp> Cache { get; set; } = new HashSet<SteamApp>();
|
||||
|
||||
public SteamCache(string uri, Type apiVersion, AppType steamAppType)
|
||||
public SteamCache(string filename, string uri, Type apiVersion, AppType steamAppType)
|
||||
{
|
||||
Filename = filename;
|
||||
SteamUri = uri;
|
||||
ApiVersion = apiVersion;
|
||||
SteamAppType = steamAppType;
|
||||
}
|
||||
}
|
||||
|
||||
public class SteamService : ISteamService
|
||||
{
|
||||
private const string UserAgent =
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " +
|
||||
"Chrome/87.0.4280.88 Safari/537.36";
|
||||
|
||||
private readonly Dictionary<AppType, SteamCache> _caches =
|
||||
new Dictionary<AppType, SteamCache>
|
||||
{
|
||||
{
|
||||
AppType.Game,
|
||||
new SteamCache(
|
||||
"https://api.steampowered.com/IStoreService/GetAppList/v1/" +
|
||||
"?max_results=50000" +
|
||||
"&include_games=1" +
|
||||
"&key=" + Secrets.SteamWebApiKey(),
|
||||
typeof(SteamAppsV1),
|
||||
AppType.Game
|
||||
)
|
||||
},
|
||||
{
|
||||
AppType.DLC,
|
||||
new SteamCache(
|
||||
"https://api.steampowered.com/IStoreService/GetAppList/v1/" +
|
||||
"?max_results=50000" +
|
||||
"&include_games=0" +
|
||||
"&include_dlc=1" +
|
||||
"&key=" + Secrets.SteamWebApiKey(),
|
||||
typeof(SteamAppsV1),
|
||||
AppType.DLC
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
private static readonly Secrets Secrets = new Secrets();
|
||||
private IMvxLog _log;
|
||||
|
||||
public async Task Initialize(IMvxLog log)
|
||||
{
|
||||
_log = log;
|
||||
|
||||
static SteamApps DeserializeSteamApps(Type type, string cacheString)
|
||||
{
|
||||
if (type == typeof(SteamAppsV1))
|
||||
return JsonSerializer.Deserialize<SteamAppsV1>(cacheString);
|
||||
else if (type == typeof(SteamAppsV2))
|
||||
return JsonSerializer.Deserialize<SteamAppsV2>(cacheString);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (DateTime.Now.Subtract(File.GetLastWriteTimeUtc("steamapps.db")).TotalDays >= 1)
|
||||
{
|
||||
using var db = new LiteDatabaseAsync("steamapps.db");
|
||||
var steamAppCollection = db.GetCollection<SteamApp>("steamapps");
|
||||
var deleteAllResult = await steamAppCollection.DeleteAllAsync().ConfigureAwait(false);
|
||||
_log.Debug($"deleteAllResult: {deleteAllResult}");
|
||||
foreach (var (type, steamCache) in _caches)
|
||||
{
|
||||
bool haveMoreResults;
|
||||
long lastAppId = 0;
|
||||
var client = new HttpClient();
|
||||
var cacheRaw = new HashSet<SteamApp>();
|
||||
do
|
||||
{
|
||||
var steamCacheSteamUri = steamCache.SteamUri;
|
||||
if (lastAppId > 0)
|
||||
{
|
||||
steamCacheSteamUri += "&last_appid=" + lastAppId;
|
||||
}
|
||||
var response = await client.GetAsync(steamCacheSteamUri).ConfigureAwait(false);
|
||||
var responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
var steamApps = DeserializeSteamApps(steamCache.ApiVersion, responseBody);
|
||||
foreach (var appListApp in steamApps.AppList.Apps) cacheRaw.Add(appListApp);
|
||||
haveMoreResults = steamApps.AppList.HaveMoreResults;
|
||||
lastAppId = steamApps.AppList.LastAppid;
|
||||
} while (haveMoreResults);
|
||||
|
||||
var cache = new HashSet<SteamApp>();
|
||||
foreach (var steamApp in cacheRaw)
|
||||
{
|
||||
steamApp.type = steamCache.SteamAppType;
|
||||
cache.Add(steamApp);
|
||||
}
|
||||
|
||||
var bulkInsertResult = await steamAppCollection.InsertBulkAsync(cache).ConfigureAwait(false);
|
||||
_log.Debug($"bulkInsertResult: {bulkInsertResult}");
|
||||
if (cache.Count.Equals(bulkInsertResult))
|
||||
{
|
||||
_log.Info($"Successfully added cache to DB (type: {type.Value})");
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.Error($"Error: could not add all items to DB (type: {type.Value})");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<SteamApp> GetListOfAppsByName(string name)
|
||||
{
|
||||
using var db = new LiteDatabase("steamapps.db");
|
||||
var steamAppCollection = db.GetCollection<SteamApp>("steamapps");
|
||||
steamAppCollection.EnsureIndex(x => x.Name);
|
||||
return steamAppCollection.Query()
|
||||
.Where(x => x.Name.Contains(name))
|
||||
.OrderBy(x => x.AppId)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public SteamApp GetAppByName(string name)
|
||||
{
|
||||
using var db = new LiteDatabase("steamapps.db");
|
||||
var steamAppCollection = db.GetCollection<SteamApp>("steamapps");
|
||||
steamAppCollection.EnsureIndex(x => x.Name);
|
||||
return steamAppCollection.FindOne(x => x.Name.Contains(name));
|
||||
}
|
||||
|
||||
public SteamApp GetAppById(int appid)
|
||||
{
|
||||
using var db = new LiteDatabase("steamapps.db");
|
||||
var steamAppCollection = db.GetCollection<SteamApp>("steamapps");
|
||||
steamAppCollection.EnsureIndex(x => x.AppId);
|
||||
return steamAppCollection.FindOne(x => x.AppId.Equals(appid));
|
||||
}
|
||||
|
||||
public async Task<List<SteamApp>> GetListOfDlc(SteamApp steamApp, bool useSteamDb)
|
||||
{
|
||||
/*using var db = new LiteDatabaseAsync("steamapps.db");
|
||||
var steamAppCollection = db.GetCollection<SteamApp>("steamapps");
|
||||
var findOneAsync =
|
||||
await steamAppCollection.FindOneAsync(x => x.Equals(steamApp)).ConfigureAwait(false);
|
||||
return new List<SteamApp>();*/
|
||||
_log.Info("Get DLC");
|
||||
var dlcList = new List<SteamApp>();
|
||||
if (steamApp != null)
|
||||
{
|
||||
var task = AppDetails.GetAsync(steamApp.AppId);
|
||||
var steamAppDetails = await task.ConfigureAwait(true);
|
||||
if (steamAppDetails.Type == AppType.Game.Value)
|
||||
{
|
||||
steamAppDetails.DLC.ForEach(x =>
|
||||
{
|
||||
/*var result = _caches[AppType.DLC].Cache.FirstOrDefault(y => y.AppId.Equals(x))
|
||||
?? new SteamApp {AppId = x, Name = $"Unknown DLC {x}"};*/
|
||||
|
||||
using var db = new LiteDatabase("steamapps.db");
|
||||
var steamAppCollection = db.GetCollection<SteamApp>("steamapps");
|
||||
steamAppCollection.EnsureIndex(y => y.AppId);
|
||||
var result = steamAppCollection.FindOne(y => y.AppId.Equals(x))
|
||||
?? new SteamApp {AppId = x, Name = $"Unknown DLC {x}"};
|
||||
dlcList.Add(result);
|
||||
});
|
||||
|
||||
dlcList.ForEach(x => _log.Debug($"{x.AppId}={x.Name}"));
|
||||
_log.Info("Got DLC successfully...");
|
||||
|
||||
// Get DLC from SteamDB
|
||||
// Get Cloudflare cookie
|
||||
// Scrape and parse HTML page
|
||||
// Add missing to DLC list
|
||||
|
||||
// ReSharper disable once InvertIf
|
||||
if (useSteamDb)
|
||||
{
|
||||
var steamDbUri = new Uri($"https://steamdb.info/app/{steamApp.AppId}/dlc/");
|
||||
|
||||
var client = new HttpClient();
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);
|
||||
|
||||
_log.Info("Get SteamDB App");
|
||||
var httpCall = client.GetAsync(steamDbUri);
|
||||
var response = await httpCall.ConfigureAwait(false);
|
||||
_log.Debug(httpCall.Status.ToString());
|
||||
_log.Debug(response.EnsureSuccessStatusCode().ToString());
|
||||
|
||||
var readAsStringAsync = response.Content.ReadAsStringAsync();
|
||||
var responseBody = await readAsStringAsync.ConfigureAwait(false);
|
||||
_log.Debug(readAsStringAsync.Status.ToString());
|
||||
|
||||
var parser = new HtmlParser();
|
||||
var doc = parser.ParseDocument(responseBody);
|
||||
|
||||
var query1 = doc.QuerySelector("#dlc");
|
||||
if (query1 != null)
|
||||
{
|
||||
var query2 = query1.QuerySelectorAll(".app");
|
||||
foreach (var element in query2)
|
||||
{
|
||||
var dlcId = element.GetAttribute("data-appid");
|
||||
var query3 = element.QuerySelectorAll("td");
|
||||
var dlcName = query3 != null
|
||||
? query3[1].Text().Replace("\n", "").Trim()
|
||||
: $"Unknown DLC {dlcId}";
|
||||
var dlcApp = new SteamApp {AppId = Convert.ToInt32(dlcId), Name = dlcName};
|
||||
var i = dlcList.FindIndex(x => x.AppId.Equals(dlcApp.AppId));
|
||||
if (i > -1)
|
||||
{
|
||||
if (dlcList[i].Name.Contains("Unknown DLC")) dlcList[i] = dlcApp;
|
||||
}
|
||||
else
|
||||
{
|
||||
dlcList.Add(dlcApp);
|
||||
}
|
||||
}
|
||||
|
||||
dlcList.ForEach(x => _log.Debug($"{x.AppId}={x.Name}"));
|
||||
_log.Info("Got DLC from SteamDB successfully...");
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.Error("Could not get DLC from SteamDB!");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.Error("Could not get DLC: Steam App is not of type \"game\"");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.Error("Could not get DLC: Invalid Steam App");
|
||||
}
|
||||
|
||||
return dlcList;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// ReSharper disable once UnusedType.Global
|
||||
// ReSharper disable once ClassNeverInstantiated.Global
|
||||
public class OldSteamService : ISteamService
|
||||
public class SteamService : ISteamService
|
||||
{
|
||||
// ReSharper disable StringLiteralTypo
|
||||
private readonly Dictionary<AppType, SteamCache> _caches =
|
||||
@ -506,5 +282,4 @@ namespace GoldbergGUI.Core.Services
|
||||
return dlcList;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
@ -476,23 +476,29 @@ namespace GoldbergGUI.Core.ViewModels
|
||||
}
|
||||
else
|
||||
{
|
||||
var pastedDlc = new List<SteamApp>();
|
||||
var result = Clipboard.GetText();
|
||||
var expression = new Regex(@"(?<id>.*) *= *(?<name>.*)");
|
||||
var pastedDlc = (from line in result.Split(new[] {"\n", "\r\n"},
|
||||
StringSplitOptions.RemoveEmptyEntries) select expression.Match(line) into match
|
||||
where match.Success select new SteamApp
|
||||
{
|
||||
AppId = Convert.ToInt32(match.Groups["id"].Value),
|
||||
Name = match.Groups["name"].Value
|
||||
}).ToList();
|
||||
foreach (var line in result.Split(new[]
|
||||
{
|
||||
"\n",
|
||||
"\r\n"
|
||||
}, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
var match = expression.Match(line);
|
||||
if (match.Success)
|
||||
pastedDlc.Add(new SteamApp
|
||||
{
|
||||
AppId = Convert.ToInt32(match.Groups["id"].Value),
|
||||
Name = match.Groups["name"].Value
|
||||
});
|
||||
}
|
||||
if (pastedDlc.Count > 0)
|
||||
{
|
||||
DLCs.Clear();
|
||||
DLCs = new ObservableCollection<SteamApp>(pastedDlc);
|
||||
//var empty = DLCs.Count == 1 ? "" : "s";
|
||||
//StatusText = $"Successfully got {DLCs.Count} DLC{empty} from clipboard! Ready.";
|
||||
var statusTextCount = DLCs.Count == 1 ? "one DLC" : $"{DLCs.Count} DLCs";
|
||||
StatusText = $"Successfully got {statusTextCount} from clipboard! Ready.";
|
||||
var empty = DLCs.Count == 1 ? "" : "s";
|
||||
StatusText = $"Successfully got {DLCs.Count} DLC{empty} from clipboard! Ready.";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -84,7 +84,7 @@
|
||||
<StackPanel Margin="5,5,5,5">
|
||||
<CheckBox Content="Offline" IsChecked="{Binding Offline, Mode=TwoWay}" Height="20" VerticalAlignment="Stretch" VerticalContentAlignment="Center"/>
|
||||
<CheckBox Content="Disable Networking" IsChecked="{Binding DisableNetworking, Mode=TwoWay}" Height="20" VerticalContentAlignment="Center"/>
|
||||
<CheckBox Content="Disable Overlay" IsChecked="{Binding DisableOverlay, Mode=TwoWay}" Height="20" VerticalContentAlignment="Center" IsEnabled="False"/>
|
||||
<CheckBox Content="Disable Overlay" IsChecked="{Binding DisableOverlay, Mode=TwoWay}" Height="20" VerticalContentAlignment="Center"/>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
@ -99,17 +99,16 @@
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Label Content="Account name" HorizontalAlignment="Left" Margin="0,0,10,0" />
|
||||
<TextBox Text="{Binding AccountName, Mode=TwoWay}" Height="20" Grid.Row="0" Grid.Column="1"/>
|
||||
<CheckBox Content="Global" Grid.Row="0" Grid.Column="2" HorizontalAlignment="Right"
|
||||
Margin="10,0,5,0" VerticalAlignment="Center" IsChecked="True"
|
||||
Margin="10,0,0,0" VerticalAlignment="Center" IsChecked="True"
|
||||
IsEnabled="False"/>
|
||||
<!--
|
||||
IsEnabled="{Binding DllSelected, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
@ -118,7 +117,7 @@
|
||||
Grid.Column="0" Margin="0,0,10,0" />
|
||||
<TextBox Text="{Binding SteamId, Mode=TwoWay}" Grid.Column="1" Height="20" Grid.Row="1"/>
|
||||
<CheckBox Content="Global" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Right"
|
||||
Margin="10,0,5,0" VerticalAlignment="Center" IsChecked="True"
|
||||
Margin="10,0,0,0" VerticalAlignment="Center" IsChecked="True"
|
||||
IsEnabled="False"/>
|
||||
<!--
|
||||
IsEnabled="{Binding DllSelected, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
@ -127,21 +126,12 @@
|
||||
Grid.Column="0" Margin="0,0,10,0" />
|
||||
<ComboBox Grid.Row="2" Grid.Column="1" ItemsSource="{Binding SteamLanguages}" SelectedItem="{Binding SelectedLanguage}" VerticalAlignment="Center"/>
|
||||
<CheckBox Content="Global" Grid.Row="2" Grid.Column="2" HorizontalAlignment="Right"
|
||||
Margin="10,0,5,0" VerticalAlignment="Center" IsChecked="True"
|
||||
Margin="10,0,0,0" VerticalAlignment="Center" IsChecked="True"
|
||||
IsEnabled="False"/>
|
||||
<!--
|
||||
IsEnabled="{Binding DllSelected, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
-->
|
||||
<Label Content="Custom Broadcast Addresses:" HorizontalAlignment="Left"
|
||||
Grid.ColumnSpan="2" Grid.Row="3" Grid.Column="0" Margin="0,0,10,0"/>
|
||||
<CheckBox Content="Global" Grid.Row="3" Grid.Column="2" HorizontalAlignment="Right"
|
||||
Margin="10,0,5,0" VerticalAlignment="Center" IsChecked="True"
|
||||
IsEnabled="False"/>
|
||||
<TextBox Grid.Row="4" Grid.ColumnSpan="3" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
|
||||
TextWrapping="Wrap"
|
||||
AcceptsReturn="True"
|
||||
VerticalScrollBarVisibility="Auto" MaxHeight="120" MinHeight="120"/>
|
||||
<TextBlock TextWrapping="Wrap" Grid.ColumnSpan="3" Grid.Column="0" Grid.Row="5" Margin="5,10,5,5">
|
||||
<TextBlock TextWrapping="Wrap" Grid.ColumnSpan="3" Grid.Column="0" Grid.Row="3" Margin="5,10,5,5">
|
||||
<Run Text="{Binding G.Header, Mode=OneTime}" FontWeight="Bold"/><!--
|
||||
--><Run Text="{Binding G.TextPreLink, Mode=OneTime}"/>
|
||||
<Hyperlink Command="{Binding OpenGlobalSettingsFolderCommand}"><Run
|
||||
|
Loading…
Reference in New Issue
Block a user