-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHumbleKeysLibrarySettings.cs
More file actions
191 lines (165 loc) · 6.78 KB
/
HumbleKeysLibrarySettings.cs
File metadata and controls
191 lines (165 loc) · 6.78 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using Playnite.SDK;
using HumbleKeys.Extensions;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using HumbleKeys.Services;
using Playnite.SDK.Data;
namespace HumbleKeys
{
public enum RedemptionStoreType
{
None, // 0
Source, // 1
Tag, // 2
Category, // 3
Platform, // 4
}
public enum TagMethodology
{
None, // 0
Monthly, // 1
All, // 2
}
public enum UnredeemableMethodology
{
Tag, // 0
Delete, // 1
}
public class KeyInfo
{
public string Name { get; set; } // Description used anywhere else needed, other than for Playnite's "Source" field
public string SourceName { get; set; } // Exact match for Playnite's "Source" field, only used when Redemption Store is saved to Source
public Guid SourceId { get; set; } // "Source" field GUID found in Playnite
}
public class HumbleKeysLibrarySettings : ObservableObject, ISettings
{
private readonly HumbleKeysLibrary plugin;
private static readonly ILogger logger = LogManager.GetLogger();
private HumbleKeysLibrarySettings editingClone;
public bool ConnectAccount { get; set; } = false;
public bool IgnoreRedeemedKeys { get; set; } = false;
public bool AddKeyStatus { get; set; } = true;
public int RedemptionStore { get; set; } = (int)RedemptionStoreType.Source;
public bool AddLinks { get; set; } = true;
public bool ImportChoiceKeys { get; set; } = false;
public int TagWithBundleName { get; set; } = (int)TagMethodology.None;
public int UnredeemableKeyHandling { get; set; } = (int)UnredeemableMethodology.Tag;
public bool CacheEnabled { get; set; } = false;
[Obsolete("Deprecated, scheduled for deletion: Use TagWithBundleName instead")]
public string CurrentTagMethodology { get; set; }
[Obsolete("Deprecated, scheduled for deletion: Use UnredeemableKeyHandling instead")]
public string CurrentUnredeemableMethodology { get; set; }
public bool AddPlatformNintendo { get; set; } = true;
public bool AddPlatformWindows { get; set; } = true;
[DontSerialize]
public Dictionary<string, KeyInfo> keyTypeWhitelist = new Dictionary<string, KeyInfo>
{
//["epic"] = new KeyInfo { Name = "Epic", SourceName = "Epic" }, // This key type is valid so do we want to add it? I only have game dev asset keys at Epic myself right now but I assume this could be real games too
//["epic_keyless"] = new KeyInfo { Name = "Epic keyless", SourceName = "Epic" }, // Is this even a valid key type? I just guessed it might be because Humble mentions it has keyless Epic keys
["gog"] = new KeyInfo { Name = "GOG", SourceName = "GOG" },
["nintendo_direct"] = new KeyInfo { Name = "Nintendo", SourceName = "Nintendo" },
["origin"] = new KeyInfo { Name = "EA", SourceName = "EA app" },
["origin_keyless"] = new KeyInfo { Name = "EA keyless", SourceName = "EA app" },
["steam"] = new KeyInfo { Name = "Steam", SourceName = "Steam" },
};
[DontSerialize]
public bool IsUserLoggedIn
{
get
{
using (var view = plugin.PlayniteApi.WebViews.CreateOffscreenView(
new WebViewSettings
{
JavaScriptEnabled = false
}))
{
var api = new HumbleKeysAccountClient(view);
return api.GetIsUserLoggedIn();
}
}
}
[DontSerialize]
public RelayCommand<object> LoginCommand
{
get => new RelayCommand<object>((a) =>
{
Login();
});
}
public HumbleKeysLibrarySettings()
{
}
public HumbleKeysLibrarySettings(HumbleKeysLibrary plugin)
{
this.plugin = plugin;
var savedSettings = plugin.LoadPluginSettings<HumbleKeysLibrarySettings>();
if (savedSettings != null)
{
// Migrate old setting strings to enum ints; This code section is scheduled for deletion in the future
if (savedSettings.CurrentTagMethodology != null || savedSettings.CurrentUnredeemableMethodology != null)
{
switch (savedSettings.CurrentTagMethodology)
{
//case "none": // None is default, so already correct
case "monthly":
savedSettings.TagWithBundleName = (int)TagMethodology.Monthly;
break;
case "all":
savedSettings.TagWithBundleName = (int)TagMethodology.All;
break;
}
// Tag is default, so no need to fix
if (savedSettings.CurrentUnredeemableMethodology == "delete")
{
savedSettings.UnredeemableKeyHandling = (int)UnredeemableMethodology.Delete;
}
// Clear deprecated values so migration only happens once
savedSettings.CurrentTagMethodology = null;
savedSettings.CurrentUnredeemableMethodology = null;
// Save, otherwise values won't stick
plugin.SavePluginSettings(savedSettings);
}
// End settings migration section
LoadValues(savedSettings);
}
}
public void BeginEdit()
{
editingClone = this.GetClone();
}
public void CancelEdit()
{
LoadValues(editingClone);
}
public void EndEdit()
{
plugin.SavePluginSettings(this);
}
private void LoadValues(HumbleKeysLibrarySettings source)
{
source.CopyProperties(this, false, null, true);
}
public bool VerifySettings(out List<string> errors)
{
errors = new List<string>();
return true;
}
private void Login()
{
try
{
using (var view = plugin.PlayniteApi.WebViews.CreateView(490, 670))
{
var api = new HumbleKeysAccountClient(view);
api.Login();
}
OnPropertyChanged(nameof(IsUserLoggedIn));
}
catch (Exception e) when (!Debugger.IsAttached)
{
logger.Error(e, "Failed to authenticate user.");
}
}
}
}