forked from molenzwiebel/Mimic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAboutWindow.xaml.cs
109 lines (93 loc) · 3.7 KB
/
AboutWindow.xaml.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using QRCoder;
using System;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
namespace Conduit
{
/// <summary>
/// Interaction logic for AboutWindow.xaml
/// </summary>
public partial class AboutWindow : Window
{
public AboutWindow()
{
InitializeComponent();
Logo.Source = Imaging.CreateBitmapSourceFromHIcon(Properties.Resources.mimic.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
StartOnStartupCheckbox.IsChecked = Persistence.LaunchesAtStartup();
AboutTitle.Content = "Mimic Conduit v" + Program.VERSION;
if (Persistence.GetHubCode() != null)
{
RenderCode();
}
Persistence.OnHubCodeChanged += RenderCode;
}
/**
* Renders the current hub code. This assumes that a hub token exists and doesn't check for null.
*/
private void RenderCode()
{
Dispatcher.Invoke(() =>
{
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("https://remote.mimic.lol/" + Persistence.GetHubCode(), QRCodeGenerator.ECCLevel.Q);
XamlQRCode qrCode = new XamlQRCode(qrCodeData);
ConnectionQR.Source = qrCode.GetGraphic(20);
ConnectionQR.Visibility = Visibility.Visible;
CodeLabel.Content = Persistence.GetHubCode();
CodeLabel.Visibility = Visibility.Visible;
ConnectionSteps.Visibility = Visibility.Visible;
NoCodeText.Visibility = Visibility.Hidden;
});
}
/**
* Opens the project github link in the default browser.
*/
public void OpenGithub(object sender, EventArgs args)
{
Process.Start("https://github.com/molenzwiebel/mimic");
}
/**
* Opens the project discord in the default browser.
*/
public void OpenDiscord(object sender, EventArgs args)
{
Process.Start("https://discord.gg/bfxdsRC");
}
/**
* (Attempts to) uninstall sentinel.
*/
public void Uninstall(object sender, EventArgs args)
{
MessageBoxResult result = MessageBox.Show("Are you sure you want to uninstall Mimic Conduit? All files will be deleted.", "Mimic Conduit", MessageBoxButton.YesNo);
if (result == MessageBoxResult.No) return;
// Step 1: Delete AppData.
try { Directory.Delete(Persistence.DATA_DIRECTORY, true); } catch { /* ignored */ }
// Step 2: Unlink launch-on-start if enabled.
if (Persistence.LaunchesAtStartup()) Persistence.ToggleLaunchAtStartup();
// Step 3: Delete Executable.
Process.Start(new ProcessStartInfo
{
Arguments = "/C choice /C Y /N /D Y /T 3 & Del " + System.Reflection.Assembly.GetExecutingAssembly().Location,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
FileName = "cmd.exe"
});
// Step 4: Stop Program.
Application.Current.Shutdown();
}
/**
* Invoked when window closes, unregisters from persistence listeners.
*/
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Persistence.OnHubCodeChanged -= RenderCode;
}
private void HandleStartupChange(object sender, EventArgs e)
{
Persistence.ToggleLaunchAtStartup();
}
}
}