forked from plenteum/plenteum-wallet-winforms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtilities.cs
77 lines (67 loc) · 2.6 KB
/
Utilities.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
using System;
using System.Windows.Forms;
using System.Diagnostics;
using System.Linq;
namespace PlenteumWallet
{
class Utilities
{
/* Set to false every time we call hide() or close() so the whole
program doesn't get shut down - but it does when we hit the x
button. The issue is that microsoft are really helpful people
and both close()/hide() and the x button give a close reason of
"UserClosing" so we have to use an extra boolean flag so we can
tell if the form is being closed or if we want to close the whole
program. Thanks MS! */
private static bool appClosing = true;
public static void CloseProgram(FormClosingEventArgs e)
{
/* For some stupid reason if we programatically call close() on
the form the closereason is still userclosing - so we need
and extra flag */
if (e.CloseReason == CloseReason.UserClosing && appClosing)
{
DialogResult dialogResult = MessageBox.Show("Are you sure you want to close Plenteum Wallet?", "Plenteum Wallet", MessageBoxButtons.YesNo);
if (dialogResult != DialogResult.Yes)
{
e.Cancel = true;
}
else
{
/* Kill the launched service in the background */
var conflictingProcesses = Process.GetProcessesByName("wallet-service").Concat(Process.GetProcessesByName("xmr-stak")).ToArray();
int numConflictingProcesses = conflictingProcesses.Length;
for (int i = 0; i < numConflictingProcesses; i++)
{
/* Need to kill all service and Plenteumd processes so
they don't lock the DB */
conflictingProcesses[i].Kill();
}
Environment.Exit(0);
}
}
}
public static void Hide(Form caller)
{
appClosing = false;
caller.Hide();
appClosing = true;
}
public static void Close(Form caller)
{
appClosing = false;
caller.Close();
appClosing = true;
}
public static void SetDialogResult(Form caller, DialogResult res)
{
appClosing = false;
caller.DialogResult = res;
appClosing = true;
}
public static void SetAppClosing(bool _appClosing)
{
appClosing = _appClosing;
}
}
}