Added link to forum search

Added status bar
List of DLC is now monospaced
Fixed weird crash with search result window
This commit is contained in:
Jeddunk 2020-12-23 12:34:31 +01:00
parent 56e92924ed
commit 45f86ecc63
11 changed files with 1447 additions and 129 deletions

View file

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.Json;
@ -11,7 +10,6 @@ using AngleSharp.Html.Parser;
using auto_creamapi.POCOs;
using auto_creamapi.Utils;
using NinjaNye.SearchExtensions;
using NinjaNye.SearchExtensions.Models;
using SteamStorefrontAPI;
namespace auto_creamapi.Model
@ -23,7 +21,7 @@ namespace auto_creamapi.Model
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 static List<POCOs.App> _cache = new List<POCOs.App>();
private static List<SteamApp> _cache = new List<SteamApp>();
public readonly List<string> Languages = new List<string>(new[]
{
@ -97,7 +95,7 @@ namespace auto_creamapi.Model
MyLogger.Log.Information("Loaded cache into memory!");
}
public EnumerableStringSearch<POCOs.App> GetListOfAppsByName(string name)
public EnumerableStringSearch<SteamApp> GetListOfAppsByName(string name)
{
var listOfAppsByName = _cache.Search(x => x.Name)
.SetCulture(StringComparison.OrdinalIgnoreCase)
@ -105,7 +103,7 @@ namespace auto_creamapi.Model
return listOfAppsByName;
}
public POCOs.App GetAppByName(string name)
public SteamApp GetAppByName(string name)
{
MyLogger.Log.Information($"Trying to get app {name}");
var app = _cache.Find(x => x.Name.ToLower().Equals(name.ToLower()));
@ -113,7 +111,7 @@ namespace auto_creamapi.Model
return app;
}
public POCOs.App GetAppById(int appid)
public SteamApp GetAppById(int appid)
{
MyLogger.Log.Information($"Trying to get app with ID {appid}");
var app = _cache.Find(x => x.AppId.Equals(appid));
@ -121,18 +119,18 @@ namespace auto_creamapi.Model
return app;
}
public async Task<List<POCOs.App>> GetListOfDlc(POCOs.App app, bool useSteamDb)
public async Task<List<SteamApp>> GetListOfDlc(SteamApp steamApp, bool useSteamDb)
{
MyLogger.Log.Information("Get DLC");
var dlcList = new List<POCOs.App>();
if (app != null)
var dlcList = new List<SteamApp>();
if (steamApp != null)
{
var task = AppDetails.GetAsync(app.AppId);
var steamApp = await task;
steamApp?.DLC.ForEach(x =>
var task = AppDetails.GetAsync(steamApp.AppId);
var steamAppDetails = await task;
steamAppDetails?.DLC.ForEach(x =>
{
var result = _cache.Find(y => y.AppId.Equals(x)) ??
new POCOs.App {AppId = x, Name = $"Unknown DLC {x}"};
new SteamApp {AppId = x, Name = $"Unknown DLC {x}"};
dlcList.Add(result);
});
@ -145,7 +143,7 @@ namespace auto_creamapi.Model
// Add missing to DLC list
if (useSteamDb)
{
var steamDbUri = new Uri($"https://steamdb.info/app/{app.AppId}/dlc/");
var steamDbUri = new Uri($"https://steamdb.info/app/{steamApp.AppId}/dlc/");
/* var handler = new ClearanceHandler();
@ -185,7 +183,7 @@ namespace auto_creamapi.Model
dlcName = query3[1].Text().Replace("\n", "").Trim();
}
var dlcApp = new POCOs.App {AppId = Convert.ToInt32(dlcId), Name = dlcName};
var dlcApp = new SteamApp {AppId = Convert.ToInt32(dlcId), Name = dlcName};
var i = dlcList.FindIndex(x => x.CompareId(dlcApp));
if (i > -1)
{
@ -207,7 +205,7 @@ namespace auto_creamapi.Model
}
else
{
MyLogger.Log.Error($"Could not find game: {app}");
MyLogger.Log.Error($"Could not find game: {steamApp}");
}
return dlcList;

View file

@ -9,23 +9,23 @@ using IniParser.Model;
namespace auto_creamapi.Model
{
public class CreamConfig
{
public int AppId { get; set; }
public string Language { get; set; }
public bool UnlockAll { get; set; }
public bool ExtraProtection { get; set; }
public bool ForceOffline { get; set; }
public Dictionary<int, string> DlcList { get; }
public CreamConfig()
{
DlcList = new Dictionary<int, string>();
}
}
public sealed class CreamConfigModel
{
// ReSharper disable once MemberCanBePrivate.Global
public struct CreamConfig
{
public int AppId;
public string Language;
public bool UnlockAll;
public bool ExtraProtection;
public bool ForceOffline;
public Dictionary<int, string> DlcList;
}
private CreamConfig _config;
public CreamConfig Config => _config;
public CreamConfig Config { get; }
private static readonly Lazy<CreamConfigModel> Lazy =
new Lazy<CreamConfigModel>(() => new CreamConfigModel());
@ -38,8 +38,8 @@ namespace auto_creamapi.Model
private CreamConfigModel()
{
_config.DlcList = new Dictionary<int, string>();
SetConfigData();
Config = new CreamConfig();
ResetConfigData();
}
public void ReadFile(string configFilePath)
@ -50,23 +50,23 @@ namespace auto_creamapi.Model
var parser = new FileIniDataParser();
var data = parser.ReadFile(_configFilePath, Encoding.UTF8);
SetConfigData(); // clear previous config data
_config.AppId = Convert.ToInt32(data["steam"]["appid"]);
_config.Language = data["steam"]["language"];
_config.UnlockAll = Convert.ToBoolean(data["steam"]["unlockall"]);
_config.ExtraProtection = Convert.ToBoolean(data["steam"]["extraprotection"]);
_config.ForceOffline = Convert.ToBoolean(data["steam"]["forceoffline"]);
ResetConfigData(); // clear previous config data
Config.AppId = Convert.ToInt32(data["steam"]["appid"]);
Config.Language = data["steam"]["language"];
Config.UnlockAll = Convert.ToBoolean(data["steam"]["unlockall"]);
Config.ExtraProtection = Convert.ToBoolean(data["steam"]["extraprotection"]);
Config.ForceOffline = Convert.ToBoolean(data["steam"]["forceoffline"]);
var dlcCollection = data["dlc"];
foreach (var item in dlcCollection)
{
_config.DlcList.Add(int.Parse(item.KeyName), item.Value);
Config.DlcList.Add(int.Parse(item.KeyName), item.Value);
}
}
else
{
MyLogger.Log.Information($"Config file does not exist @ {configFilePath}, skipping...");
SetConfigData();
ResetConfigData();
}
}
@ -75,14 +75,14 @@ namespace auto_creamapi.Model
var parser = new FileIniDataParser();
var data = new IniData();
data["steam"]["appid"] = _config.AppId.ToString();
data["steam"]["language"] = _config.Language;
data["steam"]["unlockall"] = _config.UnlockAll.ToString();
data["steam"]["extraprotection"] = _config.ExtraProtection.ToString();
data["steam"]["forceoffline"] = _config.ForceOffline.ToString();
data["steam"]["appid"] = Config.AppId.ToString();
data["steam"]["language"] = Config.Language;
data["steam"]["unlockall"] = Config.UnlockAll.ToString();
data["steam"]["extraprotection"] = Config.ExtraProtection.ToString();
data["steam"]["forceoffline"] = Config.ForceOffline.ToString();
data.Sections.AddSection("dlc");
foreach (var (key, value) in _config.DlcList)
foreach (var (key, value) in Config.DlcList)
{
data["dlc"].AddKey(key.ToString(), value);
}
@ -90,14 +90,14 @@ namespace auto_creamapi.Model
parser.WriteFile(_configFilePath, data, Encoding.UTF8);
}
public void SetConfigData()
private void ResetConfigData()
{
_config.AppId = 0;
_config.Language = "";
_config.UnlockAll = false;
_config.ExtraProtection = false;
_config.ForceOffline = false;
_config.DlcList.Clear();
Config.AppId = 0;
Config.Language = "";
Config.UnlockAll = false;
Config.ExtraProtection = false;
Config.ForceOffline = false;
Config.DlcList.Clear();
}
public void SetConfigData(int appId,
@ -107,12 +107,11 @@ namespace auto_creamapi.Model
bool forceOffline,
string dlcList)
{
_config.AppId = appId;
_config.Language = language;
_config.UnlockAll = unlockAll;
_config.ExtraProtection = extraProtection;
_config.ForceOffline = forceOffline;
Config.AppId = appId;
Config.Language = language;
Config.UnlockAll = unlockAll;
Config.ExtraProtection = extraProtection;
Config.ForceOffline = forceOffline;
SetDlcFromString(dlcList);
}
@ -134,7 +133,7 @@ namespace auto_creamapi.Model
private void SetDlcFromString(string dlcList)
{
_config.DlcList.Clear();
Config.DlcList.Clear();
var expression = new Regex(@"(?<id>.*) *= *(?<name>.*)");
using var reader = new StringReader(dlcList);
string line;
@ -143,7 +142,7 @@ namespace auto_creamapi.Model
var match = expression.Match(line);
if (match.Success)
{
_config.DlcList.Add(int.Parse(match.Groups["id"].Value), match.Groups["name"].Value);
Config.DlcList.Add(int.Parse(match.Groups["id"].Value), match.Groups["name"].Value);
}
}
}
@ -157,15 +156,15 @@ namespace auto_creamapi.Model
public override string ToString()
{
var str = $"INI file: {_configFilePath}, " +
$"AppID: {_config.AppId}, " +
$"Language: {_config.Language}, " +
$"UnlockAll: {_config.UnlockAll}, " +
$"ExtraProtection: {_config.ExtraProtection}, " +
$"ForceOffline: {_config.ForceOffline}, " +
$"DLC ({_config.DlcList.Count}):\n[\n";
if (_config.DlcList.Count > 0)
$"AppID: {Config.AppId}, " +
$"Language: {Config.Language}, " +
$"UnlockAll: {Config.UnlockAll}, " +
$"ExtraProtection: {Config.ExtraProtection}, " +
$"ForceOffline: {Config.ForceOffline}, " +
$"DLC ({Config.DlcList.Count}):\n[\n";
if (Config.DlcList.Count > 0)
{
foreach (var (key, value) in _config.DlcList)
foreach (var (key, value) in Config.DlcList)
{
str += $" {key}={value},\n";
}

View file

@ -16,28 +16,30 @@ using HttpProgress;
namespace auto_creamapi.Model
{
public class CreamDllModel
internal class CreamDll
{
private struct CreamDll
public readonly string Filename;
public readonly string OrigFilename;
public readonly string Hash;
public CreamDll(string filename, string origFilename)
{
public readonly string Filename;
public readonly string OrigFilename;
public readonly string Hash;
Filename = filename;
OrigFilename = origFilename;
Hash = "";
public CreamDll(string filename, string origFilename)
using var md5 = MD5.Create();
if (File.Exists(Filename))
{
Filename = filename;
OrigFilename = origFilename;
Hash = "";
using var md5 = MD5.Create();
using var stream = File.OpenRead(Filename);
Hash = BitConverter
.ToString(md5.ComputeHash(stream))
.Replace("-", string.Empty);
}
}
}
public class CreamDllModel
{
private static readonly Lazy<CreamDllModel> Lazy =
new Lazy<CreamDllModel>(() => new CreamDllModel());