Add option to ignore unknown DLC from SteamDB.

Show amount of DLCs after getting list of DLCs successfully.
This commit is contained in:
Jeddunk 2021-01-04 16:14:10 +01:00
parent 2cfb7dc654
commit 1d69b7b45a
4 changed files with 42 additions and 13 deletions

View File

@ -6,6 +6,6 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" mc:Ignorable="d"
Title="Auto-CreamAPI 2" MinWidth="420" MinHeight="600" Width="420" Height="600"> Title="Auto-CreamAPI 2" MinWidth="420" MinHeight="640" Width="560" Height="720">
<Grid /> <Grid />
</views:MvxWindow> </views:MvxWindow>

View File

@ -24,7 +24,7 @@ namespace auto_creamapi.Services
public IEnumerable<SteamApp> GetListOfAppsByName(string name); public IEnumerable<SteamApp> GetListOfAppsByName(string name);
public SteamApp GetAppByName(string name); public SteamApp GetAppByName(string name);
public SteamApp GetAppById(int appid); public SteamApp GetAppById(int appid);
public Task<List<SteamApp>> GetListOfDlc(SteamApp steamApp, bool useSteamDb); public Task<List<SteamApp>> GetListOfDlc(SteamApp steamApp, bool useSteamDb, bool ignoreUnknown);
} }
public class CacheService : ICacheService public class CacheService : ICacheService
@ -99,7 +99,7 @@ namespace auto_creamapi.Services
return app; return app;
} }
public async Task<List<SteamApp>> GetListOfDlc(SteamApp steamApp, bool useSteamDb) public async Task<List<SteamApp>> GetListOfDlc(SteamApp steamApp, bool useSteamDb, bool ignoreUnknown)
{ {
MyLogger.Log.Information("Get DLC"); MyLogger.Log.Information("Get DLC");
var dlcList = new List<SteamApp>(); var dlcList = new List<SteamApp>();
@ -164,6 +164,12 @@ namespace auto_creamapi.Services
var query3 = element.QuerySelectorAll("td"); var query3 = element.QuerySelectorAll("td");
if (query3 != null) dlcName = query3[1].Text().Replace("\n", "").Trim(); if (query3 != null) dlcName = query3[1].Text().Replace("\n", "").Trim();
if (ignoreUnknown && dlcName.Contains("SteamDB Unknown App"))
{
MyLogger.Log.Information($"Skipping SteamDB Unknown App {dlcId}");
}
else
{
var dlcApp = new SteamApp {AppId = Convert.ToInt32(dlcId), Name = dlcName}; var dlcApp = new SteamApp {AppId = Convert.ToInt32(dlcId), Name = dlcName};
var i = dlcList.FindIndex(x => x.AppId.Equals(dlcApp.AppId)); var i = dlcList.FindIndex(x => x.AppId.Equals(dlcApp.AppId));
if (i > -1) if (i > -1)
@ -175,6 +181,7 @@ namespace auto_creamapi.Services
dlcList.Add(dlcApp); dlcList.Add(dlcApp);
} }
} }
}
dlcList.ForEach(x => MyLogger.Log.Debug($"{x.AppId}={x.Name}")); dlcList.ForEach(x => MyLogger.Log.Debug($"{x.AppId}={x.Name}"));
MyLogger.Log.Information("Got DLC from SteamDB successfully..."); MyLogger.Log.Information("Got DLC from SteamDB successfully...");

View File

@ -38,6 +38,8 @@ namespace auto_creamapi.ViewModels
private bool _unlockAll; private bool _unlockAll;
private bool _useSteamDb; private bool _useSteamDb;
private bool _ignoreUnknown;
//private const string DlcRegexPattern = @"(?<id>.*) *= *(?<name>.*)"; //private const string DlcRegexPattern = @"(?<id>.*) *= *(?<name>.*)";
public MainViewModel(ICacheService cache, ICreamConfigService config, ICreamDllService dll, public MainViewModel(ICacheService cache, ICreamConfigService config, ICreamDllService dll,
@ -224,6 +226,16 @@ namespace auto_creamapi.ViewModels
} }
} }
public bool IgnoreUnknown
{
get => _ignoreUnknown;
set
{
_ignoreUnknown = value;
RaisePropertyChanged(() => IgnoreUnknown);
}
}
private async Task OpenFile() private async Task OpenFile()
{ {
Status = "Waiting for file..."; Status = "Waiting for file...";
@ -251,12 +263,16 @@ namespace auto_creamapi.ViewModels
var separator = Path.DirectorySeparatorChar; var separator = Path.DirectorySeparatorChar;
var strings = new List<string>(dirPath.Split(separator)); var strings = new List<string>(dirPath.Split(separator));
var index = strings.Contains("common") ? strings.FindIndex(x => x.Equals("common")) + 1 : -1; var index = strings.Contains("common") ? strings.FindIndex(x => x.Equals("common")) + 1 : -1;
if (index == -1) index = strings.Contains("steamapps") ? strings.FindIndex(x => x.Equals("steamapps")) + 2 : -1; if (index == -1)
index = strings.Contains("steamapps")
? strings.FindIndex(x => x.Equals("steamapps")) + 2
: -1;
var s = index > -1 ? strings[index] : null; var s = index > -1 ? strings[index] : null;
if (s != null) GameName = s; if (s != null) GameName = s;
await Search(); await Search();
await GetListOfDlc(); await GetListOfDlc();
} }
Status = "Ready."; Status = "Ready.";
} }
} }
@ -289,12 +305,14 @@ namespace auto_creamapi.ViewModels
AppId = navigateResult.AppId; AppId = navigateResult.AppId;
} }
} }
await GetListOfDlc(); await GetListOfDlc();
} }
else else
{ {
MyLogger.Log.Warning("Empty game name, cannot initiate search!"); MyLogger.Log.Warning("Empty game name, cannot initiate search!");
} }
MainWindowEnabled = true; MainWindowEnabled = true;
} }
@ -304,14 +322,14 @@ namespace auto_creamapi.ViewModels
if (AppId > 0) if (AppId > 0)
{ {
var app = new SteamApp {AppId = AppId, Name = GameName}; var app = new SteamApp {AppId = AppId, Name = GameName};
var task = _cache.GetListOfDlc(app, UseSteamDb); var task = _cache.GetListOfDlc(app, UseSteamDb, IgnoreUnknown);
MainWindowEnabled = false; MainWindowEnabled = false;
var listOfDlc = await task; var listOfDlc = await task;
if (task.IsCompletedSuccessfully) if (task.IsCompletedSuccessfully)
{ {
listOfDlc.Sort((app1, app2) => app1.AppId.CompareTo(app2.AppId)); listOfDlc.Sort((app1, app2) => app1.AppId.CompareTo(app2.AppId));
Dlcs = new ObservableCollection<SteamApp>(listOfDlc); Dlcs = new ObservableCollection<SteamApp>(listOfDlc);
Status = $"Got DLC for AppID {AppId}"; Status = $"Got DLC for AppID {AppId} (Count: {Dlcs.Count})";
} }
else else
{ {

View File

@ -74,6 +74,7 @@
<GroupBox Header="DLC" Grid.Row="0" VerticalAlignment="Stretch"> <GroupBox Header="DLC" Grid.Row="0" VerticalAlignment="Stretch">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
@ -85,6 +86,9 @@
<CheckBox Content="Additionally use SteamDB for DLCs" <CheckBox Content="Additionally use SteamDB for DLCs"
IsChecked="{Binding UseSteamDb, Mode=TwoWay}" HorizontalAlignment="Left" IsChecked="{Binding UseSteamDb, Mode=TwoWay}" HorizontalAlignment="Left"
Margin="10,10,0,0" VerticalAlignment="Top" Grid.Row="1" /> Margin="10,10,0,0" VerticalAlignment="Top" Grid.Row="1" />
<CheckBox Content="Ignore unknown DLC from SteamDB" IsEnabled="{Binding UseSteamDb}"
IsChecked="{Binding IgnoreUnknown, Mode=TwoWay}" HorizontalAlignment="Left"
Margin="10,10,0,0" VerticalAlignment="Top" Grid.Row="2" />
<!-- Text="{Binding Dlcs, Converter={StaticResource DlcConv}, Mode=TwoWay}"--> <!-- Text="{Binding Dlcs, Converter={StaticResource DlcConv}, Mode=TwoWay}"-->
<!-- Text="{Binding DlcsString, Mode=TwoWay}"--> <!-- Text="{Binding DlcsString, Mode=TwoWay}"-->
<wcl:WatermarkTextBox <wcl:WatermarkTextBox
@ -92,9 +96,9 @@
Margin="10,10,10,0" Watermark="List of DLCs...&#xA;0000 = DLC Name" Margin="10,10,10,0" Watermark="List of DLCs...&#xA;0000 = DLC Name"
TextWrapping="Wrap" AcceptsReturn="True" TextWrapping="Wrap" AcceptsReturn="True"
VerticalScrollBarVisibility="Visible" Padding="0" VerticalScrollBarVisibility="Visible" Padding="0"
FontFamily="../resources/#Courier Prime" Grid.Row="2" /> FontFamily="../resources/#Courier Prime" Grid.Row="3" />
<Button Content="Get DLCs for AppID" Margin="0,10,10,10" Height="19.96" HorizontalAlignment="Right" <Button Content="Get DLCs for AppID" Margin="0,10,10,10" Height="19.96" HorizontalAlignment="Right"
VerticalAlignment="Bottom" Width="108" Command="{Binding GetListOfDlcCommand}" Grid.Row="3" /> VerticalAlignment="Bottom" Width="108" Command="{Binding GetListOfDlcCommand}" Grid.Row="4" />
</Grid> </Grid>
</GroupBox> </GroupBox>
<GroupBox Header="Status" Grid.Row="1" VerticalAlignment="Bottom" IsEnabled="False"> <GroupBox Header="Status" Grid.Row="1" VerticalAlignment="Bottom" IsEnabled="False">