-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathMainWindow.xaml.cs
456 lines (383 loc) · 15.4 KB
/
MainWindow.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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
using MaterialDesignThemes.Wpf;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using TrueMiningDesktop.Core;
using TrueMiningDesktop.ViewModel;
using Application = System.Windows.Application;
using ListView = System.Windows.Controls.ListView;
using MessageBox = System.Windows.MessageBox;
using MessageBoxOptions = System.Windows.MessageBoxOptions;
using UserControl = System.Windows.Controls.UserControl;
namespace TrueMiningDesktop
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public static System.Windows.Forms.NotifyIcon NotifyIcon = new();
public static event EventHandler TapeAllRequest;
public MainWindow()
{
Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
Tools.PropertyChanged += Tools_PropertyChanged;
User.Settings.SettingsRecover();
InitializeComponent();
TapeAllRequest += CheckerPopup_TapeAllRequest;
Device.Cpu.what();
_ = new Device();
MenuMenu.Items.Add(new UserControlItemMenu(new ItemMenu("Home", Janelas.Pages.Home, PackIconKind.Home), this));
MenuMenu.Items.Add(new UserControlItemMenu(new ItemMenu("Dashboard", Janelas.Pages.Dashboard, PackIconKind.ViewDashboard), this));
MenuMenu.Items.Add(new UserControlItemMenu(new ItemMenu("Settings", Janelas.Pages.Settings, PackIconKind.Settings), this));
List<SubItem> menuConfigHardware = new()
{
new SubItem("CPU", Janelas.Pages.SettingsCPU),
new SubItem("AMD GPU", Janelas.Pages.SettingsOPENCL),
new SubItem("NVIDIA GPU", Janelas.Pages.SettingsCUDA)
};
MenuMenu.Items.Add(new UserControlItemMenu(new ItemMenu("Hardware Config", menuConfigHardware, PackIconKind.Gpu), this));
MenuMenu.Items.Add(new UserControlItemMenu(new ItemMenu("Other Stuff", new Janelas.Other(), PackIconKind.PlusBoxMultiple), this));
Janelas.Pages.Home.TitleWrapPanel.MouseDown += Down;
Janelas.Pages.Home.TitleWrapPanel.MouseMove += Move;
Janelas.Pages.Home.TitleWrapPanel.MouseUp += Up;
Janelas.Pages.Dashboard.TitleWrapPanel.MouseDown += Down;
Janelas.Pages.Dashboard.TitleWrapPanel.MouseMove += Move;
Janelas.Pages.Dashboard.TitleWrapPanel.MouseUp += Up;
Janelas.Pages.Settings.TitleWrapPanel.MouseDown += Down;
Janelas.Pages.Settings.TitleWrapPanel.MouseMove += Move;
Janelas.Pages.Settings.TitleWrapPanel.MouseUp += Up;
Janelas.Pages.SettingsCPU.TitleWrapPanel.MouseDown += Down;
Janelas.Pages.SettingsCPU.TitleWrapPanel.MouseMove += Move;
Janelas.Pages.SettingsCPU.TitleWrapPanel.MouseUp += Up;
Janelas.Pages.SettingsOPENCL.TitleWrapPanel.MouseDown += Down;
Janelas.Pages.SettingsOPENCL.TitleWrapPanel.MouseMove += Move;
Janelas.Pages.SettingsOPENCL.TitleWrapPanel.MouseUp += Up;
Janelas.Pages.SettingsCUDA.TitleWrapPanel.MouseDown += Down;
Janelas.Pages.SettingsCUDA.TitleWrapPanel.MouseMove += Move;
Janelas.Pages.SettingsCUDA.TitleWrapPanel.MouseUp += Up;
Application.Current.SessionEnding += Current_SessionEnding;
Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
Application.Current.MainWindow.Closing += MainWindow_Closing;
Application.Current.Exit += Current_Exit;
Tools.timerSystemAwake.Elapsed += Tools.AwakeSystem;
Tools.timerSystemAwake.Start();
}
private void MainWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
{
try
{
if (!windowsShutdowning && (Miner.IsMining || Miner.IsTryingStartMining))
{
if (MessageBoxResult.Yes == MessageBox.Show("Closing True Mining Desktop, mining will be stopped. Are you sure?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.None, MessageBoxOptions.DefaultDesktopOnly))
{
}
else { e.Cancel = true; return; }
}
if (!windowsShutdowning && Tools.CheckerPopup != null && Tools.CheckerPopup.Tape)
{
if (MessageBoxResult.Yes != MessageBox.Show("True Mining is checking and updating software files. Closing True Mining Desktop, process will be stopped. Are you sure?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.None, MessageBoxOptions.DefaultDesktopOnly))
{ e.Cancel = true; return; }
}
User.Settings.SettingsSaver(true);
this.Hide();
Miner.StopMiners(true);
NotifyIcon.Visible = false;
Miner.EmergencyExit = true;
Tools.CheckerPopup.Close();
Application.Current.Shutdown();
}
catch { }
}
private void Current_SessionEnding(object sender, SessionEndingCancelEventArgs e)
{
if (e.ReasonSessionEnding == ReasonSessionEnding.Shutdown || e.ReasonSessionEnding == ReasonSessionEnding.Logoff)
{
windowsShutdowning = true;
Miner.EmergencyExit = true;
Miner.StopMiners(true);
Application.Current.Shutdown();
}
}
private void Tools_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
Dispatcher.BeginInvoke((Action)(() =>
{
torIcon.Visibility = User.Settings.User.UseTorSharpOnMining ? Visibility.Visible : Visibility.Collapsed;
torIcon.Opacity = Tools.TorSharpEnabled ? 1 : Tools.TorSharpProcessesRunning ? 0.7 : User.Settings.User.UseTorSharpOnMining ? 0.4 : 0;
}));
}
private void Current_Exit(object sender, ExitEventArgs e)
{
try
{
Tools.TorSharpProxy.Stop();
Miner.EmergencyExit = true;
Miner.StopMiners(true);
}
catch { }
}
public static void DispararEvento()
{
TapeAllRequest.Invoke(null, null);
}
private void CheckerPopup_TapeAllRequest(object sender, EventArgs e)
{
if (Tools.CheckerPopup.Tape) { PanelTapeAll.Visibility = Visibility.Visible; } else { PanelTapeAll.Visibility = Visibility.Hidden; }
}
internal void SwitchScreen(UserControl userControl)
{
if (userControl != null)
{
TelaExibida.Children.Clear();
TelaExibida.Children.Add(userControl);
}
}
private void Menu_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Clicado = false;
if (((UserControlItemMenu)((ListView)sender).SelectedItem).ListViewMenu.Items.Count <= 0)
{
SwitchScreen(((UserControlItemMenu)((ListView)sender).SelectedItem).Screen);
}
bool expandItem = !((UserControlItemMenu)((ListView)sender).SelectedItem).ExpanderMenu.IsExpanded || ((UserControlItemMenu)((ListView)sender).SelectedItem) != ((UserControlItemMenu)((ListView)MenuMenu).SelectedItem);
for (int item = ((ListView)sender).Items.Count - 1; 0 <= item; item--)
{
if (((UserControlItemMenu)((ListView)sender).Items[item]) == ((UserControlItemMenu)((ListView)sender).SelectedItem))
{
((UserControlItemMenu)((ListView)sender).Items[item]).ExpanderMenu.IsExpanded = true;
}
else
{
((UserControlItemMenu)((ListView)sender).Items[item]).ExpanderMenu.IsExpanded = false;
}
}
Task.Run(() => User.Settings.SettingsSaver());
}
private void Menu_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (((ListView)sender).SelectedIndex >= 0)
{
Menu_SelectionChanged(sender, null);
}
}
private void WrapPanel_MouseDown(object sender, MouseButtonEventArgs e)
{
Task.Run(() => User.Settings.SettingsSaver());
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
if (!User.Settings.User.LICENSE_read)
{
if (MessageBoxResult.Yes == MessageBox.Show("By using the software in any way you are agreeing to the license located at " + Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", @"LICENSE.md") + "\n\nContinue?", "Accept True Mining License", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.None, MessageBoxOptions.DefaultDesktopOnly))
{
User.Settings.User.LICENSE_read = true;
}
else { Close(); }
}
try
{
CanvasSoftwareVersion.Text = "v" + Tools.GetAssemblyVersion();
CanvasSoftwareVersion.TextDecorations = null;
}
catch { }
TaskbarItemInfo = new System.Windows.Shell.TaskbarItemInfo();
Tools.TryChangeTaskbarIconAsSettingsOrder();
NotifyIcon.Visible = true;
NotifyIcon.MouseDown += Notifier_MouseDown;
Core.NextStart.Actions.Load();
if (Core.NextStart.Actions.loadedNextStartInstructions.useThisInstructions)
{
if (Core.NextStart.Actions.loadedNextStartInstructions.startHiden)
{
Hide();
}
else
{
ShowInTaskbar = true;
Activate();
Focus();
}
}
else
{
if (User.Settings.User.StartHide)
{
Hide();
}
else
{
ShowInTaskbar = true;
Activate();
Focus();
}
}
if (!Tools.HaveADM) { Janelas.Pages.Home.RestartAsAdministratorButton.Visibility = Visibility.Visible; Janelas.Pages.Home.WarningsTextBlock.Text += "You haven't opened True Mining as an administrator. Restart as ADM is recommended and generally results in a better hashrate"; } else { Janelas.Pages.Home.RestartAsAdministratorButton.Visibility = Visibility.Collapsed; }
if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + @"\Diebold\Warsaw\unins000.exe")) { Janelas.Pages.Home.UninstallWarsawDiebold.Visibility = Visibility.Visible; Janelas.Pages.Home.WarningsTextBlock.Text += "\nWarsaw Diebold found on your system. It is highly recommended to uninstall this agent. Click \"Remove Warsaw\""; } else { Janelas.Pages.Home.UninstallWarsawDiebold.Visibility = Visibility.Collapsed; }
MenuMenu.SelectedIndex = 0; // mostra a tela Home
Tools.CheckerPopup = new Janelas.CheckerPopup(Janelas.CheckerPopup.ToCheck.AppFiles);
Tools.CheckerPopup.ShowDialog();
try
{
List<string> coinList = new List<string>();
foreach (Server.PaymentCoin paymentCoin in Server.SoftwareParameters.ServerConfig.PaymentCoins)
{
if (!coinList.Contains(paymentCoin.CoinTicker + " - " + paymentCoin.CoinName))
{
coinList.Add(paymentCoin.CoinTicker + " - " + paymentCoin.CoinName);
}
}
User.Settings.User.Payment_CoinsList.Clear();
User.Settings.User.Payment_CoinsList.AddRange(coinList);
Dispatcher.BeginInvoke((Action)(() =>
{
Janelas.Pages.Home.DataContext = User.Settings.User;
}));
}
catch { }
try
{
List<string> algoListCpu = new List<string>();
List<string> algoListOpencl = new List<string>();
List<string> algoListCuda = new List<string>();
foreach (Server.MiningAlgorithm miningAlgorithm in Server.SoftwareParameters.ServerConfig.MiningAlgorithms)
{
if (miningAlgorithm.SuportedDevices.Contains("cpu")) { algoListCpu.Add(miningAlgorithm.AlgorithmName); }
if (miningAlgorithm.SuportedDevices.Contains("opencl")) { algoListOpencl.Add(miningAlgorithm.AlgorithmName); }
if (miningAlgorithm.SuportedDevices.Contains("cuda")) { algoListCuda.Add(miningAlgorithm.AlgorithmName); }
}
User.Settings.Device.cpu.AlgorithmsList.Clear();
User.Settings.Device.opencl.AlgorithmsList.Clear();
User.Settings.Device.cuda.AlgorithmsList.Clear();
User.Settings.Device.cpu.AlgorithmsList.AddRange(algoListCpu.Distinct());
User.Settings.Device.opencl.AlgorithmsList.AddRange(algoListOpencl.Distinct().ToList());
User.Settings.Device.cuda.AlgorithmsList.AddRange(algoListCuda.Distinct().ToList());
if (!User.Settings.Device.cpu.AlgorithmsList.Contains(User.Settings.Device.cpu.Algorithm)) { User.Settings.Device.cpu.Algorithm = User.Settings.Device.cpu.AlgorithmsList.First(); }
if (!User.Settings.Device.cuda.AlgorithmsList.Contains(User.Settings.Device.cuda.Algorithm)) { User.Settings.Device.cuda.Algorithm = User.Settings.Device.cuda.AlgorithmsList.First(); }
if (!User.Settings.Device.opencl.AlgorithmsList.Contains(User.Settings.Device.opencl.Algorithm)) { User.Settings.Device.opencl.Algorithm = User.Settings.Device.opencl.AlgorithmsList.First(); }
}
catch { }
Tools.TryChangeTaskbarIconAsSettingsOrder();
Task.Run(() => User.Settings.SettingsSaver());
if (Core.NextStart.Actions.loadedNextStartInstructions.useThisInstructions)
{
if (Core.NextStart.Actions.loadedNextStartInstructions.startMining)
{
if (!string.IsNullOrEmpty(User.Settings.User.Payment_Wallet))
{
if (!Miner.IsMining) { Miner.StartMiners(); }
}
}
}
else
{
if (User.Settings.User.AutostartMining)
{
if (!string.IsNullOrEmpty(User.Settings.User.Payment_Wallet))
{
if (!Miner.IsMining) { Miner.StartMiners(); }
}
}
}
try
{
// Se a PaymentCoin selecionada (ou não) não for uma moeda em fase de deslistagem, remova as moedas em fase de deslistagem da lista para que não sejam mais selecionadas
if (!User.Settings.User.PayCoin.Unlisting)
{
Server.SoftwareParameters.ServerConfig.PaymentCoins.Where(coin => coin.Unlisting).ToList().ForEach(coin => User.Settings.User.Payment_CoinsList.Remove(coin.CoinTicker + " - " + coin.CoinName));
}
}
catch { }
}
private void Notifier_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
ContextMenu menu = (ContextMenu)FindResource("NotifierContextMenu");
menu.IsOpen = true;
menu.StaysOpen = true;
new Task(() => { Thread.Sleep(5000); Dispatcher.BeginInvoke((Action)(() => { menu.IsOpen = false; })); }).Start();
}
}
private void Menu_Show(object sender, RoutedEventArgs e)
{
WindowState = WindowState.Normal;
ShowInTaskbar = true;
Show();
Activate();
Focus();
}
private void Menu_Hide(object sender, RoutedEventArgs e)
{
Hide();
}
private void Menu_Close(object sender, RoutedEventArgs e)
{
Close();
}
private bool windowsShutdowning = false;
public static bool Clicado;
private Point lm;
public void Down(object sender, MouseButtonEventArgs e)
{
Clicado = true;
lm.X = System.Windows.Forms.Control.MousePosition.X;
lm.Y = System.Windows.Forms.Control.MousePosition.Y;
lm.X = Convert.ToInt16(Left) - lm.X;
lm.Y = Convert.ToInt16(Top) - lm.Y;
}
public void Move(object sender, MouseEventArgs e)
{
if (Clicado && e.LeftButton == MouseButtonState.Pressed)
{
Left = (System.Windows.Forms.Control.MousePosition.X + lm.X);
Top = (System.Windows.Forms.Control.MousePosition.Y + lm.Y);
}
else { Clicado = false; }
}
public void Up(object sender, MouseButtonEventArgs e)
{
Clicado = false;
}
private void PackIcon_MouseDown(object sender, MouseButtonEventArgs e)
{
Close();
}
private void PackIcon_MouseDown_1(object sender, MouseButtonEventArgs e)
{
Hide();
NotifyIcon.ShowBalloonTip(4000, "Hiding", "True Mining was hidden in the notification bar", System.Windows.Forms.ToolTipIcon.Info);
}
private void PackIcon_MouseDown_2(object sender, MouseButtonEventArgs e)
{
WindowState = WindowState.Minimized;
}
private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
MenuMenu.ScrollIntoView(MenuMenu.Items[0]); //scroll to top
}
private void Window_StateChanged(object sender, EventArgs e)
{
if (Clicado) Clicado = false;
}
private void Window_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (Clicado) Clicado = false;
}
private void Window_LostMouseCapture(object sender, MouseEventArgs e)
{
if (Clicado) Clicado = false;
}
private void TorIcon_MouseDown(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("IP address: " + Tools.HttpGet("https://api.ipify.org", true));
}
}
}