Fixed crash while trying to get DLC with invalid AppID

This commit is contained in:
Jeddunk 2020-12-22 15:20:40 +01:00
parent b68f45d4d7
commit 56e92924ed
5 changed files with 38 additions and 16 deletions

2
.gitignore vendored
View File

@ -554,4 +554,4 @@ MigrationBackup/
# End of https://www.toptal.com/developers/gitignore/api/visualstudio,jetbrains,windows,visualstudiocode,rider,dotnetcore # End of https://www.toptal.com/developers/gitignore/api/visualstudio,jetbrains,windows,visualstudiocode,rider,dotnetcore
ConsoleApp1/ ConsoleApp1/
/Utils/CsRinRuLogin.cs /Utils/Secrets.cs

View File

@ -48,8 +48,7 @@
</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="11"/> <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 x:Name="Reset" Content="Reset" Margin="0,10,10,10" Height="20" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="40" Click="Reset_Click" Grid.Row="11"/> <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"/>
</Grid> </Grid>
</Window> </Window>

View File

@ -4,6 +4,7 @@ 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.Utils;
using Microsoft.Win32; using Microsoft.Win32;
namespace auto_creamapi namespace auto_creamapi
@ -98,6 +99,8 @@ namespace auto_creamapi
private async void GetListOfDlc_Click(object sender, RoutedEventArgs e) private async void GetListOfDlc_Click(object sender, RoutedEventArgs e)
{ {
if (int.TryParse(AppId.Text, out var appId)) if (int.TryParse(AppId.Text, out var appId))
{
if (appId > 0)
{ {
var app = new POCOs.App() {AppId = appId, Name = Game.Text}; var app = new POCOs.App() {AppId = appId, Name = Game.Text};
var listOfDlc = await _cacheModel.GetListOfDlc(app, var listOfDlc = await _cacheModel.GetListOfDlc(app,
@ -107,6 +110,11 @@ namespace auto_creamapi
listOfDlc.ForEach(x => result += $"{x.AppId}={x.Name}\n"); listOfDlc.ForEach(x => result += $"{x.AppId}={x.Name}\n");
ListOfDlcs.Text = result; ListOfDlcs.Text = result;
} }
else
{
MyLogger.Log.Error($"GetListOfDlc: Invalid AppID {appId}");
}
}
} }
/// <summary> /// <summary>
@ -153,9 +161,23 @@ namespace auto_creamapi
private void SetNameById() private void SetNameById()
{ {
if (int.TryParse(AppId.Text, out var appId)) if (int.TryParse(AppId.Text, out var appId))
{
if (appId > 0)
{ {
var app = _cacheModel.GetAppById(appId); var app = _cacheModel.GetAppById(appId);
if (app != null) Game.Text = app.Name; if (app != null)
{
Game.Text = app.Name;
}
else
{
MyLogger.Log.Error($"No app found for ID {appId}");
}
}
else
{
MyLogger.Log.Error($"SetNameById: Invalid AppID {appId}");
}
} }
} }

View File

@ -57,7 +57,7 @@ namespace auto_creamapi.Model
if (!(File.Exists("steam_api.dll") && File.Exists("steam_api64.dll"))) if (!(File.Exists("steam_api.dll") && File.Exists("steam_api64.dll")))
{ {
MyLogger.Log.Information("Missing files, trying to download..."); MyLogger.Log.Information("Missing files, trying to download...");
new Action(async() => await DownloadDll(CsRinRuLogin.Username, CsRinRuLogin.Password))(); new Action(async() => await DownloadDll(Secrets.ForumUsername, Secrets.ForumPassword))();
} }
else else
{ {

View File

@ -2,10 +2,11 @@ namespace auto_creamapi.Utils
{ {
/// <summary> /// <summary>
/// To use this: /// To use this:
/// Rename CsRinRuLogin_REMOVETHIS to CsRinRuLogin /// Rename file Secrets.EXAMPLE.cs to Secrets.cs
/// Rename class Secrets_REMOVETHIS to Secrets
/// Enter the relevant info below /// Enter the relevant info below
/// </summary> /// </summary>
public class CsRinRuLogin_REMOVETHIS public class Secrets_REMOVETHIS
{ {
public const string Username = "Enter username here"; public const string Username = "Enter username here";
public const string Password = "Enter password here"; public const string Password = "Enter password here";