-
Notifications
You must be signed in to change notification settings - Fork 1
/
IsthereanydealCollectionSync.cs
87 lines (78 loc) · 3.74 KB
/
IsthereanydealCollectionSync.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using Playnite.SDK;
using Playnite.SDK.Events;
using Playnite.SDK.Models;
using Playnite.SDK.Plugins;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace IsthereanydealCollectionSync
{
public class IsthereanydealCollectionSync : GenericPlugin
{
private static readonly ILogger logger = LogManager.GetLogger();
private IsthereanydealCollectionSyncSettingsViewModel settings { get; set; }
public override Guid Id { get; } = Guid.Parse("1f1c327f-8896-47de-950c-c92dc9fab556");
public IsthereanydealCollectionSync(IPlayniteAPI api) : base(api)
{
settings = new IsthereanydealCollectionSyncSettingsViewModel(this);
Properties = new GenericPluginProperties
{
HasSettings = true
};
}
public override IEnumerable<GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
{
yield return new GameMenuItem
{
Description = "Add to IsThereAnyDeal Collection",
Action = (itemArgs) =>
{
PlayniteApi.Dialogs.ActivateGlobalProgress(new Func<GlobalProgressActionArgs, Task>(async (progressArgs) =>
{
try
{
//TODO: globalProgressActionArgs.CancelToken.IsCancellationRequested and add true to GlobalProgressOptions
using (var view = PlayniteApi.WebViews.CreateOffscreenView())
{
var client = new IsthereanydealClient(this, view);
if (!await client.GetIsUserLoggedIn())
{
PlayniteApi.Dialogs.ShowErrorMessage("User not logged in.\n\nLog into IsThereAnyDeal in \"Add-ons...\" settings", "IsThereAnyDeal Collection Sync");
return;
}
var json = await client.generateImportJson(settings.Settings.ImportGroup, itemArgs.Games);
var result = await client.Import(json, settings.Settings.ImportModeReplace, settings.Settings.RemoveFromWaitlist);
PlayniteApi.Dialogs.ShowMessage($"Sent {itemArgs.Games.Count} games to IsThereAnyDeal\n\nIsThereAnyDeal response:\n{result}\n\n\"added\" will be reduced if games are already in collection\n\"copies imported\" will be reduced if \"ignore games already in collection\" setting is used", "IsThereAnyDeal Collection Sync");
}
}
catch (Exception ex)
{
PlayniteApi.Dialogs.ShowErrorMessage(ex.ToString(), "IsThereAnyDeal Collection Sync Error");
}
}), new GlobalProgressOptions($"Importing games into Is There Any Deal collection"));
}
};
}
public override void OnGameInstalled(OnGameInstalledEventArgs args)
{
// Add code to be executed when game is finished installing.
}
public override void OnLibraryUpdated(OnLibraryUpdatedEventArgs args)
{
// Add code to be executed when library is updated.
}
public override ISettings GetSettings(bool firstRunSettings)
{
return settings;
}
public override UserControl GetSettingsView(bool firstRunSettings)
{
return new IsthereanydealCollectionSyncSettingsView();
}
}
}