mirror of
https://github.com/FroggMaster/CreamInstaller.git
synced 2026-06-12 19:11:25 -07:00
9318fd7768
- Large refactoring & optimization - Fixed & optimized right-click context menu - Fixed silent HTTP cache concurrency exception - Added a better SafeIO exception output for anti-virus detections - Updated the help button dialog
166 lines
8.1 KiB
C#
166 lines
8.1 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using CreamInstaller.Components;
|
|
using CreamInstaller.Forms;
|
|
using CreamInstaller.Utility;
|
|
|
|
namespace CreamInstaller.Resources;
|
|
|
|
internal static class ScreamAPI
|
|
{
|
|
internal static void GetScreamApiComponents(this string directory, out string api32, out string api32_o, out string api64, out string api64_o,
|
|
out string config, out string log)
|
|
{
|
|
api32 = directory + @"\EOSSDK-Win32-Shipping.dll";
|
|
api32_o = directory + @"\EOSSDK-Win32-Shipping_o.dll";
|
|
api64 = directory + @"\EOSSDK-Win64-Shipping.dll";
|
|
api64_o = directory + @"\EOSSDK-Win64-Shipping_o.dll";
|
|
config = directory + @"\ScreamAPI.json";
|
|
log = directory + @"\ScreamAPI.log";
|
|
}
|
|
|
|
internal static void CheckConfig(string directory, Selection selection, InstallForm installForm = null)
|
|
{
|
|
directory.GetScreamApiComponents(out _, out _, out _, out _, out string config, out _);
|
|
List<SelectionDLC> overrideCatalogItems = selection.DLC.Where(dlc => dlc.Type is DLCType.EpicCatalogItem && !dlc.Enabled).ToList();
|
|
List<SelectionDLC> overrideEntitlements = selection.DLC.Where(dlc => dlc.Type is DLCType.EpicEntitlement && !dlc.Enabled).ToList();
|
|
foreach (Selection extraSelection in selection.ExtraSelections)
|
|
{
|
|
overrideCatalogItems.AddRange(extraSelection.DLC.Where(dlc => dlc.Type is DLCType.EpicCatalogItem && !dlc.Enabled));
|
|
overrideEntitlements.AddRange(extraSelection.DLC.Where(dlc => dlc.Type is DLCType.EpicEntitlement && !dlc.Enabled));
|
|
}
|
|
if (overrideCatalogItems.Count > 0 || overrideEntitlements.Count > 0)
|
|
{
|
|
/*if (installForm is not null)
|
|
installForm.UpdateUser("Generating ScreamAPI configuration for " + selection.Name + $" in directory \"{directory}\" . . . ", LogTextBox.Operation);*/
|
|
config.CreateFile(true, installForm).Close();
|
|
StreamWriter writer = new(config, true, Encoding.UTF8);
|
|
WriteConfig(writer, new(overrideCatalogItems.ToDictionary(dlc => dlc.Id, dlc => dlc), PlatformIdComparer.String),
|
|
new(overrideEntitlements.ToDictionary(dlc => dlc.Id, dlc => dlc), PlatformIdComparer.String), installForm);
|
|
writer.Flush();
|
|
writer.Close();
|
|
}
|
|
else if (config.FileExists())
|
|
{
|
|
config.DeleteFile();
|
|
installForm?.UpdateUser($"Deleted unnecessary configuration: {Path.GetFileName(config)}", LogTextBox.Action, false);
|
|
}
|
|
}
|
|
|
|
private static void WriteConfig(TextWriter writer, SortedList<string, SelectionDLC> overrideCatalogItems, SortedList<string, SelectionDLC> entitlements,
|
|
InstallForm installForm = null)
|
|
{
|
|
writer.WriteLine("{");
|
|
writer.WriteLine(" \"version\": 2,");
|
|
writer.WriteLine(" \"logging\": false,");
|
|
writer.WriteLine(" \"eos_logging\": false,");
|
|
writer.WriteLine(" \"block_metrics\": false,");
|
|
writer.WriteLine(" \"catalog_items\": {");
|
|
writer.WriteLine(" \"unlock_all\": true,");
|
|
if (overrideCatalogItems.Count > 0)
|
|
{
|
|
writer.WriteLine(" \"override\": [");
|
|
KeyValuePair<string, SelectionDLC> lastOverrideCatalogItem = overrideCatalogItems.Last();
|
|
foreach (KeyValuePair<string, SelectionDLC> pair in overrideCatalogItems)
|
|
{
|
|
SelectionDLC selectionDlc = pair.Value;
|
|
writer.WriteLine($" \"{selectionDlc.Id}\"{(pair.Equals(lastOverrideCatalogItem) ? "" : ",")}");
|
|
installForm?.UpdateUser($"Added locked catalog item to ScreamAPI.json with id {selectionDlc.Id} ({selectionDlc.Name})", LogTextBox.Action,
|
|
false);
|
|
}
|
|
writer.WriteLine(" ]");
|
|
}
|
|
else
|
|
writer.WriteLine(" \"override\": []");
|
|
writer.WriteLine(" },");
|
|
writer.WriteLine(" \"entitlements\": {");
|
|
writer.WriteLine(" \"unlock_all\": true,");
|
|
writer.WriteLine(" \"auto_inject\": true,");
|
|
if (entitlements.Count > 0)
|
|
{
|
|
writer.WriteLine(" \"inject\": [");
|
|
KeyValuePair<string, SelectionDLC> lastEntitlement = entitlements.Last();
|
|
foreach (KeyValuePair<string, SelectionDLC> pair in entitlements)
|
|
{
|
|
SelectionDLC selectionDlc = pair.Value;
|
|
writer.WriteLine($" \"{selectionDlc.Id}\"{(pair.Equals(lastEntitlement) ? "" : ",")}");
|
|
installForm?.UpdateUser($"Added locked entitlement to ScreamAPI.json with id {selectionDlc.Id} ({selectionDlc.Name})", LogTextBox.Action,
|
|
false);
|
|
}
|
|
writer.WriteLine(" ]");
|
|
}
|
|
else
|
|
writer.WriteLine(" \"inject\": []");
|
|
writer.WriteLine(" }");
|
|
writer.WriteLine("}");
|
|
}
|
|
|
|
internal static async Task Uninstall(string directory, InstallForm installForm = null, bool deleteOthers = true)
|
|
=> await Task.Run(() =>
|
|
{
|
|
directory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string config, out string log);
|
|
if (api32_o.FileExists())
|
|
{
|
|
if (api32.FileExists())
|
|
{
|
|
api32.DeleteFile();
|
|
installForm?.UpdateUser($"Deleted ScreamAPI: {Path.GetFileName(api32)}", LogTextBox.Action, false);
|
|
}
|
|
api32_o.MoveFile(api32!);
|
|
installForm?.UpdateUser($"Restored EOS: {Path.GetFileName(api32_o)} -> {Path.GetFileName(api32)}", LogTextBox.Action, false);
|
|
}
|
|
if (api64_o.FileExists())
|
|
{
|
|
if (api64.FileExists())
|
|
{
|
|
api64.DeleteFile();
|
|
installForm?.UpdateUser($"Deleted ScreamAPI: {Path.GetFileName(api64)}", LogTextBox.Action, false);
|
|
}
|
|
api64_o.MoveFile(api64!);
|
|
installForm?.UpdateUser($"Restored EOS: {Path.GetFileName(api64_o)} -> {Path.GetFileName(api64)}", LogTextBox.Action, false);
|
|
}
|
|
if (!deleteOthers)
|
|
return;
|
|
if (config.FileExists())
|
|
{
|
|
config.DeleteFile();
|
|
installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(config)}", LogTextBox.Action, false);
|
|
}
|
|
if (log.FileExists())
|
|
{
|
|
log.DeleteFile();
|
|
installForm?.UpdateUser($"Deleted log: {Path.GetFileName(log)}", LogTextBox.Action, false);
|
|
}
|
|
});
|
|
|
|
internal static async Task Install(string directory, Selection selection, InstallForm installForm = null, bool generateConfig = true)
|
|
=> await Task.Run(() =>
|
|
{
|
|
directory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out _, out _);
|
|
if (api32.FileExists() && !api32_o.FileExists())
|
|
{
|
|
api32.MoveFile(api32_o!);
|
|
installForm?.UpdateUser($"Renamed EOS: {Path.GetFileName(api32)} -> {Path.GetFileName(api32_o)}", LogTextBox.Action, false);
|
|
}
|
|
if (api32_o.FileExists())
|
|
{
|
|
"ScreamAPI.EOSSDK-Win32-Shipping.dll".WriteManifestResource(api32);
|
|
installForm?.UpdateUser($"Wrote ScreamAPI: {Path.GetFileName(api32)}", LogTextBox.Action, false);
|
|
}
|
|
if (api64.FileExists() && !api64_o.FileExists())
|
|
{
|
|
api64.MoveFile(api64_o!);
|
|
installForm?.UpdateUser($"Renamed EOS: {Path.GetFileName(api64)} -> {Path.GetFileName(api64_o)}", LogTextBox.Action, false);
|
|
}
|
|
if (api64_o.FileExists())
|
|
{
|
|
"ScreamAPI.EOSSDK-Win64-Shipping.dll".WriteManifestResource(api64);
|
|
installForm?.UpdateUser($"Wrote ScreamAPI: {Path.GetFileName(api64)}", LogTextBox.Action, false);
|
|
}
|
|
if (generateConfig)
|
|
CheckConfig(directory, selection, installForm);
|
|
});
|
|
} |