2023-01-05 01:23:32 +00:00
|
|
|
|
using Playnite.SDK;
|
|
|
|
|
using Playnite.SDK.Models;
|
|
|
|
|
using Playnite.SDK.Plugins;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
|
|
|
|
namespace LANCommander.Playnite.Extension
|
|
|
|
|
{
|
|
|
|
|
public class PlayniteLibraryPlugin : LibraryPlugin
|
|
|
|
|
{
|
|
|
|
|
public static readonly ILogger Logger = LogManager.GetLogger();
|
2023-01-05 07:07:17 +00:00
|
|
|
|
private PlayniteSettingsViewModel Settings { get; set; }
|
|
|
|
|
internal LANCommanderClient LANCommander { get; set; }
|
2023-01-05 01:23:32 +00:00
|
|
|
|
|
|
|
|
|
public override Guid Id { get; } = Guid.Parse("48e1bac7-e0a0-45d7-ba83-36f5e9e959fc");
|
|
|
|
|
public override string Name => "LANCommander";
|
|
|
|
|
public override LibraryClient Client { get; } = new PlayniteClient();
|
|
|
|
|
|
|
|
|
|
public PlayniteLibraryPlugin(IPlayniteAPI api) : base(api)
|
|
|
|
|
{
|
2023-01-05 02:31:02 +00:00
|
|
|
|
LANCommander = new LANCommanderClient();
|
2023-01-05 07:07:17 +00:00
|
|
|
|
Settings = new PlayniteSettingsViewModel(this);
|
2023-01-05 01:23:32 +00:00
|
|
|
|
Properties = new LibraryPluginProperties
|
|
|
|
|
{
|
|
|
|
|
HasSettings = true,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<GameMetadata> GetGames(LibraryGetGamesArgs args)
|
|
|
|
|
{
|
2023-01-05 07:07:17 +00:00
|
|
|
|
try
|
2023-01-05 02:31:02 +00:00
|
|
|
|
{
|
2023-01-05 07:07:17 +00:00
|
|
|
|
// Implement LANCommander client here
|
|
|
|
|
var games = LANCommander.GetGames().Select(g => new GameMetadata()
|
|
|
|
|
{
|
|
|
|
|
Name = g.Title,
|
|
|
|
|
Description = g.Description,
|
|
|
|
|
GameId = g.Id.ToString(),
|
|
|
|
|
ReleaseDate = new ReleaseDate(g.ReleasedOn),
|
|
|
|
|
SortingName = g.SortTitle,
|
|
|
|
|
Version = g.Archives != null && g.Archives.Count() > 0 ? g.Archives.OrderByDescending(a => a.CreatedOn).FirstOrDefault().Version : null,
|
|
|
|
|
});
|
2023-01-05 02:31:02 +00:00
|
|
|
|
|
2023-01-05 07:07:17 +00:00
|
|
|
|
return games;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return new List<GameMetadata>();
|
|
|
|
|
}
|
2023-01-05 01:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override ISettings GetSettings(bool firstRunSettings)
|
|
|
|
|
{
|
2023-01-05 07:07:17 +00:00
|
|
|
|
return Settings;
|
2023-01-05 01:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override UserControl GetSettingsView(bool firstRunView)
|
|
|
|
|
{
|
2023-01-05 07:07:17 +00:00
|
|
|
|
return new PlayniteSettingsView(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowAuthenticationWindow()
|
|
|
|
|
{
|
|
|
|
|
var window = PlayniteApi.Dialogs.CreateWindow(new WindowCreationOptions()
|
|
|
|
|
{
|
|
|
|
|
ShowMinimizeButton = false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.Title = "Authenticate to LANCommander";
|
|
|
|
|
|
|
|
|
|
window.Content = new PlayniteSettingsView(this);
|
|
|
|
|
|
|
|
|
|
window.Owner = PlayniteApi.Dialogs.GetCurrentAppWindow();
|
|
|
|
|
window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
|
|
|
|
|
window.ShowDialog();
|
2023-01-05 01:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|