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:d="http://schemas.microsoft.com/expression/blend/2008"
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 />
</views:MvxWindow>

View File

@ -24,7 +24,7 @@ namespace auto_creamapi.Services
public IEnumerable<SteamApp> GetListOfAppsByName(string name);
public SteamApp GetAppByName(string name);
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
@ -99,7 +99,7 @@ namespace auto_creamapi.Services
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");
var dlcList = new List<SteamApp>();
@ -164,15 +164,22 @@ namespace auto_creamapi.Services
var query3 = element.QuerySelectorAll("td");
if (query3 != null) dlcName = query3[1].Text().Replace("\n", "").Trim();
var dlcApp = new SteamApp {AppId = Convert.ToInt32(dlcId), Name = dlcName};
var i = dlcList.FindIndex(x => x.AppId.Equals(dlcApp.AppId));
if (i > -1)
if (ignoreUnknown && dlcName.Contains("SteamDB Unknown App"))
{
if (dlcList[i].Name.Contains("Unknown DLC")) dlcList[i] = dlcApp;
MyLogger.Log.Information($"Skipping SteamDB Unknown App {dlcId}");
}
else
{
dlcList.Add(dlcApp);
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);
}
}
}

View File

@ -38,6 +38,8 @@ namespace auto_creamapi.ViewModels
private bool _unlockAll;
private bool _useSteamDb;
private bool _ignoreUnknown;
//private const string DlcRegexPattern = @"(?<id>.*) *= *(?<name>.*)";
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()
{
Status = "Waiting for file...";
@ -251,12 +263,16 @@ namespace auto_creamapi.ViewModels
var separator = Path.DirectorySeparatorChar;
var strings = new List<string>(dirPath.Split(separator));
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;
if (s != null) GameName = s;
await Search();
await GetListOfDlc();
}
Status = "Ready.";
}
}
@ -289,12 +305,14 @@ namespace auto_creamapi.ViewModels
AppId = navigateResult.AppId;
}
}
await GetListOfDlc();
}
else
{
MyLogger.Log.Warning("Empty game name, cannot initiate search!");
}
MainWindowEnabled = true;
}
@ -304,14 +322,14 @@ namespace auto_creamapi.ViewModels
if (AppId > 0)
{
var app = new SteamApp {AppId = AppId, Name = GameName};
var task = _cache.GetListOfDlc(app, UseSteamDb);
var task = _cache.GetListOfDlc(app, UseSteamDb, IgnoreUnknown);
MainWindowEnabled = false;
var listOfDlc = await task;
if (task.IsCompletedSuccessfully)
{
listOfDlc.Sort((app1, app2) => app1.AppId.CompareTo(app2.AppId));
Dlcs = new ObservableCollection<SteamApp>(listOfDlc);
Status = $"Got DLC for AppID {AppId}";
Status = $"Got DLC for AppID {AppId} (Count: {Dlcs.Count})";
}
else
{

View File

@ -74,6 +74,7 @@
<GroupBox Header="DLC" Grid.Row="0" VerticalAlignment="Stretch">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
@ -85,6 +86,9 @@
<CheckBox Content="Additionally use SteamDB for DLCs"
IsChecked="{Binding UseSteamDb, Mode=TwoWay}" HorizontalAlignment="Left"
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 DlcsString, Mode=TwoWay}"-->
<wcl:WatermarkTextBox
@ -92,9 +96,9 @@
Margin="10,10,10,0" Watermark="List of DLCs...&#xA;0000 = DLC Name"
TextWrapping="Wrap" AcceptsReturn="True"
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"
VerticalAlignment="Bottom" Width="108" Command="{Binding GetListOfDlcCommand}" Grid.Row="3" />
VerticalAlignment="Bottom" Width="108" Command="{Binding GetListOfDlcCommand}" Grid.Row="4" />
</Grid>
</GroupBox>
<GroupBox Header="Status" Grid.Row="1" VerticalAlignment="Bottom" IsEnabled="False">