Skip to content

Commit

Permalink
Remote: Save downloaded content types
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Jun 9, 2024
1 parent 2316dfb commit 6dc5e86
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 14 deletions.
6 changes: 5 additions & 1 deletion RemoteDownloaderPlugin/Game/GameDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ public class GameDownload : ProgressStatus
public string Version { get; private set; }
public GameType Type { get; private set; }
public string BaseFileName { get; private set; }
public ContentTypes InstalledEntries { get; private set; }

public GameDownload(IEntry entry)
{
_entry = entry;
InstalledEntries = new();
}

private void OnProgressUpdate(object? obj, float progress)
Expand Down Expand Up @@ -65,6 +67,7 @@ private async Task DownloadEmu(IApp app, EmuEntry entry)

for (int i = 0; i < entry.Files.Count; i++)
{

Progress<float> localProcess = new();
localProcess.ProgressChanged += (sender, f) =>
{
Expand All @@ -75,7 +78,8 @@ private async Task DownloadEmu(IApp app, EmuEntry entry)

var fileEntry = entry.Files[i];
var destPath = Path.Join(fileEntry.Type == "base" ? basePath : extraFilesPath, fileEntry.Name);

InstalledEntries.Add(fileEntry.Type);

if (fileEntry.Type == "base")
{
baseGamePath = destPath;
Expand Down
19 changes: 14 additions & 5 deletions RemoteDownloaderPlugin/Game/InstalledGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ public class InstalledGame : IGame
public long? Size => Game.GameSize;
public bool HasImage(ImageType type)
=> ImageTypeToUri(type) != null;

public bool IsEmu => _type == GameType.Emu;

public ContentTypes InstalledContentTypes => IsEmu
? _emuGame.Types
: new ContentTypes()
{
Base = 1
};

public Task<byte[]?> GetImage(ImageType type)
{
Expand All @@ -28,11 +37,11 @@ public bool HasImage(ImageType type)

public InstalledStatus InstalledStatus => InstalledStatus.Installed;

public Platform EstimatedGamePlatform => (_type == GameType.Emu)
public Platform EstimatedGamePlatform => IsEmu
? LauncherGamePlugin.Utils.GuessPlatformBasedOnString(_plugin.Storage.Data.EmuProfiles.FirstOrDefault(x => x.Platform == _emuGame!.Emu)?.ExecPath)
: LauncherGamePlugin.Utils.GuessPlatformBasedOnString(_pcLaunchDetails!.LaunchExec);

public string GamePlatform => (_type == GameType.Emu)
public string GamePlatform => IsEmu
? _emuGame!.Emu
: "Pc";

Expand Down Expand Up @@ -70,7 +79,7 @@ public void Play()
{
try
{
if (_type == GameType.Emu)
if (IsEmu)
{
var emuProfile = _plugin.Storage.Data.EmuProfiles.FirstOrDefault(x => x.Platform == _emuGame!.Emu);

Expand Down Expand Up @@ -103,7 +112,7 @@ public void Play()

public void Delete()
{
if (_type == GameType.Emu)
if (IsEmu)
{
var baseGamePath = Path.Join(_plugin.App.GameDir, "Remote", _emuGame!.Emu, _emuGame.BaseFilename);
var extraDir = Path.Join(_plugin.App.GameDir, "Remote", _emuGame!.Emu, Game.Id);
Expand Down Expand Up @@ -152,7 +161,7 @@ public void Delete()

public void OpenInFileManager()
{
LauncherGamePlugin.Utils.OpenFolder(_type == GameType.Emu
LauncherGamePlugin.Utils.OpenFolder(IsEmu
? Path.Join(_plugin.App.GameDir, "Remote", _emuGame!.Emu)
: Path.Join(_plugin.App.GameDir, "Remote", "Pc", Game.Id));
}
Expand Down
3 changes: 2 additions & 1 deletion RemoteDownloaderPlugin/Game/OnlineGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public async Task Download()
GameSize = _download.TotalSize,
Version = _download.Version,
BaseFilename = _download.BaseFileName,
Images = Entry.Img
Images = Entry.Img,
Types = _download.InstalledEntries
});
}
else
Expand Down
27 changes: 20 additions & 7 deletions RemoteDownloaderPlugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,32 @@ public List<Command> GetGameCommands(IGame game)

if (game is InstalledGame installedGame)
{
return new()
var commands = new List<Command>()
{
new Command(game.IsRunning ? "Running" : "Launch", installedGame.Play),
new Command("Open in File Manager", installedGame.OpenInFileManager),
new Command($"Version: {installedGame.Game.Version}"),
new Command($"Platform: {installedGame.GamePlatform}"),
new Command("Uninstall", () =>
App.Show2ButtonTextPrompt($"Do you want to uninstall {game.Name}?", "Yes", "No", _ =>
{
installedGame.Delete();
App.HideForm();
}, _ => App.HideForm(), game))
};

if (installedGame.IsEmu)
{
commands.Add(new());
commands.Add(new($"Base: {installedGame.InstalledContentTypes.Base}"));
commands.Add(new($"Update: {installedGame.InstalledContentTypes.Update}"));
commands.Add(new($"Dlc: {installedGame.InstalledContentTypes.Dlc}"));
commands.Add(new($"Extra: {installedGame.InstalledContentTypes.Extra}"));
commands.Add(new());
}

commands.Add(new Command("Uninstall", () =>
App.Show2ButtonTextPrompt($"Do you want to uninstall {game.Name}?", "Yes", "No", _ =>
{
installedGame.Delete();
App.HideForm();
}, _ => App.HideForm(), game)));

return commands;
}

throw new NotImplementedException();
Expand Down
28 changes: 28 additions & 0 deletions RemoteDownloaderPlugin/Store.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,33 @@ public interface IInstalledGame
public Images Images { get; }
}

public class ContentTypes
{
public int Base { get; set; }
public int Update { get; set; }
public int Dlc { get; set; }
public int Extra { get; set; }

public void Add(string type)
{
switch (type)
{
case "base":
Base++;
break;
case "update":
Update++;
break;
case "dlc":
Dlc++;
break;
case "extra":
Extra++;
break;
}
}
}

public class InstalledEmuGame : IInstalledGame
{
public string Id { get; set; }
Expand All @@ -26,6 +53,7 @@ public class InstalledEmuGame : IInstalledGame
public string Version { get; set; }
public string BaseFilename { get; set; }
public Images Images { get; set; }
public ContentTypes Types { get; set; } = new();
}

public class InstalledPcGame : IInstalledGame
Expand Down

0 comments on commit 6dc5e86

Please sign in to comment.