-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
54 lines (45 loc) · 1.81 KB
/
Program.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
using Microsoft.Extensions.Configuration;
using System;
using System.IO;
using System.Windows.Forms;
namespace UnsplashDesktopSetter
{
internal static class Program
{
private static IConfigurationRoot config;
public static readonly string apiUrl = "https://api.unsplash.com/";
public static readonly string verificationEndpoint = "stats/month";
public static readonly string wallpaperQueryEndpoint = "photos/random?query=wallpaper&count=1&";
public static string url;
public static string apiAccessKey = null;
private static void SetupProcess()
{
apiAccessKey = Environment.GetEnvironmentVariable("UWS_API_KEY", EnvironmentVariableTarget.User);
if (apiAccessKey != null)
{
Console.WriteLine("API Access key was found. Skipping setup process.");
return;
}
var setupWindow = new SetupWindow();
while (!setupWindow.submissionWasCorrect)
{
Application.Run(setupWindow);
}
Console.WriteLine($"API Access key registered to {Environment.UserName} (USER) environment variables.");
}
[STAThread]
static void Main()
{
config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.Build();
var key = config.GetSection("APIConfig:AccessKey").Value;
url = apiUrl + wallpaperQueryEndpoint + "client_id=" + key;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
SetupProcess();
Application.Run(new MainWindow());
}
}
}