2022-03-03 16:38:17 +05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2022-03-07 07:43:46 +05:00
|
|
|
|
using CreamInstaller.Components;
|
|
|
|
|
|
2022-03-03 16:38:17 +05:00
|
|
|
|
namespace CreamInstaller;
|
|
|
|
|
|
2022-03-05 04:10:34 +05:00
|
|
|
|
internal enum DlcType
|
|
|
|
|
{
|
|
|
|
|
Default = 0,
|
|
|
|
|
CatalogItem = 1,
|
|
|
|
|
Entitlement = 2
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-03 16:38:17 +05:00
|
|
|
|
internal class ProgramSelection
|
|
|
|
|
{
|
2022-03-09 04:58:52 +05:00
|
|
|
|
internal bool Enabled;
|
2022-03-03 16:38:17 +05:00
|
|
|
|
internal bool Usable = true;
|
|
|
|
|
|
|
|
|
|
internal string Id = "0";
|
|
|
|
|
internal string Name = "Program";
|
|
|
|
|
|
2022-03-09 04:58:52 +05:00
|
|
|
|
internal string ProductUrl;
|
|
|
|
|
internal string IconUrl;
|
|
|
|
|
internal string SubIconUrl;
|
2022-03-03 16:38:17 +05:00
|
|
|
|
|
2022-03-09 04:58:52 +05:00
|
|
|
|
internal string Publisher;
|
2022-03-03 17:47:48 +05:00
|
|
|
|
|
2022-03-09 04:58:52 +05:00
|
|
|
|
internal string RootDirectory;
|
|
|
|
|
internal List<string> DllDirectories;
|
2022-03-03 16:38:17 +05:00
|
|
|
|
|
2022-03-09 04:58:52 +05:00
|
|
|
|
internal bool IsSteam;
|
2022-03-03 16:38:17 +05:00
|
|
|
|
|
2022-03-07 07:43:46 +05:00
|
|
|
|
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);
|
2022-03-05 04:10:34 +05:00
|
|
|
|
internal readonly List<Tuple<string, string, SortedList<string, (DlcType type, string name, string icon)>>> ExtraDlc = new(); // for Paradox Launcher
|
2022-03-03 16:38:17 +05:00
|
|
|
|
|
|
|
|
|
internal bool AreDllsLocked
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
foreach (string directory in DllDirectories)
|
|
|
|
|
{
|
2022-03-08 00:40:48 +05:00
|
|
|
|
directory.GetCreamApiComponents(out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config);
|
|
|
|
|
if (sdk32.IsFilePathLocked()
|
|
|
|
|
|| sdk32_o.IsFilePathLocked()
|
|
|
|
|
|| sdk64.IsFilePathLocked()
|
|
|
|
|
|| sdk64_o.IsFilePathLocked()
|
|
|
|
|
|| config.IsFilePathLocked())
|
2022-03-03 16:38:17 +05:00
|
|
|
|
return true;
|
2022-03-08 00:40:48 +05:00
|
|
|
|
directory.GetScreamApiComponents(out sdk32, out sdk32_o, out sdk64, out sdk64_o, out config);
|
|
|
|
|
if (sdk32.IsFilePathLocked()
|
|
|
|
|
|| sdk32_o.IsFilePathLocked()
|
2022-03-03 16:38:17 +05:00
|
|
|
|
|| sdk64.IsFilePathLocked()
|
|
|
|
|
|| sdk64_o.IsFilePathLocked()
|
2022-03-08 00:40:48 +05:00
|
|
|
|
|| config.IsFilePathLocked())
|
2022-03-03 16:38:17 +05:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-05 04:10:34 +05:00
|
|
|
|
private void Toggle(string dlcAppId, (DlcType type, string name, string icon) dlcApp, bool enabled)
|
2022-03-03 16:38:17 +05:00
|
|
|
|
{
|
|
|
|
|
if (enabled) SelectedDlc[dlcAppId] = dlcApp;
|
|
|
|
|
else SelectedDlc.Remove(dlcAppId);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-05 04:10:34 +05:00
|
|
|
|
internal void ToggleDlc(string dlcId, bool enabled)
|
2022-03-03 16:38:17 +05:00
|
|
|
|
{
|
2022-03-05 04:10:34 +05:00
|
|
|
|
foreach (KeyValuePair<string, (DlcType type, string name, string icon)> pair in AllDlc)
|
2022-03-03 16:38:17 +05:00
|
|
|
|
{
|
|
|
|
|
string appId = pair.Key;
|
2022-03-05 04:10:34 +05:00
|
|
|
|
(DlcType type, string name, string icon) dlcApp = pair.Value;
|
|
|
|
|
if (appId == dlcId)
|
2022-03-03 16:38:17 +05:00
|
|
|
|
{
|
|
|
|
|
Toggle(appId, dlcApp, enabled);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-06 07:14:42 +05:00
|
|
|
|
Enabled = SelectedDlc.Any() || ExtraDlc.Any();
|
2022-03-03 16:38:17 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal ProgramSelection() => All.Add(this);
|
|
|
|
|
|
|
|
|
|
internal void Validate()
|
|
|
|
|
{
|
|
|
|
|
if (Program.IsGameBlocked(Name, RootDirectory))
|
|
|
|
|
{
|
|
|
|
|
All.Remove(this);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!Directory.Exists(RootDirectory))
|
|
|
|
|
{
|
|
|
|
|
All.Remove(this);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DllDirectories.RemoveAll(directory => !Directory.Exists(directory));
|
|
|
|
|
if (!DllDirectories.Any()) All.Remove(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static void ValidateAll() => AllSafe.ForEach(selection => selection.Validate());
|
|
|
|
|
|
|
|
|
|
internal static List<ProgramSelection> All = new();
|
|
|
|
|
|
|
|
|
|
internal static List<ProgramSelection> AllSafe => All.ToList();
|
|
|
|
|
|
|
|
|
|
internal static List<ProgramSelection> AllUsable => All.FindAll(s => s.Usable);
|
|
|
|
|
|
|
|
|
|
internal static List<ProgramSelection> AllUsableEnabled => AllUsable.FindAll(s => s.Enabled);
|
|
|
|
|
|
2022-03-05 04:10:34 +05:00
|
|
|
|
internal static ProgramSelection FromId(string gameId) => AllUsable.Find(s => s.Id == gameId);
|
2022-03-03 16:38:17 +05:00
|
|
|
|
|
2022-03-05 04:10:34 +05:00
|
|
|
|
internal static (string gameId, (DlcType type, string name, string icon) app)? GetDlcFromId(string dlcId)
|
2022-03-03 16:38:17 +05:00
|
|
|
|
{
|
|
|
|
|
foreach (ProgramSelection selection in AllUsable)
|
2022-03-05 04:10:34 +05:00
|
|
|
|
foreach (KeyValuePair<string, (DlcType type, string name, string icon)> pair in selection.AllDlc)
|
|
|
|
|
if (pair.Key == dlcId) return (selection.Id, pair.Value);
|
2022-03-03 16:38:17 +05:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|