Skip to content

Commit

Permalink
Add SDL for EpicGames
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Sep 12, 2023
1 parent 8d876c5 commit 5f5e2df
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 8 deletions.
1 change: 1 addition & 0 deletions Launcher/Forms/FormTemplates/Toggle.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public Toggle(FormEntry entry) : this()
{
ToggleSwitch.OffContent = entry.Name;
ToggleSwitch.OnContent = entry.Name;
ToggleSwitch.IsEnabled = entry.Enabled;
ToggleSwitch.IsChecked = int.Parse(entry.Value) != 0;
ToggleSwitch.Checked += (_, _) =>
{
Expand Down
4 changes: 2 additions & 2 deletions LauncherGamePlugin/Forms/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public static FormEntry ClickableLinkBox(string text, Action<Form> action,
FormAlignment alignment = FormAlignment.Default, string fontWeight = "")
=> new(FormEntryType.ClickableLinkBox, text, alignment: alignment, linkClick: x => action(x.ContainingForm), value: fontWeight);

public static FormEntry Toggle(string label, bool value, FormAlignment alignment = FormAlignment.Default)
=> new(FormEntryType.Toggle, label, value ? "1" : "0", alignment: alignment);
public static FormEntry Toggle(string label, bool value, FormAlignment alignment = FormAlignment.Default, bool enabled = true)
=> new(FormEntryType.Toggle, label, value ? "1" : "0", alignment: alignment, enabled: enabled);

public static FormEntry FilePicker(string label, string value = "")
=> new(FormEntryType.FilePicker, label, value);
Expand Down
4 changes: 3 additions & 1 deletion LauncherGamePlugin/Forms/FormEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class FormEntry
{
public string Name { get; set; }
public string Value { get; set; }
public bool Enabled { get; set; }
public FormEntryType Type { get; set; }
public Action<FormEntry> LinkClick { get; set; }
public List<string> DropdownOptions { get; set; }
Expand All @@ -51,11 +52,12 @@ public class FormEntry
public void InvokeOnChange() => OnChange?.Invoke(this);

public FormEntry(FormEntryType type, string name = "", string value = "", List<string> dropdownOptions = null,

Check warning on line 54 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-linux

Cannot convert null literal to non-nullable reference type.

Check warning on line 54 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-linux

Cannot convert null literal to non-nullable reference type.

Check warning on line 54 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-windows

Cannot convert null literal to non-nullable reference type.

Check warning on line 54 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-windows

Cannot convert null literal to non-nullable reference type.

Check warning on line 54 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-windows

Non-nullable property 'ContainingForm' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
List<ButtonEntry> buttonList = null, Action<FormEntry> linkClick = null, Func<Task<byte[]?>> image = null, List<FormEntry> horizontalPanel = null, FormAlignment alignment = FormAlignment.Default)
List<ButtonEntry> buttonList = null, Action<FormEntry> linkClick = null, Func<Task<byte[]?>> image = null, List<FormEntry> horizontalPanel = null, FormAlignment alignment = FormAlignment.Default, bool enabled = true)

Check warning on line 55 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-linux

Cannot convert null literal to non-nullable reference type.

Check warning on line 55 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-linux

Cannot convert null literal to non-nullable reference type.

Check warning on line 55 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-linux

Cannot convert null literal to non-nullable reference type.

Check warning on line 55 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-linux

Cannot convert null literal to non-nullable reference type.

Check warning on line 55 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-linux

Cannot convert null literal to non-nullable reference type.

Check warning on line 55 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-linux

Cannot convert null literal to non-nullable reference type.

Check warning on line 55 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-windows

Cannot convert null literal to non-nullable reference type.

Check warning on line 55 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-windows

Cannot convert null literal to non-nullable reference type.

Check warning on line 55 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-windows

Cannot convert null literal to non-nullable reference type.

Check warning on line 55 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-windows

Cannot convert null literal to non-nullable reference type.

Check warning on line 55 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-windows

Cannot convert null literal to non-nullable reference type.

Check warning on line 55 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-windows

Cannot convert null literal to non-nullable reference type.

Check warning on line 55 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-windows

Cannot convert null literal to non-nullable reference type.

Check warning on line 55 in LauncherGamePlugin/Forms/FormEntry.cs

View workflow job for this annotation

GitHub Actions / build-windows

Cannot convert null literal to non-nullable reference type.
{
Type = type;
Name = name;
Value = value;
Enabled = enabled;
DropdownOptions = dropdownOptions;
ButtonList = buttonList;
LinkClick = linkClick;
Expand Down
58 changes: 58 additions & 0 deletions LegendaryIntegration/LegendaryGameSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using LauncherGamePlugin.Launcher;
using LegendaryIntegration.Extensions;
using LegendaryIntegration.Gui;
using LegendaryIntegration.Model;
using LegendaryIntegration.Service;
using Newtonsoft.Json;

namespace LegendaryIntegration;

Expand Down Expand Up @@ -211,12 +213,68 @@ public async void Uninstall(LegendaryGame game)
App.HideForm();
}

public async Task<string> UrlGet(string url)
{
using (HttpClient client = new())
{
return await client.GetStringAsync(url);
}
}

private Dictionary<string, string> _sdl_games = new()
{
{ "Fortnite", "https://legendary.gl/v1/sdl/Fortnite.json" },
{ "Ginger", "https://legendary.gl/v1/sdl/Ginger.json" }
};

public async void Download(LegendaryGame game)
{
if (_sdl_games.ContainsKey(game.InternalName))
{
string data = await UrlGet(_sdl_games[game.InternalName]);
Dictionary<string, LegendaryTags> tags =
JsonConvert.DeserializeObject<Dictionary<string, LegendaryTags>>(data)!;

List<FormEntry> entries = new()
{
Form.TextBox($"{game.Name} Optional Content", FormAlignment.Center, "Bold")
};

foreach (var x in tags)
{
entries.Add(Form.Toggle(x.Value.Name, x.Key == "__required", enabled: x.Key != "__required"));
}

entries.Add(Form.Button("Back", _ => App.HideForm(), "Install", x =>
{
App.HideForm();
DownloadSDL(x, tags, game);
}));
App.ShowForm(new(entries));
return;
}

await game.StartDownload();
game.Download!.OnCompletionOrCancel += _ => App.ReloadGames();
}

public async void DownloadSDL(Form form, Dictionary<string, LegendaryTags> tags, LegendaryGame game)
{
List<string> installTags = new();

foreach (var x in tags)
{
string value = form.GetValue(x.Value.Name)!;
if (value == "1")
{
installTags.AddRange(x.Value.Tags);
}
}

await game.StartDownload(tags: installTags);
game.Download!.OnCompletionOrCancel += _ => App.ReloadGames();
}

public async void Repair(LegendaryGame game)
{
await game.Repair();
Expand Down
8 changes: 8 additions & 0 deletions LegendaryIntegration/Model/LegendaryTags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace LegendaryIntegration.Model;

public class LegendaryTags
{
public string Description { get; set; }

Check warning on line 5 in LegendaryIntegration/Model/LegendaryTags.cs

View workflow job for this annotation

GitHub Actions / build-linux

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string Name { get; set; }

Check warning on line 6 in LegendaryIntegration/Model/LegendaryTags.cs

View workflow job for this annotation

GitHub Actions / build-linux

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public List<string> Tags { get; set; }

Check warning on line 7 in LegendaryIntegration/Model/LegendaryTags.cs

View workflow job for this annotation

GitHub Actions / build-linux

Non-nullable property 'Tags' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}
15 changes: 12 additions & 3 deletions LegendaryIntegration/Service/LegendaryDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,22 @@ public class LegendaryDownload : ProgressStatus
private string _path;
private string _line1 = "";
private string _line2 = "";
private List<string> _tags;

public override string Line1 => _line1;
public override string Line2 => _line2;

public LegendaryDownload(LegendaryGame game, LegendaryStatusType type, string? path = null)
public LegendaryDownload(LegendaryGame game, LegendaryStatusType type, string? path = null, List<string>? tags = null)
{
Game = game;
Type = type;
_tags = tags ?? new();

if (_tags.Count > 0)
{
_tags.Add("");
}

if (Game.Download != null)
throw new Exception("Game already has a download active");

Expand Down Expand Up @@ -137,12 +145,13 @@ public async void Start()

return;
}


string tags = string.Join(" ", _tags.Select(x => $"--install-tag \"{x}\""));

if (Type == LegendaryStatusType.Repair)
await _terminal.ExecLegendary($"-y repair {Game.InternalName}");
else
await _terminal.ExecLegendary($"-y install {Game.InternalName} --skip-sdl --game-folder \"{_path}\"");
await _terminal.ExecLegendary($"-y install {Game.InternalName} --skip-sdl --game-folder \"{_path}\" {tags}");
if (!_terminal.Killed)
OnCompletionOrCancel?.Invoke(this);
}
Expand Down
4 changes: 2 additions & 2 deletions LegendaryIntegration/Service/LegendaryGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ await Task.Run(() => output.Mutate(x => x
return localInfo;
}

public async Task StartDownload(LegendaryStatusType type = LegendaryStatusType.Download, string? path = null)
public async Task StartDownload(LegendaryStatusType type = LegendaryStatusType.Download, string? path = null, List<string>? tags = null)
{
await GetInfo();

try
{
ReattachDownload(new(this, type, path));
ReattachDownload(new(this, type, path, tags));
Parser.AddDownload(Download!);
}
catch
Expand Down

0 comments on commit 5f5e2df

Please sign in to comment.