- Unselected DLC are now properly disabled within SmokeAPI through the use of the override parameter
This commit is contained in:
pointfeev 2022-06-09 17:22:29 -05:00
parent 4a2861c364
commit 851e4ccaf5
5 changed files with 52 additions and 19 deletions

View file

@ -5,7 +5,7 @@
<UseWindowsForms>True</UseWindowsForms> <UseWindowsForms>True</UseWindowsForms>
<ApplicationIcon>Resources\ini.ico</ApplicationIcon> <ApplicationIcon>Resources\ini.ico</ApplicationIcon>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract> <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<Version>3.5.0.5</Version> <Version>3.5.1.0</Version>
<PackageIcon>Resources\ini.ico</PackageIcon> <PackageIcon>Resources\ini.ico</PackageIcon>
<PackageLicenseFile>LICENSE</PackageLicenseFile> <PackageLicenseFile>LICENSE</PackageLicenseFile>
<Copyright>2021, pointfeev (https://github.com/pointfeev)</Copyright> <Copyright>2021, pointfeev (https://github.com/pointfeev)</Copyright>

View file

@ -56,26 +56,39 @@ internal partial class InstallForm : CustomForm
} }
} }
internal static void WriteSmokeConfiguration(StreamWriter writer, bool unlockAll, SortedList<string, (DlcType type, string name, string icon)> dlc, List<(string id, string name, SortedList<string, (DlcType type, string name, string icon)> dlc)> extraDlc, InstallForm installForm = null) internal static void WriteSmokeConfiguration(StreamWriter writer, SortedList<string, (DlcType type, string name, string icon)> overrideDlc, SortedList<string, (DlcType type, string name, string icon)> allDlc, InstallForm installForm = null)
{ {
Thread.Sleep(0); Thread.Sleep(0);
writer.WriteLine("{"); writer.WriteLine("{");
writer.WriteLine(" \"$version\": 1,"); writer.WriteLine(" \"$version\": 1,");
writer.WriteLine(" \"logging\": false,"); writer.WriteLine(" \"logging\": false,");
writer.WriteLine(" \"hook_steamclient\": true,"); writer.WriteLine(" \"hook_steamclient\": true,");
writer.WriteLine(" \"unlock_all\": " + (unlockAll ? "true" : "false") + ","); writer.WriteLine(" \"unlock_all\": true,");
writer.WriteLine(" \"override\": [],"); if (overrideDlc.Count > 0)
{
writer.WriteLine(" \"override\": [");
KeyValuePair<string, (DlcType type, string name, string icon)> lastOverrideDlc = overrideDlc.Last();
foreach (KeyValuePair<string, (DlcType type, string name, string icon)> pair in overrideDlc)
{
Thread.Sleep(0);
string dlcId = pair.Key;
(_, string dlcName, _) = pair.Value;
writer.WriteLine($" {dlcId}{(pair.Equals(lastOverrideDlc) ? "" : ",")}");
if (installForm is not null)
installForm.UpdateUser($"Added override DLC to SmokeAPI.json with appid {dlcId} ({dlcName})", InstallationLog.Action, info: false);
}
writer.WriteLine(" ],");
}
else
writer.WriteLine(" \"override\": [],");
writer.WriteLine(" \"dlc_ids\": ["); writer.WriteLine(" \"dlc_ids\": [");
IEnumerable<KeyValuePair<string, (DlcType type, string name, string icon)>> dlcs = dlc.ToList(); KeyValuePair<string, (DlcType type, string name, string icon)> lastAllDlc = allDlc.Last();
foreach ((string id, string name, SortedList<string, (DlcType type, string name, string icon)> _dlc) in extraDlc) foreach (KeyValuePair<string, (DlcType type, string name, string icon)> pair in allDlc)
dlcs = dlcs.Concat(_dlc);
KeyValuePair<string, (DlcType type, string name, string icon)> lastDlc = dlcs.Last();
foreach (KeyValuePair<string, (DlcType type, string name, string icon)> pair in dlcs)
{ {
Thread.Sleep(0); Thread.Sleep(0);
string dlcId = pair.Key; string dlcId = pair.Key;
(_, string dlcName, _) = pair.Value; (_, string dlcName, _) = pair.Value;
writer.WriteLine($" {dlcId}{(pair.Equals(lastDlc) ? "" : ",")}"); writer.WriteLine($" {dlcId}{(pair.Equals(lastAllDlc) ? "" : ",")}");
if (installForm is not null) if (installForm is not null)
installForm.UpdateUser($"Added DLC to SmokeAPI.json with appid {dlcId} ({dlcName})", InstallationLog.Action, info: false); installForm.UpdateUser($"Added DLC to SmokeAPI.json with appid {dlcId} ({dlcName})", InstallationLog.Action, info: false);
} }
@ -151,7 +164,16 @@ internal partial class InstallForm : CustomForm
installForm.UpdateUser("Generating SmokeAPI configuration for " + selection.Name + $" in directory \"{directory}\" . . . ", InstallationLog.Operation); installForm.UpdateUser("Generating SmokeAPI configuration for " + selection.Name + $" in directory \"{directory}\" . . . ", InstallationLog.Operation);
File.Create(config).Close(); File.Create(config).Close();
StreamWriter writer = new(config, true, Encoding.UTF8); StreamWriter writer = new(config, true, Encoding.UTF8);
WriteSmokeConfiguration(writer, selection.SelectedDlc.Count >= selection.AllDlc.Count, selection.SelectedDlc, selection.ExtraDlc, installForm); IEnumerable<KeyValuePair<string, (DlcType type, string name, string icon)>> allDlc = selection.AllDlc.AsEnumerable();
foreach ((string id, string name, SortedList<string, (DlcType type, string name, string icon)> extraDlc) in selection.ExtraDlc)
allDlc = allDlc.Concat(extraDlc);
IEnumerable<KeyValuePair<string, (DlcType type, string name, string icon)>> overrideDlc = allDlc.Except(selection.SelectedDlc);
foreach ((string id, string name, SortedList<string, (DlcType type, string name, string icon)> extraDlc) in selection.ExtraSelectedDlc)
overrideDlc = overrideDlc.Except(extraDlc);
WriteSmokeConfiguration(writer,
new(overrideDlc.ToDictionary(pair => pair.Key, pair => pair.Value), AppIdComparer.Comparer),
new(allDlc.ToDictionary(pair => pair.Key, pair => pair.Value), AppIdComparer.Comparer),
installForm);
writer.Flush(); writer.Flush();
writer.Close(); writer.Close();
}); });
@ -287,7 +309,7 @@ internal partial class InstallForm : CustomForm
installForm.UpdateUser("Generating ScreamAPI configuration for " + selection.Name + $" in directory \"{directory}\" . . . ", InstallationLog.Operation); installForm.UpdateUser("Generating ScreamAPI configuration for " + selection.Name + $" in directory \"{directory}\" . . . ", InstallationLog.Operation);
File.Create(config).Close(); File.Create(config).Close();
StreamWriter writer = new(config, true, Encoding.UTF8); StreamWriter writer = new(config, true, Encoding.UTF8);
WriteScreamConfiguration(writer, selection.SelectedDlc, selection.ExtraDlc, installForm); WriteScreamConfiguration(writer, selection.SelectedDlc, selection.ExtraSelectedDlc, installForm);
writer.Flush(); writer.Flush();
writer.Close(); writer.Close();
}); });
@ -323,7 +345,7 @@ internal partial class InstallForm : CustomForm
{ {
Thread.Sleep(0); Thread.Sleep(0);
if (selection.IsSteam && selection.SelectedDlc.Any(d => d.Value.type is DlcType.Steam) if (selection.IsSteam && selection.SelectedDlc.Any(d => d.Value.type is DlcType.Steam)
|| selection.ExtraDlc.Any(item => item.dlc.Any(dlc => dlc.Value.type is DlcType.Steam))) || selection.ExtraSelectedDlc.Any(item => item.dlc.Any(dlc => dlc.Value.type is DlcType.Steam)))
{ {
directory.GetSmokeApiComponents(out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config); directory.GetSmokeApiComponents(out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config);
if (File.Exists(sdk32) || File.Exists(sdk32_o) || File.Exists(sdk64) || File.Exists(sdk64_o) || File.Exists(config)) if (File.Exists(sdk32) || File.Exists(sdk32_o) || File.Exists(sdk64) || File.Exists(sdk64_o) || File.Exists(config))
@ -337,7 +359,7 @@ internal partial class InstallForm : CustomForm
} }
} }
if (selection.IsEpic && selection.SelectedDlc.Any(d => d.Value.type is DlcType.EpicCatalogItem or DlcType.EpicEntitlement) if (selection.IsEpic && selection.SelectedDlc.Any(d => d.Value.type is DlcType.EpicCatalogItem or DlcType.EpicEntitlement)
|| selection.ExtraDlc.Any(item => item.dlc.Any(dlc => dlc.Value.type is DlcType.EpicCatalogItem or DlcType.EpicEntitlement))) || selection.ExtraSelectedDlc.Any(item => item.dlc.Any(dlc => dlc.Value.type is DlcType.EpicCatalogItem or DlcType.EpicEntitlement)))
{ {
directory.GetScreamApiComponents(out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config); directory.GetScreamApiComponents(out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config);
if (File.Exists(sdk32) || File.Exists(sdk32_o) || File.Exists(sdk64) || File.Exists(sdk64_o) || File.Exists(config)) if (File.Exists(sdk32) || File.Exists(sdk32_o) || File.Exists(sdk64) || File.Exists(sdk64_o) || File.Exists(config))

View file

@ -220,7 +220,7 @@ internal partial class SelectForm : CustomForm
} }
ProgramSelection selection = ProgramSelection.FromId(appId) ?? new(); ProgramSelection selection = ProgramSelection.FromId(appId) ?? new();
selection.Enabled = allCheckBox.Checked || selection.SelectedDlc.Any() || selection.ExtraDlc.Any(); selection.Enabled = allCheckBox.Checked || selection.SelectedDlc.Any() || selection.ExtraSelectedDlc.Any();
selection.Id = appId; selection.Id = appId;
selection.Name = appData?.name ?? name; selection.Name = appData?.name ?? name;
selection.RootDirectory = gameDirectory; selection.RootDirectory = gameDirectory;
@ -321,7 +321,7 @@ internal partial class SelectForm : CustomForm
} }
ProgramSelection selection = ProgramSelection.FromId(@namespace) ?? new(); ProgramSelection selection = ProgramSelection.FromId(@namespace) ?? new();
selection.Enabled = allCheckBox.Checked || selection.SelectedDlc.Any() || selection.ExtraDlc.Any(); selection.Enabled = allCheckBox.Checked || selection.SelectedDlc.Any() || selection.ExtraSelectedDlc.Any();
selection.Id = @namespace; selection.Id = @namespace;
selection.Name = name; selection.Name = name;
selection.RootDirectory = directory; selection.RootDirectory = directory;

View file

@ -29,11 +29,20 @@ internal static class ParadoxLauncher
if (paradoxLauncher is not null) if (paradoxLauncher is not null)
{ {
paradoxLauncher.ExtraDlc.Clear(); paradoxLauncher.ExtraDlc.Clear();
paradoxLauncher.ExtraSelectedDlc.Clear();
foreach (ProgramSelection selection in ProgramSelection.AllEnabled.Where(s => s != paradoxLauncher && s.Publisher == "Paradox Interactive")) foreach (ProgramSelection selection in ProgramSelection.AllEnabled.Where(s => s != paradoxLauncher && s.Publisher == "Paradox Interactive"))
paradoxLauncher.ExtraDlc.Add(new(selection.Id, selection.Name, selection.SelectedDlc)); {
paradoxLauncher.ExtraDlc.Add(new(selection.Id, selection.Name, selection.AllDlc));
paradoxLauncher.ExtraSelectedDlc.Add(new(selection.Id, selection.Name, selection.SelectedDlc));
}
if (!paradoxLauncher.ExtraDlc.Any()) if (!paradoxLauncher.ExtraDlc.Any())
{
foreach (ProgramSelection selection in ProgramSelection.AllSafe.Where(s => s != paradoxLauncher && s.Publisher == "Paradox Interactive")) foreach (ProgramSelection selection in ProgramSelection.AllSafe.Where(s => s != paradoxLauncher && s.Publisher == "Paradox Interactive"))
{
paradoxLauncher.ExtraDlc.Add(new(selection.Id, selection.Name, selection.AllDlc)); paradoxLauncher.ExtraDlc.Add(new(selection.Id, selection.Name, selection.AllDlc));
paradoxLauncher.ExtraSelectedDlc.Add(new(selection.Id, selection.Name, selection.AllDlc));
}
}
} }
} }

View file

@ -34,7 +34,9 @@ internal class ProgramSelection
internal readonly SortedList<string, (DlcType type, string name, string icon)> AllDlc = new(AppIdComparer.Comparer); internal readonly SortedList<string, (DlcType type, string name, string icon)> AllDlc = new(AppIdComparer.Comparer);
internal readonly SortedList<string, (DlcType type, string name, string icon)> SelectedDlc = new(AppIdComparer.Comparer); internal readonly SortedList<string, (DlcType type, string name, string icon)> SelectedDlc = new(AppIdComparer.Comparer);
internal readonly List<(string id, string name, SortedList<string, (DlcType type, string name, string icon)> dlc)> ExtraDlc = new(); // for Paradox Launcher
internal readonly List<(string id, string name, SortedList<string, (DlcType type, string name, string icon)> dlc)> ExtraDlc = new(); // for Paradox Launcher
internal readonly List<(string id, string name, SortedList<string, (DlcType type, string name, string icon)> dlc)> ExtraSelectedDlc = new(); // for Paradox Launcher
internal bool AreDllsLocked internal bool AreDllsLocked
{ {
@ -79,7 +81,7 @@ internal class ProgramSelection
break; break;
} }
} }
Enabled = SelectedDlc.Any() || ExtraDlc.Any(); Enabled = SelectedDlc.Any() || ExtraSelectedDlc.Any();
} }
internal ProgramSelection() => All.Add(this); internal ProgramSelection() => All.Add(this);