-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
162 lines (154 loc) · 6.01 KB
/
MainWindow.xaml.cs
File metadata and controls
162 lines (154 loc) · 6.01 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
using NAudio.CoreAudioApi;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Media;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
namespace beforewindeploy
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
SoundPlayer soundPlayer = new SoundPlayer();
private MMDeviceEnumerator deviceEnumerator;
private MMDevice defaultDevice;
public MainWindow()
{
InitializeComponent();
this.Topmost = true;
try
{
soundPlayer.SoundLocation = $@"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\title.wav";
soundPlayer.PlayLooping();
}
catch { }
deviceEnumerator = new MMDeviceEnumerator();
defaultDevice = deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
if (defaultDevice == null)
{
muteButton.IsEnabled = false;
}
if (defaultDevice.AudioEndpointVolume.Mute == true)
{
muteButton.Content = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/beforewindeploy;component/speakerMute.png")),
Width = 30,
Height = 30,
Stretch = System.Windows.Media.Stretch.Uniform
};
}
else
{
muteButton.Content = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/beforewindeploy;component/speakerUnmute.png")),
Width = 30,
Height = 30,
Stretch = System.Windows.Media.Stretch.Uniform
};
}
defaultDevice.AudioEndpointVolume.OnVolumeNotification += OnVolumeNotification;
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
var result = iNKORE.UI.WPF.Modern.Controls.MessageBox.Show("Are you sure you want to exit?", "Exit", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes)
{
var result2 = iNKORE.UI.WPF.Modern.Controls.MessageBox.Show("Do you want to restart the app?", "Exit", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (result2 == MessageBoxResult.Yes)
{
Process process = new Process();
process.StartInfo.FileName = Assembly.GetExecutingAssembly().Location;
process.StartInfo.Verb = "runas";
process.Start();
}
Process.GetCurrentProcess().Kill();
}
}
private void usbButton_Click(object sender, RoutedEventArgs e)
{
ProcessingChanges processingChanges = new ProcessingChanges(true, false, false);
processingChanges.Show();
this.Hide();
}
private void serverButton_Click(object sender, RoutedEventArgs e)
{
ProcessingChanges processingChanges = new ProcessingChanges(false, true, false);
processingChanges.Show();
this.Hide();
}
private void skipButton_Click(object sender, RoutedEventArgs e)
{
ProcessingChanges processingChanges = new ProcessingChanges(false, false, true);
processingChanges.Show();
soundPlayer.Stop();
this.Hide();
}
private void muteButton_Click(object sender, RoutedEventArgs e)
{
defaultDevice.AudioEndpointVolume.Mute = !defaultDevice.AudioEndpointVolume.Mute;
if (defaultDevice.AudioEndpointVolume.Mute == true)
{
muteButton.Content = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/beforewindeploy;component/speakerMute.png")),
Width = 30,
Height = 30,
Stretch = System.Windows.Media.Stretch.Uniform
};
} else
{
muteButton.Content = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/beforewindeploy;component/speakerUnmute.png")),
Width = 30,
Height = 30,
Stretch = System.Windows.Media.Stretch.Uniform
};
}
}
private void OnVolumeNotification(AudioVolumeNotificationData data)
{
// Check if invoking is required (i.e., if we're not on the UI thread)
if (!Dispatcher.CheckAccess())
{
// Invoke the method on the UI thread
Dispatcher.Invoke(() => OnVolumeNotification(data));
return;
}
if (defaultDevice.AudioEndpointVolume.Mute == true)
{
muteButton.Content = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/beforewindeploy;component/speakerMute.png")),
Width = 30,
Height = 30,
Stretch = System.Windows.Media.Stretch.Uniform
};
}
else
{
muteButton.Content = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/beforewindeploy;component/speakerUnmute.png")),
Width = 30,
Height = 30,
Stretch = System.Windows.Media.Stretch.Uniform
};
}
}
}
}