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

1236
Annotations/Annotations.cs Normal file

File diff suppressed because it is too large Load Diff

BIN
CourierPrime-Regular.ttf Normal file

Binary file not shown.

View File

@ -13,42 +13,58 @@
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<wcl:WatermarkTextBox x:Name="DllPath" Watermark="Path to game's steam_api(64).dll..." Margin="10,11,55,0" TextWrapping="NoWrap" VerticalAlignment="Top" Padding="0" Grid.Row="0" IsReadOnly="True" IsReadOnlyCaretVisible="True" MouseDoubleClick="DllPath_MouseDoubleClick"/> <wcl:WatermarkTextBox x:Name="DllPath" Watermark="Path to game's steam_api(64).dll..." Margin="10,11,55,0" TextWrapping="NoWrap" VerticalAlignment="Top" Padding="0" Grid.Row="0" IsReadOnly="True" IsReadOnlyCaretVisible="True" MouseDoubleClick="DllPath_MouseDoubleClick"/>
<Button x:Name="OpenFile" Content="&#xE1A5;" HorizontalAlignment="Right" Margin="0,10,10,0" VerticalAlignment="Top" FontFamily="Segoe UI Symbol" Width="40" Click="OpenFile_Click" ToolTip="Select DLL file." Grid.Row="0"/> <Button Content="&#xE1A5;" HorizontalAlignment="Right" Margin="0,10,10,0" VerticalAlignment="Top" FontFamily="Segoe UI Symbol" Width="40" Click="OpenFile_Click" ToolTip="Select DLL file." Grid.Row="0"/>
<wcl:WatermarkTextBox x:Name="Game" Margin="10,10,180,0" Watermark="Game Name" TextWrapping="Wrap" VerticalAlignment="Top" Padding="0" Grid.Row="1"/> <wcl:WatermarkTextBox x:Name="Game" Margin="10,10,180,0" Watermark="Game Name" TextWrapping="Wrap" VerticalAlignment="Top" Padding="0" Grid.Row="1"/>
<Button x:Name="Search" Content="&#xE11A;" HorizontalAlignment="Right" Margin="0,9,135,0" VerticalAlignment="Top" FontFamily="Segoe UI Symbol" Width="40" Click="Search_Click" ToolTip="Find AppID." Grid.Row="1"/> <Button Content="&#xE11A;" HorizontalAlignment="Right" Margin="0,9,135,0" VerticalAlignment="Top" FontFamily="Segoe UI Symbol" Width="40" Click="Search_Click" ToolTip="Find AppID." Grid.Row="1"/>
<wcl:WatermarkTextBox x:Name="AppId" HorizontalAlignment="Right" Margin="0,10,10,0" Watermark="AppID" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Padding="0" Grid.Row="1" KeyUp="AppId_OnTextChanged" /> <wcl:WatermarkTextBox x:Name="AppId" HorizontalAlignment="Right" Margin="0,10,10,0" Watermark="AppID" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Padding="0" Grid.Row="1" KeyUp="AppId_OnTextChanged" />
<ComboBox x:Name="Lang" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="120" Grid.Row="2"/> <TextBlock Grid.Row="2" Margin="10,10,10,0">
<CheckBox x:Name="ForceOffline" Content="Force offline mode" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" ToolTip="offlinemode" Grid.Row="3"/> <Hyperlink NavigateUri="https://cs.rin.ru/forum/search.php" RequestNavigate="Hyperlink_RequestNavigate" >Search for cs.rin.ru thread</Hyperlink>
<CheckBox x:Name="ExtraProtection" Content="Try to bypass game-specific protection" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" ToolTip="extraprotection" Grid.Row="4"/> </TextBlock>
<Grid Margin="10,10,10,0" Grid.Row="5"> <ComboBox x:Name="Lang" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="120" Grid.Row="3"/>
<CheckBox x:Name="ForceOffline" Content="Force offline mode" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" ToolTip="offlinemode" Grid.Row="4"/>
<CheckBox x:Name="ExtraProtection" Content="Try to bypass game-specific protection" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" ToolTip="extraprotection" Grid.Row="5"/>
<Grid Margin="10,10,10,0" Grid.Row="6">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<GroupBox x:Name="DlcGroup" Header="DLC" Grid.Row="0" VerticalAlignment="Stretch"> <GroupBox Header="DLC" Grid.Row="0" VerticalAlignment="Stretch">
<Grid> <Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<CheckBox x:Name="UnlockAll" Content="Unlock all DLCs (if possible)" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" ToolTip="unlockall"/> <CheckBox x:Name="UnlockAll" Content="Unlock all DLCs (if possible)" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" ToolTip="unlockall"/>
<CheckBox x:Name="SteamDb" Content="Additionally use SteamDB for DLCs" HorizontalAlignment="Left" Margin="10,30,0,0" VerticalAlignment="Top"/> <CheckBox x:Name="SteamDb" Content="Additionally use SteamDB for DLCs" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Grid.Row="1"/>
<wcl:WatermarkTextBox x:Name="ListOfDlcs" Margin="10,55,10,40" Watermark="List of DLCs...&#xA;0000 = DLC Name" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" Padding="0"/> <wcl:WatermarkTextBox x:Name="ListOfDlcs" Margin="10,10,10,0" Watermark="List of DLCs...&#xA;0000 = DLC Name" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" Padding="0" FontFamily="./#Courier Prime" Grid.Row="2"/>
<Button x:Name="GetListOfDlcs" Content="Get DLCs for AppID" Margin="0,0,10,10" Height="19.96" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="108" Click="GetListOfDlc_Click"/> <Button Content="Get DLCs for AppID" Margin="0,10,10,10" Height="19.96" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="108" Click="GetListOfDlc_Click" Grid.Row="3"/>
</Grid> </Grid>
</GroupBox> </GroupBox>
<GroupBox x:Name="StatusGroup" Header="Status" Grid.Row="1" VerticalAlignment="Bottom"> <GroupBox Header="Status" Grid.Row="1" VerticalAlignment="Bottom">
<Grid IsEnabled="False"> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<CheckBox x:Name="creamApiApplied" Content="CreamAPI DLL applied" Margin="10,10,0,10" Grid.Column="0" IsEnabled="False"/> <CheckBox x:Name="CreamApiApplied" Content="CreamAPI DLL applied" Margin="10,10,0,10" Grid.Column="0" IsEnabled="False"/>
<CheckBox x:Name="configExists" Content="CreamAPI Config exists" Margin="10,10,0,10" Grid.Column="1"/> <CheckBox x:Name="ConfigExists" Content="CreamAPI Config exists" Margin="10,10,0,10" Grid.Column="1" IsEnabled="False"/>
</Grid> </Grid>
</GroupBox> </GroupBox>
</Grid> </Grid>
<Button x:Name="Save" Content="Save" Margin="0,10,55,10" HorizontalAlignment="Right" Width="40" Height="20" VerticalAlignment="Bottom" Click="Save_Click" Grid.Row="6"/> <Button Content="Save" Margin="0,10,55,10" HorizontalAlignment="Right" Width="40" Height="20" VerticalAlignment="Bottom" Click="Save_Click" Grid.Row="7"/>
<Button x:Name="Reset" Content="Reset" Margin="0,10,10,10" Height="20" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="40" Click="Reset_Click" Grid.Row="6"/> <Button Content="Reset" Margin="0,10,10,10" Height="20" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="40" Click="Reset_Click" Grid.Row="7"/>
<StatusBar Grid.Row="8">
<StatusBarItem Height="30" Margin="0,0,0,0">
<TextBlock x:Name="Status" Text=""/>
</StatusBarItem>
</StatusBar>
</Grid> </Grid>
</Window> </Window>

View File

@ -1,9 +1,11 @@
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using auto_creamapi.Model; using auto_creamapi.Model;
using auto_creamapi.POCOs;
using auto_creamapi.Utils; using auto_creamapi.Utils;
using Microsoft.Win32; using Microsoft.Win32;
@ -28,6 +30,7 @@ namespace auto_creamapi
_cacheModel.Languages.ForEach(x => Lang.Items.Add(x)); _cacheModel.Languages.ForEach(x => Lang.Items.Add(x));
Lang.SelectedItem = DefaultLangSelection; Lang.SelectedItem = DefaultLangSelection;
SteamDb.IsChecked = true; SteamDb.IsChecked = true;
Status.Text = "Ready.";
} }
/// <summary> /// <summary>
@ -40,6 +43,7 @@ namespace auto_creamapi
var app = _cacheModel.GetAppByName(Game.Text); var app = _cacheModel.GetAppByName(Game.Text);
if (app != null) if (app != null)
{ {
Game.Text = app.Name;
AppId.Text = app.AppId.ToString(); AppId.Text = app.AppId.ToString();
} }
else else
@ -67,6 +71,7 @@ namespace auto_creamapi
private void MyOpenFile() private void MyOpenFile()
{ {
Status.Text = "Waiting for file...";
var dialog = new OpenFileDialog var dialog = new OpenFileDialog
{ {
Filter = "SteamAPI DLL|steam_api.dll;steam_api64.dll|" + Filter = "SteamAPI DLL|steam_api.dll;steam_api64.dll|" +
@ -87,6 +92,7 @@ namespace auto_creamapi
_dllModel.TargetPath = dirPath; _dllModel.TargetPath = dirPath;
_dllModel.CheckExistence(); _dllModel.CheckExistence();
CheckExistance(); CheckExistance();
Status.Text = "Ready.";
} }
} }
} }
@ -98,23 +104,39 @@ namespace auto_creamapi
/// <param name="e"></param> /// <param name="e"></param>
private async void GetListOfDlc_Click(object sender, RoutedEventArgs e) private async void GetListOfDlc_Click(object sender, RoutedEventArgs e)
{ {
Status.Text = "Trying to get DLC...";
if (int.TryParse(AppId.Text, out var appId)) if (int.TryParse(AppId.Text, out var appId))
{ {
if (appId > 0) if (appId > 0)
{ {
var app = new POCOs.App() {AppId = appId, Name = Game.Text}; var app = new SteamApp() {AppId = appId, Name = Game.Text};
var listOfDlc = await _cacheModel.GetListOfDlc(app, var task = _cacheModel.GetListOfDlc(app,
SteamDb.IsChecked != null && (bool) SteamDb.IsChecked); SteamDb.IsChecked != null && (bool) SteamDb.IsChecked);
var listOfDlc = await task;
var result = ""; var result = "";
if (task.IsCompletedSuccessfully)
{
listOfDlc.Sort((app1, app2) => app1.AppId.CompareTo(app2.AppId)); listOfDlc.Sort((app1, app2) => app1.AppId.CompareTo(app2.AppId));
listOfDlc.ForEach(x => result += $"{x.AppId}={x.Name}\n"); listOfDlc.ForEach(x => result += $"{x.AppId}={x.Name}\n");
ListOfDlcs.Text = result; ListOfDlcs.Text = result;
Status.Text = $"Got DLC for AppID {appId}";
} }
else else
{ {
Status.Text = $"Could not get DLC for AppID {appId}";
}
}
else
{
Status.Text = $"Could not get DLC for AppID {appId}";
MyLogger.Log.Error($"GetListOfDlc: Invalid AppID {appId}"); MyLogger.Log.Error($"GetListOfDlc: Invalid AppID {appId}");
} }
} }
else
{
Status.Text = $"Could not get DLC: Invalid AppID {appId}";
MyLogger.Log.Error($"GetListOfDlc: Invalid AppID {appId}");
}
} }
/// <summary> /// <summary>
@ -124,6 +146,7 @@ namespace auto_creamapi
/// <param name="e"></param> /// <param name="e"></param>
private void Save_Click(object sender, RoutedEventArgs e) private void Save_Click(object sender, RoutedEventArgs e)
{ {
Status.Text = "Saving...";
_configModel.SetConfigData( _configModel.SetConfigData(
Convert.ToInt32(AppId.Text), Convert.ToInt32(AppId.Text),
Lang.SelectedItem.ToString(), Lang.SelectedItem.ToString(),
@ -135,6 +158,7 @@ namespace auto_creamapi
_configModel.SaveFile(); _configModel.SaveFile();
_dllModel.Save(); _dllModel.Save();
CheckExistance(); CheckExistance();
Status.Text = "Saving successful.";
} }
/// <summary> /// <summary>
@ -144,8 +168,10 @@ namespace auto_creamapi
/// <param name="e"></param> /// <param name="e"></param>
private void Reset_Click(object sender, RoutedEventArgs e) private void Reset_Click(object sender, RoutedEventArgs e)
{ {
Status.Text = "Resetting...";
ResetFormData(); ResetFormData();
CheckExistance(); CheckExistance();
Status.Text = "Resetting successful.";
} }
/// <summary> /// <summary>
@ -171,11 +197,15 @@ namespace auto_creamapi
} }
else else
{ {
Game.Text = "";
AppId.Text = "";
MyLogger.Log.Error($"No app found for ID {appId}"); MyLogger.Log.Error($"No app found for ID {appId}");
} }
} }
else else
{ {
Game.Text = "";
AppId.Text = "";
MyLogger.Log.Error($"SetNameById: Invalid AppID {appId}"); MyLogger.Log.Error($"SetNameById: Invalid AppID {appId}");
} }
} }
@ -204,9 +234,43 @@ namespace auto_creamapi
private void CheckExistance() private void CheckExistance()
{ {
CreamApiApplied.IsChecked = _dllModel.CreamApiApplied();
ConfigExists.IsChecked = _configModel.ConfigExists();
}
creamApiApplied.IsChecked = _dllModel.CreamApiApplied(); private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
configExists.IsChecked = _configModel.ConfigExists(); {
// for .NET Core you need to add UseShellExecute = true
// see https://docs.microsoft.com/dotnet/api/system.diagnostics.processstartinfo.useshellexecute#property-value
// UseShellExecute = true;
Status.Text = "Opening URL...";
if (int.TryParse(AppId.Text, out var appId))
{
if (appId > 0)
{
var searchTerm = appId;//$"{Game.Text.Replace(" ", "+")}+{appId}";
var destinationUrl =
"https://cs.rin.ru/forum/search.php?keywords=" +
searchTerm +
"&terms=any&fid[]=10&sf=firstpost&sr=topics&submit=Search";
var uri = new Uri(destinationUrl);
var process = new ProcessStartInfo(uri.AbsoluteUri)
{
UseShellExecute = true
};
Process.Start(process);
}
else
{
MyLogger.Log.Error($"OpenURL: Invalid AppID {appId}");
Status.Text = $"Could not open URL: Invalid AppID {appId}";
}
}
else
{
MyLogger.Log.Error($"OpenURL: Invalid AppID {appId}");
Status.Text = $"Could not open URL: Invalid AppID {appId}";
}
} }
} }
} }

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@ using System.Text.Json.Serialization;
namespace auto_creamapi.POCOs namespace auto_creamapi.POCOs
{ {
public class App public class SteamApp
{ {
[JsonPropertyName("appid")] [JsonPropertyName("appid")]
public int AppId { get; set; } public int AppId { get; set; }
@ -16,21 +16,21 @@ namespace auto_creamapi.POCOs
return $"AppId: {AppId}, Name: {Name}"; return $"AppId: {AppId}, Name: {Name}";
} }
public bool CompareId(App app) public bool CompareId(SteamApp steamApp)
{ {
return AppId.Equals(app.AppId); return AppId.Equals(steamApp.AppId);
} }
} }
public class Applist public class AppList
{ {
[JsonPropertyName("apps")] [JsonPropertyName("apps")]
public List<App> Apps { get; set; } public List<SteamApp> Apps { get; set; }
} }
public class SteamApps public class SteamApps
{ {
[JsonPropertyName("applist")] [JsonPropertyName("applist")]
public Applist AppList { get; set; } public AppList AppList { get; set; }
} }
} }

View File

@ -13,7 +13,7 @@
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label Content="Select a game..." HorizontalAlignment="Left" Margin="0,0,0,10" VerticalAlignment="Top"/> <Label Content="Select a game..." HorizontalAlignment="Left" Margin="0,0,0,10" VerticalAlignment="Top"/>
<DataGrid Name="DgApps" Grid.Row="1" AutoGenerateColumns="False" IsReadOnly="True" SelectionMode="Single" d:DataContext="{d:DesignInstance poco:App}" MouseDoubleClick="DgApps_OnMouseDoubleClick"> <DataGrid Name="DgApps" Grid.Row="1" AutoGenerateColumns="False" IsReadOnly="True" SelectionMode="Single" d:DataContext="{d:DesignInstance poco:SteamApp}" MouseDoubleClick="DgApps_OnMouseDoubleClick">
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTextColumn Header="AppID" Binding="{Binding AppId}"></DataGridTextColumn> <DataGridTextColumn Header="AppID" Binding="{Binding AppId}"></DataGridTextColumn>
<DataGridTextColumn Header="Game Name" Binding="{Binding Name}"></DataGridTextColumn> <DataGridTextColumn Header="Game Name" Binding="{Binding Name}"></DataGridTextColumn>

View File

@ -11,6 +11,7 @@ using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Shapes; using System.Windows.Shapes;
using auto_creamapi.POCOs;
using auto_creamapi.Utils; using auto_creamapi.Utils;
using NinjaNye.SearchExtensions; using NinjaNye.SearchExtensions;
using NinjaNye.SearchExtensions.Models; using NinjaNye.SearchExtensions.Models;
@ -22,7 +23,7 @@ namespace auto_creamapi
/// </summary> /// </summary>
public partial class SearchResultWindow public partial class SearchResultWindow
{ {
public SearchResultWindow(IEnumerable<POCOs.App> list) public SearchResultWindow(IEnumerable<SteamApp> list)
{ {
InitializeComponent(); InitializeComponent();
DgApps.ItemsSource = list; DgApps.ItemsSource = list;
@ -47,11 +48,14 @@ namespace auto_creamapi
{ {
if (Application.Current.MainWindow is MainWindow currentMainWindow) if (Application.Current.MainWindow is MainWindow currentMainWindow)
{ {
var app = (POCOs.App) DgApps.SelectedItem; var app = (SteamApp) DgApps.SelectedItem;
if (app != null)
{
MyLogger.Log.Information($"Successfully got app {app}"); MyLogger.Log.Information($"Successfully got app {app}");
currentMainWindow.Game.Text = app.Name; currentMainWindow.Game.Text = app.Name;
currentMainWindow.AppId.Text = app.AppId.ToString(); currentMainWindow.AppId.Text = app.AppId.ToString();
} }
}
Close(); Close();
} }

View File

@ -22,19 +22,18 @@
<ItemGroup> <ItemGroup>
<Page Include="App.xaml" /> <Page Include="App.xaml" />
<Page Remove="ConsoleApp1\**" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Remove="ConsoleApp1\**" /> <Content Include="README.md">
</ItemGroup> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<ItemGroup> <Content Include="COPYING">
<EmbeddedResource Remove="ConsoleApp1\**" /> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</ItemGroup> </Content>
<Content Include="CourierPrime-Regular.ttf">
<ItemGroup> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<None Remove="ConsoleApp1\**" /> </Content>
</ItemGroup> </ItemGroup>
</Project> </Project>