-
Notifications
You must be signed in to change notification settings - Fork 808
Expand file tree
/
Copy pathSettingsEngine_Extras.cs
More file actions
95 lines (81 loc) · 2.6 KB
/
SettingsEngine_Extras.cs
File metadata and controls
95 lines (81 loc) · 2.6 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
using System.Net;
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
using Windows.Security.Credentials;
using UniGetUI.Core.Logging;
namespace UniGetUI.Core.SettingsEngine;
public partial class Settings
{
/*
*
*
*/
public static bool AreNotificationsDisabled()
{
return Get("DisableSystemTray") || Get("DisableNotifications");
}
public static bool AreUpdatesNotificationsDisabled()
{
return AreNotificationsDisabled() || Get("DisableUpdatesNotifications");
}
public static bool AreErrorNotificationsDisabled()
{
return AreNotificationsDisabled() || Get("DisableErrorNotifications");
}
public static bool AreSuccessNotificationsDisabled()
{
return AreNotificationsDisabled() || Get("DisableSuccessNotifications");
}
public static bool AreProgressNotificationsDisabled()
{
return AreNotificationsDisabled() || Get("DisableProgressNotifications");
}
public static Uri? GetProxyUrl()
{
if (!Settings.Get("EnableProxy")) return null;
string plainUrl = Settings.GetValue("ProxyURL");
Uri.TryCreate(plainUrl, UriKind.RelativeOrAbsolute, out Uri? var);
if(Settings.Get("EnableProxy") && var is null) Logger.Warn($"Proxy setting {plainUrl} is not valid");
return var;
}
private const string PROXY_RES_ID = "UniGetUI_proxy";
public static NetworkCredential? GetProxyCredentials()
{
try
{
var vault = new PasswordVault();
var credentials = vault.Retrieve(PROXY_RES_ID, Settings.GetValue("ProxyUsername"));
return new NetworkCredential()
{
UserName = credentials.UserName,
Password = credentials.Password,
};
}
catch (Exception ex)
{
Logger.Error("Could not retrieve Proxy credentials");
Logger.Error(ex);
return null;
}
}
public static void SetProxyCredentials(string username, string password)
{
try
{
var vault = new PasswordVault();
Settings.SetValue("ProxyUsername", username);
vault.Add(new PasswordCredential(PROXY_RES_ID, username, password));
}
catch (Exception ex)
{
Logger.Error("Cannot save Proxy credentials");
Logger.Error(ex);
}
}
public static JsonSerializerOptions SerializationOptions = new()
{
TypeInfoResolver = new DefaultJsonTypeInfoResolver(),
AllowTrailingCommas = true,
WriteIndented = true,
};
}